Repository navigation
The rotated nonlinear loop honours a user-set snes_max_it (#920) - #927
Merged
Merged
Conversation
test_1018's power-law box under rotated free slip on every wall, with the frozen (Picard) tangent, converges in 43 iterations. With snes_max_it = 3 the loop must stop after three increments and report not converged; on development it runs all 43. Underworld development team with AI support from Claude Code
SolverBaseClass._solve_rotated_if_registered and fault_contact.solve_with_fault called rotated_bc.solve_rotated_freeslip without max_it, so the loop always ran to its default 50 and a user's snes_max_it never reached it. On the add-on matrix's yielding-lid box, Coulomb and rate-and-state faults stopped at 50 in their Picard phase with the residual still falling. Both now pass max_it=solver._resolve_snes_max_it(50). SNES_Stokes_SaddlePt already resolves the key through its owned-option record (#483); the base class gains a plain resolver (a user-set snes_max_it, else the default) for the vector solver, which also reaches the rotated path and never writes the key itself. The rotated free-slip doc says so; test_1136 is in batch 4. Underworld development team with AI support from Claude Code
…e cap hook The review of 6c56b18 found, now that the cap is user-set: - the loop never tested the residual after its last increment, so a cap of N reported failure on a solve that converged in N (43 of 43 on the power-law box), and a linear solve under a cap of 1 warned and dropped has_solution; - snes_max_it = 0 ran no pass and crashed on an unbound rnorm; - SNES_Stokes_SaddlePt resolved the key on the rotated path without pushing it, so its owned-option latch could mistake a later user value equal to a stale push for its own. solve_rotated_freeslip now runs max_it increments and one more pass that only measures the residual, as PETSc's SNES tests after its max_it-th update; a cap of 0 is one residual evaluation. Both call sites ask the solver for _rotated_max_it(): the base class reads a user-set snes_max_it, else 50 (the vector solvers), and SNES_Stokes_SaddlePt resolves it through its owned-option record and pushes it. The docstring and the subsystem doc say that staged Picard steps count against the cap, unlike the standard path's warm-up. test_1136 now checks raising the cap past 50 (54 increments at tolerance 1e-9), lowering it with the exit reason DIVERGED_MAX_IT, a linear solve under a cap of 1, a cap of 0, the vector solvers' resolver and fault_contact.solve_with_fault. Five of its six fail on development; the cap-of-1 case fails on 6c56b18. Underworld development team with AI support from Claude Code
The second review found that a negative snes_max_it, which PETSc reads as PETSC_DETERMINE / PETSC_DEFAULT (-1, -2: the default) or PETSC_UNLIMITED (-3: no cap), reached the loop as range(0) and crashed it on an unbound rnorm, after writing the fields; development ignored the option. The loop now maps -3 to no cap and other negative values to 50, and its docstring says so, and that a cap of 0 leaves a cold datum lift unapplied. The comment on the increment count no longer says the index undercounts on the cap exit. test_1136 adds -1 and -3 (both converge the 43-increment solve), raises the cap at tolerance 1e-11 (60 increments, ten past the default, where 1e-9 left four), says that the cap-of-1 test guards the measuring pass and also passes on development, and carries its tier on each test. Underworld development team with AI support from Claude Code
9fa9678 moved the tier onto each test and missed one, so the "tier_a or tier_b" selection dropped the vector-solver resolver test. Underworld development team with AI support from Claude Code
…nded From the check of 9fa9678: the negative-cap test ran a 43-increment solve, so it passed whether -1 meant 50 or no cap. It now runs the 60-increment solve at tolerance 1e-11: -1 stops at 50 with DIVERGED_MAX_IT, -3 converges past 50. PETSC_UNLIMITED lifted the loop's cap with no bound at all, where PETSc still stops at its function-count limit (snes_max_funcs, 10000); the loop evaluates one residual per increment, so -3 now stops there too. -2 (PETSC_CURRENT) is the default of 50, as the docstring says; PETSc refuses anything below -3 when it reads the option. Underworld development team with AI support from Claude Code
Member
Author
Pre-PR adversarial reviewThree rounds: 6c56b18, then 2425b4f and 9fa9678, then a final check of 9fa9678 and 1157b27. Each finding below was fixed on the branch or answered in the docs, except where it says otherwise. Round 1
Round 2
Final check
Attacks that failed
Issue verdicts
Underworld development team with AI support from Claude Code |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The solver mishandles PETSC_CURRENT by resetting the iteration cap and PETSC_UNLIMITED by imposing a finite cap, while failing to enforce function-evaluation budgets across line-search calls.
2 open issues
What changed in this PR
This PR addresses #920 by passing user-configured snes_max_it limits into Underworld3’s rotated free-slip and fault-contact nonlinear solvers.
Changes:
- Adds iteration-cap resolution for both rotated solver entry points.
- Checks convergence after the final permitted increment and supports a zero-increment solve.
- Documents cap behavior and adds regression tests to the serial test runner.
| File | Description |
|---|---|
tests/test_1136_rotated_loop_honours_snes_max_it.py |
Tests cap values, convergence boundaries, and solver entry points. |
src/underworld3/utilities/rotated_bc.py |
Handles negative caps and adds the final residual-only pass. |
src/underworld3/utilities/fault_contact.py |
Passes the resolved cap into fault-contact solves. |
src/underworld3/cython/petsc_generic_snes_solvers.pyx |
Resolves and forwards user-configured rotated iteration caps. |
scripts/test.sh |
Registers the regression tests in serial batch 4. |
docs/developer/subsystems/rotated-freeslip.md |
Documents iteration limits and how Picard steps count. |
Review effort: Balanced
Comment on lines
+1197
to
+1198
| if max_it == PETSc.UNLIMITED: | ||
| max_it = 10000 |
Comment on lines
+1199
to
+1200
| elif max_it < 0: | ||
| max_it = 50 |
lmoresi
added a commit
that referenced
this pull request
Nov 3, 2026
Underworld development team with AI support from Claude Code
lmoresi
added a commit
that referenced
this pull request
Nov 3, 2026
…ial row 5 counts Underworld development team with AI support from Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The rotated free-slip Newton loop always ran at most 50 increments, whatever the user set as
snes_max_it.Change
SolverBaseClass._rotated_max_it()returns the user'ssnes_max_it, else 50.SNES_Stokes_SaddlePtresolves the cap through its owned-option latch and pushes it, so a later standard-path solve reads the user's value back correctly._solve_rotated_if_registeredandfault_contact.solve_with_fault.max_it + 1passes, and the last pass only measures the residual, as PETSc's SNES does. So a cap of N accepts a solve that converges in N increments, and a cap of 0 is one residual evaluation (it used to crash on an unbound residual).PETSC_UNLIMITED) gives 10000, the bound PETSc's ownsnes_max_funcsputs on an unlimited solve. PETSc refuses values below -3 atsetFromOptions.rotated-freeslip.mddocuments the cap, and that staged Picard steps count against it on this path (the standard path's warm-up does not).Tests
tests/test_1136_rotated_loop_honours_snes_max_it.py(tier B, serial batch 4) covers:Vector_Projectionreading the user's cap;solve_with_faultunder a cap of 0.The tests fail on development, where the cap is ignored.
On kaiju (Linux, PETSc 3.25.0):
snes_max_it, match the earlier runs that capped the loop by wrapping it: Newton 77 and 75, velocity iterations 308 and 269, slip 7.9858 and 6.6330.Closes #920. Left open: #924 (the rotated loop also ignores a user-set
snes_rtol,snes_atolandsnes_stol, and the yield ladders' per-rung cap; filed from this review), and #876, #883, #884, #887, #910 and #911 (verdicts in the review comment).Underworld development team with AI support from Claude Code