Skip to content

Resolve default ODE tolerances before specialized init (TTFX) - #4618

Merged
ChrisRackauckas merged 13 commits into
SciML:masterfrom
ChrisRackauckas-Claude:ttfx-tolerance-kwargs
Oct 31, 2026
Merged

ChrisRackauckas merged 13 commits into
SciML:masterfrom
ChrisRackauckas-Claude:ttfx-tolerance-kwargs

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

🚧 UNREVIEWED — awaiting review by @ChrisRackauckas. Filed by an AI agent running as @ChrisRackauckas; Chris has not seen this.

Please ignore until reviewed by @ChrisRackauckas.

What changed and why

solve(prob, alg; abstol, reltol) was specializing OrdinaryDiffEqCore's heavy _ode_init keyword body on Float64 instead of the workload-precompiled Nothing defaults. This PR resolves nothing tolerances to concrete defaults in SciMLBase.__init before calling public _ode_init, so the heavy keyword body always sees concrete types (TTFX).

  • resolve_ode_tolerances(prob, ::Nothing, abstol, reltol) is a dedicated method for a nothing state. It returns the scalar Float64 defaults (1//10^6, 1//10^3; false for discrete problems; supplied tolerances go through real.(...)), so no Float64[] is built on the tolerance path. __init and _ode_init pass prob.u0 straight through.
  • StochasticDiffEqCore applies SDE/RODE defaults (1//10^2) and real.(...) on user tolerances, then calls the same public _ode_init (single kwcall layer, required for ExplicitImports and for @inferred solve(... EM())). _sde_init has a matching u === nothing branch with Float64 eltypes.
  • The precompile workload covers omitted tolerances and a nothing state (resolve_ode_tolerances with a vector u0, nothing, and a null problem). This is a separate commit (2f0973dda) and can be dropped on its own; see the timing note below.
  • The @allocated(...) == 0 assertions on the nothing-state path are replaced by Base.return_types checks (see Verification).

Scope: DiffEqBase untouched. No new public names.

Open point for Chris: lib/OrdinaryDiffEqCore/src/solve.jl still has u = Float64[] in _ode_init (state coercion, not tolerances). It is unchanged here pending a decision on whether "no Float64[] at all" is wanted.

Verification

Head 94c978338 (previous review head 5d0e490; 2f0973dda is the precompile-workload commit).

Tests (this head)

  • OrdinaryDiffEqCore GROUP=Core, Julia 1.12.7: passes; "Tolerance Default Equality" 110/110.
  • Same group on Julia 1.10.12 (lts) with Pkg.test(coverage=true), as CI runs it: passes; "Tolerance Default Equality" 110/110.
  • StochasticDiffEq GROUP=Interface2, Julia 1.12.7: whole group passes; "SDE Default Tolerance Equality" 47/47 (20 + 27), "Element-wise Tolerances Tests" 12/12.
  • Runic --check and typos on the changed files: clean.

Failing before / passing after (5d0e490 sources with the new test file vs this head)

  • 5d0e490: 90 pass, 1 fail, 1 error. The "precompiled" test fails with 0 > 0; the nothing-u0 testset errors with MethodError: no method matching one(::Nothing).
  • This head: 110/110.
  • Mutation: this head's solve.jl without the precompile workload lines fails only the "precompiled" test (0 > 0), so that test discriminates the workload.

Allocation assertions removed. The earlier @allocated(...) == 0 asserts failed in CI on Julia 1.10 with Pkg.test(coverage=true) (Evaluated: 32 == 0; Core 108 passed, 2 failed locally): coverage instrumentation allocates 32 bytes. They also did not distinguish old from new code: resolve_ode_tolerances with Float64[] (old path) and with nothing both measure 0 bytes without coverage and 32 bytes with coverage (Julia 1.10.12), because the compiler elides the empty vector in a type-stable microbenchmark. The method-dispatch check (which(resolve_ode_tolerances, (typeof(prob), Nothing, Nothing, Nothing)) is the ::Nothing method) is what separates old from new, and it was already in the file. The replacement asserts Base.return_types(resolve_ode_tolerances, ...) == [Tuple{Float64, Float64}] for the omitted and the supplied tolerance calls; inference is unaffected by coverage.

Timing A/B (5d0e490 vs this head, 3 interleaved reps, shared machine under load): first-solve times are identical within noise (workload tolerances about 0.6 s on both; user tolerances about 1.0 s on both). Load time of using ModelingToolkit, OrdinaryDiffEq: 10.15-10.89 s before vs 9.92-10.27 s after. The ranges overlap, so the precompile commit has no measurable gain. The TTFX gain against master is already in 5d0e490:

case master PR (5d0e490)
ode workload tol first solve (3 reps) 1.14 / 1.18 / 1.26 s 1.06 / 0.86 / 0.74 s
ode user tol first solve (3 reps) 2.64 / 1.91 / 2.02 s 1.53 / 1.50 / 1.47 s
ode workload none first solve (3 reps) 0.57 / 0.60 / 0.57 s 0.61 / 0.63 / 0.83 s
ode user none first solve (3 reps) 1.39 / 1.50 / 1.31 s 1.47 / 1.90 / 1.38 s

Specialization property: after solve(prob, Tsit5()), a with-tolerance solve leaves the #_ode_init# kwbody specializations unchanged on this PR (5 to 5); on the merge-base the heavy #_ode_init# grows (5 to 6).

Defaults unchanged. Equality tests, unitful Quantity defaults, Float32 DAE, SDE SOSRI/EM/SRIW1, and complex user SDE tolerances (stored as Float64, SOSRI succeeds). @inferred solve(... EM(); dt) passes (Interface1 Inference 2/2); StochasticDiffEqCore GROUP=QA 21/21 (public _ode_init only, as of the earlier review head).

CI failures not caused by this PR

These are red on master as well (push runs on the default branch):

check classification
SciMLSensitivity Core1 / Core2 / Core4 red on master
OrdinaryDiffEqNonlinearSolve Core red on master (LineSearchException in newton_tests.jl)
Default GPU red on master

OrdinaryDiffEqCore Core (lts) and its Downgrade check failed on the allocation assertions above; the replacement is validated locally and CI on the new head is pending.

Risk assessment

  • Risk: low
  • Blast radius: OrdinaryDiffEqCore __init / _ode_init / precompile workload and StochasticDiffEqCore _sde_init; no public API change
  • Evidence: failing-before / passing-after (90 pass, 1 fail, 1 error vs 110/110); Core 110/110 on Julia 1.12.7 and on 1.10.12 with coverage; SDE equality 47/47; Runic/typos clean
  • Independent review: pending for the current head. Earlier heads were reviewed: Codex gpt-6.1-sol rated head 5d0e490 low, high confidence; earlier rounds covered older heads. The two later commits and the test change are not yet independently reviewed.
  • Merge: needs human review

Not verified

  • Load-independent instruction/allocation counts
  • Full OrdinaryDiffEq / DelayDiffEq / MTK suites beyond the groups above

Part of the MTK TTFX effort


🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

ChrisRackauckas and others added 8 commits September 23, 2026 21:53
Passing abstol/reltol used to specialize DiffEqBase solve and
OrdinaryDiffEqCore _ode_init on Float64 instead of Nothing, recompiling
the heavy init path (~0.7–1.9 s) even when MTK workloads already covered
solve without tolerances. Resolve nothing to the same concrete defaults
in DiffEqBase.solve/init and before _ode_init_impl so both call sites
share MethodInstances without changing numerical defaults.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.23-86fc751
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Drop the DiffEqBase solve/init inject so third-party ODE/DAE/discrete
solvers keep their own defaults. Resolve nothing tolerances only in
OrdinaryDiffEqCore._ode_init (internal helper, not public), with
SDE/RODE callers still passing their concrete 1e-2 defaults through.
Expand equality coverage for unitful, Float32 DAE, prob.kwargs, and
StochasticDiffEq SOSRI/EM/SRIW1.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.23-86fc751
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
_ode_init always resolves abstol/reltol before calling _ode_init_impl,
so the nothing/discrete/unitful default formula inside the impl was
unreachable and duplicated resolve_ode_tolerances. Assign the already-
resolved values directly and document that expectation.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.23-86fc751
Agent-Model: unknown
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Require resolved abstol/reltol on _ode_init_impl (no nothing defaults),
fix the comment that misstated the SDE path, hardcode master unitful
defaults in the equality test, and assert a with-tol solve does not add
an _ode_init_impl keyword-body specialization after a default solve.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.23-86fc751
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
The thin _ode_init wrapper that forwarded kwargs into _ode_init_impl
made @inferred solve(... EM) return Any. Resolve nothing tolerances in
SciMLBase.__init instead, and keep _ode_init as the single heavy body
that SDE calls directly with already-concrete abstol/reltol.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.23-86fc751
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Round-4 blockers: public _ode_init again accepts optional/nothing
tolerances (resolve then call _ode_init_impl), and StochasticDiffEqCore
applies real.(abstol/reltol) before calling _ode_init_impl so complex
user tolerances stay Float64 without breaking @inferred SDE solve.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Fold the heavy init body back into public _ode_init (optional
abstol/reltol + resolve) so SDE uses only the public API. SciMLBase.__init
still pre-resolves for TTFX; SDE keeps real.() then a single kwcall layer
so @inferred EM solve stays concrete.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Round-7 non-blocking cleanups only: drop retrospective "master"/prior-
behavior wording from docstrings and comments, and count specializations
via methods(fn) iteration instead of .ms. No behavior change.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/mtk-ttfx/jobs/tol/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4618/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Merged the default branch into this PR (clean merge, no conflicts; head 11e4522) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

ChrisRackauckas and others added 4 commits October 16, 2026 05:00
resolve_ode_tolerances dispatches on Nothing and returns the same
1e-6 and 1e-3 defaults an empty Float64 state produces, without
allocating that vector. StochasticDiffEqCore treats a nothing state
as Float64 when it builds tolerance eltypes. Tests check equality
with the empty-state result, zero allocation, and the Nothing method.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Grok <[email protected]>
Agent-Harness: Grok Build 1.0.70
Agent-Model: grok-4.7
Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4618 (no session URL)
The OrdinaryDiffEqCore workload resolves nothing abstol/reltol for a
vector state and for a nothing state, so those method instances exist
after loading. A test counts the Nothing specializations without
calling the method.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Grok <[email protected]>
Agent-Harness: Grok Build 1.0.70
Agent-Model: grok-4.7
Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4618 (no session URL)
The two `@allocated(...) == 0` assertions on resolve_ode_tolerances fail
under `Pkg.test(coverage=true)` on Julia 1.10 (`Evaluated: 32 == 0`):
coverage instrumentation allocates. They also did not distinguish the old
from the new code: the Float64[] path and the nothing path both measure
0 bytes without coverage and 32 bytes with it, because the compiler elides
the empty vector in a type-stable microbenchmark. The method-dispatch
check already in the file separates old from new.

Assert the inferred return type (Tuple{Float64, Float64}) instead, which
coverage does not affect.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Agent-Harness: Claude Code 2.1.316
Agent-Model: claude-sonnet-5-5
Agent-Session: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 31, 2026 10:19
@ChrisRackauckas
ChrisRackauckas merged commit 4017c37 into SciML:master Oct 31, 2026
267 of 273 checks passed
ChrisRackauckas referenced this pull request Nov 28, 2026
Bump version to 2.2.6
Bump version to 2.2.6
Bump version to 2.2.6
Bump version to 2.2.6
Bump version to 2.2.6
Bump version to 2.2.6

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: AI agent <[email protected]>
Agent-Harness: hourly_releases
Agent-Model: none (deterministic)
Agent-Session: local job hourly-release-74dba2e6-d998-45b2-acda-764f0cc7c3c4 (no session URL)
Agent-Session: local job hourly-release-3fa5fb01-9edb-4207-a008-f3e965ad262a (no session URL)
Agent-Session: local job hourly-release-12159859-e451-418a-b40a-03a35d145353 (no session URL)
Agent-Session: local job hourly-release-1f090ad0-9f29-4772-9a87-f993ebb136a2 (no session URL)
Agent-Session: local job hourly-release-399633b3-4944-4d57-9c31-97c7a8620b97 (no session URL)
Agent-Session: local job hourly-release-bac847af-5e64-4a93-b113-bf0e92dc91bd (no session URL)
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