Skip to content

DiffEqBase: wrap mass-matrix problems on the finite-difference promote_f path (default algorithm was never despecialized) - #4459

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:diffeqbase-wrap-mass-matrix-default
Sep 5, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:diffeqbase-wrap-mass-matrix-default

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Draft — please ignore until reviewed by @ChrisRackauckas.

What changed and why

solve(prob) / init(prob) with no algorithm resolves, via prepare_alg(nothing, …), to DefaultODEAlgorithm(autodiff = AutoFiniteDiff()). Because that algorithm does not use ForwardDiff, get_concrete_problem takes the non-ForwardDiff promote_f path, and that path refused to wrap any ODEFunction whose mass_matrix is not UniformScaling. So on every mass-matrix problem the default algorithm ran with the model's own RHS type baked into the integrator: the whole composite solve compiled again per model (~12 s each in the reproducer below), while an explicit Rodas5P(), which takes the ForwardDiff path, already shared one integrator type across models. The gate was introduced with the forwarddiffs_model split (48b1043) without a stated reason for the mass-matrix exclusion; finite differences only ever call the RHS with the state's eltype, so the single-signature wrapper is sufficient. The jac === nothing opt-out on that path is unchanged.

This is the last piece that kept ModelingToolkit mass-matrix DAEs from being despecialized under the default algorithm (context: https://github.com/ChrisRackauckas/InternalJunk/issues/88 and SciML/ModelingToolkit.jl#5061).

Verification

New lib/DiffEqBase/test/despecialize_mass_matrix.jl (Core group): two mass-matrix problems with different RHS types, concretized with a non-ForwardDiff algorithm (forwarddiffs_model(::FiniteDiffAlg) = false, mirroring the resolved default), must both come back wrapped and with identical concretized types, for AutoDespecialize and AutoSpecialize; a user Jacobian must still opt out.

Unmodified lib/DiffEqBase/src/solve.jl (git stash of the one-line change), same test file:

Test Summary:                                                  | Pass  Fail  Total  Time
mass-matrix problems are wrapped on the finite-difference path |    8     6     14  5.4s

With the change:

Test Summary:                                                  | Pass  Total  Time
mass-matrix problems are wrapped on the finite-difference path |   14     14  2.8s
Test Summary:                                                         | Pass  Total  Time
a user Jacobian still opts out of the finite-difference wrapping path |    1      1  0.8s

End to end (pure OrdinaryDiffEq 7.8.1, Julia 1.12.7, two AutoDespecialize mass-matrix problems with different RHS functions, init(prob) then solve!; @timed compile seconds):

integrator types identical integ.f.f solve! model A solve! model B
default algorithm, before false raw g1 12.75 11.56
default algorithm, after true FunctionWrappersWrapper 13.50 0.00
Rodas5P() (unchanged) true FunctionWrappersWrapper 4.19 0.05

Groups run locally from lib/DiffEqBase (GROUP=<name> julia --project=lib/DiffEqBase -e 'using Pkg; Pkg.test()', Julia 1.12.7):

Core          -> Despecialized mass-matrix problems | 15 15 3.2s ... Testing DiffEqBase tests passed
QA            -> Testing DiffEqBase tests passed
ModelingToolkit -> Null DE Handling | 36 36 2m39.9s ... Testing DiffEqBase tests passed
                 (run with https://github.com/SciML/SparseColumnPivotedQR.jl/pull/71 developed into the test env: AMD 0.5.4
                 otherwise breaks LinearSolve's precompile in every freshly resolved environment, master included)

Runic and typos clean on the touched files.

Not verified

  • Downstream, Downstream2, Static, Sundials groups and Julia 1.10.
  • Non-ForwardDiff explicit stiff algorithms on mass-matrix problems now also get the single-signature wrapper (e.g. Rodas5P(autodiff = AutoFiniteDiff())); the finite-difference Jacobian only calls the RHS with the state eltype, and the FunctionWrappersWrapper fallback policy (AllowNonIsBits) makes any other call fall back to the raw function rather than error, but I did not run those algorithms' own test suites.

🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

…e_f path

`prepare_alg(nothing, ...)` resolves the default algorithm to
`DefaultODEAlgorithm(autodiff = AutoFiniteDiff())`, so concretization takes the
non-ForwardDiff `promote_f` path. That path refused to wrap any problem whose
mass matrix is not `UniformScaling`, so `solve(prob)` on a mass-matrix
problem kept the model's RHS type in the integrator and the whole composite
solve compiled again for every model (~12 s each), while an explicit
`Rodas5P()` shared one integrator type across models. Finite differences only
ever call the RHS with the state's own eltype, so the single-signature wrapper
is sufficient here; the `jac === nothing` opt-out is kept.

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-Claude

ChrisRackauckas-Claude commented Sep 4, 2026 •

Copy link
Copy Markdown
Member Author

The current failed matrix is blocked before the changed DiffEqBase path runs. An exhaustive audit of all 167 failed-job logs found AMD.SS_Int in every one; there are zero unclassified failures. A representative Julia 1.10 AD job reports:

ERROR: The following 25 direct dependencies failed to precompile:
ERROR: LoadError: UndefVarError: `SS_Int` not defined
ERROR: LoadError: Failed to precompile LinearSolve

CI job: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/33891519079/job/101084174709

This reproduces on clean master after AMD 0.5.4 removed a private binding used by SparseColumnPivotedQR 2.1.7. It is tracked at SciML/SparseColumnPivotedQR.jl#72 and fixed by the green draft SciML/SparseColumnPivotedQR.jl#71. Local validation in this PR's body used that fix while retaining AMD 0.5.4.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 5, 2026 08:21
@ChrisRackauckas
ChrisRackauckas merged commit c241543 into SciML:master Sep 5, 2026
382 of 549 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]>
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Fix SciMLBase reexport QA on Julia LTS (#4450)
- Preserve conditioning in OOP no-init solves (#4438)
- Read the test group from GROUP like the CI passes it (#4447)
- Raise root GPU test timeout (#4449)
- Fix default SDE dt vector lengths (#4454)
- Bump DiffEqDevTools to 3.6.2 (#4461)
- 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)



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
* Resolve symbolic idxs in the integrator interpolant

`integrator(t; idxs = sym)` passed `idxs` straight to the dense-output
interpolant, which only accepts integer component indices, so any symbolic index
threw `ArgumentError: invalid index` and an observed equation could never be
retrieved. `sol(t; idxs = sym)` has resolved both for a long time.

Symbolic `idxs` now route to `SciMLBase.symbolic_interpolation`, which evaluates
the current step's interpolant and applies the symbolic getter to it. Integer,
`nothing`, and in-place calls are unchanged.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

* Route symbolic idxs for DelayDiffEq integrators too

`DDEIntegrator` has the same gap `ODEIntegrator` did: `integrator(t; idxs = sym)`
went straight to the dense-output interpolant, which only accepts integer
component indices, so symbolic indexes threw and observed equations were
unreachable.

The predicate moves to the public `SciMLBase.has_symbolic_idxs` rather than
staying an OrdinaryDiffEqCore internal, since DelayDiffEq, Sundials and
ODEInterfaceDiffEq all need the same decision.

`HistoryODEIntegrator` is deliberately left alone: it implements none of the
`SymbolicIndexingInterface` methods a `DEIntegrator` needs, so symbolic indexing
against it is unsupported before and after this change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

* Require SciMLBase 3.53 for has_symbolic_idxs

`has_symbolic_idxs` did not make it into the 3.52.0 release, so the floor moves
to the version that carries it.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Preserve conditioning in OOP no-init solves (#4438)
- Read the test group from GROUP like the CI passes it (#4447)
- Raise root GPU test timeout (#4449)
- Fix default SDE dt vector lengths (#4454)
- Bump DiffEqDevTools to 3.6.2 (#4461)
- 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)



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.

2 participants