2"""Compare two prof.py --dump files array by array (the VoF step-performance harness, WO-0).
4Usage: python tests/study/vof_perf/cmp.py a.npz b.npz
6One line per array (u, v, w, p, C, dts, iters, and every block colour col<id>): bitwise
7equality, max|a-b| and max|a-b|/max|a|. An array present in only one file prints bitwise=False.
8The last line is max over u, v, w, p, C of the relative difference -- N50_rtol when a is the
9rtol 1e-10 dump and b the 1e-9 one (doc/vof_step_performance_design.md sec. 8, G-NUM item 1).
10Exit status 0 only if every array is bitwise equal (G-BIT item 2), 1 otherwise.
16a, b = np.load(sys.argv[1]), np.load(sys.argv[2])
19for k
in list(a.files) + [k
for k
in b.files
if k
not in a.files]:
20 if k
not in a.files
or k
not in b.files:
21 print(f
"{k:4s} bitwise=False only in {'b' if k in b.files else 'a'}")
25 same = x.shape == y.shape
and x.dtype == y.dtype
and x.tobytes() == y.tobytes()
26 d = float(np.max(np.abs(x.astype(np.float64) - y)))
if x.shape == y.shape
else float(
'nan')
27 sc = float(np.max(np.abs(x)))
or 1.0
28 print(f
"{k:4s} bitwise={same} max|diff|={d:.3e} rel={d/sc:.3e}")
29 all_same = all_same
and same
30 if k
in (
"u",
"v",
"w",
"p",
"C"):
31 worst = max(worst, d / sc)
32print(f
"max rel over u v w p C = {worst:.3e} all bitwise={all_same}")
33sys.exit(0
if all_same
else 1)