Skip to content

Store the end-of-step slope at the new solution for SFSDIRK4-8, SDIRK2 and SSPSDIRK2 - #4853

Open
singhharsh1708 wants to merge 3 commits into
SciML:masterfrom
singhharsh1708:sdirk2-fsallast-time
Open

singhharsh1708 wants to merge 3 commits into
SciML:masterfrom
singhharsh1708:sdirk2-fsallast-time

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

SFSDIRK4 to SFSDIRK8 now give fourth-order dense output instead of second: the slope they stored at the end of a step was the last stage's, not f at the new solution, and that slope is what the Hermite interpolant and the next step read. SDIRK2 and SSPSDIRK2 stored f(u_{n+1}, t_n), wrong only when f depends on t, and are fixed the same way.
The five SFSDIRK tableaus in imex_tableaus.jl are not stiffly accurate but did not set explicit_fsallast, and the other two set fsallast_c = 0; both came over from the old hand-written steps.
On u' = -u^2 with dt = 1/64 the SFSDIRK dense-output order goes from 1.93 to 3.95 and the dense error drops by 974x to 2228x, for one more f call per step; on u' = 3cos(3t)u the SDIRK2 dense error drops from 1.5 times the error at the steps to equal to it.
The new test checks the stored slope after one step of all 38 methods; on master it fails for these seven.

Risk assessment

  • Risk: medium-low (ML2: non-default SDIRK methods' end-of-step slope, tested before and after).
  • Blast radius: OrdinaryDiffEqSDIRK only. SFSDIRK4 to SFSDIRK8 now set explicit_fsallast and pay one more f call per step; SDIRK2 and SSPSDIRK2 evaluate the stored slope at t + dt instead of t. The generic ESDIRK path (in place and out of place) also gains a mass-matrix condition: with a non-identity mass matrix, tableaus with explicit_fsallast other than ImplicitEuler (ImplicitMidpoint, Trapezoid, SDIRK2, SSPSDIRK2) now keep z_s/dt as the stored slope instead of f(u); the body does not describe this part. IMEX split solves and the default solver are not touched.
  • Evidence: On u' = -u^2 with dt = 1/64 the SFSDIRK dense-output order goes from 1.93 to 3.95 and the dense error drops 974x to 2228x; on u' = 3cos(3t)u the SDIRK2 dense error drops from 1.5 times the step error to equal to it. The new test checks the stored slope after one step of all 38 methods and fails on master for these seven. The red checks (SciMLSensitivity Core2 and Core4, ProbNumDiffEq, AD lts, both GPU lanes) also fail on master.

AI Disclosure: Claude assisted with this change.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 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 01a19738-d936-7bd2-b34b-c0760295140d, reviewed head 6754fcf

  • Verdict: CHANGES
  • Risk: medium (M2: the peripheral endpoint-cache fix changes existing mass-matrix interpolation results; the blind ML2 assessment did not yet account for this regression).
  • Round / slot: 2 / 1
  • Blocking priorities: 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: Corrects the endpoint slope for SFSDIRK4–8 and the endpoint evaluation time for SDIRK2 and SSPSDIRK2. The SFSDIRK change also feeds unscaled mass-matrix right-hand sides into Hermite interpolation and requires correction.

Blast radius: SDIRK2, SSPSDIRK2, and SFSDIRK4–8 endpoint caches; SFSDIRK mass-matrix dense output in both in-place and out-of-place execution. Default solver selection and shared interpolation code are unchanged.

Evidence: Blind assessment sealed before author context. Head targeted test file passes all 144 assertions (including all 41 added endpoint checks); the added regression fails on base in 10/41 cases and passes on head in 41/41 cases. The independent head probe passes 10 identity-matrix cases and fails all 10 non-unit mass-matrix cases, with dense-output order approximately 1.01 instead of 4. SDIRK Core CI passes on Julia 1 and LTS; failed CI jobs are detailed below.

Blocking findings

  1. [P2] Preserve the mass-matrix derivative convention when enabling explicit endpoint evaluation — lib/OrdinaryDiffEqSDIRK/src/imex_tableaus.jl:2312 (also the SFSDIRK5–8 constructors). Confirmed by running: for M = Diagonal([2.0]), f(u,t) = -2u, and exact solution u(t) = exp(-t), all five SFSDIRK methods in both modes have observed dense-output order about 1.0109; the equivalent identity-matrix problem has order 3.9822–3.9980. SFSDIRK4 with mass matrix has quarter-point errors 0.0036615643, 0.0018042816, and 0.00089535995 at step sizes 1/16, 1/32, and 1/64, respectively, versus 5.5951e-11 at 1/64 without the mass matrix. The new flag routes both step implementations through direct f(u,t) evaluation, whereas these implicit-first-stage methods previously stored stage increments divided by the step size. For M*u' = f, Hermite interpolation needs u', which differs from f for non-unit M; the generic Hermite formula consumes the cache without applying M inverse. Preserve the existing mass-matrix path when enabling direct endpoint evaluation, or compute the physical endpoint derivative with mass-matrix-aware handling, and add an analytic dense-output regression with non-unit mass matrix in both execution modes.

Non-blocking findings

None.

What I ran

Commands were run from the review workspace; src is the source checkout. In the Julia commands below, $REVIEW_DEPOT denotes the supplied shared depot and $PWD/tmp is the isolated temporary directory; machine-specific absolute values are omitted.

gh pr view 4853 --repo SciML/OrdinaryDiffEq.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid
git -C src fetch origin +refs/pull/4853/head:refs/remotes/pr/4853 master
git -C src checkout --detach pr/4853
git -C src rev-parse HEAD origin/master
git -C src merge-base origin/master HEAD
git -C src diff --stat origin/master...HEAD
git -C src diff origin/master...HEAD
sha256sum INITIAL.md > INITIAL.sha256
gh pr view 4853 --repo SciML/OrdinaryDiffEq.jl --json title,body,commits,statusCheckRollup
gh pr checks 4853 --repo SciML/OrdinaryDiffEq.jl
git -C src log -1 --no-merges --format='%H%n%B'
git -C src log --first-parent --no-merges -1 --format='%H%n%B'
gh run list --repo SciML/OrdinaryDiffEq.jl --branch master --event push --limit 5 --json databaseId,headSha,conclusion,name,url

Live head matched TARGET. The merge-base and live PR base were both 45ff46afe9919acf32e9af8058705073e0995503; the newer local origin/master was d03562190d2beb2c94da8d565b222263c418ce4a. No root or nested AGENTS.md/CLAUDE.md files were present in the checkout. Neither inspected newest non-merge commit body contained Agent-Harness or Agent-Model trailers.

Julia run 1 (exit 0):

JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing head_test.jl

The script activates an external env directory, calls Pkg.develop together for checkout packages DiffEqBase, OrdinaryDiffEqCore, OrdinaryDiffEqDifferentiation, OrdinaryDiffEqNonlinearSolve, and OrdinaryDiffEqSDIRK, then Pkg.instantiate(;allow_autoprecomp=false), and includes the complete changed lib/OrdinaryDiffEqSDIRK/test/tableau_consistency_tests.jl. Output: Julia 1.13.2; tableau consistency 57/57; added endpoint regression 41/41; split-versus-combined problems 46/46. Resolved external packages include SciMLBase 3.58.0, LinearSolve 5.18.3, NonlinearSolve 4.32.0, and ForwardDiff 1.4.6.

Julia run 2 (exit 1):

git -C src archive 45ff46afe9919acf32e9af8058705073e0995503 lib/DiffEqBase lib/OrdinaryDiffEqCore lib/OrdinaryDiffEqDifferentiation lib/OrdinaryDiffEqNonlinearSolve lib/OrdinaryDiffEqSDIRK | tar -x -C base-src
cp src/lib/OrdinaryDiffEqSDIRK/test/tableau_consistency_tests.jl regression_head.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env-base base_test.jl

env-base copies the resolved environment and redirects its five source paths to the archived base, keeping external dependency versions identical. The wrapper includes the unchanged head test file against those base packages. Output: tableau consistency 57/57; endpoint regression 31 passed, 10 failed, 0 errored. Failures: SDIRK2, SSPSDIRK2, SFSDIRK4–8 in place; SDIRK2, SSPSDIRK2, SFSDIRK4 out of place. For example, SDIRK2 stores [0.0004856740501955059] versus the expected [-0.0045101606717786735]. This establishes failing-before/passing-after from my own runs. include wraps the expected test failure in LoadError, which escaped the wrapper's TestSetException handler; the subsequent optional base analytic sweep and split-problem testset did not execute. No test was rerun.

Julia run 3 (exit 1; 10 passed, 10 failed, 0 errored):

JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env analytic_probe.jl

The independent probe solves u'=-u and the equivalent 2u'=-2u, starting at u(0)=1, with SFSDIRK4–8 in both modes. It compares dense output with the analytic solution exp(-t) at t=(j+0.25)*dt, for j from 0.5/dt through 1/dt-1, with dt equal to 1/16, 1/32, and 1/64. Relative and absolute solve tolerances are 1e-12. It asserts successful return codes and observed dense-output order above 3.6, a bound below the method/Hermite fourth-order rate.

All solves returned successfully. The independent reference exposes a silent dense-output accuracy loss. Output summary (orders computed from the 1/32 and 1/64 errors):

Method Mode Identity order Mass-matrix order Mass-matrix error at 1/64
SFSDIRK4 in place 3.990989 1.010885 0.0008953599478
SFSDIRK4 out of place 3.990989 1.010885 0.0008953599478
SFSDIRK5 in place 3.997982 1.010885 0.0008953599455
SFSDIRK5 out of place 3.997982 1.010885 0.0008953599455
SFSDIRK6 in place 3.990160 1.010885 0.0008953599453
SFSDIRK6 out of place 3.990159 1.010885 0.0008953599453
SFSDIRK7 in place 3.997746 1.010885 0.0008953599446
SFSDIRK7 out of place 3.997746 1.010885 0.0008953599446
SFSDIRK8 in place 3.982206 1.010885 0.000895359945
SFSDIRK8 out of place 3.982206 1.010885 0.000895359945

The base analytic sweep was not reached, so I do not claim a measured base-versus-head dense-order comparison. Attribution to this diff follows from its change from the stage-derived du/dt cache to unscaled f(u,t); the head's failure against the analytic solution is directly measured. No fourth Julia run or repeat test was performed.

CI logs were inspected with gh run view <ID> --repo SciML/OrdinaryDiffEq.jl --log-failed for PR runs 40419306167, 40419305631, 40419306022 and recent completed master runs 41249816166, 41249816054, 41249816432. The first attempt to cache a run log failed because the default cache was read-only; setting XDG_CACHE_HOME to the isolated temporary directory allowed the read-only log requests to succeed.

  • Passing SDIRK Julia 1 Core and LTS Core jobs.
  • PR CI: LTS AD fails with ReverseDiff's finished-tape error in test/AD/autodiff_events.jl:117; GPU autoswitch fails on a GPUCompiler deprecation warning. Both exact failures also appear in recent master CI.
  • PR IntegrationTest: SciMLSensitivity Core2 has three unexpected passes at its test/Core2/stiff_adjoints.jl:238 and the same finished-tape error; Core4 has Enzyme's mi2 !== nothing assertion at its test/Core4/ensembles.jl:19. These exact failures also appear in recent master IntegrationTest. ModelingToolkit InterfaceI also fails an equation-orientation equality in its lib/ModelingToolkitBase/test/components.jl:446; that failure was not found in the inspected recent master logs and its cause remains unverified.
  • PR Sublibrary CI: OrdinaryDiffEqDefault GPU fails on the same GPUCompiler warning; this also appears in recent master Sublibrary CI.

No upstream writes were performed.

What I did not verify

GPU execution, differentiation through solve, MPI, Reactant, non-diagonal/singular/time-dependent mass matrices, and full downstream suites were not run locally. The ModelingToolkit InterfaceI failure was not reproduced locally or matched to a recent master failure. The base analytic dense-output sweep and base split-problem testset were not reached after the regression failure. Full benchmark claims in the PR description were not independently reproduced.

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

@singhharsh1708

Copy link
Copy Markdown
Member Author

With a non-identity mass matrix the step now keeps z_s/dt as the end slope, so Hermite dense output gets du/dt rather than f. For M = Diagonal([2.0]), f = -2u, the observed dense-output order goes from 1.01 back to 2.01 for SFSDIRK4-8 in both modes, and identity-M runs keep order 4. The same guard also lifts SDIRK2, SSPSDIRK2 and ImplicitMidpoint under a mass matrix from about 1 to 2 (they stored f(u) on master too). ImplicitEuler still stores f(u), since its DAE error estimate reads the residual. Order 4 under a mass matrix would need a solve with M at the end point; I left that out of this PR.

@ChrisRackauckas

Copy link
Copy Markdown
Member

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

PR: #4853

Reviewed head: 2ec65e1
Raw SHA-256: 709ef98ba9522c0021fadd0eb2a84f656f378a3e631c5e77073bf3902b757290
Source SHA-256: 23ddfe603f7c760efa0cc73bc948759f37a1a7c69827fe057bded200f72e99d2
Source: operator-attested-codex-v1 (runner attested by pankgeorg)
Reviewer session: 01a22350-b279-72f0-ae80-71958710493f
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=6)

Risk assessment

  • Risk: medium-high (MH1)
  • Verdict: CHANGES
  • Reviewed head: 2ec65e1

Review report

VERDICT: CHANGES
PR: #4853
Head: 2ec65e1
Base: f6796ab
Reviewer: codex-cli 0.172.0 / gpt-6.2-sol
Session: 01a22350-b279-72f0-ae80-71958710493f

Risk

medium-high (MH1: The patch changes derivative caching on the common solve and init/step! paths for users who select the affected stiff SDIRK methods, with observable effects on dense output and get_du for mass-matrix problems, outside default solver selection and modeling compilation.)

Blocking findings

  • P1 — Dense output regresses on a working mass-matrix input. lib/OrdinaryDiffEqSDIRK/src/generic_imex_perform_step.jl:1374 and :2430, _perform_step_iip! and _perform_step_oop!. With ImplicitMidpoint, M = Diagonal([1.0]), and (u'=t,\ u(0)=0), the merge base returns the exact derivative 0.125 after a step of 0.125. Head returns the midpoint slope 0.0625. At one quarter of the step, head returns 0.0008544921875 instead of the exact 0.00048828125, which the merge base returns. Both RHS styles reproduce this, and unsplit IMEXSSP222 shows the same regression. The fallback uses the last stage's slope even when that stage is evaluated at a different time or state.

    The cache also starts with raw f after initialization and callback resets. For (2u'=2), the head's quarter-step error is 0.00439453125 at (h=1/32) and halves when (h) halves, both on the first interval and immediately after a state-changing callback. The merge base already has first-order error there, and head increases it for ImplicitMidpoint. The new decay test samples later intervals and misses both cases. For a narrow fix, retain merge-base mass-matrix behavior and ship the identity-case corrections. To retain the mass-matrix fix, I recommend using physical derivatives at both Hermite endpoints for nonsingular matrices and preserving the implicit-Euler residual used for singular DAEs. Assert exact endpoint derivatives and dense values on the ramp, plus exact linear interpolation on the initial and post-callback intervals, for both RHS styles. Probe

  • P2 — The changed CUDA path lacks execution evidence. lib/OrdinaryDiffEqSDIRK/src/generic_imex_perform_step.jl:1374, _perform_step_iip!. The CUDA suite includes SDIRK2 with a singular diagonal device mass matrix at test/gpu/dae_tests.jl:163. The recorded GPU job failed on both head and base, and the supplied metadata does not establish whether this case ran. Provide an exact-head CUDA log showing the SDIRK2 case ran and passed its GPU-versus-CPU interpolation assertions, or run GROUP=GPU julia --project=. -e 'using Pkg; Pkg.test()' on suitable hardware and capture that case's result. Head GPU job · Base GPU job

Nonblocking findings

None

What I ran

  • diff -qr before head found four changed files. git apply --check --directory=before changes.diff and the reverse check with --directory=head both passed. I found no removed, weakened, or newly skipped assertions.
  • A direct Julia import lacked OrdinaryDiffEqCore. I resolved dependencies offline in temporary projects and ran the head's tableau_consistency_tests.jl against both snapshots with Julia 1.13.4 on ARM64 using --compiled-modules=existing -O1. Head passed all 160 assertions. The merge base failed 10 endpoint checks and six convergence checks in the new block. A second head run of the first two testsets with --compile=min -O0 passed all 114 assertions. Head log · Base log
  • I ran .review/probe.jl in both projects and checked the results against the analytical solutions. Against (e^{-t}), later-interval convergence order for ImplicitMidpoint rose from 1.02 to 2.01 and for SDIRK2 from 0.99 to 1.83, in both RHS styles. The endpoint consistency test independently evaluates the prescribed RHS at the numerical endpoint. The decay test uses the exact solution. Head probe log · Base probe log
  • I parsed ci.json and traced the test entry points. The exact-head SDIRK Core job is recorded green and its test runner includes the tableau and DAE files. The green InterfaceV job covers CPU emulation via JLArray. SDIRK Core · InterfaceV

What I did not verify

  • Native CUDA execution. The ARM64 environment exposed no NVIDIA device, and the supplied CI metadata contained no case-level CUDA output.
  • The standalone dae_esdirk_test.jl run initially stopped because the scratch project lacked the test extra DifferentiationInterface. The rerun with that extra exposed had produced no test summary when I finished the review. DAE rerun log
  • Wall-clock cost of the added SFSDIRK endpoint RHS evaluation. The patch makes no performance claim.

Head link: 2ec65e1


🤖 Posted by an AI agent — harness: codex-cli 0.172.0 · model: gpt-6.2-sol
Conversation: local session 01a22350-b279-72f0-ae80-71958710493f (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.

3 participants