Skip to content

custom_mg.build agrees on failure: the set-up phase and the per-level loop body (#874) - #1225

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/agreed-custom-mg-build-874
Nov 20, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/agreed-custom-mg-build-874

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Addresses #874: custom_mg.build, phases 1 to 3, on the mechanism of #1218. Review: H1 (review and parallel test runs on a 96-thread Linux workstation); W1 (the session that owns the convergence and integration work, and custom_mg) for the design.

What changes

CustomMGHierarchy.build now runs its body (_build_body, unchanged apart from the agreement points) inside one agreed_build("custom_mg.build") context. A rank-local exception on one rank is raised on every rank as the same CollectiveBuildError, at the next agreement point or at the build's end.

  • The error is a builder failure, so the mesh-owned path (build_transfers) retries with the RBF builder before degrading.
  • An explicit set_custom_fmg registration surfaces it, as before.

Phase 1: set-up. There is an agreement point before each collective, and one at the phase's end. The collectives are:

  • the node coordinates (_get_coords_for_basis builds a basis DM);
  • the level layouts (a DM clone);
  • the allreduced node and DOF counts, through the agreed allreduce wrapper;
  • the move check (as_built_nodes);
  • the operator check;
  • the FAC kill check.

Phase 2: the per-level loop's own body. Each level starts at an agreement point, and there is one before each collective the body makes:

  • the provenance and cell-located transfers;
  • the node-cloud builders;
  • the zero-column counts and their allreduce;
  • the FAC split;
  • the zone's node table;
  • the patch-block gather;
  • the patch allreduce.

Phase 3: the node-cloud builders' insides.

  • _agreed_node_transfer: its verdict is now fault_contact._collective_raise, the library's one verdict protocol (agreed_build: collectives that agree on failure, proved on the FAC patch split (#874) #1218), instead of an allgather of its own on the solver's communicator. It therefore pairs with an agreed_build exit or an agree() on another rank.
    • Its error carries the first failing rank's message, with that rank's number. Before, every failing rank's message was joined; no test depends on that.
  • _assemble_node_transfer: it has agreement points before its allreduce (the agreed wrapper) and before the collective createAIJ.
  • The rest: _gather_coarse_cloud's allgathers and _count_zero_columns_parallel's allreduce go through the agreed wrappers.

Not yet converted: the fault transfers (provenance, cell-located). They keep their per-site guards from #1216, which are agreement points already. The insides of those guarded blocks would be the last custom_mg.build phase.

test_0052: an agreement point (agree(), an agreed wrapper) now counts as a collective in the guard scan, because every rank must reach each one (H1's review). The scan then finds 8 under guards in _build_body:

  • 7 under pre is not None;
  • 1 under keyed or split is not None.

Both guards are the same on every rank. The accepted list now takes a key per guard, (path, function, guard text), so only these two guards in _build_body are accepted, and any other guarded agreement point there is flagged (H1's second review). A self-test plants a rank-local guard beside an accepted one, and only the planted one is flagged. The reasons:

  • pre: it walks attributes that addon_partition sets on every rank together.
  • keyed: it is the hierarchy's own fac_zone.
  • The split's condition: it comes from is_split_level, whose fault-pair dict has a key per fault on every rank, and from the allreduced FAC kill flags.
  • The split's result: it is None only on the cover gate's allreduced counts.

A separate gap, not changed here: the base scan lists comm.rank among its uniform tokens, so a guard such as if comm.rank == 0: is not reported at all, whatever it guards.

Behaviour:

  • On the mesh-owned path in parallel, a rank-local exception in build used to escape as itself, on that rank alone. It now arrives as the same CollectiveBuildError on every rank, so it is retried and then degraded with a warning, as an agreed builder failure already was.
  • An exception raised on every rank alike (a refusal by every rank) is also converted to CollectiveBuildError, chained from the original.
  • A healthy build pays one small flag allreduce per agreement point. H1 measured 63 agreements per build, equal on every rank, with cost within noise.
  • By design: a rank-local failure in the set-up phase is a builder failure too. So the mesh-owned path does one RBF rebuild that fails the same way before it degrades. One rebuild was judged cheaper than telling set-up failures from builder failures at every agreement point.
  • The node-cloud builder's error message now carries the first failing rank's message, prefixed with its rank, rather than every failing rank's messages joined.

Test

tests/parallel/test_0874_agreed_custom_mg_build_parallel.py (min_size 2) re-runs build on the hierarchy and solver of a real solve. Each case forces one failure on the last rank, at a rank-local step just after a collective has returned. It asserts that every rank raises the same CollectiveBuildError (builder_failure set), and that the agreement calls per rank are paired.

point fixture development, np 2 this branch, np 2 to 5
the first level's coordinates placed ribbon (test_1147) MPI abort same error on every rank
a coarse layout's field read placed ribbon hang (exit 124) same error on every rank
after the move check placed ribbon hang same error on every rank
at the end of the set-up phase placed ribbon hang same error on every rank
after a node-cloud transfer placed ribbon hang same error on every rank
after the zero-column count placed ribbon hang same error on every rank
after the FAC patch blocks placed ribbon hang same error on every rank
after a split pair's cell-located transfer adapt child with a fault cut in (split coarse levels) hang same error on every rank
the node-cloud builder fails on one rank (phase 3) placed ribbon passes (#886's verdict) same error on every rank, on the shared protocol
while assembling the rows (phase 3) placed ribbon hang same error on every rank
between the local CSR and createAIJ (phase 3) placed ribbon abort (exit 142) same error on every rank

A twelfth case rebuilds cleanly and checks that the transfers' sizes are unchanged and the agreement counts paired. Results: 12 passed at np 2, 3, 4 and 5, on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

Neighbours:

  • Parallel at np 2: 122 passed, 3 skipped, after phases 1 and 2. After phase 3: 108 passed, 1 skipped (test_0874 files, test_1089, test_1095, test_1101, test_1111, test_1114, test_1120, test_1131, test_1139, test_1147, test_1152, test_1176). Files after phases 1 and 2: Files: every test_0874 file, test_1064, test_1089, test_1095, test_1096, test_1101, test_1111, test_1114, test_1120, test_1131, test_1139, test_1147, test_1152, test_1173, test_1176.
  • Serial after phase 3: 81 passed, 1 skipped. After phases 1 and 2: 91 passed and 1 skipped, plus the test_0052 stale entry, now fixed (8 passed). Files: test_0052, test_1087, test_1111, test_1120, test_1176, the test_1022 files, test_1145, test_1101, test_0078.
  • scripts/check_test_coverage.py: OK.

Underworld development team with AI support from Claude Code

… loop body (#874)

CustomMGHierarchy.build now runs its body (_build_body) inside one
agreed_build context (#1218): a rank-local exception on one rank is raised on
every rank as the same CollectiveBuildError, a builder failure (which the
mesh-owned path retries with the next builder), at the next agreement point
or at the build's end.

Agreement points:
- set-up phase: before each collective (the node coordinates' basis DM, the
  level layouts, the allreduced node and DOF counts through the agreed
  wrapper, the move check, the operator check, the FAC kill check) and at the
  phase's end;
- the per-level loop's own body: each level starts at one, and one precedes
  each collective it makes (the provenance and cell-located transfers, the
  node-cloud builders, the zero-column counts and their allreduce, the FAC
  split, the zone's node table, the patch-block gather, the patch allreduce).
The transfer builders' insides keep their own guards: the next phase.

test_0052: the accepted entry for custom_mg.build is deleted, as the test asks
(the guarded collective it was accepted for is now an agreed allreduce).

Test: tests/parallel/test_0874_agreed_custom_mg_build_parallel.py, 8 forced
failures on the last rank (4 in the set-up phase, 4 in the loop body) and a
clean rebuild. Development: 7 hangs and an MPI abort at np 2. Branch: 9 passed
at np 2 to 5.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 16, 2026 17:04

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.

- _agreed_node_transfer's verdict is now fault_contact._collective_raise
  (the library's one verdict protocol) instead of an allgather of its own on
  the solver's communicator, so it pairs with an agreed_build exit or agree()
  on another rank. The error carries the first failing rank's message, with
  its rank.
- _assemble_node_transfer: agreement points before its allreduce (the agreed
  wrapper) and before the collective createAIJ.
- _gather_coarse_cloud's two allgathers and _count_zero_columns_parallel's
  allreduce go through the agreed wrappers.

Tests: three more forced failures in test_0874_agreed_custom_mg_build_parallel
(the builder on one rank; while assembling the rows; between the local CSR
and createAIJ). Development: the builder case already passed (#886's verdict),
the other two hang or abort at np 2. Branch: 12 passed at np 2 to 5;
108 np-2 and 81 serial neighbours pass.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict at 376d815 (phases 1 to 3): changes requested. The conversion behaves correctly, and I found no hang, mis-pairing or change of answer. The one requested change is in test_0052 (finding 1). Deleting the accepted entry for build hides guarded agreement points from the scan instead of covering them. The fix is small.

What I measured

item result
PR forced failures (12) 12/12 pass at np 2, 3 and 4. 12/12 pass at np 3 with an empty last rank: emptyband layout, the last rank holding 0 cells on all four levels including the placed one, so the failure is forced on the empty rank.
Two failure points of mine After fault_mg.is_split_level in the FAC section: this is after the zero-column and outside-hull agreements and before the agreement in front of the FAC split. Inside the FAC split's call arguments (_fac_cover_max): this runs after the outer agree() and before the split's own nested context, so the healthy ranks meet the failed rank's outer exit from inside the nested context. Both points pass at np 2, 3 and 4 and with the empty rank at np 3: the same CBE on every rank, with paired counts. On development both hang at np 2 (supervisor: rank 0 in allreduce).
Agreement counts, successful build 63 per build on every rank, the same over three repeated builds, at np 2, 3 and 4 and with the empty rank at np 3. Transfer sizes are unchanged across builds.
Normal FMG solve: 2-D box (Stokes, 3-level custom FMG) np 1 and 2: bitwise identical to development (same per-rank hashes), and the same velocity iterations (1 and 2). np 4: same iterations (2) and the same answer to the last 1 or 2 digits. Development itself is not bitwise reproducible at np 4: three development runs gave three different last digits, and one of them equals the branch's run exactly.
Normal FMG solve: fault case (test_1089 faulted_2d(2) split-level MG, shear_fault_solve) Custom FMG and converged on both trees. np 1 and 2: bitwise identical, and the same velocity iterations (6 and 7). np 4: 7 iterations on both, with peak slip agreeing to 2e-16 relative.
Cost, np 4, best of 3 builds (two runs each) 0.2178 / 0.2172 s on the branch against 0.2164 / 0.2170 s on development. That is under 0.5%, within noise.
N1 in a converted build I forced an all-rank builder_failure=False check (the level-0 DOF/node divisibility, made to fail on every rank via an extra DOF on rank 0) on the mesh-owned path at np 2 and 3. Only the barycentric builder is constructed, there is no RBF retry, and the build degrades to the default preconditioner, as on development. The pc_fallbacks detail now reads "custom_mg.build: CollectiveBuildError: level 0: ..." instead of "level 0: ...".
test_0052 8 passed on the head. The agreed-build rule passes on custom_mg.py without the entry, and it flags a bare comm.tompi4py().allreduce planted after _fac_patch_killed in _build_body. It also flags n_any's wrapper reverted to a bare allreduce. See finding 1 for the main rule.
Neighbours, np 2 20 custom_mg/FAC/fault-MG files: test_1017, 1089, 1095, 1101, 1103 (custom_mg empty rank), 1106, 1108, 1111, 1120, 1133, 1134, 1135, 1139, 1147, 1149, 1152, 1176 (custom_mg), 1177, and 0874_agreed_build. Both trees: 186 passed and 4 skipped (np 4 only).

Findings

  1. Medium: test_0052's main rule no longer sees the guarded collectives in build.

    • Why the entry looked stale. The deleted entry justified pre is not None as rank-uniform. It went stale only because the conversion moved the body to _build_body and replaced the direct collectives under that guard with agree() and agreed_allreduce, which the main reach-unconditionally scan does not count as collectives.

    • What the scan misses. An agreement point is a collective. A rank-varying guard around one hangs exactly as a bare allreduce would. I counted agree and agreed_* as collectives in the main scan and ran it on the head. It finds 8 in _build_body:

      • 7 under pre is not None;
      • 1 under keyed or split is not None.

      On development the same scan finds the one guarded allreduce that the entry covered.

    • Requested:

      • make is_collective recognise agree() and the agreed_* wrappers;
      • restore the entry keyed on ("utilities/custom_mg.py", "_build_body") with its reason;
      • add a reason for keyed or split is not None. The code comment already argues that the gate's verdict is collective.
  2. Low: every rank-local failure in build is labelled a builder failure. On the mesh-owned path, a set-up-phase failure that no builder change can fix triggers a full RBF rebuild before it degrades. Examples are reading coordinates, a coarse layout, or the move check. This is by design (the PR's tests assert builder_failure for all 12 points), and it costs one futile rebuild with no wrong answer. If that cost matters, the set-up phase could run under agreed_build(..., builder_failure=False) and only the per-level loop under True.

  3. Low: the error messages changed.

    • _agreed_node_transfer now reports the first failing rank's message only. Before, it joined every failing rank's message.
    • All-rank CBE checks inside build now carry the context prefix ("custom_mg.build: CollectiveBuildError: ..."), as pc_fallbacks shows.

    Both are cosmetic. A test or log grep that anchors on the start of the old message would need updating.

What was run

  • Build: the merge base is 929459a. Its compiled sources match an existing build at a7ff735 (only .py files differ), and the head changes no compiled sources. Development's or the head's Python was overlaid on that build.
  • Parallel runs: all on cores 0 to 3.
  • Not run: np 5 and above, and Open MPI.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

…s accepted with reasons (#874)

H1's review of #1225: deleting the accepted entry for build hid the
agreement points rather than covering them, since the main scan did not
count agree() or the agreed wrappers. is_collective now counts them. The scan
then finds 8 under guards in _build_body (7 under `pre is not None`, 1 under
`keyed or split is not None`); both guards are the same on every rank, and
the restored entry says why for each.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict at 7baab75: changes requested. One small change is needed in test_0052. The restored entry is still keyed on the whole function, so it hides any new rank-local guard in _build_body.

  • Test-only. The diff since 376d815 is tests/test_0052_collective_guard_scan.py only (+26/−1), and src/ is identical. test_0052: 8 passed.
  • The scan now sees the 8 agreement points. is_collective counts agree() and agreed_*. Without the entry, the main scan finds the 8 guarded agreement points in _build_body: 7 under pre is not None and 1 under keyed or split is not None.
  • 1. Medium: a planted if comm.rank == 0: agree() in _build_body is not flagged.
    • The scan sees it (guard comm.rank == 0), but test_no_collective_under_a_rank_local_guard drops every finding whose (path, function) is in ACCEPTED. With the plant in place, test_0052 still passes 8/8. I reverted the plant afterwards.
    • The same applies to a bare allreduce under that guard. The agreed-build rule does flag the bare allreduce, both under the guard and after a risky statement, so that case is caught by the other rule.
    • Since _build_body is now all of build, the blind spot is about 400 lines.
    • Requested: match ACCEPTED on (path, function, guard) for this entry, listing the two accepted guard texts, so that any other guard in _build_body still fails the test.
  • Both reasons check out by reading.
    • pre: provenance_source follows _addon_below, _addon_parent and parent. addon_partition sets these on every rank together. An empty rank gets an empty array, not None. A record failure is raised on every rank through _collective_raise and an allreduced count.
    • keyed or split is not None:
      • keyed is the hierarchy's own fac_zone.
      • is_split_level is bool(_fault_point_pairs), and collect_point_pairs sets a key for every fault name on every rank.
      • structural_on comes from _fac_patch_killed's allreduced flags.
      • split is None only on the cover gate's allreduced counts.
  • Forced failures: the PR's 12 pass at np 2 and at np 3 (run on cores 0 to 3, source unchanged from my review of 376d815).

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

…ted self-test (#874)

H1's review of #1225: keyed on (path, function), the entry for the 400-line
_build_body waved through any guarded agreement point in it. An ACCEPTED /
IN_FLIGHT key may now name the guard, (path, function, guard text), and
covers that guard only; _build_body's entry is two such keys,
`pre is not None` and `keyed or split is not None`, each with its reason.
The stale-entry check understands both key forms. A self-test plants a
rank-local guard (a local array's size) around an agree() in a _build_body
snippet beside the accepted guard: the planted one is flagged, the accepted
one is not.

The base scan classes `comm.rank == 0` as rank-uniform (it is in
UNIFORM_TOKENS), so that guard is not a finding at all; that is a separate
gap, noted in the PR.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict at d651d32: ready to merge on green from this review. The guard-keyed entries do what was asked. The rank-token gap below predates this PR, so it should go in its own follow-up rather than hold this one.

My earlier statement was correct for _build_body; the author's explanation applies only to a guard on a function parameter. I printed the raw scan findings at both 7baab75 and d651d32.

  • comm.rank is in UNIFORM_TOKENS. The scan strips it, but the leftover ==0 matches LOCAL_TOKENS.
  • In _build_body, where comm is a local name, comm.rank == 0 is therefore classed local-data and reported.
  • At 7baab75 the function-level ACCEPTED entry then dropped it, and test_0052 passed with the plant in place. At d651d32 it is reported as unexpected.
  • In a toy def f(comm, a), the same guard is classed argument (comm is a parameter) and not reported at all. That is the case the author described.

1. Medium (predates this PR): the scan treats rank guards as uniform. UNIFORM_TOKENS has listed mpi.rank and comm.rank since before this PR (it is in development's test_0052). Rank is the standard rank-varying value, yet these guards with an agreement point under them are not reported anywhere: comm.rank == 1, comm.rank, uw.mpi.rank == last, mpi.rank < 2, comm.rank == comm.size - 1, and the plant if uw.mpi.rank == uw.mpi.size - 1: agree() in _build_body.

  • comm.rank == 0 is caught only by accident, through ==0, and not when comm is a parameter.
  • The argument rule also passes comm.getRank() == 0 whenever comm is a parameter.

Suggested fix:

  • drop mpi.rank and comm.rank from UNIFORM_TOKENS;
  • add the rank forms (rank, getRank(), Get_rank()) to a token set that always counts as rank-local;
  • exempt from the argument rule any guard that reads a rank.

The rest of UNIFORM_TOKENS looks right: sizes, .dim/.cdim, .degree, .simplex, .order and __debug__. hasattr deserves a second look, since an attribute can be set on some ranks only.

Checks at d651d32:

  • The diff since 7baab75 is test-only; src/ is unchanged.
  • test_0052: 9 passed, including the new self-test.
  • In _build_body:
    • The two accepted guards (pre is not None, keyed or split is not None) still pass.
    • A planted if local_array.size: agree() is flagged.
    • A planted if comm.rank == 0: agree() is flagged (through ==0).
    • A planted if comm.rank == 1: agree() or if uw.mpi.rank == uw.mpi.size - 1: agree() is not flagged (finding 1).

Run on cores 80 to 83. Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 9bb66d2 into development Nov 20, 2026
17 of 19 checks passed
lmoresi added a commit that referenced this pull request Nov 20, 2026
The coarse-side loop in custom_mg.build calls the collective
fault_mg.as_built_nodes once per level whose coarse side moved with the
finest. It now has an agreement point in front, as the fine-side loop has
since #1225: a failure on one rank after a coarse-side check is raised on
every rank at the next level's agreement point, where it hung the others.

- test_0874_agreed_custom_mg_build_parallel: a refined triangle box whose
  top wall has risen (two fine-side and two coarse-side checks per build,
  probed serially); the failure is forced on the last rank at the first
  coarse-side check, and must be the same CollectiveBuildError on every
  rank with the agreement calls paired.
- test_1240: the iteration count is 4 serially and 5 at np 2 and 3
  (measured by the reviewer); above np 3 it is bounded by 5.
- _plex_topology: inherited_vertices is collective on the DM's
  communicator (it creates a DMPlexTransform there); the module docstring
  said every function was rank-local.

Underworld development team with AI support from Claude Code
lmoresi pushed a commit that referenced this pull request Nov 20, 2026
The always-on np 3 and np 4 runs took 3.4 minutes on shard 6, not the 20
estimated for them: on #1225's shard 4 the np 2 batches were 26.5 of the
68.6 minutes. Sharded, the batches of tests/parallel/test_*.py now alternate:
even-numbered on shard 4, odd on shard 6. The batch boundaries are the
unsharded ones, and an unsharded run still runs every batch. The comments that
carried the 20-minute figure are corrected.

Underworld development team with AI support from Claude Code
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