Repository navigation
Despecialize DAE residual functions - #4239
Merged
ChrisRackauckas merged 2 commits intoAug 13, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
This was referenced Aug 13, 2026
ChrisRackauckas
marked this pull request as ready for review
August 13, 2026 21:30
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
AutoDespecializenow wraps in-placeDAEFunctionresiduals 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), soDFBDFcan 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_paramsinterface and erases an unboundedIDparameter 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, andFullSpecializeare unchanged.Ignore this PR until it has been reviewed by @ChrisRackauckas.
Failing before
With the final regression test applied to unmodified DiffEqBase:
The DAE test failed its concrete
DAEFunctionandDAEProblemtype-equality assertions. Applying only the residual wrapper still failed the same two assertions because the twoOverrideInitDatavalues remained encoded in theIDtype parameter: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:
Passing after
The identical DiffEqBase focused command passed:
The identical ModelingToolkit integration passed. It asserted different source
MTKParametersand generated-function types, followed by identical solver-facing problem and DFBDF cache types afterinit, successful solves, and the analytic endpoint for both AD choices:A separate OrdinaryDiffEqBDF integration exercised two handwritten residual types and two parameter types under
AutoForwardDiff()andAutoFiniteDiff():Full local DiffEqBase groups:
Julia Runic check,
typos --diff, andgit diff --checkall exited 0. No public API or documentation changed, so a docs build was not required.Compile/runtime measurement
Before adding the separate
DFBDFprecompile workload, fresh-processinitmeasurements on the one-state DAE were: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
AutoDespecializeversus 66.0 μs forFullSpecialize, about 5% overhead on this deliberately tiny problem. A stacked follow-up precompiles the stableDFBDFDAE 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.