#!/usr/bin/env python3 """Consolidated independent verification for job #1925. Cross-checks the streaming censuses (killcensus) against an independent, vectorised edge-list + scipy connected_components census, and against the explicit union-find census for the small tiles; re-derives the tile controls and the qualifying (kill-class) value lists with their weights; and reproduces the published numbers of returns #1910/#1021/#1023. Usage: verify_all.py """ import sys, json import numpy as np import census_indep as ci def a_plus(p): a = 2 while a % 6: a += p return a def qual(p, G2): return [(d, 2 if d % p == 0 else 1) for d in range(6, G2 + 1, 6) if d % p in (0, 2, p - 2)] def main(): out = sys.argv[1] res = {"tiles": {}, "folds": [], "published": {}} tiles = {} for x, f in [(23, "outputs/1925/t23_gaps.bin"), (29, "outputs/1925/t29_gaps.bin")]: g = np.fromfile(f, dtype=np.uint16) tiles[x] = g cen = json.load(open(f"outputs/1925/census_t{x}.json")) res["tiles"][str(x)] = {k: cen[k] for k in ("D", "sum_gaps", "min", "max", "ndistinct", "all_div6")} for x, p in [(23, 29), (23, 31), (23, 37), (29, 29), (29, 31), (29, 37)]: g = tiles[x] cen = json.load(open(f"outputs/1925/census_t{x}.json")) fold = [f for f in cen["folds"] if f["p"] == p][0] stream = {int(k): int(v) for k, v in fold["runs"].items()} runs_s, edges_s = ci.scipy_runs(g, p) runs_s = ci.runs_to_list(runs_s) row = {"x": x, "p": p, "stream_runs": stream, "scipy_runs": runs_s, "stream_edges": int(fold["edges"]), "scipy_edges": int(edges_s), "runs_match": runs_s == stream, "edges_match": int(edges_s) == int(fold["edges"]), "nodes_2D": int(fold["nodes"]) == 2 * int(g.size), "pairs_from_hist": int(fold["pairs_weight"])} if x == 23: runs_u, edges_u = ci.uf_runs(g, p) row["uf_runs"] = ci.runs_to_list(runs_u) row["uf_match"] = row["uf_runs"] == stream row["uf_edges_match"] = int(edges_u) == int(fold["edges"]) row["qualifying"] = qual(p, int(g.max())) row["pairs_sum_weights"] = sum(w * int((g == d).sum()) for d, w in row["qualifying"]) row["value1_hits"] = {str(d): int((g == d).sum()) for d, w in row["qualifying"]} row["weight1_total"] = sum(row["value1_hits"].values()) row["pairs_equals_edges"] = row["pairs_sum_weights"] == int(fold["edges"]) res["folds"].append(row) print(f"x={x} p={p}: scipy==stream {row['runs_match']} edges==pairs " f"{row['pairs_equals_edges']} nodes=2D {row['nodes_2D']}" + (f" uf==stream {row['uf_match']}" if x == 23 else "")) # published numbers by = {(r["x"], r["p"]): r for r in res["folds"]} def run(x, p, L): return by[(x, p)]["stream_runs"].get(L, 0) res["published"] = { "return_1910_T23_p29_j1_j2": [run(23, 29, 1), run(23, 29, 2)], "return_1910_T23_p31_j1_j2_j3": [run(23, 31, 1), run(23, 31, 2), run(23, 31, 3)], "return_1023_T29_p31_n1_n2_n3_n4": [run(29, 31, 1), run(29, 31, 2), run(29, 31, 3), run(29, 31, 4)], "return_1023_T29_p29_edges": by[(29, 29)]["stream_edges"], "return_1023_T29_p37_edges": by[(29, 37)]["stream_edges"], "return_1018_T23_p29_pairs": by[(23, 29)]["pairs_sum_weights"], "return_1018_T23_p29_weight1": by[(23, 29)]["weight1_total"], } with open(out, "w") as f: json.dump(res, f, indent=2) print(json.dumps(res["published"], indent=2)) ok = all(r["runs_match"] and r["edges_match"] and r["nodes_2D"] and r["pairs_equals_edges"] for r in res["folds"]) print("VERIFY", "PASS" if ok else "FAIL") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())