Skip to content

PETSc reload reads give the field that was written, or refuse (UNFILED 48, 49) - #1310

Open
lmoresi wants to merge 2 commits into
developmentfrom
bugfix/read-checkpoint-checks-its-point-map
Open

lmoresi wants to merge 2 commits into
developmentfrom
bugfix/read-checkpoint-checks-its-point-map

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

Fixes for two findings with no issue (UNFILED 48 and 49 in the dev hub's list), both found in the review of #1297. Review: H1, the session that reviews pull requests and runs the parallel tests on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

UNFILED 48: read_checkpoint silently read the wrong field

The failure. read_checkpoint(file, data_name="T") into a second variable on the mesh that wrote the file gave the wrong field from np 2 on, with no error. Results on a box (cellSize 1/12, a P2 field of size up to about 2):

run ∫(T_read − T)², development (∫T² = 0.86) max deviation at the nodes, development this branch
np 1 0 0 0
np 2 0.387 1.58 0
np 3 0.347 1.59 0

The reviewer saw it at np 3 (0.248 with an empty rank, 0.198 without) and not at np 2; on this build it is also wrong at np 2.

The cause.

  • The point map: the default path maps the variable file's points onto the mesh through mesh.sf, the topology SF from loading the mesh's own file.
  • The variable file: it stores no topology of its own, only sections keyed to the point numbering of the DM that wrote it. That numbering is the one in the checkpoint's mesh file (<name>.mesh.<index>.h5).
  • The writing mesh: it was loaded from the gmsh cache, and its mesh.sf maps that file's numbering. From np 2 on the two differ:
    • the file's dms/uw_mesh/order equals the gmsh cache's topology/order at np 1 and not at np 2 or 3;
    • it always equals the checkpoint mesh file's.
  • What was right: a mesh rebuilt from the checkpoint, the documented route, read correctly.

The mirror fault. load_from_h5_plex_vector loads the vector as stored. It was exact on the writing mesh and wrong on a mesh rebuilt from the checkpoint (max deviation 1.58 and 1.59 at np 2 and 3).

The change.

  • The source file. _from_plexh5 tags its topology SF with the file it was loaded from, and the mesh keeps it (_sf_source_file).
  • The written files. _write_petsc_reload_file records each file a mesh writes, with its layout. _petsc_layout_token is each rank's chart, cell count and point-SF graph. Adding a variable rebuilds the DM but keeps these, and so does moving the mesh.
  • read_checkpoint compares the file's saved point order with the order in the mesh's source file. Rank 0 reads both, and the verdict is broadcast. On a mismatch:
    • the mesh that wrote the file, in the same layout on every rank (an agreed check), reads the vector back directly (same_layout);
    • any other mesh is refused, with the same RuntimeError on every rank. The message names read_timestep, the rebuilt mesh and same_layout=True.
    • When the check cannot be made (a legacy file, a mesh built from a DMPlex), the behaviour is unchanged.
  • load_from_h5_plex_vector, in parallel, goes through read_checkpoint unless this mesh wrote the file in this layout.
  • Other read paths: no other one uses the mesh's SF. read_timestep remaps by coordinates and was exact throughout.

UNFILED 49: read_timestep hung on a payload-only file

A file written with create_xdmf=False, petsc_reload=True holds no fields/ group. read_timestep's rank 0 read fields/<name> alone, to learn the field's representation, and raised KeyError. The other ranks waited in the following bcast, so it hung at np 2 and 3.

What rank 0 finds is now shared first:

  • a file with a PETSc payload for the field is read through read_checkpoint, which this PR makes safe, so the two are in one PR;
  • a file with neither raises the same error on every rank.

Test

tests/parallel/test_1302_checkpoint_reads_get_the_right_field_parallel.py, 7 cases, all checked against the written field at the nodes (max deviation < 1e-12):

case development, np 2 / 3 this branch
read_checkpoint on the writing mesh wrong field exact
read_checkpoint on the mesh rebuilt from the checkpoint exact exact
read_checkpoint on another mesh built the same way wrong field refused on every rank (np ≥ 2); exact at np 1
load_from_h5_plex_vector, writing mesh / rebuilt mesh exact / wrong field exact / exact
read_timestep of a payload-only file, into T and into U hang (124) exact

The branch passes all 7 at np 1, 2 and 3, and at np 3 with the last rank empty (a test-only shell partition). On development, 3 fail at np 2 and 3, and the payload cases hang.

Regression

All runs are on a Python overlay of this branch.

  • The 17 serial test files that use read_checkpoint, read_timestep, write_timestep, petsc_reload, load_from_h5_plex_vector or write_checkpoint: 198 passed, 1 skipped.
  • The 6 parallel files that use them: 19 passed at np 2 and 19 passed at np 3.

Underworld development team with AI support from Claude Code

…D 48)

read_checkpoint maps a variable file's points through the mesh's topology SF,
which maps from the file the mesh was loaded from. That holds for a mesh
rebuilt from the checkpoint. The mesh that wrote the file was loaded from the
gmsh cache, numbered differently from np 2 on, and a read into a second
variable on it gave the wrong field, silently. load_from_h5_plex_vector had
the mirror fault: right on the writing mesh, wrong on a rebuilt one.

- _from_plexh5 tags its topology SF with the source file; the mesh keeps it
  (_sf_source_file).
- _write_petsc_reload_file records each file a mesh writes, with its layout
  (_petsc_layout_token: chart, cell count and point-SF graph, which adding a
  variable or moving the mesh keeps).
- read_checkpoint compares the file's saved point order with the source
  file's. On a mismatch, the mesh that wrote the file in its current layout
  (agreed over the ranks) reads it back directly (same_layout); any other
  mesh is refused, on every rank, naming read_timestep and the rebuilt mesh.
- load_from_h5_plex_vector goes through read_checkpoint in parallel unless
  this mesh wrote the file in this layout.

Underworld development team with AI support from Claude Code
…(UNFILED 49)

A file written with create_xdmf=False holds no fields/ group. read_timestep's
rank 0 read fields/<name> to find the field's representation and raised
KeyError there, while the other ranks waited in the following bcast: a hang
at np 2 and 3. What rank 0 finds is now shared first. A file with a PETSc
reload payload for the field is read through read_checkpoint (whose point
map is checked since the previous commit); one with neither raises the same
error on every rank.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:45

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 insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

3 participants