Repository navigation
fix(checkpoint): read_timestep uses one coordinate frame across sessions — DG0 fields no longer collapse (#269) - #398
Merged
Conversation
… 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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()storedfields/coordinatesfrom.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 callsset_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
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.read_timestepnow compares the saved coordinate-cloud extent with the live DOF extent (collectively, so all ranks act together) and raises aRuntimeErrornaming 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
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_0003mesh-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.Found on the way
mesh.write()crashes for a mesh loaded directly from a.mshfile (CoordinateSystemTypeis None).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