Skip to content

Serve Radau's complex stage pair from the split W - #4333

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:radau-lhl-complex-gamma
Aug 25, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:radau-lhl-complex-gamma

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Note

Please ignore this PR until it has been reviewed by @ChrisRackauckas.

Closes the headline of #4281. Follows #4266, which was squash-merged from its reviewed tip before this commit was pushed to that branch — hence the separate PR.

What changed and why

A FIRK step forms a real stage matrix and complex-conjugate pairs from one Jacobian (279 stage-matrix updates against 3 Jacobians on the Brusselator), and previously discarded the split form, so LHLFactorization re-reduced from scratch per update — measured 5.2× slower than LU, which is why #4266 shipped an ArgumentError guard. Both stages now stay split: the real stage keeps the WOperator build_J_W made, and each complex pair becomes a WOperator whose gamma slot is complex while its Jacobian — the same object as the real stage's — stays real. Inside LinearSolve one real O(n³) reduction per stage matrix then serves every dtgamma, with only the shift going complex (ws.factors::Matrix{Float64}, ws.σ::ComplexF64 — asserted in the tests). Covers RadauIIA3 (complex-only), RadauIIA5, RadauIIA9, and AdaptiveRadau (vector of pairs).

The correctness keystone is firk_new_J! marking every stage matrix stale when it rewrites J in place; the guard and _firk_reject_reduction_reuse are removed.

Benchmark (the #4281 measurement)

RadauIIA5, 128-unknown Brusselator, tol 1e-8, single-threaded BLAS, best of 5:

LU          0.2308 s   err=5.024e-08   njacs=3  nw=279  nsolve=1668
LHL         0.0891 s   err=1.351e-07   njacs=1  nw=274  nsolve=1687   (2.6× faster)
LHL r=0     0.0754 s   err=1.351e-07                                  (3.1× faster)

against 5.2× slower before. Caveat: the LHL run took njacs=1 vs LU's 3 (different Newton histories), so the timing is not perfectly controlled; the correctness tests exercise njacs > 1 explicitly.

Failing-before / passing-after

Before this change the new tests cannot pass: RadauIIA5(linsolve = LHLFactorization()) throws ArgumentError (the #4266 guard) — the old @test_throws asserting that is flipped by this PR into trajectory tests. The staleness marking is separately shown to be load-bearing, both ways:

  • Reverting all marking: 6 failures — failed retcodes and trajectories diverging from LU, because the pair's cached reduction keeps answering for the previous Jacobian.
  • Reverting only the vector path (_mark_J_moved!(::AbstractVector) = nothing): 2 failures, exactly the AdaptiveRadau assertions.

With the change, lib/OrdinaryDiffEqBDF/test/lhl_factorization_tests.jl exit 0:

Test Summary:                            | Pass  Total   Time
W is kept split                          |    3      3   3.5s
same trajectory as an assembled W        |    6      6  18.5s
the reduction is reused across dtgamma changes |  5   5   0.0s
Radau keeps both stage matrices split    |   20     20  23.7s
Radau re-reduces when the Jacobian moves |    2      2   0.0s
unsupported combinations are rejected    |    2      2   2.7s

including RadauIIA3/5/9/AdaptiveRadau trajectory ≈ LU at rtol 1e-6 on a stiff dense problem with njacs > 1, and AdaptiveRadau structure assertions (every element of the W2 vector is a split complex-γ WOperator over the shared J).

lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl (LU/Krylov/GaussLegendre/AdaptiveRadau paths, no LHL): exit 0, no failures. Runic and typos clean.

Version

No bump: rides OrdinaryDiffEqFIRK 2.8.0, which #4266 bumped and which is not yet registered (registry has 2.7.0).

Not verified / out of scope

  • The full downgrade matrix, docs build, and downstream suites (CI).
  • Sharing literally one reduction across the real and complex LinearSolve caches — each stage matrix keeps its own, re-taken only when J moves; with ~90 shifts amortizing each, the residual saving is a small constant and needs a cross-cache interface. Stays on RadauIIA: reuse one Jacobian reduction across the real and complex stage matrices #4281.
  • GaussLegendre never took the split path and still does not.

🤖 Generated with Claude Code

https://claude.ai/code/session_014CrTAi2YLkosEXXbudXyKf

A FIRK step forms a real stage matrix and complex-conjugate pairs from one
Jacobian -- 279 stage-matrix updates against 3 Jacobians on the Brusselator --
and previously discarded the split form, so LHLFactorization re-reduced from
scratch per update and was refused outright.

Both stages now stay split. The real stage keeps the WOperator build_J_W made;
each complex pair becomes a WOperator whose gamma slot is complex while its
Jacobian, the same object as the real stage's, stays real. Inside LinearSolve
one real O(n^3) reduction per stage matrix then serves every dtgamma, with only
the shift going complex. firk_new_J! marks every stage matrix stale when it
rewrites J in place; without that the pair's cached reduction kept answering
for the previous Jacobian (6 test failures, wrong trajectories).

RadauIIA5 on the 128-unknown Brusselator at tol 1e-8, single-threaded BLAS,
best of 5:

  LU        0.2308 s   err=5.0e-08
  LHL       0.0891 s   err=1.4e-07   (2.6x)
  LHL r=0   0.0754 s   err=1.4e-07   (3.1x)

against 5.2x *slower* before, which is why the guard existed. Closes SciML#4281's
headline; the remaining refinement there -- sharing literally one reduction
across the real and complex caches instead of one per stage matrix -- saves
only reductions that already amortize over ~90 shifts each.

Co-Authored-By: Chris Rackauckas <[email protected]>
Move the Radau factorization coverage out of the BDF test group and make the BDF test dependencies self-contained.
@ChrisRackauckas

Copy link
Copy Markdown
Member

Follow-up in bb955cd:

  • Moved the Radau LHL factorization tests from the BDF Core suite into the FIRK Core suite.
  • Removed the BDF test dependency on OrdinaryDiffEqFIRK.
  • Declared the BDF test dependencies directly, including SciMLOperators compat 1.27 and the missing SparseArrays compat.

Local verification:

  • OrdinaryDiffEqFIRK GROUP=Core: passed, including 22/22 FIRK LHL factorization tests.
  • OrdinaryDiffEqBDF GROUP=Core: passed, including 16/16 BDF LHL factorization tests.
  • Full repository Runic check: all 1078 Julia files passed.
  • Typos and TOML/dependency metadata checks passed.

The BDF QA dependency-resolution blockers are fixed. That suite then reached its allocation checks locally and reported the existing 160-byte warmed FBDF and DFBDF allocations; those solver allocation checks are unrelated to this test-ownership change.

@ChrisRackauckas
ChrisRackauckas merged commit 7d24de1 into SciML:master Aug 25, 2026
132 of 143 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