Skip to content

Run exit diagnostics on every failing check_error path - #1478

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:diagnostics/check-error-all-exits
Closed

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:diagnostics/check-error-all-exits

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Motivation

From a Slack thread with @MasonProtter: a large ODE solved in a loop suddenly starts hitting maxiters. Saving every step to inspect what happened OOMs a 256GB machine, and save_everystep=false leaves almost nothing to look at:

julia> trace.this_trial[].sol.t
10-element Vector{Float64}:
   0.0
   ...
 122.40941475068085

No NaNs, no large values, no obvious culprit. The solver knew exactly which equation was forcing the step size down — it just never said so.

The extended diagnostics added in #1379 do report that kind of information, but only on the dtmin, sub-epsilon, and unstable-check exits. As @oscardssmith put it in the thread, "shreyas's pr won't help if we aren't exiting with a dt<dtmin or unstable". A maxiters exit got the generic "larger maxiters is needed" string and nothing else.

What this does

The high level, quoting the thread: "should I exit?" -> "if logging is on, diagnose more information about why I exited" -> "exit".

  • Every non-Success exit from check_error now runs the same diagnostic — MaxIters and DtNaN and ConvergenceFailure included, not just the two instability branches. The shared construction moved into SciMLBase.exit_diagnostic.
  • New SciMLBase.log_error_estimate(integrator) hook, defaulting to "". Solver packages specialize it to report the adaptive error estimate and, more usefully, the state components contributing most to it. EEst = ||atmp|| only says the step was rejected; atmp says which equation rejected it. Implemented for ODEIntegrator in Report the top error-estimate contributors on solver exit OrdinaryDiffEq.jl#4057.
  • The maxiters and dt_NaN messages now report the t (and dt) they gave up at.

Two incidental fixes in the same code:

  • The diagnostics were computed and then thrown away when the verbosity toggle was off. They are now gated before the work happens, which matters because the numeric diagnostic can build a fresh Jacobian on a large system.
  • The dt-below-epsilon branch gated its diagnostic on dt_min_unstable while emitting the message under dt_epsilon, so setting dt_epsilon alone got a message with no diagnostic. Both now use dt_epsilon.

Also drops the isdefined(integrator, :EEst) ? ... : "" interpolation from the dtmin messages. ODEIntegrator moved EEst onto the controller cache, so isdefined has been permanently false and that text never printed. log_error_estimate reports the estimate through a hook the solver actually implements.

What it looks like

With SciML/OrdinaryDiffEq.jl#4057 providing the hook, on a 10-equation system where only component 7 is stiff:

┌ Warning: Verbosity toggle: max_iters
│  Interrupted. Larger maxiters is needed. [...] Reached t=0.01712924006064487 with dt=3.5068470420252215e-5.
│
│ Error estimate diagnostics:
│ step error estimate EEst = 0.1727 (a step is accepted when EEst <= 1) after 498 accepted and 2 rejected steps
│
│ largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│   atmp[7] = -0.5463, u[7] = 8.311e-07, uprev[7] = 8.311e-07
│   atmp[1] = 2.141e-19, u[1] = 0.9983, uprev[1] = 0.9983
│   atmp[2] = 2.141e-19, u[2] = 0.9983, uprev[2] = 0.9983
└

Tests

test/check_error_diagnostics.jl drives a mock integrator through the generic check_error and asserts that all six exit branches (DtNaN, MaxIters, DtLessThanMin, sub-epsilon Unstable, unstable-check Unstable, ConvergenceFailure) emit both hooks' output, that a successful check emits nothing, and that a silent toggle skips the diagnostic entirely.

Run locally on Julia 1.11:

$ GROUP=Core julia --project -e 'using Pkg; Pkg.test()'
Test Summary:           | Pass  Total  Time
check_error diagnostics |   25     25  1.2s
[...]
     Testing SciMLBase tests passed

$ GROUP=QA julia --project -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
QA            |   35     35  1m33.6s
     Testing SciMLBase tests passed

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

Supports SciML/OrdinaryDiffEq.jl#4057 (implements log_error_estimate) and composes with SciML/OrdinaryDiffEq.jl#3731, whose log_numerical_instability now also fires on maxiters exits.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DKB6v14nZHZPYtKiLsPLDT

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
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the diagnostics/check-error-all-exits branch from 4e61978 to 96a26d5 Compare July 29, 2026 14:53
@ChrisRackauckas

Copy link
Copy Markdown
Member

Supersceded by @Shreyas-Ekanathan ?

@Shreyas-Ekanathan

Copy link
Copy Markdown
Contributor

Yeah I'll take this one and refactor as we discussed

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.

3 participants