Skip to content

Fix restarts so that they reproduce uninterrupted runs bit-for-bit - #422

Merged
glesur merged 6 commits into
idefix-code:developfrom
dutta-alankar:restart_fix
Nov 26, 2026
Merged

glesur merged 6 commits into
idefix-code:developfrom
dutta-alankar:restart_fix

Conversation

@dutta-alankar

@dutta-alankar dutta-alankar commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes three issues that prevented a restarted simulation from reproducing the uninterrupted one exactly.

Changes

  • Cycle count lost on restart (TimeIntegrator): ncycles was not saved in restart dumps, so a restart always started again at ncycles=0. Because the parity of ncycles sets the order of the RKL and hydro steps (Strang splitting), restarting from a dump written after an odd cycle flipped that order, and the restarted run drifted away from the uninterrupted one. The cycle count is now stored in the dump (as a double, exact up to 2^53, since dumps cannot store int64_t) and resumed on restart. Dumps written by older versions don't have this field, so the cycle count falls back to 0, which is the old behaviour.
    • -maxcycles, the final performance figure and the cycle count printed at the end still count only the cycles performed in the current run (new GetNCyclesThisRun()). GetNCycles() returns the total.
    • The log header is now also printed after a restart (it used to be printed only when ncycles == 0).
  • Uninitialised bytes in dump headers (Dump::WriteString): the bytes after the terminating null in the fixed-size header and field-name buffers were written as they were, uninitialised, so two otherwise identical dumps could differ byte for byte. Strings are now zero-padded.
  • XDMF file number reset on restart (Xdmf): xdmfFileNumber is now registered in restart dumps, as is already done for vtkFileNumber, so XDMF outputs continue numbering after a restart instead of starting again from 0.
  • Byte-identical HDF5 files in debug builds (Xdmf): by default HDF5 stores access, modification, change and birth times in every object header, so .h5 files holding identical data differ byte for byte, even between two uninterrupted runs of the same setup. h5diff compares the content and ignores these timestamps, so they are kept by default. When compiled with -DIdefix_DEBUG=ON, time tracking is turned off (H5Pset_obj_track_times(..., false)) on the file (root group), group and dataset creation property lists, so that identical data give byte-identical .h5 files. Groups are now created with H5Gcreate2 so that a group creation property list can be passed; with a size hint of 0, H5Gcreate1 already used the default list, and file sizes are unchanged. This is documented with the other effects of Idefix_DEBUG.

Validation

test/HD/thermalDiffusion with idefix-rkl.ini (HDF5 enabled), dumps and XDMF outputs every 0.01 up to t=0.2. I ran it without interruption, then restarted it from dump 3 (written after cycle 185, odd) and from dump 2 (cycle 178, even):

before this PR with this PR
later .dmp files vs uninterrupted run differ (header bytes, and fields by ~1e-13) byte-identical
XDMF numbering after restart starts again at 0 continues (4, 5, …)
.xmf files vs uninterrupted run differ byte-identical
.h5 files vs uninterrupted run differ in content identical content (h5diff); byte-identical with -DIdefix_DEBUG=ON
later .vtk files vs uninterrupted run differ (fields, from the Strang ordering flip) byte-identical
two independent uninterrupted runs .h5 files differ (timestamps only) unchanged by default; all outputs byte-identical with -DIdefix_DEBUG=ON

I repeated the VTK and dump checks on test/MHD/AmbipolarCshock3D with idefix-rkl.ini (3D MHD, RKL ambipolar diffusion, outputs every 10 up to t=100), restarting from dump 4 (cycle 913, odd) and dump 2 (cycle 504, even). All later .vtk and .dmp files are byte-identical to the uninterrupted run, and two independent uninterrupted runs are byte-identical to each other.

Without Idefix_DEBUG, the .h5 files of a restart and of the uninterrupted run differ only by the object timestamps (all 16 objects of each file, checked with h5py), and h5diff reports no difference. As a control, h5diff does report a one-ulp change in a single value of a field.

A fresh (non-restarted) run gives the same fields and HDF5 content as the current develop (the only difference is the commit hash in the version attribute). The build passes with -DIdefix_WERROR=ON, with and without -DIdefix_DEBUG=ON, and pre-commit (including cpplint) passes. The MPI-IO branch of Xdmf::Write() uses the same property lists, but I could only test serial HDF5 locally.

- TimeIntegrator: store the cycle count in restart dumps (as a double,
  exact up to 2^53) and resume it on restart. The parity of ncycles sets
  the order of the RKL and hydro steps (Strang splitting); restarting at
  ncycles=0 from a dump written after an odd cycle flipped that order and
  made the restarted run diverge from the uninterrupted one. -maxcycles,
  the final performance figure and the cycle count reported at the end
  still refer to the cycles performed in the current run, and the log
  header is now also printed after a restart.
- Dump: zero-pad strings (header, field names) up to their fixed size.
  Uninitialised bytes after the terminating null made otherwise
  identical dumps differ.
- Xdmf: store xdmfFileNumber in restart dumps, as done for vtk, so that
  xdmf outputs do not start again from 0 after a restart.
By default HDF5 stores access, modification, change and birth times in
each object header, so HDF5 files holding identical data differ byte for
byte, e.g. between a restart and the uninterrupted run, or between two
runs of the same setup. Disable time tracking on the file (root group),
group and dataset creation property lists.
@glesur

glesur commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

there's an ongoing PR to add new types to dump files, so I suggest we wait for this to be merged before merging this PR, using a dedicated int_64 type for the cycle #.

HDF5 object timestamps are useful metadata, and h5diff, which compares
the content of the files, ignores them. Record them again by default
(HDF5's own default), and only disable them when Idefix_DEBUG is on, so
that debug builds still produce byte-identical .h5 files for identical
data (e.g. a restart vs the uninterrupted run). Document this alongside
the other effects of Idefix_DEBUG.
@glesur

glesur commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for #423 to get through.

@glesur

glesur commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rebuilt this branch (213f9db) and reproduced the fix on test/HD/thermalDiffusion, restarting from dump 3 (odd cycle) and dump 2 (even cycle):

develop (3af0355) this PR
later .dmp + .vtk vs uninterrupted run 0/32 identical 32/32 byte-identical
  • Same result for both parities, so the Strang ordering is genuinely preserved: the restarted run logs cycle 200 at t=5.085072e-02 with 11 RKL stages, matching the uninterrupted run exactly.
  • Also verified: -DIdefix_DEBUG=ON gives byte-identical .h5 too; MPI (2 ranks) restart is byte-identical; xdmfFileNumber resumes (4, 5, …) without overwriting.
  • WriteString is safe: all call sites pass buffers ≥ size, and strncpy truncates without overflow.

Note: -maxcycles now counts per run, worth a changelog line;

Good to merge from my side

Register ncycles directly as int64_t instead of mirroring it in a
double. Simplify TimeIntegrator by removing the ncyclesDump mirror
and the associated static_casts.
@glesur

glesur commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Now that #423 has been merged into develop, the cycle count is stored in dumps as native int64 (DataType::Int64) instead of a double mirror.

Changes on top of the merge:

  • ncycles is registered directly with Dump::RegisterVariable(&ncycles, "ncycles") — no more double ncyclesDump mirror or static_casts in TimeIntegrator
  • On restart, the dump reader writes the int64 value straight into ncycles
  • Verified: dumps contain ncycles as type 6 (Int64), and a restart from a dump written at cycle 287 resumes at cycle 287 with GetNCyclesThisRun() counting only the new cycles

@glesur
glesur merged commit 6836060 into idefix-code:develop Nov 26, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants