Skip to content

Add AutoDePSpecialize specialization level - #1458

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:add-autodepspecialize
Jul 22, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:add-autodepspecialize

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Note

Draft PR — please ignore until reviewed by @ChrisRackauckas.

Adds AutoDePSpecialize <: AbstractSpecialization, a specialization level that extends AutoSpecialize by also de-specializing the parameter object: solver paths with an opaque-parameter strategy pack an isbits, non-NullParameters p into a fixed-type opaque container (e.g. RespecializeParams.OpaqueParams) and install wrappers whose signatures carry the container type in the p slot. The concretized problem type — and the solver compilation — becomes independent of the user's parameter struct type, so one precompiled solve covers all isbits parameter types, while the user's f still receives p fully typed via an allocation-free unpack.

SciMLBase only defines the marker: type + docstring, @public, @docs entry in the Specialization Levels section of interfaces/Problems.md, and "AutoDePSpecialize" added to the SpecializationLevel preference allowlist. No new dependencies — the wrapping is solver-owned, so any function family (ODE, nonlinear, …) can implement its own strategy.

Placing the level here (rather than in DiffEqBase, where an earlier revision defined it) is per @ChrisRackauckas's direction so that NonlinearSolve.jl can implement the same level for its residual wrappers. The ODE-stack implementation and benchmarks live in SciML/OrdinaryDiffEq.jl#3692 (measured there: first-solve TTFX for a never-seen parameter struct 12.1 s → 0.43 s for DefaultODEAlgorithm, runtime within ~2% of AutoSpecialize).

Construction through the generic AbstractSciMLFunction constructor branches already works for arbitrary specialization types, so no constructor changes are needed; the marker alone performs no wrapping in SciMLBase (fields stay concretely typed, p untouched), which the new tests in test/problem_building_test.jl assert, along with specialization() round-tripping and unwrapped_f preserving the marker.

Version: 3.36.1 → 3.37.0 (new public API).

Tests run locally: test/problem_building_test.jl with dev'd SciMLBase — all pass including the 8 new assertions (AutoDePSpecialize specialization marker | 8 pass). Runic applied to changed .jl files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UuAbA8hSnrirMrJjFqxwn5

A new AbstractSpecialization marker that extends AutoSpecialize by also
de-specializing the parameter object: solver paths with an opaque-parameter
strategy (e.g. RespecializeParams.OpaqueParams in DiffEqBase's promote_f)
pack isbits p into a fixed-type container and wrap callables with the
container type in the p slot, making the concretized problem type — and the
solver compilation — independent of the user's parameter struct type. One
precompiled solve is then shared across all isbits parameter types, while
the user's f still receives p at its original concrete type via a
type-stable, allocation-free unpack.

SciMLBase only defines the marker (public, documented, allowed in the
SpecializationLevel preference); the wrapping itself is solver-owned so any
function family can implement it — the immediate consumers are DiffEqBase
(SciML/OrdinaryDiffEq.jl#3692) and, prospectively, NonlinearSolve.jl.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Jul 22, 2026
Per @ChrisRackauckas's direction the AutoDePSpecialize marker belongs in
SciMLBase so other solver stacks (NonlinearSolve.jl) can implement the same
level for their own function families. The type is now defined and documented
in SciMLBase (SciML/SciMLBase.jl#1458); this repo imports it from SciMLBase
(the owner) rather than defining it in DiffEqBase.

- DiffEqBase: import SciMLBase.AutoDePSpecialize (was a local struct in
  opaque_void.jl); still re-exported. opaque_void.jl keeps only the
  opaque-p machinery (OpaqueVoid, wrap_void_opaque, ...).
- OrdinaryDiffEqCore / OrdinaryDiffEq: import the marker from SciMLBase
  (owner) instead of forwarding through DiffEqBase, and re-export.
- docs/src/api/diffeqbase.md: @docs entry now targets
  SciMLBase.AutoDePSpecialize, framed as the level DiffEqBase implements.
- compat: SciMLBase = "3.37" floor in DiffEqBase, OrdinaryDiffEqCore, and
  OrdinaryDiffEq (the release that adds the marker).

Verified: GROUP=Core DiffEqBase tests pass against dev SciMLBase 3.37 (13/13
opaque tests + rest of Core); end-to-end AutoDePSpecialize across
Tsit5/Vern7/Vern9/Rosenbrock23/Rodas5P/FBDF/Default with the SciMLBase-owned
marker, interpolation, unpack roundtrip, and function-barrier zero-alloc all
green.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 22, 2026 20:38
@ChrisRackauckas
ChrisRackauckas merged commit 74ff952 into SciML:master Jul 22, 2026
48 of 63 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Jul 23, 2026
…paque

The AutoDePSpecialize glue that is identical across solver stacks now lives in
the shared packages, so NonlinearSolve.jl can reuse it verbatim:
- should_opaque_p → SciMLBase (SciML/SciMLBase.jl#1458), next to the marker and
  NullParameters.
- wrap_void_opaque installer + container/signature helpers → RespecializeParams
  (SciML/RespecializeParams.jl#23, v0.1.4).

opaque_void.jl drops from ~73 to ~24 lines — only the DiffEqBase-owned
wrapfun_iip_opaque stub (FD-ext methods) remains. promote_f calls
SciMLBase.should_opaque_p, RespecializeParams.wrap_void_opaque(ff, P,
(natural_sig,)), and pack_auto. What stays here is genuinely ODE-specific: the
ODEFunction tgrad/jac/sparsity threading in promote_f and the FD-ext 4-variant
dual-signature builder. Compat floor RespecializeParams = "0.1.4".

Verified against dev SciMLBase 3.37 + RespecializeParams 0.1.4: GROUP=Core
passes (Opaque-p Hook 13/13, ForwardDiff Dual Detection); end-to-end across all
seven solver configs green.

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Added should_opaque_p(p) alongside the AutoDePSpecialize marker — the default policy for whether the level de-specializes a parameter (isbits(p) && !(p isa NullParameters)). It lives here because it references NullParameters and both consuming stacks (DiffEqBase, NonlinearSolve) dep SciMLBase, so they share one policy instead of each inlining the check. @public + documented (Problems.md @docs) + tested (problem_building_test.jl, 6 assertions). The mechanism it gates — containers, OpaqueVoid, the wrap_void_opaque installer — lives in RespecializeParams (SciML/RespecializeParams.jl#23).

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