"""v2 step 2: compare two indexes (v2_index.py output) row by row, keyed on ms_id. Checks: same ms_id set, no ms_id twice, identical geometry hash for every ms_id, identical data.info hash, and energy/forces present and finite in the first index. usage: v2_compare.py [subset,...]""" import glob, sys, numpy as np from collections import Counter A, B = sys.argv[1], sys.argv[2]; subs = sys.argv[3].split(",") if len(sys.argv) > 3 else ["lemat", "mp20bat", "oc20", "oc22"] def load(d, s): Z = [np.load(f) for f in sorted(glob.glob(f"{d}/{s}__*.npz"))] cat = lambda k: np.concatenate([z[k] for z in Z]) ms, g, i, fl = cat("ms"), cat("geom"), cat("info"), cat("flags"); o = np.argsort(ms, kind="stable") return ms[o], g[o], i[o], fl[o], len(Z) ok = True for s in subs: ma, ga, ia, fa, na = load(A, s); mb, gb, ib, fb, nb = load(B, s) dupA, dupB = int((np.diff(ma) == 0).sum()), int((np.diff(mb) == 0).sum()) same = np.array_equal(ma, mb) print(f"{s}: A {len(ma)} rows / {na} shards, B {len(mb)} rows / {nb} shards; ms_id sets equal {same}; repeated ms_id A {dupA} B {dupB}") if not same: ok = False; print(" only in A", len(np.setdiff1d(ma, mb)), " only in B", len(np.setdiff1d(mb, ma))); continue gd, idf = int((ga != gb).sum()), int((ia != ib).sum()) print(f" geometry differs {gd}; info differs {idf}; A energy present {fa[:,0].mean():.6f} forces present {fa[:,1].mean():.6f} " f"energy finite {fa[:,2].mean():.6f} forces finite {fa[:,3].mean():.6f}; B energy present {fb[:,0].mean():.6f}") ok &= gd == 0 and dupA == 0 print("ALL OK" if ok else "*** MISMATCH ***")