Repository navigation
FAC patch blocks factor in quotient minimum degree ordering - #1022
Conversation
The FAC patch smoother's block LU had no ordering set, so PETSc's nested dissection applied, and for a fault band's long, narrow block the fill followed the subdomain's row numbering: the same block took 3.1e9 to 2.35e10 flops to factor by rank count and build (kaiju, the add-on matrix's row 5 networks, np 4 to 16). Quotient minimum degree cuts the fill 25 to 58 times, makes it the same at any rank count, and runs the block's triangular solves 3.5 to 6 times faster and the solves 2.3 to 4 times faster, with the same iterations and slip; reverse Cuthill-McKee was worse than nested dissection. _configure_pcmg writes the ordering beside the shift, in the keys the rotated path keeps, and _set_up_fac_smoothers sets it on the live blocks. test_1090, which reads the live smoother on every install path, asserts the ordering; on development every path's blocks report "matrix ordering: nd". The fault-split and FAC test set passes (526 passed, 4 skipped, serial). Underworld development team with AI support from Claude Code
…rion's review, L1, L2) L1: setFactorOrdering in _set_up_fac_smoothers changed nothing on any path, since the blocks read the ordering from the database at the ASM's set-up, where the key still is; and set on a block that has already factored it raises PETSc error 73, so it could not have served as insurance. Removed, with the reason. test_1090 catches the key's removal on every path. L2: _configure_pcmg's docstring lists the ordering key; the note, the changelog and the comment quote the pair's own figures (8.1e9 at np 4, 2.35e10 at np 8 and 16, against qmd's 4.1e8) and say "nearly the same" across rank counts (within 9 % on hyperion). Underworld development team with AI support from Claude Code
…ering Underworld development team with AI support from Claude Code # Conflicts: # docs/developer/CHANGELOG.md
K2 found that the default overwrote an ordering set through PETSC_OPTIONS for the same key. The default is now written only where the database holds none. Underworld development team with AI support from Claude Code
Review record for #1022On 0f262b7, the head: ready to merge, with no open merge condition. The record below covers e451623. The sections at its end re-check aca58b6 and 0f262b7. Paths under Adversarial review: feature/fac-patch-lu-orderingTip reviewed: e451623 (built as
Method:
VerdictReady to merge. The ordering reaches every live FAC block on every install path we could run, at np 1, 2 and 4. On every fixture:
We reproduced the claim's direction on hyperion, at 15 to 21 times on a 30 396-row band. That is smaller than kaiju's 25 to 58 times, which came from other fixtures. The test fails on the base build as it should. There are two low findings:
We also found two defects that exist on development as well. They are near this change but not caused by it. FindingsL1 (low). The
|
| fixture, np | live fill | qmd fill |
|---|---|---|
| zone_split, 2 | 7.634e5 | 7.634e5 |
| gate160, 2 | 1.043e6 | 1.043e6 |
| zone_unsplit500, 2 | 1.135e5 | 1.135e5 |
| welded08, 1 | 1.30e5 | 1.30e5 |
The reason: _set_up_fac_smoothers calls asm.setUp() while the keys are still in the database. PCASM's block KSPs read ..._sub_pc_factor_mat_ordering_type at that point, and the rotated path drops the keys only afterwards. The same holds for the existing setType / setFactorShift lines [read].
Where the line could act, it would fail loudly rather than repair anything. On a block that has already factored with another ordering, PETSc 3.25.3 raises error 73, "Cannot change ordering after use" (logs/unit_edge.log). No current path calls it on a block that has already factored [read].
Fix, either way:
- drop the line, with the docstring sentence "Their ordering ... is set the same way";
- or keep it as a guard, and say in the docstring that the database key does the work and the test cannot see the line.
L2 (nit). Stale text
- The
_configure_pcmgdocstring still lists the returned keys as "each FAC level'spc_typeand its blocks'pc_typeand factor shift". The ordering key is now returned too. - The note in
fault-split-multigrid.mdand the CHANGELOG quote "3.1e9 to 2.35e10 flops ... by rank count", but the table's nd rows are 7.24e9 and 2.35e10. 3.1e9 is not in it, and the pair case is 2.35e10 at both np 8 and np 16. Either add the row behind 3.1e9 or name the case. - "makes it the same at any rank count" is close but not exact. On hyperion, qmd's flops on the same 30 396-row block were 3.41e8, 3.68e8 and 3.73e8 at np 1, 2 and 4 (a 9 % spread). nd's were 5.82e9, 5.69e9 and 7.91e9 (39 %).
Pre-existing on development, near this change (not merge conditions; candidates for issues)
P1. After mesh.deform, a FAC solver cannot re-solve on the standard paths. This happens on both builds, at np 1 and 2 (logs/{fac,ba3f}-np{1,2}-remesh-*.log).
- The Poisson top-level and Stokes velocity-block re-solves fail with PETSc 73: "No composite preconditioners supplied via PCCompositeAddPCType() or -pc_composite_pcs".
- Mechanism (
probe_remesh_keys.py,logs/remesh-keys-fac*.log):- The standard paths never drop their FAC keys.
Solver_N_mg_levels_2_pc_type compositeand the three block keys, the ordering key among them, stay in the database. - The PC rebuilt after the deform reads
compositeand gets no members. _pcmg_still_installedaccepts the rebuilt 3-level PCMG, so the hierarchy is not installed again.
- The standard paths never drop their FAC keys.
- With the level-2 keys dropped, the re-solve runs on whole-level SOR (
mg 3 ['sor','sor']), with no FAC level. - The rotated paths re-solve after a deform and converge, but the live velocity multigrid then has no FAC level on either build (
logs/*remesh*-rot.log). - The branch adds one more lingering key under the solver's own prefix. That key is harmless in itself.
P2. Standard-path Stokes adjoint_solve does not run the FAC smoother.
- After it, the velocity block is a 1-level
mg. - The adjoint's LU work is 9.7e3 flops, against the FAC block's 2e5.
- This is the same on both builds (
logs/*-adjoint-*.log). - The Poisson adjoint does run the qmd blocks: 3 iterations, reason 2, live fill 3101, which is qmd's.
Attack 1: coverage of the FAC paths (np 1 and 2, branch default; logs/fac-np{1,2}-*-default.log)
Every live block reported matrix ordering: qmd with live fill equal to the offline qmd fill. Base and forced-nd runs reported nd with nd's fill.
| path | how reached | live fill qmd / nd (np 1) |
|---|---|---|
options-DB, scalar top-level (no _set_up_fac_smoothers) |
test_1090 poisson |
3101 / 3551 |
| options-DB, Stokes velocity block | test_1090 stokes_plain |
1.24e4 / 1.42e4 |
| rotated saddle point, keys dropped | test_1090 stokes_rotated |
1.579e4 / 2.304e4 |
| rotated vector solve (ThinSheet), keys dropped | test_1090 sheet_rotated |
1.579e4 / 2.304e4 |
keyed fac_zone + structural block, rotated |
test_1139 split | 7.643e5 / 1.212e6 |
keyed fac_zone pieces of ≤ 500 rows, unsplit, standard |
test_1139 unsplit | 1.135e5 / 1.499e5 |
| structural block alone | test_1139 keyed=None | 8.719e5 / 1.431e6 |
| cover gate taken over the old 75 % (85 % of the level) | test_1134 160 rungs | 1.061e6 / 1.554e6 |
| welded add-on, auto-injected, width 0.08 and 1.0 (96 %) | test_1134 / fault_fixtures | 1.30e5 / 2.13e5; 2.76e6 / 5.06e6 |
set_custom_fmg again on a solved solver (plain, rotated, poisson) |
reinstall | qmd on all three, np 1 and 2 |
| second solve on the cached PC or rotated ctx | solve2 rows | qmd; symbolic count 0 (numeric refactor only) |
mesh.deform then re-solve |
remesh | no FAC blocks either way (P1) |
| adjoint | adjoint_solve |
Poisson qmd; Stokes no FAC (P2) |
The 3-D box (test_1095's split patch box) declines its FAC patch at the 3-D gate: no blocks, on either ordering (logs/fac-np1-box3d-*.log, 161 s each).
No path factors with nd.
Key hygiene.
- Rotated paths: the ordering key is dropped with the other per-solve keys (0 ordering keys left).
- Standard paths: it stays under the solver's own prefix with the other three FAC keys, as those always have (P1).
- An unrelated direct-LU Poisson solved afterwards ordered with nd at np 1. At np 2 its view has no ordering line (a parallel LU). It saw no leaked key: every leftover key carries the FAC solver's
Solver_N_prefix.
Attack 2: cost on blocks that are not long bands
Offline columns are the same block under each ordering. "In-solve MatSolve" is the whole solve's MatSolve time, max over ranks, in the forced-nd run against the default (qmd) run. Its coarse LU is the same in both.
| case | np | block rows | fill nd / qmd | LU flops nd / qmd | ratio | ord+sym+num s nd / qmd | MatSolve per apply ms nd / qmd | in-solve MatSolve s nd / qmd | vel its nd / qmd | max rel diff, v_rms or slip |
|---|---|---|---|---|---|---|---|---|---|---|
| poisson | 1 | 201 | 3.55e3 / 3.10e3 | 3.38e4 / 2.49e4 | 1.4 | 0.00073 / 0.00095 | 0.014 / 0.012 | 3.2e-4 / 2.8e-4 | 3 / 3 | 1.7e-15 |
| stokes_plain | 1 | 402 | 1.42e4 / 1.24e4 | 2.78e5 / 2.05e5 | 1.4 | 0.0019 / 0.0013 | 0.036 / 0.020 | 0.026 / 0.051 | 4 / 4 | 3.8e-16 |
| stokes_rotated | 2 | 402 | 2.18e4 / 1.62e4 | 6.81e5 / 3.38e5 | 2.0 | 0.0009 / 0.0011 | 0.017 / 0.012 | 0.028 / 0.018 | 3 / 3 | 4.8e-15 |
| zone pieces ≤ 500 | 1 | 744, 702, 698, 694 | 1.50e5 / 1.14e5 | 4.79e6 / 2.43e6 | 2.0 | 0.0074 / 0.0058 | 0.177 / 0.109 | 0.59 / 0.47 | 7 / 7 | 0 |
| zone pieces ≤ 500 | 2 | same | 1.50e5 / 1.14e5 | 4.79e6 / 2.43e6 | 2.0 | 0.0085 / 0.0078 | 0.232 / 0.143 | 0.58 / 0.57 | 7 / 7 | 0 |
| welded add-on 0.08 | 1 | 2184 | 2.13e5 / 1.30e5 | 1.29e7 / 4.20e6 | 3.1 | 0.013 / 0.0073 | 0.231 / 0.152 | 0.40 / 0.26 | 4 / 4 | 9.7e-15 |
| welded add-on 0.08 | 2 | 2232 | 2.31e5 / 1.44e5 | 1.56e7 / 5.39e6 | 2.9 | 0.015 / 0.0063 | 0.232 / 0.130 | 0.37 / 0.32 | 4 / 4 | 3.0e-15 |
| zone + structural | 1 | 7720, 2706 | 1.21e6 / 7.64e5 | 1.63e8 / 4.84e7 | 3.4 | 0.082 / 0.036 | 2.49 / 1.63 | 3.09 / 1.79 | 4 / 4 | 1.9e-14 |
| welded add-on 1.0 (96 %) | 1 | 26612 | 5.06e6 / 2.76e6 | 1.31e9 / 4.31e8 | 3.0 | 0.57 / 0.23 | 12.3 / 6.5 | 4.54 / 2.56 | 2 / 2 | 1.6e-14 |
| welded add-on 1.0 (96 %) | 2 | 26662 | 4.80e6 / 2.90e6 | 1.07e9 / 4.75e8 | 2.3 | 0.63 / 0.32 | 13.3 / 8.3 | 4.29 / 2.48 | 2 / 2 | 2.6e-14 |
The full table, every case at np 1 and 2, is in review/table.md.
- qmd never raised the fill, the flops or the per-application MatSolve time.
- The only cost that goes up is the ordering itself: MatGetOrdering 0.6 ms against 0.4 ms on a 201-row block, and 0.024 s against 0.014 s on 26 612 rows. On blocks of 402 rows and up, total set-up is equal or lower.
- The in-solve MatSolve on the tiny 402-row stokes_plain block is noise: 0.026 against 0.051 s at np 1, and the other way round at np 2.
- Iterations are identical in every case.
Pivot attack. Minimum degree eliminates low-degree rows first, and LU here does not pivot. On a synthetic matrix with a zero or 1e-9 diagonal entry, qmd gave |Ax−b| = 1.6e-4 and 1.4e-7, against 1.4e-14 and 1.5e-14 under nd (logs/unit_edge.log). On every real FAC block, qmd's residual was equal to or below nd's (logs/*-res.log):
| block | rows | residual nd | residual qmd |
|---|---|---|---|
| stokes_rotated | 402 | 1.05e-14 | 9.4e-15 |
| sheet_rotated | 402 | 1.37e-14 | 1.31e-14 |
| zone + structural | 7720 | 5.2e-13 | 4.3e-13 |
| zone + structural | 2706 | 9.8e-14 | 6.5e-14 |
| gate160 | 9694 | 1.2e-12 | 1.0e-12 |
| welded add-on 1.0 | 26612 | 2.2e-12 | 1.4e-12 |
The solution norms agree to 12 digits.
Attack 3: the claimed gain, reproduced on hyperion
The fixture is test_1139's row-5 box with no zone keyed, at n_rungs 320: the structural band, one block of 30 396 rows. Kaiju's was 30 048 rows. Logs: logs/fac-np{1,2,4}-zone_struct-{nd,default}-n320.log.
| np | LU flops nd | LU flops qmd | ratio | fill nd / qmd | MatSolve per apply ms nd / qmd | in-solve MatSolve s nd / qmd | ord+sym+num s nd / qmd | vel its | slip, nd = qmd |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 5.82e9 | 3.41e8 | 17.1 | 9.49e6 / 3.39e6 | 23.1 / 8.0 | 15.1 / 5.7 | 2.24 / 0.23 | 3 / 3 | 0.1329322952 |
| 2 | 5.69e9 | 3.68e8 | 15.5 | 9.45e6 / 3.45e6 | 23.9 / 7.9 | 17.0 / 6.0 | 2.15 / 0.23 | 3 / 3 | 0.1329322885 |
| 4 | 7.91e9 | 3.73e8 | 21.2 | 1.07e7 / 3.46e6 | 24.3 / 7.9 | 19.4 / 6.9 | 3.26 / 0.24 | 3 / 3 | 0.1329323206 |
- The claim's direction holds. Under nd, the same block's fill follows the rank count: 5.69e9 to 7.91e9 for identical row counts. qmd cuts it 15 to 21 times, and the spread to 9 %.
- MatSolve per application is 2.9 to 3.1 times faster, and the solve's MatSolve 2.6 to 2.8 times faster.
- Solve wall time, which includes the mesh build, went from 41.6, 45.3 and 52.1 s to 29.8, 31.6 and 36.9 s.
- Kaiju's 25 to 58 times came from the pair and junction networks, which we did not have. On hyperion's smaller bands, the ratio is 2.5 to 4 times (gate160, zone_struct at 80 rungs).
Attack 4: the test can fail
| run | result | log |
|---|---|---|
| branch test_1090 on the base build, np 1 | 10 failed, every one on matrix ordering: nd (10 qmd assertions) |
t1090-ba3f-np1-none.log |
| branch test_1090 on the base build, np 2 | 8 failed, 2 skipped (tier C is serial), all on nd | t1090-ba3f-np2-none.log |
| branch test_1090 on the branch, np 1 (control) | 10 passed | t1090-fac-np1-none.log |
mutation A: the database key removed (_configure_pcmg returns without it) |
np 1: 10 failed; np 2: 8 failed | t1090-fac-np{1,2}-A.log |
mutation B: the setFactorOrdering call removed |
np 1: 10 passed; np 2: 8 passed | t1090-fac-np{1,2}-B.log |
Under mutation A:
- the rotated paths and
stokes_plainfail withKeyError(opts.getStringon the missing key); poissonfails with "not ordered by quotient minimum degree ... nd".
So mutation A is caught on all four paths. Mutation B escapes on all four, for the reason in L1. We mutated in-process with a pytest plugin, not with a scratch rebuild; the two are equivalent for Python-level code [read].
Attack 5: rank agreement and edge cases
- A rank with no block. At np 2 and 4, the ranks without a patch hold one 0-row ASM block (
rows=[30396, 0, 0, 0]at np 4). It reports qmd, factors without error, and gives the same iterations._set_up_fac_smoothershas no collective inside its per-block loop[read]. - Blocks of size 0, 1 and 2 under qmd: they solve exactly, the same as nd (
logs/unit_edge.log). - Re-ordering a block that has already factored.
PCFactorSetMatOrderingTypewith a different ordering on a factored PC raises error 73, "Cannot change ordering after use". The same ordering is accepted.- So a stale nd factor cannot sit behind a view that says qmd, and test_1090's view check cannot be fooled that way.
- A refactor on the same pattern keeps the symbolic factor (we saw no MatLUFactorSym on second solves).
PC.reset()gives a fresh qmd factor (5042 against 7264 fill on the unit matrix). - Every install path resets or creates the PC before
_set_up_fac_smoothersruns[read].
- Ranks agree. At np 2 and 4, slip and v_rms match np 1 to the same digits as on base, and the forced-nd runs reproduce the base build's fill exactly (e.g. 2.184e4 at np 2 on
stokes_rotated).
Attacks that failed (numbers)
- No path factors with nd. We covered the 13 entries in the attack 1 table, at np 1 and 2, plus 3 at np 4. Live fill equals qmd's offline fill in every case.
- No cost regression on small or compact blocks.
- 201-row blocks: 1.4 times fewer flops.
- 500-row zone pieces: 2.0 times fewer flops, MatSolve 1.6 times faster.
- Welded add-ons: 2.3 to 3.1 times fewer flops.
- The only increase is MatGetOrdering, by fractions of a millisecond to 10 ms.
- No accuracy loss.
- Real-block residuals under qmd are at or below nd's.
- v_rms and slip agree to ≤ 7.2e-14 relative.
- Velocity iterations are identical in all 23 comparisons.
- No leak. The rotated paths drop the key. On the standard paths it stays under the solver's own prefix. An unrelated LU solver still orders by nd.
- Edge cases. Empty blocks, 1-row blocks and empty ranks behave the same under qmd. Re-ordering after a factor raises an error instead of leaving a stale factor.
Merge conditions
- None blocking.
- Optional (L1): remove the
setFactorOrderingline and its docstring sentence, or keep it and say that the database key is what reaches the blocks and that test_1090 does not cover the line. - Optional (L2): add the ordering key to the
_configure_pcmgdocstring's key list. Make the "3.1e9" figure traceable in the design note's table, and soften "the same at any rank count" to "nearly the same" (9 % on hyperion). - File P1 (mesh.deform: lingering FAC keys and a stale
_pcmg_still_installedverdict) and P2 (the Stokes adjoint without FAC). Both exist on development too. - Issues in the territory:
- FAC structural patch cost: since #934 every fault's rows (a network's included) are one LU on one rank; 3-D and parallel cost unmeasured #895: still live. This branch makes the 2-D structural block cheaper. 3-D is unmeasured, and our small 3-D box declines its patch.
- Rotated path: FAC patch blocks run ILU(0), not the configured LU #892: no change. Mutation B confirms that its fix, setting the ASM up while the keys exist, is what delivers the block configuration.
Could not test
- Kaiju's fixtures (the add-on matrix's row 5 pair and junction networks at np 4 to 16), and so the 25 to 58 times figures and the 3.1e9 row. Hyperion's closest fixture gives 15 to 21 times.
- 3-D: test_1095's split box declines its patch (no blocks). A 3-D case that takes a patch, such as test_1097's sheet (84 435 rows), is not cheap. Kaiju is checking 3-D.
- A real scratch rebuild for the mutations. We mutated in-process instead (see attack 4).
fac_zoneas a list of masks (per-segment blocks) as its own fixture. It goes through the same_configure_pcmgloop as the single-mask blocks[read].- The legacy
set_custom_mgroute: it installs nopatch_rows, so it has no FAC blocks[read]. - Wall times are noisy, because they ran beside the other job's parallel test batches (about 12 to 20 busy cores).
Parallel run (H1, separate from the review)
The 24 tests/parallel files that use FAC or custom MG (runs/2026-11-06/fac/files.txt), run on both builds with the branch's test files:
- e451623 np 2: 91 passed, 7 skipped, 1 xfailed. np 4: 94 passed, 4 skipped, 1 xfailed.
- ba3fc23 np 2 and np 4: everything else the same, but the 8 parametrisations of
test_1090::test_every_level_runs_its_configured_smootherfail. They fail on "matrix ordering: qmd" not appearing in the view, which reports nd.
Re-check of aca58b6 (W1's L1 and L2 fixes)
- L1, fixed: the
setFactorOrderingcall is removed, and the docstring says the ordering comes from the database alone, read at ASM set-up. - L2, fixed: the docstring lists the ordering key. The comment quotes the pair's own figures (8.1e9 at np 4, 2.35e10 at np 8 and 16, against 4.1e8 for qmd) and says "nearly the same".
- Rebuilt; test_1090 at np 2 and np 4: 8 passed, 2 skipped. The fix that remains is the database key, and mutation A showed test_1090 catches its removal on all four paths.
- P1 is filed as Custom FMG with a FAC patch: re-solve after mesh.deform fails with PETSc error 73 (empty composite); the hierarchy is not re-installed #1015 and P2 as Stokes adjoint_solve drops the custom-FMG velocity hierarchy and its FAC patch: one-level mg, 29 iterations against the forward's 4 #1016. Both are reproduced standalone on development ba3fc23 at np 1 and 2. P2 affects only the adjoint: a forward solve afterwards takes 3 levels and 4 iterations again.
Correction to P1 (from the #1015 review)
P1 above says _pcmg_still_installed accepts the rebuilt PC, so the hierarchy is not installed again. That is wrong. On development the check answered False at the first re-solve after a deform: the rebuilt PC had 1 level (Poisson) or no reachable block (Stokes). The hierarchy was installed again, and the install failed with error 73 on the leftover mg_levels_2_pc_type composite key. The stale key alone is the cause. See records/1015-review.md (L1), and the correction posted on #1015.
Re-check of 0f262b7 (K2's user-ordering change; development 80d3ebe merged)
- The change: the qmd default is written only when the options database holds no ordering key for the block. Rebuilt and probed (
fac/userord/):- a user's
<prefix>mg_levels_2_sub_1_sub_pc_factor_mat_ordering_type nd, set as PETSC_OPTIONS would, is honoured. Every rank's FAC block views nd, the key is still nd after two solves, and the solve converges (np 1 and np 2); - with no user key, every block is qmd (np 1 and np 2).
- a user's
- The rotated paths drop everything under their per-solve
rotfs/rotvecprefix after set-up. That prefix is internal and numbered per solve, so a user can't target it in advance, and the change has no bearing there[read]. - test_1090: at np 2 and np 4, 8 passed and 2 skipped.
- The rest of the merge is development 80d3ebe (One convergence reference for every solver: warm starts, the linear floor, the rotated loop (#911, #985, #924) #1014), which hyperion reviewed on its own PR.
Underworld development team with AI support from Claude Code
…ering Underworld development team with AI support from Claude Code
…ering Underworld development team with AI support from Claude Code
The FAC patch smoother's block LU now factors in quotient minimum degree (qmd) order (found while measuring #895).
The problem
The blocks had no ordering set, so PETSc's default, nested dissection (nd), applied. For a fault band's long, narrow block the fill then followed the subdomain's row numbering. The same block of the add-on matrix's fault pair took 8.1e9 flops to factor at np 4 and 2.35e10 at np 8 and 16 (kaiju, K2).
The change
_configure_pcmgwrites..._sub_1_sub_pc_factor_mat_ordering_type qmdnext to the shift key. It goes into the keys the rotated path keeps through set-up, and is written only where the database holds no ordering already.test_1090, which reads the live smoother on every install path, asserts the ordering. On development every path reportsmatrix ordering: nd.Evidence
2-D, the add-on matrix's row 5 networks (kaiju, K2):
3-D, a split disc sheet in the unit cube (
sheet3d_addon.py, ref 1, np 4). One block of 87666 rows, the same block in both runs:Slip, max and L2 over 5993 pairs, agrees to 1e-15.
Hyperion's review:
Serial on wombat: the FAC and fault-split set, 529 passed and 4 skipped. The first commit's message says 526; it is 529.
Reviews
setFactorOrderingcall that had no effect, and that would raise PETSc error 73 on a block already factored;Issues
Underworld development team with AI support from Claude Code