Skip to content

custom_mg: merge coarse unknowns sharing one sole fine image when two levels are not nested (#1101) - #1104

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/custom-mg-shared-sole-image
Nov 12, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/custom-mg-shared-sole-image

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #1101. H1: READY at a508570 / f285af2, with conditions M1 (a signed-ratio test) and M2 (this text), both done.

What and why

A coarse level and the level above it need not be nested. The transfer between such a pair is built by locating one level's nodes in the other, not derived from a refinement. That is an ordinary, legitimate configuration:

  • a placed, cut or add-on level over a base it was not refined from;
  • any level pair whose geometry differs.

In such a pair, two coarse unknowns can have the same single fine node as their only fine image. Their prolongation columns are then proportional, their Galerkin rows are too, and the coarse operator is singular. SOR's inode block over the two rows meets a zero pivot.

A mesh move under coarse levels that are not moved with it makes this more likely, and that is where it was seen: in test_1152, after #1024's mover, 4 of 8 coordinate perturbations of 1e-13 hit the zero pivot. Development also builds such levels in unperturbed test_1152 today (see Tests).

fault_mg.restrict_unreached and rotated_split_transfers now find such groups and merge them, at install.

How a group is found:

  • the search is collective;
  • only columns with at most 4 fine images are examined.

How it is merged:

  • the largest-weight column is kept, with ties going to the lowest global column so every rank keeps the same one;
  • the other columns are dropped;
  • each dropped unknown's row in the level below is folded into its kept twin's, scaled by the signed weight ratio.

The composite transfer is unchanged, so constants still reach the shared fine row at full weight. A plain drop would lose the dropped weight there. The range of P is unchanged.

The repair warns. A support of s > 1 rows shared by more than s columns is refused on every rank. With no such group, the transfers are returned untouched.

Limits, stated in the docstring and the warning: columns with wider supports, or with different supports on too few rows, are not detected. In W1's scan every group was 2 columns on 1 row.

The guard does not depend on how the pair arose, so it stays correct for non-nested pairs once moves stop being a trigger.

Tests

tests/parallel/test_1101_custom_mg_dependent_columns_parallel.py builds the configuration directly. Rank 0 owns the shared fine row and the last rank owns the two columns, so at np 2 and 3 the shared row is on another rank. The file runs serially (batch 3) and in the parallel batches.

np 1 np 2 np 3
this branch 6 passed 6 passed 6 passed
development 3 failed; the 3-level PCMG solve gives -11 (PC failed, zero pivot) the same the same
drop only (no fold) only the test of the composite transfer fails
fold without the ratio's sign (abs) only the opposite-sign composite test fails the same the same

Perturbed test_1152 (1e-13): all 8 seeds pass, and the repair fires in each. On f8c6014, 4 of 8 fail.

Existing tests, from H1's review:

  • the repair is bit-identical on 50 of 51 serial custom-MG files, 29 at np 2 and 16 at np 4;
  • it fires on unperturbed test_1152 on hyperion: serial [zone] at every move, serial [split], and np 4 [zone]. The iteration counts are equal.

So development already builds rank-deficient coarse levels in test_1152. SOR survives them on that CPU, and on some other inputs, or with another rounding, it meets the zero pivot (4 of 8 perturbed seeds). With the guard those levels are repaired; everywhere else the same Mats come back.

Development (01b06c9) is merged in, so this branch's CI should show test_1152 [zone] green with the guard.

Checklist

  • Style Charter followed (S2)
  • No drive-by changes (S9)
  • Regression test written first, with level_1 / tier_b markers (S8)
  • No hedging names or commented-out code (S3, S4)
  • No exception swallows
  • No new data access
  • Parallel: np 2 and 3 checked, with the shared row on another rank (S11)
  • No dependency changes
  • AI attribution below

Underworld development team with AI support from Claude Code

🤖 Generated with Claude Code

When the fine level moves far from coarse levels that did not move with
it, two coarse unknowns can be left whose prolongation columns each have
one entry, on the same fine row. Their Galerkin rows are proportional and
the coarse operator is singular; in test_1152 (a mover after #1024) SOR's
inode block met a zero pivot on 4 of 8 1e-13 coordinate perturbations.

restrict_unreached and rotated_split_transfers now find such groups
(collectively, columns with at most 4 fine images), keep the largest-weight
column (ties to the lowest global column), drop the others, and fold each
dropped unknown's row of the level below into its kept twin's, scaled by
the signed weight ratio. The composite transfer is unchanged, so constants
still reach the shared row at full weight. The repair warns; more columns
than rows on a multi-row support is refused on every rank; with no such
group the transfers are returned untouched.

Test: the configuration built directly, the shared fine row on rank 0 and
the columns on the last rank, at np 1, 2 and 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mg-shared-sole-image

# Conflicts:
#	scripts/test.sh
Copilot AI balanced review requested due to automatic review settings November 12, 2026 09:50

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.

@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Verdict: READY at a508570 (the same library change as #1104's f285af2; the merge brings only development's changes), with two merge conditions: a signed-ratio test (M1) and a correction to the no-op claim (M2). Two items can follow in their own issue: the detection's scalability (M3) and the warning's visibility (L1).

All runs used git archive copies (runs/2026-11-12-1101/{br,base}) against the prebuilt wt-1101 and wt-dev594 envs, with PYTHONDONTWRITEBYTECODE=1, -p no:cacheprovider and --with-mpi. MPI ran under mpi_supervisor. I checked that the installed fault_mg.py matches each archive. Instrumentation was a read-only pytest plugin (plug/h1101hash.py). It wraps restrict_unreached, rotated_split_transfers, _dependent_columns, custom_mg._install_transfers and rotated_bc._build_rotated_custom_Pl, hashes each P's global CSR (layout, indices and values; also Mat type and block size), and records the last KSP and SNES iteration counts per test. Mutants went in through plug/h1101mut.py (pytest) and plug/site/sitecustomize.py (scripts). Everything here was measured unless it is marked [read].

The fix's central claim: the fold is exact (condition 5). Confirmed.

In what sense "exact". Column d of P_l is r times column k (both have a single entry on the same fine row). So:

  • dropping d leaves range(P_l) unchanged;
  • folding r times row d of P_{l-1} into row k gives P_l'·P_{l-1}' = P_l·P_{l-1};
  • every composite to a coarser level, and so every Galerkin operator below the repaired level, is unchanged;
  • the repaired level's own operator is the original with d's row and column deleted.

On test_1152 [zone] I measured this with probe_fold.py. At each install it calls the branch's restrict_unreached with the repair, then the same function with _dependent_columns forced empty (that is base's algorithm), on the same input Ps. Runs: seed 1 (a seed that fails on base) and the unperturbed fixture, moves 1 and 2.

seed 1, move 2 unperturbed, move 2
level-2 columns dropped 4 (2 nodes × 2 components) 4
composite to level 1, max abs diff vs no-repair 1.1e-16 5.6e-17
composite to level 0, max abs diff 1.1e-16 1.1e-16
level-1 Galerkin λmin, λmax (repair / none) 0.0227276 / 15.294 (agree to 1e-12 rel) 0.0227331 / 15.311 (same)
level-0 Galerkin λmin, λmax 0.0906913 / 14.539 (agree to 1e-12 rel) 0.0906958 / 14.455
PETSc's own level operators vs our composite PᵀAP 1.3e-15 to 2.2e-15 rel 1.8e-15 to 4.0e-15 rel
base columns at level 2 outside the new range 0 0
  • Level-2 conditioning (the repaired level) was not measured. The sparse shift-invert probe (probe_fold2.py) had not finished after more than 65 minutes. The evidence that level 2 is non-singular is indirect: the solve converges on all 8 seeds, and its operator is a principal submatrix of base's.
  • Non-singularity on constructed cases (collective_cases.py, 1-D Laplacian, np 1–4): λmin/λmax after repair was 1.6e-2 on the repaired level. On the coarser levels it was 2.5e-3, 9.0e-2, 2.1e-1 and 3.8e-2.
  • Composite exactness on constructed cases:
    • two-level fold with a negative ratio (case viii): composite difference 0.0;
    • three levels with drops on two consecutive levels (ix): 0.0, both warnings issued, coarsest Galerkin well conditioned.
  • A coarse column supported only on the two twins' rows (viii-b) cancels to an exact zero after the fold and is then dropped as unreached. The range is unchanged (residual 1e-15). This is correct: in base that composite column is zero, so base is singular there.

Dirichlet / split / rotated DOFs.

  • [read] Coarse spaces are BC-reduced, so Dirichlet DOFs are never columns.
  • [read] In rotated_split_transfers the level's opening/normal rows are removed from adm before detection, so a constrained unknown can never be a twin.
  • Because the dropped column is already an exact multiple of the kept one as a fine-space function, the fold imposes no tie on admissible values. It is a change of basis, not a constraint. So it is admissible on a split side too.
  • [read] The only DOF-keyed state on coarse levels is the FAC patch rows, and both install routes already discard them for any renumbered coarse level.
  • My answer to H5's question to W1: there is no case where merging is wrong and dropping is right. The plain drop (mutant "nofold") is the inexact one: composite error 0.24–0.5 in cases viii, viii-b and ix.

rotated_split_transfers is covered.

  • [read] The diff adds the same fold and drop there. The fold runs before the row restriction, in the level's full numbering, and _renumber_fold goes through adm. I checked the index bookkeeping and found it correct.
  • Measured: on the unperturbed test_1152 [zone_on_a_split_level] (serial, rotated route) the repair fires at level 2: drop [6120, 6121] → keep [1954, 1955], ratio 0.2074. The test passes, with iteration counts equal to base.

Three or more columns, and chains.

  • 3 columns on one row (case v): both extras merge into the largest-weight column; range residual 1.2e-15. Correct.
  • Not detected, and still singular (as on base, so no worse; the docstring states these limits):
    • the chain {r1}, {r1,r2}, {r2}: λmin/λmax = −1.3e-17;
    • two exactly proportional columns on two rows: λmin = 0.
  • [read] The test for "single entry" is data != 0.0, exact. A column with one O(1) weight and a 1e-17 rounding weight (barycentric weights have no cutoff) would escape detection. I did not see this; it is a residual risk.
  • [read] The refusal (RuntimeError when more than s columns share s > 1 rows) is a new hard failure where base would carry on. No test reaches it.

Findings by severity

M1 (MEDIUM, merge condition): test_1101 does not catch a dropped sign.

  • Mutants on test_1101 (6 tests), at np 1, 2 and 3:
mutant test_1101 constructed cases
none 6/6 pass —
fold disabled (drop only) caught: 1 fail (composite test) composite error 0.47 / 0.50 / 0.24
keep the smaller weight caught: 1 fail —
tie-break reversed (highest column) not caught decision changes (case iv keeps 13, not 12); composite still exact to 1e-15
ratio sign dropped (abs) not caught composite error 0.95 (viii) and 1.0 (viii-b)
  • Why the sign is missed: every twin weight in the fixture is positive. So are all 14 ratios in test_1152's real fires.
  • Signed entries are normal under rotation (cos/sin in rotated_split_transfers), and the sign is what makes the fold exact.
  • Condition: give the composite test a twin pair of opposite sign. For example, row-1 weights 0.5 and −1.0, as in my case viii, which takes abs() from an exact match to a 0.95 error.
  • The tie-break mutant is equivalent, not a gap: any deterministic key over the allgathered data is rank-uniform and exact. Its only property worth testing is determinism, which the gather already guarantees.

M2 (MEDIUM, merge condition: correct the claim): the repair is not a no-op on test_1152 itself.

  • Bit-identical elsewhere. Transfers and iteration counts are identical between branch and base on:
run files transfer lists hashed restrict_unreached / rotated_split_transfers calls fires
serial 50 of 51 custom-MG files (the H5 set plus every tests/ file that touches custom MG) 760 136 / 45 0
np 2 29 parallel files 434 71 / 26 0
np 4 16 of 18 files 328 — 0
  • At np 4, test_1017 [constrained] gave 13 iterations on the branch against 14 on base, with identical hashes. Two reruns of each gave 14/14/14/14, so this is run-to-run noise, not the change.
  • Where nothing is found, the returned Mat is the same object (out[0] is T on all ranks, np 1–4). [read] Detection only reads (getValuesCSR, a temporary Vec, allgathers): no reorder and no type or preallocation change.
  • Where the repair fires (all at coarse level 2, the background under the moved fine mesh; each pair is the two components of one node):
    • test_1152 [zone], unperturbed, serial on hyperion: at all 3 moves, for kept and fresh (6 fires). Drops [1462, 1463], [1448, 1449, 5992, 5993], [2418, 2419, 5978, 5979].
    • test_1152 [zone_on_a_split_level], serial: 2 fires (rotated route).
    • test_1152 [zone], np 4: 2 fires.
    • np 2: none.
  • So development's own test_1152 already carries rank-deficient Galerkin levels on hyperion. SOR gets through them on this CPU. The branch changes test_1152's transfers there, with equal iteration counts and both cases passing.
  • Condition: say this in the PR. "Nothing needs repair" is not the same as "base passes".

M3 (MEDIUM, follow-up, not blocking at test sizes): the detection gathers most of the level, not "a few pairs".

  • On test_1152's finest transfer, 8982–9062 of 10114 columns have at most 4 fine images (levels 0 and 1: none). A near-nested add-on level is mostly injection.
  • Every rank allgathers all of those (column, row, weight) triples and loops over them in Python.
  • Measured serial cost of _dependent_columns on a near-nested synthetic transfer:
coarse DOFs time per level per install
10k 0.03 s
100k 0.65 s
1M 5.6 s
  • The cost is not divided across ranks; each rank also holds the whole gathered array.
  • Suggested follow-up: a distributed test. Per column, count the entries and record the sole row (column-layout Vec); per fine row, count the single-image columns (row-layout Vec ADD); gather only the rows with a count of 2 or more.

L1 (LOW): the warning is rank-uniform but not once per install.

  • Emitted on rank 0 only. The count is global and every rank makes the same decision (allgathered; checked at np 1–4: other ranks emit 0).
  • It fires once per level that fires, not once per install. Case ix gave 2 warnings.
  • It goes through warnings.warn, so Python's default filter shows an identical message only once per call site. Measured: 3 identical installs printed 1 warning (warn_dedup.py). The perturbed runs, outside a catch_warnings("always"), printed 2–3 of the 6 installs.
  • So in a long MMPDE run, later fires with the same level and count are silent.
  • Suggest also recording it in solver.pc_fallbacks, as custom_mg.fac_patch is.

L2 (LOW, documented): detection limits. The chain and two-row proportional cases above, and the exact-zero test, as described under the central claim.

Collective safety (condition 2). Pass.

[read] Every collective is reached on every rank:

  • in _dependent_columns: createVecRight, assemblyBegin/End, the 2 allgathers;
  • the early return on small.size uses gathered data;
  • in _drop_dependent_columns: createSubMatrix;
  • in _renumber_fold: the allgather;
  • in _fold_rows: createAIJ, assemble, matMult. Only the off-diagonal setValue is guarded by row ownership.
  • Every branch condition comes from gathered or allreduced data.

Constructed at np 1, 2, 3 and 4 (owners verified in the output); all ranks finished with no hang:

  • (i) shared row on rank 0, d on rank 1, k on rank 2; at np 4, rank 3 owns no column;
  • (ii) row and both twins on the same rank;
  • (iii) one rank owns every fine row and another owns no columns;
  • (iv) equal |weights|, twins on ranks 0 and the last.

In every case the decision was identical on all ranks, the warning was on rank 0 only, and the composite was exact to 1e-15. For the tie, the lowest global column (12) was kept on every rank.

The regression (condition 4): test_1152 [zone], serial, fixture perturbed by 1e-13, seeds 0–7

"Pass" here means both solves converge at every move, and kept and fresh agree within the test's bounds. The probe does not check the test's iteration bound.

tree failures detail
base 594a804 4/8 seeds 1, 2, 4: DIVERGED (−11) at move 2, NaN pressure; seed 6: no result within 90 min (killed by timeout, rc 124; branch seed 6 finished in about 20 min)
branch a508570 0/8 all converged (3) at moves 1–3; the worst kept–fresh pressure difference was 5.4e-8
  • On the branch the repair fires on all 8 seeds, including the 4 that pass on base.
  • This matches H5's 4/8 against 8/8.

Neighbouring regressions (condition 7)

All pass, on both branch and base:

test np 1 np 2 np 4
test_1152 (unperturbed) 2/2 2/2 2/2
test_1139 — 9/9 9/9
test_1147 — 4/4 4/4
test_0078_rebuild_memory_rotated_fmg — 2/2 2/2
test_0078_rebuild_memory — 1/1 —
test_1101 (branch only) 6/6 6/6 6/6 (also 6/6 at np 3)
  • test_1173 could not be run. It is not on development or on this branch; its commits, such as 9a39ce6, are not ancestors of 594a804, and it needs Mesh.add_fault.
  • Totals: the 51 serial files had no failures on either tree. At np 2 the branch had 248 passed and 12 skipped; base had 236 passed and 12 skipped (the whole difference is test_1101, whose 6 tests are counted once per rank). At np 4, all 18 branch files passed.

Merge conditions

  1. Add an opposite-sign twin pair to test_1101's composite test, so that dropping the ratio's sign fails it (M1).
  2. In the PR text, correct "no-op where nothing needs repair": the repair fires on unperturbed test_1152 on hyperion (serial [zone] and [split], and np 4 [zone]), with the same iteration counts (M2).
  3. Optional, for a follow-up issue: distributed detection (M3), and a pc_fallbacks record or a non-deduplicated notice (L1).

Artefacts are in runs/2026-11-12-1101/: logs/ (s-, p-, q- and reg-* logs plus jsonl; probe-; cc-np.raw; mutants-test1101.txt), compare.py, probe_fold.py, collective_cases.py, cost_detect.py, warn_dedup.py, plug/.

Underworld development team with AI support from Claude Code

The fold scales the dropped row by the signed weight ratio. With every
fixture weight positive, dropping the sign (abs) went uncaught; the
negative twin fails it at np 1, 2 and 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lmoresi lmoresi changed the title custom_mg: merge coarse unknowns sharing one sole fine image (#1101) custom_mg: merge coarse unknowns sharing one sole fine image when two levels are not nested (#1101) Nov 12, 2026
@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

PR #1104 at c65d816: M1 is in

c65d816 changes only test_1101_custom_mg_dependent_columns_parallel.py. The composite test is now parametrized with an opposite-signed twin (dropped_weight 0.5 and −0.5). I ran it on the a508570 build, since the library is unchanged, with the tests taken from c65d816.

  • Unmutated: 7 passed on every rank at np 1, 2 and 3.
  • abs-ratio mutant (ratio.append(abs(...))): 1 failed, 6 passed on every rank at np 1, 2 and 3. The failure is test_the_composite_coarse_functions_are_unchanged[-0.5], so the mutant is now caught.

Logs: runs/2026-11-12-1101/logs/c65-{none,abssign}-np{1,2,3}.log.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit cff3b01 into development Nov 12, 2026
10 checks passed
lmoresi pushed a commit that referenced this pull request Nov 12, 2026
Louis's framing (#1104): the configuration is a coarse level and the level
above it that are not nested (a placed, cut or add-on level over a base it
was not refined from; any pair whose transfer locates one level's nodes in
the other), an ordinary situation; a mesh move under unmoved coarse levels
only makes it more likely. The docstring, the warning (which names the
level and no longer suggests the mesh was moved wrongly), the refusal, the
pc_fallbacks record and the test's docstring say so; the warning test now
also checks for 'not nested'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lmoresi pushed a commit that referenced this pull request Nov 12, 2026
…hing

On a fault cut into an adapt child that moved before the cut, #1104's
guard refused groups of three coarse columns on one fine node's two
component rows (the rotated transfer mixes components): "share fewer fine
images than there are of them". The same solve converged in 6 velocity
iterations before the guard (W1). Every group with the same small support
is now reduced to as many columns as it spans: columns taken largest norm
first (ties to the lowest global column), each one the kept ones span to a
relative residual of 1e-10 dropped and written as their combination, and
the level below folded with the same coefficients, so the composite
transfer is unchanged, as in the pair case. Nothing is refused.

W1's fixture at the amplitudes he measured (0.002 to 0.015, both axes):
every case solves at np 1, 2 and 3, the 0.002 case at 6 iterations;
development's code refuses 5 of the 7. The refusal test becomes a test of
the exact reduction of three columns on two rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gthyagi pushed a commit to gthyagi/underworld3 that referenced this pull request Nov 13, 2026
…; record each repair

M3 (H1's review of underworldcode#1104). The detection gathered about 89 % of the finest
transfer's columns to every rank and grouped them in a Python loop: 9 s
per level at 1M coarse DOFs on hyperion, on every install, and Louis's
refinement 4 and 5 runs install after every move. Each entry now goes to
its column's owner (one alltoall), which finds the small columns; each
small column's support goes to the owner of its first row (a second
alltoall), which groups them with np.unique. Only the decisions are
gathered. At 1M coarse DOFs: 1.4 s serially, 0.36 s at np 4. Same
decisions, same tie-break.

L1. The warning prints once per Python session. Each install that needed
the merge is now also recorded in solver.pc_fallbacks
("custom_mg.dependent_columns", with the levels, the counts and the number
of installs so far), so a run's report shows how often it fired.

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.

3 participants