@@ -344,28 +344,17 @@ def _split_into_restarts(ds, variables, savepath, nxpe, nype, tind, prefix, over
344344
345345 ny_inner = ds .metadata ["ny_inner" ]
346346
347- # These variables need to be saved to restart files in addition to evolving ones
348- restart_metadata_vars = [
349- "zperiod" ,
350- "MZSUB" ,
351- "MXG" ,
352- "MYG" ,
353- "MZG" ,
354- "nx" ,
355- "ny" ,
356- "nz" ,
357- "MZ" ,
358- "NZPE" ,
359- "ixseps1" ,
360- "ixseps2" ,
361- "jyseps1_1" ,
362- "jyseps2_1" ,
363- "jyseps1_2" ,
364- "jyseps2_2" ,
365- "ny_inner" ,
366- "ZMAX" ,
367- "ZMIN" ,
368- "BOUT_VERSION" ,
347+ # These metadata variables are created by xBOUT, so should not be saved to restart
348+ # files
349+ restart_exclude_metadata_vars = [
350+ "bout_tdim" ,
351+ "bout_xdim" ,
352+ "bout_ydim" ,
353+ "bout_zdim" ,
354+ "fine_interpolation_factor" ,
355+ "is_restart" ,
356+ "keep_xboundaries" ,
357+ "keep_yboundaries" ,
369358 ]
370359
371360 if variables is None :
@@ -374,7 +363,8 @@ def _split_into_restarts(ds, variables, savepath, nxpe, nype, tind, prefix, over
374363 # variables
375364 variables = [v for v in ds if "t" in ds [v ].dims ]
376365 else :
377- # No time dimension, so just save all variables
366+ # No time dimension in Dataset, so cannot distinguish time-evolving
367+ # variables: just include all variables
378368 variables = [v for v in ds ]
379369
380370 # Add extra variables always needed
@@ -395,25 +385,28 @@ def _split_into_restarts(ds, variables, savepath, nxpe, nype, tind, prefix, over
395385 "g_13" ,
396386 "g_23" ,
397387 "J" ,
388+ "zShift" ,
398389 ]:
399- if v not in variables :
390+ if v not in variables and v in ds :
400391 variables .append (v )
401392
402393 # number of points in the domain on each processor, not including guard or boundary
403394 # points
404395 mxsub = (ds .metadata ["nx" ] - 2 * mxg ) // nxpe
405396 mysub = ds .metadata ["ny" ] // nype
406397
407- if "hist_hi" in ds .metadata :
408- hist_hi = ds .metadata ["hist_hi" ]
409- else :
410- # hist_hi represents the number of iterations before the restart. Attempt to
411- # reconstruct here
412- iteration = ds .metadata .get ("iteration" , - 1 )
398+ # hist_hi represents the number of iterations before the restart. Attempt to
399+ # reconstruct here
400+ iteration = ds .metadata .get ("iteration" , - 1 )
401+ if "t" in ds .dims :
413402 nt = ds .sizes ["t" ]
414403 hist_hi = iteration - (nt - tind )
415404 if hist_hi < 0 :
416405 hist_hi = - 1
406+ elif "hist_hi" in ds .metadata :
407+ hist_hi = ds .metadata ["hist_hi" ]
408+ else :
409+ hist_hi = - 1
417410
418411 has_second_divertor = ds .metadata ["jyseps2_1" ] != ds .metadata ["jyseps1_2" ]
419412
@@ -422,8 +415,11 @@ def _split_into_restarts(ds, variables, savepath, nxpe, nype, tind, prefix, over
422415 ds = ds .isel ({"t" : tind }).persist ()
423416 tt = ds ["t" ].values .flatten ()[0 ]
424417 else :
425- # If loaded from restart files, "tt" should be a scalar in metadata
426- tt = ds .metadata ["tt" ]
418+ if "tt" in ds .metadata :
419+ # If loaded from restart files, "tt" should be a scalar in metadata
420+ tt = ds .metadata ["tt" ]
421+ else :
422+ tt = 0.0
427423
428424 ds = _pad_x_boundaries (ds )
429425 ds = _pad_y_boundaries (ds )
@@ -448,15 +444,22 @@ def _split_into_restarts(ds, variables, savepath, nxpe, nype, tind, prefix, over
448444 data_variable .attrs = {}
449445
450446 restart_ds [v ] = data_variable
451- for v in restart_metadata_vars :
452- restart_ds [v ] = ds .metadata [v ]
447+ for v in ds .metadata :
448+ if v not in restart_exclude_metadata_vars :
449+ restart_ds [v ] = ds .metadata [v ]
450+
451+ # These variables need to be altered, because they depend on the number of
452+ # files and/or the rank of this file.
453453 restart_ds ["MXSUB" ] = mxsub
454454 restart_ds ["MYSUB" ] = mysub
455455 restart_ds ["NXPE" ] = nxpe
456456 restart_ds ["NYPE" ] = nype
457457 restart_ds ["PE_XIND" ] = xproc
458458 restart_ds ["PE_YIND" ] = yproc
459459 restart_ds ["hist_hi" ] = hist_hi
460+ restart_ds ["PE_XIND" ] = xproc
461+ restart_ds ["PE_YIND" ] = yproc
462+ restart_ds ["MYPE" ] = yproc * nxpe + xproc
460463
461464 # tt is the simulation time where the restart happens
462465 restart_ds ["tt" ] = tt
0 commit comments