Skip to content

Despecialize DAE residual functions - #4239

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/despecialize-dae-residual
Aug 13, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/despecialize-dae-residual

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

What changed

AutoDespecialize now wraps in-place DAEFunction residuals behind the same parameter-unwrapping barrier used for ODE functions. The ForwardDiff-aware wrapper accepts the five-argument DAE residual signature (resid, du, u, p, t), so DFBDF can reuse one concrete problem and nonlinear-cache type across different residual and parameter types.

The generic AutoDespecialize path also widens model-specific SciMLFunction metadata. It uses SciMLBase's public widen_bounded_type_params interface and erases an unbounded ID parameter while retaining the original metadata value. This contains ModelingToolkit initialization data behind the same function barrier instead of allowing each compiled system to specialize the solver-facing function type. AutoSpecialize, AutoRespecialize, and FullSpecialize are unchanged.

Ignore this PR until it has been reviewed by @ChrisRackauckas.

Failing before

With the final regression test applied to unmodified DiffEqBase:

julia +release --startup-file=no --project=lib/DiffEqBase -e 'include("lib/DiffEqBase/test/despecialized_p_test.jl")'

The DAE test failed its concrete DAEFunction and DAEProblem type-equality assertions. Applying only the residual wrapper still failed the same two assertions because the two OverrideInitData values remained encoded in the ID type parameter:

other differential equation functions use the dynamic path | 21 pass / 2 fail / 23 total

The focused ModelingToolkit integration then compiled two different DAE systems. With the residual wrapper but before metadata widening, both ForwardDiff and FiniteDiff cases failed their problem-type and DFBDF-cache-type equality assertions:

MTK DAE AutoDespecialize | 16 pass / 4 fail / 20 total

Passing after

The identical DiffEqBase focused command passed:

other differential equation functions use the dynamic path | 23 pass / 23 total

The identical ModelingToolkit integration passed. It asserted different source MTKParameters and generated-function types, followed by identical solver-facing problem and DFBDF cache types after init, successful solves, and the analytic endpoint for both AD choices:

MTK DAE AutoDespecialize | 20 pass / 20 total

A separate OrdinaryDiffEqBDF integration exercised two handwritten residual types and two parameter types under AutoForwardDiff() and AutoFiniteDiff():

DFBDF despecializes DAE residuals | 12 pass / 12 total

Full local DiffEqBase groups:

GROUP=Core julia +release --startup-file=no --project=lib/DiffEqBase -e 'using Pkg; Pkg.test(coverage=false)'
Testing DiffEqBase tests passed

GROUP=QA julia +release --startup-file=no --project=lib/DiffEqBase -e 'using Pkg; Pkg.test(coverage=false)'
Aqua | 9 pass / 9 total
Testing DiffEqBase tests passed

Julia Runic check, typos --diff, and git diff --check all exited 0. No public API or documentation changed, so a docs build was not required.

Compile/runtime measurement

Before adding the separate DFBDF precompile workload, fresh-process init measurements on the one-state DAE were:

AutoDespecialize first: 2.35 s compile
AutoDespecialize second distinct model: 0.382 s compile
FullSpecialize first: 1.56 s compile
FullSpecialize second distinct model: 1.15 s compile

The second-model comparison shows the stable solver cache removing about 0.77 s (67%) of compilation. Warm solve time over 100 samples was 69.5 μs for AutoDespecialize versus 66.0 μs for FullSpecialize, about 5% overhead on this deliberately tiny problem. A stacked follow-up precompiles the stable DFBDF DAE path to remove the remaining first-use solver-cache compilation.

Not verified

GPU and Julia prerelease paths were not run locally. The full ModelingToolkit suite was not run locally; the discriminating two-system integration was run against the ModelingToolkit AutoDespecialize branch.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 13, 2026 21:30
@ChrisRackauckas
ChrisRackauckas merged commit 9d92d1c into SciML:master Aug 13, 2026
239 of 271 checks passed
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.

2 participants