Repository navigation
NonlinearSolveBase: report the wrapped arity for despecialization wrappers - #1230
Merged
ChrisRackauckas merged 1 commit intoSep 7, 2026
Conversation
…ppers `ParameterDespecializationWrapper` and `AutoSpecializeCallable` forward through a single `(args...)` method, so `SciMLBase.numargs` reported arity 1 for every wrapped callback. `remake` of a wrapped problem rebuilds its `NonlinearFunction`, whose constructor re-derives `isinplace` for each callback; arity 1 pushed that check into the method-table introspection fallback, which Enzyme reverse mode cannot differentiate through (`BoundsError: attempt to access Core.SimpleVector at index [2]`). Delegating `numargs` to the wrapped function keeps the arity fast path. Release 2.49.4. 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
ChrisRackauckas
marked this pull request as ready for review
September 7, 2026 06:16
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]>
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
ParameterDespecializationWrapperandAutoSpecializeCallableforward through a single(args...)method, soSciMLBase.numargsreported arity[1]for every wrapped residual/callback. When a problem that was wrapped at construction (ModelingToolkit's initialization problems after SciML/ModelingToolkit.jl#5062) isremaked,remake(::NonlinearProblem)rebuilds theNonlinearFunction, whose constructor re-derivesisinplaceforjac/jvp/vjp. Arity 1 pushes that check intoSciMLBase.isinplace's method-table introspection fallback (any(isequal(Vararg{Any}), methods(f).ms[1].sig.parameters)), which Enzyme reverse mode cannot differentiate through:(from https://github.com/SciML/ModelingToolkit.jl/actions/runs/33963346747/job/101298982372, SciMLSensitivity
Core8against MTK PR 5062.)The fix defines
SciMLBase.numargs(public, documented as the arity hook for "foreign-function wrappers") for both wrapper types, delegating to the wrapped function, so the arity fast path is taken. Version bumped to 2.49.4.Verification
Failing before (registry NonlinearSolveBase 2.49.3, Enzyme 0.13.200, Julia 1.12.7; the concretized initialization problem of an MTK DAE built with
jac = true):Passing after (this branch dev'd into the same environment):
The new testset in
test/autodespecialize.jlassertsnumargsof the wrappedf/jacequals that of the raw functions (this is[1] != [3]on master, so it fails without the fix) and runsEnzyme.autodiff(Reverse, ...)throughremakeof aget_concrete_problemresult.Runic (
--check --diff, Runic 1.10.0) andtyposon the diff: clean.Not verified
Only the
NonlinearSolveBasesublibrary was tested locally; downstreamNonlinearSolvegroups and the SciMLSensitivityCore8run against the fixed version are still in progress locally and will be reported on the MTK PR.🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn