Skip to content

FAC patch summary: one collective record of the patch on the multigrid hierarchy - #928

Merged
lmoresi merged 4 commits into
developmentfrom
feature/mg-hierarchy-patch-summary
Nov 3, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
feature/mg-hierarchy-patch-summary

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 2, 2026

Copy link
Copy Markdown
Member

CustomMGHierarchy.level_patch_rows is rank-local, and its form differs between ranks: None, one (owned, subdomain) pair, a list of pairs, or an empty pair on a rank that holds no part of a zone. Every driver summed it with its own MPI calls. One driver looped a reduction over its own blocks, and that hung at np 4 on kaiju after its solve had finished.

Change

  • hierarchy.patch_summary holds, per level:
    • the block count;
    • the owned and subdomain rows summed over the ranks;
    • the largest block;
    • each rank's block sizes.
  • One allgather (_fac_patch_summary) makes it when the patch is installed:
    • install(), and both rotated sites after the FAC smoothers are set up;
    • on the monolithic route, after configuration.
  • build() clears it. Reading it makes no collective call.
  • The sizes are the blocks as handed to PCASM, before its overlap layer.
  • No smoother, transfer or default changes.
  • fault-split-multigrid.md documents the record.

Tests

tests/parallel/test_1133_fac_patch_summary_parallel.py (tier B; np 1 in CI's serial phase, np 2 in the MPI phase) has two cases:

  • A fault-zone strip near one wall, so that at np > 1 some ranks hold the empty pair. Every rank holds the same summary, and the coarse levels are None. At np 1 the zone has 1510 rows; at np > 1 the union of the ranks' global rows is exactly 1510.
  • test_1106's fault fixture through the rotated path. The structural rows are the recorded serial counts at every rank count.

On kaiju (Linux, PETSc 3.25.0), test_1133 passes at np 1, 2 and 4. tests/parallel at np 2 and 4, and tier A+B, show no failure beyond the development baseline.

scripts/test.sh gains a line in serial batch 4 at the same place as the #919 PR and the serial_reference PR.

No issue. Left open in this territory: #888 (whether a rank holds an empty pair at np 2 depends on the partition).

Underworld development team with AI support from Claude Code

CustomMGHierarchy.level_patch_rows is rank-local, and its form differs
between ranks (None, one (owned, subdomain) pair, or a list of pairs; an empty
pair on a rank holding no part of a zone). Every driver summed it itself with
raw MPI, and one that looped a reduction over its own blocks hung at np 4 on
kaiju after its solve had finished (the add-on matrix's row 5).

custom_mg.fac_patch_summary makes the per-level record with one allgather:
blocks, owned and subdomain rows summed over the ranks, the largest block,
and each rank's block sizes. CustomMGHierarchy.record_patch_summary stores it
as hierarchy.patch_summary, and every install route calls it with the rows it
installs: CustomMGHierarchy.install and the rotated path's two
_configure_pcmg calls. Reading it afterwards makes no collective call. No
smoother, transfer or default changes.

test_1133 (tier B, np 1/2/4):
- a fault-zone strip near one wall, so that ranks without zone cells hold
  the empty pair at np > 1: every rank holds the same summary, coarse levels
  None, and 1510 rows at np 1;
- test_1106's fault fixture through the rotated path: the structural rows
  are the recorded serial counts at any rank count, and equal the rank-local
  record summed.
Both pass serially; np 2 and 4 run on kaiju.

Underworld development team with AI support from Claude Code
…parallel

From the adversarial review of 04b7a76:
- test_1133 had no serial line in scripts/test.sh, unlike the other
  tests/parallel files without a min_size mark, so CI never ran its np 1
  baseline (1510 rows, one block); it is now in serial batch 4. At np > 1
  the zone test also asserts that the union of the ranks' global rows is
  exactly the serial 1510, not only that the summed rows are no fewer.
- The record is made after the patch is installed (install, both rotated
  _configure_pcmg sites), and its docstring and the doc say it is each
  block as handed over, before PCASM adds its overlap layer.
- The helper is private (_fac_patch_summary); the rotated sites test
  `_hier is not None` instead of hasattr.

Underworld development team with AI support from Claude Code
…uild

From the second review: the rotated route recorded the summary before the
velocity PC's set-up and the standard route after it, so a set-up that
raised left a record on one route only, and a record survived a later
failed re-install. Both rotated sites now record after the FAC smoothers
are set up, as install() does, and build() clears the previous record.
The collective recorder is private (_record_patch_summary); test_1133
carries its tier on each test.

Underworld development team with AI support from Claude Code
…cords

The monolithic (single-field) route configures PCMG without setting it up,
so the record follows configuration there and set-up on the velocity-block
routes.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 2, 2026 23:14
@lmoresi

lmoresi commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Pre-PR adversarial review

Three rounds: 04b7a76, then eed0a6c, then a final check of 35a0aac. No HIGH findings. Each finding below was fixed on the branch, except two LOWs left as they are.

Round 1

  • MEDIUM: CI never ran the file at np 1, and at np 2 the zone test checked only a lower bound (owned_rows >= 1510). Fixed in eed0a6c:
    • a serial batch 4 line;
    • at np > 1, the union of the ranks' global row ids must be exactly 1510.
  • LOW: the docstring said the record is what the smoothers carry, but the sizes come before PCASM's overlap layer. Fixed: the docstring and the doc say "before PCASM adds its overlap layer". The record also moved after the install. (The measurement knobs this finding mentioned are removed by the LU block-solver PR.)
  • LOW: the structural test repeats test_1106's fixture with a host-loose baseline (in SERIAL_PATCH_ROWS.values()). Left as is: it is the fixture the summary exists for, and the counts are test_1106's per-host records.
  • LOW: the empty-rank case is not asserted. Left as is: whether a rank is empty at np 2 depends on the partition (Fault-split integration tests: cross-partition transfer and empty-rank cases not exercised in CI #888). The test's docstring still says the strip leaves ranks with no zone cells, which is unproven.
  • LOW: a public helper outside __all__, and a hasattr guard. Fixed: _fac_patch_summary is private, and the guard tests _hier is not None.

Round 2 (eed0a6c)

  • The record count is the same on every rank. The union assertion is correct (lay.l2g rows, BC rows dropped, np.unique collapsing seam nodes).
  • LOW: the two install routes recorded on different sides of set-up, and a record survived a failed re-install. Fixed in 35a0aac: both rotated sites record after _set_up_fac_smoothers, as install() does, and build() clears the record.
  • LOW: the recorder was public. Fixed: _record_patch_summary.

Final check (35a0aac)

  • Rank symmetry between set-up and the record: nothing found.
  • No library path leaves a live PC with patch_summary is None. An explicit public build() after an install does, and so do transfers and level_patch_rows, which predates the branch.
  • LOW: on the monolithic route the record follows configuration, not set-up. Fixed in a46bf3f: the docstring says when each route records.

Attacks that failed

  • An emulated 4-rank allgather mixing a list, a pair, an empty pair and None, with ranks holding different level counts: identical JSON on every rank.
  • Install routes: inject_custom_mg, auto_inject_custom_mg and the two rotated sites. The legacy _install_transfers carries no patch.
  • Repeat solves that skip the re-install keep a summary that matches the live PC.
  • Cost: one int per block per rank. Blocks are capped at fac_block_rows, so the payload is bounded.

Issue verdicts

Underworld development team with AI support from Claude Code

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.

🟡 Changes recommended

The summary can report patch blocks that were never installed, and the tests do not cover the unequal per-rank block counts behind the reported collective hang.

2 open issues
What changed in this PR

Adds a collective FAC patch summary to the custom multigrid hierarchy so diagnostics can read global patch sizes without issuing rank-dependent collective calls.

Changes:

  • Records per-level block counts, row totals and per-rank block sizes at installation, and clears the summary on rebuild.
  • Integrates summary recording into ordinary and rotated solver paths.
  • Documents the record and adds serial/MPI regression tests with serial test-runner coverage.
File Description
tests/​parallel/​test_1133_fac_patch_summary_parallel.py Adds zone-strip and structural-patch summary tests.
src/​underworld3/​utilities/​rotated_bc.py Records summaries at both rotated installation sites.
src/​underworld3/​utilities/​custom_mg.py Implements collective aggregation and summary lifecycle management.
scripts/​test.sh Includes the new tests in serial batch 4.
docs/​developer/​subsystems/​fault-split-multigrid.md Documents summary contents and collective-free reads.

Review effort: Balanced

recorded as handed over, before PCASM adds its overlap layer at
set-up. Reading :attr:`patch_summary` afterwards makes no collective
call, so any rank can read it alone."""
self.patch_summary = _fac_patch_summary(patch_rows, comm)
centroids = np.array([base.dm.computeCellGeometryFVM(c)[1][:2]
for c in range(cS, cE)]).reshape(-1, 2)
zone = (centroids[:, 0] > 0.05) & (centroids[:, 0] < 0.2)
set_custom_fmg(stokes, levels, field_id=0, fac_zone=zone)
@lmoresi
lmoresi merged commit d9783f0 into development Nov 3, 2026
9 checks passed
lmoresi pushed a commit that referenced this pull request Nov 3, 2026
…-selection

One conflict in scripts/test.sh, adjacent batch-4 lines (test_1133 from #928,
test_1138 from this branch); both kept.

Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 3, 2026
…k solver (#929)

The cover gate's record (fac_gate) and the patch summary's reset sit side by
side at build; test.sh's batch 4 carries test_1133 and test_1134.

Underworld development team with AI support from Claude Code
lmoresi pushed a commit that referenced this pull request Nov 3, 2026
…k-919

One conflict in scripts/test.sh, adjacent batch-4 lines (test_1132 from this
branch, test_1133 from #928); both kept.

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.

2 participants