Skip to content

Use DEFAULT_SPECIALIZATION for all SciMLFunction constructors#1298

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nonlinear-autospecialize-default
Mar 29, 2026
Merged

Use DEFAULT_SPECIALIZATION for all SciMLFunction constructors#1298
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nonlinear-autospecialize-default

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • Change NonlinearFunction constructors to use DEFAULT_SPECIALIZATION (defaults to AutoSpecialize via Preferences) instead of hardcoded FullSpecialize
  • This matches how the preference system was intended to work — DEFAULT_SPECIALIZATION already exists and defaults to AutoSpecialize, but the NonlinearFunction constructors were bypassing it

Motivation

SciML/NonlinearSolve.jl#838 adds AutoSpecialize/norecompile infrastructure to NonlinearSolve. When NonlinearFunction uses AutoSpecialize, NonlinearSolve wraps the function in FunctionWrappers so that solving with different functions doesn't trigger recompilation each time. Benchmarks show ~85% reduction in per-function compilation overhead.

Without NonlinearSolve.jl#838 merged, AutoSpecialize is a no-op — the trait is stored in the type parameter but never read. So this change is backwards compatible.

What changes

# Before
NonlinearFunction{iip}(f)  NonlinearFunction{iip, FullSpecialize}(f)

# After  
NonlinearFunction{iip}(f)  NonlinearFunction{iip, DEFAULT_SPECIALIZATION}(f)
# DEFAULT_SPECIALIZATION defaults to AutoSpecialize via Preferences

Users can override via Preferences.@set_preferences!("SciMLBase", "SpecializationLevel" => "FullSpecialize") if needed.

🤖 Generated with Claude Code

Co-Authored-By: Chris Rackauckas accounts@chrisrackauckas.com

Change all SciMLFunction constructors (ODEFunction, NonlinearFunction,
DAEFunction, SDEFunction, DDEFunction, DiscreteFunction, RODEFunction,
BVPFunction, IntegralFunction, etc.) to use DEFAULT_SPECIALIZATION
instead of hardcoded FullSpecialize.

DEFAULT_SPECIALIZATION is set via Preferences and defaults to
AutoSpecialize. The preference system already existed but constructors
were bypassing it.

The only places that retain explicit FullSpecialize are:
- The struct definition itself
- unwrapped_f methods (which construct fully-typed copies)
- Documentation/comments

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the nonlinear-autospecialize-default branch from b14675e to 28e884f Compare March 29, 2026 11:45
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title Use DEFAULT_SPECIALIZATION for NonlinearFunction constructors Use DEFAULT_SPECIALIZATION for all SciMLFunction constructors Mar 29, 2026
@ChrisRackauckas ChrisRackauckas merged commit 7c96038 into SciML:master Mar 29, 2026
43 of 61 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request Mar 29, 2026
The change in SciML#1298 exposed multiple breaking issues:
- BigFloat tableau coefficients promote t past FunctionWrapper signatures
- GradientTracer/sparsity detection types not in wrapper signatures
- MatrixOperator jac_prototype causes promote_op → Union{} in promote_f
- Hard DAE numerical accuracy regression with wrapped functions

Deferring this to v4 where the underlying issues (tableau two-type
constructors, promote_f robustness) can be addressed properly.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request Mar 30, 2026
Only reverts ODEFunction, SplitFunction, and DynamicalODEFunction
back to FullSpecialize. Other function types (NonlinearFunction,
SDEFunction, DiscreteFunction, etc.) keep DEFAULT_SPECIALIZATION
from SciML#1298.

The ODEFunction change exposed multiple issues in OrdinaryDiffEq.jl:
- BigFloat tableau c promotes t past FunctionWrapper signatures
- GradientTracer types not in wrapper signatures (AutoSparse)
- MatrixOperator jac_prototype causes promote_op → Union{}
- Hard DAE numerical accuracy regression

Deferring ODEFunction AutoSpecialize default to v4.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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