Repository navigation
Add serial spectral deferred correction (SDC) solver family - #4208
Conversation
f3474d4 to
b88be30
Compare
7d9f334 to
017d6c1
Compare
|
added wpd. |
| @.. broadcast = false nls.z = zk[m] | ||
| nls.γ = QΔ[m, m] | ||
| nls.c = nodes[m] | ||
| markfirststage!(nls) |
There was a problem hiding this comment.
why is it marking it as the first stage each time?
There was a problem hiding this comment.
Each node has its own gamma = QDelta[m,m], and W reuse is keyed on isfirststage. Reusing W across sweeps within a node would be a real win, can follow up on that.
| nls.tmp = tmp | ||
| nls.z = zk[m] | ||
| nls.γ = QΔ[m, m] | ||
| nls.c = nodes[m] |
There was a problem hiding this comment.
What justifies this stage predictor?
There was a problem hiding this comment.
zk[m] is the previous sweep iterate at that node, so it is the natural initial guess; a cold start costs about one extra Newton iteration per node.
There was a problem hiding this comment.
Measured: cold start doubles the Newton iterations per solve on ROBER (5.6 vs 2.8), and VdP mu=100 takes 70 steps against 23, error 8.4e-4 against 5.6e-9.
| function _lagrange_integrals(τ::Vector{BigFloat}, uppers::Vector{BigFloat}) | ||
| M = length(τ) | ||
| V = [τ[k]^(i - 1) for k in 1:M, i in 1:M] | ||
| C = [uppers[m]^i / i for m in 1:length(uppers), i in 1:M] | ||
| return C / V |
There was a problem hiding this comment.
Using bigfloats is going to be pretty slow, does it need to be higher precision?
There was a problem hiding this comment.
Only at init, 2 to 12 ms for M = 3 to 8; the Vandermonde solve is ill-conditioned in Float64, hence BigFloat. Can memoize like RadauIIATableauCache if that matters.
| """Generate golden reference coefficients + expected SDC orders from qmat.""" | ||
| import json | ||
| import sys | ||
|
|
||
| sys.path.insert(0, "qmat") | ||
|
|
||
| import numpy as np | ||
| from qmat.qcoeff.collocation import Collocation | ||
| from qmat import genQDeltaCoeffs | ||
| from qmat.utils.sdc import getOrderSDC, errorDahlquistSDC | ||
| from qmat.utils.num import numericalOrder | ||
|
|
||
| NODE_TYPES = ["LEGENDRE", "EQUID"] | ||
| QUAD_TYPES = ["GAUSS", "RADAU-LEFT", "RADAU-RIGHT", "LOBATTO"] | ||
| SWEEPERS = ["BE", "FE", "TRAP", "LU", "PIC", "BEPAR", "MIN-SR-NS"] | ||
|
|
||
| out = {"coeffs": [], "orders": [], "measured": []} | ||
|
|
||
| for nodeType in NODE_TYPES: |
There was a problem hiding this comment.
What's this? Why not make it Julia?
There was a problem hiding this comment.
It regenerates the checked-in JSON from qmat so the coefficients are checked against something independent of this code; the tests only read the JSON.
There was a problem hiding this comment.
Porting it would check our coefficients against our own code; qmat is the independent source and the tests only read its JSON.
|
It seems correct, so I'll merge, but follow up with improvements based on the comments I gave. |
- 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) 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]>
- 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) 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]>
- 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]>
Adds
OrdinaryDiffEqSDC, a sublibrary with a serial spectral deferred correction solver. SDC sweeps the collocation problem on each step with a cheap preconditioner instead of solving it directly, so accuracy is a runtime parameter:num_nodessets the ceiling,num_sweepshow far toward it, and one method covers order 1 up to the collocation order (2MGauss,2M-1Radau,2M-2Lobatto) without new coefficients.SDC(; num_nodes = 3, node_type = SDCNodes.Legendre, quad_type = SDCQuadrature.RadauRight, num_sweeps = 3, sweeper = SDCSweeper.BE, step_update = SDCStepUpdate.Quadrature, nlsolve = NLNewton(), linsolve, autodiff, concrete_jac);SDCSweeper.LUis the preconditioner for stiff problems. Fixed step only for now, soadaptive = falseand adtare required. Not re-exported from the umbrella until the package is registered.Two design points worth a look: one
NLSolverper node, because each node has its owngamma = QDelta[m,m]anddo_newJWkeysWreuse onJ_twithout comparinggamma(thePDIRK44precedent); and coefficients depend only on the node set, so they are built once inalg_cache, nodes from Jacobi polynomial roots andQassembled at extended precision before rounding.Coefficients match qmat, the reference SDC implementation, to
atol = 1e-13across 6 node configurations times 7 sweepers, with the generator checked in attest/gen_reference.py. The convergence gate mirrors qmat'stest_timestepping.pyand 470 combinations pass, edges included (M = 4Radau-right withK = 6measures 6.79 against a ceiling of 7). 2230 assertions in total, with Aqua, JET and ExplicitImports.Benchmarks
Fixed-step work-precision on two problems, run locally on Julia 1.10.10, Apple M1,
single threaded, minimum of 3 samples per point. Reference solution from
Vern9atabstol = reltol = 1e-14; error is relative L2 at the final time. Every method runswith
adaptive = false, so this compares method quality rather than step control.The natural comparator is
RadauIIA5. SDC on Radau-Right nodes converges to exactlythat collocation solution, so it is the fixed point serial SDC iterates toward.
Work-precision diagrams. Each series is truncated where it reaches the roundoff floor,
so a line ending is the method running out of achievable accuracy, not diverging.
On Lotka-Volterra the SDC(M=5,K=9) line crosses below RadauIIA5 at the tight end. On
Van der Pol RadauIIA5 stays lowest and leftmost at every accuracy. The f-eval panels show
where the cost goes: the SDC curves sit far to the right of the RK ones at equal error.
Fastest method reaching each accuracy target:
Lotka-Volterra (non-stiff, t = 10)
At 1e-14 no non-SDC method in the set reaches the target anywhere in the dt range tested.
Van der Pol mu=10 (stiff, t = 3)
Serial SDC wins in the tight-tolerance non-stiff regime, where high order pays for the
extra implicit solves. On the stiff problem RadauIIA5 leads at every target, though the
gap narrows from 23x at 1e-6 to 3.5x at 1e-14.
That is the expected shape for vanilla serial SDC, and the cost driver shows up in the
f-eval counts: SDC does
num_nodes * num_sweepsimplicit solves per step, soSDC(M=3,K=5) spends 20412 f evals where RadauIIA5 spends 4612 for the same 2.5e-13 error
on Van der Pol. Parallel-across-the-nodes and IMEX are what buy that back, and both are
follow-up work rather than part of this PR.
Convergence orders were checked separately against
alg_order: SDC(M=2,K=2) observed3.0 and SDC(M=3,K=3) observed 4.0 on a scalar linear problem. Higher configurations
reach the roundoff floor before an order can be measured.
AI Disclosure: Claude assisted with this change.