#!/usr/bin/env python3 """Gate iecell output against a sieve output (lagspec pairs1 / hist) cell by cell. Usage: gate4301.py -> JSON verdict on stdout. Every IE cell (a+b <= A) and every h_a (a <= A) must equal the sieve's value (absent in the sieve = 0), and D must match.""" import json, sys ie = json.load(open(sys.argv[1])); sv = json.load(open(sys.argv[2])) A = ie["A"] svp = {(a, b): c for a, b, c in sv["pairs1"]} iep = {(a, b): c for a, b, c in ie["pairs1"]} svh = {int(k): v for k, v in sv["hist"].items()} ieh = {int(k): v for k, v in ie["hist"].items()} bad = [] ncell = 0 for a in range(6, A + 1, 6): for b in range(6, A - a + 1, 6): ncell += 1 if iep.get((a, b), 0) != svp.get((a, b), 0): bad.append(["pair", a, b, iep.get((a, b), 0), svp.get((a, b), 0)]) nh = 0 for a in range(6, A + 1, 6): nh += 1 if ieh.get(a, 0) != svh.get(a, 0): bad.append(["hist", a, ieh.get(a, 0), svh.get(a, 0)]) print(json.dumps({"x": ie["x"], "A": A, "D_ie": ie["D"], "D_sieve": sv["D"], "D_equal": ie["D"] == sv["D"], "pair_cells_checked": ncell, "hist_cells_checked": nh, "nonzero_pair_cells_sieve": sum(1 for (a, b), c in svp.items() if a + b <= A and c), "mismatches": len(bad), "first_mismatches": bad[:10]}))