@@ -338,10 +338,6 @@ def _open_model(self, ml_config: MachineLearningConfig, step: str):
338
338
def time (self ) -> cftime .DatetimeJulian :
339
339
return self ._state .time
340
340
341
- def cleanup (self ):
342
- self ._print_global_timings ()
343
- self ._fv3gfs .cleanup ()
344
-
345
341
def _step_dynamics (self ) -> Diagnostics :
346
342
self ._log_debug (f"Dynamics Step" )
347
343
self ._fv3gfs .step_dynamics ()
@@ -378,28 +374,34 @@ def _apply_physics(self) -> Diagnostics:
378
374
"total_precip_after_physics" : self ._state [TOTAL_PRECIP ],
379
375
}
380
376
381
- def _print_timing (self , name , min_val , max_val , mean_val ):
382
- self ._print (f"{ name :<30} { min_val :15.4f} { max_val :15.4f} { mean_val :15.4f} " )
383
-
384
- def _print_global_timings (self , root = 0 ):
385
- is_root = self .rank == root
386
- recvbuf = np .array (0.0 )
387
- reduced = {}
377
+ def _print_timings (self , reduced ):
388
378
self ._print ("-----------------------------------------------------------------" )
389
379
self ._print (" Reporting clock statistics from python " )
390
380
self ._print ("-----------------------------------------------------------------" )
391
381
self ._print (f"{ ' ' :<30} { 'min (s)' :>15} { 'max (s)' :>15} { 'mean (s)' :>15} " )
382
+ for name , timing in reduced .items ():
383
+ self ._print (
384
+ f"{ name :<30} { timing ['min' ]:15.4f} "
385
+ f"{ timing ['max' ]:15.4f} { timing ['mean' ]:15.4f} "
386
+ )
387
+
388
+ def log_global_timings (self , root = 0 ):
389
+ is_root = self .rank == root
390
+ recvbuf = np .array (0.0 )
391
+ reduced = {}
392
392
for name , value in self ._timer .times .items ():
393
393
reduced [name ] = {}
394
394
for label , op in [("min" , MPI .MIN ), ("max" , MPI .MAX ), ("mean" , MPI .SUM )]:
395
395
self .comm .Reduce (np .array (value ), recvbuf , op = op )
396
396
if is_root and label == "mean" :
397
397
recvbuf /= self .comm .Get_size ()
398
398
reduced [name ][label ] = recvbuf .copy ().item ()
399
- self ._print_timing (
400
- name , reduced [name ]["min" ], reduced [name ]["max" ], reduced [name ]["mean" ]
401
- )
402
- self ._log_info (f"python_timing:{ json .dumps (reduced )} " )
399
+ self ._print_timings (reduced )
400
+ log_out = {
401
+ "steps" : reduced ,
402
+ "units" : "[s], cumulative and reduced across ranks" ,
403
+ }
404
+ self ._log_info (json .dumps ({"python_timing" : log_out }))
403
405
404
406
def _step_prephysics (self ) -> Diagnostics :
405
407
@@ -529,6 +531,11 @@ def _apply_postphysics_to_dycore_state(self) -> Diagnostics:
529
531
)
530
532
return diagnostics
531
533
534
+ def _intermediate_restarts (self ) -> Diagnostics :
535
+ self ._log_info ("Saving intermediate restarts if enabled." )
536
+ self ._fv3gfs .save_intermediate_restart_if_enabled ()
537
+ return {}
538
+
532
539
def __iter__ (
533
540
self ,
534
541
) -> Iterator [Tuple [cftime .DatetimeJulian , Dict [str , xr .DataArray ]]]:
@@ -551,6 +558,7 @@ def __iter__(
551
558
),
552
559
self ._compute_postphysics ,
553
560
self .monitor ("python" , self ._apply_postphysics_to_dycore_state ),
561
+ self ._intermediate_restarts ,
554
562
]:
555
563
with self ._timer .clock (substep .__name__ ):
556
564
diagnostics .update (substep ())
0 commit comments