Skip to content

One convergence reference for every solver: warm starts, the linear floor, the rotated loop (#911, #985, #924) - #1014

Merged
lmoresi merged 19 commits into
developmentfrom
feature/convergence-reference-policy
Nov 8, 2026
Merged

lmoresi merged 19 commits into
developmentfrom
feature/convergence-reference-policy

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member

Every solve now measures one convergence reference and two targets, on the native routes and in the rotated free-slip loop alike (#911, #985, #924). The design is docs/developer/design/CONVERGENCE_REFERENCE_POLICY_2026-11.md.

The problem

  • Warm starts. PETSc measures a nonlinear solve relative to the residual of the guess it starts from. A warm start near the answer was asked for tolerance of an already small residual and kept iterating.
  • Linear solves inside Newton. Each was asked for a fraction of its own right-hand side. On the last step of a tight solve that fraction is below round-off: test_0022's rotated solve ran its last increment into a 300-iteration cap, which took 18 to 52 minutes on CI (test_0022 takes 18 to 52 minutes by BLAS kernel: its last Newton step solves past round-off, with pressure at its cap #985).
  • Louis, 2026-11-07: "the equation knows what to define as the residual and the solver should be more mechanical about applying the rules."

The change

The nonlinear target is T = max(tolerance * max(||F(x0)||, R), atol). R is what the equation declares in _reference_residual:

  • ||F(0)|| for a stationary equation, so a warm start or a continuation step is held to the cold start's target;
  • 0 for a solve with memory: a time step through a DDt, a viscoelastic step (Louis, 2026-11-08: "Yes");
  • 0 for a weakly imposed nonzero datum, Nitsche or a penalty (_weak_datum), whose F(0) measures the penalty;
  • solver._convergence_reference_rule = "increment" or "stationary" overrides the declaration.

The linear floor. Each linear solve stops at 0.1 * T, and always cuts its own residual at least tenfold.

  • Native routes. It is a convergence test composed with PETSc's own, on the outer KSP. It is scaled into the KSP's norm, and the true residual is confirmed on a preconditioned norm. The test shares petsc4py's one Python test per KSP with the wall-clock guard (utilities/ksp_convergence_tests).
  • Left alone. A ksp_rtol that tolerance did not derive, and Eisenstat-Walker, which still sets the saddle point's rtol.
  • Rotated loop. The outer FGMRES takes an absolute tolerance. The fieldsplit sub-KSPs keep their configured rtols, scaled by how far the floor relaxed the outer target.

The rotated loop follows the same reference rule, and honours a user-set snes_rtol, snes_atol and snes_stol (#924).

Tests at their tolerance (Louis, 2026-11-08: "Remove the redundant work, set a reasonable tolerance."):

  • test_1057's evaluate bound is now its projector's 1e-6;
  • test_0009's warm ratio is now 1e-4;
  • the changelog records what users see in evaluate().

Edge cases found and fixed on the branch

  • The floor as a KSP atol was in the wrong norm. GMRES with left preconditioning measures the preconditioned residual, about 40 times smaller, so a Newton step's linear solve stopped at iteration 0.
  • The floor as a KSP pre-solve replaced Eisenstat-Walker, which is PETSc's pre-solve.
  • A round-off bound on the floor overstated round-off at least 300 times, and stalled test_1136's Picard box.
  • The max rule in time loops was 20 to 70 times less accurate (test_0008). That led to the memory rule.
  • A Nitsche-driven lid was 70 to 1300 times less accurate on a warm re-solve. That led to the weak-datum rule.
  • From hyperion's review:
    • H1: an absolute floor on the rotated sub-KSPs moved the fault slip 2.2e-4 (test_1087, test_1089), and made every zg95 step a zero update on kaiju.
    • M1: the datum was read by value.
    • M2: the floor stopped on the preconditioned estimate.

Evidence

Serial, wombat (full tier A/B: 2940 passed; only test_0063 fails, and it fails on development too):

case development this branch
test_0022 (rotated, tol 1e-11) 758 s; last increments 300 (cap), 32, 12 linear its 13.6 s; 1 linear it each
time loop, test_0008's box, 300 steps at tol 1e-4 against 1e-12 error 1.36e-6 1.45e-6 (max rule: 9.07e-5)
Nitsche lid, warm re-solve after a 1 % change, tol 1e-4 5.2e-6 to 5.9e-6 the same (max rule: 3.6e-4 to 7.7e-3)
warm nonlinear Poisson re-solves, Newton steps 2 1
test_1087 / test_1111 (rotated FMG, single increment) baselines the same iterations and answers

test_0022's four arms (tol 1e-11; the two numbers are the two fixtures):

change converges time
none (development) no, the last step stalls 55 / 254 s
pressure rtol 1e-2 only no 110 / 107 s
linear floor only yes 6.6 / 2.1 s
both yes, 4 pressure its a step 2.0 / 0.6 s

The pressure rtol default is a separate branch and is not included here.

Kaiju (K2), np 16. The zg95 faulted annulus, restarted from the TAf-v2 step-25 checkpoint for 10 steps:

development 06c574e this branch
converged steps 10 of 10 10 of 10, 0 cold retries
Newton its, total 48 47
vel / pres KSP mean 7.0 / 21.8 5.8 / 17.4
s/step, median 191 138 (same node; indicative)
  • vrms agrees to 1e-6 to 1.4e-5 before a fault rebuild, and to 2e-4 to 1.3e-3 after it.
  • The solver tolerance is 1e-3, and identical code drifts by up to 4e-4 through rebuilds.
  • Events, fault counts, dt and geometry are identical.
  • The plain Spiegelman notch, a cold solve at ref 1 and 2, is identical on both builds: 5 and 6 Newton its, 168 and 253 KSP its, the same band widths.

The viscoelastic rotated case (ruling 2, for Louis): a VEP annulus, 40 steps of 0.1 Maxwell times at tolerance 1e-5, against a 1e-8 run.

rule Newton its wall error at steps 10 / 20 / 30 / 40
increment (the default) 67 37.7 s 7.3e-8 / 8.9e-7 / 9.7e-7 / 7.8e-7
stationary (max) 42 33.2 s 1.1e-5 / 3.9e-6 / 5.6e-6 / 5.4e-6

Parallel, hyperion, np 2 and 4 (scripts/test.sh --parallel-only --p 2 --full-parallel): all passed, rc 0.

  • test_1089 and test_1139 pass. On 43857a5 they failed, with slip 2.2e-4 off and 6 iterations against ≤ 5.
  • The floor and guard decisions, and the per-increment tolerance trace, are identical on every rank at np 1 to 4.
  • The relaxed later increments of a rotated power-law annulus land within 0.01 to 0.1 of the tolerance at np 1, 2 and 4.

Behaviour users will see

  • An answer is as accurate as tolerance asks, and no more: a linear solve no longer gets a second, exact Newton step for free. evaluate() of an expression with derivatives returns its projector's 1e-6.
  • A stationary equation re-solved in a time loop under slowly changing forcing can take no step while the change stays inside T. Its answer then lags the forcing by up to the tolerance. Stokes already did this on development.
  • Both points are in the design note and the nonlinear-solver guide.

Reviews

  • Hyperion's review of 43857a5 found it not ready (H1, M1, M2, M3). Its re-check of 26e4031 finds it ready to merge, with one low (N1: an expression re-pointed in place keeps its cached datum verdict, now documented with the override) and a doc nit (fixed). Both records are comments on this PR.
  • The kaiju arms were run by K2; their records are in K2's DEV-RUNS.md, entry 95.

Issues

Underworld development team with AI support from Claude Code

For Louis's review before any code ("PETSc does not respect the original
residual of the solve when we warm start. We should try to find a DRY
solution"). It covers:
- one reference per solve() call, max(|F(x0)|, |F(0)|), with rules for a
  datum-only forcing and a null space;
- the nonlinear target T from the user's tolerances;
- an inexact-Newton absolute floor eta*T on the outer and fieldsplit
  linear solves, bounded by the round-off floor;
- one helper on SolverBaseClass, called from _snes_solve_with_retries and
  the rotated loop, replacing five separate references;
- the PETSc mechanisms (SNES and KSP atol; UIRNorm not needed; EW kept);
- the issues it settles (#911/#985, #924, #883, #884, and the pressure
  rtol overlap);
- the four-arm evidence plan.

It rests on hyperion's inventory on #911 and on a probe of test_0022's
rotated solve.

Underworld development team with AI support from Claude Code
The viscous stress vanishes at zero strain rate for any finite eta(0), so
the viscosity cap or regularisation does not enter F(0)'s interior rows;
what remains is the forcing, as a cold start measures it today. The one term
that carries the cap is a nonzero weakly imposed velocity (gamma mu(0)/h g);
for that case the reference leaves the weak boundary terms out. The evidence
plan adds the notch, a zg95 viscoplastic run and a weak nonzero velocity, and
records |F(x0)|, |F(0)| and the forcing-only norm on each.

Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
Every native solve goes through _snes_solve_with_retries, which now calls
_apply_convergence_reference: F_ref = max(|F(x0)|, |F(0)|), the SNES atol
T = max(rtol F_ref, atol), and the outer KSP atol eta T (eta 0.1), restored
after the solve. The saddle-point warm start's tolerance * |F(guess)| atol
and its zero-iteration nrichardson pre-solve are gone. The probe's resume
anchor takes the larger of its anchor and T.

test_0028 (tier B): a nonlinear problem solved cold, then warm after a 1 %
change in forcing, stops at the first iterate inside T on the saddle-point
and scalar routes. On development the scalar warm solve passed T (9.3e-6
against 2.7e-4) and took one more step.

The rotated loop, sub-KSP floors and the remaining references are the next
stages; the evidence arms are still to run.

Underworld development team with AI support from Claude Code
…e_residual

The reference residual is a hook the equation owns, ||F(0)|| with the boundary
data in place by default; an equation whose F(0) carries what no iterate
measures (a weak nonzero velocity, a datum lift, a projected null space)
overrides it. _apply_convergence_reference only measures the solve's own
|F(x0)| and applies the rules, the same way on every route.

Underworld development team with AI support from Claude Code
… same per-call target

Underworld development team with AI support from Claude Code
…orkspace

Underworld development team with AI support from Claude Code
…ear floor is relative

An equation whose residual carries the last step's answer through a history (DuDt or
DFDt) declares a zero reference, so a time step stops at rtol of its own first
residual, PETSc's default. Under max(||F(x0)||, ||F(0)||) a step short against the
diffusion time stopped near rtol of the whole field. _convergence_reference_rule
overrides the declaration on a solver, so both rules can be measured while the ruling
is pending.

The linear floor was a KSP atol in ||F|| units. GMRES with left preconditioning
measures the preconditioned residual, about 40 times smaller on the scalar route, so a
Newton step's linear solve stopped at its first residual and the SNES ended on a zero
step above its target. The floor is now set before each linear solve as a reduction of
its own first residual, eta T / ||F(x_k)||, which is right in either norm.

test_0028 gains a nonlinear advection-diffusion time step; both the max rule and the
absolute floor fail it.

Underworld development team with AI support from Claude Code
…a relative reduction

Underworld development team with AI support from Claude Code
…g 2026-11-08)

Underworld development team with AI support from Claude Code
…eaves set rtols alone

The floor as a KSP pre-solve replaced PETSc's own: on the saddle-point route
Eisenstat-Walker is KSPPreSolve_SNESEW, so the floor switched EW off, and clearing the
hook after the solve left it off. The floor is now appended to the outer KSP's
convergence test (once per KSP, the solver held weakly), scaled into the KSP's own norm
by the ratio of its first residual to ||F(x_k)||. EW sets the rtol and the floor bounds
it from below, as the design intends.

The floor replaces only the ksp_rtol that tolerance derives (_TOLERANCE_DERIVED_KEYS, or
0.1 tolerance on the routes without the table). A linear rtol set by the user, or by
the library for a solve it wants tight, stays in force: five suite tests that set
ksp_rtol 1e-8 to 1e-10 had their answers loosened to the nonlinear target.

test_0028: Eisenstat-Walker's rtol_0 reaches the first linear solve, and a set
ksp_rtol is not loosened. The pre-solve floor and the absolute floor each fail one.

Underworld development team with AI support from Claude Code
…ence-reference-policy

Underworld development team with AI support from Claude Code
…911)

The rotated Newton loop took max(r0, ||F(0)||) on every warm start. It now asks the
solver (_resolved_reference_rule): a stationary equation keeps the max, and one with
memory, a viscoelastic step, measures its own first residual.

Each increment's linear solves, outer and fieldsplit, stop at the floor
max(0.1 T, 10 eps |A|_F |u|), T the loop's own target (from the paused
bugfix/rotated-inexact-newton-911 patch, on the vector route too). Every rotated KSP is
FGMRES, which measures the true residual, so the floor is an absolute tolerance there.
test_0022 goes from 758 s to 13.6 s on wombat: its last increments' linear solves took
300 (the cap), 32 and 12 iterations, and now take 1.

Underworld development team with AI support from Claude Code
test_0022's forward problem at the parameter its finite difference takes, a
transversely isotropic power law in an annulus under rotated free slip at tolerance
1e-11. With the increment floor its linear iterations are [1, 2, 1, 1, 1, 1] and it
passes in 7.6 s; with the floor removed at run time it ends with SNES reason -6
after 96 s. The design note records the rotated stage, and that #964's projection
threshold keyed on the tolerance is the per-call one while the rotated atol is fixed.

Underworld development team with AI support from Claude Code
…NES tolerances (#924)

- The linear floor and the wall-clock guard each need petsc4py's one Python
  convergence test per KSP; with both, the guard raised "converged callback already
  set" (test_0203). utilities/ksp_convergence_tests prepends one dispatcher per KSP
  and both register in it.
- The rotated increment floor drops its round-off term, 10 eps |A|_F |u|, which
  overstated round-off at least 300 times: on test_1136's Picard power-law box it
  stalled the loop at 3.4e-9 against a target of 1.1e-11 (a zero step, line search
  failed), where development converges in 60 increments. The floor is now
  min(0.1 T, 0.1 |b|), the native rule: every increment cuts its residual at least
  tenfold. The box converges in 60 again, test_0022's forward problem in 6.
- A NaN or infinite target leaves the tolerances alone, so the solve fails on the
  residual with its own reason (test_1115: PETSc error 63 instead of reason -9).
- #924: the rotated loop takes a user-set snes_rtol (through the saddle point's
  owned-option record, as snes_max_it), snes_atol and snes_stol. test_1143, tier B,
  fails on the build before: the loop ran past a user rtol of 1e-3, and took 7
  increments under a user atol ten times the cold residual.

Underworld development team with AI support from Claude Code
…lerance (ruling)

A boundary term that depends on the unknowns and is nonzero at rest, a Nitsche or
penalty condition with a nonzero datum, puts the penalty times the datum into F(0),
at the coefficient at rest. On a Nitsche-driven power-law lid ||F(0)|| grew with the
viscosity at rest (118, 548, 2540) and a warm re-solve held to it was 70 to 1300 times
less accurate than under PETSc's test (3.6e-4 to 7.7e-3 against 5.2e-6 to 5.9e-6).
_weak_datum reads the boundary terms symbolically (the unknowns and their gradients
set to zero; a datum in a constant counts) and such an equation measures its
increment. The warm re-solves now match development's. test_0028: the warm lid stops
at the first iterate inside rtol of its own first residual (fails under the max
rule), and a zero-datum Nitsche condition and a traction are not a datum.

Louis's ruling on accuracy that came from over-solving: "Remove the redundant work,
set a reasonable tolerance." Tests assert at the accuracy their solver is asked for:
- test_1057: evaluate()'s projector is asked for 1e-6, so the bound is 1e-6 of the
  value, not 1e-10;
- test_0009: the warm ratio at the tolerance, 1e-4, not 1e-6;
- test_1111: iterations re-recorded at tolerance 1e-6, (3, 6) and (4, 14) for (4, 7)
  and (5, 17); the shell's v_rms at 1e-6 (it lands 3.9e-7 from the SVD value);
- test_1087 counts the cycle with the rotated floor off (_INCREMENT_TARGET_FRACTION =
  None): under the floor the sub-solves stop at the Newton target and the count
  follows it (4 and 6), not the cycle (5 and 5).
The changelog records the policy and what users see in evaluate().

Underworld development team with AI support from Claude Code
H1. The rotated floor's absolute tolerance on the fieldsplit sub-KSPs was in the outer
residual's units: on test_1087's single increment the pressure solve stopped at 6
iterations in place of 15 and the fault slip moved 2.2e-4 at tolerance 1e-6, where
development is 2.7e-7 off. The sub-KSPs now keep their configured rtols, scaled by how
far the floor relaxed the outer target, (0.1 T / |b|) / rtol, never below 1 and capped
at 0.1. A first increment is solved exactly as on development: test_1087 and test_1111
pass with development's own baselines again (the rebaselines and test_1087's floor-off
switch are reverted), and test_0022's last increments still relax. The configured
tolerances live on the context and come back when the floor is switched off.

M1. _weak_datum read the datum by its value, so a lid ramped up from zero, or a Robin
ambient set later, was cached as no datum. Every UW expression whose value is a number
is now held as a symbol before the term is unwrapped (keep_constants is ignored by
the unwrapper); the cache key is the terms' hashes, not only the BC ids. test_0028
ramps a lid from zero and sets a Robin ambient from zero; the value-based reading
fails it.

M2. On a preconditioned norm the native floor stopped on its scaled estimate, which
left the true residual above the floor and cost Newton a step. When the estimate says
stop it now builds the true residual once and stops only under the floor. Warm
nonlinear Poisson re-solves take 1 Newton step against development's 2 (wombat,
serial). A KSP with no norm gets no floor.

M3 and the design note: a stationary equation re-solved in a time loop lags its
forcing by up to the tolerance; documented in the design note and the nonlinear-solver
guide, with the override. The note's sections on the floor, the rotated loop, the weak
datum and the KSP mechanism now say what the code does.

Underworld development team with AI support from Claude Code
… target formula in the docs

Hyperion's re-check of 26e4031: an expression re-pointed in place between the unknown
and a constant keeps its hash, so _weak_datum's cached verdict is not read again until
the boundary conditions change; documented, with the override. The guide and the
changelog wrote the native target as tolerance * F_ref + atol; it is
max(tolerance * F_ref, atol), and only the rotated loop adds atol.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 8, 2026 06:56

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

Copy link
Copy Markdown
Member Author

Review record 1 of 2: 43857a5 (superseded; kept for the record)

The second record, below, re-checks every finding here on 26e4031. Paths under runs/2026-11-06/ are on hyperion.

Tip reviewed: 43857a5 (built as wt-crp2; wt-crp was still in use by the parallel suite). Base: development 06c574e (wt-dev06). Most of the work ran on b2a8840. The native floor, the dispatcher and the rotated floor are byte-identical between b2a8840 and 43857a5, so those results carry over. Every number quoted for the tip was re-run on wt-crp2.
Probes and logs: runs/2026-11-06/crp/review/. Nothing in either worktree was changed, nothing was pushed, nothing was posted. [read] marks a finding that comes from reading code and has no run behind it.

Verdict

Not ready to merge. The parallel behaviour is clean: every floor and guard decision was identical on every rank at np 1–4, including on empty ranks. #911 and #924 are fixed, and the rotated case drops from >900 s to 13 s. Two correctness defects remain:

  1. With the rotated floor on, a converged fault solve is 800 times less accurate in slip than on base: 2.2e-4 at tolerance 1e-6. test_1087 now turns the floor off before it measures slip, so the shipping configuration goes unchecked.
  2. A weak datum held in a uw.expression whose value is 0 on its first read is cached as "not a datum". Ramping it afterwards then gives development's inaccurate warm path (6.4e-3) instead of the branch's 1.1e-6.

Findings

High

H1. The rotated floor on the fieldsplit sub-KSPs costs accuracy beyond the tolerance (test_1087 territory). Probe probe_1087.py runs test_1087's fault box at the test's tolerance of 1e-6. It compares peak slip against the same solve at 1e-10.

k, tail base slip error branch slip error branch vel/pres its (last) base
2, split 2.65e-7 2.17e-4 4 / 6 5 / 15
3, split 5.09e-7 1.9e-8 6 / 15, 2 outer 5 / 15, 1 outer
3, welded 4.5e-8 2.4e-10 6 / 15, 2 outer 5 / 15

The loop reports converged=True at k=2, so the residual target is met while slip is 217 times the tolerance. Two overlays (ov-nosub, ov-noatol) attribute the loss:

  • dropping only the sub-KSP atol in _set_absolute_target restores base exactly (2.651e-7, 5 / 15);
  • dropping the atol entirely gives the same result.

The cause is the atol on the pressure and velocity sub-KSPs. That atol is in outer-residual units, and it cuts the Schur solve at 6 iterations. In the tight welded run, the branch's pressure sub-KSP also reaches its cap of 200 iterations, against 25 on base.

The tip's test_1087 now sets _INCREMENT_TARGET_FRACTION = None for the whole test, so its slip check (slip_w against slips[3] to 1e-4) never sees the floor. The test was changed to pass rather than to keep its contract. Logs: pr-1087-{crp2,dev,nosub,noatol}.log.

Medium

M1. _weak_datum misses a datum whose expression value is 0 when first read, and caches the miss (probe_weak0.py, w0-*.log).

  • Robin flux 3(T − E) with E = uw.expression(0): the verdict is False. After E.sym = 1 the cached verdict is still False; recomputing gives True.
  • A Nitsche lid U·sin(πx) with U an expression ramped 0 → 0.5 → 1 → 1.01 → 1.02 keeps the stationary rule. Its warm re-solve errors against a 1e-10 solve are 6.4e-3 and 2.7e-3, the same as development.
  • The same lid built with U = 1 from the start (w-nitsche-crp2.log) gives 1.1e-6 to 1.4e-6.

The docstring says "a datum held in a constant counts whatever its value". The unwrap evidently folds a zero-valued expression away. The id-keyed cache cannot notice a value change. Ramping a forcing up from zero is a common continuation pattern.

M2. On left-preconditioned GMRES the floor is not a true-residual bound, and linear problems pay extra Newton steps. The floor is scaled into the preconditioned norm by ||Bb||/||b||, so the true residual after the linear solve can miss T, and SNES then re-assembles and re-sets up GAMG.

  • test_0009's third solve (linear Poisson): 2 Newton steps (5 + 2 KSP its), against 1 step (6 its) on base. It ends at 6.50e-5 against a target of 6.25e-5.
  • Nonlinear Poisson, warm +1 %, at np 2, 3 and 4: 3 Newton steps against 2 on base (p-poisson-*).
  • Linear scalar time loop (sl-crp2.log): 3 Newton steps on some steps of a linear problem.

The design's merge bar says "Newton iterations do not increase". It does not hold on these routes.

M3. The cold-start reference extends to Scalar and Vector solvers, and a quasi-static field in a time loop then lags the moving part of its forcing (attack 4). Setup: a stationary Poisson, warm-started every step, forced by H = 30 plus a moving unit perturbation. The probe measures error on the moving part against a cold 1e-11 solve.

build max error typical error Newton steps per time step
development 5.6e-9 9.4e-11 2 every step
branch 1.3e-2 — 0 on many steps

The branch keeps the residual within T = 1e-4·‖F(0)‖, which is the design's stated guarantee. Users of a time loop should still be told: their answer now drifts by up to one cold-start tolerance band of the steady part.

The same experiment on saddle-point Stokes (a hydrostatic-dominated convection proxy, cl-*.log) gives identical numbers on base and branch: up to 7.0e-3 at tolerance 1e-4. So this is development's existing Stokes behaviour, and the branch now applies it to the other routes.

Low

L1. A KSP with ksp_norm_type none is cut to one iteration per application. PETSc passes rnorm = 0, so threshold = 0 and rnorm <= threshold fires at iteration 1. With CG or Richardson + Jacobi, 40 fixed iterations become 1 (m-normnone-*). The configuration also fails on base, though differently, so the impact is small. Fix: skip the floor when ksp.getNormType() == NONE.

L2. The design note no longer matches the code [read].

  • §2 says the native floor goes "on the outer KSP and on every fieldsplit sub-KSP". _install_linear_floor_test registers on snes.getKSP() only.
  • §4 describes a KSPSetPreSolve hook. The code uses a convergence test.

L3. Setting the rotated floor to None does not clear an atol already set on a cached rotated KSP [read]. _set_absolute_target(None) returns before touching the KSP. "Floor off" is therefore not "floor off" for a solver whose cache was built with the floor on. It is harmless in test_1087, which builds fresh solvers, and monkeypatch restores the switch at teardown, so the switch cannot leak between tests.

L4. Tests that cannot fail on their bug. Run on base, test_a_warm_start_stops_at_the_cold_start_target[saddle_point] and test_the_saddle_point_route_keeps_eisenstat_walker pass. Base Stokes already took atol = tol·‖F(0)‖ through its nrichardson pre-solve on a zeroed gvec. The other 8 of the 10 new tests fail on base, some only on a missing attribute.

L5. _weak_datum false positive [measured, harmless]. A nonlinear flux q0(1+u²) is classified as a datum. That selects the increment rule, which is PETSc's default and conservative.

Attacks that failed (numbers)

  • Rank uniformity (attack 1). Every dispatcher call was wrapped and logged per rank: (prefix, test, its, rnorm, reason).
    • Scenarios: nonlinear Poisson, Poisson on 2 cells with empty ranks ([0,2,0] at np 3), F(x0) = 0, power-law Stokes fieldsplit, Stokes with the guard armed, Stokes with the guard firing.
    • Result: identical decision sequences on every rank at np 1–4. For example, 1054 calls across 3 ranks with identical=True; with the guard on, 892 to 968 calls covering the outer, velocity and pressure KSPs.
    • The floor registers only on the outer KSP. The guard is on the sub-KSPs as well, and its deadline is all-reduced.
    • Rotated case at np 1–4: increment iterations were [1,1,1,1,1,1] every time, in 10–14 s.
  • Dispatcher (attack 2).
    • Order: when the guard fires, its reason comes out (DIVERGED_LINEAR_SOLVE, rank-uniform), the same as on base.
    • When every test returns ITERATING, the native test still decides: EW's rtol_0 shows on the saddle point, and user ksp_rtol and ksp_atol results match base exactly.
    • Rebuild loop: 60 setup-dirtying rebuilds leave exactly one linear_floor entry, with RSS flat (378.9 → 379.6 MB).
    • 40 new solvers: +91 MB on the branch against +99 MB on base. That is a pre-existing per-solver growth, with no new leak.
  • F(x0) = 0 (attack 4). Target = atol = 1e-50, 0 iterations, the right answer on every np.
  • Memory solves (attack 4). AdvDiff has its own ksp_rtol, so the floor is off and R = 0 is PETSc's default. test_0028's time-step test passes at np 1, 2 and 3.
  • Penalty datum in the body force (which the BC scan cannot see) on the saddle point. Warm errors are 2.6e-6, 2.3e-6 and 2.3e-6, identical to base.
  • Weak-datum cache through id reuse. No collision in 200 replacement trials. The verdict was identical on every rank.
  • User settings (attack 5). snes_rtol 1e-8, snes_atol 1e-3 (honoured: target 1e-3), snes_stol, ksp_rtol 1e-2 (floor off, the same as base) and ksp_atol 1e-3 (the same as base) all behaved correctly. test_1143 passes at np 1, 2 and 3 and fails on base.
  • Cap (attack 6). At tol 1e-10, warm from half the answer, the branch took 6 Newton steps, the same as base, and reached 1.1e-11. The tenfold cap never stopped Newton early.
  • A weakly imposed nonzero velocity makes the cold-solve target follow the penalty: 1e-3 to 3e-2 off at tolerance 1e-4 #1011. The cold Nitsche-lid error at 1e-4 is 4.260e-2 on both builds. The branch leaves cold solves alone.
  • New and changed tests on the tip. Serial: 52 passed, 1 skipped (test_1111 shell skipped: this host's gmsh mesh differs). test_0028 + test_1143 at np 2 and np 3: 10/10 passed.

The five "by design" tests

test verdict
test_0009 By design. The ratio is off by 1.45e-6 at tolerance 1e-4.
test_1057 By design. The projector stops at 8.7e-10, inside its snes_rtol of 1e-6 (base over-solved to 9.6e-14). The resulting eta error is 4.0e-9, a relative 8e-8.
test_1111 annulus By design. v_rms meets its 1e-9 bound; only the pinned counts move, (4,7) → (3,6).
test_1111 shell Could not test (mesh fingerprint skip).
test_1087 Not by design. See H1. The premise the author calls stale is confirmed on dev06: the welded tail takes 5 iterations at k = 3, not the 13 in the docstring.

Issue verdicts

issue verdict evidence
#911 Fixed by this branch test_0028's rotated test: 915.8 s on base against seconds on the branch. The base rotated probe at np 1–4 was killed after 240 s of silence; the branch finished in 10–14 s. H1 must be fixed before this verdict stands without a caveat.
#924 Fixed by this branch test_1143 fails on base and passes on the branch at np 1, 2 and 3.
#985 Fixed by this branch The same mechanism and evidence as #911.
#1011 Still live The cold weak-datum error is unchanged (4.26e-2 on both builds).

Merge conditions

  • H1: drop the atol on the rotated sub-KSPs (the overlay restores base accuracy), or scale it into each block's own norm. Then restore test_1087's slip check with the floor on, and keep the floor-off switch only for the iteration count.
  • M1: detect a datum through the expression symbol, not its current value, or key the cache on the expressions' values. Add a test that ramps from 0.
  • M2: make the floor a true-residual bound on left-preconditioned routes, or document the extra Newton step and drop "Newton iterations do not increase" from the design's merge bar.
  • M3: state the time-loop consequence in the design note and in the user docs.
  • L1: skip the floor when the KSP's norm type is NONE.
  • L2: bring §2 and §4 of the design note into line with the code.

Could not test

  • The test_1111 shell case (this host's gmsh mesh differs).
  • The full parallel suite: another process owns it. On wt-crp (the old tip), every batch run so far has passed.
  • zg95 viscoelastic and rotated time loops.
  • Units-scaled models.
  • Fieldsplit and MG inner KSPs under the floor: by reading, the native floor is never registered on them [read].

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Review record 2 of 2: 26e4031, re-check

Verdict: ready. The merge condition below is met. On hyperion the full parallel suite on 26e4031 passed: scripts/test.sh --parallel-only --p 2 --full-parallel, every batch at np 2 and np 4, rc 0 in 2309 s. test_1089 and test_1139 failed on 43857a5, with slip 2.2e-4 off at np 2 and 6 iterations against at most 5 at np 4. Both pass now.

The head, caebd29, differs from 26e4031 only in a docstring, the nonlinear-solver guide and the changelog (git diff --stat 26e40318..caebd298: 3 files, 9 insertions, 6 deletions, no code). So these runs stand. It also settles both optional items:

  • N1 is documented in _weak_datum's docstring, with _convergence_reference_rule as the way out.
  • The guide now gives the native target as max(tolerance·F_ref, atol).

On the np 2 hangs under "Could not test": test_1087 and test_1111 are serial-only files, run here under mpirun by hand. They hang the same way on development, and are not filed, by agreement with the author. Their parallel twin, test_1089, and the rotated parallel files pass.

Tip reviewed: 26e4031 (built as wt-crp2). Base: development 06c574e (wt-dev06). Previous review: crp-review.md, on 43857a5.
Probes and logs: runs/2026-11-06/crp/review3/. We changed nothing in either worktree, pushed nothing and posted nothing. Two test logs were written into the worktree roots by mistake; we moved them to review3 and checked that git status is clean in both trees. [read] marks a finding that comes from reading code and has no run behind it.

Verdict

Ready to merge once the parallel suite on 26e4031 passes.

  • H1, M1, M2, L1, L2 and L3 are fixed, and M3 is documented. We confirmed each one by running it.
  • The fault solve now matches development bit for bit, with the floor on or off.
  • The ramped-from-zero datums take the increment rule and are accurate.
  • Linear and warm Newton counts are now at or below development's.
  • Every rank-agreement, user-tolerance, F(x0)=0 and cold-solve check still holds.

There is one new low finding (N1): the hash-keyed _weak_datum cache goes stale in a contrived case. We found no new high or medium finding.

Findings from the last review

H1. Rotated floor on the fieldsplit sub-KSPs: fixed

probe_1087b.py runs test_1087's fault box. It compares peak slip at the test's tolerance of 1e-6 with a 1e-10 run.

case dev06 tip, floor on tip, floor off
k=2 split: slip at 1e-6 0.1595808977030 0.1595808977030 0.1595808977030
k=2 split: error / vel its / pres its 2.651e-7, 5 / 15 2.651e-7, 5 / 15 2.651e-7, 5 / 15
k=3 split: error, its 5.088e-7, 5 / 15 5.088e-7, 5 / 15 5.088e-7, 5 / 15
k=3 welded: error, its 4.471e-8, 5 / 15 4.471e-8, 5 / 15 4.471e-8, 5 / 15

The author's claim holds: slip 0.1595809 with 5 / 15 iterations, the same with the floor on and off. On a single increment, the sub-KSP rtols stay at their configured 3.3e-8 and 1e-7 (factor 1). Logs: h1-{crp2-on,crp2-off,dev06-on}-linear.log.

test_1087 and test_1111 are now byte-identical to development's (git diff 06c574e8 26e40318 is empty for both files). Both pass on both builds (shell case skipped):

  • tip: test_0028 + test_1087 + test_1111 serial, 16 passed, 1 skipped (t-crp2-serial.log);
  • dev06: test_1087 + test_1111, 7 passed, 1 skipped (t-dev06-1087-1111.log).

Attack: later increments, where the relaxation applies.

Power-law fault box (η = (0.01 + ε̇_II)^-1/2, k=2 split, 7 increments; h1-*-powerlaw.log).

  • Slip error against the tight run: 1.55e-8 on the tip, 1.93e-9 on dev06. Both are at most 0.016 × tol.
  • Only the last increments relax. At inc 4–6, sub rtols rise from (3.3e-8, 1e-7) to (3.9e-5, 1.2e-4), and vel / pres its fall 7 → 4 and 15 → 8.
  • The first four increments are identical to development's.

Rotated TI power-law annulus, multi-increment Newton, cold and warm (rot-*.log, probe_rot3.py). Errors are measured against the tip's own 1e-11 solve. Development's 1e-11 solve does not converge: its pressure KSP fails (reason -11, |r| = NaN) after 205 its, and Newton stops at 1.17e-10.

tol np cold error warm A=101 warm A=102 dev06 cold error
1e-5 1 8.04e-7 (0.08 tol) 7.34e-7 7.17e-7 3.7e-11
1e-5 2 9.08e-7 1.04e-6 (0.10 tol) 1.02e-6 —
1e-7 1 1.97e-9 (0.02 tol) 2.01e-9 1.98e-9 9.3e-13
1e-7 4 8.89e-10 8.88e-10 8.72e-10 —

Every solve lands well inside its tolerance. Development over-solves by 4 to 5 orders of magnitude.

Does the cap hold? No sub rtol exceeded 0.1 in any trace; the largest seen with default margins was 7.9e-3. With default margins (velocity 0.033·tol, pressure 0.1·tol), the sub rtol tops out at 0.0033 and 0.01, so the cap cannot bind [read].

To make it bind, we set _rotated_pres_rtol = 0.05 on the power-law fault box (h1cap-*.log):

  • The pressure rtol is held at exactly 1.00e-1 on inc 5–6. It never goes above 0.1, and never below the user's 0.05.
  • Slip error is 1.93e-7 (0.19 tol), against 1.79e-9 on dev06. That is inside the tolerance.

Rank verdicts. The per-increment (atol, ‖b̂‖, outer tolerances, sub rtols) trace was identical on every rank at np 2 and np 4. The rotated probe in probe_par at np 1–4 runs increments [1,1,1,1,1,1] then [1,1,1], in 5–6 s.

M1. _weak_datum and a datum that starts at zero: fixed

Robin ambient 0 → 1 (w0-crp2.log): True at value 0, True cached after the change to 1, True fresh. On the last tip this was False → False → True.

Nitsche lid ramped from 0 (w0-*.log): it now takes the increment rule from U = 0.

U tip error tip Newton its dev06 error dev06 Newton its
0.5 4.45e-3 2 4.45e-3 2
1.0 1.05e-4 11 6.63e-3 5
1.01 1.51e-6 10 6.38e-3 1
1.02 1.38e-6 10 2.72e-3 1

These match the lid built at U = 1 from the start (w-nitsche-crp2.log: 1.09e-6, 1.38e-6, 1.36e-6).

Robin ambient ramped 0 → 1 → 1.01 → 1.02, warm accuracy (w3-*.log): errors 2.4e-5, then 2.7e-7, then 2.5e-7 at tol 1e-4, under the increment rule.

Attacks on the classifier and the cache key (probe_weak3.py, np 1 and np 3):

case verdict ranks agree
Robin with ambient = expr(0) True yes
Robin with ambient = expr(expr(0)) True yes
Robin with ambient = a mesh variable holding 0 True yes
k = expr(0), flux k·(T − 1) True yes
pure flux False yes
Robin with u_ext = 0 False yes
  • fn_f is an ImmutableDenseMatrix, so it is hashable and the key really is hash-based.
  • A value change keeps the hash and the key, and the verdict stays correct, because the term is read by its symbols.
  • BC removed, then re-added: across 200 alternating datum/traction swaps on the same BC slot, the cached verdict never differed from a fresh one (0 / 200). Removing every BC gives False; re-adding the Robin datum gives True.
  • Hash collision: in CPython hash(-1) == hash(-2), so the terms −1·T and −2·T have equal keys. Both are correctly "no datum". We could not build a collision that changes the verdict: that needs a term that is zero at rest and one that is not, with the same hash, and hash(0) = 0 is not shared by any other small integer. The exception is N1 below.

M2. Preconditioned norm and true residual: fixed

Warm nonlinear Poisson +1 % at tol 1e-4 (p4-poisson-*.log):

np tip Newton steps / KSP its dev06
1 1 / [6] 2 / [7, 7]
2 1 / [6] 2 / [7, 7]
3 1 / [6] 2 / [7, 7]
4 1 / [6] 2 / [7, 7]

The tip's dispatch log is identical across ranks at every np. The author's claim holds.

The same problem at tol 1e-6 (p-poisson-crp2-*.log) takes 2 steps ([9 or 8, 5] its) at np 1–4. That is development's 2, against 3 on the last tip.

test_0009's third solve is in test_mesh_t_resolves_to_the_model_clock (tr-0009-*.log). It now takes 1 Newton step, 6 KSP its, and ends at 1.05e-5 against a target of 6.25e-5. That is identical to development; the last tip took 2 steps (5 + 2) and ended at 6.50e-5. The other two Poisson tests in test_0009 also match development's counts.

Memory: the RSS rebuild loop stays flat (369.7 → 372.0 MB over 60 rebuilds, one linear_floor entry). 40 new solvers add 99 MB, against 99 MB on development (m-rss-crp2.log). The buildResidual vector is destroyed.

M3. Time-loop lag: documented

  • Design note §1 has a new bullet, "A stationary equation in a time loop". It gives 1.3e-2 against 5.6e-9 and the _convergence_reference_rule = "increment" way out.
  • docs/developer/guides/nonlinear-solver.md has a new paragraph, "Where a solve stops". [read]

Low

  • L1. ksp_norm_type none: fixed (m-normnone-crp2.log). CG gives reason -3 at Newton 0, and Richardson does 40 its per application up to max_it. Both match development exactly; the last tip cut each application to 1 iteration.
  • L2. Design note §2 and §4: fixed [read].
    • §2 now says the native floor is on the outer KSP only, as a convergence test composed with PETSc's. It describes the true-residual check and says a KSP with no norm gets no floor.
    • §4 describes the convergence test, not a pre-solve.
    • The rotated paragraph describes the sub-rtol scaling and the switch-off. All of this matches the code.
    • Nit: the user guide writes T = tolerance·max(...) + atol. The native code uses max(rtol·F_ref, atol); only the rotated loop adds atol. The difference is immaterial at default atol.
  • L3. Floor off on a cached rotated KSP: fixed (rot-crp2-np1-1e-7.log, rot-crp2-np4-1e-7.log). After solves with the floor on, setting _INCREMENT_TARGET_FRACTION = None puts back the configured values on the same cached KSP:
    • outer atol: 1e-50;
    • sub rtols: 3.3e-9 and 1e-8 (0.033·tol and 0.1·tol).
      The warm re-solve then over-solves as development does (5.5e-11 at tol 1e-7). The 1e-11 reference solve with the floor off then reproduces development's own failure: pressure PC fails with NaN, and Newton does not converge in 6 at 1.27e-10. That is base behaviour (Rotated solve past round-off fails its last linear solve; since #907 a time loop rebuilds its KSP every step #911), not new.
      The baseline is captured once per ctx. The ctx is rebuilt when tolerance changes (cache["tolerance"], rotated_bc.py:1328), so a stale baseline cannot carry across a tolerance change [read].
  • L4 and L5: no change from the last review.

New findings

N1 (low). The _weak_datum cache cannot see an expression's definition change from unknown-dependent to constant (w3-*.log, "structural stale").

  • Setup: the ambient E2 = uw.expression(..., T.sym[0]), so the Robin flux 3(T − E2) is zero at rest and the verdict is False. Then E2.sym = 1.0.
  • hash(E2) is the symbol's hash, so the key does not move. The cached verdict stays False; a fresh read gives True, the same on every rank.
  • The solve then keeps the stationary rule: the accuracy loss of M1.
  • The opposite direction (constant → unknown-dependent) leaves a cached True. That is conservative.
  • The case is contrived: an expression re-pointed from the unknown to a number.
  • Fix: key on the held term (after _held swaps constants for Dummies, .sym included), or note the limitation in the docstring.

Observed, by design. Under the increment rule, the Nitsche lid's step from U = 0.5 to 1.0 takes 11 Newton its against development's 5. It is 60 times more accurate (1.05e-4 against 6.6e-3).

Attacks that failed (numbers)

  • Rank agreement (p-*-crp2-{1..4}.log). Identical per-rank dispatcher decisions at np 1–4 in every scenario:
    • poisson: 84–89 calls;
    • poisson_empty: 34 calls, cells per rank [0, 2, 0] and [0, 0, 0, 2];
    • zero;
    • stokes: 10 calls;
    • stokes_guard: 892, 968, 1054 and 981 calls, the same counts as the last review;
    • stokes_guard_fire: 14 calls, guard reason -3 on every rank;
    • rotated.
      The _weak_datum verdicts agree across ranks at np 3.
  • F(x0) = 0. Target 1e-50, 0 iterations, |u| = 0 at np 1–4.
  • Cold solves unchanged.
  • User tolerances (m-user-crp2.log).
    • snes_atol 1e-3: target 1e-3.
    • snes_rtol 1e-8: target 2.69e-9.
    • ksp_rtol 1e-2: linear_floor None, counts the same as base.
    • ksp_atol 1e-3: the same as base.
    • snes_atol 1e-12 with ksp_rtol 1e-12: floor None.
  • Cap (m-cap-crp2.log). Tol 1e-10, warm from half the answer: 6 Newton steps, the same as base, ending at 1.7e-12.
  • Tests.
    • test_0028 at np 2: 10 / 10 passed (t-crp2-np2-0028.log).
    • test_0028, test_1087 and test_1111 serial on the tip: 16 passed, 1 skipped.

Merge conditions

  • The full parallel suite on 26e4031 passes. Another process is running it; we did not see its result.
  • Optional, low: N1. Key the _weak_datum cache on the held term, or document the limitation.
  • Optional, nit: align the user guide's T = ... + atol with the native max(rtol·F_ref, atol).

Could not test

  • test_1087 and test_1111 at np 2.
    • test_1087: one rank fails a test and the ranks then hang, at the same place on development (rank 0 in solve_rotated_freeslip, rank 1 in _collective_raise).
    • test_1111: rank 0 is in _agree_source_across_ranks and rank 1 in _free_petsc_garbage, on both builds.
    • These are serial tests, and the hang is not this branch's (t-{crp2,dev06}-np2-{1087,1111}.log).
    • The combined np-2 run of the three files hangs in test_1087 for the same reason (t-crp2-np2.log).
  • The test_1111 shell case: this host's gmsh mesh differs (4560 cells against 4904), so it skips on both builds.
  • Development's warm rotated solves. Its 1e-11 reference stalls (Rotated solve past round-off fails its last linear solve; since #907 a time loop rebuilds its KSP every step #911), and the supervisor killed the dev06 rotated probes after 600 s of silence, once their cold row was printed. The two tip 1e-5 probes were killed the same way at the floor-off step, after their warm rows. Their floor-off rows are covered by the 1e-7 runs.
  • The rotated vector route (no fieldsplit): not probed directly. It has no sub-KSPs and only the outer atol, which is unchanged from the last tip [read].
  • The zg95 viscoelastic and rotated time loops, including the design note's ruling-2 table: not reproduced.
  • Units-scaled models.

Underworld development team with AI support from Claude Code

…rence-policy

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit 80d3ebe into development Nov 8, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 8, 2026
…ering

Underworld development team with AI support from Claude Code

# Conflicts:
#	docs/developer/CHANGELOG.md
lmoresi added a commit that referenced this pull request Nov 8, 2026
…stom-mg-1016

Underworld development team with AI support from Claude Code

# Conflicts:
#	scripts/test.sh
lmoresi added a commit that referenced this pull request Nov 8, 2026
…eform-1015

Underworld development team with AI support from Claude Code

# Conflicts:
#	scripts/test.sh
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
underworldcode#1115)

_robust_owning_cells accepted the first cell it tried (the nearest control
point's) whenever the point was within the 1e-2 face tolerance of it. A
point just inside the NEIGHBOURING cell, within that tolerance of the face
they share, was then evaluated in the wrong cell, and the box clamp in
DMInterpolationEvaluate_UW put it on the shared face: an error of about
|grad f| times its distance from the face, for any field, the ones the
element represents exactly included. On a 1/16 simplex box: 4e-6 at 1e-6
from an edge or vertex, 4.4e-5 at 1e-5; 5 of 20,000 random points.

The locator now takes two passes: a cell that contains the point to
rounding (_EVAL_CONTAIN_TOL, 1e-10, face-relative), and the 1e-2 face
tolerance only for points no local cell contains. The set of points a
rank claims is unchanged, so ownership and migration are untouched; only
which of a rank's cells evaluates a point changes.

The face tolerance dates from 2026-05-28 (c52201b, parallel locator
hardening); underworldcode#1014 (register row 6) did not touch this path.

test_0511 (tier B): 2-D and 3-D simplices, P1 and P2, points on and at
1e-8..1e-3 from vertices and edges, exact to rounding; quads as control.
The four simplex cases fail on development.

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