Skip to content

ExpRK: cache ishermitian (rebase of #4305, + review fixes) - #4497

Merged
ChrisRackauckas merged 7 commits into
SciML:masterfrom
ChrisRackauckas-Claude:cache-ishermitian-exprk-rebase
Sep 11, 2026
Merged

ChrisRackauckas merged 7 commits into
SciML:masterfrom
ChrisRackauckas-Claude:cache-ishermitian-exprk-rebase

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Rebase of #4305 onto current master (eed19e7a0), with the review comment on
_cached_ishermitian addressed in commits stacked on top. @KeshavVenkatesh's two commits are
cherry-picked unchanged with authorship preserved; everything after them is new. Credit for the
optimization is his — this only rebases it and answers the review.

Please ignore until reviewed by @ChrisRackauckas. Supersedes #4305.

What the review comment was about

It's not necessarily a fixed linear part in a split function, only if the operator A is constant.

Correct, and the docstring said otherwise: it justified the snapshot with "a SplitFunction's
linear part is fixed for the whole solve". A split linear part is an operator like any other,
and evaluating the split right-hand side runs update_coefficients! on it, so a non-constant
one really does change its entries mid-solve. Measured directly on a MatrixOperator carrying
an update_func, over 5 steps of ETDRK4(krylov = true):

after init:        ishermitian(A) = true   A[1,2]=10.0                A[2,1]=10.0
after 5 steps:     ishermitian(A) = false  A[1,2]=10.075000000000001  A[2,1]=10.0

That is exactly the "hermitian at t=0 because the initial point is odd, not for any t>0" case
from the earlier review comment, and isconstant(A) — already in the guard as of 594dcd19a —
is the whole thing that rules it out. The SplitFunction test only picks out which object A
is: f.f1.f, as against a Jacobian calc_J! overwrites every step. So the code was right and
its stated reason was wrong; 74e40ab5e fixes the reason and pins the behavior with a test.

Commits

2210f5345, e0e7a407e @KeshavVenkatesh's, cherry-picked unchanged
74e40ab5e correct the invariant + regression test for the mid-solve case
1ae996b96 hand the cached flag to the arnoldi! calls that were still missing it
3beea3685 Runic formatting (no behavior change)
fe3099b28 version 2.3.1 → 2.3.2
5edca8df9 explicit SciMLOperators module import, required by the QA group

1ae996b96 fixes something separate that the rebase surfaced: NorsettEulerCache destructured
the cached flag out of KsCache and then called arnoldi! without it, so ETDRK1 kept paying for
the full ishermitian scan per Krylov build — the cost this PR exists to remove — and the
binding sat unused. The two Exprb caches destructured it and hand-rolled the same keyword
tuple; theirs is always nothing (a per-step Jacobian cannot be cached), so routing them
through _arnoldi_kwargs changes no behavior, it just drops the duplicated block and the unused
binding. Drop that commit if you would rather it went separately.

Verification

All runs on Julia 1.12.4, lib/OrdinaryDiffEqExponentialRK.

Tests, final branch state:

$ GROUP=Core julia --project -e 'using Pkg; Pkg.test()'
Test Summary:                         | Pass  Broken  Total     Time
Linear-Nonlinear Krylov Methods Tests |  126       2    128  2m41.0s
Test Summary:                      | Pass  Broken  Total     Time
Linear-Nonlinear Convergence Tests |   44       2     46  5m24.7s
     Testing OrdinaryDiffEqExponentialRK tests passed

$ GROUP=QA julia --project -e 'using Pkg; Pkg.test()'
Allocation Tests |    1      17     18  5m09.5s
JET Tests        |    1              1  1m13.4s
Aqua             |   21             21  1m10.4s
     Testing OrdinaryDiffEqExponentialRK tests passed

The 2 broken in each group are pre-existing (CFNLIRK3() and friends), unchanged from master.

Both new tests discriminate. Dropping the isconstant gate — i.e. the state of the first
commit, which assumed split ⇒ fixed — fails the new mid-solve assertion, along with two of
@KeshavVenkatesh's own:

Cached ishermitian flag: Test Failed at linear_nonlinear_krylov_tests.jl:226
  Expression: (_arnoldi_kwargs(alg, A, integ, integ.cache.KsCache[4])).ishermitian === false
   Evaluated: true === false
Linear-Nonlinear Krylov Methods Tests |  123     3       2    128

Reverting only the NorsettEuler hunk of 1ae996b96 fails the new counter test — the operator
gets asked for its symmetry once per step instead of once per solve:

Cached ishermitian flag: Test Failed at linear_nonlinear_krylov_tests.jl:267
  Expression: counter.count == built
   Evaluated: 6 == 2
Linear-Nonlinear Krylov Methods Tests |  125     1       2    128

Both pass on the final state (126/128 above).

End-to-end timing, N=4096 periodic 1-D Laplacian (symmetric, sparse) as the split linear
part, dt = 1e-2 to t = 1, min of 5 runs, this branch vs master:

ETDRK4(krylov=true, m=15)        306.5 ms  vs  334.1 ms   (-8.3%)
NorsettEuler(krylov=true, m=15)   57.9 ms  vs   63.1 ms   (-8.2%)

NorsettEuler is the one 1ae996b96 unblocks; on master's code it is unchanged by #4305.

Format and spelling: runic --check and typos are both clean on the sublibrary. Runic is
clean on master for these files, so 3beea3685 only reformats lines this branch added.

Not verified

  • Downstream, GPU, and julia pre jobs — not run locally.
  • Other sublibraries and the root test suite: untouched by this branch, not run.
  • LawsonEuler still derives ishermitian per step. It goes through expv with a two-element
    KsCache built by a different alg_cache, so it is outside the shape ExpRK: cache ishermitian implementation #4305 introduced.
    expv does accept the keyword, so this is reachable, just not done here.
  • The out-of-place (ConstantCache) paths pass _arnoldi_kwargs(alg, A, integrator, nothing)
    and so derive the flag per call, as before. No cache exists to hold it on those paths.

Worth pushing back on

  • isconstant is false for anything that is not an AbstractSciMLOperator, so the cache is
    declined for linear parts that are not operators. That is deliberately conservative — a stale
    true routes arnoldi! into lanczos! and is silently wrong, a stale false only costs
    time — but it does mean the optimization is narrower than "split problems".
  • The SymmetryCounter test helper defines LinearAlgebra.ishermitian/mul! on a test-local
    matrix type to count calls. It is the only way I found to assert that the flag actually
    reaches arnoldi! rather than merely being stored in the cache.

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

https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht

KeshavVenkatesh and others added 7 commits September 11, 2026 05:07
The docstring justified the snapshot with "a SplitFunction's linear part is
fixed for the whole solve". It is not. A split linear part is an operator like
any other, and evaluating the split right-hand side runs update_coefficients!
on it, so a non-constant one really does change its entries mid-solve --
symmetric at t=0 and asymmetric afterwards. `isconstant(A)` is the whole
licence for caching; the `SplitFunction` test only picks out which object `A`
is, as against a Jacobian that `calc_J!` overwrites every step.

The guard already checked `isconstant`, so this corrects the stated reasoning
and pins the behavior it protects: after two steps of a split problem whose
operator loses symmetry, the flag reaching `arnoldi!` is `false`, not the
`true` snapshot taken at t=0.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht
…sing it

NorsettEuler destructured the cached flag out of KsCache and then called
arnoldi! without it, so ETDRK1 kept paying for a full ishermitian scan per
Krylov build -- the cost this PR exists to remove -- and the binding sat
unused. The two Exprb caches destructured it and hand-rolled the same keyword
tuple; theirs is always nothing (a per-step Jacobian cannot be cached), so
routing them through _arnoldi_kwargs changes no behavior, just drops the
duplicated block and the unused binding.

The existing loop only asserts that the flag is stored in the cache, which
cannot catch a perform_step! that receives it and ignores it. The new test
counts how often the operator is asked for its symmetry across five steps: once
while the cache is built, and never again.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht
Formatting only, no behavior change. `runic --check` is clean on master for
this sublibrary, so everything here is code this branch added.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht
SciML#4305 bumped 2.3.0 -> 2.3.1, but master has since released 2.3.1, so the
rebase left the version equal to the released one.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht
`using SciMLOperators: isconstant` alone trips ExplicitImports in the QA group
("relying on the following implicit imports: SciMLOperators"), which is why
every other dependency in this file is spelled `using Foo: Foo, bar`.

    GROUP=QA julia --project -e 'using Pkg; Pkg.test()'
    Aqua | 21 pass, 21 total   (was 20 pass, 1 error)

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_01H8v7A5YkRi8bj8eqWR3wht
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 11, 2026 10:35
@ChrisRackauckas
ChrisRackauckas merged commit bbf4e54 into SciML:master Sep 11, 2026
127 of 133 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas referenced this pull request Sep 11, 2026
- Add serial SDC solver family (OrdinaryDiffEqSDC) (#4208)
- Give each threaded complex stage its own JVP operator (#4430)
- Fix the adaptive error estimates of MRIGARKERK22a and MIS (#4232)
- Skip sparsity prep for matrix-free jac_prototype operators (#4445)
- Format differentiation tests (#4446)
- Fix SciMLBase reexport QA on Julia LTS (#4450)
- Preserve conditioning in OOP no-init solves (#4438)
- Read the test group from GROUP like the CI passes it (#4447)
- Raise root GPU test timeout (#4449)
- Fix default SDE dt vector lengths (#4454)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
- Release OrdinaryDiffEqBDF 2.4.7 (#4490)
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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