Skip to the content.

Accuracy golden-master regression tests

Fixed experiments whose diffusion signals are frozen as baselines, so any change elsewhere in the code can be checked for “does it still produce the same physics?”. These are also the reference a future GPU / re-implementation is validated against.

All fixtures are self-contained and tracked under tests/accuracy/ (meshes in meshes/, the PGSE scheme, the configs and list) — nothing depends on the gitignored debug/ directory, so the suite works on a clean checkout.

Experiment 1 — sphere_impermeable.conf

Experiment 2 — two_meshes_impermeable.conf (stress)

To validate the per-compartment assignment directly, add the debug flag (presence-only — just the word debug on its own line; there is no debug 1, and debug 0 would NOT turn it off — remove the line to disable). The simulator then writes a per-process *_debug_trace.txt logging, for every walker and step, walker step x y z location compartment Di T2 (position in mm, Di in mm²/ms, T2 in ms; the model has no T1). Each row’s Di/T2 should match the compartment in the compartment column (e.g. ply0, ply1, extra). The file is large, so it is only written when debug is present.

PLY list options

The geometry scale is mandatory in every form (it has no global default).

Captured outputs (the actual scientific signal, 270 PGSE measurements each): *_DWI.txt (real), *_DWI_intra.txt, *_DWI_extra.txt, stored in golden/.

Experiment 3 — permeable_sphere.conf (Powles permeability)

A single permeable sphere with DISTINCT intra/extra diffusivities (Di=0.5e-9, De=2.0e-9 m²/s) and κ=1e-4 m/s, seeded uniformly in a tight voxel (num_process 1 for exact, race-free counters). The directional crossing counters (<prefix>_perm_counters.txt) give the empirical per-encounter probability p̂ = crossings / hits, which tests/test_permeability_powles.py checks against the prescribed prob_cross_{i→e,e→i} within 6σ, and confirms the two prescribed probabilities are distinct (directional, since Di≠De).

This validates that the Powles probabilities are applied correctly — an implementation sanity check on easy (smooth-sphere) geometry, not a physical benchmark of the model on complex meshes (that’s the future S/V-adjusted model). Run it with python3 tests/test_permeability_powles.py (or ctest -R accuracy_permeability).

Experiments 4 & 5 — native Sphere / Cylinder (*_hex_impermeable.conf)

The mesh goldens above validate the PLY collision path. These two validate the simulator’s native analytic obstacles, which have entirely separate collision code (sphere.cpp, cylinder.cpp):

Both: radius 5e-6, icvf 0.5 (the hex packing builds the arrangement and sets the voxel automatically — no <voxels> block), impermeable, walkers init intra → restricted diffusion, extra signal ~0 (leak detector). Same golden harness: python3 tests/test_accuracy_golden.py --conf tests/accuracy/sphere_hex_impermeable.conf (or ctest -R accuracy_golden_sphere_hex / accuracy_golden_cylinder_hex).

Running

# all accuracy + reproducibility tests
ctest --test-dir build

# experiment 1 (default conf) against the committed golden
python3 tests/test_accuracy_golden.py

# experiment 2 (two meshes)
python3 tests/test_accuracy_golden.py --conf tests/accuracy/two_meshes_impermeable.conf

# loosen tolerance, e.g. when comparing a GPU port or a different compiler
python3 tests/test_accuracy_golden.py --rtol 1e-4

# regenerate a baseline after an INTENTIONAL, reviewed behaviour change
python3 tests/test_accuracy_golden.py [--conf <conf>] --update

Comparison is |run - golden| <= atol + rtol*|golden| per value (defaults rtol=1e-9, atol=1e-12 — effectively bit-identical on the same build). The test reports the worst absolute and relative deviation per signal.

When the baseline legitimately changes

num_process 2 makes the run reproducible only for that process count (see the seed warning in SimErrno::checkSimulationParameters). Any intentional physics change that alters this impermeable signal — regenerate with --update and call it out explicitly in the commit. A change you did not expect to move the signal failing here is the test doing its job.