Skip to content

Power up pre-commit #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
known_third_party = PIL,atomicwrites,holoviews,ipykernel,matplotlib,nbconvert,numpy,pytest,scipy,setuptools,skopt,sortedcollections,sortedcontainers,zmq
45 changes: 36 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.3b0
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
rev: v2.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: check-ast
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
rev: 3.7.9
hooks:
- id: flake8
args: ['--max-line-length=500', '--ignore=E203,E266,E501,W503', '--max-complexity=18', '--select=B,C,E,F,W,T4,B9']
args:
- --max-line-length=500
- --ignore=E203,E266,E501,W503
- --max-complexity=18
- --select=B,C,E,F,W,T4,B9
- repo: https://github.com/ambv/black
rev: 19.10b0
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/asottile/pyupgrade
rev: v1.25.2
hooks:
- id: pyupgrade
args: ['--py36-plus']
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
args:
- --multi-line=3
- --trailing-comma
- --force-grid-wrap=0
- --use-parentheses
- --line-width=88
- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.3
hooks:
- id: seed-isort-config
2 changes: 0 additions & 2 deletions adaptive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from contextlib import suppress

from adaptive import learner, runner, utils
Expand Down
1 change: 0 additions & 1 deletion adaptive/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# This file is part of 'miniver': https://github.com/jbweston/miniver
#
import os
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from contextlib import suppress

from adaptive.learner.average_learner import AverageLearner
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/average_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from math import sqrt

import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/balancing_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import itertools
from collections import defaultdict
from collections.abc import Iterable
Expand Down
4 changes: 1 addition & 3 deletions adaptive/learner/base_learner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-

import abc
from contextlib import suppress
from copy import deepcopy

from adaptive.utils import load, save, _RequireAttrsABCMeta
from adaptive.utils import _RequireAttrsABCMeta, load, save


def uses_nth_neighbors(n):
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/data_saver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import functools
from collections import OrderedDict

Expand Down
1 change: 0 additions & 1 deletion adaptive/learner/integrator_coeffs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Based on an adaptive quadrature algorithm by Pedro Gonnet

from collections import defaultdict
Expand Down
13 changes: 9 additions & 4 deletions adaptive/learner/integrator_learner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Based on an adaptive quadrature algorithm by Pedro Gonnet

import sys
Expand Down Expand Up @@ -572,9 +571,15 @@ def _get_data(self):
)

def _set_data(self, data):
self.priority_split, self.data, self.pending_points, self._stack, x_mapping, self.ivals, self.first_ival = (
data
)
(
self.priority_split,
self.data,
self.pending_points,
self._stack,
x_mapping,
self.ivals,
self.first_ival,
) = data

# Add the pending_points to the _stack such that they are evaluated again
for x in self.pending_points:
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import itertools
import math
from collections.abc import Iterable
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/learner2D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import itertools
import warnings
from collections import OrderedDict
Expand Down
6 changes: 2 additions & 4 deletions adaptive/learner/learnerND.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import functools
import itertools
import random
Expand Down Expand Up @@ -340,8 +338,8 @@ def __init__(self, func, bounds, loss_per_simplex=None):
self._min_value = None
self._max_value = None
self._output_multiplier = (
1
) # If we do not know anything, do not scale the values
1 # If we do not know anything, do not scale the values
)
self._recompute_losses_factor = 1.1

# create a private random number generator with fixed seed
Expand Down
2 changes: 0 additions & 2 deletions adaptive/learner/skopt_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import collections

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def simplex_volume_in_embedding(vertices) -> float:
# Make matrix and find volume
sq_dists_mat = scipy.spatial.distance.squareform(bordered)

coeff = -(-2) ** (num_verts - 1) * factorial(num_verts - 1) ** 2
coeff = -((-2) ** (num_verts - 1)) * factorial(num_verts - 1) ** 2
vol_square = fast_det(sq_dists_mat) / coeff

if vol_square < 0:
Expand Down
2 changes: 0 additions & 2 deletions adaptive/notebook_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import asyncio
import datetime
import importlib
Expand Down
2 changes: 0 additions & 2 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import abc
import asyncio
import concurrent.futures as concurrent
Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_average_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import random

import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_balancing_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import pytest

from adaptive.learner import BalancingLearner, Learner1D
Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_cquad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from functools import partial
from operator import attrgetter

Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_learner1d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import random

import numpy as np
Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_learnernd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import numpy as np
import scipy.spatial

Expand Down
6 changes: 2 additions & 4 deletions adaptive/tests/test_learners.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import collections
import functools as ft
import inspect
Expand Down Expand Up @@ -129,15 +127,15 @@ def linear_with_peak(x, d: uniform(-1, 1)):
def ring_of_fire(xy, d: uniform(0.2, 1)):
a = 0.2
x, y = xy
return x + math.exp(-(x ** 2 + y ** 2 - d ** 2) ** 2 / a ** 4)
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)


@learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)))
@learn_with(SequenceLearner, sequence=np.random.rand(1000, 3))
def sphere_of_fire(xyz, d: uniform(0.2, 1)):
a = 0.2
x, y, z = xyz
return x + math.exp(-(x ** 2 + y ** 2 + z ** 2 - d ** 2) ** 2 / a ** 4) + z ** 2
return x + math.exp(-((x ** 2 + y ** 2 + z ** 2 - d ** 2) ** 2) / a ** 4) + z ** 2


@learn_with(SequenceLearner, sequence=range(1000))
Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_notebook_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import ipykernel.iostream
import zmq

Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import asyncio
import time

Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_skopt_learner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import numpy as np
import pytest

Expand Down
2 changes: 0 additions & 2 deletions adaptive/tests/test_triangulation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import itertools
from collections import Counter
from math import factorial
Expand Down
2 changes: 1 addition & 1 deletion adaptive/tests/unit/test_learnernd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def ring_of_fire(xy):
a = 0.2
d = 0.7
x, y = xy
return x + math.exp(-(x ** 2 + y ** 2 - d ** 2) ** 2 / a ** 4)
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)


def test_learnerND_inits_loss_depends_on_neighbors_correctly():
Expand Down
2 changes: 1 addition & 1 deletion adaptive/tests/unit/test_learnernd_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def ring_of_fire(xy, d=0.75):
a = 0.2
x, y = xy
return x + math.exp(-(x ** 2 + y ** 2 - d ** 2) ** 2 / a ** 4)
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)


def test_learnerND_runs_to_10_points():
Expand Down
2 changes: 0 additions & 2 deletions adaptive/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import abc
import functools
import gzip
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def f_1d(x, offset=offset):
def f_2d(xy):
x, y = xy
a = 0.2
return x + np.exp(-(x ** 2 + y ** 2 - 0.75 ** 2) ** 2 / a ** 4)
return x + np.exp(-((x ** 2 + y ** 2 - 0.75 ** 2) ** 2) / a ** 4)


class TimeLearner1D:
Expand Down
4 changes: 2 additions & 2 deletions docs/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

sys.path.insert(0, os.path.abspath("..")) # to get adaptive on the path

import adaptive # noqa: E402
import adaptive # noqa: E402, isort:skip

holoviews.notebook_extension("matplotlib")

Expand All @@ -19,7 +19,7 @@ def ring(xy):

x, y = xy
a = 0.2
return x + np.exp(-(x ** 2 + y ** 2 - 0.75 ** 2) ** 2 / a ** 4)
return x + np.exp(-((x ** 2 + y ** 2 - 0.75 ** 2) ** 2) / a ** 4)

learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
Expand Down
6 changes: 2 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -18,12 +17,11 @@
package_path = os.path.abspath("../..")
# Insert into sys.path so that we can import adaptive here
sys.path.insert(0, package_path)

import adaptive # noqa: E402

# Insert into PYTHONPATH so that jupyter-sphinx will pick it up
os.environ["PYTHONPATH"] = ":".join((package_path, os.environ.get("PYTHONPATH", "")))

import adaptive # noqa: E402, isort:skip

# -- Project information -----------------------------------------------------

project = "adaptive"
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

Expand Down