Skip to content

Various bug fixes - #1051

Merged
ChrisRackauckas merged 7 commits into
SciML:masterfrom
JamesWrigley:audit
Jul 19, 2026
Merged

ChrisRackauckas merged 7 commits into
SciML:masterfrom
JamesWrigley:audit

Conversation

@JamesWrigley

@JamesWrigley JamesWrigley commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

All found by auditing NLSBase and NLSFirstOrder with Claude, and checked by me (not that I'm much of an expert). See the commit messages for more details:

  • 02986f8: the reinit!(::EisenstatWalkerForcing2Cache) method incorrectly assigned p (problem parameters) to cache.p (the forcing algorithm struct).
  • ef0a12c: fix missing variable in init() for NewtonDescent.
  • ff8ef19: implement reinit!(::SwitchedEvolutionRelaxation), which previously did nothing when reiniting.
  • d09598f: drop extra arguments to step!().
  • 11b48f6: fix the dogleg Cauchy-point length, which was apparently incorrect in normal-form mode.

The fixes I'm particularly unfamiliar with are 11b48f6 (Cauchy point-length) and ff8ef19 (implementing reinit!(::SwitchedEvolutionRelaxation)) so they could likely do with extra review.

Written with Claude 🤖

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

@JamesWrigley

Copy link
Copy Markdown
Member Author

(I'll investigate the compat failures tomorrow)

@JamesWrigley

Copy link
Copy Markdown
Member Author
  • To fix downgrade CI I bumped LinearSolve/SciMLBase compat in 2233d61
  • Added a method to fix a method ambiguity from Aqua, and updated the list of broken tests in ae6601c.

The broken tests appears to have changed in #1039:

1: Generalized Rosenbrock function | alg #4: Test Failed at /home/runner/_work/NonlinearSolve.jl/NonlinearSolve.jl/test/Core/setup_robustnesstesting.jl:25
  Expression: norm(res, Inf) ≤ ϵ
   Evaluated: 4.3999999999999995 ≤ 0.001
  Stacktrace:
   [1] macro expansion
     @ ~/_work/_tool/julia/1.13.0-rc1/x64/share/julia/stdlib/v1.13/Test/src/Test.jl:753 [inlined]
   [2] macro expansion
     @ ~/_work/NonlinearSolve.jl/NonlinearSolve.jl/test/Core/setup_robustnesstesting.jl:25 [inlined]
   [3] macro expansion
     @ ~/_work/_tool/julia/1.13.0-rc1/x64/share/julia/stdlib/v1.13/Test/src/Test.jl:2042 [inlined]
   [4] test_on_library(problems::Tuple{typeof(NonlinearProblemLibrary.p1_f!), typeof(NonlinearProblemLibrary.p2_f!), typeof(NonlinearProblemLibrary.p3_f!), typeof(NonlinearProblemLibrary.p4_f!), typeof(NonlinearProblemLibrary.p5_f!), typeof(NonlinearProblemLibrary.p6_f!), typeof(NonlinearProblemLibrary.p7_f!), typeof(NonlinearProblemLibrary.p8_f!), typeof(NonlinearProblemLibrary.p9_f!), typeof(NonlinearProblemLibrary.p10_f!), typeof(NonlinearProblemLibrary.p11_f!), typeof(NonlinearProblemLibrary.p12_f!), typeof(NonlinearProblemLibrary.p13_f!), typeof(NonlinearProblemLibrary.p14_f!), typeof(NonlinearProblemLibrary.p15_f!), typeof(NonlinearProblemLibrary.p16_f!), typeof(NonlinearProblemLibrary.p17_f!), typeof(NonlinearProblemLibrary.p18_f!), typeof(NonlinearProblemLibrary.p19_f!), typeof(NonlinearProblemLibrary.p20_f!), typeof(NonlinearProblemLibrary.p21_f!), typeof(NonlinearProblemLibrary.p22_f!), typeof(NonlinearProblemLibrary.p23_f!)}, dicts::NTuple{23, Dict{String, Any}}, alg_ops::Tuple{NonlinearSolveQuasiNewton.QuasiNewtonAlgorithm{Nothing, Missing, NonlinearSolveBase.NewtonDescent{Nothing}, NonlinearSolveQuasiNewton.GoodBroydenUpdateRule, NonlinearSolveQuasiNewton.NoChangeInStateReset{Nothing}, NonlinearSolveQuasiNewton.IdentityInitialization{Nothing, NonlinearSolveQuasiNewton.FullStructure}, Val{false}}, NonlinearSolveQuasiNewton.QuasiNewtonAlgorithm{Nothing, Missing, NonlinearSolveBase.NewtonDescent{Nothing}, NonlinearSolveQuasiNewton.GoodBroydenUpdateRule, NonlinearSolveQuasiNewton.NoChangeInStateReset{Nothing}, NonlinearSolveQuasiNewton.TrueJacobianInitialization{NonlinearSolveQuasiNewton.FullStructure, Nothing}, Val{true}}, NonlinearSolveQuasiNewton.QuasiNewtonAlgorithm{Nothing, Missing, NonlinearSolveBase.NewtonDescent{Nothing}, NonlinearSolveQuasiNewton.BadBroydenUpdateRule, NonlinearSolveQuasiNewton.NoChangeInStateReset{Nothing}, NonlinearSolveQuasiNewton.IdentityInitialization{Nothing, NonlinearSolveQuasiNewton.FullStructure}, Val{false}}, NonlinearSolveQuasiNewton.QuasiNewtonAlgorithm{Nothing, Missing, NonlinearSolveBase.NewtonDescent{Nothing}, NonlinearSolveQuasiNewton.BadBroydenUpdateRule, NonlinearSolveQuasiNewton.NoChangeInStateReset{Nothing}, NonlinearSolveQuasiNewton.TrueJacobianInitialization{NonlinearSolveQuasiNewton.FullStructure, Nothing}, Val{true}}, SimpleNonlinearSolve.SimpleBroyden{Nothing, Nothing}}, broken_tests::Dict{NonlinearSolveBase.AbstractNonlinearSolveAlgorithm, Vector{Int64}}, ϵ::Float64; skip_tests::Nothing)
     @ Main.var"##23 Test Problems: Broyden#160" ~/_work/NonlinearSolve.jl/NonlinearSolve.jl/test/Core/setup_robustnesstesting.jl:13

8: Brown almost linear function | alg #4: Error During Test at /home/runner/_work/NonlinearSolve.jl/NonlinearSolve.jl/test/Core/setup_robustnesstesting.jl:25
 Unexpected Pass
 Expression: norm(res, Inf) ≤ ϵ
 Got correct result, please change to @test if no longer broken.

So 1 now fails (according to Claude it was always dubious) and 8 now passes.

@JamesWrigley

Copy link
Copy Markdown
Member Author

The allocation failures in https://github.com/SciML/NonlinearSolve.jl/actions/runs/29238046017/job/86778787036?pr=1051 appear to be because of a change to reshape() in 1.12. Investigation by Claude:

Julia 1.12 deleted the identity fast path from reshape(::Array, ::Dims):

 # present in 1.11, gone in 1.12
 if N == M && dims == size(a)
     return a
 end

1.12's replacement comment states the intent: "reshape(::Array, ::Dims) returns a new Array (to avoid conditionally aliasing the structure, only the data)". It now unconditionally allocates a fresh Array header sharing the data, and
offers a separate reshape! for the identity case. Measured directly: reshape(vec, size(vec)) costs 32 B and reshape(mat, size(mat)) costs 48 B on 1.12 and 1.13, both 0 B on 1.11.

How that adds up to the exact failing numbers

Allocation profiling found two per-Newton-iteration allocations, both of which are reshapes to an array's existing shape:

  • 48 B — ForwardDiff's reshape_jacobian(result, ydual, xdual) = reshape(result, length(ydual), length(xdual)), where result is already that exact matrix (ForwardDiff/src/jacobian.jl:120, via DI.jacobian! from
    NonlinearSolveBase/src/jacobian.jl:221).
  • 32 B — your Utils.restructure (utils.jl:114) → ArrayInterface.restructure(x::Array, y) = reshape(convert(Array, y), size(x)...), called from NewtonDescent (descent/newton.jl:128) where linres.u and δu are both length-50 vectors.

That's 80 B per Newton iteration. Arclength does exactly one iteration per step → 80.0. The sweep averages 1.93 → 154.4. Both match the CI output to the digit.

The old definition would set `cache.p = p`, but `cache.p` is the forcing
algorithm struct and not the problem parameters. It just needs to update η, the
rest is reinited by the use of `@internal_caches`. Also fixed resetting of
`rnorm` and `rnorm_prev`.
`N` is not defined, the value should come from `shared` instead.
Explanation from Claude:
`SwitchedEvolutionRelaxationCache` has no `reinit!` method, so the generic no-op
applies. Measured: `α⁻¹` goes from `1000.0` at init to `5.3e-8` after a solve
and stays there through `reinit!`; the re-solve then runs with essentially no
pseudo-time damping — silently a different (pure-Newton-like): algorithm,
defeating the point of PseudoTransient on stiff problems. Since the mass-matrix
support (SciML#1001) the cache also holds a scaled damping matrix `D` that would leak
the same way. Contrast with `LevenbergMarquardtDampingCache`, which correctly
resets `λ` and `DᵀD`.
`step!()` only supports `recompute_jacobian`.
Explanation from Claude:
With `g = -Jᵀfu`, the code computes `δu_cache_mul = JᵀJ·g` and then `δuJᵀJδu =
dot(δu_cache_mul, δu_cache_mul)` = ‖JᵀJ·g‖² = gᵀ(JᵀJ)²g. The non-normal-form
branch:(lines 123–124) correctly computes ‖J·g‖² = gᵀJᵀJg. It should be
`dot(δu_cauchy, cache.δu_cache_mul)`.
Needed for downgrade CI.
- Fix method ambiguity
- Update list of broken tests
@ChrisRackauckas
ChrisRackauckas merged commit 74405d3 into SciML:master Jul 19, 2026
98 of 107 checks passed
@JamesWrigley
JamesWrigley deleted the audit branch July 19, 2026 22:42
ChrisRackauckas added a commit that referenced this pull request Jul 21, 2026
Releases the unreleased fixes on master: Various bug fixes (#1051).



Claude-Session: https://claude.ai/code/session_01SFmcAmLrGPrGtzwP333mX8

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Jul 28, 2026
…1125)

Problem #8 (Brown almost linear) solved with
Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden))
is the same knife-edge case as problem #1, which #1108 already moved into
skip_tests. #1051 removed 8 from that algorithm's broken list
([5, 6, 8, 11] -> [1, 5, 6, 11]) after validating on a machine where it
converges; it does not converge on the SciML self-hosted pool or on current
GitHub-hosted runners, where it returns the initial best residual 5.5.

As documented in #1096, the outcome is deterministic per machine but flips with
the BLAS kernel, and it has failed in both directions: the 2026-07-15 Downgrade
run errored with "Unexpected Pass" while it was still marked broken. Neither
pass nor @test_broken is a stable expectation, which is exactly what the
harness's skip_tests mechanism is for.

Local verification on Julia 1.12.6, test/Core/23_test_problems_tests__item7.jl:
this machine is one where #8 converges, so the run goes from 95 pass / 20 broken
on master to 94 pass / 21 broken with this change - one test moved from pass to
skip, nothing else changed.

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
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