Skip to content

Commit 7302fe4

Browse files
committed
MNT: flake8: fix E704, E226; ignore = F824, W503, W504
1 parent 60b5352 commit 7302fe4

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

benchmark/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ def method_note(method):
124124
return ' \N{DAGGER}' if is_nonconstrained else ''
125125

126126
header = f'{"Test function":24s}\t{"Method":24s}\tN Evals\tError %\tDuration'.expandtabs(4)
127-
print(header, '—'*len(header), sep='\n')
127+
print(header, '—' * len(header), sep='\n')
128128
for r in sorted(results, key=lambda r: (r['func'], r['error'], r['nfev'], r['method'])):
129129
print(f"{r['func']:24s}\t{r['method'] + method_note(r['method']):24s}\t{str(r['nfev']):>6s}{('' if r['success'] else '*')}\t{r['error']:7d}\t{r['duration']:5.2f}".expandtabs(4)) # noqa: E501
130130

131131
print('\n')
132132

133133
header = f'{"Method":24s}\t{"Correct":7s}\tN Evals\tError %\tDuration'.expandtabs(4)
134-
print(header, '—'*len(header), sep='\n')
134+
print(header, '—' * len(header), sep='\n')
135135

136136
def key_func(r):
137137
return r['method']

benchmark/funcs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424
'name': 'rosenbrock',
2525
'func': rosen,
2626
'constraints': lambda x: sum(x**2) <= 1.1 * len(x),
27-
'bounds': [[-2., 2.1]]*10,
27+
'bounds': [[-2., 2.1]] * 10,
2828
'tol': 1,
2929
'solution': 0,
3030
'codomain': [0, 3500],
3131
},
3232
{
3333
'name': 'bird',
34-
'func': lambda x: sin(x[1]) * exp((1-cos(x[0]))**2) + cos(x[0]) * exp((1-sin(x[1]))**2) + (x[0] - x[1])**2,
35-
'constraints': lambda x: (x[0] + 5)++2 + (x[1] + 5)**2 < 25,
34+
'func': lambda x: sin(x[1]) * exp((1 - cos(x[0]))**2) + cos(x[0]) * exp((1 - sin(x[1]))**2) + (x[0] - x[1])**2,
35+
'constraints': lambda x: (x[0] + 5)**2 + (x[1] + 5)**2 < 25,
3636
'bounds': [[-10., 0.], [-6.5, 0.]],
3737
'tol': 1,
3838
'solution': -106.77,
3939
'codomain': [-106.77, 97.7],
4040
},
4141
{
4242
'name': 'gomez-levy',
43-
'func': lambda x: 4*x[0]**2 - 2.1*x[0]**4 + 1/3*x[0]**6 + x[0]*x[1] - 4*x[1]**2 + 4*x[1]**4,
44-
'constraints': lambda x: -sin(4*pi*x[0]) + 2*sin(2*pi*x[1])**2 <= 1.5,
43+
'func': lambda x: 4 * x[0]**2 - 2.1 * x[0]**4 + x[0]**6 / 3 + x[0] * x[1] - 4 * x[1]**2 + 4 * x[1]**4,
44+
'constraints': lambda x: -sin(4 * pi * x[0]) + 2 * sin(2 * pi * x[1])**2 <= 1.5,
4545
'bounds': [[-1., .75], [-1., 1.]],
4646
'tol': .1,
4747
'solution': -1.0317,
@@ -78,7 +78,7 @@
7878
},
7979
{
8080
'name': '6-hump-camelback',
81-
'func': lambda x: (4 - 2.1*x[0]**2 + x[0]**4/3)*x[0]**2 + x[0]*x[1] + (-4 + 4*x[1]**2)*x[1]**2,
81+
'func': lambda x: (4 - 2.1 * x[0]**2 + x[0]**4 / 3) * x[0]**2 + x[0] * x[1] + (-4 + 4 * x[1]**2) * x[1]**2,
8282
'constraints': None,
8383
'bounds': [[-2., 2.], [-1., 1.]],
8484
'tol': 1,
@@ -87,7 +87,7 @@
8787
},
8888
{
8989
'name': 'griewank',
90-
'func': lambda x: 1 + sum(x**2) / 4000 - prod(cos(x/sqrt(1 + arange(len(x))))),
90+
'func': lambda x: 1 + sum(x**2) / 4000 - prod(cos(x / sqrt(1 + arange(len(x))))),
9191
'constraints': None,
9292
'bounds': [[-600., 590.], [-590., 600.]],
9393
'tol': 300,

sambo/_smbo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
)
1616

1717

18-
def _LCB(*, mean, std, kappa): return mean - np.outer(kappa, std)
18+
def _LCB(*, mean, std, kappa):
19+
return mean - np.outer(kappa, std)
1920

2021

2122
class Optimizer:
@@ -243,7 +244,7 @@ def _fit(self):
243244
def _predict(self, X):
244245
means, stds, masks = [], [], []
245246
for estimator in self.estimators:
246-
X_batched = [X[i:i+10_000] for i in range(0, len(X), 10_000)]
247+
X_batched = [X[i:i + 10_000] for i in range(0, len(X), 10_000)]
247248
try:
248249
mean, std = np.concatenate(
249250
[estimator.predict(X, return_std=True) for X in X_batched], axis=1)

sambo/_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_ask_tell_interface(self):
7878
np.testing.assert_array_equal(res.funv, np.arange(4))
7979

8080
def test_multiple_runs_continue_ie_warm_start(self):
81-
optimizer = Optimizer(fun=sum, x0=[0]*3, n_init=1)
81+
optimizer = Optimizer(fun=sum, x0=[0] * 3, n_init=1)
8282
optimizer.run(max_iter=1)
8383
optimizer.run(max_iter=1)
8484
res = optimizer.run(max_iter=1)
@@ -325,7 +325,7 @@ def test_estimator_factory(self):
325325
}
326326
for estimator in BUILTIN_ESTIMATORS:
327327
with self.subTest(estimator=estimator):
328-
res = smbo(lambda x: sum((x-2)**2), bounds=[(-100, 100)], estimator=estimator,
328+
res = smbo(lambda x: sum((x - 2)**2), bounds=[(-100, 100)], estimator=estimator,
329329
**dict(DEFAULT_KWARGS, **ESTIMATOR_KWARGS[estimator]))
330330
self.assertLess(res.fun, 1, msg=res)
331331

@@ -364,7 +364,7 @@ def test_make_doc_plots(self):
364364
}
365365
results = [
366366
minimize(
367-
rosen, bounds=[(-2., 2.)]*2,
367+
rosen, bounds=[(-2., 2.)] * 2,
368368
constraints=lambda x: sum(x**2) <= 2**len(x),
369369
max_iter=100, method=method, rng=2,
370370
**KWARGS.get(method, {}),
@@ -418,7 +418,7 @@ def evaluate(x):
418418

419419
results = []
420420
for estimator in BUILTIN_ESTIMATORS:
421-
optimizer = Optimizer(fun=None, bounds=[(-2, 2)]*4, estimator=estimator, rng=0)
421+
optimizer = Optimizer(fun=None, bounds=[(-2, 2)] * 4, estimator=estimator, rng=0)
422422

423423
for i in range(30):
424424
suggested_x = optimizer.ask(n_candidates=1)

sambo/_util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ def wrapper(*args, **kwargs):
8484

8585
@runtime_checkable
8686
class _SklearnLikeRegressor(Protocol):
87-
def fit(self, X, y): pass
88-
def predict(self, X, return_std=False): pass
87+
def fit(self, X: np.ndarray, y: np.ndarray):
88+
pass
89+
def predict(self, X, return_std=False): # noqa: E301
90+
pass
8991

9092

9193
class OptimizeResult(_OptimizeResult):

sambo/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def plot_convergence(
9292
mins = np.minimum.accumulate(result.funv)
9393

9494
ax.plot(range(1, nfev + 1), mins,
95-
label=name, marker=next(MARKER), markevery=(.05 + .05*i, .2),
95+
label=name, marker=next(MARKER), markevery=(.05 + .05 * i, .2),
9696
linestyle='--', alpha=.7, markersize=6, lw=2)
9797

9898
if true_minimum is not None:
@@ -195,7 +195,7 @@ def plot_regret(
195195
for i in range(1, nfev + 1)]
196196

197197
ax.plot(range(1, nfev + 1), regrets,
198-
label=name, marker=next(MARKER), markevery=(.05 + .05*i, .2),
198+
label=name, marker=next(MARKER), markevery=(.05 + .05 * i, .2),
199199
linestyle='--', alpha=.7, markersize=6, lw=2)
200200

201201
if name is not None:

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[flake8]
22
max-line-length = 120
3+
# F824 `nonlocal x` is unused: name is never assigned in scope
4+
# W503 Line break before a binary operator
5+
# W504 Line break after a binary operator -- https://www.flake8rules.com/rules/W504.html
6+
ignore = F824, W503, W504
37

48
[mypy]
59
warn_unused_ignores = True

0 commit comments

Comments
 (0)