Skip to content

Add better logging for singular cases in integration - #1379

Merged
ChrisRackauckas merged 4 commits into
SciML:masterfrom
Shreyas-Ekanathan:master
Jun 11, 2026
Merged

ChrisRackauckas merged 4 commits into
SciML:masterfrom
Shreyas-Ekanathan:master

Conversation

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Uses u and the jacobian from the integrator to give more insightful error messages on retcodes DtLessThanMin and Unstable.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

The Downstream CI failure on this PR ("Unitful interpolations" erroring and aborting the rest of the downstream suite, run 27226679941) is caused by a unit bug in the new diagnostic block:

ref = max(abs(u0[i]), one(eltype(u)))

For a Unitful state (e.g. u0 = 1.0u"g/L" in test/downstream/unitful_interpolations.jl), one(eltype(u)) is the dimensionless multiplicative identity, so max(::Quantity{Float64, 𝐌 𝐋⁻³}, ::Float64) throws:

DimensionError: 1.0 and 1.0 g L^-1 are not dimensionally compatible.
 [4] max(x::Unitful.Quantity{Float64, 𝐌 𝐋^-3, ...}, y::Float64)
 [5] check_error(integrator::OrdinaryDiffEqCore.ODEIntegrator{...})
   @ SciMLBase src/integrator_interface.jl:710

Verified locally (Julia 1.10.11, OrdinaryDiffEq v7.0.0, Unitful v1.28.0): the unitful test passes on master, fails with this branch with exactly the CI stacktrace, and passes again with the one-character-class fix:

ref = max(abs(u0[i]), oneunit(eltype(u)))

oneunit preserves the units (and is identical to one for plain floats), and the subsequent abs(u[i]) > 1.0e6 * ref comparison is then dimensionally consistent.

Two more things worth addressing while in here:

  1. This block runs on every step, not just on failure. check_error! is called once per iteration of the solve! loop (OrdinaryDiffEqCore src/solve.jl:764), and the new state/Jacobian analysis sits inside if !opts.force_dtmin && opts.adaptive before any of the abort conditions are checked. So every adaptive solve now pays findall(!isfinite, u) + a blow-up scan + (for Radau-style caches) a fresh calc_J on every accepted step. The diagnostics should be computed lazily, only inside the branches that actually return DtLessThanMin/Unstable.
  2. round(u[i], sigdigits = 4) in the message construction may also need care for exotic number types, but it's only reached when a diagnostic fires.

Comment thread src/integrator_interface.jl Outdated
Comment on lines +718 to +720
diagnostic = log_instability(integrator)
EEst = isdefined(integrator, :EEst) ?
lazy", step error estimate = $(integrator.EEst)" : ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to allocate this unless verbosity is on.

Comment thread src/integrator_interface.jl Outdated
Comment on lines 666 to 671

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a bool? @jClugstor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably left over from needing backwards compatibility before.

@jClugstor

Copy link
Copy Markdown
Member

@Shreyas-Ekanathan verbose is now always a DEVerbosity so bool comparisons won't work. What you probably want to do here is check if a specific toggle is Silent, which you can do using SciMLLogging.verbosity_to_bool(verbose.toggle) where toggle is whatever verbosity toggle you want, I think in this case dt_NaN?

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor Author

should be fixed now, lmk if there are any other changes needed!

@ChrisRackauckas
ChrisRackauckas merged commit 99cdf17 into SciML:master Jun 11, 2026
24 of 62 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request Jul 29, 2026
The extended diagnostics added in SciML#1379 only ran on the dtmin, sub-epsilon,
and unstable-check exits. A solve that dies on maxiters — the common outcome
when one equation quietly forces the step size down — reported nothing beyond
"larger maxiters is needed", so there was no information to debug from. Every
non-Success exit now runs the same diagnostic and reports the time it exited at.

Adds `log_error_estimate`, a hook for solver packages to report the adaptive
error estimate and the state components contributing most to it. The scalar
estimate says "the step was rejected"; the per-component breakdown says which
equation rejected it, which is what the user needs to look at.

The diagnostics were previously computed and then discarded when the verbosity
toggle was off. They are now gated before the work is done, which matters
because the numeric diagnostic can build a fresh Jacobian. The dt-below-epsilon
exit also gated its diagnostic on `dt_min_unstable` while emitting under
`dt_epsilon`; it now uses `dt_epsilon` for both.

Drops the `isdefined(integrator, :EEst)` interpolation from the dtmin messages.
ODEIntegrator moved `EEst` onto the controller cache, so that branch had gone
permanently dead; `log_error_estimate` reports the estimate instead.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DKB6v14nZHZPYtKiLsPLDT
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.

5 participants