File size: 2,533 Bytes
e1ced61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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()