Skip to content

The rotated free-slip solve counts and warns on capped sub-solves (#625) - #1260

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/rotated-sub-solve-caps-625
Nov 20, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/rotated-sub-solve-caps-625

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A rotated free-slip solve now counts the sub-solves that stopped at their iteration cap and warns once per capped block, as the native Stokes path does since #1062. This is part of #625, which stays open.

What changes

On development.

  • The rotated free-slip loop (rotated_bc) solves its own fieldsplit-Schur KSP, so the native path's count (solve_report.sub[...].capped) and its warning never saw it.
  • The loop recorded the iteration count of the last velocity application and the last pressure application, once per Newton increment.
  • It never read the pressure sub-solve's converged reason. A pressure solve that stopped at its 200-iteration cap left a converged outer solve and said nothing.

Now.

  • Each sub-KSP of the rotated fieldsplit gets a post-solve hook. The hook counts the applications that ended at the cap (DIVERGED_MAX_IT) over the whole solve, and the counts reset when a solve starts on a cached context.
  • The counts are in _rotated_freeslip_info["sub_capped"] as {"velocity": n, "pressure": n}. They are None where there are no sub-KSPs (the direct-LU path, the sheet's single KSP).
  • The solver warns once per capped block with a RuntimeWarning attributed to the user's solve() line, in the native warning's words.
  • The converged reason is global to the KSP, so the counts agree on every rank. Rank 0 warns. No collective is added.

Cost of the hooks

The probe runs the same rotated annulus solve with the hooks on, and with KSP.setPostSolve replaced by a no-op so that none is installed. Serial, macOS (12-core Apple M4); wall time of the solve, median of 3:

case sub-solve applications hooks on hooks off ratio
capped pressure, cell size 0.25 1 pressure, about 208 velocity 0.263 s 0.258 s 1.020
capped pressure, cell size 0.1 1 pressure, 200+ velocity 0.879 s 0.865 s 1.016
default tolerance, cell size 0.1 1 pressure, 7+ velocity 0.243 s 0.243 s 1.003

In all 18 runs the velocity, the pressure, and the outer and sub-solve iteration counts are bitwise identical with and without the hooks. Wall time on this machine moves by a few percent from run to run, so the ratios bound the overhead rather than measure it. I timed this annulus in place of test_0022.

A fixture with two or more capped applications per increment. I didn't find a cheap one. With a viscosity contrast of 1e4, the capped solve still takes one outer iteration. At 1e6 it takes 300 outer iterations (62,298 velocity applications) and does not converge, which is too slow for a test.

Left open on #625

  • The 200-iteration caps themselves, at four sites in petsc_generic_snes_solvers.pyx: a pressure preconditioner that never reaches the cap, or an inexactness made deliberate and cheap.
  • Caps a user sets in petsc_options still do not reach the rotated loop, whose options live under its own prefix. Whether they should is a design question and is not taken here.

Tolerances and coordinate matches

None.

Tests

tests/test_0207_rotated_subsolve_cap_detection.py, level 2, tier B. It is an annulus with rotated free slip on both walls.

  • Capped. _rotated_pres_rtol = 1e-30, a tolerance the pressure sub-solve cannot reach:
    • every outer application stops at the cap of 200 (measured: one outer iteration, 200 pressure iterations);
    • the pressure count equals the outer iteration count and the velocity count is 0;
    • the warning names the pressure sub-solve.
  • Default tolerance: both counts are 0 and nothing is said.

Both fail on development (KeyError: 'sub_capped').

What the test does not show. The fixture has one pressure application per Newton increment. It therefore does not tell the count over every application from a last-application readout, and no case caps the velocity block. Those rest on PETSc running the post-solve hook after every KSPSolve of the sub-KSP. Measured on the capped fixture: the velocity sub-KSP's hook ran 208 times in one solve (200 pressure iterations, each a Schur product through the velocity solve, plus the factorization's own velocity solves), and the pressure hook once. So the hook sees the inner Schur solves. A nonlinear viscosity gave four increments and a pressure count of 4, one per increment, so it does not separate them either.

Serial runs (macOS, 12-core Apple M4): test_0205, 0206, 0207, 0022, 1084, 1131, 1142, 1188 → 98 passed, 1 skipped (an x86-only case).

Review

Adversarial review, below.

Issue state

#625: partly addressed. The rotated path's detection is fixed here; the caps and the user-cap question stay open. No fixed-in label.

Underworld development team with AI support from Claude Code

The rotated loop solves its own fieldsplit-Schur KSP, so the native path's
count and warning (#585, #1062) never saw it. It read the last velocity and
pressure application only, and never read the pressure sub-solve's reason.

Each sub-KSP now has a post-solve hook that counts the applications that
stopped at their cap (DIVERGED_MAX_IT) over the whole solve, reset when a
solve starts on a cached context. The count is in
_rotated_freeslip_info["sub_capped"] (None without sub-KSPs), and the solver
warns once per capped block, attributed to the user's solve() line, as the
native path does. The reason is global to the KSP, so the counts agree on
every rank; rank 0 warns.

test_0207: a pressure tolerance the sub-solve cannot reach caps every
application, counted and warned; at the default tolerance the counts are
zero and nothing is said. Both fail on development (no count).

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

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

Copy link
Copy Markdown
Member Author

Adversarial review, round 1 (head 5ac6537)

  • Rank asymmetry. The hook runs inside each sub-KSP's KSPSolve, which every rank enters together. It reads getConvergedReason(), which is global to the KSP, so every rank increments alike. The warning is rank 0 only, after the counts are final. No collective is added.
  • Hook lifetime. The hooks are set once, when the fieldsplit context is built, after pc.setUp(). The velocity PC's reset() and the projection wrapper (test_1064 annulus FMG solve runs past the CI supervisor at np 2 since eddab707; same tree passed on #947's PR run #963) act on the PC and leave the KSP and its hook alone. The counts dict is held by the closure and by ctx, and goes with the KSP when the context is destroyed.
  • Cached context. A solve that reuses the workspace resets the counts at its start, so sub_capped is per solve. When a warm start exits converged before building a context, or on the LU path, it is None, not a stale dict. The warning reads info["sub_capped"] or {}.
  • Coverage of applications. Measured: on the capped fixture the velocity hook ran 208 times (each Schur product goes through the velocity sub-KSP) and the pressure hook once. The count therefore covers every application, not the last.
  • Tests that cannot fail. Both fail on development. The capped case asserts an exact count (pressure = outer iterations, velocity = 0); the control asserts zeros and silence.
  • What the test does not separate. One pressure application per increment makes a last-application readout give the same number here. The PR body says so, and gives the measurement above in its place.
  • CI reach. test_0207 falls in scripts/test.sh's tests/test_02*py batch.
  • Solver contract. Unchanged: options, tolerances and caps are as on development; the hooks only read.

No findings.

Issue state:

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Second-desk review by H7 (a Claude review session running parallel probes on a 96-thread Linux workstation: Intel Xeon Gold 6240R, AVX-512, MPICH). The base is development e7e02b9, the merge base of the rotated batch (#1260, #1261, #1262, #1265, #1263). #1261, #1262, #1265 and #1263 change only rotated_bc.py, so each was measured by placing the branch's file, or a clean three-way merge of the files, in a build of e7e02b9. #1260 was built from its own branch. Parallel runs were under the MPI supervisor, at most 4 ranks.

Verdict: passes. It is independent of the others in the batch.

Checked

  • Answers and iterations. We ran the 49 serial files that touch the rotated solver, development and branch, logging every rotated solve (604 solves):

    • iterations: the outer and Krylov counts are identical in every solve;
    • answers: the velocity norm differs in 151 solves, all in tests that differ between two runs of development itself. Run serially twice, development varies by up to 7.4e-2 on test_1018/test_1131's deformed-wall cases. On the probe annulus: serial and np 3 are bitwise identical. At np 2 the branch gives development's value in 1 of 3 runs (1.4e-14 apart otherwise), and development's own np 2 velocity-capped case varies by 5e-11 run to run.
  • Counts on every rank, one warning on rank 0 (annulus, cell size 0.25):

    case np sub_capped (every rank) warnings on rank 0 / others
    pressure capped (_rotated_pres_rtol = 1e-30) 1, 2, 3 pressure 1 1 / 0
    tolerance 1e-12 2 velocity 110 1 / 0
    tolerance 1e-12 3 velocity 204, pressure 1 2 / 0
    default 1, 2, 3 0, 0 0 / 0

    The tolerance-1e-12 rows are the case the PR body says it could not build: many capped velocity applications per increment, counted over every application. The answers and iteration counts are equal to development's.

  • Overhead: the 49-file suite at 2 workers took 4568 s on development and 4654 s on the branch (+1.9%, one run each, noisy). The annulus solve takes 0.23-0.25 s on both. Consistent with the body's 0.3-2%.

  • test_0207: 2 failed on development, 2 passed on the branch.

Findings

  • Low: test_0207 covers only the pressure cap. At np 1 the tolerance-1e-12 annulus does not cap the velocity block, but at np 2 it does (110), so a velocity-cap case would need a parallel test or another fixture.

Underworld development team with AI support from Claude Code

The conflict in petsc_generic_snes_solvers.pyx is two methods added at the
same place: this branch's _warn_on_capped_rotated_sub_solves (#625) and
#1255's _refuse_unfactorable_pressure_preconditioner (#1059). Both are
kept, with their call sites (the rotated solve's sub_capped warning, and
the post-solve refusal with its forced setup after a PC failure).

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged development into this branch: c3332a6.

The conflict. It was in petsc_generic_snes_solvers.pyx, where two methods had been added at the same place: this branch's _warn_on_capped_rotated_sub_solves (#625) and #1255's _refuse_unfactorable_pressure_preconditioner (#1059). Both are kept, with all their call sites:

Serial runs on the merge (macOS, 12-core Apple M4):

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit eabceed into development Nov 20, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 20, 2026
Brings in #1260 (rotated sub-solve caps); the merge of rotated_bc.py is
automatic.

Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 20, 2026
…nts-941

Brings in #1260 and #1262; the merge of rotated_bc.py is automatic.

Underworld development team with AI support from Claude Code
lmoresi added a commit that referenced this pull request Nov 20, 2026
Brings in #1260, #1262 and #1265 (the summed normal this branch's corner
datum reads); the merge of rotated_bc.py is automatic.

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