Skip to content

Check the refined initial step against machine epsilon - #4635

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
singhharsh1708:initdt-guard-after-refinement
Sep 28, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
singhharsh1708:initdt-guard-after-refinement

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

In-place problems no longer fall back to dt = 1e-6 just because the first initial-step guess is below 10eps(T): such a guess now falls back only if the refined step is also below 10eps(T) or non-finite, so a well-scaled Float32 problem gets the step Float64 gets.
The in-place initdt compared the first guess dt₀ = (d₀/d₁)/100 against an absolute 10eps(Float32) ≈ 1.2e-6 before refining. Lorenz from #4601 has dt₀ ≈ 3.6e-7 there, so it got 1e-6 and a spurious "near machine epsilon" message. The out-of-place path never had the guard.
Float32 Lorenz now starts at 3.568e-5, the Float64 value, and Float32 u' = 1 - u from u = 0 at 1e-4 instead of 1e-6; both are tested, and so is u' = -1e16 u, which still falls back.
The same rule moves very stiff Float64 problems off the fallback: Rodas5P on u' = -k u starts at 1e-13 and 1e-14 for k = 1e13 and 1e14 (30 and 31 steps instead of 9), which is what k = 1e12 already gets on master. Fixes #4601; #3161 would replace this path with CVHin.
AI Disclosure: Claude assisted with this change.

@singhharsh1708
singhharsh1708 force-pushed the initdt-guard-after-refinement branch from bd9494c to ec7005a Compare September 26, 2026 04:33
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated review from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris. It is posted so that you can act on it. Chris or a maintainer may disagree.

Verdict: changes needed before merge (reviewed at ec7005a).

In the in-place initdt, the absolute dt₀ < 10eps(T) early return becomes a check on the refined step. That fixes the Float32 Lorenz case from #4601 (1e-6 → 3.57e-5, the Float64 value; 33 → 30 steps), and the new test fails on master and passes on the head. It also changes Float64 behaviour, which the PR description says does not happen: first guesses in roughly [2.2e-17, 2.2e-15) no longer fall back to 1e-6. On a stiff scalar decay problem (k = 1e13–1e14) Rodas5P then takes 3.3× more steps, and no test covers the fallback that remains, so this is a judgement call to settle before merge.

Risk assessment

  • Risk: medium (the code change is small, but it changes the default initial dt for every in-place ODE solve in one band of Float32 and Float64 problems)
  • Blast radius: In-place ode_determine_initdt users: all OrdinaryDiffEq solvers and DelayDiffEq. The out-of-place path is unchanged. Affected cases: Float32 problems whose first guess is below 1.19e-6, including every Float32 problem with u0 = 0 or f₀ = 0, because smalldt = 1e-6 < 10eps(Float32). Also Float64 problems whose first guess is (d₀/d₁)/100 ∈ [~10eps/100, 10eps), i.e. very stiff or badly scaled ones.
  • Evidence:
    • CI on the head vs master at the merge base 4e8d61f (push runs 36177136847/36177136855/36177137048/36177137270):
      • These checks fail on both, so they are pre-existing:
        • SciMLSensitivity.jl/Core1
        • downgrade-sublibraries / test (lib/DiffEqBase)
        • downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation)
        • sublibrary-ci lib/OrdinaryDiffEqDifferentiation Core
        • sublibrary-ci lib/GlobalDiffEq Core
        • sublibrary-ci lib/OrdinaryDiffEqNonlinearSolve Core
        • sublibrary-ci lib/OrdinaryDiffEqBDF [QA]
        • tests / GPU
      • Only on the head: sublibrary-ci / lib/DelayDiffEq [Regression] / Julia 1, where regression/waltman.jl throws "ArgumentError: matrix contains Infs or NaNs". I don't think the PR causes it:
        • The same error happened on unrelated PR runs 36081682148 and 36079846128 (branch feat/taylor-series-implicit-followup), so it is a flake.
        • Locally the whole DelayDiffEq Regression group passes on both base and head (Waltman 26/26).
        • Waltman's initial dt is 0.03733 on both, far from the band this PR touches.
      • Runic, Typos, Documentation, InterfaceI downgrade and the other downstream suites pass.
    • Local runs (Julia 1.13.0, arm64 macOS, dev envs pointing at the base worktree and at the head):
      • test/InterfaceI/ode_initdt_tests.jl with the new block added:

        • base fails ≈(dt32, dt64, rtol=1e-4): 1.0f-6 ≈ 3.5678604836301404e-5
        • head passes everything
      • Probe results:

        Case base head
        Float32 Lorenz dt0 (steps) 1.0e-6 (33) 3.56786e-5 (30)
        Float32 du = 1 - u, u0 = 0, dt0 (steps) 1.0e-6 (24) 1e-4 (22)
        Float64 du = -k*u, u0 = [1.0], Rodas5P, k = 1e13 dt0 = 1e-6, 9 accepted steps / 92 f-evals dt0 = 1e-13, 30 / 302
        same, k = 1e14 dt0 = 1e-6, 9 / 92 dt0 = 1e-14, 31 / 312
        same, k = 1e12 dt0 = 1e-12, 29 steps same
        same, k ≥ 1e15 falls back to 1e-6 falls back to 1e-6
        Near-singular 2×2 mass matrix 1e-6 1e-6
        Waltman DDE identical identical
      • The near-singular mass matrix case reaches 1e-6 without the dt_epsilon message on both base and head. So it is caught by the earlier linsolve / singular-matrix path, not by the guard this PR edits.

      • Runic --check on both changed files: clean.

  • Merge: needs changes. See findings 1–3. The code is otherwise correct. There is no internals misuse and no new dependency; the patch bump 4.18.0 → 4.18.1 is appropriate for an initdt heuristic fix.

Findings

  1. Undisclosed Float64 behaviour change. Location: lib/OrdinaryDiffEqCore/src/initdt.jl:232 together with lines 263 and 303–305.
    • The refined step is min(100dt₀, dt₁), so after this PR the fallback only fires once dt₀ is roughly 100× below 10eps(T). That is true for every T, not just Float32.
    • The description says "a first guess above 10eps(T) is handled exactly as before" and reports bit-identical results on seven Float64 problems. None of those problems has a first guess in the band that moved.
    • On stiff Float64 decay problems in that band (k = 1e13, 1e14), Rodas5P now starts at 1e-13 / 1e-14 instead of 1e-6, and takes 30–31 steps instead of 9 (3.3× the f-evals).
    • This moves the existing cliff rather than creating a new one: k = 1e12 already starts at 1e-12 on master. It may still be acceptable.
    • Fix: the author should say this in the PR, show the trade-off, and let a maintainer accept it. Alternatively, compare the refined step against a threshold that leaves the Float64 band unchanged.
  2. The remaining fallback path has no test. Location: test/InterfaceI/ode_initdt_tests.jl:155-164.
    • The test only checks that Float32 Lorenz no longer falls back.
    • Nothing checks that _fallback_if_tiny still returns smalldt when the refined step is tiny. The PR's "Andreas' near-singular mass matrix still falls back" does not exercise this guard either; the linsolve catch path handles it first.
    • Fix: add a case that reaches the guard. For example, Float64 du .= -1e16 .* u with u0 = [1.0] and Rodas5P, which should give init(...).dt == 1e-6. Also add a Float32 u0 = 0 case matching Float64, since that behaviour also changes.
  3. Comment points the wrong way. Location: lib/OrdinaryDiffEqCore/src/initdt.jl:17-18. The comment says "Andreas' example above", but that block is below (lines 129–158). Fix: "below".
  4. Minor, not blocking. In the out-of-place path _ode_initdt_oop, dt₁ = max(smalldt, dt₀/1000), while the in-place path uses max(1e-6, dt₀/1000). The paths already differed before this PR and the PR leaves that alone. Just noting that iip/oop are still not symmetric.

Push a fix and the PR is reviewed again automatically at the new head.


🤖 Posted by an AI agent — harness: Claude Code · model: claude-opus-5-5[1m] (fleet master); review by Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)

@singhharsh1708
singhharsh1708 force-pushed the initdt-guard-after-refinement branch from ec7005a to e9ce451 Compare September 28, 2026 03:35
@singhharsh1708

Copy link
Copy Markdown
Member Author

The Float64 band change is now in the description with your numbers, which I reproduced; the remaining fallback and the Float32 u0 = 0 case are tested, and the comment no longer cites the mass-matrix example.

@ChrisRackauckas
ChrisRackauckas merged commit c73aab8 into SciML:master Sep 28, 2026
256 of 264 checks passed
ChrisRackauckas referenced this pull request Sep 29, 2026
* Bump DiffEqBase to 7.21.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqBDF to 2.4.12

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSDIRK to 2.9.7

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqRosenbrock to 2.7.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqLowOrderRK to 2.2.6

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqTsit5 to 2.1.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqVerner to 2.4.2

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSymplecticRK to 2.2.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.

Float32: initdt falls back to dt=1e-6 via absolute eps guard, +27% steps on Lorenz

2 participants