Skip to content

Add StormerVerlet, a second-order symplectic solver - #804

Open
nstarman wants to merge 1 commit into
patrick-kidger:mainfrom
nstarman:stormer-verlet
Open

nstarman wants to merge 1 commit into
patrick-kidger:mainfrom
nstarman:stormer-verlet

Conversation

@nstarman

@nstarman nstarman commented Nov 18, 2026 •

Copy link
Copy Markdown

This adds diffrax.StormerVerlet, a second-order symplectic solver, in its velocity Verlet (kick-drift-kick leapfrog) form. It takes the same (AbstractTerm, AbstractTerm) terms and (v, w) state as SemiImplicitEuler. At the moment SemiImplicitEuler, which is first order, is diffrax's only symplectic solver. LeapfrogMidpoint is second order, but it is a multistep method for a single term and is not symplectic.

This builds on #303, which proposed a Störmer–Verlet solver in 2023 but stalled. The review there asked whether the method is just semi-implicit Euler offset by half a step, and pointed out that it evaluates a vector field twice at the same point. This version avoids that:

  • The end-of-step vector field g(t1, v1) is kept as the solver state and reused as g(t0, v0) on the next step. Each step evaluates f once and g once.
  • After a jump (made_jump), g is evaluated afresh. When made_jump is statically False, nothing extra is traced. Under vmap, the fresh evaluation runs only if some batch element jumped (eqxi.unvmap_any), the same pattern as the FSAL Runge–Kutta solvers.
  • All controls come from term.contr, so integrating backwards in time works.

This implementation comes from galax, where it has been the leapfrog integrator for orbits and stellar streams. @adrn started it there and also commented on #303. Thanks to him for getting this going, and to @packquickly for #303 and its symplectic tests.

Changes

  • diffrax/_solver/stormer_verlet.py: the solver. Dense output uses linear interpolation, as SemiImplicitEuler does.
  • Export it from diffrax, list it under "Symplectic methods" in docs/api/solvers/ode_solvers.md, and give it the same Hairer–Lubich–Wanner citation as SemiImplicitEuler.
  • test/test_integrate.py:
    • test_semi_implicit_euler becomes test_symplectic_solvers, run for both solvers.
    • test_symplectic_ode_order: measured order of convergence on a harmonic oscillator, for both solvers.
    • Stormer–Verlet against a hand-written kick-drift-kick loop with a time-dependent nonlinear force, a backwards round trip, and resuming from a saved solver_state with a changed vector field and made_jump=True.

Questions

  • Naming: I went with StormerVerlet, as in Add the Störmer-Verlet method + symplectic test changes #303 and Hairer et al. VelocityVerlet or Leapfrog would also fit, though Leapfrog is easy to confuse with LeapfrogMidpoint.
  • Dense output is linear, so between steps it is first order. A cubic Hermite interpolant from the stored vector fields would be possible as a follow-up, if that's wanted.

🤖 Generated with Claude Code

Velocity Verlet (kick-drift-kick) form. The end-of-step vector field is reused as the solver state, so each step evaluates each term once; it is recomputed after a jump.

Co-authored-by: Adrian Price-Whelan <583379+adrn@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread diffrax/_autocitation.py
@citation_rules.append
def _symplectic_solver(solver, terms=None):
if type(solver) is SemiImplicitEuler and not is_sde(terms):
if type(solver) in (SemiImplicitEuler, StormerVerlet) and not is_sde(terms):

@nstarman nstarman Nov 18, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Another potential followup is to make an AbstractSymplectic base class.

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.

1 participant