Repository navigation
Conversation
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>
nstarman
commented
Nov 18, 2026
| @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): |
Author
There was a problem hiding this comment.
Another potential followup is to make an AbstractSymplectic base class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asSemiImplicitEuler. At the momentSemiImplicitEuler, which is first order, is diffrax's only symplectic solver.LeapfrogMidpointis 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:
g(t1, v1)is kept as the solver state and reused asg(t0, v0)on the next step. Each step evaluatesfonce andgonce.made_jump),gis evaluated afresh. Whenmade_jumpis staticallyFalse, nothing extra is traced. Undervmap, the fresh evaluation runs only if some batch element jumped (eqxi.unvmap_any), the same pattern as the FSAL Runge–Kutta solvers.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, asSemiImplicitEulerdoes.diffrax, list it under "Symplectic methods" indocs/api/solvers/ode_solvers.md, and give it the same Hairer–Lubich–Wanner citation asSemiImplicitEuler.test/test_integrate.py:test_semi_implicit_eulerbecomestest_symplectic_solvers, run for both solvers.test_symplectic_ode_order: measured order of convergence on a harmonic oscillator, for both solvers.solver_statewith a changed vector field andmade_jump=True.Questions
StormerVerlet, as in Add the Störmer-Verlet method + symplectic test changes #303 and Hairer et al.VelocityVerletorLeapfrogwould also fit, thoughLeapfrogis easy to confuse withLeapfrogMidpoint.🤖 Generated with Claude Code