Algorithmadvanced
Reversible reference system propagator algorithm
Also called r-RESPA, multiple time step integrator.
Splits forces into fast and slow parts and integrates the fast part with smaller steps inside a symplectic Trotter splitting.
- Time
- O(n F + S + n N) worst
- Space
- O(N) extra
- Where
- F = the cost of one fast force; N = the number of coordinates; S = the cost of one slow force; n = the number of inner steps per outer step
- Model
- Real RAM
- Properties
- deterministicsymplectictime reversible
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Mark Tuckerman, Bruce J. Berne, Glenn J. Martyna, 1992
The reversible reference system propagator algorithm, r-RESPA, is a multiple time step integrator for molecular dynamics. It splits the force into a fast part, such as bond vibrations, which is cheap and changes quickly, and a slow part, such as long-range electrostatics, which is costly and changes slowly. One outer step of size gives a half kick with the slow force, then velocity Verlet steps of size with the fast force alone, then a second half kick with the slow force. The slow force is computed once per outer step instead of times. Each part is the exact flow of a Hamiltonian, so the step is symplectic, time reversible and of order 2. Its limit is resonance: when is close to half a period of a fast motion, or as Ma, Izaguirre and Skeel found, even a third of one, the slow kicks pump energy into the fast motion. The shadow Hamiltonian theory explains the good energy behaviour of a symplectic method with a step small against all time scales; RESPA uses an outer step that is not small against the fast ones, which is why the resonance is possible.
In plain words
In a molecule, some forces change very fast and some change slowly. A normal integrator must use a step small enough for the fastest force, and it pays for all forces at every small step. That is a waste, because the slow forces are often the costly ones.
RESPA gives the slow force a big step and the fast force many small steps inside it. It starts with half a push from the slow force, then lets the atoms move under the fast force alone for many small steps, then gives the second half push from the slow force. The pattern is the same backward and forward in time, which keeps the energy from drifting. The big step must not match the rhythm of the fast motion, or the pushes build it up like a swing.
The problem
There are positions and velocities with inverse masses , and the force is split as , where both parts come from potentials, and . Given an outer step and a number of inner steps, find a map that approximates the flow of with one evaluation of per step. The operator form is the Trotter splitting
where and are the kicks with each force and is the free drift.
The algorithm
RESPA-STEP(x, v, W, F_fast, F_slow, h, n)- 1
v ← v + (h/2) W F_slow(x) ▷ slow half kick - 2
for k ← 1 to n do ▷ δ = h / n - 3
v ← v + (δ/2) W F_fast(x) - 4
x ← x + δ v - 5
v ← v + (δ/2) W F_fast(x) - 6
v ← v + (h/2) W F_slow(x) ▷ slow half kick - 7
return (x, v)
The fast force at the end of one inner step is the one at the start of the next, so one call per inner step is enough. The slow force at the end of an outer step is the one at the start of the next. More levels are possible: the fast loop can itself be a RESPA step with a faster force inside.
Example
Take one particle of mass 1 with a fast spring , , so the fast period is , and a slow pendulum force . Start at , , with the energy , and run to the time 20. The largest energy error over the run:
| method | slow force calls | fast force calls | largest energy error |
|---|---|---|---|
| Verlet, | 200 | 200 | 12.72 |
| RESPA, , | 200 | 2000 | 0.293 |
| RESPA, , | 400 | 4000 | 0.0707 |
| Verlet, | 2000 | 2000 | 0.127 |
RESPA with ten inner steps cuts the error of Verlet with the large step by a factor of 43 at the same number of slow force calls. Halving the outer step divides the error by 4.1, the second order. Verlet with the small step is more accurate, but it calls the slow force ten times as often.
Resonance. Replace the slow force by with , and use inner steps. The one-step map is linear with determinant 1, so it is stable only when the absolute value of its trace is below 2. The trace from the code agrees to with the formula :
| outer step | trace |
|---|---|
| 0.1 | 1.0722 |
| 0.2 | -0.8505 |
| 0.25 | -1.6173 |
| 0.3 | -1.9842 |
| -2.00024 |
The last step is just below half the fast period, and the map is unstable there: after 3000 steps the amplitude has grown by a factor of about . The same total force with a third of that step is stable.
Correctness
The proof below shows these claims:
- The step is the composition of the slow half kick, velocity Verlet steps with the fast force, and the slow half kick, the Trotter splitting above.
- Special cases. With it is velocity Verlet with the full force. With no slow force it is Verlet steps of size .
- Symplectic. Each part is the exact flow of a Hamiltonian, and a composition of symplectic maps is symplectic.
- Time reversible. The composition is a palindrome, so reversing the velocities and taking one step returns to the start.
- Order 2, because a symmetric method has even order.
- Resonance in a linear model. With the inner loop replaced by its exact limit, the trace of the step is , and there are unstable steps just below for every . This is a theorem for the model; the limit of about a third of the fast period found by Ma, Izaguirre and Skeel (2003) for nonlinear systems is a measurement.
The tests check both special cases, reversibility to , the preserved area to , the second order of the energy error, and the resonance.
Proof: r-RESPA is a symmetric composition of exact Hamiltonian flows, so it is symplectic, reversible and of order 2, and it is unstable near half a fast periodfull
We use the line numbers of the pseudocode. The state is , is the diagonal matrix of inverse masses, and the force is with and . Define three maps for a time :
Each is the exact flow for time of a Hamiltonian: , and the kinetic energy , in the coordinates .
Claim 1 (the step). With , one call of respa_step is
Proof. Line L1 is . Each pass of the loop of line L2 applies line L3, a fast half kick at the current , line L4, a drift, and line L5, a fast half kick at the new , which is . The code computes the fast force once per pass, because the force at the end of one pass is the force at the start of the next. Line L6 is at the final .
Claim 2 (special cases). For , is the velocity Verlet step with the full force . For , is velocity Verlet steps of size with the force .
Proof. Kicks change only by an amount that depends only on , so any two kicks commute, and , the kick with the full force. For , , the velocity Verlet step. For the slow kicks are the identity.
Claim 3 (symplectic). is a symplectic map.
Proof. The exact flow of a Hamiltonian system is symplectic, and a composition of symplectic maps is symplectic.
Claim 4 (time reversal). Let . Then : from with , one step returns to .
Proof. For each of the three maps, : for a kick, flips the sign of the velocity change, and for a drift, flips the sign of the position change. is the identity, so is the same composition with each replaced by , and since the list of factors reads the same from both ends, this is the inverse of .
Claim 5 (order 2). For a fixed and smooth forces, the local error of is , so the global error over a fixed time is .
Proof. Each factor agrees with the identity plus times its vector field up to , so the composition agrees with the exact flow of up to : the method has order at least 1. A method whose map satisfies has even order (Hairer, Lubich and Wanner, the theorem on symmetric methods). The palindromic composition of Claim 4 with replaced by is the same composition with all times negated, which is , so is symmetric and its order is at least 2.
The test measures the largest energy error over for a fast spring of frequency and a slow pendulum force: it falls from 0.293 to 0.0707, a factor of 4.15, when is halved with .
Claim 6 (resonance in the linear model, a theorem). Let be one coordinate with , and with , and replace the inner loop by the exact rotation of the fast oscillator over time , which is its limit as . Then the step matrix has determinant 1 and trace
and for each there are steps just below with , where the method is unstable.
Proof. The rotation is , and the slow half kick is with . Both have determinant 1, so does. Its trace is . Put with small : , which is below when up to higher order. A real matrix with determinant 1 and has a real eigenvalue of modulus above 1, so the iterates grow exponentially.
The width of the unstable band in is about , small when the slow force is weak, but it is there for every , and the same holds near every multiple of . In the test, , and give a trace of , and 3000 steps make the amplitude grow by a factor of more than . For nonlinear systems, Ma, Izaguirre and Skeel (2003) report instabilities when is as small as a third, or possibly a fourth, of the period of the fastest motion. That bound is a measurement and an analysis of model problems, not a theorem for all force fields.
Complexity
One outer step costs fast force calls, one slow force call and for the updates, where is the number of coordinates. With Verlet at the small step , the same time costs calls of each force. RESPA saves almost a factor of when the slow force dominates the cost. Memory is , plus one stored slow force.
Properties
- Symplectic and reversible, so the energy stays in a band for steps away from resonance.
- Order two in the outer step for a fixed .
- One slow force per outer step, with the stored force reused at the start of the next step.
- Resonance limited. The outer step must stay below about a third of the shortest period of the fast motion for nonlinear systems, which caps the possible gain.
- Nested. Three or more levels of forces fit the same pattern.
Variants and improvements
- Impulse method. The same scheme is the impulse method or Verlet-I of Grubmüller, Heller, Windemuth and Schulten (1991).
- Mollified impulse. Evaluating the slow force at averaged positions softens the kicks and widens the stable range of steps.
- Isokinetic and stochastic versions. Thermostats that hold the kinetic energy of each degree of freedom, or Langevin damping on the fast modes, damp the resonance and can allow larger outer steps.
- Splitting by distance. In molecular dynamics, the slow force is often the long-range part of the electrostatics from SPME, and the fast force contains the bonds and short-range pairs.
- With constraints. The position and velocity projections of RATTLE fit after each inner drift and kick.
When to use it
Use RESPA when a costly force changes slowly and a cheap force changes fast, for example the reciprocal part of the Ewald sum against bonded and short-range forces. Keep the outer step well below half the shortest period of the fast motion, and in practice below a third of it. When the costly force is not much smoother than the cheap one, or when the bonds to hydrogen are already removed by constraints, the gain is small, and plain Verlet is simpler.
Pitfalls
- Resonance. An outer step near half a period of any fast motion, or near a multiple of it, makes the energy grow. Scan the outer step on a small test before a long run.
- A slow force that is not smooth. A sharp cutoff between the fast and slow parts puts fast changes into the slow force. Split with a smooth switching function.
- Kicks in the wrong place. The slow half kicks must come at both ends of the outer step, not one full kick at one end, or the method loses its symmetry and its second order.
- Reusing the wrong force. The slow force at the end of an outer step must be computed at the final positions of the inner loop.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/respa-multiple-time-step/. The authors are listed in prov/2SQEWG.jsonl.
"""r-RESPA: the reversible multiple time step integrator of Tuckerman, Berne and Martyna (1992).
The force is split as F = F_fast + F_slow. One outer step of size h is the
Trotter splitting
exp(h/2 L_slow) [exp(delta/2 L_fast) exp(delta L_x) exp(delta/2 L_fast)]^n exp(h/2 L_slow),
with delta = h / n: a half kick with the slow force, n velocity Verlet steps
with the fast force alone, and a second half kick with the slow force. The
slow force is computed once per outer step and the fast force n times.
Each factor is the exact flow of a Hamiltonian, so the map is symplectic, and
the splitting is symmetric, so it is time-reversible and of order 2. The
slow kicks are impulses spaced h apart. When h is near a multiple of half
the period of a fast motion the impulses resonate with it and the method is
unstable, even if each force is accurate.
Positions and velocities are flat lists of floats here; inv_mass has one
entry per coordinate.
"""
from typing import Callable
Field = Callable[[list[float]], list[float]]
def respa_step(
x: list[float], v: list[float], inv_mass: list[float], f_fast: Field, f_slow: Field, h: float, n: int,
) -> tuple[list[float], list[float]]:
"""One outer r-RESPA step of size h with n inner steps on the fast force."""
delta = h / n
fs = f_slow(x)
v = [vi + 0.5 * h * wi * fi for vi, wi, fi in zip(v, inv_mass, fs)] # @line L1
ff = f_fast(x)
for _ in range(n): # @line L2
v = [vi + 0.5 * delta * wi * fi for vi, wi, fi in zip(v, inv_mass, ff)] # @line L3
x = [xi + delta * vi for xi, vi in zip(x, v)] # @line L4
ff = f_fast(x)
v = [vi + 0.5 * delta * wi * fi for vi, wi, fi in zip(v, inv_mass, ff)] # @line L5
fs = f_slow(x)
v = [vi + 0.5 * h * wi * fi for vi, wi, fi in zip(v, inv_mass, fs)] # @line L6
return x, v # @line L7
def velocity_verlet_step(
x: list[float], v: list[float], inv_mass: list[float], force: Field, h: float,
) -> tuple[list[float], list[float]]:
"""One velocity Verlet step with the full force, the reference for n = 1."""
f = force(x)
v = [vi + 0.5 * h * wi * fi for vi, wi, fi in zip(v, inv_mass, f)]
x = [xi + h * vi for xi, vi in zip(x, v)]
f = force(x)
v = [vi + 0.5 * h * wi * fi for vi, wi, fi in zip(v, inv_mass, f)]
return x, v
test_respa_multiple_time_step.py 111 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/respa-multiple-time-step/. The authors are listed in prov/2SQEWG.jsonl.
import math
import random
from respa_multiple_time_step import respa_step, velocity_verlet_step
OMEGA = 10.0 # frequency of the fast spring
def fast(x):
return [-OMEGA * OMEGA * c for c in x]
def slow(x):
return [-math.sin(c) for c in x]
def energy(x, v):
return sum(0.5 * b * b + 0.5 * OMEGA * OMEGA * a * a + 1 - math.cos(a) for a, b in zip(x, v))
def test_one_inner_step_is_velocity_verlet() -> None:
rng = random.Random(1)
x = [rng.uniform(-1, 1) for _ in range(3)]
v = [rng.uniform(-1, 1) for _ in range(3)]
w = [1.0, 0.5, 2.0]
a, b = list(x), list(v)
for _ in range(50):
x, v = respa_step(x, v, w, fast, slow, 0.03, 1)
a, b = velocity_verlet_step(a, b, w, lambda y: [p + q for p, q in zip(fast(y), slow(y))], 0.03)
assert max(abs(p - q) for p, q in zip(x + v, a + b)) < 1e-12
def test_without_slow_force_it_is_verlet_with_the_small_step() -> None:
x, v, w = [0.4], [0.1], [1.0]
a, b = list(x), list(v)
for _ in range(20):
x, v = respa_step(x, v, w, fast, lambda y: [0.0], 0.1, 5)
for _ in range(5):
a, b = velocity_verlet_step(a, b, w, fast, 0.02)
assert abs(x[0] - a[0]) < 1e-12 and abs(v[0] - b[0]) < 1e-12
def test_reversibility() -> None:
x0, v0, w = [0.3, -0.7], [0.5, 0.2], [1.0, 1.0]
x, v = x0, v0
for _ in range(100):
x, v = respa_step(x, v, w, fast, slow, 0.1, 8)
v = [-c for c in v]
for _ in range(100):
x, v = respa_step(x, v, w, fast, slow, 0.1, 8)
assert max(abs(p - q) for p, q in zip(x, x0)) < 1e-10
assert max(abs(-p - q) for p, q in zip(v, v0)) < 1e-10
def test_map_preserves_phase_area() -> None:
def flow(x, v):
a, b = [x], [v]
for _ in range(7):
a, b = respa_step(a, b, [1.0], fast, slow, 0.1, 4)
return a[0], b[0]
e = 1e-6
dx = [(p - m) / (2 * e) for p, m in zip(flow(0.5 + e, 0.2), flow(0.5 - e, 0.2))]
dv = [(p - m) / (2 * e) for p, m in zip(flow(0.5, 0.2 + e), flow(0.5, 0.2 - e))]
assert abs(dx[0] * dv[1] - dx[1] * dv[0] - 1.0) < 1e-6
def max_energy_error(h: float, n: int, t_end: float) -> float:
x, v = [1.0], [0.0]
e0 = energy(x, v)
worst = 0.0
for _ in range(int(round(t_end / h))):
x, v = respa_step(x, v, [1.0], fast, slow, h, n)
worst = max(worst, abs(energy(x, v) - e0))
return worst
def test_energy_error_is_second_order() -> None:
e1 = max_energy_error(0.1, 10, 20.0)
e2 = max_energy_error(0.05, 10, 20.0)
assert e1 < 0.05 * energy([1.0], [0.0])
assert 3.0 < e1 / e2 < 5.0
def trace_of_linear_map(h: float, kappa: float, n: int) -> float:
def step(x, v):
a, b = respa_step([x], [v], [1.0], fast, lambda y: [-kappa * y[0]], h, n)
return a[0], b[0]
return step(1.0, 0.0)[0] + step(0.0, 1.0)[1]
def test_resonance_near_half_the_fast_period() -> None:
kappa, n = 1.0, 200
# with the inner motion integrated almost exactly, the trace is 2 cos(Omega h) - kappa h sin(Omega h) / Omega
for h in (0.1, 0.25):
exact = 2 * math.cos(OMEGA * h) - kappa * h * math.sin(OMEGA * h) / OMEGA
assert abs(trace_of_linear_map(h, kappa, n) - exact) < 1e-3
assert abs(trace_of_linear_map(h, kappa, n)) < 2.0
h_bad = (math.pi - 0.015) / OMEGA
assert abs(trace_of_linear_map(h_bad, kappa, n)) > 2.0
# the same total force with a small enough step is stable
assert abs(trace_of_linear_map(h_bad / 3, kappa, n)) < 2.0
# an unstable map makes the amplitude grow without bound
x, v = [1.0], [0.0]
for _ in range(3000):
x, v = respa_step(x, v, [1.0], fast, lambda y: [-kappa * y[0]], h_bad, 20)
assert abs(x[0]) + abs(v[0]) / OMEGA > 10.0
History
Grubmüller, Heller, Windemuth and Schulten (1991) gave the impulse form of multiple time stepping for long-range interactions. Tuckerman, Berne and Martyna (1992) derived the reversible version from a Trotter factorisation of the classical Liouville propagator. Ma, Izaguirre and Skeel (2003) analysed the instabilities and found that nonlinear resonance limits the outer step to about a third of the fastest period.
References
- Mark Tuckerman, Bruce J. Berne and Glenn J. Martyna, Reversible multiple time scale molecular dynamics, Journal of Chemical Physics 97(3), 1992, 1990-2001, the Trotter factorisation of the classical propagator into fast and slow parts
- Helmut Grubmüller, Helmut Heller, Andreas Windemuth and Klaus Schulten, Generalized Verlet algorithm for efficient molecular dynamics simulations with long-range interactions, Molecular Simulation 6(1-3), 1991, 121-142, the impulse form of the multiple time step method
- Qun Ma, Jesús A. Izaguirre and Robert D. Skeel, Verlet-I/r-RESPA/impulse is limited by nonlinear instabilities, SIAM Journal on Scientific Computing 24(6), 2003, 1951-1973, the resonance limit on the outer step
- Michael P. Allen and Dominic J. Tildesley, Computer Simulation of Liquids, second edition, Oxford University Press, 2017, Section 5.4, Non-bonded interactions and multiple timesteps
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 2SQEWG Edit this page History Report an error Markdown