Skip to content

Make event tests independent of @muladd fusion differences - #4594

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:test-event-muladd-robust
Sep 23, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:test-event-muladd-robust

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Fixes #4589. Test-only change.

What changed and why

@muladd lets LLVM either fuse into an FMA or not, depending on the CPU target the code was compiled for. Since #4376, a default AutoSpecialize solve with a callback can run code from the pkgimage, while a solve with a different integrator type (e.g. saveat = t), and every FullSpecialize solve, is JIT-compiled. When the pkgimage target and the JIT target fuse differently, the located event time moves by a few ULPs. The package is behaving within @muladd semantics. The tests assumed bitwise equality across different compiled methods.

  • saveat at the event time (ContinuousCallback and VectorContinuousCallback blocks): t is now found with a scalar saveat = tspan[2] solve. That solve shares its integrator type, and so its compiled code, with the saveat = t / saveat = t - eps(t) solves. All the exact assertions are kept.
  • AutoTsit5(Rosenbrock23()) vs Tsit5 with TerminateSteadyState (was sol.u == sol1.u): these are inherently different compiled methods. The test now requires the same step count and per-step rtol = 1e-5. Observed drift is up to 7e-7 relative, from rounding-level differences amplified by the step controller; the solver's reltol is 1e-3.

Verification

Reproduced on x86 (znver2) by building pkgimages with JULIA_CPU_TARGET=generic (no FMA) and running natively. Pkgimages built for haswell (which has FMA) make all variants agree, which confirms FMA fusion is the cause on x86.

Before (master, generic pkgimages), test/Integrators_I/ode_event_tests.jl. These are the same 7 assertions as in the issue:

Test Failed at .../ode_event_tests.jl:166   Evaluated: 1 == 2
Test Failed at .../ode_event_tests.jl:168   Evaluated: 0 == 2
Test Failed at .../ode_event_tests.jl:170   Evaluated: -31.320919526731657 > 0
Test Failed at .../ode_event_tests.jl:198   Evaluated: 1 == 2
Test Failed at .../ode_event_tests.jl:200   Evaluated: 0 == 2
Test Failed at .../ode_event_tests.jl:202   Evaluated: -31.32091952673139 > 0
Test Failed at .../ode_event_tests.jl:398   (sol.u == sol1.u)
Events Tests   |   50     7     57  2m27.7s

After, same setup:

Events Tests  |   58     58  2m23.8s

After, normal setup, GROUP=Integrators_I: Reinit 31/31, Events 58/58, Alg Events 177/177, Discrete Callback Dual 4/4, Callback Allocation (1 pre-existing broken), Iterator 15/15, Integrator Interface 36/36, Symbolic Interpolation 12/12, Error Check 10 + 1 pre-existing broken, Event Detection 23/23, Event Repetition 6/6.

Runic and typos are clean on the changed file.

Not verified

  • Not run on aarch64; no hardware available. The issue's Jetson values differ from the x86 no-FMA values, so the exact codegen difference there is not confirmed. The test changes remove the cross-integrator-type bitwise assumption regardless of which codegen difference caused it.
  • The last three Integrators_I testsets (Multi-VCC Mask, Step Limiter, Discontinuity Detection) were cut off by my local 1 h timeout. They do not touch the changed file.

For the reviewer

The line-398 change replaces exact equality with a tolerance. The justification is in the comment next to it and above.

🤖 Generated with Claude Code (model: claude-opus-5-5[1m])

https://claude.ai/code/session_012H1cxx1FFbAEP7nkpdapJc

The saveat-at-event tests took the event time from a `save_everystep = false`
solve and reused it as `saveat` in solves with a different integrator type. Since
SciML#4376 the former can run pkgimage code while the latter is JIT-compiled, and
`@muladd` may fuse differently in code compiled for different CPU targets, so the
located root moved by a few ULPs and the exact-equality checks failed. The event
time is now found with a scalar `saveat` solve that shares the integrator type.

The AutoTsit5-vs-Tsit5 TerminateSteadyState check compared two different compiled
algorithms bitwise; it now requires the same step count and agreement to
rtol = 1e-5 per step (observed drift up to 7e-7, solver reltol 1e-3).

Fixes SciML#4589

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_012H1cxx1FFbAEP7nkpdapJc
Claude-Session: https://claude.ai/code/session_012H1cxx1FFbAEP7nkpdapJc
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 23, 2026 07:51
@ChrisRackauckas
ChrisRackauckas merged commit 91d6176 into SciML:master Sep 23, 2026
127 of 130 checks passed
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.

AutoSpecialize callback wrapping shifts located continuous-event times

2 participants