Skip to content

Precompile SDE solves through specialization levels - #4467

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:codex/precompile-standard-sde
Sep 7, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:codex/precompile-standard-sde

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

What changed and why

SDE concretization now applies the existing SciML specialization levels to both the drift and diffusion functions, preserving the marker and producing reusable concrete function types for AutoSpecialize, AutoDespecialize, AutoDePSpecialize/AutoRespecialize, FunctionWrapperSpecialize, and NoSpecialize. Non-diagonal diffusion uses noise_rate_prototype for its wrapper signature, and repeated concretization is type-stable instead of nesting wrappers.

StochasticDiffEq now mirrors the ODE precompile preference matrix and constructs its workloads with SDEProblem{isinplace, specialize}. The earlier typed Ref{Function} default-dispatch workaround has been removed; this revision does not change the default forwarding methods.

This supersedes the rejected implementation in #4457.

This PR depends on the missing public SDE constructor route added in SciML/SciMLBase.jl#1580. Its SciMLBase = "3.51" compatibility floor is intentionally unreleased until that prerequisite merges and is tagged, so registry-only CI may remain unresolved in the meantime.

PrecompileTools and Preferences are both MIT-licensed, matching this repository.

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

Failing before, passing after

I ran the same two assertions against clean OrdinaryDiffEq master c241543c4b, with the SciMLBase constructor prerequisite developed locally, and against this branch:

using StochasticDiffEq, Test
f1!(du, u, p, t) = (du .= p.drift .* u)
g1!(du, u, p, t) = (du .= p.diffusion .* u)
f2!(du, u, p, t) = (du .= (p.drift - 0.01) .* u)
g2!(du, u, p, t) = (du .= (p.diffusion - 0.01) .* u)
p = (drift = 1.01, diffusion = 0.87)
prob1 = SDEProblem{true, SciMLBase.AutoDespecialize}(f1!, g1!, ones(2), (0.0, 0.1), p)
prob2 = SDEProblem{true, SciMLBase.AutoDespecialize}(f2!, g2!, ones(2), (0.0, 0.1), p)
f1 = init(prob1, SOSRI(); dt = 0.1).sol.prob.f
f2 = init(prob2, SOSRI(); dt = 0.1).sol.prob.f
@test SciMLBase.specialization(f1) === SciMLBase.AutoDespecialize
@test typeof(f1) === typeof(f2)

Before:

specialization=AutoSpecialize
same_concrete_type=false
SDE concretization specialization: 2 failed

After:

specialization=AutoDespecialize
same_concrete_type=true
SDE concretization specialization | 2 passed

Fresh-process measurement

Julia 1.12.7, same resolved environment, one process per measurement. The explicit vector SOSRI() solve compiled in 1.14 s and 2.09 s in two runs, compared with 6.64 s on master (68%–83% lower). Process elapsed time was 10.25 s and 12.03 s, compared with 12.91 s on master.

The no-algorithm default path did not improve in the revised design, so the earlier default-path performance claims have been removed. This PR now claims only the specialization-backed explicit-solver workload improvement.

Benchmark command:

/usr/bin/time -f 'process_elapsed=%e max_rss_kb=%M' \
  /home/crackauc/.juliaup/bin/julia +1.12 --startup-file=no \
  --project=lib/StochasticDiffEq ../benchmark_sde.jl SOSRI vector

Verification

Julia 1.12.4:

GROUP=DiffEqBase_Core julia --project=. -e 'using Pkg; Pkg.test()'
Despecialized-p Hook | 50 passed
Despecialized mass-matrix problems | 15 passed
Testing DiffEqBase tests passed
Testing OrdinaryDiffEq tests passed

GROUP=StochasticDiffEq_Core julia --project=. -e 'using Pkg; Pkg.test()'
Precompile Workload Tests | 20 passed
Mass matrix tests | 5 passed
Noise Type Tests | 2024 passed
Solver Reversal Tests | 152 passed
Testing StochasticDiffEq tests passed
Testing OrdinaryDiffEq tests passed

GROUP=QA julia --project=. -e 'using Pkg; Pkg.test()'
Quality Assurance Tests | 109 passed
Testing OrdinaryDiffEq tests passed

Julia 1.10.11 in an isolated environment developing SciMLBase 3.51.0, DiffEqBase 7.21.0, and StochasticDiffEq 7.2.0:

Pkg.precompile()
50 dependencies successfully precompiled

include("lib/StochasticDiffEq/test/precompilation_tests.jl")
Julia 1.10 specialization tests passed
julia --project=. -e 'using Runic; exit(Runic.main(ARGS))' -- --check <changed Julia files>
exit code 0

typos <changed files>
exit code 0

git diff --check upstream/master
exit code 0

Not run locally: GPU, convergence, downstream, or documentation jobs. No documentation or public name was added in this repository; the new public constructor is documented and docs-built in the prerequisite SciMLBase PR.

Reviewer judgment: stochastic implicit methods use function-derived ForwardDiff tags that cannot be represented by the fixed dual signatures used for the ODE wrapper path. Those SDE functions therefore retain their specialization marker and parameter despecialization but skip installation of the fixed ForwardDiff wrapper; the ImplicitRKMil and mass-matrix tests cover this branch.

🤖 Generated with Codex CLI 0.153.4 (model: unknown; session: local thread 01a06c1d-564b-7ef0-ada6-d83a233b55e2; no shareable URL was exposed).

Add SDE specialization handling to DiffEqBase concretization and mirror the ODE specialization preference matrix in StochasticDiffEq precompilation.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: OpenAI Codex <[email protected]>
Agent-Harness: Codex CLI 0.153.4
Agent-Model: unknown
Agent-Session: local thread 01a06c1d-564b-7ef0-ada6-d83a233b55e2
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI note (2026-09-05): every failed job inspected so far stops during dependency resolution, before tests run. The checked-out StochasticDiffEq 7.2.0 requires SciMLBase 3.51, while General currently contains SciMLBase only through 3.50.2. The resolver therefore reports Unsatisfiable requirements detected for package SciMLBase.

This PR is intentionally stacked on SciML/SciMLBase.jl#1580. After that prerequisite is merged and SciMLBase 3.51 is available, these jobs need to be rerun. The PR body records the local validation performed with both feature checkouts developed together.

ChrisRackauckas and others added 2 commits September 7, 2026 06:41
SDE AutoSpecialize now installs FunctionWrappers, matching the ODE path.
AllocCheck flags the FunctionWrappers ccall as dynamic dispatch, and
`@allocated` of `perform_step!` inside a `@testset` measures runtime
dispatch of the wrapped integrator rather than the step.

Use FullSpecialize for the sparse EulerHeun AllocCheck, as the ODE
allocation tests already do, and run `perform_step!` through a function
barrier like `step_void!`.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Grok <[email protected]>
Agent-Harness: Grok CLI 1.0.13
Agent-Model: grok-4.6
Agent-Session: local session 01a07b4a-0048-7b82-bdcf-da33c4b4d812
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI follow-up on 44fd6de61: the four remaining red jobs were StochasticDiffEq allocation tests, not resolver failures.

SDE AutoSpecialize now wraps f and g in FunctionWrappers, matching the ODE path. That is allocation-free at runtime (@allocated of perform_step! is 0 behind a function barrier; dense EulerHeun already passed). What broke:

  1. Interface3 nondiag_noise_eulerheun_test.jl uses AllocCheck.check_allocs. AllocCheck flags the FunctionWrappers ccall as dynamic dispatch. ODE allocation tests already avoid this with FullSpecialize.
  2. Allocations perform_step! allocation - EM calls perform_step! directly inside a @testset. The wrapped integrator is not inferred there, so @allocated measures runtime dispatch (288 bytes) rather than the step. step! already went through step_void! and passed.

Failing before, passing after

Same assertions on this checkout, Julia 1.12.7:

Before (unfixed tests, wrapped AutoSpecialize):

testset perform_step! allocs=288
AutoSpecialize AllocCheck count=12   # FunctionWrappers ccall / reinit_wrapper
FullSpecialize AllocCheck count=0

After (perform_step_void! + SDEProblem{true, FullSpecialize} for the AllocCheck case):

alloc_tests   | 9 passed
nondiag_eulerheun | 2 passed

Precompilation tests still exit 0. Runic --check and typos on the two files are clean.

GPU jobs were not part of this; they were still queued on the previous run.

🤖 Generated with Grok CLI 1.0.13 (model: grok-4.6; session: local 01a07b4a-0048-7b82-bdcf-da33c4b4d812)

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 7, 2026 11:57
@ChrisRackauckas
ChrisRackauckas merged commit efef2fc into SciML:master Sep 7, 2026
283 of 284 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Precompile SDE solves through specialization levels (#4467)
- Add 32-bit InterfaceI CI lane via test_groups.toml (#4480)
- incorporate time/stab filter for larger steps in FBDF (#3878)
- Keep 32-bit CI lane hard-failing. (#4482)
- Correct and validate FBDF time and stability filters (#4484)
- Keep DAE init from overwriting uprev during callback truncation (#4486)
- DiffEqBase: Int64 interp_points range length for 32-bit (#4487)
- Release OrdinaryDiffEqBDF 2.4.7 (#4490)
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)



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