Skip to content

Commit 8fcb227

Browse files
committed
black fixes
1 parent fb13739 commit 8fcb227

File tree

8 files changed

+211
-92
lines changed

8 files changed

+211
-92
lines changed

pySDC/core/Controller.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ def __setup_custom_logger(level=None, log_to_file=None, fname=None):
101101
pass
102102

103103
def welcome_message(self):
104-
out = 'Welcome to the one and only, really very astonishing and 87.3% bug free' + \
105-
'\n _____ _____ _____ ' + \
106-
'\n / ____| __ \ / ____|' + \
107-
'\n _ __ _ _| (___ | | | | | ' + \
108-
'\n | \'_ \| | | |\___ \| | | | | ' + \
109-
'\n | |_) | |_| |____) | |__| | |____ ' + \
110-
'\n | .__/ \__, |_____/|_____/ \_____|' + \
111-
'\n | | __/ | ' + \
112-
'\n |_| |___/ ' + \
113-
'\n '
104+
out = (
105+
'Welcome to the one and only, really very astonishing and 87.3% bug free'
106+
+ '\n _____ _____ _____ '
107+
+ '\n / ____| __ \ / ____|'
108+
+ '\n _ __ _ _| (___ | | | | | '
109+
+ '\n | \'_ \| | | |\___ \| | | | | '
110+
+ '\n | |_) | |_| |____) | |__| | |____ '
111+
+ '\n | .__/ \__, |_____/|_____/ \_____|'
112+
+ '\n | | __/ | '
113+
+ '\n |_| |___/ '
114+
+ '\n '
115+
)
114116
self.logger.info(out)
115117

116118
def dump_setup(self, step, controller_params, description):

pySDC/implementations/convergence_controller_classes/adaptivity.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ def get_new_step_size(self, controller, S):
199199
order = S.status.iter # embedded error estimate is same order as time marching
200200

201201
e_est = self.get_local_error_estimate(controller, S)
202-
L.status.dt_new = self.compute_optimal_step_size(self.params.beta, L.params.dt, self.params.e_tol, e_est,
203-
order)
202+
L.status.dt_new = self.compute_optimal_step_size(
203+
self.params.beta, L.params.dt, self.params.e_tol, e_est, order
204+
)
204205
self.log(f'Adjusting step size from {L.params.dt:.2e} to {L.status.dt_new:.2e}', S)
205206

206207
return None
@@ -223,6 +224,7 @@ class AdaptivityRK(Adaptivity):
223224
'''
224225
Adaptivity for Runge-Kutta methods. Basically, we need to change the order in the step size update
225226
'''
227+
226228
def check_parameters(self, controller, params, description):
227229
'''
228230
Check whether parameters are compatible with whatever assumptions went into the step size functions etc.
@@ -238,8 +240,11 @@ def check_parameters(self, controller, params, description):
238240
str: The error message
239241
'''
240242
if 'update_order' not in params.keys():
241-
return False, 'Adaptivity needs an order for the update rule! Please set some up in \
242-
description[\'convergence_control_params\'][\'update_order\']!'
243+
return (
244+
False,
245+
'Adaptivity needs an order for the update rule! Please set some up in \
246+
description[\'convergence_control_params\'][\'update_order\']!',
247+
)
243248

244249
return super(AdaptivityRK, self).check_parameters(controller, params, description)
245250

@@ -261,8 +266,9 @@ def get_new_step_size(self, controller, S):
261266
# compute next step size
262267
order = self.params.update_order
263268
e_est = self.get_local_error_estimate(controller, S)
264-
L.status.dt_new = self.compute_optimal_step_size(self.params.beta, L.params.dt, self.params.e_tol, e_est,
265-
order)
269+
L.status.dt_new = self.compute_optimal_step_size(
270+
self.params.beta, L.params.dt, self.params.e_tol, e_est, order
271+
)
266272
self.log(f'Adjusting step size from {L.params.dt:.2e} to {L.status.dt_new:.2e}', S)
267273

268274
return None

pySDC/implementations/convergence_controller_classes/estimate_embedded_error.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ def estimate_embedded_error_serial(self, L):
6363
# order rises by one between sweeps, making this so ridiculously easy
6464
return abs(L.uold[-1] - L.u[-1])
6565
else:
66-
raise NotImplementedError(f'Don\'t know how to estimate embedded error for sweeper type \
67-
{self.params.sweeper_type}')
66+
raise NotImplementedError(
67+
f'Don\'t know how to estimate embedded error for sweeper type \
68+
{self.params.sweeper_type}'
69+
)
6870

6971

7072
class EstimateEmbeddedErrorNonMPI(EstimateEmbeddedError):

pySDC/implementations/sweeper_classes/Runge_Kutta.py

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def __init__(self, weights, nodes, matrix):
3838

3939
# Set number of nodes, left and right interval boundaries
4040
self.num_nodes = matrix.shape[0] + 1
41-
self.tleft = 0.
42-
self.tright = 1.
41+
self.tleft = 0.0
42+
self.tright = 1.0
4343

4444
self.nodes = np.append(np.append([0], nodes), [1])
4545
self.weights = weights
@@ -95,8 +95,8 @@ def __init__(self, weights, nodes, matrix):
9595

9696
# Set number of nodes, left and right interval boundaries
9797
self.num_nodes = matrix.shape[0] + 2
98-
self.tleft = 0.
99-
self.tright = 1.
98+
self.tleft = 0.0
99+
self.tright = 1.0
100100

101101
self.nodes = np.append(np.append([0], nodes), [1, 1])
102102
self.weights = weights
@@ -158,13 +158,16 @@ def __init__(self, params):
158158
self.params = _Pars(params)
159159

160160
if 'collocation_class' in params or 'num_nodes' in params:
161-
self.logger.warning('You supplied parameters to setup a collocation problem to the Runge-Kutta sweeper. \
162-
Please be aware that they are ignored since the quadrature matrix is entirely determined by the Butcher tableau.')
161+
self.logger.warning(
162+
'You supplied parameters to setup a collocation problem to the Runge-Kutta sweeper. \
163+
Please be aware that they are ignored since the quadrature matrix is entirely determined by the Butcher tableau.'
164+
)
163165
self.coll = params['butcher_tableau']
164166

165167
if not self.coll.right_is_node and not self.params.do_coll_update:
166-
self.logger.warning('we need to do a collocation update here, since the right end point is not a node. '
167-
'Changing this!')
168+
self.logger.warning(
169+
'we need to do a collocation update here, since the right end point is not a node. ' 'Changing this!'
170+
)
168171
self.params.do_coll_update = True
169172

170173
# This will be set as soon as the sweeper is instantiated at the level
@@ -200,8 +203,9 @@ def update_nodes(self):
200203

201204
# implicit solve with prefactor stemming from the diagonal of Qd
202205
if self.coll.implicit:
203-
L.u[m + 1] = P.solve_system(rhs, L.dt * self.QI[m + 1, m + 1], L.u[m + 1],
204-
L.time + L.dt * self.coll.nodes[m])
206+
L.u[m + 1] = P.solve_system(
207+
rhs, L.dt * self.QI[m + 1, m + 1], L.u[m + 1], L.time + L.dt * self.coll.nodes[m]
208+
)
205209
else:
206210
L.u[m + 1] = rhs
207211
# update function values
@@ -216,12 +220,20 @@ def update_nodes(self):
216220
class RK1(RungeKutta):
217221
def __init__(self, params):
218222
implicit = params.get('implicit', False)
219-
nodes = np.array([0.])
220-
weights = np.array([1.])
223+
nodes = np.array([0.0])
224+
weights = np.array([1.0])
221225
if implicit:
222-
matrix = np.array([[1.], ])
226+
matrix = np.array(
227+
[
228+
[1.0],
229+
]
230+
)
223231
else:
224-
matrix = np.array([[0.], ])
232+
matrix = np.array(
233+
[
234+
[0.0],
235+
]
236+
)
225237
params['butcher_tableau'] = ButcherTableau(weights, nodes, matrix)
226238
super(RK1, self).__init__(params)
227239

@@ -230,6 +242,7 @@ class CrankNicholson(RungeKutta):
230242
'''
231243
Implicit Runge-Kutta method of second order
232244
'''
245+
233246
def __init__(self, params):
234247
nodes = np.array([0, 1])
235248
weights = np.array([0.5, 0.5])
@@ -244,13 +257,14 @@ class MidpointMethod(RungeKutta):
244257
'''
245258
Runge-Kutta method of second order
246259
'''
260+
247261
def __init__(self, params):
248262
implicit = params.get('implicit', False)
249263
if implicit:
250264
nodes = np.array([0.5])
251265
weights = np.array([1])
252266
matrix = np.zeros((1, 1))
253-
matrix[0, 0] = 1. / 2.
267+
matrix[0, 0] = 1.0 / 2.0
254268
else:
255269
nodes = np.array([0, 0.5])
256270
weights = np.array([0, 1])
@@ -264,13 +278,14 @@ class RK4(RungeKutta):
264278
'''
265279
Explicit Runge-Kutta of fourth order: Everybodies darling.
266280
'''
281+
267282
def __init__(self, params):
268283
nodes = np.array([0, 0.5, 0.5, 1])
269-
weights = np.array([1., 2., 2., 1.]) / 6.
284+
weights = np.array([1.0, 2.0, 2.0, 1.0]) / 6.0
270285
matrix = np.zeros((4, 4))
271286
matrix[1, 0] = 0.5
272287
matrix[2, 1] = 0.5
273-
matrix[3, 2] = 1.
288+
matrix[3, 2] = 1.0
274289
params['butcher_tableau'] = ButcherTableau(weights, nodes, matrix)
275290
super(RK4, self).__init__(params)
276291

@@ -279,6 +294,7 @@ class Heun_Euler(RungeKutta):
279294
'''
280295
Second order explicit embedded Runge-Kutta
281296
'''
297+
282298
def __init__(self, params):
283299
nodes = np.array([0, 1])
284300
weights = np.array([[0.5, 0.5], [1, 0]])
@@ -292,15 +308,20 @@ class Cash_Karp(RungeKutta):
292308
'''
293309
Fifth order explicit embedded Runge-Kutta
294310
'''
311+
295312
def __init__(self, params):
296-
nodes = np.array([0, 0.2, 0.3, 0.6, 1., 7. / 8.])
297-
weights = np.array([[37. / 378., 0., 250. / 621., 125. / 594., 0., 512. / 1771.],
298-
[2825. / 27648., 0., 18575. / 48384., 13525. / 55296., 277. / 14336., 1. / 4.]])
313+
nodes = np.array([0, 0.2, 0.3, 0.6, 1.0, 7.0 / 8.0])
314+
weights = np.array(
315+
[
316+
[37.0 / 378.0, 0.0, 250.0 / 621.0, 125.0 / 594.0, 0.0, 512.0 / 1771.0],
317+
[2825.0 / 27648.0, 0.0, 18575.0 / 48384.0, 13525.0 / 55296.0, 277.0 / 14336.0, 1.0 / 4.0],
318+
]
319+
)
299320
matrix = np.zeros((6, 6))
300-
matrix[1, 0] = 1. / 5.
301-
matrix[2, :2] = [3. / 40., 9. / 40.]
321+
matrix[1, 0] = 1.0 / 5.0
322+
matrix[2, :2] = [3.0 / 40.0, 9.0 / 40.0]
302323
matrix[3, :3] = [0.3, -0.9, 1.2]
303-
matrix[4, :4] = [-11. / 54., 5. / 2., -70. / 27., 35. / 27.]
304-
matrix[5, :5] = [1631. / 55296., 175. / 512., 575. / 13824., 44275. / 110592., 253. / 4096.]
324+
matrix[4, :4] = [-11.0 / 54.0, 5.0 / 2.0, -70.0 / 27.0, 35.0 / 27.0]
325+
matrix[5, :5] = [1631.0 / 55296.0, 175.0 / 512.0, 575.0 / 13824.0, 44275.0 / 110592.0, 253.0 / 4096.0]
305326
params['butcher_tableau'] = ButcherTableauEmbedded(weights, nodes, matrix)
306327
super(Cash_Karp, self).__init__(params)

pySDC/projects/Resilience/accuracy_check.py

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def setup_mpl(font_size=8):
7171

7272
def get_results_from_stats(stats, var, val, hook_class=log_errors):
7373
results = {
74-
'e_embedded': 0.,
75-
'e_extrapolated': 0.,
76-
'e': 0.,
74+
'e_embedded': 0.0,
75+
'e_extrapolated': 0.0,
76+
'e': 0.0,
7777
var: val,
7878
}
7979

@@ -94,8 +94,16 @@ def get_results_from_stats(stats, var, val, hook_class=log_errors):
9494
return results
9595

9696

97-
def multiple_runs(k=5, serial=True, Tend_fixed=None, custom_description=None, prob=run_piline, dt_list=None,
98-
hook_class=log_errors, custom_controller_params=None):
97+
def multiple_runs(
98+
k=5,
99+
serial=True,
100+
Tend_fixed=None,
101+
custom_description=None,
102+
prob=run_piline,
103+
dt_list=None,
104+
hook_class=log_errors,
105+
custom_controller_params=None,
106+
):
99107
"""
100108
A simple test program to compute the order of accuracy in time
101109
"""
@@ -104,7 +112,7 @@ def multiple_runs(k=5, serial=True, Tend_fixed=None, custom_description=None, pr
104112
if dt_list is not None:
105113
pass
106114
elif Tend_fixed:
107-
dt_list = 0.1 * 10.**-(np.arange(5) / 2)
115+
dt_list = 0.1 * 10.0 ** -(np.arange(5) / 2)
108116
else:
109117
dt_list = 0.01 * 10.0 ** -(np.arange(20) / 10.0)
110118

@@ -123,8 +131,13 @@ def multiple_runs(k=5, serial=True, Tend_fixed=None, custom_description=None, pr
123131
if custom_description is not None:
124132
desc = {**desc, **custom_description}
125133
Tend = Tend_fixed if Tend_fixed else 30 * dt_list[i]
126-
stats, controller, _ = prob(custom_description=desc, num_procs=num_procs, Tend=Tend,
127-
hook_class=hook_class, custom_controller_params=custom_controller_params)
134+
stats, controller, _ = prob(
135+
custom_description=desc,
136+
num_procs=num_procs,
137+
Tend=Tend,
138+
hook_class=hook_class,
139+
custom_controller_params=custom_controller_params,
140+
)
128141

129142
level = controller.MS[-1].levels[-1]
130143
e_glob = abs(level.prob.u_exact(t=level.time + level.dt) - level.u[-1])
@@ -162,17 +175,21 @@ def plot(res, ax, k):
162175
color = plt.rcParams['axes.prop_cycle'].by_key()['color'][k - 2]
163176

164177
for i in range(len(keys)):
165-
if all([me == 0. for me in res[keys[i]]]):
178+
if all([me == 0.0 for me in res[keys[i]]]):
166179
continue
167180
order = get_accuracy_order(res, key=keys[i])
168181
if keys[i] == 'e_embedded':
169182
label = rf'$k={{{np.mean(order):.2f}}}$'
170-
assert np.isclose(np.mean(order), k, atol=4e-1), f'Expected embedded error estimate to have order {k} \
183+
assert np.isclose(
184+
np.mean(order), k, atol=4e-1
185+
), f'Expected embedded error estimate to have order {k} \
171186
but got {np.mean(order):.2f}'
172187

173188
elif keys[i] == 'e_extrapolated':
174189
label = None
175-
assert np.isclose(np.mean(order), k + 1, rtol=3e-1), f'Expected extrapolation error estimate to have order \
190+
assert np.isclose(
191+
np.mean(order), k + 1, rtol=3e-1
192+
), f'Expected extrapolation error estimate to have order \
176193
{k+1} but got {np.mean(order):.2f}'
177194
else:
178195
label = None
@@ -213,22 +230,52 @@ def get_accuracy_order(results, key='e_embedded', thresh=1e-14):
213230
return order
214231

215232

216-
def plot_orders(ax, ks, serial, Tend_fixed=None, custom_description=None, prob=run_piline, dt_list=None,
217-
custom_controller_params=None):
233+
def plot_orders(
234+
ax,
235+
ks,
236+
serial,
237+
Tend_fixed=None,
238+
custom_description=None,
239+
prob=run_piline,
240+
dt_list=None,
241+
custom_controller_params=None,
242+
):
218243
for i in range(len(ks)):
219244
k = ks[i]
220-
res = multiple_runs(k=k, serial=serial, Tend_fixed=Tend_fixed, custom_description=custom_description,
221-
prob=prob, dt_list=dt_list, hook_class=do_nothing,
222-
custom_controller_params=custom_controller_params)
245+
res = multiple_runs(
246+
k=k,
247+
serial=serial,
248+
Tend_fixed=Tend_fixed,
249+
custom_description=custom_description,
250+
prob=prob,
251+
dt_list=dt_list,
252+
hook_class=do_nothing,
253+
custom_controller_params=custom_controller_params,
254+
)
223255
plot_order(res, ax, k)
224256

225257

226-
def plot_all_errors(ax, ks, serial, Tend_fixed=None, custom_description=None, prob=run_piline, dt_list=None,
227-
custom_controller_params=None):
258+
def plot_all_errors(
259+
ax,
260+
ks,
261+
serial,
262+
Tend_fixed=None,
263+
custom_description=None,
264+
prob=run_piline,
265+
dt_list=None,
266+
custom_controller_params=None,
267+
):
228268
for i in range(len(ks)):
229269
k = ks[i]
230-
res = multiple_runs(k=k, serial=serial, Tend_fixed=Tend_fixed, custom_description=custom_description,
231-
prob=prob, dt_list=dt_list, custom_controller_params=custom_controller_params)
270+
res = multiple_runs(
271+
k=k,
272+
serial=serial,
273+
Tend_fixed=Tend_fixed,
274+
custom_description=custom_description,
275+
prob=prob,
276+
dt_list=dt_list,
277+
custom_controller_params=custom_controller_params,
278+
)
232279

233280
# visualize results
234281
plot(res, ax, k)

0 commit comments

Comments
 (0)