Algorithm Search⌘K

Algorithmresearch

BAOAB Langevin integrator

Also called BAOAB splitting.

Splits Langevin dynamics into kick, drift and exact Ornstein-Uhlenbeck steps in the order B A O A B, which gives very accurate configurational sampling.

Time
O(S N^2) worst
Space
O(N) extra
Where
N = the number of particles; S = the number of time steps
Properties
randomizediterativerandomizedsymmetricnot symplectic
Origin
Benedict Leimkuhler, Charles Matthews, 2013

BAOAB is an integrator for Langevin dynamics, the equations of motion with friction and random forces that sample the canonical ensemble. It splits the equations into three parts that can each be solved exactly: a kick B by the forces, a drift A of the positions, and an Ornstein-Uhlenbeck step O of the velocities, which holds the friction and the noise. It composes them in the order B A O A B, with the O step in the middle of the drift. Leimkuhler and Matthews (2013) showed that this order gives a much smaller error in averages of the positions than other orders at the same cost. On a harmonic oscillator the positions have the exact canonical law for every stable time step (a theorem).

In plain words

Langevin dynamics mixes three simple motions: atoms push each other, atoms move on, and the solvent slows them and knocks them at random. A program does the three motions one after another in small time steps, and the order matters.

BAOAB does half a push, half a move, then the slowing and knocking, then the other half of the move and the other half of the push. Doing the random part in the middle of the move turns out to make the positions of the atoms much more accurate. The speeds are less accurate in exchange, but for most questions, such as the shape of a molecule or the free energy of a state, the positions are what matter. It costs the same as other orders: one force computation per step.

The problem

The input is as for Langevin dynamics: positions xi∈Rdx_i \in \mathbb{R}^d, velocities viv_i and masses mim_i of NN particles, a force routine for fi=−∇iUf_i = -\nabla_i U, a time step hh, a number of steps SS, the target kBTk_B T, the friction γ≥0\gamma \ge 0 and a random number source. The equations are

dxi=vi dt,mi dvi=fi dt−miγvi dt+2miγkBT dWi.dx_i = v_i\, dt, \qquad m_i\, dv_i = f_i\, dt - m_i \gamma v_i\, dt + \sqrt{2 m_i \gamma k_B T}\, dW_i.

The parts are B: dv=(f/m) dtdv = (f/m)\,dt, A: dx=v dtdx = v\,dt, and O: dv=−γv dt+2γkBT/m dWdv = -\gamma v\,dt + \sqrt{2\gamma k_B T / m}\,dW. The output is the trajectory and samples of (x,v)(x, v), to be used for averages of functions of xx. The kinetic temperature uses Nf=dNN_f = dN, since the noise does not conserve momentum.

The algorithm

  1. BAOAB(x, v, m, FORCES, h, S, kT, gamma)
  2. 1f ← FORCES(x); c ← exp(-gamma h)
  3. 2for step ← 1 to S do
  4. 3v_i ← v_i + (h / 2) f_i / m_i for each particle i ▷ B
  5. 4x_i ← x_i + (h / 2) v_i for each particle i ▷ A
  6. 5v_i ← c v_i + sqrt((1 - c²) kT / m_i) R_i for each particle i ▷ O, R_i standard normal in R^d
  7. 6x_i ← x_i + (h / 2) v_i for each particle i ▷ A
  8. 7f ← FORCES(x)
  9. 8v_i ← v_i + (h / 2) f_i / m_i for each particle i ▷ B
  10. 9every k steps, record a copy of (x, v)
  11. 10return (x, v, the recorded samples)

The forces from line L7 serve the kick on line L3 of the next step, so there is one force evaluation per step. Line L5 is the exact solution of the Ornstein-Uhlenbeck part over the full time hh. With γ=0\gamma = 0, line L5 does nothing, the two drifts join, and the step is velocity Verlet. The OBABO splitting uses the same parts with the O step split in two at the ends.

Example

One step by hand. One particle on a spring with m=k=kBT=1m = k = k_B T = 1 in reduced units, x=1x = 1, v=0v = 0, h=0.1h = 0.1, γ=1\gamma = 1, so c=e−0.1=0.904837c = e^{-0.1} = 0.904837 and 1−c2=0.425757\sqrt{1 - c^2} = 0.425757. With the normal draw R=0.5R = 0.5 on line L5:

after L3 L4 L5 L6 L8
xx 1 0.9975 0.9975 1.005882 1.005882
vv −0.05-0.05 −0.05-0.05 0.167637 0.167637 0.117343

Exact positions on a harmonic oscillator. For U=12kx2U = \frac12 k x^2, ω2=k/m\omega^2 = k/m and hω<2h\omega < 2, the stationary law of BAOAB has ⟨x2⟩=kBT/k\langle x^2 \rangle = k_B T / k exactly and ⟨v2⟩=(kBT/m)(1−h2ω2/4)\langle v^2 \rangle = (k_B T/m)(1 - h^2\omega^2/4), for any γ>0\gamma > 0 (a theorem, Claim 4 of the proof). A run of 50 oscillators with m=k=kBT=γ=1m = k = k_B T = \gamma = 1, 4000 steps from rest, a sample every 5 steps and the first 200 steps dropped (seed 1) gives:

hh measured ⟨x2⟩\langle x^2 \rangle exact measured ⟨v2⟩\langle v^2 \rangle exact OBABO exact ⟨x2⟩\langle x^2 \rangle
0.5 0.9916 1 0.9335 0.9375 1.0667
1 0.9918 1 0.7510 0.75 1.3333
1.5 1.0039 1 0.4366 0.4375 2.2857

OBABO has the opposite behavior: exact velocities and wrong positions.

A quartic well. For U=x4/4U = x^4/4 in one dimension with kBT=1k_B T = 1, the canonical value is ⟨x2⟩=2Γ(3/4)/Γ(1/4)=0.67598\langle x^2 \rangle = 2\Gamma(3/4)/\Gamma(1/4) = 0.67598. 50 particles with m=γ=1m = \gamma = 1, 8000 steps from rest, a sample every 5 steps and the first 500 steps dropped, averaged over seeds 1 to 5, with the standard error over the seeds:

hh BAOAB ⟨x2⟩\langle x^2 \rangle OBABO ⟨x2⟩\langle x^2 \rangle
0.1 0.6745±0.00080.6745 \pm 0.0008 0.6759±0.00160.6759 \pm 0.0016
0.2 0.6744±0.00080.6744 \pm 0.0008 0.6791±0.00140.6791 \pm 0.0014
0.3 0.6724±0.00050.6724 \pm 0.0005 0.6850±0.00160.6850 \pm 0.0016
0.4 0.6721±0.00100.6721 \pm 0.0010 0.6944±0.00120.6944 \pm 0.0012

These are measurements. The error of OBABO grows like h2h^2, to 0.018 at h=0.4h = 0.4. The error of BAOAB stays below 0.004 over this range. For this well, both are unstable near h=0.6h = 0.6, since the force grows like x3x^3.

Correctness

The proof in proofs/correctness.md shows:

  1. The parts are exact. Lines L3 and L8 are the flow of B, lines L4 and L6 the flow of A, and line L5 an exact draw from the flow of O.
  2. What each part keeps. O keeps the canonical density exactly. A and B keep the volume of phase space but not the density.
  3. The regrouped chain. Cut the step at line L5: the state there follows Ah/2BhAh/2OhA_{h/2} B_h A_{h/2} O_h, which is position Verlet followed by O.
  4. The harmonic oscillator. The chain has a unique stationary law, it converges to it from any start, and the positions have the exact canonical variance.
  5. Limits. With γ=0\gamma = 0 the step is velocity Verlet.

For general smooth potentials, the error of BAOAB in averages of the positions is O(h2)O(h^2), and in the limit of high friction the leading term vanishes and the error is of order h4h^4, as shown by Leimkuhler and Matthews (2013). That result is a theorem of the paper, under its assumptions; it is not proved on this page. So the method samples the canonical ensemble up to the time step error, and the error is smaller than for other splittings of the same cost.

Proof: Each BAOAB part is an exact flow, and for a harmonic force the positions have the exact canonical lawfull

We use the Langevin equations dx=v dtdx = v\,dt, m dv=f(x) dt−mγv dt+2mγkBT dWm\,dv = f(x)\,dt - m\gamma v\,dt + \sqrt{2m\gamma k_B T}\,dW and the pseudocode of the page.

Claim 1 (the parts). Line L3 and line L8 are the exact flow Bh/2B_{h/2} of dv=(f/m) dtdv = (f/m)\,dt with xx fixed. Lines L4 and L6 are the exact flow Ah/2A_{h/2} of dx=v dtdx = v\,dt with vv fixed. Line L5 is an exact draw from the flow OhO_h of dv=−γv dt+2γkBT/m dWdv = -\gamma v\,dt + \sqrt{2\gamma k_B T/m}\,dW with xx fixed.

Proof. With xx fixed, ff is constant, so the kick is exact. With vv fixed, the drift is exact. The O flow over a time hh is v↦cv+(1−c2)kBT/m Rv \mapsto c v + \sqrt{(1 - c^2) k_B T/m}\,R with c=e−γhc = e^{-\gamma h} and RR standard normal (the Ornstein-Uhlenbeck solution, as on the Langevin dynamics page). Line L5 uses cc and the standard deviation computed before the loop. The force used in line L3 of a step was computed in line L7 of the step before, at the same positions, because nothing changes xx between them. □\square

Claim 2 (what each part keeps). OhO_h keeps the canonical density ρ∝e−β(K+U)\rho \propto e^{-\beta(K + U)} exactly. AA and BB keep the volume of phase space, but not ρ\rho.

Proof. OhO_h keeps the Maxwell-Boltzmann law of vv (c2+(1−c2)=1c^2 + (1 - c^2) = 1 times kBT/mk_B T/m) and does not touch xx. AA and BB are shears, with Jacobian determinant 1. □\square

So BAOAB is not exact for a general force. The error in the configurational averages is O(h2)O(h^2) in general. Leimkuhler and Matthews (2013) show that in the limit of large friction it becomes O(h4)O(h^4) for BAOAB; this proof does not repeat that analysis. The next claim shows the effect in a case we can solve.

Claim 3 (the regrouped chain). Let unu_n be the state just before line L5 of step n+1n + 1. Then un+1=N(un)u_{n+1} = N(u_n) with N=Ah/2∘Bh∘Ah/2∘OhN = A_{h/2} \circ B_h \circ A_{h/2} \circ O_h, read from right to left, and the state at the end of step n+1n + 1 is zn+1=Bh/2∘Ah/2∘Oh(un)z_{n+1} = B_{h/2} \circ A_{h/2} \circ O_h (u_n).

Proof. After line L5 of step n+1n + 1 the step applies Ah/2A_{h/2} (L6) and Bh/2B_{h/2} (L8). The next step applies Bh/2B_{h/2} (L3) and Ah/2A_{h/2} (L4) before its line L5. Two kicks at the same positions add up to BhB_h. □\square

Ah/2BhAh/2A_{h/2} B_h A_{h/2} is one step of position Verlet.

Claim 4 (the harmonic oscillator). Let U=12kx2U = \frac12 k x^2 in one dimension, ω2=k/m\omega^2 = k/m, q=h2ω2/4<1q = h^2\omega^2/4 < 1 and γ>0\gamma > 0. Then the chain znz_n of states at the ends of the steps has a unique stationary law, it converges to it from any start, and the law is normal with

⟨x2⟩=kBTk,⟨v2⟩=kBTm(1−q),⟨xv⟩=0.\langle x^2 \rangle = \frac{k_B T}{k}, \qquad \langle v^2 \rangle = \frac{k_B T}{m}(1 - q), \qquad \langle x v \rangle = 0.

So the positions have the exact canonical law for every stable hh.

Proof. Scale so that m=ω=kBT=1m = \omega = k_B T = 1 (put hωh\omega for hh). Position Verlet is the linear map

x′=ax+h(1−q)v,v′=av−hx,a=1−h2/2,x' = a x + h(1 - q) v, \qquad v' = a v - h x, \qquad a = 1 - h^2/2,

with determinant 1. It keeps Q=x2/(1−q)+v2Q = x^2/(1 - q) + v^2: the cross terms are 2ahxv−2ahxv=02ahxv - 2ahxv = 0, the coefficient of x2x^2 is (a2+h2(1−q))/(1−q)=1/(1−q)(a^2 + h^2(1 - q))/(1 - q) = 1/(1 - q), and the coefficient of v2v^2 is h2(1−q)+a2=1h^2(1 - q) + a^2 = 1. So it keeps the normal law GG with density proportional to e−Q/2e^{-Q/2}: xx and vv independent, ⟨x2⟩=1−q\langle x^2 \rangle = 1 - q, ⟨v2⟩=1\langle v^2 \rangle = 1. OhO_h keeps GG, since under GG the velocity is independent of xx with variance 1. So GG is stationary for NN.

It is the only stationary law. In the norm ∥z∥2=Q(z)\|z\|^2 = Q(z), position Verlet PP is an isometry and D=diag⁡(1,c)D = \operatorname{diag}(1, c), the mean part of OhO_h, is a contraction with ∥Dz∥=∥z∥\|Dz\| = \|z\| only if v=0v = 0. If ∥PDPDz∥=∥z∥\|PDPDz\| = \|z\|, then v=0v = 0 and the velocity of PzPz is 0, which is −hx=0-hx = 0, so z=0z = 0. So ∥(PD)2∥<1\|(PD)^2\| < 1, the spectral radius of PDPD is less than 1, and unu_n converges in law to GG.

Now push GG through OhO_h (no change), then Ah/2A_{h/2} and Bh/2B_{h/2}:

x1=x+h2v,v1=v−h2x1=(1−q)v−h2x.x_1 = x + \tfrac{h}{2} v, \qquad v_1 = v - \tfrac{h}{2} x_1 = (1 - q) v - \tfrac{h}{2} x.

Then ⟨x12⟩=(1−q)+h2/4=1\langle x_1^2 \rangle = (1 - q) + h^2/4 = 1, ⟨v12⟩=(1−q)2+h24(1−q)=1−q\langle v_1^2 \rangle = (1 - q)^2 + \frac{h^2}{4}(1 - q) = 1 - q and ⟨x1v1⟩=h2(1−q)−h2(1−q)=0\langle x_1 v_1 \rangle = \frac{h}{2}(1 - q) - \frac{h}{2}(1 - q) = 0. □\square

The error is moved into the velocities, which have the variance 1−q1 - q of the right value. Velocity averages, such as the kinetic temperature, must therefore not be computed from vv at the end of a BAOAB step if the time step is large. For hω=1h\omega = 1 the velocity variance is 3/43/4 of the right value.

Claim 5 (limits). With γ=0\gamma = 0, c=1c = 1 and the noise is 0, so line L5 does nothing and the step is Bh/2AhBh/2B_{h/2} A_h B_{h/2}, velocity Verlet. □\square

Complexity

Each step does one force evaluation, dNdN normal draws and O(N)O(N) other work. With the all-pairs forces of the molecular dynamics page, SS steps take O(SN2)O(S N^2) time. The extra space is O(N)O(N) for the copies of xx and vv, plus the samples.

Properties

  • Ensemble. Canonical (NVT) for the positions, up to a small time step error, for any γ>0\gamma > 0.
  • Accurate positions, less accurate velocities. On a harmonic oscillator the position law is exact and the velocity law at the end of a step is too narrow by the factor 1−h2ω2/41 - h^2\omega^2/4.
  • Robust at high friction. As γh→∞\gamma h \to \infty the method becomes a stable and accurate integrator of Brownian dynamics, where other splittings degrade.
  • Dynamics. For small γ\gamma the motion is close to Newtonian, as for any Langevin integrator, and diffusion is slowed as γ\gamma grows.
  • Cost. The same as velocity Verlet plus dNdN normal draws.

Variants and improvements

  • Other orders. The five-letter words in A, B and O give a family of methods. ABOBA, OBABO and BAOAB are the symmetric ones studied by Leimkuhler and Matthews. OBABO, the splitting of Bussi and Parrinello, has exact velocities on the harmonic oscillator, and BAOAB has exact positions.
  • The high friction limit. For γ→∞\gamma \to \infty with the time rescaled, BAOAB becomes the update x′=x+hγmf(x)+hkBT2γm(Rn+Rn+1)x' = x + \frac{h}{\gamma m} f(x) + \sqrt{\frac{h k_B T}{2\gamma m}}(R_n + R_{n+1}), which averages two successive normal draws. It is a more accurate alternative to the Euler-Maruyama step of Brownian dynamics.
  • Constraints. With bond constraints, the A step is followed by a projection, as in RATTLE and its geodesic variants.
  • Exact sampling. A Metropolis test on top of a Langevin step removes the bias, as in the Metropolis-adjusted Langevin algorithm and generalized Hamiltonian Monte Carlo.

When to use it

Use BAOAB when the goal is configurational averages from Langevin dynamics: free energies, structures, distributions of collective variables. It allows larger time steps for the same accuracy, so it saves force evaluations. It is a good choice at high friction too. When velocity statistics or dynamical properties at large steps matter, use a different splitting or a smaller step.

Pitfalls

  • The kinetic temperature from the end-of-step velocities. At large hh it is too low, as the example shows, even though the positions are right. Do not use it to judge the thermostat. On the harmonic oscillator the velocity just before line L5 has the right variance, so it is a better choice there.
  • Unstable steps. The method needs hω<2h\omega < 2 for the fastest motion ω\omega, as velocity Verlet does. Stiff bonds limit the step.
  • The force at line L7. It serves line L3 of the next step. If something else moves the positions between steps, such as a barostat, compute the force again.
  • Comparing integrators by the temperature. Compare them by configurational averages, such as the potential energy or a radial distribution function.

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.

baoab_langevin_integrator.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/baoab-langevin-integrator/. The authors are listed in prov/V8MPCG.jsonl.
"""The BAOAB splitting for Langevin dynamics (Leimkuhler and Matthews 2013).

The Langevin equations for N particles in d dimensions are

    dx_i = v_i dt,
    m_i dv_i = f_i dt - m_i gamma v_i dt + sqrt(2 m_i gamma kT) dW_i.

The vector field is split into three parts, each solved exactly:

    B: dv = (f / m) dt                  (kick, positions fixed)
    A: dx = v dt                        (drift, velocities fixed)
    O: dv = -gamma v dt + noise         (Ornstein-Uhlenbeck, positions fixed)

One step of length h is B for h / 2, A for h / 2, O for h, A for h / 2 and
B for h / 2. The O step is v <- c v + sqrt((1 - c^2) kT / m) R with
c = exp(-gamma h) and R standard normal. The force after the second A part
is kept for the first B part of the next step, so there is one force
evaluation per step.

Cost: one force evaluation, N d normal draws and Theta(N d) extra work per
step.
"""

import math
import random
from typing import Callable

Vec = list[float]
ForceField = Callable[[list[Vec]], tuple[float, list[Vec]]]


def harmonic(k: float) -> ForceField:
    """Independent springs U = k |x_i|^2 / 2 for each particle."""
    def field(pos: list[Vec]) -> tuple[float, list[Vec]]:
        u = sum(0.5 * k * c * c for p in pos for c in p)
        return u, [[-k * c for c in p] for p in pos]
    return field


def quartic() -> ForceField:
    """Independent quartic wells U = |x_i|^4 / 4 for each particle (1D use)."""
    def field(pos: list[Vec]) -> tuple[float, list[Vec]]:
        u = sum(0.25 * c ** 4 for p in pos for c in p)
        return u, [[-c ** 3 for c in p] for p in pos]
    return field


def baoab(
    x: list[Vec], v: list[Vec], m: list[float], forces: ForceField, h: float,
    steps: int, kT: float, gamma: float, rng: random.Random, every: int = 1,
) -> tuple[list[Vec], list[Vec], list[tuple[list[Vec], list[Vec]]]]:
    """Run steps of BAOAB.

    Returns the final positions and velocities, and copies of (x, v) after
    every `every` steps. The inputs are not changed.
    """
    if h <= 0 or gamma < 0 or kT <= 0 or every < 1:
        raise ValueError("need h > 0, gamma >= 0, kT > 0 and every >= 1")
    x = [list(p) for p in x]
    v = [list(p) for p in v]
    n = len(x)
    c = math.exp(-gamma * h)
    sd = [math.sqrt((1.0 - c * c) * kT / mi) for mi in m]
    _, f = forces(x)  # @line L1
    samples = []
    for step in range(1, steps + 1):  # @line L2
        for i in range(n):
            for a in range(len(x[i])):
                v[i][a] += 0.5 * h * f[i][a] / m[i]  # @line L3
                x[i][a] += 0.5 * h * v[i][a]  # @line L4
                v[i][a] = c * v[i][a] + sd[i] * rng.gauss(0.0, 1.0)  # @line L5
                x[i][a] += 0.5 * h * v[i][a]  # @line L6
        _, f = forces(x)  # @line L7
        for i in range(n):
            for a in range(len(x[i])):
                v[i][a] += 0.5 * h * f[i][a] / m[i]  # @line L8
        if step % every == 0:  # @line L9
            samples.append(([list(p) for p in x], [list(p) for p in v]))
    return x, v, samples  # @line L10
test_baoab_langevin_integrator.py 72 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/baoab-langevin-integrator/. The authors are listed in prov/V8MPCG.jsonl.
import math
import random

import pytest

from baoab_langevin_integrator import baoab, harmonic, quartic


def stationary_covariance(h, gamma, omega2=1.0, kT=1.0):
    """Exact stationary covariance of (x, v) for one BAOAB step on U = omega2 x^2 / 2.

    Iterates S <- A S A^T + Q over the five linear parts of the step.
    """
    c = math.exp(-gamma * h)
    b = ([[1, 0], [-0.5 * h * omega2, 1]], [[0, 0], [0, 0]])
    a = ([[1, 0.5 * h], [0, 1]], [[0, 0], [0, 0]])
    o = ([[1, 0], [0, c]], [[0, 0], [0, (1 - c * c) * kT]])
    s = [[0.0, 0.0], [0.0, 0.0]]
    for _ in range(3000):
        for mat, q in (b, a, o, a, b):
            ms = [[sum(mat[i][k] * s[k][j] for k in range(2)) for j in range(2)] for i in range(2)]
            s = [[sum(ms[i][k] * mat[j][k] for k in range(2)) + q[i][j] for j in range(2)] for i in range(2)]
    return s


def moments(samples, n):
    xx = sum(p[0] ** 2 for s in samples for p in s[0]) / (len(samples) * n)
    vv = sum(p[0] ** 2 for s in samples for p in s[1]) / (len(samples) * n)
    return xx, vv


@pytest.mark.parametrize("h", [0.5, 1.0, 1.5])
def test_harmonic_positions_are_exact_for_every_stable_step(h):
    # BAOAB gives <x^2> = kT / k exactly for h omega < 2, and
    # <v^2> = (kT / m)(1 - h^2 omega^2 / 4).
    s = stationary_covariance(h, 1.0)
    assert s[0][0] == pytest.approx(1.0, abs=1e-10)
    assert s[1][1] == pytest.approx(1.0 - h * h / 4.0, abs=1e-10)
    assert s[0][1] == pytest.approx(0.0, abs=1e-10)


def test_harmonic_samples_match_the_exact_law():
    n, h = 50, 1.0
    rng = random.Random(1)
    _, _, samples = baoab([[0.0]] * n, [[0.0]] * n, [1.0] * n, harmonic(1.0), h, 1200, 1.0, 1.0, rng, every=5)
    xx, vv = moments(samples[20:], n)
    assert xx == pytest.approx(1.0, rel=0.06)
    assert vv == pytest.approx(0.75, rel=0.06)


def test_quartic_well_position_moment_is_close_to_canonical():
    # Canonical <x^2> for U = x^4 / 4 at kT = 1 is 2 Gamma(3/4) / Gamma(1/4).
    exact = 2 * math.gamma(0.75) / math.gamma(0.25)
    assert exact == pytest.approx(0.67598, abs=1e-5)
    n = 50
    rng = random.Random(1)
    _, _, samples = baoab([[0.0]] * n, [[0.0]] * n, [1.0] * n, quartic(), 0.3, 1500, 1.0, 1.0, rng, every=5)
    xx, _ = moments(samples[20:], n)
    assert xx == pytest.approx(exact, rel=0.04)


def test_zero_friction_is_velocity_verlet_and_conserves_energy():
    x, v, _ = baoab([[1.0]], [[0.0]], [1.0], harmonic(1.0), 0.05, 200, 1.0, 0.0, random.Random(0))
    assert 0.5 * v[0][0] ** 2 + 0.5 * x[0][0] ** 2 == pytest.approx(0.5, abs=1e-3)
    assert x[0][0] == pytest.approx(math.cos(10.0), abs=0.01)


def test_bad_arguments_raise():
    with pytest.raises(ValueError):
        baoab([[1.0]], [[0.0]], [1.0], harmonic(1.0), 0.0, 1, 1.0, 1.0, random.Random(0))

History

Splittings of Langevin dynamics with an exact Ornstein-Uhlenbeck part were used by Bussi and Parrinello (2007), in the order OBABO. Leimkuhler and Matthews (2013) studied the error of the invariant measure for all symmetric orders of the A, B and O parts and found the order B A O A B best for configurational averages, with a fourth order error in the high friction limit. Leimkuhler, Matthews and Stoltz (2016) gave error expansions for equilibrium and nonequilibrium averages. Integrators based on BAOAB are available in several molecular dynamics codes.

References

  1. Benedict Leimkuhler and Charles Matthews, Rational construction of stochastic numerical methods for molecular sampling, Applied Mathematics Research eXpress 2013(1), 2013, 34-56, the splittings of Langevin dynamics into A, B and O parts, the error of their invariant measures, and the high friction limit of BAOAB
  2. Benedict Leimkuhler, Charles Matthews and Gabriel Stoltz, The computation of averages from equilibrium and nonequilibrium Langevin molecular dynamics, IMA Journal of Numerical Analysis 36(1), 2016, 13-79, the error expansions of averages for splitting methods of Langevin dynamics
  3. Ben Leimkuhler and Charles Matthews, Molecular Dynamics, With Deterministic and Stochastic Numerical Methods, Springer, 2015, Chapter 7, numerical methods for stochastic molecular dynamics

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example