Skip to content

fix(checkpoint): read_timestep uses one coordinate frame across sessions — DG0 fields no longer collapse (#269) - #398

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/dg0-read-timestep
Jul 23, 2026
Merged

lmoresi merged 1 commit into
developmentfrom
bugfix/dg0-read-timestep

Conversation

@lmoresi

@lmoresi lmoresi commented Jul 23, 2026

Copy link
Copy Markdown
Member

Closes #269.

The bug, finally isolated

MeshVariable.read_timestep() returned a silently wrong, near-constant field for the Spiegelman benchmark's DG0 variables (edot, viscosity, stress), while the HDF5 file held correct data. The issue could not isolate the trigger among its three suspects — multi-variable checkpoint, gmsh mesh, units model. A factor-matrix reproducer showed why: all eight combinations round-trip correctly within one session. The real trigger is a units-state change between the writing and the reading session:

  • MeshVariable.write() stored fields/coordinates from .coords, which is dimensional when a units model is active (the benchmark's file: coordinate extent ±1.8e6 — km-frame gmsh numbers multiplied by the 30 km scale in metres — against a mesh file storing ±60);
  • read_timestep() queried with the reading session's .coords. The failing context was post-processing/rendering — a session that never calls set_reference_quantities, so it queried in the model frame against a dimensionally-scaled cloud, and the nearest-neighbour match returned garbage. In-session reads re-applied the same scale, which is why the bug hid from every single-session reproducer.

DG0 was simply where this was visible (nearest-neighbour with no smoothing); the frame dependence affected every variable in such checkpoints.

The fix

  1. One frame, by contract. Both sides of the remap now use the model frame (coords_nd) — the same frame as the mesh-file geometry, identical in every session regardless of units state. Files written without an active units model are unchanged (the frames coincide), so existing healthy checkpoints keep reading.
  2. A loud guard for legacy corrupt files. read_timestep now compares the saved coordinate-cloud extent with the live DOF extent (collectively, so all ranks act together) and raises a RuntimeError naming the cause and the workarounds when they differ by more than 10x. Verified against the actual corrupt Spiegelman artifact: extent ratio 3e4, now refused with a clear message instead of returning a constant.

Verification

  • Factor matrix (multi-var × units × gmsh, 8 combinations): all round-trip, before and after.
  • The km-frame benchmark shape (gmsh coordinates in km numbers, 30 km reference length), written under units and read in a units-free session: wrong values before (std 8.52 written vs 0.61 read), exact after.
  • New regression tests in tests/test_0003_save_load.py: cross-session DG0 round-trip (global-statistics comparison, partition-independent) and the frame-mismatch refusal — pass at serial, np2 and np4.
  • test_0003 mesh-variable tests pass at np2; the swarm-test failure/hang in that file is the pre-existing, already-tracked Swarm.save: non-zero ranks return while rank 0 still appends metadata — immediate reopen hits HDF5 file locking (BlockingIOError) #330 (Swarm.save metadata race), unrelated to this diff.
  • Full level_1 + tier_a gate: 438 passed, 11 skipped, 1 xfail (pre-existing), 0 failures.

Found on the way

Reminder for the merge: manual issue close needed (#269) — PRs target development, so GitHub auto-close does not fire.

Underworld development team with AI support from Claude Code

… sessions (#269)

The coordinate-remap pair was frame-dependent: MeshVariable.write stored
'fields/coordinates' from .coords — DIMENSIONAL when a units model is
active — while read_timestep queried with the reading session's .coords.
Any units-state difference between the writing and reading sessions (the
reported case: a Spiegelman run with model scaling, then a units-free
post-processing session) made the nearest-neighbour match meaningless and
returned a silently wrong, near-constant DG0 field. The issue's three
suspected triggers (multi-var checkpoint, gmsh mesh, units) all round-trip
individually — the real trigger is the cross-session frame change, which
is why it could not be isolated within one session.

Both sides now use the MODEL frame (coords_nd) — identical to the
mesh-file geometry in every session, whatever the units state. A
collective frame guard compares the saved cloud extent with the live DOF
extent and raises a RuntimeError naming the legacy cause (checkpoints
written by the old writer under units carry dimensional coordinates)
instead of returning nearest-garbage — verified against the actual
corrupt Spiegelman artifact (extent ratio 3e4, now refused loudly).

Verification: 8-combo factor matrix (multi-var x units x gmsh) and the
km-frame benchmark shape all round-trip; cross-session DG0 regression and
guard tests pass serial/np2/np4; test_0003 mesh-variable tests pass at
np2 (the swarm-test failure in that file is pre-existing #330).

Closes #269

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings July 23, 2026 05:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lmoresi
lmoresi merged commit 54a4fc5 into development Jul 23, 2026
2 checks passed
@lmoresi
lmoresi deleted the bugfix/dg0-read-timestep branch July 23, 2026 05:55
@jcgraciosa jcgraciosa mentioned this pull request Sep 29, 2026
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