Datasets:
Download scripts/verify_bounded_witness_bundle.py from sungguk/visual-answerability: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/scripts/verify_bounded_witness_bundle.py
- Command line
-
hf download hf://datasets/sungguk/visual-answerability/scripts/verify_bounded_witness_bundle.py
-
curl -L -o verify_bounded_witness_bundle.py https://huggingface.co/datasets/sungguk/visual-answerability/resolve/main/scripts/verify_bounded_witness_bundle.py
2.53 kB
| #!/usr/bin/env python3 | |
| """Replay portable bounded PlotQA witnesses using direct semantic/pixel checks.""" | |
| from __future__ import annotations | |
| import argparse | |
| import gzip | |
| import json | |
| import sys | |
| import time | |
| from concurrent.futures import ProcessPoolExecutor | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | |
| from explicit_learning.certificates.bounded_plot import verify_bounded_plot as verify | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--proofs", type=Path, required=True) | |
| parser.add_argument("--output", type=Path, required=True) | |
| parser.add_argument("--workers", type=int, default=8) | |
| parser.add_argument("--limit", type=int) | |
| args = parser.parse_args() | |
| if args.workers < 1 or (args.limit is not None and args.limit < 1): | |
| parser.error("workers and limit must be positive") | |
| start = time.perf_counter() | |
| try: | |
| with gzip.open(args.proofs, "rt") as handle: | |
| rows = [json.loads(line) for line in handle if line.strip()] | |
| if args.limit: | |
| rows = rows[: args.limit] | |
| if not rows: | |
| raise ValueError("empty proof bundle") | |
| if any(not isinstance(row, dict) for row in rows): | |
| raise ValueError("proof records must be JSON objects") | |
| ids = [row.get("group_id") for row in rows] | |
| if any(not isinstance(value, str) or not value for value in ids): | |
| raise ValueError("nonempty string group IDs required") | |
| if len(ids) != len(set(ids)): | |
| raise ValueError("duplicate group IDs") | |
| except (OSError, ValueError, TypeError) as exc: | |
| parser.error(str(exc)) | |
| with ProcessPoolExecutor(max_workers=args.workers) as pool: | |
| results = list(pool.map(verify, rows, chunksize=1)) | |
| summary = { | |
| "rows": len(results), | |
| "passed": sum(row["ok"] for row in results), | |
| "failed": sum(not row["ok"] for row in results), | |
| "failures": [row for row in results if not row["ok"]], | |
| "sha_validation_performed": False, | |
| "wall_seconds": time.perf_counter() - start, | |
| "workers": args.workers, | |
| "scope": "fixed-axis complete rational PlotQA lookup worlds; conditional on question/program and renderer", | |
| } | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| args.output.write_text(json.dumps(summary, indent=2) + "\n") | |
| print(json.dumps(summary)) | |
| if summary["failed"]: | |
| raise SystemExit(1) | |
| if __name__ == "__main__": | |
| main() | |