Repository navigation
Fix safe-mode stagnation to honor mode.internalnorm (#1310) - #1333
Draft
ChrisRackauckas-Claude wants to merge 6 commits into
Draft
ChrisRackauckas-Claude wants to merge 6 commits into
ChrisRackauckas-Claude wants to merge 6 commits into
Conversation
Stagnation step-norm (and RelNorm u0_norm) checks hard-coded L2_NORM, so custom norms such as MPI reductions were bypassed during stall detection. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-NonlinearSolve.jl-1310/log.txt on amdci2.julia.csail.mit.edu
…ML#1310) Document that the L2 stall sanity check is for an explicit L2_NORM mode (package default is Linf), and assert RelNormSafe* init/reinit routes u0_norm through mode.internalnorm. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-NonlinearSolve.jl-1310/log.txt on amdci2.julia.csail.mit.edu
Keep the present-tense note that the package default is Linf, not L2. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-NonlinearSolve.jl-1310/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <noreply@cognition.ai> Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration) Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_NonlinearSolve.jl-1333/log.txt
Member
Merged the default branch into this PR (clean merge, no conflicts; head a14fb3e) so CI runs on current master. 🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
Bring in the upstream return-code type assertion and retain the existing stagnation norm changes. The LTS inference test fails on the pre-merge checkout and passes with this merge; full LTS Core and QA also pass. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local fixer job SciML__NonlinearSolve.jl__1333 (no session URL)
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6.2-sol Agent-Job: SciML__NonlinearSolve.jl__1333--20261122T044713Z-codex-gpt-6.2-sol Agent-Session: local session 01a20194-837e-7d62-80ec-c8e36423e0fb (no session URL)
This branch has not been deployed
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.
Summary
Safe termination modes evaluated residual norms via
mode.internalnormbut hard-codedL2_NORMfor the stagnation step-norm (and RelNormu0_norm), so custom norms (e.g. MPI reductions) were silently bypassed during stall detection. This patch routes those checks throughUtils.apply_norm(mode.internalnorm, …)and adds counting-norm regressions for AbsNorm step norms and RelNormu0_norm, plus an explicit-L2_NORMstall sanity check.Behaviour change
Default
NonlinearProblemsolves useAbsNormSafeBestTerminationMode(Base.Fix1(maximum, abs))(L∞), not L2. Stagnation previously compared step sizes with hard-codedL2_NORM, so default solves effectively mixed L∞ residuals with L2 stall checks. After this PR, stagnation uses the mode's L∞ norm as well.Demo (
n=100, 40 constant steps of2e-7per entry,abstol=1e-6): on master the solve reaches step 40 without stopping; with this PR it returnsStalledat step 33. NonlinearProblemLibrary: 236 solves identical.Failing before / passing after
AbsNorm step-norm (src fix stashed; regression asserts
calls[] == 5):After (fix restored):
RelNorm
u0_norm(u0_norm lines temporarily reverted toL2_NORM; expects 3 calls on init and reinit):After (fix restored):
Test group
NONLINEARSOLVE_TEST_GROUP=CoreviaPkg.testinlib/NonlinearSolveBase— passed (rerun after review follow-ups).Tail:
CI notes
Current CI reds on this PR (Adjoint, FirstOrder Core — see #1325 — and two sublibrary QA public-API findings on names this PR does not touch) are pre-existing / unrelated; they are not caused by this change.
Not verified
Reviewer pushback
u0_normshould stay L2 for historical tolerance scaling (this PR usesinternalnormfor consistency)Fixes #1310
Please ignore this draft until reviewed by @ChrisRackauckas.
Risk assessment
u0_normnow usemode.internalnorm, so every norm intermination_conditions.jlgoes through it. Behaviour change: the default mode's norm is L∞, so default solves now test stagnation in L∞ instead of L2. In the reviewer's demo (n=100, 40 constant steps of 2e-7, abstol 1e-6) the solve returnsStalledat step 33 where master runs on. NonlinearProblemLibrary gave identical results across 236 solves. No public API change, no allocation or inference regression.🤖 Generated with Cursor Agent CLI 2026.09.26-dd393fe (model: auto), transcript /log.txt
Risk assessment and review coordination by 🤖 Claude Code (model: claude-opus-5-5[1m]), https://claude.ai/code/session_01NdFVhANTF4nepTbqYxjfRP
Risk assessment
NonlinearProblemsolve. The default mode isAbsNormSafeBestTerminationMode(Base.Fix1(maximum, abs); max_stalled_steps = 32)(termination_conditions.jl:390). Its stall check used the L2 norm of the step and now uses the L∞ norm. For a vector, L∞ ≤ L2, so large or slow-converging systems can now returnStalledearlier where master kept iterating. DefaultNonlinearLeastSquaresProblemsolves are not affected because their mode's norm is already L2. For RelNorm safe modes with a custom norm, the stall scaleu0_normalso changes. MPI and other custom-norm users get the intended fix for Stagnation checks ignore custom norms (problematic for MPI) #1310. Downstream jobs pass on the head commit: MTK Initialization/InterfaceI/InterfaceII, OrdinaryDiffEq InterfaceI/InterfaceII/Regression_I, BoundaryValueDiffEq, DiffEqCallbacks.9aa3c84also fails on master or on other PRs from the same period.tests / Adjoint, all 4 jobs (julia 1 and lts, ubuntu and macos): pre-existing. All 4 fail on the last three master CI runs (29af7e60,54e9eea8,192b11f5).downgrade-sublibraries / test (lib/NonlinearSolveFirstOrder): pre-existing. Master29af7e60fails with the same output: 1512 passed, 28 errored, allThunkCallErroratrootfind_tests__item8.jl:30(SVector OOP). The PR description does not mention this failure.sublibraries / lib/NonlinearSolveFirstOrderCore (Julia 1): pre-existing. SameThunkCallErrorerrors, tracked in master red on lib/NonlinearSolveFirstOrder GROUP=Core: Enzyme.Compiler.ThunkCallError, bisects to Enzyme v0.13.203 (good) -> v0.13.204 (bad) #1325 (Enzyme 0.13.204). It also fails on master708f2c7dand4b5a6162, and on PRspolyalg-fallthrough-stale-subcache,smc/unwrapped-problem-specializationandfix-1288-bounded-lm-enzyme.sublibraries / lib/NonlinearSolveFirstOrder [QA]: pre-existing. The finding is thatRobustTrustRegionLinsolveis imported from NonlinearSolveBase but is not public there. It fails on master708f2c7d/4b5a6162and on the same three PRs.sublibraries / lib/NonlinearSolveBase [QA]: pre-existing. Two findings: a non-public import ofimplicit_sensitivity_solveinNonlinearSolveBaseForwardDiffExt, andnlls_solve_adjoint_dp/solve_callare not rendered in the docs. It fails on master708f2c7dand on the same three PRs. This PR touches none of those names.NonlinearSolveBaseCore passes on Julia lts, 1 and pre. Root Core, Downstream, PolyAlgorithms, Wrappers and QA all pass.NonlinearProblemsolve.L2_NORM(...)toUtils.apply_norm(mode.internalnorm, ...).apply_normis internal to NonlinearSolveBase itself, so no dependency internals are used.NonlinearProblemsolves (max_stalled_steps = 32), so some solves may now returnStalledearlier. That is user-visible, and a maintainer should decide whether it counts as a bug fix or a behavior change that needs a docs or NEWS note and a minor version bump.u0_normwith that norm instead of L2, which changes their tolerance scaling. The author also flagged this as an open question.downgrade-sublibrariesFirstOrder job. It is also red on master, so it is not a regression.🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 (session ID, no URL)
Risk assessment (independent review, Codex gpt-6.1-sol, head a14fb3e)
NonlinearProblemsafe-best mode changes its stagnation step norm from L2 to L∞, changing termination iterations and returned states on the default path of core NonlinearSolve). Other matched criteria: L2 (added assertions), ML1 (configured-norm contract fix), and M2 (working-path results change); H2 sets the rating.git diff origin/HEAD...HEAD; checked exact-head check-run metadata and failing logs.git diff origin/HEAD...HEAD --checkpassed; checkout remained clean. Local targeted commands and results, using Julia 1.12.4,JULIA_NUM_THREADS=4, the requestedJULIA_DEPOT_PATH, and scratch-local temporary files:SCRATCH=<local path>. ArchivedHEADandorigin/HEAD(8d5e163e724ddfc1232055175dd8fb592915809f) into scratch and used identical resolved dependency versions. Rantimeout 3600 julia --project="$SCRATCH/env" "$SCRATCH/new_tests.jl": 5 passed. Ran the same extracted PR testsets with--project="$SCRATCH/env-base": 2 passed, 3 failed; observed3 == 5,2 == 3, and2 == 3failures. Logs:scratch/head-tests.log,scratch/base-tests.log.timeout 3600 julia --project="$SCRATCH/env" "$SCRATCH/numerical_probe.jl"and the same command withenv-base. For the supplied sequenceu_k = fill(k*2e-7,100)and analytic residualf(u)=1e6*(u-8e-6), head's default termination cache stops at 33, Stalled, residual L∞ 1.4; base stops at 40, Success, residual 0. This exercises the default cache with prescribed iterates, not a solver-generated trajectory. Logs:scratch/head-numerical.log,scratch/base-numerical.log.cache.u0_norm.timeout 3600 julia --project="$SCRATCH/env-mutant" "$SCRATCH/new_tests.jl"still reports 5 passed. This deliberately faulty copy is evidence about test sensitivity, not a defect in the submitted assignment. Log:scratch/mutant-tests.log.5476c468atcore_tests__item3.jl:27(solve!()inference; 8 passed, 1 errored), including identical type-mismatch text. SCC Core matches that same master'sisconcretetype(eltype(scc_sol_debug.original))failure (12 passed, 1 failed). The LTS benchmark log fails resolving SciMLJacobianOperators while explicitly benchmarking its own base revision8a86577a, before a head comparison. These four reds are not evidence of regressions introduced here. Detailed read-only comparison:scratch/baseline-ci-report.md.🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.
Risk assessment (independent review, Codex desktop (runtime 0.164.0-alpha.11.1) gpt-6.1-sol, slot 1, head a14fb3e)
Review round 1, written by the reviewer named above (Codex desktop (runtime 0.164.0-alpha.11.1) / gpt-6.1-sol) in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.
Summary: Routes stagnation step norms and relative initial-iterate norms through internalnorm. The implementation passes targeted checks, but committed tests do not detect stale norm state and do not establish changed-default numerical accuracy or the claimed MPI behavior.
Blast radius: Safe/SafeBest termination displacement checks and RelNorm initialization/reinitialization, including the default Linf mode and user-supplied distributed norms.
Evidence: Julia 1.13.0: all five added assertions pass. Restoring exact base init/reinit/safe-call methods fails the AbsNorm route assertion (3 calls instead of 5). An independent 100-component constant-step check has Linf(step)=2e-7, L2(step)=2e-6, abstol=1e-6, and correctly stops at step 33 under the head default. A deliberate stale-value reinit mutant also passes all five committed assertions, then fails an independent cached-value assertion (10 versus 30); this exposes a G3 coverage gap rather than an incorrect submitted assignment.
Blocking findings
Non-blocking findings
None.
What I ran
Read the issue #58 review contract, exact-head diff, relevant surrounding code and repository AGENTS.md/CLAUDE.md where present. Initial independent risks/code notes were frozen before fetching author descriptions and discussion. Only review scratch environments were added; tracked source files remain unchanged. Base records the fetched current target branch. The PR metadata reported 8a86577, which equals the verified merge base; the three-dot diff is therefore unchanged. Negative-control methods were compared with the fetched base: they are identical except the SimpleTrustRegion control, which was refreshed and rerun successfully.
Executed both added testsets unchanged: 3/3 stagnation plus 2/2 relative init/reinit assertions, exit 0. Base-method control exits 1 at the first discriminating call-count failure, so its second testset does not run; no passing base claim is made. The analytic default check asserts Stalled at step 33, exit 0. Inspected successful Base Core job 115562242009, failed benchmark/SCC logs, issue #1310 and current base CI. In a separate process, replaced only the reinit assignment with a call that discards the result: both committed testsets still report 3/3 and 2/2, then a value-sensitive check fails (exit 1). No tracked source was edited.
Local Julia commands used Julia 1.13.0, JULIA_NUM_THREADS=4, OPENBLAS_NUM_THREADS=1, a dedicated TMPDIR, an isolated writable depot with existing packages available read-only, and one top-level Julia process at a time. Dependencies were developed into separate scratch projects, never a sublibrary's own project. No full-suite result is inferred from a targeted run. G1: changed-default end-to-end accuracy remains unverified. G2: real MPI callback execution remains unverified. G3: the stale-value mutant demonstrates missing reinit coverage.
Live-head check snapshot: 4 FAILURE, 3 SKIPPED, 93 SUCCESS.
What I did not verify
No real MPI multi-rank run or independent end-to-end convergence/accuracy test for the changed default stopping rule. G1/G2 remain needs-verification, and G3 is not satisfied by call-count-only reinit coverage. Full local Core/QA/downstream suites were not run. The complete initial review was saved before reading the detailed prior same-head assessment, but author summaries were already visible, so the reviewer comparison is not fully blinded.
Targeted harnesses were invoked as
julia --startup-file=no --project="$REVIEW_ENV" "$REVIEW_SCRIPT" [base-source-control]; those variables designate the isolated project and source-specific harness described above. These are portable command spellings; the actual invocation used the corresponding concrete scratch paths, which this issue's output format prohibits publishing.🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74
Fix by Codex CLI 0.164.0 gpt-6.1-sol (head a09be83)
Merged current master normally, preserving both parents and the existing stagnation changes. The two reported LTS Core failures are the
solve!()return-type inference error addressed upstream by #1347. Master’s latest push run passes both affected jobs. This update incorporates that fix without a second implementation or changes to assertions.Verification
Julia 1.10.12, four threads, one-hour command timeouts. The archived pre-merge source and merged source used the same resolved dependency versions, including SciMLBase 3.58.0.
test/Core/core_tests__item3.jlfrom the pre-merge archive, both with normal compilation and with--compiled-modules=no. Both executions exited 1. Eightsolve()assertions passed, followed by the samesolve!()inference error seen in CI: the concrete solution includesReturnCode.Twhile the inferred solution omits that type parameter.timeout 3600 julia +lts --compiled-modules=no --project -e 'using Test; include("test/Core/core_tests__item3.jl")'exited 0:GROUP=Core timeout 3600 julia +lts --project -e 'using Pkg; Pkg.test()'exited 0; top-level summaries total 1,587 passing assertions, including all 16 inference assertions. Tail:GROUP=QA timeout 3600 julia +lts --project -e 'using Pkg; Pkg.test()'exited 0:timeout 3600 julia +1.12 --project=@runic -m Runic --inplace lib/NonlinearSolveBase/src/termination_conditions.jl lib/NonlinearSolveBase/test/runtests.jlexited 0 with no output or changes. Also ran Runic viaxargson all 33 Julia files incorporated by the merge; exit 0, no output or changes.git diff --cached --unified=0 | python3 -c 'import sys; print("".join(l[1:] for l in sys.stdin if l.startswith("+") and not l.startswith("+++")), end="")' | typos - --format briefexited 0 with no output before committing. Diff metadata was excluded from spelling input.git diff --cached --checkexited 0 before committing.Not verified locally: macOS, MPI, GPU, downstream suites, docs build, or completion of the new CI run. Existing review findings G1 (independent numerical accuracy), G2 (multi-rank MPI), and G3 (value-sensitive reinitialization coverage) remain outstanding; this update addresses the assigned LTS Core failures only.
Risk assessment
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__NonlinearSolve.jl__1333 (no session URL)
Fix by Codex CLI 0.170.0 gpt-6.2-sol (head b1f9e6e)
Added an end-to-end Newton accuracy regression against a known root for the default and weighted maximum norms. The longer weighted-norm solve distinguishes the stagnation rules. The relative safe-best reinit test now checks the cached norm at both initial states. The two-rank MPI reproduction exercises both absolute safe modes.
Homotopy Continuation CI
Both assigned Julia 1 jobs failed while importing TaylorDiff 0.3.5. Its derivative generator passed a symbolic value into the ChainRules
tanhrule, which threwTypeError: non-boolean (Symbolics.Num) used in boolean context. An isolatedusing TaylorDiffreproduced the failure with TaylorDiff 0.3.5, ChainRules 1.74.13, and Symbolics 7.48.0. Updating only the requested TaylorDiff version to 0.3.6 made that import exit 0 withTaylorDiff loaded.Master’s Julia 1 Core and QA jobs pass with TaylorDiff 0.3.6 and ChainRules 1.74.13. The original PR checkout also passes both groups with a fresh resolution to TaylorDiff 0.3.6. The fix is in TaylorDiff. Upstream fix · PR failures · Master Core · Master QA
Regression controls
Julia 1.13.3, four threads or fewer and one-hour timeouts.
SCRATCHdenotes the directory containing the archived master source and isolated local environments.timeout 3600 julia +1 --startup-file=no --project="$SCRATCH/master" test/Core/stagnation_tests__item1.jlexited 1. The default solve passed both assertions. The weighted-norm solve returnedStalledand its error was1.7501326545824839e-6against the analytic bound3.0e-13. The same command with--project=.exited 0 withDefault | 2 2andWeighted maximum norm | 2 2.timeout 3600 julia +1 --startup-file=no --project="$SCRATCH/reinit-stale" "$SCRATCH/reinit-norm.jl"exited 1 with3 passed, 1 failedand10.0 == 30.0. That environment evaluates the norm during reinit and discards its result. The same extracted test with--project="$SCRATCH/mpi-head"exited 0 withRelNorm u0_norm uses mode.internalnorm | 4 4.timeout 3600 julia +1 --startup-file=no --project="$SCRATCH/mpi-master" "$SCRATCH/run-mpi.jl" "$SCRATCH/mpi-stagnation.jl"exited 1. Each rank reported6 passed, 2 failedand the gathered stop decisions were[1, 0]while one rank was moving. The same command with--project="$SCRATCH/mpi-head"exited 0, withCollective stagnation norms | 8 8on each rank. Both ranks continued while either rank moved and both returnedStalledonce stationary, in both absolute safe modes.Full groups and checks
GROUP=Core timeout 3600 julia +1 --project -e 'using Pkg; Pkg.test()'. Output includedNewton stagnation and accuracy | 4 4and ended withTesting NonlinearSolve tests passed.GROUP=QA timeout 3600 julia +1 --project -e 'using Pkg; Pkg.test()'. Tail showedQA | 28 28andTesting NonlinearSolve tests passed.lib/NonlinearSolveBase. Core reportedTermination Conditions | 51 51, withDense LU refactorization allocations | 14 14in the tail. QA reportedQA | 20 20. Both ended withTesting NonlinearSolveBase tests passed.lib/NonlinearSolveHomotopyContinuationat the original PR head. Core reportedAllRoots | 116 116,Single Root | 35 35andTaylor Polynomialize | 40 40. QA reportedQA | 19 1 20, with the existing broken persistent-task check. Both ended withTesting NonlinearSolveHomotopyContinuation tests passed.timeout 3600 julia --project=@runic -m Runic --inplace lib/NonlinearSolveBase/test/runtests.jl test/runtests.jl test/Core/stagnation_tests__item1.jlwith Julia 1.12.4. Exit 0 with no output.git diff --cached --unified=0 | python3 -c 'import sys; print("".join(line[1:] for line in sys.stdin if line.startswith("+") and not line.startswith("+++")), end="")' | typos - --format brief. It andgit diff --cached --checkexited 0 with no output.The separate SCC Core failure also occurs on master with the same abstract
NonlinearSolutionelement type. The local validation covers the assigned Julia 1 jobs and the new regressions. The default L∞ stopping policy still awaits a maintainer decision. Master SCC failureTwo-rank reproducer
Run in an environment with MPI, SciMLBase and the local NonlinearSolveBase source. Save the launcher and test as
run-mpi.jlandmpi-stagnation.jl.Next counted review must come from a smart model in a fresh session, not this fix session.
🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a20194-837e-7d62-80ec-c8e36423e0fb (no session URL)