Repository navigation
Stokes refuses a solve whose pressure preconditioner cannot be factored (#1059) - #1255
Conversation
…ed (#1059) The pressure block's preconditioner factors the pressure mass matrix divided by the viscosity, and PETSc's ILU treats pivots below 2.2e-14 as zero: from a viscosity of about 1e11 in the solver's frame the factorisation failed, the solve stopped at iteration 0 and the fields held u = 0 with a warning. Such a failure now raises on every rank, with the matrix's scale and the remedy (reference quantities, so the viscosity is of order one). Underworld development team with AI support from Claude Code
|
Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) Verdict on d48b37d: ready to merge on green from this review.
How it was runBuilds:
Probe: a small script runs the PR test's box: a unit square,
The fields were not zeroed between solves on the same solver. Partitions: parallel runs used random and band partitions, through a shell partitioner hook on gmsh meshes. With the band layout each rank owns a horizontal strip. With the empty-band layout the last rank owns no cells. Solve log: the solve-logging pytest plugin from our earlier reviews recorded each solve's SNES and KSP counts, reason, and solution vector, on both builds. The records were then matched solve by solve. Every run used four cores. Every parallel run was under the MPI supervisor with a 300 s timeout. All solves here took seconds; the timeout was not reached. The pressure preconditioner here is GASM with ILU sub-blocks, not block Jacobi. A zero pivot in a sub-block shows on the pressure PC as SUBPC_ERROR (6). That is why the PR counts SUBPC_ERROR. ResultsThe key parallel question: is a local failure seen on every rank?Viscosity is 1 below y = 0.8 and 1e12 above it, with the band partition. Only the top rank's local block has the tiny pivots.
PETSc already reports the failure on every rank: development shows SUBPC_ERROR on every rank too. The PR's own MAX reduction is a second guard on top of that. The diagonal norm for the message runs only after a MIN reduction of "found the pressure block", so every rank takes it or none does. The raise comes after all the solve's collectives (the copy-back and Boundary sweep, serial, cellSize 0.1
The edge matches the smallest diagonal: 1.22e-15 at 1e12 reaches 2.2e-14 at about 5.5e10. Nothing that converged on development is refused. That follows from the method's first line too: it returns at once when the converged reason is 0 or more. Mesh dependence: at Author's zero-pivot claim: with Other diverged reasons, and nonlinear solves (serial)
Units model (the remedy the message names)The box is lid-driven, with reference quantities of 1000 km, 5 cm/yr and 1e21 Pa s, and a viscosity of 1e21 Pa s.
The PR's test
Unchanged answers on standard Stokes filesSerial (test_0022 x3, test_0610, test_0786, test_0818, test_1010, test_1011, test_1013 x2, test_1014_stokes_multigrid, test_1050): 77 passed on both builds. 64 solves match in SNES and KSP counts and are bitwise equal.
Parallel (test_0780, test_0786 rank without cells, test_1167, test_1200): same pass counts on both builds at np 2 and 3. Iteration counts match. At np 2 the answers are bitwise equal. At np 3 one test_1200 solve differs by 1.2e-14 relative. Two development runs differ from each other by the same amount, so it is run-to-run round-off. Other solvers: the new method is called only from Findings
What was run and not runRun:
Not run:
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
…huge-viscosity-refuses-1059
From the review of the refusal. The message reported the largest pressure diagonal, but the smallest pivot decides: it now gives both, and says whether every entry is tiny (the viscosity's scale: reference quantities) or a contrast spans them (which reference quantities cannot remove; the zero-pivot option and a direct velocity solve, measured), with no fixed viscosity threshold, which is mesh-dependent. Only a zero pivot, or a sub-PC error with entries near the tolerance, is refused. "The initial guess" only at iteration 0. And a PC that failed kept its failed state, so the same solver failed again with a healthy matrix: the next solve after a PC failure forces its setup. Underworld development team with AI support from Claude Code
|
Answers to the review of d48b37d are in 3f20212, with development merged in. 1. The message gives the cause and the remedy that fit.
2. The same solver works once the viscosity is fixed. When the outer KSP stopped with Lows:
Tests ( Runs: the diverged-solve files (#1161, #1163, the wall-clock guard, the transcript report) and the Stokes, nullspace, rotated, constrained, Navier-Stokes and Nitsche files, tier C excluded: 389 passed, 1 skipped. The coverage check passes. Underworld development team with AI support from Claude Code |
|
Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) Verdict on 3f20212: ready to merge on green from this review.
Earlier findings: then and now
How it was runBuilds:
Probe: the same probe as in the first review: the PR test's box (unit square,
Partitions: random, band and empty-band partitions came from the same shell partitioner hook as before. Solve logs: the same solve-logging pytest plugin as before. Resources: every run used four cores. Every parallel run was under the MPI supervisor with a 300 s timeout. That allows for slow healthy solves. All solves here took seconds, and no run reached the timeout. ResultsFinding 1: the message text (serial unless noted)
The author's zero-pivot claim: for the 1e12 band, Finding 2: the same solver after a failureUniform cases use the random partition in parallel. The band case uses viscosity 1e12 above y = 0.8 and the band layout. "Fresh" is the speed from a new solver at the second viscosity (0.00384 at 1; 3.84e-13 at 1e10).
Same flag on every rank: the flag is set from the KSP's converged reason, which is global. At np 2, 3 and 4, every rank reported the same flag before and after each solve. Cost:
Lows 3 and 4
What held at d48b37d still holds
At d48b37d, The PR's test (5 tests now):
Standard Stokes files:
The diff (1a1d537..3f20212, excluding the development merge)
New findings
What was run and not runRun:
Not run:
Logs kept by the reviewer. Underworld development team with AI support from Claude Code |
An absolute bound on the largest pressure diagonal called a 1e9-to-1e12 model a contrast reference quantities cannot remove, though divided by 1e9 it solves in one iteration: the commonest real case (raw SI, 1e19 to 1e24 Pa s) got the wrong advice. The span decides now: within 1e8, which one rescaling brings into range (measured: a centred contrast of 1e8 solves by default, 1e9 does not), the model is too viscous as a whole and the remedy is reference quantities; beyond it, the contrast. The test docstring no longer names a fixed viscosity threshold. Underworld development team with AI support from Claude Code
|
At 2e3fa2d: scale or contrast is now decided by the span of the pressure block's diagonal, not by an absolute bound on its largest entry.
Underworld development team with AI support from Claude Code |
|
Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) Verdict on 2e3fa2d: ready to merge on green from this review.
Earlier items: then and now
The message (serial; unit box, P2/P1,
|
| case | span printed | remedy named | rescaled model, default options |
|---|---|---|---|
| uniform 5e10 | — (converges, 1 iteration) | — | — |
| uniform 5.5e10, 1e11, 1e12, 1e21 | 4.4 | reference quantities | viscosity 1 converges |
uniform 1e12, cellSize=0.03 |
4.5 | reference quantities | — |
| uniform 1e12, mesh graded y → y³ | 1.2e3 | reference quantities | — |
| band 1 / 1e12 | 4.4e12 | contrast | — |
| band 1e9 / 1e12 | 4.4e3 | reference quantities | 1 / 1e3: converges, 1 iteration |
band 1e9 / 1e12, cellSize=0.03 |
4.5e3 | reference quantities | 1 / 1e3: converges, 1 iteration |
| band 1e9 / 1e12, graded y → y³ | 1.1e3 | reference quantities | 1 / 1e3: converges, 1 iteration |
| band 1e5 / 1e12 | 4.4e7 | reference quantities | 1 / 1e7: converges, 1 iteration |
| band 1e4 / 1e12 | 4.4e8 | contrast | 1 / 1e8: converges, 3 SNES / 5 KSP iterations (new finding 1) |
| band 1e3 / 1e12 | 4.4e9 | contrast | 1 / 1e9: converges, 2 SNES / 4 KSP iterations (new finding 1) |
band 1e5 / 1e12, cellSize=0.03 |
4.5e7 | reference quantities | 1 / 1e7: not finished in 900 s; 3.2e-4 / 3.2e3: converges, 3 SNES iterations, 79 s (new finding 1) |
Mesh dependence: the span is the viscosity contrast times the spread of the element areas. On a uniform mesh that spread is about 4.4, whether cellSize is 0.1 or 0.03. The y → y³ grading raises it to about 1.2e3. That is still five orders below the cut, so no realistic grading changes the verdict for a uniform viscosity.
The author's bound (a contrast centred on one, on the coarse box):
| contrast | viscosities | outcome |
|---|---|---|
| 1e7 | 3.2e-4 / 3.2e3 | converges, 3 SNES / 6 KSP iterations |
| 1e8 | 1e-4 / 1e4 | converges, 5 SNES / 9 KSP iterations, 10 s |
| 1e9 | 3.2e-5 / 3.2e4 | diverged with a warning, not refused. The velocity sub-solve ends in NaN/Inf; the pressure PC has no failure. |
| 1e10 | 1e-5 / 1e5 | the same, at iteration 0 |
That matches the author's account: the failure is in the velocity multigrid, with no zero pivot. On the finer mesh (0.03), the 1e8 centred contrast did not finish within 300 s; the velocity multigrid was still iterating.
Runs
-
Builds:
- This branch: a fresh build of 2e3fa2d in a new worktree. All 12 installed compiled modules are dated after the build started, and
generic_solvers._RESCALABLE_SPANis 1e8. - Previous head: the existing 3f20212 build, used for the "new test fails there" check.
- Development: the existing 6fc3fc5 build.
- Every run printed
underworld3.__file__, and each run used the intended build.
- This branch: a fresh build of 2e3fa2d in a new worktree. All 12 installed compiled modules are dated after the build started, and
-
Same verdict on every rank: the probe gathers every rank's message.
case layout ranks that raised distinct messages remedy band 1e9 / 1e12 band, np 2, 3, 4 all 1 reference quantities band 1 / 1e12 band, np 2, 3, 4 all 1 contrast band 1e9 / 1e12 at y = 0.6 empty band, np 3 3 of 3 1 reference quantities band 1 / 1e12 at y = 0.6 empty band, np 3 3 of 3 — contrast uniform 1e12 empty band, np 3 3 of 3 — reference quantities band 1e9 / 1e12 random, np 3 (one rank owns no pressure dofs) 3 of 3 — reference quantities In the band layout, only the top rank holds the 1e-15 pivots, and the bottom rank's local minimum is 1e-12 or 1e-3. Every rank still gives the same verdict.
-
The PR's test (6 tests now):
build np 1 np 2 np 3 np 4 np 4 band np 3 empty band 2e3fa2d 6 passed 6 passed 6 passed 6 passed 6 passed 6 passed 3f20212 5 passed, 1 failed 5 passed, 1 failed — — — — On 3f20212 the failing test is the new moderate-contrast test, as expected.
-
Unchanged behaviour:
- Boundary: uniform 5e10 converges in 1 iteration; 5.5e10 is refused.
- Stuck-solver recovery: 1e12 then 1 on the same solver: refused, then converges in 1 iteration at speed 0.00384, the fresh-solver value. We checked this at np 1 and at np 2 with a random partition.
- Repeat solves: 1 → 1 → 1 runs at 0.15 s per repeat solve, as before.
-
Serial Stokes solve logs, same solve-logging plugin as before, development vs this branch. Both builds passed 39 tests, and every solve was bitwise equal:
file solves SNES iterations, development / this branch KSP iterations, development / this branch test_0818_stokes_nd 8 8 / 8 8 / 8 test_1010_stokesCart 6 6 / 6 6 / 6 test_1013_stokes_fields_by_solver_number 15 12 / 12 24 / 24 test_1050_VEstokesCart 5 6 / 6 6 / 6 -
The diff:
- Code: one changed comparison,
largest <= _RESCALABLE_SPAN * smallest, plus the new text.smallestandlargestare stillVec.min()/Vec.max()on the global diagonal, which are collective. So no branch is rank-local. - Test: one new test, which allgathers the messages and asserts on every rank.
- Code: one changed comparison,
-
Resources: every run used four cores, while other jobs ran on the machine. Every parallel run was under the MPI supervisor with an outer timeout of 300 s. The one exception was a 900 s serial run, which timed out (see finding 1).
Logs kept by the reviewer.
New findings
- Low: The cut was measured on one coarse box with the range centred on one. The message states the verdict more firmly than that supports.
- Calibration:
_RESCALABLE_SPAN = 1e8comes from contrasts centred on one, oncellSize=0.1. - On that box, "contrast" is given to models that rescale. At 1e4 / 1e12 and 1e3 / 1e12, the message says reference quantities "cannot remove" the contrast. Yet the same models divided by the low viscosity (1 / 1e8 and 1 / 1e9) converge by default.
- On a finer mesh, "reference quantities" is given to a model whose obvious rescaling does not solve. On
cellSize=0.03, 1e5 / 1e12 gets the reference-quantities advice (span 4.5e7). Dividing by the low viscosity (1 / 1e7) had not finished after 900 s; the velocity multigrid was still iterating. Centring the range (3.2e-4 / 3.2e3) converged in 3 iterations, but took 79 s. - Not blocking. Both verdicts are reasonable first advice, and the far cases (uniform; 1 / 1e12) are clear.
- Suggestions (wording only):
- In the contrast text, say "probably wider than one rescaling brings into range" instead of "cannot remove".
- In the scale text, say to choose the reference viscosity near the middle of the range (the geometric mean of the low and high viscosities), not at the low end.
- The code comment could note that the measured limit also depends on the mesh.
- Calibration:
Not run
- 3D meshes;
- the slow fine-mesh cases on the development build. They are healthy solves that this change does not touch, and the solve logs show no change on healthy solves;
- the parallel Stokes files. They were compared at np 2 and 3 at 3f20212, and this commit changes only the text chosen after a refusal;
- the author's regression set.
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
Fixes #1059 by refusing. The cause is found, and a fix that would make these solves work is offered below for the maintainer's decision. It changes a solver option, so it is not in this PR.
The cause
The NaN comes from the pressure block, not the velocity block:
The pressure block's preconditioner is GASM with ILU sub-solves, on the pressure mass matrix divided by the viscosity. PETSc's LU and ILU treat a pivot below an absolute tolerance, 2.22e-14, as zero. The largest diagonal entry of that matrix, on #1059's box (cell size 0.1), is:
SUBPC_ERROR, SNESDIVERGED_LINEAR_SOLVEat iteration 0, u = 0Once the pivots fall to the tolerance, the factorisation fails. Its failure surfaces first as the velocity sub-KSP's NaN.
With
fieldsplit_pressure_sub_pc_factor_zeropivot = 0, the same solves converge at 1e11, 1e15 and 1e21. The answer scales exactly as 1/viscosity (max |v| 3.84e-14, 3.84e-18, 3.84e-24).What this PR does
A Stokes-family solve that diverges because the pressure preconditioner could not be factored now raises a RuntimeError on every rank. Before, it returned with u = 0 and a warning. The message:
How it decides:
For the maintainer: the option that would make these solves work
The tolerance is absolute, but this matrix scales as 1/viscosity, so the failure is set by the units the model is written in, not by the problem.
fieldsplit_pressure_sub_pc_factor_zeropivotto 0 in the Stokes defaults would let raw-SI models solve.Either would make the refusal here reachable only by a genuinely singular block. It changes a solver default, so it is not in this PR.
Test
tests/parallel/test_1059_stokes_unfactorable_pressure_pc_refused_parallel.py, tier B, in batch 3 ofscripts/test.sh:It passes at np 1, 2 and 4.
Runs. The serial files on diverged-solve reporting (#1161, #1163, the wall-clock guard, the transcript report), Stokes, nullspaces, rotated and constrained conditions, Navier-Stokes, Nitsche and units, tier C excluded:
The coverage check passes.
Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).
Underworld development team with AI support from Claude Code