Skip to content
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

Update pre-commit filters versions #345

Merged
merged 2 commits into from
May 31, 2022
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -9,16 +9,16 @@ repos:
- id: debug-statements
- id: check-ast
- repo: https://github.com/ambv/black
rev: 21.9b0
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v2.27.0
rev: v2.32.1
hooks:
- id: pyupgrade
args: ['--py37-plus']
- repo: https://github.com/timothycrosley/isort
rev: 5.9.3
rev: 5.10.1
hooks:
- id: isort
- repo: https://gitlab.com/pycqa/flake8
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/average_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def tell(self, n: int, value: Real) -> None:
self.data[n] = value
self.pending_points.discard(n)
self.sum_f += value
self.sum_f_sq += value ** 2
self.sum_f_sq += value**2
self.npoints += 1

def tell_pending(self, n: int) -> None:
Expand All @@ -111,7 +111,7 @@ def std(self) -> Float:
n = self.npoints
if n < self.min_npoints:
return np.inf
numerator = self.sum_f_sq - n * self.mean ** 2
numerator = self.sum_f_sq - n * self.mean**2
if numerator < 0:
# in this case the numerator ~ -1e-15
return 0
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def curvature_loss(xs: XsType1, ys: YsType1) -> Float:
default_loss_ = default_loss(xs_middle, ys_middle)
dx = xs_middle[1] - xs_middle[0]
return (
area_factor * (triangle_loss_ ** 0.5)
area_factor * (triangle_loss_**0.5)
+ euclid_factor * default_loss_
+ horizontal_factor * dx
)
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/learner2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def resolution_loss(ip):

A = areas(ip)
# Setting areas with a small area to zero such that they won't be chosen again
loss[A < min_distance ** 2] = 0
loss[A < min_distance**2] = 0

# Setting triangles that have a size larger than max_distance to infinite loss
# such that these triangles will be picked
loss[A > max_distance ** 2] = np.inf
loss[A > max_distance**2] = np.inf

return loss

Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _relative_volume(self, simplex):
vertices = array(self.get_vertices(simplex))
vectors = vertices[1:] - vertices[0]
average_edge_length = mean(np_abs(vectors))
return self.volume(simplex) / (average_edge_length ** self.dim)
return self.volume(simplex) / (average_edge_length**self.dim)

def add_point(self, point, simplex=None, transform=None):
"""Add a new vertex and create simplices as appropriate.
Expand Down
2 changes: 1 addition & 1 deletion adaptive/notebook_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def should_update(status):
# i.e. we're offline for 12h, with an update_interval of 0.5s,
# and without the reduced probability, we have buffer_size=86400.
# With the correction this is np.log(86400) / np.log(1.1) = 119.2
return 1.1 ** buffer_size * random.random() < 1
return 1.1**buffer_size * random.random() < 1
except Exception:
# We catch any Exception because we are using a private API.
return True
Expand Down
4 changes: 2 additions & 2 deletions adaptive/tests/algorithm_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def f0(x):


def f7(x):
return x ** -0.5
return x**-0.5


def f24(x):
Expand All @@ -421,7 +421,7 @@ def f24(x):
def f21(x):
y = 0
for i in range(1, 4):
y += 1 / np.cosh(20 ** i * (x - 2 * i / 10))
y += 1 / np.cosh(20**i * (x - 2 * i / 10))
return y


Expand Down
16 changes: 8 additions & 8 deletions adaptive/tests/test_learner1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,17 @@ def test_tell_many():
def f(x, offset=0.123214):
a = 0.01
return (
np.sin(x ** 2)
+ np.sin(x ** 5)
+ a ** 2 / (a ** 2 + (x - offset) ** 2)
+ x ** 2
+ 1e-5 * x ** 3
np.sin(x**2)
+ np.sin(x**5)
+ a**2 / (a**2 + (x - offset) ** 2)
+ x**2
+ 1e-5 * x**3
)

def f_vec(x, offset=0.123214):
a = 0.01
y = x + a ** 2 / (a ** 2 + (x - offset) ** 2)
return [y, 0.5 * y, y ** 2]
y = x + a**2 / (a**2 + (x - offset) ** 2)
return [y, 0.5 * y, y**2]

def assert_equal_dicts(d1, d2):
xs1, ys1 = zip(*sorted(d1.items()))
Expand Down Expand Up @@ -395,7 +395,7 @@ def f(x):
a = 0.01
if random.random() < 0.2:
return np.NaN
return x + a ** 2 / (a ** 2 + x ** 2)
return x + a**2 / (a**2 + x**2)

learner = Learner1D(f, bounds=(-1, 1))
simple(learner, lambda l: l.npoints > 100)
Expand Down
12 changes: 6 additions & 6 deletions adaptive/tests/test_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ def maybe_skip(learner):

@learn_with(Learner1D, bounds=(-1, 1))
def quadratic(x, m: uniform(1, 4), b: uniform(0, 1)):
return m * x ** 2 + b
return m * x**2 + b


@learn_with(Learner1D, bounds=(-1, 1))
@learn_with(SequenceLearner, sequence=np.linspace(-1, 1, 201))
def linear_with_peak(x, d: uniform(-1, 1)):
a = 0.01
return x + a ** 2 / (a ** 2 + (x - d) ** 2)
return x + a**2 / (a**2 + (x - d) ** 2)


@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)))
Expand All @@ -147,15 +147,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, 0.5)):
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 All @@ -172,7 +172,7 @@ def noisy_peak(
offset: uniform(-0.6, -0.3),
):
seed, x = seed_x
y = x ** 3 - x + 3 * peak_width ** 2 / (peak_width ** 2 + (x - offset) ** 2)
y = x**3 - x + 3 * peak_width**2 / (peak_width**2 + (x - offset) ** 2)
noise = np.random.normal(0, sigma)
return y + noise

Expand Down Expand Up @@ -264,7 +264,7 @@ def test_uniform_sampling2D(learner_type, f, learner_kwargs):
ys, dy = np.linspace(*ybounds, int(n * r), retstep=True)

distances, neighbors = tree.query(list(it.product(xs, ys)), k=1)
assert max(distances) < math.sqrt(dx ** 2 + dy ** 2)
assert max(distances) < math.sqrt(dx**2 + dy**2)


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions adaptive/tests/test_pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def goal_2(learner):


def pickleable_f(x):
return hash(str(x)) / 2 ** 63
return hash(str(x)) / 2**63


nonpickleable_f = lambda x: hash(str(x)) / 2 ** 63 # noqa: E731
nonpickleable_f = lambda x: hash(str(x)) / 2**63 # noqa: E731


def identity_function(x):
Expand Down
2 changes: 1 addition & 1 deletion adaptive/tests/test_skopt_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_skopt_learner_runs():
"""

def g(x, noise_level=0.1):
return np.sin(5 * x) * (1 - np.tanh(x ** 2)) + np.random.randn() * noise_level
return np.sin(5 * x) * (1 - np.tanh(x**2)) + np.random.randn() * noise_level

learner = SKOptLearner(g, dimensions=[(-2.0, 2.0)])

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
12 changes: 6 additions & 6 deletions benchmarks/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

def f_1d(x, offset=offset):
a = 0.01
return x + a ** 2 / (a ** 2 + (x - offset) ** 2)
return x + a**2 / (a**2 + (x - offset) ** 2)


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 All @@ -31,16 +31,16 @@ def time_run(self):
class TimeLearner2D:
def setup(self):
self.learner = adaptive.Learner2D(f_2d, bounds=[(-1, 1), (-1, 1)])
self.xs = np.random.rand(50 ** 2, 2)
self.ys = np.random.rand(50 ** 2)
self.xs = np.random.rand(50**2, 2)
self.ys = np.random.rand(50**2)

def time_run(self):
for _ in range(50 ** 2):
for _ in range(50**2):
points, _ = self.learner.ask(1)
self.learner.tell_many(points, map(f_2d, points))

def time_ask(self):
for _ in range(50 ** 2):
for _ in range(50**2):
self.learner.ask(1)

def time_tell(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/logo_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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.005)
Expand Down