Skip to content

Commit 3cc3479

Browse files
committed
[ruff] fix some ruff errors and warnings
1 parent 3a81bc7 commit 3cc3479

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

comocma/como_logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def store(self, moes):
202202
# update the number of times this function have been called
203203
self.num_calls += 1
204204
# update the maximum and minimum stepsize of the current run
205-
if not "max_stepsize" in self._data:
205+
if "max_stepsize" not in self._data:
206206
self._data["max_stepsize"] = - float('inf')
207-
if not "min_stepsize" in self._data:
207+
if "min_stepsize" not in self._data:
208208
self._data["min_stepsize"] = float('inf')
209209
if moes.kernels[-1].countevals > 0 or len(moes.kernels) < 1:
210210
self._data["max_stepsize"] = max(self._data["max_stepsize"], moes.kernels[-1].sigma)

comocma/hv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def hvRecursive(self, dimIndex, length, bounds):
108108
hvRecursive = self.hvRecursive
109109
p = sentinel
110110
q = p.prev[dimIndex]
111-
while q.cargo != None:
111+
while q.cargo is not None:
112112
if q.ignore < dimIndex:
113113
q.ignore = 0
114114
q = q.prev[dimIndex]

comocma/sofomore_logger.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ def initialize(self, modulo=None):
120120
"""reset logger, overwrite original files, `modulo`: log only every modulo call"""
121121
if modulo is not None:
122122
self.modulo = modulo
123-
try:
124-
es = self.es # must have been registered
125-
except AttributeError:
126-
pass # TODO: revise usage of es... that this can pass
127-
raise AttributeError('call register() before initialize()')
128123

129124
self.counter = 0 # number of calls of add
130125
self.last_iteration = 0 # some lines are only written if iteration>last_iteration
@@ -295,18 +290,21 @@ def add(self, es=None, more_data=(), modulo=None):
295290
1 + len(kernel._last_offspring_f_values) )
296291

297292

298-
first_quartile_ratio_offspring_incumbent = np.percentile(es._ratio_nondom_offspring_incumbent, 25);
299-
median_ratio_offspring_incumbent = np.percentile(es._ratio_nondom_offspring_incumbent, 50);
300-
last_quartile_ratio_offspring_incumbent = np.percentile(es._ratio_nondom_offspring_incumbent, 75);
293+
first_quartile_ratio_offspring_incumbent = np.percentile(
294+
es._ratio_nondom_offspring_incumbent, 25)
295+
median_ratio_offspring_incumbent = np.percentile(
296+
es._ratio_nondom_offspring_incumbent, 50)
297+
last_quartile_ratio_offspring_incumbent = np.percentile(
298+
es._ratio_nondom_offspring_incumbent, 75)
301299

302300

303-
median_axis_ratios = np.median([kernel.D.max() / kernel.D.min() \
304-
if not kernel.opts['CMA_diagonal'] or kernel.countiter > kernel.opts['CMA_diagonal']
305-
else max(kernel.sigma_vec*1) / min(kernel.sigma_vec*1) for kernel in es.kernels])
301+
median_axis_ratios = np.median([kernel.D.max() / kernel.D.min()
302+
if not kernel.opts['CMA_diagonal'] or kernel.countiter > kernel.opts['CMA_diagonal']
303+
else max(kernel.sigma_vec*1) / min(kernel.sigma_vec*1) for kernel in es.kernels])
306304
median_sigmas = np.median([kernel.sigma for kernel in es.kernels])
307-
median_min_stds = np.median([kernel.sigma * min(kernel.sigma_vec * kernel.dC**0.5) \
305+
median_min_stds = np.median([kernel.sigma * min(kernel.sigma_vec * kernel.dC**0.5)
308306
for kernel in es.kernels])
309-
median_max_stds = np.median([kernel.sigma * max(kernel.sigma_vec * kernel.dC**0.5) \
307+
median_max_stds = np.median([kernel.sigma * max(kernel.sigma_vec * kernel.dC**0.5)
310308
for kernel in es.kernels])
311309
median_stds = self.es.median_stds
312310

@@ -444,6 +442,7 @@ def plot(self, filename=None, x_iteration = False):
444442
445443
Otherwise, plot all.
446444
"""
445+
from matplotlib import pyplot as plt
447446
if filename:
448447
iteration, countevals, res = self.load(filename)
449448
for i in range(len(res)):
@@ -452,7 +451,6 @@ def plot(self, filename=None, x_iteration = False):
452451
else:
453452
plt.plot(iteration, res)
454453
else:
455-
from matplotlib import pyplot as plt
456454
plt.figure(np.random.randint(9999999))
457455
self.plot_divers()
458456
plt.figure(np.random.randint(9999999))
@@ -608,14 +606,14 @@ def plot_stds(self, iabscissa=1):
608606
iteration, countevals, res = self.load(filename)
609607
absciss = countevals if iabscissa else iteration
610608
self._enter_plotting()
611-
# color = iter(pyplot.cm.plasma_r(np.linspace(0.35, 1, 3)))
609+
# color = iter(pyplot.cm.plasma_r(np.linspace(0.35, 1, 3)))
612610
self._xlabel(iabscissa)
613611

614612
pyplot.semilogy(absciss, res[0])
615613
# pyplot.plot(absciss, res[i],
616614
# '-', color=next(color), label = mylabel[i])
617615
# pyplot.semilogy(absciss, res[i],
618-
# '-', color=next(color), label = mylabel[i])
616+
# '-', color=next(color), label = mylabel[i])
619617
# pyplot.hold(True)
620618
pyplot.grid(True)
621619
ax = np.array(pyplot.axis())

0 commit comments

Comments
 (0)