Skip to content

Keep extracted boundary names consistent across MPI ranks - #856

Merged
lmoresi merged 1 commit into
underworldcode:developmentfrom
gthyagi:bugfix/submesh-boundary-names
Nov 12, 2026
Merged

lmoresi merged 1 commit into
underworldcode:developmentfrom
gthyagi:bugfix/submesh-boundary-names

Conversation

@gthyagi

@gthyagi gthyagi commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Extracting a distributed region currently builds each rank’s boundary enum from locally surviving strata. A coarse annulus mantle extraction can omit Upper on a rank with no upper-wall points. Registering the natural Stokes boundary condition then raises KeyError: Upper while other ranks enter collective solver setup.

This change selects surviving boundary names over the submesh communicator and creates empty local labels for globally retained boundaries. Candidate order is preserved, and labels absent everywhere remain excluded. It changes metadata, not mesh coordinates, partitioning or equations.

Validation: two focused regressions pass serial and on both MPI ranks, including actual region extraction and an intentionally empty local label. The fresh Gadi PETSc int32 build passed 34 serial checks and 4 checks on each of 16 MPI ranks. All four affected case1/case2 Poisson models at h=1/8 and h=1/16 completed successfully on 16 ranks after the fix; the original failures are retained. No spherical models or tests are run.

Review follow-up (29 October 2026)

Merge prerequisite: #858 must land first. Do not merge this PR independently. Its collective surface-extraction guards prevent an empty rank raising before this PR's _surviving_labels collective. The prerequisite's review follow-up is implemented in f93cadbd and passes its complete ownership/extraction file in serial and on MPI2/MPI3.

The first test is a focused helper-level test of global label survival: _surviving_labels currently uses no instance state. The second test is the public caller contract (extract_region produces identical boundary enums on every rank); future instance-state requirements should update the focused fixture rather than weaken that caller contract.

Empty PETSc index sets must be checked by truth value (if not index_set), because a NULL IS is not necessarily Python None. The reviewer found no current library defect in that audit; no unrelated caller changes are included here.

Underworld development team with AI support from Claude Code

Region filtering previously selected boundary enum members from rank-local strata. A coarse extracted annulus lost Upper on some ranks, causing KeyError in natural Stokes boundary registration while peers entered collectives. Union label presence over the DM communicator and create empty labels where globally retained boundaries have no local points. Preserve candidate order and exclude globally absent labels.

Validation: two focused regressions pass serial and on each of two MPI ranks, including actual region extraction. No equations, coordinates, partitioning or finite-element values change. Next validate the existing int32 Gadi installation gates and rerun only the four affected coarse Poisson models.
@gthyagi
gthyagi marked this pull request as ready for review October 23, 2026 07:15
@gthyagi
gthyagi requested a review from lmoresi as a code owner October 23, 2026 07:15
@gthyagi
gthyagi marked this pull request as draft October 25, 2026 15:39
@lmoresi

lmoresi commented Oct 28, 2026

Copy link
Copy Markdown
Member

Adversarial review

1. Ordering hazard with #858 — this can hang where it used to fail. The
change makes _surviving_labels collective (allgather at
discretisation_mesh.py:1966). extract_surface reaches it at :2190, but on
development the three checks above it raise rank-locally: label is None,
int(label_value) not in live_values, and the empty-stratum probe. A boundary
present globally and absent on one rank is exactly the case this PR exists for.
That rank raises, the others enter the allgather, and the job hangs instead of
failing with a traceback.

#858 is the PR that makes those checks collective
(uw.mpi.comm.allreduce(local_faces)). So land #858 first, or land the two
together
; this one alone converts a loud rank-local error into a deadlock.

2. The first test does not exercise the method as callers reach it.

uw.discretisation.Mesh._surviving_labels(None, dm, {...})

passes None for self, so it holds only while self stays unused. The
second test covers a real extract_region path. Worth saying which of the two
is the contract, so a later change that needs self does not fail in the
confusing direction.

3. A note for callers, not a defect here. The labels created on empty ranks
carry no values, so getStratumIS(value) returns a NULL IS there. Guards must
be written if not IS, not is None. The library was audited for this on
2026-10-10 and is clean, so this is a constraint the change adds for future
callers rather than a problem in it.

What we attacked and could not break: set().union(*allgather(present)) is safe
because allgather always returns one entry per rank; candidate order is
preserved by the final comprehension over candidates.items(); and names absent
everywhere stay excluded, which the second assertion of test 1 pins.

Finding 1 is a merge-order constraint, not a code change.

@gthyagi

gthyagi commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lmoresi. I have explicitly recorded #858 as a merge prerequisite in the description; this PR should not merge independently. Its collective extraction guards must be present before _surviving_labels adds another collective.

I also clarified the test contracts: the first is a focused helper-level check of global label survival, while the second exercises the public extract_region path and identical boundary enums. The helper fixture will need updating if instance state becomes required.

The NULL-IS truth-value requirement is recorded for callers. No unrelated library changes were made for that non-defect finding. The updated #858 ownership/extraction suite passes in serial and on MPI2/MPI3.

@gthyagi
gthyagi marked this pull request as ready for review October 29, 2026 12:47
@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member

Adversarial review of #856

Verdict: ready with listed changes. The library change is correct and fixes the defect. What needs changing is the test: on the old code it hangs instead of failing cleanly, and one of its assertions cannot fail. #858 has to land first.

Reviewed at head 9bf307d, merge base 0dfb734. The branch is 376 commits behind development eddab70. The patch applies with a 19-line offset. CI is green, but only against the old base.

Findings

  1. Medium. Test 1 turns a failure into a hang. dm.destroy() (test_1085_submesh_boundary_names.py:21) runs after rank-dependent asserts, so on a failure only rank 0 reaches it. Old code, np 2, 4, 8: exit 124 after 300 s of silence, with every rank stuck in _from_plexh5() in test 2. CI shares one mpirun per 6-file batch, so the rest of that batch goes down too. With the destroy removed, np 2: exit 1, clean.
  2. Medium. test_1085:16 cannot fail. dm.getLabel(absent) is not None is True, because petsc4py returns a falsy wrapper and never None. With createLabel removed, line 19 kills the job instead: exit 59 at np 2 and 4, no assertion message. It should use dm.hasLabel.
  3. Medium. The file has no level or tier marker, so the tier_a or tier_b gate cannot select it (Charter section 8; 20 of 49 files in tests/parallel share this). It has no mpi(min_size=2), and both tests pass on the old code at np 1. Test 2 asserts only rank agreement and 'Top'; the exact list is known and should be pinned: Top 12, Right 13, Left 14, Internal 15, Outer 102, All_Boundaries 1001.
  4. Low. The createLabel branch (discretisation_mesh.py:1969-1972) never fired outside the synthetic test: 0 firings on box region and nested at np 2, 4, 8, annulus region at np 1, 2, 4, 8, one-rank region at np 4, and box and annulus surfaces (with Fix MPI submesh injection across parent ownership boundaries #858) at np 2, 4, 8. The raw label list and order are identical on every rank, chart (0,0) ranks included. Charter section 5: drop it, or name the state that reaches it. The not in local_names guard is redundant either way, since createLabel is idempotent, and the branch makes a method documented as a query mutate the DM.
  5. Low. Nothing tests extract_surface through the changed method. A test can be added only once Fix MPI submesh injection across parent ownership boundaries #858 is in.

Attacks that failed

  • Collective ordering: the allgather at :1968 sits outside every branch; extract_region calls it unconditionally; the self.boundaries gate in extract_surface does not vary by rank.
  • Empty rank with a natural BC, max|u-exact| on this PR: np 1 6.1e-7, np 2 4.6e-7, np 4 7.5e-7 (nodes [0,19,18,0]), np 8 2.4e-7 (nodes [0,0,0,0,10,13,0,17]). The Top boundary integral is 1.0 at every np. development eddab70 gives KeyError: 'Top' and exit 124 at np 2, 4, 8; development plus the patch exits 0.
  • Determinism: a different PYTHONHASHSEED per rank at np 4 and 8 leaves enum and label order agreeing.
  • Region on one rank (redistribution path), holder first and last, np 2 and 4: enums agree and the solve reaches reason 3; on development the enums disagree.
  • Checkpoint: write and write_timestep exit 0 at np 2, 4, 8, with all 6 names in the metadata, where development records only {"All_Boundaries": 1001} when rank 0 is empty. That is a second defect this PR fixes.
  • Nested extraction and direct _re_extract_from_parent, np 2, 4, 8: enums and labels agree.
  • Annulus Stokes with a natural BC on Upper, np 1, 2, 4, 8: reason 3, integral of v.v 1.82575e-8 (spread 1.3e-7 relative). The old code also passes here; the box case carries the evidence.
  • Mutants: no allgather killed by the hang in finding 1; a rank-0 bcast instead of a union killed by test 2, exit 1; no createLabel killed only by the crash in finding 2.
  • Regression: test_0768, 0770, 0779, 0781: 16 passed at np 2 and 4. CI reach: the file matches tests/parallel/test_*.py.

#858 ordering

This PR alone: extract_surface('Top') raises on ranks without Top and aborts with MPI "Message truncated", exit 142, 142, 9 at np 2, 4, 8. development gives the same exit codes, so we did not reproduce a regression to a hang in this script. #858 plus this patch (3-line offset): box Top passes at np 2, 4, 8 with identical enums and empty ranks present; annulus Upper and Internal agree too.

Issues

No open issue covers this defect.

Merge conditions

  • Fix MPI submesh injection across parent ownership boundaries #858 lands first, as the PR body says.
  • Test 1 reaches dm.destroy() on every rank on failure (try/finally), and the old code then shows a clean failure.
  • test_1085:16 uses dm.hasLabel.
  • Add level and tier markers and mpi(min_size=2), and pin the exact enum list in test 2.
  • Remove the createLabel branch or justify it; at minimum drop the local_names guard.
  • Rebase on current development and get CI green there.

Not tested

The PR's 16-rank Gadi models or anything above np 8; Open MPI (MPICH only); 3-D meshes; a solver on a surface mesh; re-extraction after a real adapt; a full build of the combinations (development plus patch and #858 plus patch ran as overlays on the built packages).

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member

Finishing this PR (H5, at Louis's and C1's direction): a superseding PR from underworldcode/underworld3:bugfix/submesh-boundary-names-856. @gthyagi, your commit is kept and merged, not squashed. The branch is stacked on #1095 (your #858, completed), as this PR requires.

What changed, against H1's review of 9bf307d (2026-11-06):

  • Order. Fix MPI submesh injection across parent ownership boundaries (completes #858) #1095, with development f8c6014, is merged in, so Fix MPI submesh injection across parent ownership boundaries #858's collective extraction guards come first.
  • Finding 4: createLabel removed. _surviving_labels keeps your allgathered union, which is the fix, and no longer creates labels or mutates the DM. A filtered DM carries the parent's label list on every rank, and the branch never fired outside the synthetic test.
  • Findings 1 and 2: test 1 rewritten.
    • It builds the reachable state: the label on every rank, points on rank 0 only.
    • It checks agreement collectively and uses hasLabel.
    • It destroys its DM in finally.
  • Finding 3:
    • level, tier and mpi(min_size=2) markers added;
    • the enum pinned exactly (Top 12, Right 13, Left 14, Internal 15, Outer 102, All_Boundaries 1001), for the default partition and for the region held by one rank.
  • New tests:
  • Clean failure. On the old code, every test now fails cleanly: exit 1, 5 of 5 at np 2 and 4, with no hang. Each test checks agreement collectively before any call that would raise on some ranks only. A rank-0 broadcast instead of the union is also caught.

Results: the test file passes 5/5 at np 2, 3 and 4. The submesh files pass serially (81) and at np 2, 3 and 4 (59–61).

Underworld development team with AI support from Claude Code

lmoresi added a commit that referenced this pull request Nov 12, 2026
…names-856

Keep extracted boundary names consistent across MPI ranks (completes #856; after #1095)
@lmoresi
lmoresi merged commit f74c2e9 into underworldcode:development Nov 12, 2026
2 checks passed
gthyagi pushed a commit to gthyagi/underworld3 that referenced this pull request Nov 13, 2026
…cleanly and pin the contract

H1's review of 9bf307d (2026-11-06).

- _surviving_labels keeps the allgathered union (the fix) and no longer
  creates labels: a filtered DM carries the parent's label list on every
  rank, and the branch never fired outside the synthetic test.
- The helper test builds the reachable state (the label on every rank,
  points on rank 0 only), checks agreement on every rank, uses hasLabel,
  and destroys its DM in a finally, so a failure cannot hang the batch.
- The enum is pinned exactly, for the default partition and for the
  region on one rank.
- New: the symptom itself, a natural condition on Top for a region held
  by rank 0 alone, solved to u = y; and extract_surface on that region.
- level, tier and mpi(min_size=2) markers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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