Repository navigation
Differentiate wrapped DAEFunctions with chunk size 1, like ODEFunctions (fixes #4458) - #4464
Merged
ChrisRackauckas merged 1 commit intoSep 7, 2026
Conversation
The AutoSpecialize/AutoDespecialize wrapper carries only Float64 and one-chunk dual signatures, and a fixed chunk is what keeps the integrator type independent of the model. `_prepare_ADType_fwd` applied that rule only to `ODEFunction`, so a wrapped `DAEFunction` got `pickchunksize(length(u))`, which ends up in the NLNewton Jacobian config inside the DFBDF cache type and recompiles the whole step for every new state length. Route both function types (and the AutoFiniteDiff complex-fdtype guard) through `_has_wrapped_f`. Closes SciML#4458. 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:20
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 7, 2026
- DiffEqBase: wrap mass-matrix problems on the finite-difference promote_f path (#4459) - Preserve the DAE step start during callback interpolation (#4466) - Release DiffEqBase 7.20.1 (#4474) - Release OrdinaryDiffEqCore 4.16.1 (#4475) - Release OrdinaryDiffEqNonlinearSolve 2.9.5 (#4476) - Run IDSolve's nonlinear solve at the integrator's tolerances (#4468) - Build W through the allocating path for a sparse GPU Jacobian with a scalar mass matrix (#4452) - Fix threaded stochastic work-precision isolation (#4462) - Differentiate wrapped DAEFunctions with chunk size 1, like ODEFunctions (#4464) - Rebuild MethodOfSteps W after history updates (#4396) 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.
Closes #4458.
What changed and why
OrdinaryDiffEqDifferentiation._prepare_ADType_fwdforcesAutoForwardDiff{1}when the problem's function is wrapped by AutoSpecialize/AutoDespecialize, because such a wrapper carries onlyFloat64and one-chunk dual signatures and because a fixed chunk is what keeps the integrator type independent of the model. That rule was written asprob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrapper, so aDAEFunctionwith exactly the same wrapper fell through topickchunksize(length(u)). The chunk then lands in theNLNewtonJacobian config inside the DFBDF/DImplicitEuler cache type, and every new state length below the chunk cap recompiles the whole step (~3–4 s in the issue). TheAutoFiniteDiffcomplex-fdtype guard had the same ODE-only restriction.Both now go through
_has_wrapped_f(f::Union{ODEFunction, DAEFunction}). The DAE wrapper from DiffEqBase already builds its dual signature with chunk 1 (_forwarddiff_chunksizeresolvesVal(0)toVal(1)), so the solver side now matches it, the same way the ODE path does.Verification
New
lib/OrdinaryDiffEqDifferentiation/test/wrapped_dae_chunksize_tests.jl(Core group): for a despecialized heat-equationDAEProblematn = 8andn = 12,prepare_ADType(AutoForwardDiff(), cprob, …)must returnAutoForwardDiff{1}, the twoDFBDFintegrators must have identical types, and both solves must succeed.Unmodified
alg_utils.jl(git stashof the change), same test file:With the change:
Reproducer from #4458 (pure OrdinaryDiffEq,
DAEProblem{true, AutoDespecialize}+DFBDFat n = 8 / 12 / 16,@timedcompile seconds), with the change:Groups run locally (Julia 1.12.7):
Runic and typos clean on the touched files.
Not verified
chunk_sizeare unaffected (the rule only applies when the chunk is unset), so I did not test those.🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn