Skip to content

Rebuild the linear W on every gamma dt change - #4470

Closed
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:linear-w-cutoff-adaptive
Closed

singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:linear-w-cutoff-adaptive

Conversation

@singhharsh1708

Copy link
Copy Markdown
Member

new_W_dt_cutoff no longer applies to the islinearfunction path, so W = J - M/(γdt) is refactorized on every step whose γdt differs, adaptive solves included; #4401 did this for fixed steps only.

For a linear function J is constant, so a rebuild is a refactorization with no Jacobian evaluation, and keeping a stale W buys nothing while costing Newton iterations.

On the issue's 400-point heat equation with SDIRK2 at reltol 1e-8 the default cutoff took 4844 Newton iterations and 85.0 ms against 1030 and 38.2 ms with the cutoff off; at 1e-10 it is 26340 and 454.3 ms against 4680 and 173.8 ms. Dense random operators are faster too, by 23% at N=100, 11% at N=300, 5.5% at N=600 and 3.5% at N=900, and the end states agree to the last digit.

The new test in stale_w_linear_operator_tests.jl solves adaptively at cutoff 0.2 and 0 and compares the end state, nw and nnonliniter; on master those runs take 30 factorizations against 455.

Closes #4370. The carried-over η the issue also names is not what moves the answer on the adaptive path: forcing convergence with κ = 1e-4 and max_iter = 30 leaves the error at 5.9e-9 against 6.1e-9.

AI Disclosure: Claude assisted with this change.

@oscardssmith

Copy link
Copy Markdown
Member

we also likely want to do this when using an iterative linear solver since in that case we aren't saving work by reusing

@termi-official

Copy link
Copy Markdown
Contributor

since in that case we aren't saving work by reusing

I am not sure about that. Building J/W and rebuilding preconditioners is not free either.

ChrisRackauckas added a commit that referenced this pull request Sep 12, 2026
* Rebuild the linear W on every gamma dt change

* Say why the linear path ignores new_W_dt_cutoff

The comment on the `islin` branch of `do_newJW` justified taking every γdt
change with "there is nothing for `new_W_dt_cutoff` to amortize", which is
backwards: the refactorization is exactly what that cutoff amortizes. The
reason the cutoff is not worth taking here is that `defaultalg` answers
`LHLFactorization` for this split `W`, and LHL absorbs a new γdt by
re-shifting the Hessenberg form in O(n²) with the reduction untouched —
cheap precisely because `J` never moves on a linear function.

Verified at runtime that the default is LHL for this path, dense and sparse
`J` alike: `_lhl_defaultable` is true and `DefaultLinearSolver.alg` is
`LHLFactorization` for `ODEFunction(MatrixOperator(A))` at n = 800 sparse and
n = 1000 dense.

Also bumps OrdinaryDiffEqDifferentiation to 3.11.6: #4470 bumped to 3.11.5,
which master has since released.

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

---------

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

Copy link
Copy Markdown
Member Author

Merged as #4527.

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.

new_W_dt_cutoff not respected for linear problems

3 participants