Skip to content

Project exact rotations out of the rotated velocity preconditioner; fixes the shard-4 hang (#963) - #967

Merged
lmoresi merged 6 commits into
developmentfrom
bugfix/rotated-vel-pc-projection-963
Nov 7, 2026
Merged

lmoresi merged 6 commits into
developmentfrom
bugfix/rotated-vel-pc-projection-963

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member

The rotated custom-FMG velocity preconditioner projects out the exact rotation modes, so the inner velocity solve no longer stalls (#963). This turns CI's shard 4 green again.

The bug

Every CI run from development eddab70 hung in test_1064_rotated_freeslip_parallel.py::test_rotated_freeslip_annulus_fmg_partition_independent at np 2, until the MPI supervisor killed it. #947's own PR run had passed on the same tree, so the code was not the difference: whether the solve finished depended on the host's OpenBLAS kernel.

The mechanism, found on hyperion:

  • The annulus case uses the analytic radial normal on both walls. That makes the rigid rotation an exact null vector of the rotated velocity block: |A m| / (|A| |m|) = 1.7e-18.
  • The inner FGMRES is right-preconditioned by the custom FMG, and each cycle returns a rounding-level component along m.
  • PETSc's MatNullSpace removes the mode from the right-hand side and from the solution, not from the preconditioned directions. So the inner residual floors at an absolute 4e-8 to 1.2e-7, against an inner rtol of 3.3e-11, and the inner solve runs to its cap of 200.
  • Whether the outer FGMRES converges after that depends on rounding. At np 1 or 2, SkylakeX and the default kernel finished. Zen and Haswell stalled at np 2, Nehalem and Sandybridge at np 1, Core2 and Prescott at both.

Ruled out on hyperion: #947's coarse shift (shift off, shift forced on, an SVD coarse solve), the level smoother (Richardson, Chebyshev), the orthogonalisation (MGS, CGS with refinement), attaching m as the velocity block's MatNullSpace, and a looser inner atol.

The change

After the custom-FMG velocity PC is set up, the admitted rotations (the velocity parts of the rotated null space) that A_vv annihilates to 1e-10 relative are orthonormalised. The velocity sub-KSP's PC becomes a Python PCShell around the configured multigrid:

z = P M (P r),   P = I - sum_i m_i m_i^T

A near-null mode is left to the multigrid, as it is today. An example is a declared rotation on a faceted wall, where A m is the faceting error. The solve record gains projected_null_modes, and velocity_pc_type still reports the inner PC ("mg"). The GAMG velocity route and the rotated vector-problem route are unchanged.

Evidence

The answer is unchanged, and the inner solve takes 4 to 5 iterations where it took up to 200.

macOS arm64, projection on and off:

case projection modes projected outer its inner velocity its (last) answer
annulus_fmg, analytic normal on 1 1 4 L2 0.0190696175990617
annulus_fmg, analytic normal off 0 1 200 L2 0.0190696175995057
0.3 shell, refinement 1, FMG, analytic normal on 3 1 5 v_rms 1.80576312419345
0.3 shell, refinement 1, FMG, analytic normal off 0 1 5 v_rms 1.80576312419324

Hyperion (Linux, Xeon Gold 6240R), annulus_fmg on this branch under eight forced OpenBLAS kernels:

  • The kernels: default, SkylakeX, Haswell, Zen, Sandybridge, Nehalem, Core2 and Prescott.
  • Every run finished, outer its 1, inner max 4, none diverged. Before the fix, 8 of these 16 kernel and rank-count combinations stalled.
  • L2 across the eight kernels: 0.01906961745108643 to 0.01906961745108652 at np 1, and 0.01906961745108457 to ...467 at np 2.
  • The parallel set passes at np 2 and 4: test_1064 (6 passed, 3 skipped), 1066, 1068, 1112, 1116 and 1140.

Tests

tests/test_1142_rotated_exact_mode_projected_pc.py is tier B:

  • The analytic-normal annulus converges with at most 10 inner velocity iterations, projects one mode, and keeps its answer (L2 0.0190696176, rel 1e-8). Against development's rotated_bc this fails with 200 <= 10 on macOS arm64 and on the x86 kernels that stall. Under SkylakeX, development takes 4 inner iterations, so there the next check is the one that bites.
  • On x86, the same solve in a child process under OPENBLAS_CORETYPE=Nehalem must finish within 240 s. On eddab70 it timed out (hyperion); on this branch it passes in 14 s.
  • Under the default normal, the near-null rotation is not projected.

In CI it runs in shard 3. The 53 serial files that use rotated free slip or the custom multigrid give 504 passed, 4 skipped and 1 failed on this branch (macOS). The failure was test_1021, which read the multigrid configuration off the velocity sub-PC object and found the projection around it. The configuration is unchanged; the test now unwraps the projection, and test_1021 and test_1142 give 24 passed and 1 skipped (the forced-kernel child).

Issues

Underworld development team with AI support from Claude Code

…ditioner

With the analytic normal on a circle or sphere, the rotated constraint leaves
a rotation an exact null vector of the rotated velocity block (|A m| /
(|A| |m|) = 1.7e-18 on test_1064's annulus). The custom-FMG cycle returns a
rounding-level component along it in each preconditioned direction, and the
KSP's null space, acting on the right-hand side and solution only, does not
remove it. The inner FGMRES floored near 1e-7 against 3.3e-11, and the outer
FGMRES kept restarting it until CI's supervisor killed the job, on every CI
run from eddab70. Whether rounding lands above the tolerance depends on the
OpenBLAS kernel (hyperion): SkylakeX finishes; Zen and Haswell stall at np 2,
Nehalem and Sandybridge at np 1, Core2 and Prescott at both.

When the admitted rotations include modes A_vv annihilates to 1e-10 relative,
the velocity sub-KSP's PC becomes a PCShell, z = P M (P r), around the
configured multigrid. Near-null modes (a declared rotation on a faceted wall)
are left to the multigrid. The solve record gains projected_null_modes, and
velocity_pc_type still reports the inner PC. The GAMG and vector-problem
routes are unchanged.

test_1142: the analytic-normal annulus projects one mode and keeps its
answer; the default normal projects none; on x86, the solve under
OPENBLAS_CORETYPE=Nehalem must finish within 240 s in a child process.

Underworld development team with AI support from Claude Code
…y host

Without the projection the analytic-normal annulus's inner velocity solve runs
to its cap of 200 on macOS arm64 too; the outer solve converges there anyway,
which is why only some CI kernels hung. With it the inner solve takes 4. The
in-process test now asserts at most 10 inner iterations before it checks the
projected-mode count, so it fails on behaviour on every host: against
development's rotated_bc it fails with "200 <= 10", on this branch it passes.
The forced-kernel child stays as the x86 check of the hang itself.

Underworld development team with AI support from Claude Code
The previous commit said the bound fails on any host. Hyperion measured
development's inner velocity solve at 4 iterations under SkylakeX, so there
only the forced-kernel child catches a regression. The bound catches it on
macOS arm64 and on the x86 kernels that stall.

Underworld development team with AI support from Claude Code
The rotated route's velocity sub-PC is now the projection around the
multigrid when the constraint leaves an exact rotation, as test_1021's
analytic-normal annulus does. The test checks the multigrid's configuration
(redundant LU coarse solve with the nonzero shift), which is unchanged, so it
unwraps the projection first.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 6, 2026 08:10

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 6, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #967

Verdict: not ready, one must-fix with a verified four-line fix. The projection removes the #963 stall and leaves answers unchanged, but at np >= 2 the wrapped multigrid is never destroyed: 19 MB per adjoint solve.

Reviewed at 108f9de (library unchanged from 348f068; test_1021's later commit not reviewed), base eddab70. Host: hyperion, Xeon 6240R, loaded at about 25. Probes on hyperion in runs/2026-11-06/rev963/.

Findings

  1. Must-fix: inner PC leak at np >= 2. _NullModeProjectedPC.destroy (rotated_bc.py:2298) frees the modes and work vector but not self.inner. The whole MG hierarchy survives garbage_cleanup() and PETSc finalize. 31 adjoint solves, annulus cs=0.1, np 2: RSS 532.7 to 1106.4 MB on the branch against 534.5 to 551.0 on base. PCs destroyed at finalize: 193 of 353 on the branch; all 321 on base. Forward rebuilds leak too: np 2, 96 PCs created and 56 destroyed, against 88/88 on base. Serial is clean. test_0078 cannot see this, because its fixture has no exact mode. With self.inner.destroy(); self.inner = None in destroy: RSS 532.7 to 549.1, 348 of 353 destroyed (the 5 left belong to the live forward context), same multiplier as the branch, no error on repeated forward solves at np 2. A regression test belongs in tests/parallel.
  2. Should-fix: "ran to its cap of 200 on every host" (test_1142:89-90, docstring) does not hold here, so line 91 is inert on the default kernel. Inner iterations on eddab70: SkylakeX or default, np 1 and 2, 4 each in all solves; Haswell np 1, Zen np 1, Nehalem np 2, Sandybridge np 2, 4 each; Zen np 2, Haswell np 2, 200, stalled; Nehalem np 1, 260 of 265 logged at 200. A no-projection mutant on the default kernel passes line 91 and fails only at line 92, the mode count. The macOS state, inner at cap with the outer converging in 1, does occur here (Core2 np 2, delta=8e-8, an unadmitted mode), so it is plausible as a third state, not proof that the stall is on every host. arm64 could not be tested. The comment should say what was measured on which host.
  3. Should-fix: vel_its_last samples only the last Schur application. At delta=5e-7 on the default kernel, 6 inner solves hit the cap, yet vel_its_last=[4]. Line 91 can pass over a stall.
  4. Should-fix: test_a_near_null_rotation_is_left_to_the_multigrid cannot fail on the threshold. With _EXACT_NULL_MODE_TOL=1e10, 3 of 3 pass. The default normal is rejected at admission (rot=0), so nothing reaches the gate. On every mesh and normal we measured, each admitted mode was also projected.
  5. Should-fix: the L2 pin is off-centre. 0.01906961745108 sits 7.8e-9 from L2_ANALYTIC (test_1142:44) against rel=1e-8, with a 1e-9 solve tolerance. test_1064 allows 1e-6 on this value. Spread across kernels here is about 1e-13. Suggest rel=1e-7.
  6. Should-fix, docs: projected_null_modes is missing from the record lists in docs/developer/subsystems/rotated-freeslip.md:281 and the solve_rotated_freeslip docstring; the shell is not described there; no CHANGES entry. CI reach is fine: batch 3 tests/test_1142*py.
  7. Not from this branch, not must-fix: an exact rotation not centred on the origin is rejected, and FMG then returns a large rigid rotation while reporting converged. _rigid_rotation_fields (:3114) fixes the centre at the origin. With a normal centred at (delta, 0), rotation about that point is exactly null but rejected for delta >= 5e-8. FMG reports reason 2 with L2 between 2.0 and 201 against 0.019; bit-identical on eddab70 where both finished. GAMG gets 0.019075. Filed separately.

Attacks that failed

  • Threshold: the ratio is about 1.04e-3 delta and exact modes are 1e-16 to 1e-18; admission cuts off before 1e-10 is reached. delta from 1e-13 to 3e-8 under Nehalem np 1, Zen np 2, Core2 np 1 and default: 0 capped inner solves, proj=1, L2 within about 1e-12 relative. No admitted mode at 1e-9 exists to stall.
  • Collective: global norms only; np 8 gives proj=1, reason 2.
  • Shell: three modes, ratio 1e-18, proj=3, L2 0.346969683841478 against ...476 on base, same iterations. Base did not stall at 1e-6 either, so the shell is safety evidence, not a fix.
  • FAC and split fault on an annulus: proj=1, L2 identical to 14 digits at np 1 and 2, and under Zen np 2 and Nehalem np 1.
  • Newton, power law, 7 increments: L2 4.53609041906065 identical, same iterations, operators aligned at every increment.
  • Repeats and warm starts: five solves, L2 within 7e-15; warm start with changed viscosity 5.5084416 against 5.5084407 (exact 5.5084409).
  • Adjoint runs through the shell with reason 2. The multiplier difference to base is purely gauge. applyTranspose raises error 56 on the shell and on base's PCMG; no current path calls it.
  • selfp: L2 0.734458789209952 against ...948. GAMG: 7 forced cells, inner 54-55, no stall. Default-normal FMG: 7 cells, inner 5, no stall. rotvec (ThinSheet sphere with FMG, 3 modes): 8 cells, its 19-21, no stall.
  • Cost within noise: Newton 17.9 s against 18.6 s, shell 62.0 against 60.4 (np 2), 31 adjoints 127 against 123.
  • Existing tests, same exit on both trees: 1022_composed, 1065, 1087, 1111, 1113, 1115, 1136, 1141; np 2 0078, 1088 and 1089.
  • test_1142 fails for the right reason on x86: the 240 s Nehalem timeout. Its first two tests fail on base on KeyError, not the bug. Passing costs 15-16 s; failing 250 s, under the 300 s silence budget.

Runs from the author's request, at 108f9de

Kernel table: 8 kernels at np 1 and 2 all finish, inner max 4, its=[1], reason 2, L2 spread about 1e-13. Parallel set at np 2 and 4: test_1064, 1066, 1068, 1112, 1116, 1140 pass.

Issues

Merge conditions

  • destroy destroys self.inner, with an np >= 2 regression test on an analytic-normal annulus.
  • Correct the "every host" wording in test_1142, and do not treat line 91 as the behavioural guard: on x86 the child test is.
  • Give the near-null test a fixture that reaches the gate, or delete it and say the admission test decides.
  • Widen the L2 pin, and add projected_null_modes to the doc and docstring.

Could not test

arm64; real CI runner CPUs; a truly off-centre mesh; empty-rank partitions; a complete CubedSphere solve (#946 folds it on both trees); test_0022 and test_1018 (timeouts on both trees); a clean cost measurement on an idle host.

Underworld development team with AI support from Claude Code

…nd docs

From hyperion's review of #967:
- Must fix: _NullModeProjectedPC.destroy freed its modes and work vector
  but not the wrapped multigrid, which the sub-KSP had given up to it. At
  np 2, where petsc4py defers destruction, the whole hierarchy outlived every
  solve: 533 to 1106 MB over 31 adjoint solves against 535 to 551 MB on base
  (hyperion). It now destroys it. _destroy_rotated_ksp_ctx also releases the
  context's own reference to the fieldsplit PC, which alone kept the PC, its
  sub-KSPs and the projection alive after the KSP was destroyed.
  test_the_projection_releases_the_multigrid_it_wraps checks that the wrapped
  PC is destroyed with the workspace; it fails when destroy leaves the
  multigrid alive.
- The record gains null_mode_ratios, |A m| / (|A| |m|) per admitted rotation;
  the test pins the exact mode below 1e-14, eight orders under the 1e-10
  threshold.
- The default-normal case admits no rotation on development, so its test now
  says that, instead of claiming a near-null mode is left alone; the
  near-null case arrives with #906.
- The L2 pin is centred between macOS (0.0190696175990617) and Linux
  (0.01906961745108), whose gmsh builds a slightly different annulus.
- rotated-freeslip.md describes the projection and the two record fields.

Underworld development team with AI support from Claude Code
…igrid on every rank

At np 2 petsc4py defers the destruction of a dropped reference, so the
wrapped multigrid outlived every solve before the fix (hyperion, on 108f9de).
The test checks, on every rank, one mode projected, a short inner solve, and
the wrapped PC destroyed with the workspace. Its body passes serially here.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Response to hyperion's review, at 488c53b

Must fix: the wrapped multigrid leaked. Fixed in a6d1a80.

  • _NullModeProjectedPC.destroy now destroys inner.
  • _destroy_rotated_ksp_ctx also releases the context's own pc reference. That reference alone kept the fieldsplit PC, its sub-KSPs and the projection alive after the KSP was destroyed, so even the corrected destroy did not run while a workspace was being torn down.
  • Tests:
    • serial: test_the_projection_releases_the_multigrid_it_wraps destroys the solve's workspace and checks that the wrapped PC's handle is gone. It fails when destroy leaves the multigrid alive.
    • parallel: tests/parallel/test_1142_rotated_exact_mode_projected_pc_parallel.py (488c53b) checks the same on every rank, with the projection in place and the inner solve short. Its body passes serially. Please run it at np 2, 4 and 8, along with your 31-adjoint memory probe.

Should fix:

  • "Every host" wording: corrected in dab53e1. The docstring now says the inner-iteration bound catches a regression on macOS arm64 and the x86 kernels that stall, and that under SkylakeX only the forced-kernel child does.
  • The near-null test could not fail on the threshold: right. On development, no rotation is admitted under the default normal at all; the constraint test rejects the faceted rotation. So there was no near-null mode to leave alone. The test now says that, and asserts that nothing is admitted or projected. The record gains null_mode_ratios (|A m| / (|A| |m|) per admitted rotation). The exact mode is pinned below 1e-14, eight orders under the 1e-10 threshold; macOS measures 2.0e-18. The near-null case arrives with Rotated free slip on a spherical shell with the default normal: the rotations are rejected and the answer carries a rigid rotation #906 (PR Rotated free slip takes its rotation modes from the mesh, while the walls stay put (#906, #877) #964), and its test will be extended there after this merges.
  • The L2 band: centred between macOS (0.0190696175990617) and Linux (0.01906961745108), whose gmsh builds a slightly different annulus. Each is now at about 40 % of the 1e-8 band.
  • Docs: rotated-freeslip.md describes the projection, projected_null_modes and null_mode_ratios.

#969 (an exact rotation about a point off the origin): not this PR's change, as you say. With #964, a mesh can declare the rotation about the normal's centre. Walls with a given normal then take the constraint test, which that rotation passes exactly, and this PR projects it. An undeclared mesh keeps the detection, which offers rotations about the origin only. I'll put a probe on #969 once both have merged.

Serial on macOS: test_1142 plus test_1021 give 25 passed, 1 skipped.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Rerun at 488c53b, on hyperion. The review's must-fix is closed.

  • 31 adjoint solves, annulus cs=0.1, np 2: RSS 533.1 to 549.5 MB, about base's 534.5 to 551.0 (the review's branch figure was 1106.4). One shell alive throughout.
  • tests/parallel/test_1142_rotated_exact_mode_projected_pc_parallel.py: 1 passed at np 2, 4, 8. With self.inner.destroy() removed it fails at np 2 and 4, AssertionError: [False, False] and [False, False, False, False], so it can fail on the leak.
  • tests/test_1142: 4 passed in serial, forced-kernel child included.
  • Repeated forward solves at np 2, five right-hand sides and a changed viscosity: all reason 2, its=[1], vel=[4], proj=1, handles checked on each. L2 5.50844091851822 and, after the viscosity change, 5.50844091598384.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 7c3d31f into development Nov 7, 2026
8 checks passed
lmoresi added a commit that referenced this pull request Nov 7, 2026
…m-values

Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 7, 2026
…anup-950

Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 7, 2026
Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 7, 2026
…from-mesh-906

Underworld development team with AI support from Claude Code

# Conflicts:
#	scripts/test.sh
lmoresi added a commit that referenced this pull request Nov 7, 2026
With development merged in (#967), the shell under the analytic normal
has three exact modes, which the velocity preconditioner projects out
(ratio below 1e-14). Under the facet-averaged normal its three declared
modes are near-null, exempt and admitted, but left to the multigrid
(ratio above 1e-8, against the 1e-10 at which a mode is projected). This
is the near-null case #967's review noted would arrive with #906.

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