Skip to content

ExpRK: cache ishermitian implementation - #4305

Closed
KeshavVenkatesh wants to merge 2 commits into
SciML:masterfrom
KeshavVenkatesh:cache-ishermitian-exprk
Closed

KeshavVenkatesh wants to merge 2 commits into
SciML:masterfrom
KeshavVenkatesh:cache-ishermitian-exprk

Conversation

@KeshavVenkatesh

@KeshavVenkatesh KeshavVenkatesh commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Checklist

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

Additional context

While reviewing the Benchmark results of Exponential Utilties came across a way to improve the performance of ETDRK methods by caching the ishermitian call results.

These are the results of the time savings with the implementation for per arnoldi call.

-- per Arnoldi build (ms, min of 100 calls) --
operator ishermitian(A) arnoldi! before arnoldi!-after saving
Brusselator N=32 (symmetric L) 0.02463 0.24900 0.22187 10.9%
upwind 1-D n=2048 (non-symmetric L) 0.00025 0.22587 0.22350 1.1%

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e653169229

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if alg.krylov
F1 = integrator.fsalfirst
Ks, phiv_cache, ws = KsCache
Ks, phiv_cache, ws, herm = KsCache

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass cached symmetry to low-order Arnoldi calls

When a mutable split ETDRK2 solve uses a symmetric sparse operator, alg_cache_expRK now computes and stores herm, but both arnoldi! calls omit ishermitian = herm; ExponentialUtilities therefore performs its default ishermitian(A) scan twice per step, defeating the advertised cache optimization. The same omission occurs in NorsettEulerCache, so these call sites should pass the shared _arnoldi_kwargs (or the keyword directly).

Useful? React with 👍 / 👎.

@ChrisRackauckas

Copy link
Copy Markdown
Member

I'm a bit scared that it's possible to have a matrix that is weird right at the start. Hermitian at t=0 because the initial point is "odd" (ball on the ground, etc.), but then not for any t>0. It would be safer to periodically re-check.

@KeshavVenkatesh

KeshavVenkatesh commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm a bit scared that it's possible to have a matrix that is weird right at the start. Hermitian at t=0 because the initial point is "odd" (ball on the ground, etc.), but then not for any t>0. It would be safer to periodically re-check.

@ChrisRackauckas :
Ontop of the current implementation, I have added a check to see if A is constant or if it can be modified mid-way through the solve. Rather than re-check periodically, I've used isconstant(A) Is there any other scenario that we should handle? Added a test case to verify this.

The issue with periodic re-check could still leave a window where we might return a stale true , which is not just a slow but a error condition.

Comment on lines +119 to +120
* `f isa SplitFunction`, so `A` is the fixed linear part rather than a Jacobian that
`calc_J!` rebuilds every step; and

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 necessarily a fixed linear part in a split function, only if the operator A is constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As you pointed out the code has the right implementation. This first section of the comment was trying to check for the same logic we have in perform_step which has A = isa(f, SplitFunction) ? f.f1.f : (calc_J!(J, integrator, cache); J).

In the subsequent step we are handling if isConstant(A).

ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
* ExpRK: cache ishermitian implementation

* Addressed feedback comments

* ExpRK: constancy, not splitting, licenses the ishermitian cache

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

* ExpRK: hand the cached flag to the arnoldi! calls that were still missing 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

* Apply Runic formatting to the ExpRK Krylov tests

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

* Bump OrdinaryDiffEqExponentialRK to 2.3.2

#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

* ExpRK: import the SciMLOperators module name explicitly

`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

---------

Co-authored-by: KeshavVenkatesh <[email protected]>
Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@ChrisRackauckas

Copy link
Copy Markdown
Member

Rebased and finished in #4497. Kept your commits for authorship.

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 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.

2 participants