Notebooks · lib/hf/sweep
Sweeping array-valued strategies, and blaming the one that dissents
Every stage of the Hartree-Fock code has more than one implementation: McMurchie-Davidson, Obara-Saika and Rys for the electron repulsion integrals, in-core and direct J/K builds, several orthogonalizers. In debug mode a stage runs all of them on the same input and requires them to agree. Agreement between algorithms that share no code is strong evidence each one is right, and a disagreement names the one that is wrong.
The drivers here do that for strategies that return arrays. Each member of a registry runs, its result is flattened into one row of a table, and the consensus is the elementwise median of the rows. The member farthest from the median at any entry is blamed, together with the flat (row-major) index of that entry. The median matters: if the consensus were member 0's result, a bad member 0 would put the blame on every good member instead.
Deviation is relative, abs(v - median) / (1 + abs(median)), so a tolerance
reads as relative for large values and absolute for small ones.
Only the first ncmp entries are compared. An SCF result vector carries the
energy and densities first and then the iteration count; two correct
accelerators converge in different numbers of iterations, and comparing that
tail would fail on correct code. Past ncmp the result carries member 0's
values.
release_mode() runs member 0 only. The sw_check* variants never assert:
they return 1 when the members agree and 0 when they do not, so a test can
check that a planted bug is caught.
A Viv def is typed by the one registry signature it is called with (finding F4 of the contracts), so there is one driver per signature:
sweep3_arr members (Arr, Arr, Arr) -> Arr integrals, transforms, eigen
sweep5_arr members (Arr, Arr, Arr, Arr, Arr) -> Arr J/K
sweep3_num members (Arr, Arr, Arr) -> number
sweepnx_arr members (nmax, x) -> Arr Boys
N is the number of entries a member returns; Viv has no element-count
builtin. rep receives [strategy, flat index, worst, nstrat, lo, hi]; lo
and hi are reserved for the interval wave and stay 0.
The coverage counters at the end record which integral classes, Boys regions and SCF regimes each strategy has actually been exercised on, so a build can fail when a class was only ever checked by one strategy.
Used with import hf.sweep.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.