Coverage for pySDC/implementations/hooks/log_work.py: 100%
12 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-29 09:02 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-29 09:02 +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 )