Spaces:
Running
Running
| """Primary verifier for paper-scale Armadillo evidence.""" | |
| from __future__ import annotations | |
| import json | |
| import math | |
| import sys | |
| from pathlib import Path | |
| EXPECTED_DATA_SHA256 = ( | |
| "8b9b56cc36e66d54429b1e1e75bd89e833645bfe0dc7c1afd1205877a7356a3f" | |
| ) | |
| def verify(payload: dict) -> dict: | |
| failures: list[str] = [] | |
| claim_status = {"1": True, "3": True, "4": True} | |
| if payload["data_source"]["sha256"] != EXPECTED_DATA_SHA256: | |
| failures.append("data hash") | |
| claim_status = {key: False for key in claim_status} | |
| if payload["mesh"]["vertex_count"] != 172974: | |
| failures.append("mesh vertex count") | |
| claim_status = {key: False for key in claim_status} | |
| if payload["mesh"]["face_count"] != 345944: | |
| failures.append("mesh face count") | |
| claim_status = {key: False for key in claim_status} | |
| if payload["sampling"]["count"] != 5000: | |
| failures.append("sample count") | |
| claim_status = {key: False for key in claim_status} | |
| for record in payload["kernels"]: | |
| label = record["kernel"] | |
| if record["final_max_mass_residual"] > 2e-10: | |
| failures.append(label + ": final residual") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| if not 5 <= record["iterations_to_mean_error_below_1e-3"] <= 10: | |
| failures.append(label + ": iteration gate") | |
| claim_status["3"] = False | |
| if not math.isfinite(record["minimum_log_operator_entry_lower_bound"]): | |
| failures.append(label + ": positivity") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| if record["top_eigenvalues"][-1] > 1.0 + 2e-9: | |
| failures.append(label + ": damping") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| if record["landmark_minimum_eigenvalue"] < -2e-11: | |
| failures.append(label + ": PSD") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| normalizations = { | |
| item["normalization"]: item | |
| for item in record["normalizations"] | |
| } | |
| if normalizations["sinkhorn"]["mass_max_error"] > 2e-10: | |
| failures.append(label + ": Sinkhorn mass") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| if ( | |
| normalizations["sinkhorn"]["self_adjoint_relative_error"] | |
| > 2e-12 | |
| ): | |
| failures.append(label + ": Sinkhorn self-adjointness") | |
| claim_status["1"] = False | |
| claim_status["4"] = False | |
| if normalizations["row"]["self_adjoint_relative_error"] < 1e-3: | |
| failures.append(label + ": row negative control") | |
| claim_status["4"] = False | |
| if normalizations["symmetric"]["mass_max_error"] < 1e-3: | |
| failures.append(label + ": symmetric negative control") | |
| claim_status["4"] = False | |
| return { | |
| "verifier": "primary_armadillo", | |
| "claim_status": claim_status, | |
| "pass": not failures, | |
| "failures": failures, | |
| } | |
| def main() -> int: | |
| if len(sys.argv) != 3: | |
| raise SystemExit("usage: verify_armadillo.py INPUT_JSON OUTPUT_JSON") | |
| payload = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) | |
| result = verify(payload) | |
| Path(sys.argv[2]).write_text( | |
| json.dumps(result, indent=2) + "\n", encoding="utf-8" | |
| ) | |
| print("ARMADILLO_PRIMARY_VERIFIER=" + json.dumps(result, sort_keys=True)) | |
| return 0 if result["pass"] else 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |