Skip to content

Keep error checks on when DefaultODEAlgorithm starts a mass-matrix problem stiff - #4993

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
SebastianM-C:smc/default-alg-massmatrix-error-check
Nov 13, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
SebastianM-C:smc/default-alg-massmatrix-error-check

Conversation

@SebastianM-C

Copy link
Copy Markdown
Member

Problem

On a mass-matrix problem, DefaultODEAlgorithm can turn off the integrator's error checks for the whole solve. maxiters, dtmin, NaN dt and unstable_check then never fire:

using OrdinaryDiffEqDefault, LinearAlgebra
function f!(du, u, p, t)
    k, c = p
    du[1] = c - u[1]
    du[2] = k * (u[2]^3 + u[2] - u[1])   # stiff algebraic constraint
end
fun = ODEFunction(f!; mass_matrix = Diagonal([1.0, 0.0]))
prob = ODEProblem(fun, [1.0, 0.6823278038280184], (0.0, 10.0), [1.0e5, 2.0])
solve(prob, DefaultODEAlgorithm(); maxiters = 3).retcode                          # Success, 22 points
solve(prob, DefaultODEAlgorithm(stiffalgfirst = true); maxiters = 3).retcode      # MaxIters, 4 points
solve(prob, DefaultImplicitODEAlgorithm(); maxiters = 3).retcode                  # MaxIters, 4 points

With k = 1.0, all three return MaxIters.

Cause

In default_autoswitch:

  • A mass-matrix problem starts on stiffchoice, and the mass-matrix branch never switches it. But AS.is_stiffalg stays false.
  • is_stiff still runs every step. Once the stiff member's Jacobian norm (eigen_est = opnorm(J, Inf)) makes eigen_est * dt / STABILITY_SIZES[...] exceed the nonstiff tolerance, it reports "stiff" and sets do_error_check = (... || !bool) || is_stiffalg, which is false.
  • solve! only calls check_error! when do_error_check is set, so every check is skipped from then on.
  • stiffalgfirst = true (and therefore DefaultImplicitODEAlgorithm) is not affected, because it starts with is_stiffalg = true.

Change

Set AS.is_stiffalg whenever the first choice is the stiff branch (stiffalgfirst or a non-identity mass matrix), so a mass-matrix problem is treated exactly like stiffalgfirst = true.

  • Same solver sequence: such a problem already started on, and stayed on, the stiff algorithm.
  • What changes: the error checks stay on, and is_stiff compares against stifftol instead of nonstifftol. On the mass-matrix branch that only affects the switch counter, which this branch never acts on.
  • reinit!: it resets is_stiffalg = stiffalgfirst and current = 0, so the first choice sets the flag again.

Tests

lib/OrdinaryDiffEqDefault/test/massmatrix_error_check.jl (Core group) covers the reproducer above for k = 1 and k = 1e5:

  • maxiters is respected by DefaultODEAlgorithm() and by DefaultODEAlgorithm(stiffalgfirst = true), including after reinit!;
  • the uncapped solve still succeeds, reaches the right state, and never leaves the stiff branch.

On master the k = 1e5 testset fails 4 of its 9 checks; with this change all pass. The OrdinaryDiffEqDefault Core group passes locally (Julia 1.13).

I found no existing issue. #4878 concerns the same is_stiff function (NaN eigen_est read as stiff), but a different symptom.

🤖 Generated with Claude Code · model: claude-opus-5-5
Review: unreviewed
Independent review: codex gpt-6-astra · 0 findings

…problem stiff

`default_autoswitch` starts a mass-matrix problem on the stiff branch and
never switches it, but left `is_stiffalg = false`. The stiffness test still
runs every step, and once it reports stiffness (large Jacobian norm, as in
a stiff algebraic constraint) it sets `do_error_check = false`, because
the switcher believes it is on the nonstiff branch. `solve!` then skips
`check_error!` for those steps, so `maxiters`, `dtmin`, NaN `dt` and
`unstable_check` stop applying: `solve(prob, DefaultODEAlgorithm();
maxiters = 3)` ran to the end with `Success`.

Set `is_stiffalg` when the first choice is the stiff branch, as
`stiffalgfirst = true` already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ChrisRackauckas

Copy link
Copy Markdown
Member

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

PR: #4993

Reviewed head: 3b90ab4
Raw SHA-256: d30dec481946111945b234c012110f5c6bfd472508421a1012ad7cf6ee2b3f83
Source SHA-256: 7c064c8f79a8adf81268c19449d2b5565c6f35177cb0592f9342bea853f046e0
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1d06f-a205-7301-aea3-3af480a5586a
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes

Risk assessment

  • Risk: medium-low (ML1)
  • Verdict: MERGE
  • Reviewed head: 3b90ab4

Review report

VERDICT: MERGE
Round: 1
Head: 3b90ab4
Slot: 1
CI: CI is not green
Session: 01a1d06f-a205-7301-aea3-3af480a5586a

Risk

medium-low (ML1: restores documented failure checks on the mass-matrix branch; solver selection and tested uncapped trajectories are unchanged).

Blocking findings

None confirmed.

  • Verdict: MERGE
  • Round: 1
  • Blocking priorities: none
  • Deferred P2 issues: none supplied

Non-blocking findings

  • lib/OrdinaryDiffEqDefault/src/default_alg.jl:176 and lib/OrdinaryDiffEqDefault/test/massmatrix_error_check.jl:3: inspection confirms retrospective narration (“turned off”, “used to”), contrary to the supplied instruction to describe current behavior. Shorten these comments to the invariant: mass-matrix problems keep the stiff branch and its error checks active.

What I ran

Reviewer: codex-cli 0.164.0, model gpt-6.1-sol. All test processes finished. The original checkout is clean.

  • Inspected git diff origin/master...HEAD, surrounding switch/reset/error-check code, affected tests, and the newest commit trailers. Root AGENTS.md and CLAUDE.md are absent. git diff --check origin/master...HEAD passed.
  • Exported the requested TMPDIR; preserved JULIA_DEPOT_PATH. Tested a git archive HEAD copy in scratch/head so package operations could not edit the checkout. Julia 1.13.2; package-declared dependencies resolved into its scratch manifest, including SciMLBase 3.58.0.
  • With that copy's lib/OrdinaryDiffEqDefault as the project, ran GROUP=Core julia --project=… -e 'using Pkg; Pkg.test(; julia_args=["--threads=2", "--check-bounds=yes"], allow_reresolve=true)': exit 0, 264/264 assertions, including 18/18 new assertions (scratch/core.log).
  • Ran scratch/probes.jl base_regression with only default_autoswitch replaced in memory by its origin/master implementation: expected exit 1, 14 passed / 4 failed. At k=1e5, the capped solve returned Success and saved 22 times instead of 4; both capped reinit! assertions also failed (scratch/base_regression.log).
  • Ran scratch/probes.jl base and head in separate Julia processes using the same manifest: both exited 0; 140 baseline and 228 head assertions passed. Checked forward/backward nonlinear DAE accuracy against the analytic exponential and cubic root, algebraic residuals, seven matrix representations, both starting modes, repeated reinit!, and the 2/51/501-state Rodas5P/FBDF/KrylovFBDF branches. All 21 uncapped snapshots matched the base exactly in times, states, choices and return codes. The base bypassed custom instability and iteration checks; the head stopped correctly (scratch/{base,head}_probes.log).
  • Ran scratch/extra_gates.jl: exit 0, 2/2 assertions; actual solve! returned DtLessThanMin and DtNaN at t=0.01 (scratch/extra_gates.log).
  • Ran uv run --locked python --version: Python 3.15.0, with warning that --locked has no effect outside a project. This checkout supplies no Python project/lock; this does not verify a project Python environment.

What I did not verify

QA, GPU, supported Julia versions other than 1.13.2, downstream/full-monorepo suites, or CI. No checked-in Julia manifest pins dependencies. The baseline comparison isolates the changed method rather than running a separate full master checkout. Initial scratch probes rejected obsolete verbosity syntax and an inconsistent floating-point initial condition; both setup errors were corrected before the passing runs. No PR body, discussion, author risk rating or earlier review was read.

AUTHOR_GRADE: {"task":"bugfix","score":4,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The new regression fails four assertions with the base method and passes on the head. Core and targeted numerical/error-gate probes pass; 21 uncapped trajectories match exactly. Retrospective comments remain a minor instruction violation. The newest commit has no Agent-Harness or Agent-Model trailers."}

Head link: 3b90ab4


🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol
Conversation: local session 01a1d06f-a205-7301-aea3-3af480a5586a (no session URL)

@ChrisRackauckas
ChrisRackauckas merged commit 535e41f into SciML:master Nov 13, 2026
130 of 137 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.

2 participants