Performance Benchmarking for VibeSpin

This notebook measures the runtime behaviour of four simulation models across two update schemes and five lattice sizes. The models are: Ising [1] (discrete \(\pm 1\) spins), XY [2] (continuous 2D unit vectors), Clock Continuous (\(q=6\), XY dynamics plus \(q\)-fold anisotropy), and Clock Discrete (\(q=6\), integer state indices). Each runs with both checkerboard and random-sequential Metropolis [4] updates, for eight curves in total.

Analysis costs divide into two tiers by when in a measurement run the cost is paid. Per-step observables (magnetization \(M\) and energy \(E\)) are evaluated at every MC sweep inside the measurement window, so their per-call cost multiplies with the window length. Post-hoc observables (susceptibility \(\chi = N\,\mathrm{Var}(M)/T\), specific heat \(C_v = N\,\mathrm{Var}(E)/T^2\), the spatial correlation function \(G(r)\), and the autocorrelation time \(\tau_\mathrm{int}\)) are computed once after the window closes from the stored M and E series or from a spin-field snapshot. They carry no per-step cost. Sections below treat each tier separately: the thermodynamic cost section covers per-step M and E collection; G(r) and \(\tau_\mathrm{int}\) have dedicated sections since their scaling and use differ from per-step collection.

Because Numba JIT compiles each kernel on first call, reported times are only stable after warm-up. The measure_performance helper runs three warm-up steps before starting any clock. For reproducible numbers, execute all cells once to compile, then re-run the benchmark cell.

[1]:
import os
import time

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import linregress
from tqdm.auto import tqdm

from models.clock_model import ClockSimulation, DiscreteClockSimulation
from models.ising_model import IsingSimulation
from models.xy_model import XYSimulation
from utils.exceptions import ZeroVarianceAutocorrelationError
from utils.statistics import calculate_autocorr

%matplotlib inline
plt.style.use('seaborn-v0_8-muted')
plt.rcParams['figure.dpi'] = 100

Setup

The first code cell below defines global constants: a fixed seed (SEED = 42), the number of iterations for analysis timing (ANALYSIS_ITERS = 50), and a sweep count per lattice size (N_SWEEPS_MAP). Larger lattices get fewer timed sweeps to keep total runtime under a few minutes while preserving the scaling trend across five decades of \(N\). It also sets consistent plot colours, markers, and line styles for all eight model variants.

The second code cell defines measure_performance. It accepts a live simulation instance and runs three silent warm-up steps to trigger JIT compilation for sweep, thermodynamic, and \(G(r)\) kernels before any timing begins. (Compiling the \(G(r)\) kernel at this stage means the dedicated \(G(r)\) section later gets stable timings without its own warm-up pass.) Sweep throughput is then measured over the full sweeps count. Thermodynamic collection cost is averaged over analysis_iters independent calls to _get_energy() and _get_magnetization(), which represent the per-step overhead incurred inside a measurement window.

[2]:
# --- Benchmark configuration -------------------------------------------------
SEED = 42
ANALYSIS_ITERS = 50
N_SWEEPS_MAP = {32: 200, 64: 200, 128: 200, 256: 50, 512: 50}

_model_names = [
    'Ising (Checkerboard)',
    'Ising (Random)',
    'XY (Checkerboard)',
    'XY (Random)',
    'Clock Continuous (Checkerboard)',
    'Clock Continuous (Random)',
    'Clock Discrete (Checkerboard)',
    'Clock Discrete (Random)',
]

_palette = [c['color'] for c in plt.rcParams['axes.prop_cycle']]
MODEL_COLORS = {name: _palette[i % len(_palette)] for i, name in enumerate(_model_names)}
MODEL_MARKERS = {
    'Ising (Checkerboard)': 'o',
    'Ising (Random)': 's',
    'XY (Checkerboard)': '^',
    'XY (Random)': 'D',
    'Clock Continuous (Checkerboard)': 'v',
    'Clock Continuous (Random)': 'P',
    'Clock Discrete (Checkerboard)': 'X',
    'Clock Discrete (Random)': '*',
}
MODEL_LS = {name: '-' if 'Checkerboard' in name else '--' for name in _model_names}

Throughput timing helper

The next code cell defines measure_performance, the timing helper used throughout the notebook. It warms up the JIT-compiled sweep and observable kernels before benchmarking, then reports both raw sweep throughput and the per-step cost of the thermodynamic observables that are sampled inside measurement windows.

[3]:
def measure_performance(sim, sweeps=100, analysis_iters=50):
    """Measure sweeps/sec and per-step thermodynamic collection cost.

    PER-STEP observables (timed here):
        _get_magnetization(), _get_energy()
        Called at every sweep inside a measurement window; cost multiplies
        with window length and depends on model and lattice size.

    POST-HOC observables (NOT timed here, zero per-step cost):
        susceptibility  chi = N * Var(M) / T
        specific heat   C_v = N * Var(E) / T^2
        Both are derived once from the accumulated M and E arrays after the
        window closes -- a single variance pass independent of N and model.
        G(r) and tau_int fall into the same category and have dedicated sections.
    """
    # Warm-up: triggers JIT compilation for sweep, thermo, and G(r) kernels.
    # G(r) is compiled here so the dedicated G(r) section gets stable timings later.
    for _ in range(3):
        sim.step()
        sim.get_energy()
        sim.get_magnetization()
        sim.calculate_correlation_function()

    # 1. Sweep speed (Throughput)
    start = time.perf_counter()
    for _ in range(sweeps):
        sim.step()
    sweep_duration = time.perf_counter() - start
    sps = sweeps / sweep_duration

    # 2. Per-step thermodynamic collection: M and E.
    # chi and C_v are NOT measured here -- they derive post-hoc from Var(M) and
    # Var(E) of the collected series and add no per-step cost to the run.
    start = time.perf_counter()
    for _ in range(analysis_iters):
        sim.get_energy()
        sim.get_magnetization()
    thermo_ms = (time.perf_counter() - start) / analysis_iters * 1000

    return {'sps': sps, 'thermo_ms': thermo_ms}

Throughput Benchmark

The benchmark runs all eight model variants at lattice sizes \(L \in \{32, 64, 128, 256, 512\}\). Temperatures are fixed at physically relevant points: \(T = 2.269\) for Ising (the exact 2D critical temperature is \(T_c = 2.2692\)), \(T = 0.89\) for XY (near the Berezinskii–Kosterlitz–Thouless transition at \(T_{\text{BKT}} = 0.8933\) [3]), and \(T = 0.5\) for both \(q = 6\) clock variants. For the discrete clock this lies below the lower transition \(T_1 = 0.7014\) [3], in the ordered phase, and the continuous variant with its weak sixfold anisotropy (\(A = 0.1\)) is likewise far below \(T_{\text{BKT}}\).

Results are stored in results[model_name][L] as a dict with keys sps (sweeps per second) and thermo_ms (per-step thermodynamic collection cost in milliseconds). All subsequent plots up to the \(G(r)\) section read from this structure.

Load or compute data

The benchmark results are cached at ../results/benchmarks/scaling_benchmark.npz. When the cache file is present, the next cell loads it and extracts all benchmark metrics, including the \(G(r)\) and topological timings used further below, without recomputation.

When the cache file is absent, the cell runs an inline benchmark of the four models and two update schemes at sizes 32 to 512, with 200 timed sweeps up to \(L = 128\) and 50 beyond. The stored outputs of this notebook come from that inline run on a four-core machine. It is enough to verify the analysis pipeline end to end and to give rough estimates within a few minutes, but every number is a single timing, so differences of a few percent between curves should not be over-read.

For production-quality benchmarks with longer averaging windows, run:

python scripts/benchmarks/throughput.py --sizes 32 64 128 256 512 --sweeps 500

This script populates ../results/benchmarks/scaling_benchmark.npz, and the notebook will automatically use the updated cache on subsequent runs.

[4]:
sizes = [32, 64, 128, 256, 512]
model_configs = [
    (
        'Ising (Checkerboard)',
        lambda L: IsingSimulation(size=L, temp=2.269, update='checkerboard', seed=SEED),
    ),
    ('Ising (Random)', lambda L: IsingSimulation(size=L, temp=2.269, update='random', seed=SEED)),
    (
        'XY (Checkerboard)',
        lambda L: XYSimulation(size=L, temp=0.89, update='checkerboard', seed=SEED),
    ),
    ('XY (Random)', lambda L: XYSimulation(size=L, temp=0.89, update='random', seed=SEED)),
    (
        'Clock Continuous (Checkerboard)',
        lambda L: ClockSimulation(size=L, temp=0.5, q=6, A=0.1, update='checkerboard', seed=SEED),
    ),
    (
        'Clock Continuous (Random)',
        lambda L: ClockSimulation(size=L, temp=0.5, q=6, A=0.1, update='random', seed=SEED),
    ),
    (
        'Clock Discrete (Checkerboard)',
        lambda L: DiscreteClockSimulation(size=L, temp=0.5, q=6, update='checkerboard', seed=SEED),
    ),
    (
        'Clock Discrete (Random)',
        lambda L: DiscreteClockSimulation(size=L, temp=0.5, q=6, update='random', seed=SEED),
    ),
]

_NPZ_PATH = '../results/benchmarks/scaling_benchmark.npz'
_NPZ_METRICS = ('sps', 'thermo_ms', 'corr_ms', 'vort_ms', 'vden_ms', 'heli_ms')

_cache_ok = False
if os.path.exists(_NPZ_PATH):
    _data = np.load(_NPZ_PATH, allow_pickle=True)
    _required = {'model_names', 'sizes'} | set(_NPZ_METRICS)
    if _required.issubset(set(_data.files)):
        _npz_names = [str(n) for n in _data['model_names']]
        _npz_sizes = [int(s) for s in _data['sizes']]
        results = {
            name: {
                L: {m: float(_data[m][i, j]) for m in _NPZ_METRICS}
                for j, L in enumerate(_npz_sizes)
            }
            for i, name in enumerate(_npz_names)
        }
        sizes = _npz_sizes
        _loaded_from_npz = True
        print(f'Loaded from {_NPZ_PATH}')
        print(f'  Models : {_npz_names}')
        print(f'  Sizes  : {_npz_sizes}')
        _cache_ok = True
    else:
        print(f'Cache at {_NPZ_PATH} is missing expected keys; running inline benchmark.')
if not _cache_ok:
    results = {name: {} for name, _ in model_configs}
    for L in tqdm(sizes, desc='Lattice Sizes'):
        for name, constructor in model_configs:
            sim = constructor(L)
            n_sweeps = N_SWEEPS_MAP.get(L, 200 if L <= 128 else 50)
            metrics = measure_performance(sim, sweeps=n_sweeps, analysis_iters=ANALYSIS_ITERS)
            results[name][L] = metrics
    _loaded_from_npz = False
    print('Benchmark complete. Run scripts/benchmarks/throughput.py to cache results for re-use.')
Benchmark complete. Run scripts/benchmarks/throughput.py to cache results for re-use.

Throughput: Log-Log Plot

The plot below shows sweeps per second on a log-log scale against system size \(N = L^2\). One sweep corresponds to a full lattice pass: \(N\) randomly chosen flip attempts for random-sequential updates, or two sublattice passes for checkerboard. On a log-log scale, a line with slope \(-1\) would indicate constant cost per spin (ideal \(O(N)\) scaling).

The Ising checkerboard kernel occupies the top of the chart, at 241 sweeps per second for \(L = 512\). Its spins are stored as one byte each, and every Metropolis decision uses one of two precomputed Boltzmann factors (\(e^{-4J\beta}\) and \(e^{-8J\beta}\)), with no transcendental function evaluated per site. The XY kernel draws a rotation angle per site, evaluates its cosine and sine, and computes the energy change from dot products of two-component float vectors. The continuous clock adds the anisotropy term, which costs an arctan2 and two evaluations of \(\cos(q\phi)\) per proposal, and is the slowest model at 24.5 sweeps per second. The discrete clock replaces all trigonometry with lookups in a length-\(q\) cosine table, but each proposal still performs eight table lookups with integer modulo and an exponential for uphill moves. It runs at 58.5 sweeps per second, level with XY (56.9), 2.4 times faster than the continuous clock, and about four times slower than Ising.

[5]:
plt.figure(figsize=(10, 6))
for name in results:
    L_vals = sorted(results[name].keys())
    N_vals = [L*L for L in L_vals]
    sps_vals = [results[name][L]['sps'] for L in L_vals]
    plt.loglog(
        N_vals, sps_vals,
        marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name], color=MODEL_COLORS[name],
        label=name, markersize=8,
    )

plt.title('Simulation Throughput vs System Size', fontsize=14)
plt.xlabel('Number of Sites $N = L^2$', fontsize=12)
plt.ylabel('Sweeps per Second', fontsize=12)
plt.grid(True, which="both", ls="-", alpha=0.3)
plt.legend()
plt.show()
_images/benchmarks_10_0.png

Thermodynamic Analysis Cost: Per-Step Collection

A measurement run has two distinct cost phases. During the window, _get_magnetization() and _get_energy() are called at every sweep to build the time series \(M(t)\) and \(E(t)\). This is the only thermodynamic cost paid per step, and it scales with window length: a \(W = 10{,}000\) sweep window means \(10{,}000\) calls to each. After the window closes, susceptibility and specific heat are derived from the accumulated arrays with a single variance pass:

\[\chi = \frac{N}{T}\bigl(\langle M^2 \rangle - \langle M \rangle^2\bigr), \qquad C_v = \frac{N}{T^2}\bigl(\langle E^2 \rangle - \langle E \rangle^2\bigr)\]

This post-hoc step costs a fixed amount regardless of \(N\) or model; it does not appear in the per-step timings plotted here. \(G(r)\) and \(\tau_\mathrm{int}\) are likewise post-hoc: \(G(r)\) operates on a single spin-field snapshot, and \(\tau_\mathrm{int}\) is extracted from the full \(M(t)\) series; both receive dedicated sections further below.

The plot shows the per-call timing of _get_energy() plus _get_magnetization() against system size \(N\). At \(L = 512\) the pair costs 0.31 ms for Ising, 3.7 ms for the discrete clock, 4.5 ms for XY, and 20.3 ms for the continuous clock, so the planar models cost 12 to 65 times the Ising value. Ising sums a \(\pm 1\) array stored as one byte per site. XY reads two float64 components per site, sixteen bytes instead of one, and forms two dot products per site for the energy, without trigonometric functions. The discrete clock reads four-byte integers, but gathers cosine and sine values from lookup tables into temporary arrays for the magnetisation and performs two table lookups with integer modulo per site for the energy. The continuous clock pays the XY cost plus an arctan2 and a cosine per site for the anisotropy energy, which makes it about 4.5 times as expensive as XY. Checkerboard and random variants of the same model coincide, since the measurement does not depend on the update scheme. At large \(N\) all curves approach a slope of one, a single linear pass per call; for \(L \le 64\) the Ising cost of a few microseconds is dominated by fixed per-call overhead.

[6]:
plt.figure(figsize=(10, 6))

for name in results:
    L_vals = sorted(results[name].keys())
    N_vals = [L*L for L in L_vals]
    thermo_vals = [results[name][L]['thermo_ms'] for L in L_vals]
    plt.loglog(
        N_vals, thermo_vals,
        marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name], color=MODEL_COLORS[name],
        label=name,
    )

plt.title('Per-Step Thermodynamic Measurement Cost (M + E)', fontsize=14)
plt.xlabel('Number of Sites $N = L^2$', fontsize=12)
plt.ylabel('Time per call (ms)', fontsize=12)
plt.grid(True, which='both', alpha=0.3)
plt.legend()
plt.show()
_images/benchmarks_12_0.png

Thermodynamic Overhead Ratio

This plot shows (per-step M+E collection time) / (sweep time), the fraction of each sweep’s budget consumed by recording the two per-step observables. The ratio only covers the quantities that must be collected at every step; post-hoc observables (χ, C_v, G(r), τ_int) are paid once per window regardless of its length and do not contribute to this ratio.

A ratio above 1.0 (dashed reference) would mean that recording \(M\) and \(E\) at every sweep costs more than the sweep itself. No model comes close: every ratio stays below 0.51 at all sizes, and the curves are flat from \(L \approx 128\) onward. At \(L = 512\) the ratio is 0.08 for Ising with checkerboard updates and 0.02 with random updates, 0.26 and 0.15 for XY, 0.22 and 0.14 for the discrete clock, and 0.49 and 0.39 for the continuous clock. The ordering follows the measurement cost of the previous plot: the continuous clock evaluates trigonometric functions in its energy, while the Ising measurement is a pass over a one-byte array that stays cheap even against its fast sweep. For each model the random-update variant has the smaller ratio, because its sweep is slower while the measurement cost is unchanged.

[7]:
plt.figure(figsize=(10, 6))
for name in results:
    L_vals = sorted(results[name].keys())
    ratios = []
    for L in L_vals:
        m = results[name][L]
        sweep_ms = (1.0 / m['sps']) * 1000
        ratios.append(m['thermo_ms'] / sweep_ms)

    plt.plot(
        L_vals, ratios,
        marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name], color=MODEL_COLORS[name],
        label=name,
    )

plt.title('Thermodynamic Overhead Ratio', fontsize=14)
plt.xlabel('Lattice Size $L$', fontsize=12)
plt.ylabel('Thermo Cost / Sweep Time', fontsize=12)
plt.axhline(1.0, color='black', linestyle='--', alpha=0.5)
plt.grid(True, alpha=0.3)
plt.legend()
plt.show()
_images/benchmarks_14_0.png

Scaling Exponents

The plot below fits a power law \(t_{\text{sweep}} \propto N^\alpha\) to the measured sweep times via log-log linear regression, then reports \(\alpha\) in the legend for each model. Ideal \(O(N)\) cost gives \(\alpha = 1.0\) exactly. Values above 1 indicate super-linear growth, which can arise from cache pressure at large \(L\). At \(L = 512\) the Ising spin array (one byte per site) occupies 256 kB, the discrete clock array (four-byte integers) 1 MB, and the XY and continuous clock arrays (two float64 components per site) 4 MB, the last two larger than the L2 cache of most CPUs. Values slightly below 1 arise when a fixed per-call overhead inflates the time of the smallest lattices and flattens the fit.

Comparing \(\alpha\) across models separates models where cost per spin is constant from those where it drifts with size, independent of the absolute sweep rate shown in earlier plots. The fitted exponents lie between 0.954 and 1.022. The checkerboard variants fit slightly below 1 (0.954 for Ising, 0.981 to 0.993 for the others), mainly because the cost per site at \(L = 32\) is higher than at large \(L\). The random variants fit at or slightly above 1 (0.999 to 1.022), since their cost per site rises at \(L = 512\), where random access into a multi-megabyte array misses the cache more often. Within these deviations the cost per spin is constant over the measured range.

[8]:
def analyze_scaling(sizes, results):
    plt.figure(figsize=(10, 6))
    N_vals = [L*L for L in sizes]

    for name in results:
        sps = [results[name][L]['sps'] for L in sizes]
        time_per_sweep = [1.0/s for s in sps]

        # Log-log regression for exponent extraction
        log_N = np.log(N_vals)
        log_T = np.log(time_per_sweep)
        slope, intercept, r_value, p_value, std_err = linregress(log_N, log_T)

        plt.loglog(
            N_vals, time_per_sweep,
            marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name], color=MODEL_COLORS[name],
            label=rf"{name} ($\alpha={slope:.3f}$)",
        )

    plt.title(r'Scaling Behaviour: Time per Sweep vs $N$ ($T \propto N^\alpha$)', fontsize=14)
    plt.xlabel('Number of Spins $N = L^2$', fontsize=12)
    plt.ylabel('Time per Sweep (s)', fontsize=12)
    plt.grid(True, which="both", ls="-", alpha=0.2)
    plt.legend()
    plt.show()

analyze_scaling(sizes, results)
_images/benchmarks_16_0.png

Cost per Spin Update

Dividing sweep time by \(N = L^2\) gives a size-normalized cost in nanoseconds per attempted spin flip. This collapses the \(O(N)\) factor and reveals whether the per-spin cost is truly constant or carries a hidden size dependence, for instance through rising cache-miss rates as the spin array grows beyond LLC capacity.

At \(L = 512\) the cost per attempted update with checkerboard updates is 16 ns for Ising, 65 ns for the discrete clock, 67 ns for XY, and 156 ns for the continuous clock. The Ising model sits at the bottom because a proposal needs only a neighbour sum of \(\pm 1\) spins and one random number; the energy change takes one of five values, \(\Delta E \in \{-8J, -4J, 0, 4J, 8J\}\), and only the two positive ones need the precomputed Boltzmann factors. XY pays a cosine and a sine per proposal, and the continuous clock additionally an arctan2 and two evaluations of \(\cos(q\phi)\) for the anisotropy. The discrete clock avoids trigonometry by looking up \(\cos(2\pi\,\Delta k/q)\) in a length-\(q\) table, which closes about 65% of the gap between the continuous clock and Ising, \((156 - 65)/(156 - 16) \approx 0.65\), with the same fraction for random updates, and puts it level with XY. Random-sequential updates are 1.3 to 3.0 times slower than checkerboard at \(L = 512\): by a factor of 3.04 for Ising, 1.70 for XY, 1.55 for the discrete clock, and 1.30 for the continuous clock. The penalty is a per-attempt overhead, from drawing a random site index and reading memory out of order, so it weighs most on the model whose update arithmetic is cheapest.

[9]:
plt.figure(figsize=(10, 6))
for name in results:
    N_vals = [L*L for L in sizes]
    sps = [results[name][L]['sps'] for L in sizes]
    tps = [(1.0/s)/N for s, N in zip(sps, N_vals, strict=True)]
    plt.semilogx(
        N_vals, [t*1e9 for t in tps],
        marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name], color=MODEL_COLORS[name],
        label=name,
    )

plt.title('Computational Cost per Spin Update', fontsize=14)
plt.xlabel('Number of Spins $N = L^2$', fontsize=12)
plt.ylabel('Time per Update (ns)', fontsize=12)
plt.grid(True, alpha=0.3)
plt.legend()
plt.show()
_images/benchmarks_18_0.png

Summary Table and Speedup Analysis

The table below records primary performance metrics at the largest lattice size (\(L = 512\)), separating the update kernel from measurement overhead.

The table reports Sweeps/s (update throughput), Sweep (ms) (wall time of one step() call, the update kernel alone, since the throughput loop collects no observables), Thermo (ms) (the cost of one get_energy() and get_magnetization() pair), Measured (ms) (the cost of one sweep that also records \(M\) and \(E\), the sum of the two), and Overhead (%) (the share of a measured sweep spent on the measurement).

We quantify two major optimizations below the table: the Checkerboard Speedup (achieved via cache-friendly striding and SIMD vectorization) and the Discrete Speedup (achieved by replacing trigonometric evaluations with integer lookups).

[10]:
L_max = sizes[-1]
print(f"Performance metrics at L = {L_max} (N = {L_max*L_max})")
print("-" * 108)
print(f"{'Model':<35} | {'Sweeps/s':>10} | {'Sweep (ms)':>10} | {'Thermo (ms)':>11} | {'Measured (ms)':>13} | {'Overhead (%)':>12}")
print("-" * 108)

for name in results:
    m = results[name][L_max]
    # measure_performance times step() alone, so the sweep time already
    # excludes observable collection; a measured sweep costs both.
    sweep_ms = (1.0 / m['sps']) * 1000
    measured_ms = sweep_ms + m['thermo_ms']
    overhead_pct = (m['thermo_ms'] / measured_ms) * 100.0
    print(f"{name:<35} | {m['sps']:>10.1f} | {sweep_ms:>10.2f} | {m['thermo_ms']:>11.3f} | {measured_ms:>13.2f} | {overhead_pct:>11.1f}%")

print("\n1. Checkerboard vs Random Speedup (at constant model representation):")
for base in ['Ising', 'XY', 'Clock Continuous', 'Clock Discrete']:
    cb_key = f'{base} (Checkerboard)'
    rnd_key = f'{base} (Random)'
    cb_sps = results[cb_key][L_max]['sps']
    rnd_sps = results[rnd_key][L_max]['sps']
    speedup = cb_sps / rnd_sps
    print(f"  {base:<18}: {speedup:5.2f}x faster with Checkerboard updates")

print("\n2. Discrete vs Continuous Speedup (at constant update scheme):")
for scheme in ['Checkerboard', 'Random']:
    cont_key = f'Clock Continuous ({scheme})'
    disc_key = f'Clock Discrete ({scheme})'
    cont_sps = results[cont_key][L_max]['sps']
    disc_sps = results[disc_key][L_max]['sps']
    speedup = disc_sps / cont_sps
    print(f"  {scheme:<12}: {speedup:5.2f}x faster with Discrete representation")

Performance metrics at L = 512 (N = 262144)
------------------------------------------------------------------------------------------------------------
Model                               |   Sweeps/s | Sweep (ms) | Thermo (ms) | Measured (ms) | Overhead (%)
------------------------------------------------------------------------------------------------------------
Ising (Checkerboard)                |      240.8 |       4.15 |       0.314 |          4.47 |         7.0%
Ising (Random)                      |       79.3 |      12.61 |       0.302 |         12.91 |         2.3%
XY (Checkerboard)                   |       56.9 |      17.59 |       4.489 |         22.07 |        20.3%
XY (Random)                         |       33.4 |      29.98 |       4.441 |         34.42 |        12.9%
Clock Continuous (Checkerboard)     |       24.5 |      40.80 |      20.083 |         60.88 |        33.0%
Clock Continuous (Random)           |       18.9 |      52.85 |      20.544 |         73.39 |        28.0%
Clock Discrete (Checkerboard)       |       58.5 |      17.10 |       3.698 |         20.80 |        17.8%
Clock Discrete (Random)             |       37.7 |      26.55 |       3.765 |         30.31 |        12.4%

1. Checkerboard vs Random Speedup (at constant model representation):
  Ising             :  3.04x faster with Checkerboard updates
  XY                :  1.70x faster with Checkerboard updates
  Clock Continuous  :  1.30x faster with Checkerboard updates
  Clock Discrete    :  1.55x faster with Checkerboard updates

2. Discrete vs Continuous Speedup (at constant update scheme):
  Checkerboard:  2.39x faster with Discrete representation
  Random      :  1.99x faster with Discrete representation

At \(L = 512\) a checkerboard sweep takes 4.15 ms for Ising, 17.1 ms for the discrete clock, 17.6 ms for XY, and 40.8 ms for the continuous clock. Recording \(M\) and \(E\) at every sweep takes 7.0% of a measured Ising checkerboard sweep (2.3% with random updates), 17.8% for the discrete clock, 20.3% for XY, and 33.0% for the continuous clock, so for the planar models the measurement is a visible but minor share of the cost.

Checkerboard updates are faster than random-sequential ones for every model, by a factor of 3.04 for Ising, 1.70 for XY, 1.55 for the discrete clock, and 1.30 for the continuous clock; the more expensive the per-site arithmetic, the smaller the relative gain from the regular memory access of the sublattice stride. The discrete representation runs 2.39 times faster than the continuous one with checkerboard updates and 1.99 times faster with random updates. That comparison is between two sixfold-symmetric planar models rather than one Hamiltonian, since the continuous variant is the XY model with a weak anisotropy (\(A = 0.1\)) and the discrete variant is the \(q = 6\) clock model.

Spatial Correlation \(G(r)\): Cost per Call

\(G(r)\) measures the equal-time spatial correlation between spins separated by lattice distance \(r\). It is a post-hoc observable: evaluated once on a spin-field snapshot after the measurement window closes, carrying no per-step cost during the run. Its wall-clock cost matters when scanning many temperatures or lattice sizes, because each call involves a full FFT of the spin field.

The implementation divides naturally into three cost tiers by spin representation. Ising spins form a scalar field, so a single forward and inverse transform suffices. XY and continuous clock spins are two-component vectors; each component is transformed independently, doubling the FFT count and increasing memory traffic. The discrete clock model first extracts floating-point components from integer state indices before following the same two-transform path. The plot below shows how these tiers separate as \(N\) grows, including an \(O(N \log N)\) reference line to verify that FFT scaling dominates at large system sizes.

[11]:
CORR_ITERS = 50  # timed calls per (model, size)

if _loaded_from_npz:
    # G(r) cost data is already in results; no re-timing needed.
    corr_results = {
        name: {L: results[name][L]['corr_ms'] for L in sizes}
        for name in results
    }
else:
    corr_results = {}
    for corr_name, corr_constructor in tqdm(model_configs, desc='G(r) Cost'):
        corr_results[corr_name] = {}
        for L in sizes:
            corr_sim = corr_constructor(L)
            # Two warm-up calls; JIT is already compiled from the main benchmark warm-up.
            corr_sim.calculate_correlation_function()
            corr_sim.calculate_correlation_function()
            start = time.perf_counter()
            for _ in range(CORR_ITERS):
                corr_sim.calculate_correlation_function()
            corr_results[corr_name][L] = (time.perf_counter() - start) / CORR_ITERS * 1000

# N log N reference line anchored to the mean cost at L=32
N_ref = np.array([L * L for L in sizes], dtype=float)
mean_at_L0 = float(np.mean([corr_results[n][sizes[0]] for n in corr_results]))
N0 = float(sizes[0] ** 2)
nlogn_ref = mean_at_L0 * (N_ref * np.log2(N_ref)) / (N0 * np.log2(N0))

plt.figure(figsize=(10, 6))
for corr_name in corr_results:
    L_vals = sorted(corr_results[corr_name].keys())
    N_vals = [L * L for L in L_vals]
    cost_vals = [corr_results[corr_name][L] for L in L_vals]
    plt.loglog(
        N_vals, cost_vals,
        marker=MODEL_MARKERS[corr_name], linestyle=MODEL_LS[corr_name],
        color=MODEL_COLORS[corr_name], label=corr_name, markersize=7, alpha=0.85,
    )

plt.loglog(N_ref, nlogn_ref, 'k--', linewidth=1.5, alpha=0.6, label=r'$O(N \log N)$ reference')
plt.title('Spatial Correlation $G(r)$: Cost per Call vs System Size', fontsize=14)
plt.xlabel('Number of Sites $N = L^2$', fontsize=12)
plt.ylabel('Cost per call (ms)', fontsize=12)
plt.grid(True, which='both', ls='-', alpha=0.2)
plt.legend(fontsize=9)
plt.show()

# --- Cost table grouped by spin-representation tier --------------------------
L_show = sizes[-1]
_tier = {
    'Ising (Checkerboard)':            'scalar, 1 FFT',
    'Ising (Random)':                  'scalar, 1 FFT',
    'XY (Checkerboard)':               '2-component float, 2 FFTs',
    'XY (Random)':                     '2-component float, 2 FFTs',
    'Clock Continuous (Checkerboard)': '2-component float, 2 FFTs',
    'Clock Continuous (Random)':       '2-component float, 2 FFTs',
    'Clock Discrete (Checkerboard)':   'int -> float + 2 FFTs',
    'Clock Discrete (Random)':         'int -> float + 2 FFTs',
}

print(f"G(r) cost per call at L={L_show} (N={L_show**2})")
print(f"{'Model':<35} {'ms/call':>9}  representation")
print("-" * 72)
for corr_name in corr_results:
    ms = corr_results[corr_name][L_show]
    print(f"{corr_name:<35} {ms:>9.2f}  {_tier[corr_name]}")

# Tier averages and cross-tier ratios
ising_ms = np.mean([corr_results[k][L_show] for k in ('Ising (Checkerboard)', 'Ising (Random)')])
xy_ms    = np.mean([corr_results[k][L_show] for k in (
    'XY (Checkerboard)', 'XY (Random)',
    'Clock Continuous (Checkerboard)', 'Clock Continuous (Random)',
)])
disc_ms  = np.mean([corr_results[k][L_show] for k in (
    'Clock Discrete (Checkerboard)', 'Clock Discrete (Random)',
)])

print()
print("Tier means:")
print(f"  Ising (scalar, 1 FFT)              {ising_ms:6.2f} ms  (reference)")
print(f"  XY / Clock Continuous (2 FFTs)     {xy_ms:6.2f} ms  ({xy_ms/ising_ms:.2f}x Ising)")
print(
    f"  Clock Discrete (convert + 2 FFTs)  {disc_ms:6.2f} ms  "
    f"({disc_ms/xy_ms:.2f}x XY tier,  {disc_ms/ising_ms:.2f}x Ising)"
)
_images/benchmarks_23_1.png
G(r) cost per call at L=512 (N=262144)
Model                                 ms/call  representation
------------------------------------------------------------------------
Ising (Checkerboard)                     8.77  scalar, 1 FFT
Ising (Random)                           8.63  scalar, 1 FFT
XY (Checkerboard)                       13.22  2-component float, 2 FFTs
XY (Random)                             13.04  2-component float, 2 FFTs
Clock Continuous (Checkerboard)         13.15  2-component float, 2 FFTs
Clock Continuous (Random)               13.21  2-component float, 2 FFTs
Clock Discrete (Checkerboard)           17.20  int -> float + 2 FFTs
Clock Discrete (Random)                 17.04  int -> float + 2 FFTs

Tier means:
  Ising (scalar, 1 FFT)                8.70 ms  (reference)
  XY / Clock Continuous (2 FFTs)      13.16 ms  (1.51x Ising)
  Clock Discrete (convert + 2 FFTs)   17.12 ms  (1.30x XY tier,  1.97x Ising)

Autocorrelation Time and Sampling Efficiency

The spatial correlation function \(G(r)\) measures equal-time correlations between sites separated by distance \(r\). Its MC-time counterpart is the integrated autocorrelation time \(\tau_{\text{int}}\), measured in sweeps: two magnetization samples separated by fewer than \(\tau_{\text{int}}\) sweeps are statistically dependent and do not independently reduce the error on ensemble averages.

Raw throughput in sweeps per second is therefore not the complete figure of merit for equilibrium sampling. The relevant rate is the independent samples per second, \(\text{ISS} = \text{sweeps/s} \div \tau_{\text{int}}\). A model with twice the throughput but four times the autocorrelation time explores configuration space at half the effective rate.

\(\tau_{\text{int}}\) is estimated via an FFT-based autocorrelation estimator with the Madras–Sokal automatic windowing rule [5], which cuts integration at lag \(W = 6\,\tau_{\text{int}}\) to suppress noise accumulation at large lags. Each model is started from a random configuration and run for a \(500\)-sweep burn-in, then a \(2000\)-sweep magnetization series at \(L=64\); this is long enough for well-separated phases but may under-resolve \(\tau_{\text{int}}\) right at a critical point where the true value diverges with \(L\). In that case the reported number is a lower bound.

[12]:
TAU_L      = 64    # lattice size for autocorrelation measurement
TAU_BURNIN = 500   # equilibration steps before the measurement window
TAU_SWEEPS = 2000  # magnetization time-series length

tau_results = {}

for tau_name, tau_constructor in tqdm(model_configs, desc='Autocorrelation'):
    tau_sim = tau_constructor(TAU_L)
    tau_sim.equilibrate(n_steps=TAU_BURNIN)
    tau_mags, _ = tau_sim.run(n_steps=TAU_SWEEPS)
    try:
        _, tau = calculate_autocorr(time_series=np.array(tau_mags))
    except ZeroVarianceAutocorrelationError:
        # Zero-variance series (fully ordered phase): tau_int is undefined.
        # This is a NumericalAnalysisError (a RuntimeError), not a ValueError.
        tau = float('nan')
    tau_sps = results[tau_name][TAU_L]['sps']
    tau_iss = tau_sps / tau if np.isfinite(tau) and tau > 0 else float('nan')
    tau_results[tau_name] = {'tau_int': tau, 'iss': tau_iss}

print(f"MC autocorrelation at L={TAU_L}  ({TAU_SWEEPS}-sweep series, {TAU_BURNIN}-step burn-in)")
print("-" * 72)
print(f"{'Model':<35} {'tau_int (sweeps)':>18} {'ISS (samples/s)':>18}")
print("-" * 72)
for tau_name, d in tau_results.items():
    tau_str = f"{d['tau_int']:>18.1f}" if np.isfinite(d['tau_int']) else f"{'N/A':>18}"
    iss_str = f"{d['iss']:>18.1f}"     if np.isfinite(d['iss'])     else f"{'N/A':>18}"
    print(f"{tau_name:<35}{tau_str}{iss_str}")
MC autocorrelation at L=64  (2000-sweep series, 500-step burn-in)
------------------------------------------------------------------------
Model                                 tau_int (sweeps)    ISS (samples/s)
------------------------------------------------------------------------
Ising (Checkerboard)                             34.8             388.7
Ising (Random)                                   69.3              77.7
XY (Checkerboard)                                72.2              47.6
XY (Random)                                     287.1               8.9
Clock Continuous (Checkerboard)                 190.0               8.2
Clock Continuous (Random)                       262.1               5.2
Clock Discrete (Checkerboard)                   271.3              14.2
Clock Discrete (Random)                         299.3               8.9

The table above reports raw numbers. The two panels below plot the same data as horizontal bar charts, making it straightforward to rank models by decorrelation speed and by effective sampling rate in a single glance.

[13]:
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))

tau_names  = list(tau_results.keys())
tau_colors = [MODEL_COLORS[n] for n in tau_names]
y_pos      = np.arange(len(tau_names))
short_labels = [
    n.replace(' (Checkerboard)', ' (CB)').replace(' (Random)', ' (Rnd)')
    for n in tau_names
]

tau_vals = [tau_results[n]['tau_int'] for n in tau_names]
iss_vals  = [tau_results[n]['iss']     for n in tau_names]

ax1.barh(y_pos, tau_vals, color=tau_colors, edgecolor='white', height=0.6)
ax1.set_yticks(y_pos)
ax1.set_yticklabels(short_labels, fontsize=9)
ax1.set_xlabel(r'$\tau_\mathrm{int}$ (sweeps)', fontsize=12)
ax1.set_title(rf'Integrated Autocorrelation Time at $L={TAU_L}$', fontsize=13)
ax1.invert_yaxis()
ax1.grid(True, alpha=0.3, axis='x')

ax2.barh(y_pos, iss_vals, color=tau_colors, edgecolor='white', height=0.6)
ax2.set_yticks(y_pos)
ax2.set_yticklabels(short_labels, fontsize=9)
ax2.set_xlabel(r'ISS = Sweeps/s $\div\,\tau_\mathrm{int}$  (samples/s)', fontsize=12)
ax2.set_title(rf'Independent Samples per Second at $L={TAU_L}$', fontsize=13)
ax2.invert_yaxis()
ax2.grid(True, alpha=0.3, axis='x')

plt.tight_layout()
plt.show()
_images/benchmarks_27_0.png

At \(L = 64\) the Ising checkerboard run decorrelates in 35 sweeps and delivers 389 independent samples per second, about eight times the XY checkerboard rate (48 per second) and 27 times the discrete clock (14 per second). For every model the random-sequential variant has the longer autocorrelation time in sweeps, so its lower throughput and slower decorrelation compound: Ising with random updates reaches 78 samples per second, a factor of five below checkerboard.

These values rank the models but do not measure \(\tau_{\text{int}}\) precisely. Sokal’s estimate of the variance of the windowed estimator [5], \(\mathrm{Var}(\hat\tau_{\text{int}}) \approx 2(2W+1)\,\tau_{\text{int}}^2/N\) with \(W = 6\,\tau_{\text{int}}\) and \(N = 2000\), gives a relative error of about 65% for the Ising checkerboard value and of order 100% for every other entry, because the series spans only about 7 to 60 autocorrelation times. The clock values carry a further caveat: at \(T = 0.5\) both clock variants are in the ordered phase, and a 500-sweep burn-in from a random start may not have completed the ordering at \(L = 64\), so part of their measured autocorrelation can be slow relaxation rather than equilibrium fluctuation.

Hardware Scaling & Multi-core Performance

This section probes the limits of VibeSpin’s architecture on modern CPU hierarchies. We examine the nanoseconds per spin update to detect cache-tier transitions and benchmark Topological Observables which involve non-local plaquette traversals. Finally, we quantify the gain from Numba Multi-threading (parallel=True) which distributes sublattice updates across multiple cores.

Efficiency: Nanoseconds per site update

Throughput (sweeps/s) decreases as \(N\) increases, but the cost per spin update should ideally remain constant. The plot below shows this metric for all models. Upward drifts at large \(L\) indicate hardware bottlenecks (cache misses or memory bandwidth saturation), while downward drifts suggest Numba’s vectorization becoming more effective.

[14]:
plt.figure(figsize=(10, 6))
for name in results:
    L_vals = sorted(results[name].keys())
    ns_per_site = []
    for L in L_vals:
        t_sweep = 1.0 / results[name][L]['sps']
        ns_per_site.append((t_sweep / (L*L)) * 1e9)

    plt.semilogx(L_vals, ns_per_site, marker=MODEL_MARKERS[name], linestyle=MODEL_LS[name],
                 color=MODEL_COLORS[name], label=name)

plt.title('Update Cost per Spin', fontsize=14)
plt.xlabel('Lattice Size $L$', fontsize=12)
plt.ylabel('Time (ns / site)', fontsize=12)
plt.grid(True, which='both', alpha=0.3)
plt.legend(fontsize='small', ncol=2)
plt.show()
_images/benchmarks_31_0.png

Topological and Vector Analysis Cost

Physical studies of the XY and Clock models often depend on detecting topological defects (vortices) or calculating the helicity modulus (phase-twist response). These operations involve trigonometric sums and phase-wrapping operations per site, and their cost per call is compared below with the per-step \(M\) and \(E\) cost.

[15]:
topo_results = {name: {} for name, _ in model_configs if 'Ising' not in name}

if _loaded_from_npz:
    # Topological cost data is already in results as separate vden_ms and heli_ms
    # components, matching what this section measures: _get_vortex_density() +
    # _get_helicity_data() timed together per call.
    for name in topo_results:
        for L in sizes:
            r = results[name][L]
            topo_results[name][L] = r['vden_ms'] + r['heli_ms']
else:
    for L in tqdm(sizes, desc='Topological Analysis'):
        for name, constructor in model_configs:
            if 'Ising' in name: continue
            sim = constructor(L)
            # Warm-up
            if hasattr(sim, 'calculate_vorticity'): sim.calculate_vorticity()
            if hasattr(sim, 'get_helicity_data'): sim.get_helicity_data()

            start = time.perf_counter()
            for _ in range(ANALYSIS_ITERS):
                v_dens = sim.get_vortex_density()
                heli = sim.get_helicity_data()
            topo_ms = (time.perf_counter() - start) / ANALYSIS_ITERS * 1000
            topo_results[name][L] = topo_ms

plt.figure(figsize=(10, 6))
for name in topo_results:
    L_vals = sorted(topo_results[name].keys())
    plt.loglog(L_vals, [topo_results[name][L] for L in L_vals],
               marker=MODEL_MARKERS[name], color=MODEL_COLORS[name], label=name)

plt.title('Topological Analysis Cost (Vortex Density + Helicity)', fontsize=14)
plt.xlabel('Lattice Size $L$', fontsize=12)
plt.ylabel('Time per call (ms)', fontsize=12)
plt.grid(True, which='both', alpha=0.3)
plt.legend()
plt.show()
_images/benchmarks_33_1.png

At \(L = 512\) one combined call to _get_vortex_density() and _get_helicity_data() costs about 10.5 ms for XY and the continuous clock and about 17 to 18 ms for the discrete clock, which first converts its integer states to vector components. For XY this is about 2.3 times the per-step \(M\) and \(E\) cost; for the continuous clock it is about half of it, because that model’s energy evaluation is itself trigonometric. All curves grow about linearly in \(N\). The XY checkerboard point at \(L = 32\) lies above the trend, most likely a timing artefact of a short measurement.

These routines are typically evaluated intermittently rather than every sweep, so the plot is an analysis budget per call versus lattice size, not an update-kernel throughput metric.

Parallel Scaling Benchmark

Checkerboard updates partition the lattice into two independent sublattices, one updated per half-step. Because sites within each sublattice do not share nearest neighbours, all updates in a sublattice pass are independent and can execute concurrently without read-write conflicts. VibeSpin exposes this via parallel=True, which directs Numba to spawn threads across the sublattice using prange.

The code below measures Ising checkerboard throughput at \(L \in \{128, 256, 512, 1024\}\) in both serial and parallel modes, timing 100 sweeps after one warm-up sweep for each. The left panel shows absolute throughput and the right panel the speedup, parallel over serial sweeps per second. Two effects can limit the speedup: on small lattices the cost of starting and synchronising threads for every sublattice pass, and on large lattices memory bandwidth.

[16]:
p_sizes = [128, 256, 512, 1024]
p_results = {'Serial': [], 'Parallel': []}
# Both modes run and are normalised by the same number of sweeps.
P_SWEEPS = 100

for L in tqdm(p_sizes, desc='Parallel Benchmark'):
    # Serial
    s_sim = IsingSimulation(size=L, temp=2.269, update='checkerboard', parallel=False)
    s_sim.step() # Warm-up
    start = time.perf_counter()
    for _ in range(P_SWEEPS): s_sim.step()
    p_results['Serial'].append(P_SWEEPS / (time.perf_counter() - start))

    # Parallel
    p_sim = IsingSimulation(size=L, temp=2.269, update='checkerboard', parallel=True)
    p_sim.step() # Warm-up
    start = time.perf_counter()
    for _ in range(P_SWEEPS): p_sim.step()
    p_results['Parallel'].append(P_SWEEPS / (time.perf_counter() - start))

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))
ax1.plot(p_sizes, p_results['Serial'], 'o-', label='Serial')
ax1.plot(p_sizes, p_results['Parallel'], 's-', label='Parallel')
ax1.set_title('Ising Throughput: Serial vs Parallel')
ax1.set_xlabel('Lattice Size $L$')
ax1.set_ylabel('Sweeps / sec')
ax1.legend()
ax1.grid(True, alpha=0.3)

speedup = [p/s for p, s in zip(p_results['Parallel'], p_results['Serial'], strict=True)]
ax2.plot(p_sizes, speedup, 'D-', color='tab:green')
ax2.axhline(1.0, color='black', linestyle='--', alpha=0.5)
ax2.set_title('Multi-core Speedup Ratio')
ax2.set_xlabel('Lattice Size $L$')
ax2.set_ylabel('Speedup (Parallel / Serial)')
ax2.grid(True, alpha=0.3)
plt.show()
_images/benchmarks_36_1.png

On the four-core machine used for this run the parallel kernel is 3.1 to 3.7 times faster than the serial one at every size from \(L = 128\) to \(1024\), a parallel efficiency of 77% to 92%. The speedup is already above 3 at \(L = 128\), so no overhead-bound regime appears in this range, and it does not fall at \(L = 1024\), so memory bandwidth is not yet limiting. Each point is a single 100-sweep timing, so the dip at \(L = 512\) (3.07) is not significant. The gain applies to equilibrium sampling with checkerboard updates; the random-site updates used for kinetics are not parallelised this way.

Performance Dashboard

The six-panel figure below assembles the main performance dimensions into a single view. From top-left to bottom-right: update throughput (sweeps/s), per-spin update cost (ns/site), \(G(r)\) analysis time, topological analysis time, thermodynamic collection cost, and the per-step overhead ratio. All panels share the same lattice sizes, model colours, and markers, so cross-panel comparisons are direct.

[17]:
fig, axes = plt.subplots(3, 2, figsize=(15, 18))
fig.suptitle('VibeSpin Comprehensive Performance Summary', fontsize=16)
ax1, ax2, ax3, ax4, ax5, ax6 = axes.flatten()

for name in results:
    L_vals = sorted(results[name].keys())
    N_vals = [L*L for L in L_vals]

    # 1. Throughput
    ax1.loglog(N_vals, [results[name][L]['sps'] for L in L_vals], marker=MODEL_MARKERS[name], color=MODEL_COLORS[name], label=name)

    # 2. ns per site
    ns_site = [( (1.0/results[name][L]['sps']) / (L*L) ) * 1e9 for L in L_vals]
    ax2.semilogx(N_vals, ns_site, marker=MODEL_MARKERS[name], color=MODEL_COLORS[name])

    # 3. Correlation function G(r)
    if 'corr_results' in locals() and name in corr_results:
        c_L = sorted(corr_results[name].keys())
        ax3.loglog([l*l for l in c_L], [corr_results[name][l] for l in c_L], marker=MODEL_MARKERS[name], color=MODEL_COLORS[name])

    # 4. Topological Analysis
    if 'topo_results' in locals() and name in topo_results:
        t_L = sorted(topo_results[name].keys())
        ax4.loglog([l*l for l in t_L], [topo_results[name][l] for l in t_L], marker=MODEL_MARKERS[name], color=MODEL_COLORS[name])

    # 5. Thermodynamic Measurement
    ax5.loglog(N_vals, [results[name][L]['thermo_ms'] for L in L_vals], marker=MODEL_MARKERS[name], color=MODEL_COLORS[name])

    # 6. Per-Step Overhead Ratio
    overheads = [results[name][L]['thermo_ms'] / (1000.0/results[name][L]['sps']) for L in L_vals]
    ax6.plot(L_vals, overheads, marker=MODEL_MARKERS[name], color=MODEL_COLORS[name])

ax1.set_title('Throughput (Sweeps/sec)'); ax1.set_ylabel('Sweeps/s'); ax1.legend(fontsize='x-small', ncol=2)
ax2.set_title('Update Cost per Spin'); ax2.set_ylabel('Time (ns/site)')
ax3.set_title('Correlation Function Cost (FFT-based)'); ax3.set_ylabel('Time (ms)')
ax4.set_title('Topological Analysis Cost (Vort+Heli)'); ax4.set_ylabel('Time (ms)')
ax5.set_title('Thermodynamic Measurement (M+E)'); ax5.set_ylabel('Time (ms)')
ax6.set_title('Per-Step Overhead Ratio'); ax6.set_ylabel('Ratio'); ax6.axhline(1.0, color='black', ls='--', alpha=0.5)

for ax in axes.flatten(): ax.grid(True, alpha=0.3)
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
plt.show()
_images/benchmarks_39_0.png

The final panelized figure aggregates update throughput, per-spin update cost, observable overheads, and analysis-time scaling across models. Use this summary to compare asymptotic trends rather than single-point values, since warm-up costs and finite-size effects can distort small-system timings. In equilibrium workflows near criticality, combine these timing curves with autocorrelation behavior to estimate effective independent-sample throughput.

Bibliography

[1] L. Onsager, “Crystal Statistics. I. A Two-Dimensional Model with an Order-Disorder Transition,” Physical Review, vol. 65, no. 3-4, pp. 117–149, 1944. APS

[2] J. M. Kosterlitz and D. J. Thouless, “Ordering, metastability and phase transitions in two-dimensional systems,” Journal of Physics C: Solid State Physics, vol. 6, no. 7, pp. 1181–1203, 1973. IOP

[3] Y. Tomita and Y. Okabe, “Probability-changing cluster algorithm for two-dimensional XY and clock models” (2002). Gives \(T_{\mathrm{BKT}} = 0.8933(6)\) for the XY model and \(T_1 = 0.7014(11)\), \(T_2 = 0.9008(6)\) for the \(q = 6\) clock model. arXiv:cond-mat/0202161

[4] W. K. Hastings, “Monte Carlo sampling methods using Markov chains and their applications,” Biometrika, vol. 57, no. 1, pp. 97–109, 1970. Oxford Academic

[5] A. D. Sokal, “Monte Carlo Methods in Statistical Mechanics: Foundations and New Algorithms,” lecture notes (1989), published in Functional Integration: Basics and Applications (C. DeWitt-Morette, P. Cartier, A. Folacci, eds.), Springer, 1997, pp. 131–192. Integrated autocorrelation time, the automatic windowing estimator, and its statistical error. Springer Link