|
1 | 1 | import numpy as np |
2 | | -import pySDC.core.PFASST_stepwise as mp |
3 | | -import pySDC.helpers.fault_tolerance as ft |
4 | | -from pySDC.core.Stats import grep_stats |
5 | | -from pySDC.core.datatype_classes.fenics_mesh import fenics_mesh |
6 | | -from pySDC.core.sweeper_classes.generic_LU import generic_LU |
7 | 2 |
|
8 | | -from examples.fenics_grayscott.TransferClass import mesh_to_mesh_fenics |
9 | | -from pySDC.core import CollocationClasses as collclass |
10 | | -from pySDC.core import Log |
11 | | -from pySDC.implementations.problem_classes.ProblemClass import fenics_grayscott |
| 3 | +import projects.node_failure.emulate_hard_faults as ft |
| 4 | +from projects.node_failure.allinclusive_classic_nonMPI_hard_faults import allinclusive_classic_nonMPI_hard_faults |
| 5 | +from pySDC.helpers.stats_helper import filter_stats, sort_stats |
| 6 | +from pySDC.implementations.collocation_classes.gauss_radau_right import CollGaussRadau_Right |
| 7 | +from pySDC.implementations.sweeper_classes.generic_LU import generic_LU |
| 8 | +from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh |
| 9 | +from pySDC.implementations.transfer_classes.TransferFenicsMesh import mesh_to_mesh_fenics |
| 10 | +from pySDC.implementations.problem_classes.GrayScott_1D_FEniCS_implicit import fenics_grayscott |
12 | 11 |
|
13 | 12 |
|
14 | | -if __name__ == "__main__": |
15 | | - |
16 | | - # set global logger (remove this if you do not want the output at all) |
17 | | - logger = Log.setup_custom_logger('root') |
| 13 | +# noinspection PyShadowingNames,PyShadowingBuiltins |
| 14 | +def main(ft_strategies): |
| 15 | + """ |
| 16 | + This routine generates the heatmaps showing the residual for node failures at different steps and iterations |
| 17 | + """ |
18 | 18 |
|
19 | 19 | num_procs = 32 |
20 | 20 |
|
21 | | - # assert num_procs == 1,'turn on predictor!' |
22 | | - |
23 | | - # This comes as read-in for the level class |
24 | | - lparams = {} |
25 | | - lparams['restol'] = 1E-07 |
26 | | - |
27 | | - sparams = {} |
28 | | - sparams['maxiter'] = 50 |
29 | | - sparams['fine_comm'] = True |
30 | | - |
31 | | - # This comes as read-in for the problem class |
32 | | - pparams = {} |
33 | | - # pparams['Du'] = 1.0 |
34 | | - # pparams['Dv'] = 0.01 |
35 | | - # pparams['A'] = 0.01 |
36 | | - # pparams['B'] = 0.10 |
| 21 | + # setup parameters "in time" |
| 22 | + t0 = 0 |
| 23 | + dt = 2.0 |
| 24 | + Tend = 1280.0 |
| 25 | + Nsteps = int((Tend-t0)/dt) |
| 26 | + |
| 27 | + # initialize level parameters |
| 28 | + level_params = dict() |
| 29 | + level_params['restol'] = 1E-07 |
| 30 | + level_params['dt'] = dt |
| 31 | + |
| 32 | + # initialize step parameters |
| 33 | + step_params = dict() |
| 34 | + step_params['maxiter'] = 50 |
| 35 | + |
| 36 | + # initialize space transfer parameters |
| 37 | + space_transfer_params = dict() |
| 38 | + space_transfer_params['finter'] = True |
| 39 | + |
| 40 | + # initialize sweeper parameters |
| 41 | + sweeper_params = dict() |
| 42 | + sweeper_params['collocation_class'] = CollGaussRadau_Right |
| 43 | + sweeper_params['num_nodes'] = [3] |
| 44 | + sweeper_params['QI'] = 'LU' |
| 45 | + |
| 46 | + # initialize controller parameters |
| 47 | + controller_params = dict() |
| 48 | + controller_params['logger_level'] = 20 |
| 49 | + |
| 50 | + # initialize problem parameters |
| 51 | + problem_params = dict() |
| 52 | + # problem_params['Du'] = 1.0 |
| 53 | + # problem_params['Dv'] = 0.01 |
| 54 | + # problem_params['A'] = 0.01 |
| 55 | + # problem_params['B'] = 0.10 |
37 | 56 | # splitting pulses until steady state |
38 | | - # pparams['Du'] = 1.0 |
39 | | - # pparams['Dv'] = 0.01 |
40 | | - # pparams['A'] = 0.02 |
41 | | - # pparams['B'] = 0.079 |
| 57 | + # problem_params['Du'] = 1.0 |
| 58 | + # problem_params['Dv'] = 0.01 |
| 59 | + # problem_params['A'] = 0.02 |
| 60 | + # problem_params['B'] = 0.079 |
42 | 61 | # splitting pulses until steady state |
43 | | - pparams['Du'] = 1.0 |
44 | | - pparams['Dv'] = 0.01 |
45 | | - pparams['A'] = 0.09 |
46 | | - pparams['B'] = 0.086 |
47 | | - |
48 | | - pparams['t0'] = 0.0 # ugly, but necessary to set up ProblemClass |
49 | | - # pparams['c_nvars'] = [(16,16)] |
50 | | - pparams['c_nvars'] = [512] |
51 | | - pparams['family'] = 'CG' |
52 | | - pparams['order'] = [4] |
53 | | - pparams['refinements'] = [1,0] |
54 | | - |
55 | | - |
56 | | - # This comes as read-in for the transfer operations |
57 | | - tparams = {} |
58 | | - tparams['finter'] = True |
59 | | - |
60 | | - # Fill description dictionary for easy hierarchy creation |
61 | | - description = {} |
62 | | - description['problem_class'] = fenics_grayscott |
63 | | - description['problem_params'] = pparams |
64 | | - description['dtype_u'] = fenics_mesh |
65 | | - description['dtype_f'] = fenics_mesh |
66 | | - description['collocation_class'] = collclass.CollGaussRadau_Right |
67 | | - description['num_nodes'] = 3 |
68 | | - description['sweeper_class'] = generic_LU |
69 | | - description['level_params'] = lparams |
70 | | - description['transfer_class'] = mesh_to_mesh_fenics |
71 | | - description['transfer_params'] = tparams |
72 | | - # description['hook_class'] = fenics_output |
| 62 | + problem_params['Du'] = 1.0 |
| 63 | + problem_params['Dv'] = 0.01 |
| 64 | + problem_params['A'] = 0.09 |
| 65 | + problem_params['B'] = 0.086 |
| 66 | + |
| 67 | + problem_params['t0'] = t0 # ugly, but necessary to set up ProblemClass |
| 68 | + problem_params['c_nvars'] = [256] |
| 69 | + problem_params['family'] = 'CG' |
| 70 | + problem_params['order'] = [4] |
| 71 | + problem_params['refinements'] = [1, 0] |
| 72 | + |
| 73 | + # fill description dictionary for easy step instantiation |
| 74 | + description = dict() |
| 75 | + description['problem_class'] = fenics_grayscott # pass problem class |
| 76 | + description['problem_params'] = problem_params # pass problem parameters |
| 77 | + description['dtype_u'] = fenics_mesh # pass data type for u |
| 78 | + description['dtype_f'] = fenics_mesh # pass data type for f |
| 79 | + description['sweeper_class'] = generic_LU # pass sweeper (see part B) |
| 80 | + description['sweeper_params'] = sweeper_params # pass sweeper parameters |
| 81 | + description['level_params'] = level_params # pass level parameters |
| 82 | + description['step_params'] = step_params # pass step parameters |
| 83 | + description['space_transfer_class'] = mesh_to_mesh_fenics # pass spatial transfer class |
| 84 | + description['space_transfer_params'] = space_transfer_params # pass paramters for spatial transfer |
73 | 85 |
|
74 | 86 | ft.hard_random = 0.03 |
75 | 87 |
|
76 | | - # strategies = ['NOFAULT'] |
77 | | - # strategies = ['SPREAD','INTERP','INTERP_PREDICT','SPREAD_PREDICT'] |
78 | | - strategies = ['INTERP', 'INTERP_PREDICT'] |
| 88 | + controller = allinclusive_classic_nonMPI_hard_faults(num_procs=num_procs, |
| 89 | + controller_params=controller_params, |
| 90 | + description=description) |
| 91 | + |
| 92 | + # get initial values on finest level |
| 93 | + P = controller.MS[0].levels[0].prob |
| 94 | + uinit = P.u_exact(t0) |
79 | 95 |
|
80 | | - for strategy in strategies: |
| 96 | + for strategy in ft_strategies: |
81 | 97 |
|
82 | | - print('------------------------------------------ working on strategy ',strategy) |
| 98 | + print('------------------------------------------ working on strategy ', strategy) |
83 | 99 | ft.strategy = strategy |
84 | 100 |
|
85 | 101 | # read in reference data from clean run, will provide reproducable locations for faults |
86 | | - if not strategy is 'NOFAULT': |
87 | | - reffile = np.load('PFASST_GRAYSCOTT_stats_hf_NOFAULT_P32.npz') |
| 102 | + if strategy is not 'NOFAULT': |
| 103 | + reffile = np.load('data/PFASST_GRAYSCOTT_stats_hf_NOFAULT_P16.npz') |
88 | 104 | ft.refdata = reffile['hard_stats'] |
89 | 105 |
|
90 | | - # quickly generate block of steps |
91 | | - MS = mp.generate_steps(num_procs,sparams,description) |
92 | | - |
93 | | - # setup parameters "in time" |
94 | | - t0 = MS[0].levels[0].prob.t0 |
95 | | - dt = 2.0 |
96 | | - Tend = 1280.0 |
97 | | - |
98 | | - # get initial values on finest level |
99 | | - P = MS[0].levels[0].prob |
100 | | - uinit = P.u_exact(t0) |
101 | | - |
102 | 106 | # call main function to get things done... |
103 | | - uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) |
| 107 | + uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend) |
104 | 108 |
|
105 | | - # stats magic: get all residuals |
106 | | - extract_stats = grep_stats(stats,level=-1,type='residual') |
| 109 | + # get residuals of the run |
| 110 | + extract_stats = filter_stats(stats, type='residual_post_iteration') |
107 | 111 |
|
108 | | - # find boundaries |
109 | | - maxsteps = 0 |
| 112 | + # find boundaries for x-,y- and c-axis as well as arrays |
| 113 | + maxprocs = 0 |
110 | 114 | maxiter = 0 |
111 | 115 | minres = 0 |
112 | 116 | maxres = -99 |
113 | | - for k,v in extract_stats.items(): |
114 | | - maxsteps = max(maxsteps,getattr(k,'step')) |
115 | | - maxiter = max(maxiter,getattr(k,'iter')) |
116 | | - minres = min(minres,np.log10(v)) |
117 | | - maxres = max(maxres,np.log10(v)) |
118 | | - |
119 | | - # fill residual array |
120 | | - residual = np.zeros((maxiter,maxsteps+1)) |
121 | | - residual[:] = 0 |
122 | | - for k,v in extract_stats.items(): |
123 | | - step = getattr(k,'step') |
124 | | - iter = getattr(k,'iter') |
| 117 | + for k, v in extract_stats.items(): |
| 118 | + maxprocs = max(maxprocs, getattr(k, 'process')) |
| 119 | + maxiter = max(maxiter, getattr(k, 'iter')) |
| 120 | + minres = min(minres, np.log10(v)) |
| 121 | + maxres = max(maxres, np.log10(v)) |
| 122 | + |
| 123 | + # grep residuals and put into array |
| 124 | + residual = np.zeros((maxiter, maxprocs + 1)) |
| 125 | + residual[:] = -99 |
| 126 | + for k, v in extract_stats.items(): |
| 127 | + step = getattr(k, 'process') |
| 128 | + iter = getattr(k, 'iter') |
125 | 129 | if iter is not -1: |
126 | | - residual[iter-1,step] = v |
| 130 | + residual[iter - 1, step] = np.log10(v) |
127 | 131 |
|
128 | 132 | # stats magic: get niter (probably redundant with maxiter) |
129 | | - extract_stats = grep_stats(stats,iter=-1,type='niter') |
130 | | - iter_count = np.zeros(maxsteps+1) |
131 | | - for k,v in extract_stats.items(): |
132 | | - step = getattr(k,'step') |
133 | | - iter_count[step] = v |
| 133 | + extract_stats = filter_stats(stats, level=-1, type='niter') |
| 134 | + sortedlist_stats = sort_stats(extract_stats, sortby='process') |
| 135 | + iter_count = np.zeros(Nsteps) |
| 136 | + for item in sortedlist_stats: |
| 137 | + iter_count[item[0]] = item[1] |
134 | 138 | print(iter_count) |
135 | 139 |
|
136 | | - np.savez('PFASST_GRAYSCOTT_stats_hf_'+ft.strategy+'_P'+str(num_procs)+'_cN512',residual=residual,iter_count=iter_count,hard_stats=ft.hard_stats) |
| 140 | + np.savez('data/PFASST_GRAYSCOTT_stats_hf_' + ft.strategy + '_P' + str(num_procs), residual=residual, |
| 141 | + iter_count=iter_count, hard_stats=ft.hard_stats) |
| 142 | + |
| 143 | + |
| 144 | +if __name__ == "__main__": |
| 145 | + # ft_strategies = ['SPREAD', 'SPREAD_PREDICT', 'INTERP', 'INTERP_PREDICT'] |
| 146 | + ft_strategies = ['NOFAULT'] |
137 | 147 |
|
| 148 | + main(ft_strategies=ft_strategies) |
0 commit comments