Coverage for pySDC/projects/soft_failure/FaultHooks.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 14:51 +0000

1from __future__ import division 

2 

3import numpy as np 

4 

5from pySDC.core.hooks import Hooks 

6 

7 

8class fault_hook(Hooks): 

9 def __init__(self): 

10 """ 

11 Initialization of fault hooks 

12 """ 

13 super(fault_hook, self).__init__() 

14 

15 self.fault_iteration = None 

16 

17 def pre_run(self, step, level_number): 

18 super(fault_hook, self).pre_run(step, level_number) 

19 

20 L = step.levels[level_number] 

21 

22 L.sweep.reset_fault_stats() 

23 

24 self.fault_iteration = np.random.randint(1, L.sweep.params.niters) 

25 

26 def pre_iteration(self, step, level_number): 

27 super(fault_hook, self).pre_iteration(step, level_number) 

28 

29 L = step.levels[level_number] 

30 

31 L.sweep.fault_iteration = self.fault_iteration == step.status.iter 

32 

33 def post_run(self, step, level_number): 

34 super(fault_hook, self).post_run(step, level_number) 

35 

36 L = step.levels[level_number] 

37 

38 self.add_to_stats( 

39 process=step.status.slot, 

40 time=L.time, 

41 level=L.level_index, 

42 iter=step.status.iter, 

43 sweep=L.status.sweep, 

44 type='fault_stats', 

45 value=L.sweep.fault_stats, 

46 )