Skip to content

Commit 63eab10

Browse files
committed
Implemented some tests
1 parent d6c92ab commit 63eab10

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

pySDC/projects/Resilience/strategies.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def get_base_parameters(self, problem, num_procs=1):
297297
'run_Schroedinger': 150,
298298
'run_quench': 150,
299299
'run_AC': 150,
300-
'run_RBC': 500,
300+
'run_RBC': 1000,
301301
}
302302

303303
custom_description['convergence_controllers'][StopAtMaxRuntime] = {
@@ -847,7 +847,7 @@ def get_custom_description(self, problem, num_procs, *args, **kwargs):
847847
desc['level_params']['dt'] = 0.4 * desc['problem_params']['eps'] ** 2 / 8.0
848848
elif problem.__name__ == "run_RBC":
849849
desc['level_params']['dt'] = 7e-2
850-
desc['level_params']['restol'] = 1e-6
850+
desc['level_params']['restol'] = 1e-9
851851
return desc
852852

853853
def get_custom_description_for_faults(self, problem, *args, **kwargs):
@@ -856,6 +856,8 @@ def get_custom_description_for_faults(self, problem, *args, **kwargs):
856856
desc['level_params']['dt'] = 5.0
857857
elif problem.__name__ == 'run_AC':
858858
desc['level_params']['dt'] = 0.6 * desc['problem_params']['eps'] ** 2
859+
elif problem.__name__ == 'run_RBC':
860+
desc['level_params']['restol'] = 1e-6
859861
return desc
860862

861863
def get_reference_value(self, problem, key, op, num_procs=1):
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
3+
4+
@pytest.mark.mpi4py
5+
@pytest.mark.parametrize('Tend', [1.2345, 1, 4.0 / 3.0])
6+
@pytest.mark.parametrize('dt', [0.1, 1.0 / 3.0, 0.999999])
7+
def test_ReachTendExactly(Tend, dt, num_procs=1):
8+
from pySDC.projects.Resilience.RBC import ReachTendExactly
9+
from pySDC.implementations.hooks.log_solution import LogSolution
10+
from pySDC.implementations.problem_classes.Van_der_Pol_implicit import vanderpol
11+
from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit
12+
from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
13+
from pySDC.helpers.stats_helper import get_sorted
14+
import numpy as np
15+
16+
level_params = {}
17+
level_params['dt'] = dt
18+
19+
sweeper_params = {}
20+
sweeper_params['quad_type'] = 'RADAU-RIGHT'
21+
sweeper_params['num_nodes'] = 2
22+
sweeper_params['QI'] = 'LU'
23+
24+
problem_params = {
25+
'mu': 0.0,
26+
'newton_tol': 1e-1,
27+
'newton_maxiter': 9,
28+
'u0': np.array([2.0, 0.0]),
29+
'relative_tolerance': True,
30+
}
31+
32+
step_params = {}
33+
step_params['maxiter'] = 2
34+
35+
convergence_controllers = {ReachTendExactly: {'Tend': Tend}}
36+
37+
controller_params = {}
38+
controller_params['logger_level'] = 15
39+
controller_params['hook_class'] = LogSolution
40+
controller_params['mssdc_jac'] = False
41+
42+
description = {}
43+
description['problem_class'] = vanderpol
44+
description['problem_params'] = problem_params
45+
description['sweeper_class'] = generic_implicit
46+
description['sweeper_params'] = sweeper_params
47+
description['level_params'] = level_params
48+
description['step_params'] = step_params
49+
description['convergence_controllers'] = convergence_controllers
50+
51+
t0 = 0.0
52+
53+
controller = controller_nonMPI(num_procs=num_procs, controller_params=controller_params, description=description)
54+
55+
P = controller.MS[0].levels[0].prob
56+
uinit = P.u_exact(t0)
57+
58+
uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
59+
60+
u = get_sorted(stats, type='u')
61+
t_last = u[-1][0]
62+
63+
assert np.isclose(
64+
t_last, Tend, atol=1e-10
65+
), f'Expected {Tend=}, but got {t_last}, which is off by {t_last - Tend:.8e}'
66+
67+
68+
if __name__ == '__main__':
69+
test_ReachTendExactly(1.2345, 0.1)

pySDC/projects/Resilience/work_precision.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def get_forbidden_combinations(problem, strategy, **kwargs):
7272
return False
7373

7474

75+
Tends = {
76+
'run_RBC': 16,
77+
}
78+
t0s = {
79+
'run_RBC': 0.2,
80+
}
81+
82+
7583
def single_run(
7684
problem,
7785
strategy,
@@ -134,12 +142,16 @@ def single_run(
134142
}
135143
problem_args = {} if problem_args is None else problem_args
136144

145+
Tend = Tends.get(problem.__name__, None) if Tend is None else Tend
146+
t0 = t0s.get(problem.__name__, None)
147+
137148
stats, controller, crash = problem(
138149
custom_description=description,
139150
Tend=strategy.get_Tend(problem, num_procs) if Tend is None else Tend,
140151
hook_class=[LogData, LogWork, LogGlobalErrorPostRun] + hooks,
141152
custom_controller_params=controller_params,
142153
use_MPI=True,
154+
t0=t0,
143155
comm=comm_time,
144156
**problem_args,
145157
)
@@ -277,7 +289,7 @@ def record_work_precision(
277289
else:
278290
exponents = [-3, -2, -1, 0, 0.2, 0.8, 1][::-1]
279291
if problem.__name__ == 'run_RBC':
280-
exponents = [2, 1, 0, -1]
292+
exponents = [1, 0, -1, -2, -3, -4]
281293
elif param == 'dt':
282294
power = 2.0
283295
exponents = [-1, 0, 1, 2, 3][::-1]
@@ -300,7 +312,7 @@ def record_work_precision(
300312
param_range = [1.25, 2.5, 5.0, 10.0, 20.0][::-1]
301313
if problem.__name__ == 'run_RBC':
302314
if param == 'dt':
303-
param_range = [7e-2, 6e-2, 5e-2, 4e-2]
315+
param_range = [2e-1, 1e-1, 8e-2, 6e-2]
304316

305317
# run multiple times with different parameters
306318
for i in range(len(param_range)):
@@ -1621,7 +1633,7 @@ def aggregate_parallel_efficiency_plot(): # pragma: no cover
16211633
'parallel_efficiency',
16221634
'compare_strategies',
16231635
]:
1624-
# all_problems(**all_params, mode=mode)
1636+
all_problems(**all_params, mode=mode)
16251637
comm_world.Barrier()
16261638

16271639
if comm_world.rank == 0:

pySDC/tests/test_convergence_controllers/test_step_size_limiter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,17 @@ def test_step_size_limiter():
108108
assert L.status.dt_new == 0.5
109109

110110

111+
@pytest.mark.base
112+
@pytest.mark.parametrize('dt', [1 / 3, 2 / 30])
113+
def test_step_size_rounding(dt):
114+
from pySDC.implementations.convergence_controller_classes.step_size_limiter import StepSizeRounding
115+
116+
expect = {
117+
1 / 3: 0.3,
118+
2 / 30: 0.065,
119+
}
120+
assert StepSizeRounding._round_step_size(dt, 5, 1) == expect[dt]
121+
122+
111123
if __name__ == '__main__':
112124
test_step_size_slope_limiter()

0 commit comments

Comments
 (0)