Skip to content

Commit d1b0b2a

Browse files
authored
Update pre-commit filters versions (#345)
* update pre-commit versions * run all pre-commit filters
1 parent 8d4263a commit d1b0b2a

16 files changed

+40
-40
lines changed

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.2.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -9,16 +9,16 @@ repos:
99
- id: debug-statements
1010
- id: check-ast
1111
- repo: https://github.com/ambv/black
12-
rev: 21.9b0
12+
rev: 22.3.0
1313
hooks:
1414
- id: black
1515
- repo: https://github.com/asottile/pyupgrade
16-
rev: v2.27.0
16+
rev: v2.32.1
1717
hooks:
1818
- id: pyupgrade
1919
args: ['--py37-plus']
2020
- repo: https://github.com/timothycrosley/isort
21-
rev: 5.9.3
21+
rev: 5.10.1
2222
hooks:
2323
- id: isort
2424
- repo: https://gitlab.com/pycqa/flake8

adaptive/learner/average_learner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def tell(self, n: int, value: Real) -> None:
9393
self.data[n] = value
9494
self.pending_points.discard(n)
9595
self.sum_f += value
96-
self.sum_f_sq += value ** 2
96+
self.sum_f_sq += value**2
9797
self.npoints += 1
9898

9999
def tell_pending(self, n: int) -> None:
@@ -111,7 +111,7 @@ def std(self) -> Float:
111111
n = self.npoints
112112
if n < self.min_npoints:
113113
return np.inf
114-
numerator = self.sum_f_sq - n * self.mean ** 2
114+
numerator = self.sum_f_sq - n * self.mean**2
115115
if numerator < 0:
116116
# in this case the numerator ~ -1e-15
117117
return 0

adaptive/learner/learner1D.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def curvature_loss(xs: XsType1, ys: YsType1) -> Float:
162162
default_loss_ = default_loss(xs_middle, ys_middle)
163163
dx = xs_middle[1] - xs_middle[0]
164164
return (
165-
area_factor * (triangle_loss_ ** 0.5)
165+
area_factor * (triangle_loss_**0.5)
166166
+ euclid_factor * default_loss_
167167
+ horizontal_factor * dx
168168
)

adaptive/learner/learner2D.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ def resolution_loss(ip):
133133

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

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

142142
return loss
143143

adaptive/learner/triangulation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def _relative_volume(self, simplex):
581581
vertices = array(self.get_vertices(simplex))
582582
vectors = vertices[1:] - vertices[0]
583583
average_edge_length = mean(np_abs(vectors))
584-
return self.volume(simplex) / (average_edge_length ** self.dim)
584+
return self.volume(simplex) / (average_edge_length**self.dim)
585585

586586
def add_point(self, point, simplex=None, transform=None):
587587
"""Add a new vertex and create simplices as appropriate.

adaptive/notebook_integration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def should_update(status):
186186
# i.e. we're offline for 12h, with an update_interval of 0.5s,
187187
# and without the reduced probability, we have buffer_size=86400.
188188
# With the correction this is np.log(86400) / np.log(1.1) = 119.2
189-
return 1.1 ** buffer_size * random.random() < 1
189+
return 1.1**buffer_size * random.random() < 1
190190
except Exception:
191191
# We catch any Exception because we are using a private API.
192192
return True

adaptive/tests/algorithm_4.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def f0(x):
411411

412412

413413
def f7(x):
414-
return x ** -0.5
414+
return x**-0.5
415415

416416

417417
def f24(x):
@@ -421,7 +421,7 @@ def f24(x):
421421
def f21(x):
422422
y = 0
423423
for i in range(1, 4):
424-
y += 1 / np.cosh(20 ** i * (x - 2 * i / 10))
424+
y += 1 / np.cosh(20**i * (x - 2 * i / 10))
425425
return y
426426

427427

adaptive/tests/test_learner1d.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ def test_tell_many():
262262
def f(x, offset=0.123214):
263263
a = 0.01
264264
return (
265-
np.sin(x ** 2)
266-
+ np.sin(x ** 5)
267-
+ a ** 2 / (a ** 2 + (x - offset) ** 2)
268-
+ x ** 2
269-
+ 1e-5 * x ** 3
265+
np.sin(x**2)
266+
+ np.sin(x**5)
267+
+ a**2 / (a**2 + (x - offset) ** 2)
268+
+ x**2
269+
+ 1e-5 * x**3
270270
)
271271

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

277277
def assert_equal_dicts(d1, d2):
278278
xs1, ys1 = zip(*sorted(d1.items()))
@@ -395,7 +395,7 @@ def f(x):
395395
a = 0.01
396396
if random.random() < 0.2:
397397
return np.NaN
398-
return x + a ** 2 / (a ** 2 + x ** 2)
398+
return x + a**2 / (a**2 + x**2)
399399

400400
learner = Learner1D(f, bounds=(-1, 1))
401401
simple(learner, lambda l: l.npoints > 100)

adaptive/tests/test_learners.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ def maybe_skip(learner):
131131

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

136136

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

143143

144144
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)))
@@ -147,15 +147,15 @@ def linear_with_peak(x, d: uniform(-1, 1)):
147147
def ring_of_fire(xy, d: uniform(0.2, 1)):
148148
a = 0.2
149149
x, y = xy
150-
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)
150+
return x + math.exp(-((x**2 + y**2 - d**2) ** 2) / a**4)
151151

152152

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

160160

161161
@learn_with(SequenceLearner, sequence=range(1000))
@@ -172,7 +172,7 @@ def noisy_peak(
172172
offset: uniform(-0.6, -0.3),
173173
):
174174
seed, x = seed_x
175-
y = x ** 3 - x + 3 * peak_width ** 2 / (peak_width ** 2 + (x - offset) ** 2)
175+
y = x**3 - x + 3 * peak_width**2 / (peak_width**2 + (x - offset) ** 2)
176176
noise = np.random.normal(0, sigma)
177177
return y + noise
178178

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

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

269269

270270
@pytest.mark.parametrize(

adaptive/tests/test_pickling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def goal_2(learner):
3838

3939

4040
def pickleable_f(x):
41-
return hash(str(x)) / 2 ** 63
41+
return hash(str(x)) / 2**63
4242

4343

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

4646

4747
def identity_function(x):

adaptive/tests/test_skopt_learner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_skopt_learner_runs():
1616
"""
1717

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

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

adaptive/tests/unit/test_learnernd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def ring_of_fire(xy):
1212
a = 0.2
1313
d = 0.7
1414
x, y = xy
15-
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)
15+
return x + math.exp(-((x**2 + y**2 - d**2) ** 2) / a**4)
1616

1717

1818
def test_learnerND_inits_loss_depends_on_neighbors_correctly():

adaptive/tests/unit/test_learnernd_integration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def ring_of_fire(xy, d=0.75):
1212
a = 0.2
1313
x, y = xy
14-
return x + math.exp(-((x ** 2 + y ** 2 - d ** 2) ** 2) / a ** 4)
14+
return x + math.exp(-((x**2 + y**2 - d**2) ** 2) / a**4)
1515

1616

1717
def test_learnerND_runs_to_10_points():

benchmarks/benchmarks/benchmarks.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

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

1414

1515
def f_2d(xy):
1616
x, y = xy
1717
a = 0.2
18-
return x + np.exp(-((x ** 2 + y ** 2 - 0.75 ** 2) ** 2) / a ** 4)
18+
return x + np.exp(-((x**2 + y**2 - 0.75**2) ** 2) / a**4)
1919

2020

2121
class TimeLearner1D:
@@ -31,16 +31,16 @@ def time_run(self):
3131
class TimeLearner2D:
3232
def setup(self):
3333
self.learner = adaptive.Learner2D(f_2d, bounds=[(-1, 1), (-1, 1)])
34-
self.xs = np.random.rand(50 ** 2, 2)
35-
self.ys = np.random.rand(50 ** 2)
34+
self.xs = np.random.rand(50**2, 2)
35+
self.ys = np.random.rand(50**2)
3636

3737
def time_run(self):
38-
for _ in range(50 ** 2):
38+
for _ in range(50**2):
3939
points, _ = self.learner.ask(1)
4040
self.learner.tell_many(points, map(f_2d, points))
4141

4242
def time_ask(self):
43-
for _ in range(50 ** 2):
43+
for _ in range(50**2):
4444
self.learner.ask(1)
4545

4646
def time_tell(self):

docs/logo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def ring(xy):
1919

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

2424
learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
2525
adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)

docs/logo_animated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def ring(xy):
6565

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

7070
learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
7171
adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.005)

0 commit comments

Comments
 (0)