#!/usr/bin/env python3 """agreement.py -- cross-implementation agreement of job #2559's two producers and its checker. Reads the producer artefacts and the checker's claim file from the same run directory and prints one line per shared field, plus ALL FIELDS AGREE: True. Run from the run's parent directory: python /evidence/agreement.py # writes nothing; prints to stdout """ import json import os import sys R = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def load(*parts): with open(os.path.join(R, *parts), encoding="utf-8") as fh: return json.load(fh) prod = load("work", "transfacet.out.json") lift = load("work", "liftchain.out.json") chk = load("evidence", "claims-2559.json") plev = {r["x"]: r for r in prod["levels"]} plift = {p["pair"]: p for p in lift["pairs"]} print("Two independent implementations of the same object, same run dir.") print("producer: work/transfacet.py + work/liftchain.py (numpy mask sweep)") print("checker : evidence/check2559.py (separate file, re-entered with claims-2559.json)") print() ok = True for x, g in sorted(chk["gates"].items(), key=lambda kv: int(kv[0])): p = plev[int(x)] same = (g["cover0_plus1"] == p["cover0"] + 1 and g["cover2"] == p["cover2"] and g["max_plus1"] == p["max_plus1"] and g["argmax_count"] == p["argmax_count"]) ok &= same print("gate x=%-3s agree=%s cover0+1=%d cover2=%d max+1=%d argmax=%d" % (x, same, g["cover0_plus1"], g["cover2"], g["max_plus1"], g["argmax_count"])) for x, f in sorted(chk["facets"].items(), key=lambda kv: int(kv[0])): p = plev[int(x)] same = (f["low_size"] == p["low_div_family_size"] and f["low_max"] == p["low_div_max_cover"] and f["high_max"] == p["high_div_max_cover"]) ok &= same print("facet x=%-3s agree=%s low %d max %d (attained %d times) high %d max %d" % (x, same, f["low_size"], f["low_max"], f["low_max_count"], f["high_size"], f["high_max"])) for r in chk["lifts"]: p = plift[r["pair"]] same = (r["best_lift"] == p["best_lift_cover"] and r["attains"] == p["lift_attains_max_b"] and r["argmax_a_count"] == p["argmax_a_count"]) ok &= same print("lift %-7s agree=%s argmax_a=%d lifts %d (producer, low-facet filter) vs %d (complete)" % (r["pair"], same, r["argmax_a_count"], p["lifts_tested"], r["lifts_tested"])) print(" best_lift=%d target=%d attains=%s" % (r["best_lift"], r["target"], r["attains"])) print() print("ALL FIELDS AGREE:", ok) sys.exit(0 if ok else 1)