Skip to content

Fix Float32 short-tspan oversized tstop snap (#4738) - #4754

Draft
ChrisRackauckas-Claude wants to merge 11 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4738-float32-tstop-snap
Draft

ChrisRackauckas-Claude wants to merge 11 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4738-float32-tstop-snap

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

In modify_dt_for_tstops!, an oversized 100*eps(t) snap tolerance could mark next_step_tstop when dt was still short of the remaining interval; fixed_t_for_tstop_error! then teleported t to the tstop without integrating the gap. Cap the snap tolerance by half the step, and whenever the snap flag is set take dt = distance_to_tstop exactly (skipping re-lengthening after adaptive rejections so a stiff last step cannot reject-loop).

Fixes #4738

Fail before / pass after

Issue MWE (stiff Float32 short tspan)

Master: naccept=1, u≈0.367. With fix: Success, naccept=33, u≈2.5e-7.

u' = 1 teleport window

Fixed-dt (adaptive=false) and adaptive (default) Tsit5, Float32 span 8eps with dt=6eps, and Float64 t0=1e10 span 150eps with dt=110eps:

  • Without lengthen-on-snap (adaptive branch using min(dt, distance)): ratios 0.75 / 0.733; adaptive Core testset fails (7.15e-7 ≉ 9.54e-7, 2.10e-4 ≉ 2.86e-4).
  • With fix: ratios 1.0; Core tstop snap 24/24.

Negative control: only the adaptive-branch dt = distance assignment reverted to min(original_dt, distance_to_tstop) → adaptive u'=1 testset fails as above; fixed-dt branch still lengthens so adaptive=false cases stay green.

Verification

Runic --check / typos on touched files: clean.

cd lib/OrdinaryDiffEqCore && GROUP=Core julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total   Time
tstop snap    |   24     24  20.8s
     Testing OrdinaryDiffEqCore tests passed

InterfaceI ode_tstops_tests.jl (Euler-only u'=1 cases; Tsit5 covered in Core):

Test Summary:               | Pass  Total     Time
InterfaceI ode_tstops_tests |   71     71  1m17.3s

#3441: Euler dt=0.1 on (0,1) still 11 points ending at 1.0.

Endpoint / step-count honesty:

  • Fixed-dt runs whose last step lands within the snap window of a tstop now differ at ~1e-14 relative because that sliver is integrated instead of skipped. Example Euler(); dt=0.1 on (0,10) with u'=u: master u_end=13780.612339822275 → fix 13780.612339822515.
  • LV Tsit5/Rodas5P in plain / tstops / saveat / tstops+saveat remain bit-identical to master in the printed A/B comparisons (naccept 33/57/33/57 and 54/72/54/72).

Not verified

Reviewer pushback

  • Whether reject_retry should live forever vs tightening the relative snap window further.
  • Whether adaptive u'=1 with default tolerances is enough coverage of the lengthen path under step rejection.

Risk assessment

  • Risk: medium (hot-path tstop handling for every solver)
  • Blast radius: adaptive and fixed-dt paths in modify_dt_for_tstops!
  • Evidence: MWE and u'=1 (fixed + adaptive) fail-before/pass-after; Fix spurious tiny final step for fixed-dt methods #3441 preserved; LV bit-identical; fixed-dt endpoints shift ~1e-14 as expected; Core + InterfaceI tstops green
  • Independent review: Claude Code (claude-opus-5-5[1m]) rated it medium, high confidence: correct and closes the teleport window; touches the tstop hot path for every solver and changes fixed-dt endpoints at ~1e-14 (round 2)
  • Merge: needs human review — core time-stepping change

Please ignore this draft until reviewed by @ChrisRackauckas.

🤖 Generated with Cursor Agent CLI (model: auto)
Transcript: /log.txt

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 6ccc3b5)

Addresses both blocking findings in the current independent review. Rejection statistics protect retries before the first accepted step. Retries within the snap window use a representable clock interval rounded toward the current time, avoiding both step growth and endpoint drift. Adaptive and fixed-step snapping respect dtmax, including backward integration and fixed steps requested above the bound.

Added forward/backward exponential regressions at decay factors 1.2, 1.4, and 1.6, plus accepted-step-size assertions for adaptive/fixed and forward/backward solves. No assertion was weakened or disabled.

Failing before / passing after

On the original PR source, the initial regression run used:

GROUP=Core timeout 7200 julia +1.12 --project=lib/OrdinaryDiffEqCore -e 'using Pkg; Pkg.test()'
First-step rejection near a tstop: sol.retcode == ReturnCode.Success
Evaluated: SciMLBase.ReturnCode.MaxIters == SciMLBase.ReturnCode.Success
Snapped steps respect dtmax: maximum(abs, diff(sol.t)) <= dtmax
Evaluated: 9.536743f-7 <= 7.1525574f-7
Test Summary: | Pass  Fail  Total
tstop snap    |   51    17     68

After adding backward-retry cases, the complete final test file was also run against the original source in a temporary environment developing the checkout's Core, Tsit5, and DiffEqBase packages. Exact Julia expression:

using Test; @testset "tstop snap" begin include("lib/OrdinaryDiffEqCore/test/tstop_snap_tests.jl") end
Test Summary:                       | Pass  Fail  Total
tstop snap                          |   54    26     80
  First-step rejection near a tstop |    6    18     24
  Snapped steps respect dtmax       |   24     8     32

Final full Core run, with the fix restored:

GROUP=Core timeout 7200 julia +1.12 --project=lib/OrdinaryDiffEqCore -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total   Time
tstop snap    |   80     80  17.2s
Test Summary:        | Pass  Total     Time
Enzyme Interpolation |    2      2  2m43.3s
     Testing OrdinaryDiffEqCore tests passed

Other local validation

Julia 1.12.7, four Julia threads, one OpenBLAS thread, automatic precompilation disabled, one validation command at a time.

GROUP=QA timeout 7200 julia +1.12 --project=lib/OrdinaryDiffEqCore -e 'using Pkg; Pkg.test()'
Core Infrastructure AllocCheck Tests | 1 pass / 1 total
JET Tests | 30 pass / 1 existing broken / 31 total
Aqua | 26 pass / 26 total
     Testing OrdinaryDiffEqCore tests passed
julia +1.12 --project=@runic -m Runic --inplace lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl lib/OrdinaryDiffEqCore/test/tstop_snap_tests.jl
julia +1.12 --project=@runic -m Runic --check lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl lib/OrdinaryDiffEqCore/test/tstop_snap_tests.jl

Both exited 0 with no output. typos over the generated diff and git diff --check also exited 0 with no output.

Baseline CI failures

The old Core4 assertion is inherited: latest master Core4 passes 16 assertions with two existing broken assertions using Enzyme 0.13.217. The failing PR log used 0.13.216; the existing RAT685 investigation traces its threading assertion. No OrdinaryDiffEq source workaround was added.

The Newton LineSearchException also appears in master CI. Issue 4681 already records clean-master reproduction and a bisect to 498c765ccc07522b48e6cb8df0567e734c0a46c1. The latest sublibrary workflow omits that package through path filtering, so it does not establish resolution. MTK5335 concerns causal-equation test orientation and does not apply to either failed check.

Limits and risk

Full root InterfaceI, downstream suites, DDE/SDE consumers, GPU execution, other Julia versions, benchmarks, and documentation builds were not run locally. No docstring or public API was added. The inherited high-risk assessment remains appropriate for this shared time-stepping path; independent review of this final head is pending. This fix session does not supply a counted review.

Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).

Links


🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__OrdinaryDiffEq.jl__4754 (no session URL)

ChrisRackauckas and others added 9 commits October 3, 2026 01:49
Bare 100*eps(t) can exceed a short Float32 tspan, so modify_dt_for_tstops!
was setting next_step_tstop even when the proposed dt could not reach the
tstop, then fixed_t_for_tstop_error! teleported t to tf after one accept.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Reproduce the issue SciML#4738 MWE and check Float32/Float64 tstops still land
with matching accept counts.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Keep the adaptive regression beside the fixed-dt SciML#3441 case.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
When the snap flag is set, lengthen dt to the remaining interval so
fixed_t_for_tstop_error! cannot teleport past unintegrated dynamics.
Skip re-lengthening after adaptive rejections to avoid a reject cycle.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Cover Float32 short spans (forward/backward) and Float64 large-t0 cases
where a partial step plus tstop teleport previously under-covered the span.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Exercise Euler and Tsit5 on the Float32/Float64 reach-the-tstop regressions.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Add adaptive (default) u'=1 reach tests, rename Core snap tests, keep
InterfaceI coverage on Euler only, and document reject_retry / snap-window
invariants.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Resolve runtests.jl conflict by keeping both the tstop snap regression
and master's save_discretes initialization test include.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4738-cursor/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Devin <noreply@cognition.ai>
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-4754/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 2380cb5) 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-Claude

Copy link
Copy Markdown
Member Author

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

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19834-d46e-7ec2-823b-ad3e4a632235, reviewed head 28ed66b

  • Verdict: CHANGES
  • Risk: high (H2: adaptive and fixed-step tstop selection changes default-path integration intervals and numerical results).
  • Round / slot: 1 / 1
  • Blocking priorities: P1, P2

Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Caps the tstop snap window and integrates the full snapped interval instead of advancing time over an unintegrated gap. The added tests pass on head, but initial-step rejection loops and explicit dtmax violations require changes.

Blast radius: Common tstop handling for all ODE algorithms, including Tsit5, default solvers, callbacks, and final-time integration; shared consumers include DDE and SDE integrators.

Evidence: Blind assessment sealed before author context. Head passes all 24 added Core assertions and nine added Euler assertions; independent probes reproduce initial rejection loops and dtmax violations. The identical added assertions fail on merge-base 59ba40e (23 pass, 10 fail), confirming failing-before/passing-after from my own runs. Core and InterfaceI CI pass; the two failed CI jobs have matching failures in inspected completed master runs.

Blocking findings

  1. [P1] Protect retries of the first step as well as later steps — confirmed by running; lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl:294. The condition success_iter > 0 remains false until a step succeeds, so a first-step rejection can shrink dt by less than one third and immediately have that shrink undone by snapping. With t0=1.5f0, span=8eps(t0), lambda=1.2f0/span, solve u'=-lambda*u, u(t0)=1.0f0, over (t0,t0+span) using Tsit5(); dt=6eps(t0), maxiters=30: head returns MaxIters, zero accepted steps, 30 rejected steps, and final time still t0; the analytic endpoint is approximately 0.3011942. The same stall occurs for dimensionless decay factors 1.4 and 1.6. Default PI rejection does not necessarily shrink the first step tenfold, unlike the predictive-controller special case. Track whether an actual rejection occurred independently of accepted-step count, avoid lengthening that retry, and add a regression that reaches the endpoint against the exact exponential.
  2. [P2] Preserve dtmax when lengthening a step to a stop — confirmed by running; lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl:303 and lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl:322. fix_dt_at_bounds! runs before this function, but both snap branches can increase dt beyond the bound it just enforced. For u'=1, u0=0.0f0, tspan=(1.5f0,1.5f0+8eps(1.5f0)), and Tsit5(); dt=6eps(1.5f0), dtmax=6eps(1.5f0), both adaptive and fixed-step solves take a single step of eight epsilons: 9.536743e-7 versus the requested maximum 7.1525574e-7. This is a 33% increase, rather than a rounding sliver. Require the candidate snapped interval to satisfy dtmax; otherwise integrate the bounded step and leave the stop flag unset. Add coverage of the actual integration step size for both branches.

Non-blocking findings

None.

What I ran

  • gh pr view 4754 --repo SciML/OrdinaryDiffEq.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid,files; PR is open and draft, and live head matches the target.
  • In the source checkout: git fetch origin '+refs/pull/4754/head:refs/remotes/pr/4754' master; git checkout --detach refs/remotes/pr/4754; git rev-parse HEAD origin/master; git merge-base origin/master HEAD; git diff origin/master...HEAD. The merge-base is the Base recorded above. sha256sum INITIAL.md > INITIAL.sha256 sealed the blind H2 rating before reading the PR body, issue 4738, or author commit messages.
  • gh api --paginate repos/SciML/OrdinaryDiffEq.jl/pulls/4754/commits: newest non-merge PR commit is e9e2b8a; author trailers identify Cursor Agent CLI 2026.10.01-14929f9 and auto.
  • Julia 1.13.2, aarch64, one process at a time, four Julia threads and one OpenBLAS thread. All runs use an isolated temporary directory, the assigned shared depot followed by default depots, automatic precompilation disabled, and timeout 3600. Temporary environments develop the checkout's DiffEqBase, OrdinaryDiffEqCore, OrdinaryDiffEqTsit5, and OrdinaryDiffEqLowOrderRK; SciMLBase is a direct test dependency.
  • Run 1: julia +1.13.2 --startup-file=no head_tests.jl, exit 1 before tests: temporary environment omitted direct SciMLBase dependency. Corrected that environment before the next run; this is a reviewer setup failure.
  • Run 2: julia +1.13.2 --startup-file=no --project=env head_verify.jl, exit 1: 42 passed, nine failed, zero errors. The complete added Core test file passes 24/24 and the verbatim added Euler testset passes 9/9. Analytic exponential probes at factors 1.2, 1.4, and 1.6 reproduce 30 rejected steps without progress; both dtmax assertions fail. An additional factor-2 exponential accuracy assertion also fails (0.13570139 versus 0.13533528 at rtol=0.002); no attribution or separate defect claim is made for that tolerance-sensitive result.
  • Run 3: julia +1.13.2 --startup-file=no --project=env_base base_verify.jl, exit 1: 23 passed, 10 failed, zero errors. The base is an archive of merge-base 59ba40e with the same added test files and dependency versions. Core fails 7/24 assertions and Euler fails 3/9. The issue reproducer accepts one step and returns 0.36746436; constant-derivative cases integrate only six of eight Float32 epsilons or 110 of 150 Float64 epsilons. Head passes all these assertions. Exactly three Julia processes were launched; no suite was repeated.
  • gh pr checks 4754 --repo SciML/OrdinaryDiffEq.jl; inspected gh run view 38865178756 --repo SciML/OrdinaryDiffEq.jl --log-failed and gh run view 38865179169 --repo SciML/OrdinaryDiffEq.jl --log-failed. Core CI and InterfaceI CI succeed. SciMLSensitivity Core4 fails with AssertionError: mi2 !== nothing in the threaded ensemble Enzyme rule; OrdinaryDiffEqNonlinearSolve Core fails with LineSearchException: Search direction is not a direction of descent. Step length: 0.0 in Newton Tests.
  • Compared completed master runs after gh run list --repo SciML/OrdinaryDiffEq.jl --branch master --event push --limit 5: inspected failed logs of master IntegrationTest 41319752001 and master Sublibrary CI 41318549950. They contain the exact same Core4 threaded ensemble assertion and Newton Tests line-search exception, respectively; these CI failures are not charged to this PR.

What I did not verify

No full package suite or Pkg.test was run. The complete existing InterfaceI file was not executed locally; its added Euler block was extracted verbatim and tested. The new adversarial cases were executed only on head; their behavior on base was not run. DDE/SDE consumers, GPU execution, AD, Reactant, MPI, other platforms, performance, and heavy downstream suites were not run locally. GPU and AD CI groups report success, but I did not inspect their full logs or establish that they exercise the newly introduced snap/rejection combinations. I did not determine the origin of the factor-2 probe's accuracy discrepancy.

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

Use rejection statistics to protect first-step retries. Align retries within
snap windows to a representable clock interval without lengthening them, and
keep snapped adaptive and fixed steps within dtmax. Cover forward and backward
rejections and actual accepted step sizes.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Codex <noreply@openai.com>
Agent-Harness: Codex CLI 0.164.0
Agent-Model: gpt-6.1-sol
Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4754 (no session URL)

This branch has not been deployed

No deployments
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.

Tiny Float32 tspan: adaptive Tsit5 with explicit dt returns Success with a wrong answer (one oversized step)

2 participants