Skip to content

A capped fieldsplit sub-solve says so, and a diverged solve warns (#585, #625, #1059) - #1062

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/sub-solve-cap-warning-585-625
Nov 11, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/sub-solve-cap-warning-585-625

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 11, 2026

Copy link
Copy Markdown
Member

A sub-solve stopped at its cap. PETSc does not count a fieldsplit sub-KSP that stops at its iteration cap (DIVERGED_ITS) as a failure. The outer solve can then converge while a block never solved: the Schur operator is applied through a velocity solve that is inexact and varies between applications. The count was recorded (solve_report.sub[name].capped), but nothing said so at solve time.

_warn_on_capped_sub_solves issues one RuntimeWarning per capped block, after the solve has recorded its status, on rank 0:

  • It names the block. A digit-named block is named by its DM fields: a constrained solve's field-1 (pressure + multiplier_0 + ...) is the pressure and its multipliers, solved as one Schur block.
  • It gives the cap, read from the sub-KSP.
  • It points to the counts. Its advice is that a higher ksp_max_it helps only a block that converges slowly, and one that stagnates needs a better preconditioner. On the constrained parallel tests, a cap of 5000 still caps, at 11 times the wall time.
  • It is attributed to the caller's solve() line (_warn_from_caller), so the default filter shows it once per block and call site in a time loop.
  • It is skipped during estimate_difficulty, whose caps are the point.

A diverged solve. A solve that diverges printed a notice and returned, so a script carried on with whatever the fields held. At a viscosity of 1e11 or more in PETSc's frame that is u = 0 (#1059). _warn_on_diverged_solve adds a RuntimeWarning, after the record and on rank 0. It names the reason and whether the fields hold the initial guess or the last iterate. The bounded difficulty probe's DIVERGED_MAX_IT is exempt.

The Stokes GAMG-fallback warning used a fixed stacklevel that landed on memprobe's wrapper, and it printed on every rank. It now goes through _warn_from_caller on rank 0.

Where it fires

In the test suite, the cap warning fires in:

  • test_0205, which caps on purpose;
  • test_1018's geometric-FMG test (pressure at 200);
  • the constrained solves in test_1065 and test_1019, and every constrained parallel test (field-1 at 200, one application in four stagnating).

The divergence warning fires in test_0203 (×4, a deadline on purpose) and test_0017 (×2, filtered). A converging homotopy run issues none.

Tests

  • tests/test_1160_a_capped_sub_solve_says_so.py (new, tier B). A velocity cap of 2 warns once, on rank 0 only. The message has the cap value and is attributed to the test file. A loop of solves whose capped counts differ shows it once. estimate_difficulty is quiet, and a solve within its caps is quiet. These mutants each fail it: counts in the message, no probe exclusion, the outer KSP's cap, the old attribution, and warning on every rank (np 2).
  • tests/test_1161_a_diverged_solve_warns.py (new, tier B). A solve that diverges by construction (ksp_divtol 1e-30, so independent of Stokes at viscosity >= 1e11 (PETSc frame): the velocity sub-solve returns NaN at iteration 0 and the solve returns u = 0 #1059's cause) warns once on rank 0, with the reason and "initial guess". A converged solve and a bounded probe's DIVERGED_MAX_IT do not warn.
  • Both pass at np 1, 2 and 4 (hyperion, at 9bc93f7) and fail on development. The bounded-probe case of test_1161 came in round 2; removing the probe's exemption fails it.
  • Serial on wombat: 284 passed over 15 files in the territory. Hyperion: 109 serial and the np 2 solver files are identical on branch and base.

Limits

  • -W error::RuntimeWarning in parallel. Only rank 0 warns, so only rank 0 raises. Uncaught, its exception leaves while the other ranks enter the next collective, and the run hangs. Both warnings are issued after every rank has recorded the solve, so has_solution agrees across ranks. Caught in a try/except, it is clean.
  • The rotated path is not covered. The rotated loop reports its sub-solves in its own diagnostics: a capped pressure sub-solve there is not checked, and only the last velocity application is read (hyperion's review, F4). That is Stokes pressure sub-solve runs at its 200-iteration cap — the inner Schur solve is silently unconverged and dominates solve time #625's remaining part.

Issues

Underworld development team with AI support from Claude Code

…625)

PETSc does not count a sub-KSP that stops at its cap (DIVERGED_ITS) as a
failure, so a Stokes solve can report convergence while its velocity or
pressure block never solved. The Schur operator is applied through the
velocity solve, and a capped velocity block hands the pressure Krylov an
operator that moves between applications. The count was recorded
(solve_report.sub[name].capped, and the transcript's t.capped()), but nothing
said so at solve time.

_warn_on_divergence, which every solver calls after its solve, now first warns
once per capped block. The warning names the solver, the block and its cap,
and points at the report's count and the two remedies. It does not fire
during a bounded difficulty probe, where the caps are the point. The message
carries no counts, so Python's warning filter shows it once per block in a
time loop. Rank 0 warns; nothing collective. No cap value changes.

Measured on the level_1 tier_a suite (1483 passed), the warning fired in
four places:
- test_0205's two deliberately capped solves;
- the pressure block of a Stokes solve in test_0010 (200);
- block 1 of the block-constrained Stokes path in test_1019 and test_1065
  (200), named "field-1" since that path splits by field index.

test_1160 (new, tier B): a velocity block capped at 2 warns exactly once,
naming the block, while the solve still reports convergence; a solve within
its caps is quiet. On development the first fails: the cap is recorded and
nothing is said.

Underworld development team with AI support from Claude Code
hyperion's review of 5bd1481:
- F1: the cap warning is attributed to the caller's solve() line
  (_warn_from_caller); stacklevel=3 landed on memprobe's wrapper, so the filter
  showed it once per process, not per call site. The Stokes GAMG-fallback
  warning had the same fixed stacklevel and gets the same fix.
- F5: the advice says a higher ksp_max_it helps only a block that converges
  slowly; a digit-named block is named by its DM fields (a constrained solve's
  field-1 is the pressure and its multipliers).
- F6: the warnings come after _record_convergence_status, so under -W error
  rank 0 raises only after every rank has recorded the solve.
- F2, F3: test_1160 counts the velocity block's warning, asserts the cap value,
  the attribution, one warning over a loop of solves whose counts differ, quiet
  under estimate_difficulty, and nothing off rank 0. Counts in the message, no
  probe exclusion, the outer KSP's cap and the old attribution each fail it.

#1059: a solve that diverges warns (RuntimeWarning, rank 0, after the record),
naming the reason and whether the fields hold the initial guess or the last
iterate; the bounded difficulty probe's DIVERGED_MAX_IT does not.
test_1161 (tier B) diverges by construction (ksp_divtol 1e-30) and fails
without the warning.

Underworld development team with AI support from Claude Code
… GAMG warning on rank 0

hyperion's review of 9bc93f7:
- N1: test_1161 asserts that estimate_difficulty(1) on a nonlinear box stops at
  DIVERGED_MAX_IT without a divergence warning; removing the probe exemption
  fails it (it survived every test before).
- N3: the Stokes GAMG-fallback warning is issued on rank 0 only, as the solve's
  other warnings; it printed once per rank.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 11, 2026 12:14

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

Copy link
Copy Markdown
Member Author

Review record, round 1 of 2: 5bd1481 (pre-PR)

9bc93f7 answers F1, F2, F3, F5 and F6 (partly); round 2 follows. Paths under review/ are on hyperion, in runs/2026-11-11-585/.


Bundle D review: the sub-solve cap warning (#585, #625)

Branch bugfix/sub-solve-cap-warning-585-625, head 5bd1481, on development 8417977.

Verdict: the mechanism is sound (rank-uniform, no stale reports, the probe exclusion works, no regressions in the sample), but do not merge as is. The warning points at memprobe.py:269 rather than at user code. That also makes "once" process-wide. test_1160 fails at np 2, and it catches none of the four mutants. #625 is not fixed by this change.

Method

  • Branch build: wt-585 (5bd1481), activated with activate.sh 585 r585. Base build: wt-910, whose compiled pyx is 8417977. Development's rotated_bc.py was swapped in at import through probes/site/sitecustomize.py (SWAP_SRC=probes/rotated_bc_dev.py). I checked that the swap is live: the swapped module lacks wt-910's _SchurRoundoffTest, and the unswapped one has it.
  • Tests ran from git archive copies (tests_branch/ at 5bd1481, tests_base/ at 8417977, with test_1160 copied into the base tree). I used PYTHONDONTWRITEBYTECODE=1 and -p no:cacheprovider. MPI ran under mpi_supervisor.py --silence 600. No more than 2 cores were in use at any time.
  • Every issued cap warning was counted before any filter by a pytest plugin, probes/capcount.py. It wraps warnings.warn and records the test, the message and the frame the warning is attributed to.
  • Mutants were installed at runtime by replacing SolverBaseClass._warn_on_capped_sub_solves (probes/mutplug.py). SolverBaseClass is a plain Python class in Cython, so the attribute is looked up dynamically. A silent mutant is caught, which confirms that the harness reaches the code.
  • Probes: p_stack.py (checks 1, 3, 4, probe exclusion), p_loop.py (time loop), p_rot.py (rotated path), p_constrained.py (constrained field-1). They are in review/probes/, with logs in review/logs/.
  • Anything marked [read] was established by reading code, not by running it.

Check 1: np 2, rank 0 only, rank uniformity

probe (p_stack.py, np 2) rank 0 issued rank 1 issued capped on r0 / r1
A: velocity cap 2, 3 cold solves 6 (velocity and pressure, x3) 0 {velocity: 227, pressure: 1} / identical
C, D, E, F (stale, probe, pressure cap 1) as at np 1, rank 0 only 0 identical on both ranks
np 2 parallel solver files (6 files) 4 0 n/a
  • [read] capped is counted in _InstrumentedKSP._after_application, a KSP post-solve hook, from ksp.getConvergedReason() == DIVERGED_MAX_IT. That reason is decided from globally reduced norms, so it is the same on every rank. The measurements agree: the counts are equal on both ranks in every case.
  • [read] The warning code makes no reduction. getFieldSplitSubKSP() and getTolerances() run on every rank, outside the selective_ranks(0) block. Only warnings.warn runs inside it. No rank can take a collective path that another rank skips.
  • Caveat F6 [read]: under a -W error::RuntimeWarning filter, rank 0 raises out of solve() while the other ranks return normally.

Check 2: the rotated path

The probe is a rotated free-slip SolCx box (16x16, tolerance 1e-9, ksponly), serial unless stated. The caps were forced on the live rotated sub-KSPs after _set_absolute_target. Each application's reason was recorded by a post-solve hook.

case velocity apps / capped pressure apps / capped last velocity app RuntimeWarning [rotated_bc] WARNING about a cap solve_report.sub
default 24 / 0 1 / 0 ok 0 0 {}
petsc_options[fieldsplit_velocity/pressure_ksp_max_it] = 2 24 / 0, max_it still 200 1 / 0, max_it 200 ok 0 0 {}
velocity cap 2 7402 / 7402 36 / 35 capped 0 1 (velocity) {}
velocity cap 34 25 / 4 (apps 0, 1, 2, 24) 1 / 0 capped 0 1 {}
velocity cap 38 24 / 2 (apps 0, 1) 1 / 0 ok 0 0 {}
velocity cap 39 24 / 1 (app 0) 1 / 0 ok 0 0 {}
pressure cap 5 28 / 0 4 / 4 ok 0 0 {}
pressure cap 5, np 2 28 / 0 4 / 4 on both ranks ok 0 0 {}
  • The new warning is silent on the rotated path, as expected: that path returns before _warn_on_divergence, and sub is empty.
  • The user's petsc_options caps do not reach the rotated KSP (prefix rotfsN_). The caps there are hard-wired to 200.
  • _warn_if_ksp_diverged reads only the last velocity application. Early capped applications (2 of 24 at cap 38) pass in silence. The pressure sub-KSP is never checked at all: every pressure application capped, and nothing was said.
  • The rotated warnings are mpi.pprint lines, not RuntimeWarnings, so they cannot be filtered or recorded.
  • This is a real gap, worth a follow-up issue. The Stokes pressure sub-solve runs at its 200-iteration cap — the inner Schur solve is silently unconverged and dominates solve time #625 comments of 2026-09-03 (the contact fixtures, with the pressure block at 200 "in every configuration") describe exactly this path, and this change does not reach it.

Check 3: stacklevel and "once"

context file:line the warning shows
plain user script (p_stack.py), both with and without my warnings.warn wrapper memprobe.py:269
pytest summary (test_0205, test_1065, test_1160) .../underworld3/utilities/memprobe.py:269
every cap warning in every run (capcount) memprobe.py:269, 100 %
  • stacklevel=3 is counted from the nearest Python frame, because Cython frames are invisible. That frame is the timing or memprobe wrapper around Stokes.solve, so the warning is attributed to memprobe.py:269 (return func(*args, **kw)), not to the user's call.
  • The same file already has _warn_from_caller, which uses skip_file_prefixes on 3.12 and does this correctly.

Time loop, default filters (p_stack.py A/B; p_loop.py: 6 warm steps with changing forcing, velocity cap 2):

case issued shown
A: one solver, 3 capped solves 3 1
B: a second solver, same cap, a different user line +1 +0
loop: velocity capped every step; pressure starts capping at step 4 12 2 (velocity once, pressure once)
loop with MUT=counts (counts in the message) 12 4 (a new message whenever the counts change)
  • "Once per block" holds within a loop. But it rests on the registry of whichever module the warning is attributed to. Because that is always memprobe.py:269, the effective rule is once per (class, block, cap) text per process.
  • A second, unrelated model in the same script or notebook that hits the same cap is not told (case B). With correct attribution it would be once per call site.

Check 4: stale reports

  • [read] All four families capture the report before _warn_on_divergence runs: SNES_Scalar (pyx 7206 then 7228), SNES_Vector (8269/8299), SNES_MultiComponent (8957/8977) and SNES_Stokes_SaddlePt (12914/12973). The capture is _capture_solve_report in the finally of _snes_solve_with_retries. SNES_Stokes_Constrained.solve delegates to super().solve. The rotated early returns leave before _warn_on_divergence.
  • [read] Instrumentation counters are reset in begin_solve.
case (np 1; np 2 the same) solve 1 capped / warns solve 2 capped / warns
C: velocity cap 2, then cap raised to 1000 {velocity: 17} / 1 {velocity: 0} / 0
D: no cap, then cap 2 {velocity: 0} / 0 {velocity: 17} / 1
E: estimate_difficulty(2) on cap 2, then solve() probe: {velocity: 17} / 0 {velocity: 17} / 1

There are no stale reports, and the probe exclusion works. One note: a warm re-solve from a converged state runs no sub-applications, so sub is {} and it is quiet. That is correct.

Check 5: noise

W1's four files, level_1 tier_a selection, serial:

file branch: new cap warnings base pass
test_0205 4 (velocity 2 and pressure 200, in 2 tests; deliberate) 0 87 passed / 87 passed
test_0010 (both files, the full snapshot file too) 0 (W1 reported pressure at 200; not reproduced) 0
test_1019 (test_cbf_refuses_a_multiplier_constrained_boundary, level_2, run separately) 1, Constrained field-1 (200) 0
test_1065 rotation gauge 1, Constrained field-1 (200) 0

Serial sample of 29 files, level_1: Darcy x3, Poisson, Stokes Cart/Sph/nullspace/multigrid/SolCx, VE, VEP, NS SUPG, advection-diffusion, constrained x3, Nitsche, rotated free-slip, solve_report, guard, penalty, homotopy, Newton cold start, transcript, gauge, rate-strengthening and pc-fallback.

  • Both builds: 99 passed, 110 deselected.
  • New cap warnings: 5 in all. Four are test_0205's deliberate ones. One was unplanned: test_1018_rotated_freeslip.py::test_rotated_freeslip_geometric_fmg_velocity_block, pressure at 200.
  • The ordinary Stokes, Darcy, advection-diffusion and NS tests in the sample were quiet.
  • The serial constrained files (1061 to 1063) were quiet.

np 2, parallel solver files: 0780 VE Stokes, 1062 and 1063 constrained, 1077 advection-diffusion SUPG, 1078 NS SUPG, 1064 rotated.

  • Both builds: 13 passed, 3 skipped.
  • Every constrained parallel test fired "field-1 at 200": 4 warnings, on rank 0 only.

Is the constrained field-1 cap genuine? I measured it with p_constrained.py on the test_1065 annulus, at np 1:

field-1 cap outer field-1 apps / capped velocity its / apps wall
200 (default) converged, 4 outer 4 / 1 12122 / 340 12 s
5000 (the message's advice) converged, 4 outer, same 4 / 1, at 5000 192598 / 5300 135 s
  • The block genuinely does not converge: one of the four applications stagnates below rtol 1e-4.
  • Raising the cap, as the message advises, does not cure it and costs 11x in wall time.
  • So the warning is true but its remedy is wrong for this block. "field-1" also does not tell a user that this is the grouped [p, lambda] Schur block.
  • On the constrained box (Top constraint, other walls Dirichlet) field-1 converges in 17 iterations and nothing fires.
  • No warning was duplicated per block within one solve.

Check 6: test_1160 and mutants

run np 1 np 2
branch 2 passed 1 failed: rank 0 sees 2 messages (velocity at 2 and pressure at 200; the pressure block genuinely caps once at np 2)
base 1 failed (as intended) 1 failed (rank 0)
mutant (branch, np 1) test_1160
silent (harness sanity) caught (1 failed)
control (faithful copy) 2 passed
warn on every rank survives (the assert only runs on rank 0; at np 2 it fails only for the pre-existing reason)
counts in the message survives (one solve; never tests the repeat. p_loop shows it doubles the shown warnings)
no difficulty-probe exclusion survives (the test never calls estimate_difficulty)
cap read from the outer KSP survives (asserts only that "cap" in msg)
cap never found (None) survives

Check 7: regressions and warning filters

  • There is no global filterwarnings or error::RuntimeWarning in tests/pytest.ini (addopts -ra only) or in conftest.py. pyproject has no pytest section.
  • Local simplefilter("error", RuntimeWarning) around solves appears in test_0011 (adv-diff only), test_1069 and test_1071. The last two catch any RuntimeWarning and assert on its text, so a cap warning there would be tolerated. All three pass on the branch.
  • pytest.warns(RuntimeWarning, ...) appears in test_0053, test_1069, test_1071 and test_1079. These are unaffected (an extra warning does not fail pytest.warns).
  • Serial sample and np 2 sample: identical pass counts on branch and base (above). No regression found.

Check 8: issue verdicts

Findings

  • F1 (medium): misattributed warning. stacklevel=3 attributes every cap warning to memprobe.py:269, not to the user's solve call. This holds in scripts and in pytest. The warnings registry therefore dedupes per message text process-wide, and a second model at the same cap is not warned (measured). Fix: inside the rank-0 block, use _warn_from_caller (with skip_file_prefixes).
  • F2 (medium): test_1160 is not partition-robust. It fails at np 2 on the branch, because the pressure block also caps once there. It is not in the parallel phase, so CI is green, but "exactly 1" is a partition-dependent fact. Count velocity-block messages only, or assert one velocity message plus any others.
  • F3 (medium): test_1160 is weak. All four requested mutants survive: every-rank, counts, no probe exclusion, wrong cap. The test should assert:
    • the cap value (2) in the message;
    • quiet during estimate_difficulty;
    • one shown warning over repeated solves under default filters, attributed to the test file;
    • at np 2, no message on rank 1.
  • F4 (medium, follow-up): the rotated path stays silent.
    • Capped pressure applications are never reported.
    • Capped early velocity applications are not reported (only the last application is read).
    • petsc_options caps are ignored, solve_report.sub is empty, and the warnings are prints rather than RuntimeWarnings.
    • Wiring the rotated sub-KSPs into SolverInstrumentation (the code's own TODO) would close it.
  • F5 (low to medium): misleading advice for the constrained block. The field-1 cap fires in every constrained parallel test and in test_1065 and test_1019. It is genuine, but raising the cap as advised does not converge it: 5000 is still capped, at 11x the wall time. The message should not promise that remedy for this block, and should name the block as the [p, lambda] Schur block.
  • F6 (low) [read]: rank-divergent control flow under an error filter. With -W error::RuntimeWarning, rank 0 raises out of solve() before _record_convergence_status and the divergence report, while the other ranks return. Emitting the cap warning after the divergence check, or after _record_convergence_status, would make it less intrusive.
  • F7 (low): W1's firing list does not match what I measured. test_0010 did not fire here. test_1018 (geometric FMG, pressure 200) and every constrained parallel test did fire, and they are not in W1's list. Fix the commit message.
  • F8 (info): rank uniformity, stale-report safety and the probe exclusion are all confirmed by measurement. No cap values changed.

Merge conditions

  1. Attribute the warning to user code (F1). Re-measure that the file:line is the caller's.
  2. Make test_1160 np-robust (F2) and strengthen it until the every-rank, counts, no-probe and wrong-cap mutants are caught (F3).
  3. Change the commit message to "Refs Stokes pressure sub-solve runs at its 200-iteration cap — the inner Schur solve is silently unconverged and dominates solve time #625". Use "Fixes Stokes velocity KSP truncates silently at its default 200-iteration cap #585" only if a rotated-path follow-up issue (F4) is filed. Correct the firing list (F7).
  4. Recommended, not blocking: reword the advice for the constrained field-1 block (F5), and move the call after the divergence check (F6).

Queued for np 4

review/queue_np4.sh (not run):

  • test_1160 at np 4;
  • p_stack.py at np 4;
  • p_rot.py at np 4 with velocity cap 38 and pressure cap 5;
  • the six parallel solver files at np 4, on branch (with capcount) and on base.

Not tested

  • np 4 (queued).
  • The whole level_1 suite (sampled instead).
  • Jupyter or IPython display of the warning.
  • The memprobe.ENABLED=True attribution (by reading, it would be another memprobe line).
  • The ptest_0202 and ptest_0203 parallel scripts: they are not pytest-collectable and were not run as scripts.
  • The rotated path's own mpi.pprint at np 2 was seen on rank 0 only, but I did not examine it further.
  • -W error::RuntimeWarning at np > 1 (F6 is from reading).

Addendum: tests that diverge on purpose (for W1's #1059 divergence warning)

W1's next change makes _warn_on_divergence issue a RuntimeWarning for any negative SNES reason. It keeps the printed notice and the -5 exemption for difficulty probes.

How I built this list:

  • I grepped tests_branch/tests (5bd1481) for getConvergedReason() <, reason < 0, == -N, converged is False, assert not ...converged, has_solution is False, DIVERGED, tolerate_ and "diverged".
  • I then read each hit's warning context.
  • Pass status comes from my sample runs where the file was in them (0203, 1057, 1058). Everything else in this section is [read].
file::test expected reason reaches _warn_on_divergence? filter in force would a new RuntimeWarning break it?
test_0017_solve_outcome_transcript::test_a_diverged_solve_is_recorded_as_diverged Poisson, SNES DIVERGED (ksp_max_it 1, snes_max_it 1) yes simplefilter("ignore") around model.step no. Ignored warnings never reach the step's showwarning shim, so no "warning" event is added.
test_0017::test_the_text_transcript_says_diverged_in_the_outcome_column same yes simplefilter("ignore") no
test_0203_solver_wallclock_guard::test_exhausted_budget_stops_the_solve_and_reports_it -3 DIVERGED_LINEAR_SOLVE (guard deadline) yes none (pytest default) no. It adds one warning per test to the summary.
test_0203::test_deadline_bites_inside_the_fieldsplit_blocks not converged (deadline) yes none no (one more warning)
test_0203::test_a_guard_armed_before_the_first_solve_still_fires not converged (deadline) yes none no (one more warning)
parallel/ptest_0203_wallclock_guard_parallel.py (script) not converged (deadline), every rank yes none (plain script) no. Depending on the rank rule, rank 0 or every rank warns.
test_1057_yield_homotopy_solve (the test at line ~270, cold_reason < 0) negative: cold sharp-Min solve under the frozen tangent yes none no. The later homotopy stages may also warn on internal failed attempts. That is noise, not a failure (not measured).
test_1058_solve_report::test_estimate_difficulty_bounded -5, under a difficulty probe yes none no. The -5 exemption applies.
test_1058::test_resume_is_lossless_and_same_termination -5 then converged yes (probe) none no (exempt)
test_1115_rotated_solve_raises_on_failure (6 tests: -11 cold raise, tolerate_linear_failure, warm keep, datum, fault -9) KSP -11 / -9 on the rotated path; snes.getConvergedReason() < 0 at line 108 no. Rotated solves return before _warn_on_divergence (pyx 8235 and 12822) pytest.raises(RuntimeError) only no (unaffected)
test_1136_rotated_loop_honours_snes_max_it (cap 3, 0, -1) DIVERGED_MAX_IT (-5) on the rotated loop no (rotated) none no (unaffected; level_2)
test_0201 / ptest_0202 has_solution is False before the first solve, or after a rebuild; not a divergence no none no

Tests where a warning would interact with a filter:

  • simplefilter("error", RuntimeWarning) is used in test_0011 (two tests), test_1069 and test_1071. None of them expects divergence.
    • test_0011's solves are advection-diffusion and converge. A divergence warning there would fail the test. test_0011:276 and :313 also assert the exact list of event kinds in the step, so any warning event would break them.
    • test_1069 and test_1071 wrap s.solve() in try/except RuntimeWarning and assert only that a specific text is absent. If their solve ever diverged, the new warning would raise out of solve() and the test would still pass, hiding the divergence. All three passed on the branch serially, so their solves converge today.
  • pytest.warns(RuntimeWarning, match=...) is used in test_0053, 1069, 1071 and 1079. An extra warning does not fail pytest.warns, and none of these expects divergence.
  • No filterwarnings in pytest.ini, conftest or pyproject; no global -W error.

Verdict for W1: no test that diverges on purpose runs under an error filter. The new warning breaks nothing in this list.

  • It adds about 4 warnings to the summary (0203 x3, 1057 x1; 0017 stays silent because its warnings are ignored).
  • The rotated failure tests (1115, 1136) never reach _warn_on_divergence. So Stokes at viscosity >= 1e11 (PETSc frame): the velocity sub-solve returns NaN at iteration 0 and the solve returns u = 0 #1059-style rotated divergences stay as printed notices unless the rotated path is wired in too (same gap as F4).
  • The caution from F6 applies again: under an error filter at np > 1, a rank-0-only warning raises on rank 0 alone. A divergence warning should therefore be issued uniformly.
  • Not measured: unintended divergences inside passing tests (for example internal homotopy or continuation attempts). pytest captured stdout, so the existing "SNES solve diverged" notice is not in my logs to count. Counting them needs a run with a capcount-style plugin keyed on the new message.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Review record, round 2 of 2: 9bc93f7

9ebb02c answers N1 (the probe-exemption test), N3 (the GAMG fallback under rank 0) and F7 (issue keywords; the rotated-path gap is kept in #625). A check of 9ebb02c follows. Paths under review2/ are on hyperion.


Bundle D review, round 2 (9bc93f7)

Branch bugfix/sub-solve-cap-warning-585-625. Round 1 reviewed 5bd1481; this round reviews 9bc93f7 on top of it. The base is development 8417977: wt-910 with development's rotated_bc.py swapped in, as in round 1.

Verdict: mergeable with two small conditions.

Method

  • Tests ran from git archive copies: review2/tests_branch at 9bc93f7, and review2/tests_base at 8417977 with test_1160 and test_1161 copied in. I used PYTHONDONTWRITEBYTECODE=1 and -p no:cacheprovider, and ran MPI under mpi_supervisor.py. No more than 4 cores were in use at once.
  • Mutants: review2/probes/mutplug2.py replaces _warn_on_capped_sub_solves and _warn_on_diverged_solve at runtime. The mutant frames live in the probes directory, so their warnings skip that directory as well as the package's. Otherwise every mutant would fail the new filename assert for the wrong reason.
    • Harness checks: the faithful copy (control) passes, and silent is caught.
  • Counting: capcount.py, extended for this round. It records every issued cap, divergence and GAMG-fallback warning with the frame it will be attributed to. It adds its own directory to skip_file_prefixes, so it does not change attribution: test_1160 and test_1161 pass with it loaded.
  • Probes: p_attr.py (attribution, case B, per-rank counts), p_werror.py (F6), p_constrained.py (F5). Logs are in review2/logs/.

Check 1: mutants

mutant np 1 np 2 caught by
control (faithful copy) pass pass (harness)
silent caught caught 1160 cap, loop
cap: warn on every rank survives (expected at np 1) caught 1160 test_a_velocity_block_at_its_cap_warns, rank 1
cap: counts in the message caught caught 1160 loop
cap: no probe exclusion caught caught 1160 probe
cap: cap read from the outer KSP caught caught 1160 cap ((2))
cap: old attribution (warnings.warn, fixed stacklevel, lands on memprobe) caught caught 1160 cap (filename)
div: control pass pass (harness)
div: warn on every rank survives (expected at np 1) caught 1161 diverged, rank 1
div: no -5 probe exemption survives survives none
div: call removed caught caught 1161 diverged

The exemption is live but untested. With the no-exemption mutant, test_1058's test_estimate_difficulty_bounded and test_resume_is_lossless_and_same_termination each issue "the solve diverged (DIVERGED_MAX_IT)", and both still pass. On the branch they are quiet. A test asserting no divergence warning under estimate_difficulty, with reason -5, would catch it (N1).

Check 2: test_1160 and test_1161 at np 1, 2 and 4

build np 1 np 2 (per rank) np 4 (per rank)
branch 9bc93f7 6 passed 6 passed / 6 passed 6 passed x 4
base 8417977 3 failed (both 1160 cap tests, 1161 diverged) rank 0: 3 failed; rank 1: 6 passed rank 0: 3 failed; ranks 1–3: 6 passed

F2 is fixed: the np 2 failure from round 1 is gone, and np 4 passes too.

Check 3: attribution

Plain script (p_attr.py), default filters, user lines A (a loop of 3 capped solves), B (a second solver at the same cap), D (divergence) and G (GAMG fallback):

memprobe / timing cap divergence GAMG fallback case B shown?
off / off p_attr.py:37 (A), :39 (B) p_attr.py:42 p_attr.py:44 yes
on (UW_MEMPROBE=1) / off :37, :39 :42 (not run separately) yes
off / on (uw.timing.start()) :37, :39 :42 (not run separately) yes
on / on :37, :39 :42 :44 yes
  • The loop at line A issued 3 times and was shown once.
  • In pytest, every warning is attributed to the test file's own solve line:
    • test_1160.py:58 and :79;
    • test_1161.py:49 (divergence and GAMG fallback) and :67;
    • test_0203.py:178, test_0017.py:80, test_1018.py:43, test_0205.py:45, test_1063_parallel.py:123, and so on.
  • There were no memprobe or timing frames in any run.
  • F1 is fixed, and case B now gets its own warning.

Check 4: the GAMG-fallback warning at np 2

rank GAMG fallback shown cap divergence
0 1 4 1
1 1 0 0
  • The GAMG fallback is printed once per rank, so stderr has 2 copies at np 2, and it would have N at np N. It is the only warning of the three without a rank-0 guard.
  • Inside a pytest run the summary collapses the copies (4 per rank in the np 2 parallel files).
  • Minor (N3): guard it like the other two, or note that it is per rank on purpose.

Check 5: F5 wording, and F6 under -W error at np 2

F5, on the test_1065 annulus at np 1:

SNES_Stokes_Constrained: the field-1 (pressure + multiplier_0 + multiplier_1) sub-solve stopped at its iteration cap (200) without converging, so the solve's convergence does not mean that block solved. Counts in solve_report.sub['1'].capped. A higher fieldsplit_1_ksp_max_it helps only a block that converges slowly; one that stagnates needs a better preconditioner (#585, #625).

  • The block is now named, and the advice no longer promises that a higher cap helps. On this block, which stagnates, the round-1 measurement was 5000 still capped at 11x the wall time.
  • In the np 2 constrained files the label reads pressure + multiplier_0 + ... + multiplier_3 where there are four constraints. That is accurate, but long.
  • F5 is fixed.

F6 (p_werror.py, np 2, python -W error::RuntimeWarning):

case rank 0 rank 1 has_solution after (r0 / r1) next collective outcome
cap, solve in try/except raises the cap warning returns True / True integral ok; second solve ok clean, rc 0
divergence, in try/except raises the divergence warning returns False / False integral ok clean, rc 0
cap, uncaught exception escapes; at exit stuck in MPI_Allreduce enters Integral.evaluate and is stuck in MPI_Allgather n/a deadlock the supervisor found no output for 90 s, reported the ranks in different collectives and killed the job (rc 124)
  • Every rank now reaches _record_convergence_status before the raise. That part of F6 is fixed: has_solution agrees across ranks.
  • Rank 0 still raises while the others return. When the exception is uncaught, an np 2 job hangs rather than aborting (N2).
  • The same applies inside pytest under -W error: rank 0 fails the test at the solve, while rank 1 carries on to the test's later collectives.
  • Rank-0-only output and rank-symmetric control flow cannot both hold under an error filter. Warning on every rank would make the raise uniform, but it repeats the text N times (the GAMG fallback already does that).
  • I recommend documenting this limitation rather than blocking the merge. -W error is opt-in.

Check 6: #1059 noise and accuracy

New divergence warnings issued (capcount counts them before any filter):

run divergence warnings where diverges on purpose? accurate?
serial sample (31 files, 109 tests) 6 test_0203 x4 (guard cut: DIVERGED_LINEAR_SOLVE, "initial guess"); test_0017 x2 (SNES_Poisson DIVERGED_LINEAR_SOLVE, "initial guess"; the test sets simplefilter("ignore"), so neither is shown) yes, all six yes. A cut or failed first linear solve leaves gvec at the guess.
test_1057 homotopy rescue (level_2, run separately) 1 the deliberate cold solve at line 286: DIVERGED_MAX_IT, "last iterate" yes yes. The homotopy march that follows, which converges in the end, issued none.
np 2 parallel files (6) 0 none n/a n/a
test_1058 bounded probes 0 (6 under the no-exemption mutant) none (exempt) n/a
  • Continuation and Picard tests in the sample (1068, 1071, 1067, 1052) issued none.
  • No retry or homotopy path warned for an attempt it later recovered from. The noise is acceptable.
  • Not covered, as before: the rotated path. Its failures still return before these calls (pyx 8235, 12822), and the docstring now says it covers the native path only.

Check 7: regressions

run branch 9bc93f7 base
serial sample, level_1 (31 files: Darcy, Poisson, Stokes, VE/VEP, NS, advection-diffusion, constrained, Nitsche, rotated, solve_report, guard, penalty, homotopy, Newton, Picard, transcript x2, gauge, rate-strengthening, pc-fallback, 0205) 109 passed, 63 warnings 109 passed, 37 warnings
np 2: 0780, 1062, 1063, 1077, 1078, 1064 13 passed, 3 skipped (both ranks) 13 passed, 3 skipped

The branch has 26 more pytest summary entries than the base. 11 of the issued warnings are new: 6 divergence and 5 cap. The GAMG fallback was issued 64 times on each build. On the base those were attributed to memprobe.py:269, and on the branch they are attributed to each test's own line. I did not break the summary delta down entry by entry. No regressions.

Status of the round-1 findings

finding status evidence
F1 attribution / once per process fixed user file:line in every context; case B shown
F2 test_1160 at np 2 fixed 6 passed at np 2 and np 4
F3 test_1160 weak fixed all five cap mutants caught (every-rank at np 2)
F4 rotated path silent open (follow-up) unchanged; the docstring now scopes it out and points at #625. File it as its own issue.
F5 constrained advice and name fixed wording above
F6 rank-divergent raise under -W error partly fixed status recorded on every rank; uncaught raise at np 2 still deadlocks (N2)
F7 commit message accuracy and issue keywords open, trivial 9bc93f7 has no Fixes/Refs keywords and does not correct 5bd1481's firing list. The PR body should carry "Fixes #585 (native path), Refs #625, Fixes #1059", plus the rotated follow-up.

New findings

  • N1 (low, merge condition): test_1161 does not cover the -5 difficulty-probe exemption. The no-exemption mutant passes 1160, 1161 and 1058. Add one probe case asserting no "the solve diverged" warning.
  • N2 (low, document): under -W error::RuntimeWarning at np 2, an uncaught rank-0 cap or divergence warning deadlocks the job: rank 0 in Allreduce at exit, rank 1 in the next collective. This was measured and killed by the supervisor. It is inherent to rank-0-only warnings.
  • N3 (minor): the GAMG-fallback warning is shown once per rank (N copies at np N), unlike the cap and divergence warnings.
  • N4 (info): the constrained block label lists every multiplier field (up to multiplier_3 here), which grows long with many constraints. It is accurate.

Issue verdicts

Not tested

Underworld development team with AI support from Claude Code

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Check of 9ebb02c (head now 189ca99, a merge of development)

189ca99 merges development into 9ebb02c. Against its merge-base with development, the branch still touches only D's five files: the .pyx, solvers.py, test_1160, test_1161 and test.sh. So this check of 9ebb02c covers the code.


Bundle D (PR #1062), check of 9ebb02c

The change from 9bc93f7 is in solvers.py (the GAMG-fallback warning) and test_1161 (a new bounded-probe case). Tests ran from a git archive copy of 9ebb02c (review2/tests_r3) on the rebuilt wt-585, with at most 2 cores in use.

Verdict: N1 and N3 are closed, and nothing regressed. From this check's side, 9ebb02c is fine to merge. F4 (the rotated path) and N2 (a rank-0-only raise under -W error) remain as recorded in d-review2.md.

check np 1 np 2 result
test_1160 + test_1161 (7 tests) 7 passed 7 passed on each rank pass
N1: test_a_bounded_probe_at_its_cap_does_not_warn on the branch passed passed on each rank pass
N1: no-exemption mutant vs test_1161 caught (bounded probe fails) caught (rank 0 fails) closed
divergence mutant: control 3 passed 3 passed on each rank harness ok
divergence mutant: warn on every rank survives (expected at np 1) caught (test_a_diverged_solve_warns, rank 1) as before
divergence mutant: call removed caught caught as before
N3: GAMG fallback, per-rank count (p_attr.py) n/a rank 0: 1, rank 1: 0; 1 copy on stderr closed
N3: GAMG fallback attribution n/a p_attr.py:44 (the user's solve line) ok
other warnings in the same run (np 2) n/a rank 0: cap 4, divergence 1; rank 1: none unchanged
solvers.py diff [read] no collective inside the rank-0 block

On the solvers.py diff: the message's inputs (installed, cost) are computed before the with uw.selective_ranks(0) block. The block contains only _warn_from_caller, which calls warnings.warn and does no MPI or PETSc work. Every rank reaches the with statement.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit f72c3d2 into development Nov 11, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 11, 2026
The finite-difference test builds each SNES with a solve stopped at 0
iterations, which since #1062 warns that the solve diverged. The test now
expects that warning, so it runs clean under -W error::RuntimeWarning.

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