Skip to content

Testing, Verification & Benchmarking ​

This guide documents the test suite architecture, first-principles physics verification protocols, chunked compute-sanitizer workflows, and reproducible GPU benchmarking practices for ParticleDynamics.


1. CPU vs GPU Test Architecture ​

The test entrypoint is test/runtests.jl, which sets CUDA.allowscalar(false) globally so any accidental scalar GPU indexing fails immediately.

Host-Only (CPU) Tests (.github/workflows/ci-cpu.yml) ​

Without a CUDA device, test/runtests.jl validates 54,947 checks across 13 CPU test files covering host mathematics, B2ProlateWindow / fewest-PSWF quadrature, configuration/API invariants, public exports, and static source audits:

  • test/test_neighbor_reference.jl (against test/neighbor_reference.jl)

  • test/test_rigid_water_math.jl (SETTLE/RATTLE algebra & double-float math)

  • test/test_periodic_displacement_math.jl (minimum-image displacement identities)

  • test/test_w1_recip_octant_math.jl (orthorhombic octant G_oct/Vc_oct & even-preferring smooth mesh snapping)

  • test/test_w1_runtime_cpu.jl (graph scheduling, runtime config & Philox MUFU math)

  • test/test_w2_autotune_dualrc_cpu.jl (verlet_buffer_skin, tune_pme_parameters, P = 5 stencil math & static LOC/hygiene audit)

  • test/test_w3_respa_cpu.jl (check_respa_stability, respa_engine_config, symplectic impulse-RESPA algebra & static audit)

  • test/test_friction_rate_cpu.jl (uniform friction_rate / tau Langevin & barostat API validation)

  • test/test_public_exports_cpu.jl, test/test_static_hygiene_cpu.jl, test/test_coverage_gaps_cpu.jl, test/test_v105_quadrature_cpu.jl, test/test_pme_kernels_cpu.jl

When gpu_required() is false, the GPU @testset skips cleanly so hosted CPU CI validates package loading, host algebra, and documentation builds (docs/make.jl).

Full GPU Suite (.github/workflows/ci-gpu-selfhosted.yml) ​

On a CUDA-capable machine, run:

bash
julia --project --startup-file=no test/runtests.jl

Or run targeted subsystem test files directly during development:

bash
julia --project --startup-file=no test/test_p1e2_direct_pairs_gpu.jl
julia --project --startup-file=no test/test_p1e2_scatter_prune_gpu.jl
julia --project --startup-file=no test/test_p1e2_general_constr_gpu.jl

The GPU suite combines:

  1. First-principles physics & analytic oracle checks:

    • Independent Float64 CPU Ewald oracle (test/ewald_reference.jl) and dispersion Ewald oracle (test/dispersion_reference.jl) with finite-difference cell-strain virial checks.

    • Independent GPU all-pairs pair-force oracles (test/gpu_force_reference.jl, test/pair_reference_gpu.jl, test/test_force_precision_gpu.jl).

    • NVE energy drift, NVT kinetic temperature & equipartition, NPT target pressure & compressibility/density equilibrium, constraint bond-length drift (< 1e-6 in Float32 :df64, < 1e-13 in Float64), and Newton-3 momentum conservation (||Σ F|| / ||F||).

  2. External golden regression fixtures (test/golden_fixtures.jl, test/README.md):

    • Checksum-verified historical records (SHA256SUMS) for deterministic trajectories (v1-20261009T122031), engine regression states (v3-engine-tests), and 2D/3D equilibrium ensembles (v2-eq-*).

    • Controlled via environment variables:

      • PD_GOLDEN_ROOT=/path/to/golden-staged — root directory holding the 4 dataset folders (or per-dataset PD_GOLDEN_DIR, PD_ENGINE_GOLDEN_DIR, PD_GOLDEN_EQ2D, PD_GOLDEN_EQ3D).

      • PD_REQUIRE_GOLDEN=1 — fail instead of skipping if any golden dataset is missing (required for release validation).

      • PD_GOLDEN_DOWNLOAD=yes|no|ask and PD_GOLDEN_URL — unattended download control.

  3. GPU residency & kernel-hygiene assertions:

    • test/test_gpu_residency.jl confirms zero host copies for state/thermostat buffers.

    • Direct-pair, bonded, constraint, and fusion suites assert CUDA.memory(k).local == 0 and absence of .local in PTX.

Chunked compute-sanitizer Runs ​

Running compute-sanitizer --tool memcheck --error-exitcode=99 slows GPU kernels by ~10-50x. Heavy verification suites expose subset environment variables so sanitizer checks stay fast and CI-friendly:

Test FileEnvironment VariableExample Values
test/test_p1de_custom_potentials_gpu.jlPD_P1DE_SAN_PARTall, individual part selectors
test/test_p1de_solute_dry_fuse_gpu.jlP1DE_SAN_PARTall, 2B, 4, etc.
test/test_p1de_workflow_npt_gpu.jlPD_P1DE_SUBSETall, subset selectors
bash
# Example: chunked memcheck pass with strict non-zero exit code on any hazard
P1DE_SAN_PART=2B compute-sanitizer --tool memcheck --error-exitcode=99 \
  julia --project --startup-file=no test/test_p1de_solute_dry_fuse_gpu.jl

2. Single-Frame Force Accuracy Parity Protocol ​

Whenever optimizing direct-space kernels (ClusterPairs), reciprocal-space meshes (Electrostatics), CompactFFT, or constraint/bonded force paths, validate single-frame force accuracy against a converged 128^3 Float64 reference (or exact CPU Ewald test/ewald_reference.jl for small boxes) on identical atomic coordinates before running throughput benchmarks:

  1. Freeze one representative condensed-phase frame (e.g., solvated biomolecule, neat water box, or molten salt) in Float64 coordinates R_ref and box box_ref.

  2. Compute the reference forces F_ref, energy U_ref, and virial W_ref:

    • For small N <= 1000: direct CPU Ewald (EwaldReference.ewald_reference in test/ewald_reference.jl, digits=16) and DispersionReference.dispersion_reference (test/dispersion_reference.jl, digits=15).

    • For large production systems (N >= 10^4): evaluate the exact same coordinates in Float64 precision with a converged 128 x 128 x 128 smooth PME / C²-ESP mesh (order=6, tight real_space_tolerance=1e-7, force_accumulation=:float64) via evaluate_configuration!.

  3. Evaluate the candidate Float32 / optimized configuration on the exact same frozen coordinates (evaluate_configuration!, testing both force_accumulation=:float32 and :fixed64, and both energy=false force-only and energy=true paths).

  4. Verify parity metrics:

    • Relative RMS force error: norm(F - F_ref) / norm(F_ref) — must match the target splitting/mesh tolerance (typically ~1e-4 to 5e-4 for production Float32 C²-ESP/PME, < 1e-5 for pure Float32 LJ, and < 1e-11 for Float64).

    • Net-force momentum neutrality: norm(sum(F; dims=2)) / norm(F_ref) (< 1e-6 for Float32, < 1e-13 for Float64).

    • Potential energy & virial agreement: |U - U_ref| / max(|U_ref|, 1) and norm(W - W_ref) / max(norm(W_ref), 1).

    • Exact equivalence against unfused baseline: When validating pure algorithmic optimizations (e.g., SLJP2, scatter-into-BAOAB fusion, CompactFFT, SMEM general constraints), compare Float32 candidate vs Float32 reference directly — expect ULP-level agreement (0 to a few ULPs, or bitwise identical under :fixed64).


3. Reproducible GPU Benchmarking Protocol ​

Standard Throughput Metric & Harness Rules ​

  1. Primary Metric: Report wall-clock steps/s (n_steps / elapsed_s, and ms/step = 1000 / steps_per_s). Never report single-step timings or un-synchronized launch times.

  2. Mandatory Warm-Up: Run at least 200-500 warm-up steps before timing so that:

    • All CUDA kernels compile (@cuda),

    • StateEngine captures single-step, batch, and NPT super-batch graphs (e.batches),

    • MeshTune completes its 40-step warm-up + 64-step alternating priority calibration (MESH_TUNE_WARM + 2 * MESH_TUNE_BLOCK * MESH_TUNE_ROUNDS = 104 fast launches), and

    • GPU clocks stabilize at steady-state boost frequency.

  3. Median of 3 Repeats: Measure 3 independent timed windows (e.g., 2,000-10,000 steps each via step_many! or run!(sim, Stage(...))) bracketed by CUDA.synchronize() before time_ns() start and stop. Report the median of the 3 repeats (and note min/max spread if > 1%).

  4. Equilibrium Sanity Gate: Every benchmark configuration MUST also pass a short physics sanity check confirming it did not drift or explode:

    • Mean kinetic temperature <T> within statistical error of T_target (checking kinetic_dof(st) accounts for all RigidWater and ConstraintClusters DOF),

    • Mean volume <V> and mass density <ρ> stable under NPT (DeviceCRescale or MonteCarloBarostatSpec),

    • Maximum constraint bond-length error (max |r_ij - d_ij|) within tolerance,

    • Zero latched errors (NL.device_neighbor_status(st.engine.run.neighbors).error == 0) and zero unexpected st.engine.recoveries in steady state.

julia
# Minimal reproducible timing skeleton
function benchmark_steps_per_sec(st, spec, dt; warmup=500, nsteps=5000, repeats=3)
    step_many!(st, spec, dt, warmup; compute_energy=false)
    CUDA.synchronize()
    rates = Float64[]
    for _ in 1:repeats
        CUDA.synchronize()
        t0 = time_ns()
        step_many!(st, spec, dt, nsteps; compute_energy=false)
        CUDA.synchronize()
        elapsed = (time_ns() - t0) * 1e-9
        push!(rates, nsteps / elapsed)
    end
    sort!(rates)
    return (median=rates[2], min=rates[1], max=rates[3])
end

Nsight Systems Graph Profiling (nsys) ​

Because DeviceEngine executes inside captured CUDA graphs and super-batches, always pass --cuda-graph-trace=node to NVIDIA Nsight Systems so individual kernel nodes inside each graph appear in the timeline and summary stats (instead of a single opaque cudaGraphLaunch bar):

bash
nsys profile \
  --trace=cuda,nvtx \
  --cuda-graph-trace=node \
  --force-overwrite=true \
  -o pd_profile \
  julia --project --startup-file=no my_benchmark.jl

# Inspect per-kernel GPU time breakdown from the captured trace:
nsys stats --report cuda_gpu_kern_sum pd_profile.nsys-rep

Use NVTX ranges around the timed window (CUDA.@profile or NVTX.@range "production") and set DeviceEngine.with_engine_config(batch_graph=...) to compare single-step vs K-step super-batch launch overhead directly in the timeline.


4. Verified v1.2.0 Benchmarks & Numerical Accuracy (NVIDIA GeForce RTX 3090) ​

Measured on an isolated NVIDIA GeForce RTX 3090 (Float32, :fixed64 force accumulation, :df64 rigid-water and solute constraints, Julia 1.13.4, clock-locked warmup, median of 3 replicates, reported in steps/s):

SystemAtomsConfigurationMeshThroughput (steps/s)
DHFR23,558LJPME 0.70 nm 5e-4, BAOAB (4 fs HMR)536³8,886
DHFR23,558LJPME 0.70 nm 5e-4, RESPA M=2 (4 fs HMR)536³9,640
DHFR23,558LJPME 0.70 nm 1e-4, BAOAB (4 fs HMR)636³8,157
DHFR23,558ESP 0.90 nm 5e-4, CSVR (4 fs HMR)527³9,147
BACE69,983LJPME 0.70 nm 5e-4, NPT-MC M=1 / M=2548³3,536 / 3,872
BACE69,983LJPME 0.70 nm 5e-4, NPT-CR M=1 / M=2548³3,686 / 3,997
ApoA192,224LJPME 0.70 nm 5e-4, BAOAB / RESPA M=2560³2,718 / 3,002
ApoA192,224ESP 0.90 nm 5e-4, CSVR (4 fs HMR)548³2,842
Water 100k100,002LJPME 0.70 nm 5e-4, BAOAB / NPT-CR (4 fs)554³3,175 / 3,122
Water Slab8,100LJPME 1.00 nm 1e-4 (2 fs, 4.5×4.5×16 nm)524×24×8415,184
Water 24k24,000LJPME 0.90 nm 1e-4, BAOAB / CSVR (2 fs)536³8,706 / 8,612

Rank-1 SVD Lorentz–Berthelot dispersion charges cut heterogeneous cross-term reciprocal error 15.6× (36.53% → 2.35%) and Float64 unwrapped coordinates hold displacement drift at to 4.75e-8 nm.


5. Cross-Engine Comparison (v1.2.0 vs. OPcuPO & GROMACS 2026.2, NVIDIA GeForce RTX 3090) ​

All throughput results below were measured on an isolated NVIDIA GeForce RTX 3090 (Float32, deterministic :fixed64 force accumulation, default B2ProlateWindow P=5 electrostatics, default :df64 SETTLE and ConstraintClusters, median of 5 repeats, steps/s, higher is faster) following the public NVIDIA/cuPotential (nv-openmm-plugin 0.3.5, denoted OPcuPO) biomolecular protocol (4 fs HMR 1.5 amu, rigid TIP3P SETTLE, HBonds ConstraintClusters, AMBER 1–4 scaling, barostat interval = 25) and the general-purpose 2 fs SPC/E water and 5 M NaCl protocol (298 K).

A. Truncated-LJ PME 0.90 nm — Biomolecular & 100k-Water Suite (M=1 Zero-MTS & M=2 RESPA) ​

System (Atoms, Mesh)ModeParticleDynamics v1.2.0 (steps/s)OPcuPO (M=1, steps/s)Ratio vs OPcuPO
dhfr (23,558, 27³)NVT (M=1) / NPT-MC (M=1) / NPT-CR (M=1)8,733 / 7,970 / 8,4759,219 / 8,346 / 8,346 (MC)0.95× / 0.95× / 1.02×
NVT (M=2 RESPA)9,1239,2190.99×
tyk2 (48,940, 36³)NVT (M=1) / NPT-MC (M=1) / NPT-CR (M=1)5,016 / 4,613 / 4,9425,502 / 4,800 / 4,800 (MC)0.91× / 0.96× / 1.03×
NVT (M=2 RESPA)5,2475,5020.95×
bace (69,983, 40³)NVT (M=1) / NPT-MC (M=1) / NPT-CR (M=1)3,744 / 3,479 / 3,7344,143 / 3,677 / 3,677 (MC)0.90× / 0.95× / 1.02×
NVT (M=2 RESPA)3,9374,1430.95×
apoa1 (92,224, 48³)NVT (M=1) / NPT-MC (M=1) / NPT-CR (M=1)2,818 / 2,632 / 2,7622,878 / 2,607 / 2,607 (MC)0.98× / 1.01× / 1.06×
NVT (M=2 RESPA)2,9902,8781.04×
water_100k (100,002, 42³)NVT (M=1) / NPT-MC (M=1) / NPT-CR (M=1)3,065 / 2,779 / 3,0423,219 / 2,837 / 2,837 (MC)0.95× / 0.98× / 1.07×
NVT (M=2 RESPA)3,2623,2191.01×

B. Full Lattice Dispersion LJPME 0.70 nm Suite (15 / 15 Faster than OPcuPO) ​

System (Atoms, Mesh)PD v1.2.0 NVT (M=1 / M=2, steps/s)PD v1.2.0 NPT-MC / NPT-CR (steps/s)OPcuPO NVT / NPT-MC (steps/s)Speedup vs OPcuPO (M=1 NVT / NPT-MC / NPT-CR)
dhfr (23,558, 36³)8,847 / 9,5577,999 / 8,3957,519 / 6,0341.18× / 1.33× / 1.39× (1.27× M2)
tyk2 (48,940, 42³)5,028 / 5,5284,696 / 4,8694,253 / 3,1931.18× / 1.47× / 1.52× (1.30× M2)
bace (69,983, 48³)3,744 / 4,1213,503 / 3,6823,385 / 2,8501.11× / 1.23× / 1.29× (1.22× M2)
apoa1 (92,224, 60³)2,718 / 3,0172,547 / 2,6452,313 / 1,9531.18× / 1.30× / 1.35× (1.30× M2)
water_100k (100,002, 54³)3,158 / 3,5962,907 / 3,1112,567 / 2,0431.23× / 1.42× / 1.52× (1.40× M2)

C. General-Purpose Liquids, Electrolytes & Pure LJ Suite (M=1, steps/s) ​

System & ModeParticleDynamics v1.2.0OPcuPOGROMACS 2026.2 GPUSpeedup vs OPcuPO / GROMACS
spce_water (30k, 0.90 nm) NVT BAOAB / CSVR8,596 / 8,6159,134 / —— / 5,0800.94× / 1.70×
spce_water (30k, 0.90 nm) NPT-MC / NPT-CR7,813 / 8,4517,930— / 4,8340.99× (1.07× CR) / 1.75×
spce_water (30k, 1.00 nm) NVT BAOAB / CSVR7,523 / 7,5196,549 / —— / 4,7541.15× / 1.58×
spce_water (30k, 1.00 nm) NPT-MC / NPT-CR6,826 / 7,3925,907— / 4,5471.16× (1.25× CR) / 1.63×
nacl_5m (31.8k, 0.90 nm) NVT BAOAB / CSVR8,017 / 8,0238,841 / —— / 4,6170.91× / 1.74×
nacl_5m (31.8k, 0.90 nm) NPT-MC / NPT-CR7,298 / 7,8837,785— / 4,4160.94× (1.01× CR) / 1.79×
nacl_5m (31.8k, 1.00 nm) NVT BAOAB / CSVR6,991 / 6,9736,393 / —— / 4,3531.09× / 1.60×
nacl_5m (31.8k, 1.00 nm) NPT-MC / NPT-CR6,337 / 6,8445,848— / 4,1801.08× (1.17× CR) / 1.64×
argon_10k NVE / NVT CSVR (:ell)45,832 / 33,85131,283 / —34,387 / 18,8851.47× / 1.33–1.79×
argon_100k NVE / NVT CSVR (:ell)8,215 / 7,3745,302 / —6,752 / 3,4201.55× / 1.22–2.16×

D. Single-Frame Force Accuracy vs. Exact 128³ Float64 Ewald (#1 on 6 / 6) ​

SystemParticleDynamics v1.2.0 rel_dFrel_dEOPcuPO rel_dFGROMACS 2026.2 rel_dFRank
argon_10k5.08e-62.25e-81.22e-59.84e-6#1
argon_100k1.34e-55.77e-82.61e-52.31e-5#1
spce_0901.98e-41.69e-63.23e-46.08e-4#1
spce_1001.53e-41.87e-63.52e-44.17e-4#1
nacl_0902.69e-41.75e-64.38e-46.74e-4#1
nacl_1002.03e-45.15e-84.18e-44.91e-4#1

ParticleDynamics v1.2.0 · GPU-native molecular dynamics in pure Julia · MIT License