@@ -163,7 +163,7 @@ def vanderpol_setup():
163163 return description , controller_params
164164
165165
166- def run_clean_simulations (type = None , f = None ):
166+ def run_clean_simulations (type = None ):
167167 """
168168 A simple code to run fault-free simulations
169169
@@ -185,10 +185,6 @@ def run_clean_simulations(type=None, f=None):
185185 t0 = 0.0
186186 Tend = description ['level_params' ]['dt' ]
187187
188- # out = '\nCLEAN RUN: Working with %s setup..' % type
189- # f.write(out + '\n')
190- # print(out)
191-
192188 # instantiate controller
193189 controller = controller_nonMPI (num_procs = 1 , controller_params = controller_params , description = description )
194190
@@ -210,14 +206,15 @@ def run_clean_simulations(type=None, f=None):
210206 return iter_counts [0 ][1 ]
211207
212208
213- def run_faulty_simulations (type = None , niters = None , f = None ):
209+ def run_faulty_simulations (type = None , niters = None , cwd = '' ):
214210 """
215211 A simple program to run faulty simulations
216212
217213 Args:
218214 type (str): setup type
219215 niters (int): number of iterations in clean run
220216 f: file handler
217+ cwd (str): current workind directory
221218 """
222219
223220 if type == 'diffusion' :
@@ -233,11 +230,7 @@ def run_faulty_simulations(type=None, niters=None, f=None):
233230 t0 = 0.0
234231 Tend = description ['level_params' ]['dt' ]
235232
236- out = '\n FAULTY RUN: Working with %s setup..' % type
237- f .write (out + '\n ' )
238- print (out )
239-
240- filehandle_injections = open ('dump_injections_' + type + '.txt' , 'w' )
233+ filehandle_injections = open (cwd + 'data/dump_injections_' + type + '.txt' , 'w' )
241234
242235 controller_params ['hook_class' ] = fault_hook
243236 description ['sweeper_params' ]['allow_fault_correction' ] = True
@@ -262,10 +255,13 @@ def run_faulty_simulations(type=None, niters=None, f=None):
262255
263256 filehandle_injections .close ()
264257
265- dill .dump (results , open ("results_" + type + ".pkl" , "wb" ))
258+ dill .dump (results , open (cwd + "data/results_" + type + ".pkl" , "wb" ))
259+
266260
261+ def process_statistics (type = None , cwd = '' ):
262+
263+ results = dill .load (open (cwd + "data/results_" + type + ".pkl" , "rb" ))
267264
268- def process_statistics (type = None , results = None ):
269265 # get minimal length of residual vector
270266 minlen = 1000
271267 nruns = 0
@@ -314,7 +310,7 @@ def process_statistics(type=None, results=None):
314310
315311 # call helper routine to produce residual plot
316312 # fname = 'residuals.png'
317- fname = type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'residuals.png'
313+ fname = cwd + 'data/' + type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'residuals.png'
318314 show_residual_across_simulation (stats = stats , fname = fname )
319315 meanres /= nruns
320316 # print(minres)
@@ -327,7 +323,7 @@ def process_statistics(type=None, results=None):
327323 # print(medianres)
328324 # call helper routine to produce residual plot of minres, maxres, meanres and medianres
329325 # fname = 'min_max_residuals.png'
330- fname = type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'min_max_residuals.png'
326+ fname = cwd + 'data/' + type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'min_max_residuals.png'
331327 show_min_max_residual_across_simulation (stats = stats , fname = fname , minres = minres , maxres = maxres , meanres = meanres ,
332328 medianres = medianres , maxiter = minlen )
333329
@@ -340,7 +336,7 @@ def process_statistics(type=None, results=None):
340336 # print(maxiter)
341337 # call helper routine to produce histogram of maxiter
342338 # fname = 'iter_hist.png'
343- fname = type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'iter_hist.png'
339+ fname = cwd + 'data/' + type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'iter_hist.png'
344340 show_iter_hist (stats = stats , fname = fname , maxiter = maxiter , nruns = nruns )
345341
346342 # initialize sum of nfaults_detected
@@ -360,7 +356,7 @@ def process_statistics(type=None, results=None):
360356 nfm += fault_stats .nfaults_missed
361357 nfpc += fault_stats .nfalse_positives_in_correction
362358
363- g = open (type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'Statistics.txt' , 'w' )
359+ g = open (cwd + 'data/' + type + '_' + str (nruns ) + '_' + 'runs' + '_' + 'Statistics.txt' , 'w' )
364360 out = 'Type: ' + type + ' ' + str (nruns ) + ' runs'
365361 g .write (out + '\n ' )
366362 # detector metrics (Sloan, Kumar, Bronevetsky 2012)
@@ -392,27 +388,21 @@ def process_statistics(type=None, results=None):
392388
393389
394390def main ():
395- f = open ('generate_statistics.txt' , 'w' )
396391
397392 # type = 'diffusion'
398- # niters = run_clean_simulations(type=type, f=f)
399- # run_faulty_simulations(type=type, niters=niters, f=f)
400- # results = dill.load(open("results_" + type + ".pkl", "rb"))
401- # process_statistics(type=type, results=results)
402- #
393+ # niters = run_clean_simulations(type=type)
394+ # run_faulty_simulations(type=type, niters=niters)
395+ # process_statistics(type=type)
396+
403397 # type = 'reaction'
404- # niters = run_clean_simulations(type=type, f=f)
405- # run_faulty_simulations(type=type, niters=niters, f=f)
406- # results = dill.load(open("results_" + type + ".pkl", "rb"))
407- # process_statistics(type=type, results=results)
398+ # niters = run_clean_simulations(type=type)
399+ # run_faulty_simulations(type=type, niters=niters)
400+ # process_statistics(type=type)
408401
409402 type = 'vanderpol'
410- niters = run_clean_simulations (type = type , f = f )
411- run_faulty_simulations (type = type , niters = niters , f = f )
412- results = dill .load (open ("results_" + type + ".pkl" , "rb" ))
413- process_statistics (type = type , results = results )
414-
415- f .close ()
403+ niters = run_clean_simulations (type = type )
404+ run_faulty_simulations (type = type , niters = niters )
405+ process_statistics (type = type )
416406
417407
418408if __name__ == "__main__" :
0 commit comments