Coverage for pySDC/implementations/hooks/log_work.py: 100%
18 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1from pySDC.core.hooks import Hooks
4class LogWork(Hooks):
5 """
6 Log the increment of all work counters in the problem between steps
7 """
9 def __init__(self):
10 """
11 Initialize the variables for the work recorded in the last step
12 """
13 super().__init__()
14 self.__work_last_step = {}
16 def pre_step(self, step, level_number):
17 """
18 Store the current values of the work counters
20 Args:
21 step (pySDC.Step.step): the current step
22 level_number (int): the current level number
24 Returns:
25 None
26 """
27 if level_number == 0:
28 self.__work_last_step[step.status.slot] = [
29 {key: step.levels[i].prob.work_counters[key].niter for key in step.levels[i].prob.work_counters.keys()}
30 for i in range(len(step.levels))
31 ]
33 def post_step(self, step, level_number):
34 """
35 Add the difference between current values of counters and their values before the iteration to the stats.
37 Args:
38 step (pySDC.Step.step): the current step
39 level_number (int): the current level number
41 Returns:
42 None
43 """
44 L = step.levels[level_number]
45 for key in self.__work_last_step[step.status.slot][level_number].keys():
46 self.add_to_stats(
47 process=step.status.slot,
48 process_sweeper=L.sweep.rank,
49 time=L.time + L.dt,
50 level=L.level_index,
51 iter=step.status.iter,
52 sweep=L.status.sweep,
53 type=f'work_{key}',
54 value=L.prob.work_counters[key].niter - self.__work_last_step[step.status.slot][level_number][key],
55 )
58class LogSDCIterations(Hooks):
59 """
60 Log the number of SDC iterations between steps.
61 You can control the name in the stats via the class attribute ``name``.
62 """
64 name = 'k'
66 def post_step(self, step, level_number):
67 super().post_step(step, level_number)
69 L = step.levels[level_number]
70 self.increment_stats(
71 process=step.status.slot,
72 process_sweeper=L.sweep.rank,
73 time=L.time + L.dt,
74 level=L.level_index,
75 iter=step.status.iter,
76 sweep=L.status.sweep,
77 type=self.name,
78 value=step.status.iter,
79 )