Repository navigation
NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p - #1226
Merged
ChrisRackauckas merged 2 commits intoSep 5, 2026
Conversation
`maybe_wrap_nonlinear_f` returned an already-wrapped `AutoSpecializeCallable` unchanged. A problem that was wrapped at construction and then `remake`d with an outer-AD Dual `u0`/`p` (e.g. ForwardDiff through an ODE initialization) kept a `FunctionWrappersWrapper` whose signatures only cover the value eltype, and the solve failed with `NoFunctionWrapperFoundError`. Hand back the raw callable in that case, mirroring the existing rule that Dual-eltype state is never wrapped. `_despecialize_parameters` also skips its `remake` when the problem is already despecialized and wrapped, so re-concretizing such a problem is free. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> Agent-Harness: Claude Code 2.1.259 Agent-Model: claude-fable-5-1 Agent-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn
…atch u0/p A function wrapped at construction carries signatures for the state and parameter types it was wrapped with. Instead of special-casing a Dual `u0`, check whether the stored wrapper has a signature for `(u0, u0, p)` (`wrapper_accepts`): if it does, reuse it; if not, unwrap and go through the normal wrapping path, which rebuilds the wrapper for a new value eltype and leaves the raw callable for an outer-AD Dual eltype. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> Agent-Harness: Claude Code 2.1.259 Agent-Model: claude-fable-5-1 Agent-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn
u0 is promoted to Dual
Member
Author
|
Release ordering: #1228 needs to own NonlinearSolveBase 2.49.3 because SciML/ModelingToolkit.jl#5062 now requires its reverse-mode AD fixes. This PR currently also claims 2.49.3. After pull request 1228 is reviewed, merged, and released, this branch should rebase on the updated base and bump NonlinearSolveBase to 2.49.4 before merge. I have not rewritten or force-pushed this branch. |
ChrisRackauckas
marked this pull request as ready for review
September 5, 2026 08:24
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 7, 2026
- NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226) - Fix reverse AD through despecialized parameters (#1228) - Preserve Jacobian cache parameter representation (#1227) - Preserve TrustRegion cache parameter representation on reinit (#1229) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 7, 2026
- NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226) - Fix reverse AD through despecialized parameters (#1228) - Preserve Jacobian cache parameter representation (#1227) - Preserve TrustRegion cache parameter representation on reinit (#1229) - Run runic on docstrings and markdown files (#1231) - Release NonlinearSolveFirstOrder 2.5.1 (#1232) - NonlinearSolveBase: report the wrapped arity for despecialization wrappers (#1230) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas
referenced
this pull request
Sep 7, 2026
- Drop stale [compat] majors older than one year (#1198) - Drop @fastmath from L2_NORM/Linf_NORM so isfinite guards survive (#1182) - Release 4.28.1 (#1202) - Release 2.48.1 (#1206) - Align QA NLsolve compat with root project (#1205) - Widen NonlinearSolveBase LogExpFunctions compat to 0.3.28–1 (#1203) - Continue polyalgorithm after stalled least-squares solves (#1204) - Align Wrappers NLsolve compat with root project (#1208) - Release 2.48.2 (#1210) - Preserve despecialized parameters during reinit (#1199) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 10, 2026
- Require all components to stall before resetting Broyden (#1184) - Add adaptive Jacobian reuse to first-order solvers (#1072) - Release 4.29.1 (#1220) - Release 2.49.1 (#1221) - Release 1.15.3 (#1222) - Fix @static_timeit for TimerOutputs ≥ 0.5.27 (#1224) (#1225) - NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226) - Fix reverse AD through despecialized parameters (#1228) - Preserve Jacobian cache parameter representation (#1227) - Preserve TrustRegion cache parameter representation on reinit (#1229) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas
referenced
this pull request
Sep 10, 2026
- Remove name duplicates in keyword arguments/named tuples (#1238) - Add 32-bit Core CI lane via test_groups.toml (#1239) - Add a native bounded trust-region solver (#1219) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
What changed and why
maybe_wrap_nonlinear_freturned an already-wrappedAutoSpecializeCallableunchanged. A wrapper built byget_concrete_problemcarriesFunctionWrappersWrappersignatures for exactly the state and parameter types it was wrapped with, so a problem that was wrapped at construction time and thenremaked with different types (another value eltype, a different array type, an outer-AD Dual) was handed a wrapper with no matching signature: the call throwsNoFunctionWrapperFoundError(or falls into the slow fallback path, depending on the policy).The check is now general:
wrapper_accepts(f, (u0, u0, p))asks whether the stored wrapper has a signature for the current arguments. If it does, the wrapper is reused; if not, the raw callable is recovered withget_raw_fand goes through the normal wrapping path, which rebuilds the wrapper for the new types, or leaves the function raw whenu0is Dual-typed (the existing rule for outer AD)._despecialize_parametersalso skips itsremakewhen the problem is already despecialized and wrapped, so concretizing an already-concretized problem is a no-op.Motivation: SciML/ModelingToolkit.jl#5062 stores initialization problems pre-wrapped;
ReconstructInitializeprob/remakelater change theiru0/ptypes. That PR does not require this one (theAllowNonIsBitsfallback keeps non-isbits cases working), but benefits from it.Verification
New testset
maybe_wrap_nonlinear_f rebuilds a pre-wrapped f whose signatures do not match u0inlib/NonlinearSolveBase/test/runtests.jl: wrap at construction, thenremakewith (a)Float32u0/p— expects a rebuilt wrapper that accepts the new types and computes the right residual, and (b) an outer-AD Dualu0/p— expects the raw callable and correct values/partials; both forAutoSpecializeandAutoDespecialize.Against master
NonlinearSolveBase(78b1484f), same testset (wrapper_acceptsdoes not exist there, so those assertions error; the Float32 call itself throws):With this PR,
NONLINEARSOLVE_TEST_GROUP=Core julia --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test()'(Julia 1.12.7):NONLINEARSOLVE_TEST_GROUP=QA:Testing NonlinearSolveBase tests passed. Runic and typos clean on the changed files.Not verified
CoreandQAwere run locally.For the reviewer
wrapper_acceptscompares against the base signature only ((u0, u0, p)); the inner-AD Dual signatures the ForwardDiff extension adds are keyed off that base type, so a base match implies the Dual ones match too._despecialize_parameters' early return assumes that whenf.fis already wrapped andpis alreadyDespecializedParameters, the other callbacks (jac, …) were wrapped in the same earlier pass. That holds for anything produced bymaybe_wrap_f.🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn