@@ -116,22 +116,6 @@ def run(dt, problem, sweeper, use_switch_estimator, use_adaptivity, V_ref):
116116 # call main function to get things done...
117117 uend , stats = controller .run (u0 = uinit , t0 = t0 , Tend = Tend )
118118
119- Path ("data" ).mkdir (parents = True , exist_ok = True )
120- fname = 'data/battery.dat'
121- f = open (fname , 'wb' )
122- dill .dump (stats , f )
123- f .close ()
124-
125- # filter statistics by number of iterations
126- iter_counts = get_sorted (stats , type = 'niter' , recomputed = False , sortby = 'time' )
127-
128- # compute and print statistics
129- f = open ('data/battery_out.txt' , 'w' )
130- niters = np .array ([item [1 ] for item in iter_counts ])
131-
132- assert np .mean (niters ) <= 4 , "Mean number of iterations is too high, got %s" % np .mean (niters )
133- f .close ()
134-
135119 return description , stats
136120
137121
@@ -182,7 +166,6 @@ def check(cwd='./'):
182166
183167 if use_SE or use_A :
184168 restarts_sorted = np .array (get_sorted (stats , type = 'restart' , recomputed = None ))[:, 1 ]
185- print ('Restarts for dt={}: {}' .format (dt_item , np .sum (restarts_sorted )))
186169 if use_SE and not use_A :
187170 restarts_SE .append (np .sum (restarts_sorted ))
188171
@@ -342,7 +325,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
342325
343326 if problem == 'battery' :
344327 if use_switch_estimator and use_adaptivity :
345- msg = 'Error when using switch estimator and adaptivity for battery for dt={}' . format ( dt )
328+ msg = f 'Error when using switch estimator and adaptivity for battery for dt={ dt :.1e } :'
346329 if dt == 4e-2 :
347330 expected = {
348331 'cL' : 0.5525783945667581 ,
@@ -351,6 +334,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
351334 'e_em' : 6.21240694442804e-08 ,
352335 'switches' : 0.18231603298272345 ,
353336 'restarts' : 4.0 ,
337+ 'sum_niters' : 56 ,
354338 }
355339 elif dt == 4e-3 :
356340 expected = {
@@ -360,6 +344,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
360344 'e_em' : 2.5628611677319668e-08 ,
361345 'switches' : 0.18230920573953438 ,
362346 'restarts' : 3.0 ,
347+ 'sum_niters' : 48 ,
363348 }
364349
365350 got = {
@@ -369,40 +354,45 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
369354 'e_em' : data ['e_em' ][- 1 ],
370355 'switches' : data ['switches' ][- 1 ],
371356 'restarts' : data ['restarts' ],
357+ 'sum_niters' : data ['sum_niters' ],
372358 }
373359 elif use_switch_estimator and not use_adaptivity :
374- msg = 'Error when using switch estimator for battery for dt={}' . format ( dt )
360+ msg = f 'Error when using switch estimator for battery for dt={ dt :.1e } :'
375361 if dt == 4e-2 :
376362 expected = {
377363 'cL' : 0.6139093327509394 ,
378364 'vC' : 1.0010140038721593 ,
379365 'switches' : 0.1824302065533169 ,
380366 'restarts' : 1.0 ,
367+ 'sum_niters' : 48 ,
381368 }
382369 elif dt == 4e-3 :
383370 expected = {
384371 'cL' : 0.5429509935448258 ,
385372 'vC' : 1.0001158309787614 ,
386373 'switches' : 0.18232183080236553 ,
387374 'restarts' : 1.0 ,
375+ 'sum_niters' : 392 ,
388376 }
389377
390378 got = {
391379 'cL' : data ['cL' ][- 1 ],
392380 'vC' : data ['vC' ][- 1 ],
393381 'switches' : data ['switches' ][- 1 ],
394382 'restarts' : data ['restarts' ],
383+ 'sum_niters' : data ['sum_niters' ],
395384 }
396385
397386 elif not use_switch_estimator and use_adaptivity :
398- msg = 'Error when using adaptivity for battery for dt={}' . format ( dt )
387+ msg = f 'Error when using adaptivity for battery for dt={ dt :.1e } :'
399388 if dt == 4e-2 :
400389 expected = {
401390 'cL' : 0.5966289599915113 ,
402391 'vC' : 0.9923148791604984 ,
403392 'dt' : 0.03564958366355817 ,
404393 'e_em' : 6.210964231812e-08 ,
405394 'restarts' : 1.0 ,
395+ 'sum_niters' : 36 ,
406396 }
407397 elif dt == 4e-3 :
408398 expected = {
@@ -411,6 +401,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
411401 'dt' : 0.022880524075396924 ,
412402 'e_em' : 1.1130212751453428e-08 ,
413403 'restarts' : 3.0 ,
404+ 'sum_niters' : 52 ,
414405 }
415406
416407 got = {
@@ -419,11 +410,12 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
419410 'dt' : data ['dt' ][- 1 ],
420411 'e_em' : data ['e_em' ][- 1 ],
421412 'restarts' : data ['restarts' ],
413+ 'sum_niters' : data ['sum_niters' ],
422414 }
423415
424416 elif problem == 'battery_implicit' :
425417 if use_switch_estimator and use_adaptivity :
426- msg = 'Error when using switch estimator and adaptivity for battery_implicit for dt={}' . format ( dt )
418+ msg = f 'Error when using switch estimator and adaptivity for battery_implicit for dt={ dt :.1e } :'
427419 if dt == 4e-2 :
428420 expected = {
429421 'cL' : 0.6717104472882885 ,
@@ -432,6 +424,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
432424 'e_em' : 6.208836400567463e-08 ,
433425 'switches' : 0.18232158833761175 ,
434426 'restarts' : 3.0 ,
427+ 'sum_niters' : 36 ,
435428 }
436429 elif dt == 4e-3 :
437430 expected = {
@@ -441,6 +434,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
441434 'e_em' : 2.220446049250313e-16 ,
442435 'switches' : 0.18230549652342606 ,
443436 'restarts' : 4.0 ,
437+ 'sum_niters' : 44 ,
444438 }
445439
446440 got = {
@@ -450,40 +444,45 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
450444 'e_em' : data ['e_em' ][- 1 ],
451445 'switches' : data ['switches' ][- 1 ],
452446 'restarts' : data ['restarts' ],
447+ 'sum_niters' : data ['sum_niters' ],
453448 }
454449 elif use_switch_estimator and not use_adaptivity :
455- msg = 'Error when using switch estimator for battery_implicit for dt={}' . format ( dt )
450+ msg = f 'Error when using switch estimator for battery_implicit for dt={ dt :.1e } :'
456451 if dt == 4e-2 :
457452 expected = {
458453 'cL' : 0.613909968362315 ,
459454 'vC' : 1.0010140112484431 ,
460455 'switches' : 0.18243023230469263 ,
461456 'restarts' : 1.0 ,
457+ 'sum_niters' : 48 ,
462458 }
463459 elif dt == 4e-3 :
464460 expected = {
465461 'cL' : 0.5429616576526073 ,
466462 'vC' : 1.0001158454740509 ,
467463 'switches' : 0.1823218812753008 ,
468464 'restarts' : 1.0 ,
465+ 'sum_niters' : 392 ,
469466 }
470467
471468 got = {
472469 'cL' : data ['cL' ][- 1 ],
473470 'vC' : data ['vC' ][- 1 ],
474471 'switches' : data ['switches' ][- 1 ],
475472 'restarts' : data ['restarts' ],
473+ 'sum_niters' : data ['sum_niters' ],
476474 }
477475
478476 elif not use_switch_estimator and use_adaptivity :
479- msg = 'Error when using adaptivity for battery_implicit for dt={}' . format ( dt )
477+ msg = f 'Error when using adaptivity for battery_implicit for dt={ dt :.1e } :'
480478 if dt == 4e-2 :
481479 expected = {
482480 'cL' : 0.5556563012729733 ,
483481 'vC' : 0.9930947318467772 ,
484482 'dt' : 0.035507110551631804 ,
485483 'e_em' : 6.2098696185231e-08 ,
486484 'restarts' : 6.0 ,
485+ 'sum_niters' : 64 ,
487486 }
488487 elif dt == 4e-3 :
489488 expected = {
@@ -492,6 +491,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
492491 'dt' : 0.03176025170463925 ,
493492 'e_em' : 4.0386798239033794e-08 ,
494493 'restarts' : 8.0 ,
494+ 'sum_niters' : 80 ,
495495 }
496496
497497 got = {
@@ -500,6 +500,7 @@ def check_solution(stats, dt, problem, use_adaptivity, use_switch_estimator):
500500 'dt' : data ['dt' ][- 1 ],
501501 'e_em' : data ['e_em' ][- 1 ],
502502 'restarts' : data ['restarts' ],
503+ 'sum_niters' : data ['sum_niters' ],
503504 }
504505
505506 for key in expected .keys ():
0 commit comments