File size: 2,792 Bytes
5338e3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
"""Primary machine verifier for the Claim 2 resolution evidence."""

from __future__ import annotations

import json
import sys
from pathlib import Path


MAX_FINAL_ERROR = 5e-4
MAX_REDUCTION_RATIO = 0.12
MAX_SLOPE = -1.25
MAX_REFERENCE_DISAGREEMENT = 5e-6
MAX_CONSTANT_RESIDUAL = 2e-11


def verify_payload(payload: dict) -> dict:
    failures: list[str] = []
    checked = 0
    for case in payload["cases"]:
        if case["reference"]["max_constant_residual"] > MAX_CONSTANT_RESIDUAL:
            failures.append(
                f"{case['density']}/{case['discretization']}/{case['kernel']}: reference constant residual"
            )
        if case["max_probe_constant_residual"] > MAX_CONSTANT_RESIDUAL:
            failures.append(
                f"{case['density']}/{case['discretization']}/{case['kernel']}: probe constant residual"
            )
        for record in case["signals"]:
            checked += 1
            label = (
                f"{case['density']}/{case['discretization']}/"
                f"{case['kernel']}/{record['signal']}"
            )
            if record["reference_stability"] > MAX_REFERENCE_DISAGREEMENT:
                failures.append(label + ": unstable reference")
            if record["signal"] == "constant":
                if record["final_error"] > MAX_CONSTANT_RESIDUAL:
                    failures.append(label + ": does not preserve constants")
                continue
            if record["final_error"] > MAX_FINAL_ERROR:
                failures.append(label + ": final uniform error too large")
            if record["reduction_ratio"] > MAX_REDUCTION_RATIO:
                failures.append(label + ": insufficient error reduction")
            if record["loglog_slope"] > MAX_SLOPE:
                failures.append(label + ": convergence slope too shallow")
    return {
        "verifier": "primary",
        "checked_signal_cases": checked,
        "thresholds": {
            "max_final_error": MAX_FINAL_ERROR,
            "max_reduction_ratio": MAX_REDUCTION_RATIO,
            "max_loglog_slope": MAX_SLOPE,
            "max_reference_disagreement": MAX_REFERENCE_DISAGREEMENT,
            "max_constant_residual": MAX_CONSTANT_RESIDUAL,
        },
        "pass": not failures,
        "failures": failures,
    }


def main() -> int:
    if len(sys.argv) != 3:
        raise SystemExit("usage: verify_resolution.py INPUT_JSON OUTPUT_JSON")
    payload = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8"))
    result = verify_payload(payload)
    Path(sys.argv[2]).write_text(
        json.dumps(result, indent=2) + "\n", encoding="utf-8"
    )
    print("PRIMARY_VERIFIER=" + json.dumps(result, sort_keys=True))
    return 0 if result["pass"] else 1


if __name__ == "__main__":
    raise SystemExit(main())