Skip to content

Differentiate wrapped DAEFunctions with chunk size 1, like ODEFunctions (fixes #4458) - #4464

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:dae-wrapped-chunksize-1
Sep 7, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:dae-wrapped-chunksize-1

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Draft — please ignore until reviewed by @ChrisRackauckas.

Closes #4458.

What changed and why

OrdinaryDiffEqDifferentiation._prepare_ADType_fwd forces AutoForwardDiff{1} when the problem's function is wrapped by AutoSpecialize/AutoDespecialize, because such a wrapper carries only Float64 and one-chunk dual signatures and because a fixed chunk is what keeps the integrator type independent of the model. That rule was written as prob.f isa ODEFunction && prob.f.f isa FunctionWrappersWrapper, so a DAEFunction with exactly the same wrapper fell through to pickchunksize(length(u)). The chunk then lands in the NLNewton Jacobian 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). The AutoFiniteDiff complex-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_chunksize resolves Val(0) to Val(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-equation DAEProblem at n = 8 and n = 12, prepare_ADType(AutoForwardDiff(), cprob, …) must return AutoForwardDiff{1}, the two DFBDF integrators must have identical types, and both solves must succeed.

Unmodified alg_utils.jl (git stash of the change), same test file:

  Expression: ad isa AutoForwardDiff{1}
   Evaluated: AutoForwardDiff(tag=ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}()) isa AutoForwardDiff{1}
Test Summary:                                           | Pass  Fail  Total  Time
wrapped DAEFunction is differentiated with chunk size 1 |    2     2      4  3.1s

With the change:

Test Summary:                                           | Pass  Total  Time
wrapped DAEFunction is differentiated with chunk size 1 |    4      4  0.3s
Test Summary:                                            | Pass  Total  Time
DFBDF integrator type is independent of the state length |    4      4  4.8s

Reproducer from #4458 (pure OrdinaryDiffEq, DAEProblem{true, AutoDespecialize} + DFBDF at n = 8 / 12 / 16, @timed compile seconds), with the change:

  DAEProblem n=8   DFBDF   init   1.28/  1.28  solve!   2.25/  2.24  retcode Success
  DAEProblem n=12  DFBDF   init   0.00/  0.00  solve!   0.00/  0.00  retcode Success   (was 0.70 / 3.98)
  DAEProblem n=16  DFBDF   init   0.00/  0.00  solve!   0.00/  0.00  retcode Success
  DFBDF integrator types identical n=8 vs n=12: true                                   (was false)
  FBDF  integrator types identical n=8 vs n=12: true

Groups run locally (Julia 1.12.7):

OrdinaryDiffEqDifferentiation  GROUP=Core -> Wrapped DAE chunk size | 8 8 8.0s ... Testing OrdinaryDiffEqDifferentiation tests passed
OrdinaryDiffEqDifferentiation  GROUP=QA   -> JET Tests 1/1, Aqua 19/19 ... Testing OrdinaryDiffEqDifferentiation tests passed
OrdinaryDiffEqBDF              GROUP=Core -> 11 testsets incl. DAE Convergence/AD/Initialization/Nonlinear Solve Path ... Testing OrdinaryDiffEqBDF tests passed

Runic and typos clean on the touched files.

Not verified

  • Julia 1.10, GPU groups, downstream solver packages beyond OrdinaryDiffEqBDF.
  • Algorithms that set an explicit chunk_size are 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

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
ChrisRackauckas marked this pull request as ready for review September 7, 2026 06:20
@ChrisRackauckas
ChrisRackauckas merged commit ed04e84 into SciML:master Sep 7, 2026
187 checks passed
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]>
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.

DFBDF/DImplicitEuler on a despecialized DAEProblem recompile per state size (chunk size baked into the NLNewton JacobianConfig)

2 participants