Repository navigation
Cover out-of-place init in the Jacobian cache inference tests - #1137
Merged
ChrisRackauckas merged 1 commit intoAug 3, 2026
Merged
Conversation
`inference_tests__item1.jl` only exercised in-place problems, so the out-of-place instability in SciML#1092 went unnoticed: prob = NonlinearProblem((u, p) -> u .^ 2 .- 2.0, [1.0]) @inferred SciMLBase.init(prob, TrustRegion(autodiff = AutoFiniteDiff())) inferred the cache's `jac_cache`/`descent_cache` to open `where`-bounds. The root cause was FiniteDiff's out-of-place `finite_difference_jacobian` returning `Any` (JuliaDiff/FiniteDiff.jl#229); the Jacobian cache is typed by that return value, so the whole solver cache went with it. Add the out-of-place problem to the existing testset and raise the FiniteDiff lower bound to the release carrying the fix, so Downgrade CI resolves a version where these tests hold. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MoeiVWqAEFJQK22kiXu48f
Member
|
I think this is making most of the tests fail and NLSFirstOrder fail to instantiate, because FiniteDiff 2.32.1 hasn't been released yet. |
Member
|
It should be released now though, I was just pushing it through quicker because it was going to be easier than trying to remember the inference test down the line. |
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.
Fixes #1092.
Please ignore until reviewed by @ChrisRackauckas.
Diagnosis
The reported instability is not in
NonlinearSolveFirstOrder/NonlinearSolveBase. Walkingthe cache construction:
DoglegCacheandNewtonDescentCacheinfer fully concretely when handed a concreteJ— I checkedBase.return_typesonInternalAPI.init(prob, alg.descent, J, fu, u; …)in isolation and got the exact runtime type.
where-bounds start atconstruct_jacobian_cache, which infersJacobianCache{_A, _B, …} where {_A, _B}—JandJ_destination.@report_optputs the origin atjacobian.jl:129:%56is the AD-computedJ. WithAutoFiniteDiff,DI.jacobianbottoms out inFiniteDiff's out-of-place
finite_difference_jacobian, whose per-color closures assignvariables that also live in the enclosing function's scope. That boxes the captures, so the
function returns
Any, and theAnypropagates up through the Jacobian cache into thedescent caches — exactly the shape reported in the issue.
Once JuliaDiff/FiniteDiff.jl#229 lands, the issue's reproducer is
clean:
What this PR changes
inference_tests__item1.jlonly ever built in-place problems, which is why this wentunnoticed — the in-place FiniteDiff path in DI was already inferrable. This adds the
out-of-place problem to the Jacobian-cache testset and folds the two
Full inittestsetsinto one loop over
{in-place, out-of-place} × {TrustRegion, NewtonRaphson}. I confirmedthe new cases fail on FiniteDiff 2.32.0 and pass on the patched build.
The
FiniteDifflower bound moves2.24 → 2.32.1so Downgrade CI resolves a version wherethese tests actually hold.
Not fixed here
Two neighbouring instabilities that are not what #1092 reports, listed so they don't get
conflated:
AutoForwardDiff()on out-of-place problems.ForwardDiff.JacobianConfigencodes the chunk size in its type and
pickchunksize(length(u))is a runtime value, sothe DI prep — and therefore the cache — cannot be inferred. Passing
AutoForwardDiff(chunksize = n)makes it inferrable; I verified both. This is inherent toForwardDiff, not something NonlinearSolve can paper over.
LevenbergMarquardt, on every AD backend. ItsDampedNewtonDescentCacheinit picksmode(Val{:normal_form}/Val{:least_squares}/ …) at runtime, leaving__T_lincache,__T_JᵀJ_cache,__T_modeand friends as open bounds. Separate rootcause in
damped_newton.jl; happy to open an issue for it.Testing
GROUP=Coreforlib/NonlinearSolveFirstOrderon Julia 1.10.11, against the patchedFiniteDiff:
The new inference cases also pass on 1.11.9 and 1.12.6.
🤖 Generated with Claude Code
https://claude.ai/code/session_01MoeiVWqAEFJQK22kiXu48f