guldo-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. guldo/__init__.py +0 -0
  2. guldo/_src/COMPILER.md +329 -0
  3. guldo/_src/DEPLOY.md +200 -0
  4. guldo/_src/LAUNCH.md +85 -0
  5. guldo/_src/PROTOCOL.md +294 -0
  6. guldo/_src/RULES.md +25 -0
  7. guldo/_src/SUBMIT.md +170 -0
  8. guldo/_src/__init__.py +0 -0
  9. guldo/_src/attest.py +257 -0
  10. guldo/_src/build_site.py +958 -0
  11. guldo/_src/bundle_templates/check.py +1382 -0
  12. guldo/_src/bundle_templates/qcheck.py +253 -0
  13. guldo/_src/bundle_templates/qscore.py +402 -0
  14. guldo/_src/bundle_templates/score.py +649 -0
  15. guldo/_src/certificate.py +828 -0
  16. guldo/_src/certs_site.py +108 -0
  17. guldo/_src/claims.py +343 -0
  18. guldo/_src/compile_domain.py +1312 -0
  19. guldo/_src/compile_quality.py +286 -0
  20. guldo/_src/count_runner.py +248 -0
  21. guldo/_src/counted.py +274 -0
  22. guldo/_src/declared.py +215 -0
  23. guldo/_src/deploy/Caddyfile +48 -0
  24. guldo/_src/deploy/ledger-backup.service +9 -0
  25. guldo/_src/deploy/ledger-backup.sh +73 -0
  26. guldo/_src/deploy/ledger-backup.timer +10 -0
  27. guldo/_src/deploy/ledger-export.service +12 -0
  28. guldo/_src/deploy/ledger-export.timer +9 -0
  29. guldo/_src/deploy/ledger-web.service +38 -0
  30. guldo/_src/deploy/pin_cpu.sh +34 -0
  31. guldo/_src/deploy/provision_eval.sh +128 -0
  32. guldo/_src/deploy_smoke.py +148 -0
  33. guldo/_src/dlog_experiment.py +165 -0
  34. guldo/_src/domains/aidecode/compiled.json +586 -0
  35. guldo/_src/domains/aidecode/decl.py +134 -0
  36. guldo/_src/domains/aidecode/reference.py +73 -0
  37. guldo/_src/domains/aiinfer/compiled.json +722 -0
  38. guldo/_src/domains/aiinfer/decl.py +91 -0
  39. guldo/_src/domains/aiinfer/reference.py +42 -0
  40. guldo/_src/domains/dlog/compiled.json +248 -0
  41. guldo/_src/domains/dlog/decl.py +41 -0
  42. guldo/_src/domains/dlog/reference.py +10 -0
  43. guldo/_src/domains/maxcut/compiled.json +291 -0
  44. guldo/_src/domains/maxcut/decl.py +46 -0
  45. guldo/_src/domains/maxcut/reference.py +16 -0
  46. guldo/_src/drift_check.py +89 -0
  47. guldo/_src/export_bundle.py +750 -0
  48. guldo/_src/extrapolate.py +326 -0
  49. guldo/_src/families.py +53 -0
  50. guldo/_src/gen_cheat_table.py +36 -0
  51. guldo/_src/gpu_meter.py +634 -0
  52. guldo/_src/gpu_runner.py +63 -0
  53. guldo/_src/harness.py +273 -0
  54. guldo/_src/instances.py +86 -0
  55. guldo/_src/instances_factor.py +40 -0
  56. guldo/_src/instances_mlwe.py +69 -0
  57. guldo/_src/judge.py +278 -0
  58. guldo/_src/limits_plan.py +158 -0
  59. guldo/_src/official.py +189 -0
  60. guldo/_src/ops.py +281 -0
  61. guldo/_src/portal.py +313 -0
  62. guldo/_src/portal_core.py +57 -0
  63. guldo/_src/power.py +174 -0
  64. guldo/_src/prereg.py +173 -0
  65. guldo/_src/public_portal.py +500 -0
  66. guldo/_src/quality_core.py +126 -0
  67. guldo/_src/recheck.py +236 -0
  68. guldo/_src/remeasure.py +88 -0
  69. guldo/_src/report_html.py +493 -0
  70. guldo/_src/results/.keep +0 -0
  71. guldo/_src/rounds.py +846 -0
  72. guldo/_src/runner.py +52 -0
  73. guldo/_src/sandbox/Dockerfile +11 -0
  74. guldo/_src/sandbox/Dockerfile.v2 +19 -0
  75. guldo/_src/sandbox/README.md +40 -0
  76. guldo/_src/sandbox/linux_selftest.py +117 -0
  77. guldo/_src/sandbox/meter.py +89 -0
  78. guldo/_src/sandbox/meter_core.py +28 -0
  79. guldo/_src/site_assets.py +176 -0
  80. guldo/_src/site_live_check.py +79 -0
  81. guldo/_src/solvers/aidecode_flops_kv.py +73 -0
  82. guldo/_src/solvers/aidecode_flops_lossy.py +73 -0
  83. guldo/_src/solvers/aidecode_flops_ref.py +64 -0
  84. guldo/_src/solvers/aidecode_kv.py +76 -0
  85. guldo/_src/solvers/aidecode_kv_f32.py +77 -0
  86. guldo/_src/solvers/aidecode_lossy.py +76 -0
  87. guldo/_src/solvers/aidecode_repeat.py +5 -0
  88. guldo/_src/solvers/aiinfer_batched.py +40 -0
  89. guldo/_src/solvers/aiinfer_f32.py +41 -0
  90. guldo/_src/solvers/aiinfer_gpu_batched.py +42 -0
  91. guldo/_src/solvers/aiinfer_gpu_ref.py +45 -0
  92. guldo/_src/solvers/aiinfer_lossy.py +42 -0
  93. guldo/_src/solvers/baseline_bkz.py +14 -0
  94. guldo/_src/solvers/cheat_lookup.py +24 -0
  95. guldo/_src/solvers/cheat_table.json +1 -0
  96. guldo/_src/solvers/cheat_table_v1_stale.json +1 -0
  97. guldo/_src/solvers/daemon_cpu_hider.py +17 -0
  98. guldo/_src/solvers/dlog_bsgs.py +19 -0
  99. guldo/_src/solvers/dlog_stride4.py +18 -0
  100. guldo/_src/solvers/egg_base.py +11 -0
  101. guldo/_src/solvers/egg_eightaxis.py +68 -0
  102. guldo/_src/solvers/egg_template.py +11 -0
  103. guldo/_src/solvers/factor_brent.py +34 -0
  104. guldo/_src/solvers/factor_floyd.py +19 -0
  105. guldo/_src/solvers/factor_trial_fast_py.py +21 -0
  106. guldo/_src/solvers/factor_trial_np.py +21 -0
  107. guldo/_src/solvers/factor_trial_py.py +12 -0
  108. guldo/_src/solvers/fixed_overhead_ref.py +21 -0
  109. guldo/_src/solvers/fork_bomb.py +18 -0
  110. guldo/_src/solvers/gpu_noop.py +6 -0
  111. guldo/_src/solvers/hostile_probe.py +36 -0
  112. guldo/_src/solvers/kill_meter.py +27 -0
  113. guldo/_src/solvers/memory_bomb.py +10 -0
  114. guldo/_src/solvers/noop.py +5 -0
  115. guldo/_src/solvers/orphan_cpu_hider.py +16 -0
  116. guldo/_src/solvers/planted_peek.py +23 -0
  117. guldo/_src/solvers/sleeping_daemon_hang.py +12 -0
  118. guldo/_src/solvers/small_n_trick.py +22 -0
  119. guldo/_src/solvers/starter_template.py +21 -0
  120. guldo/_src/solvers/stdout_flood.py +9 -0
  121. guldo/_src/solvers/tmp_fill.py +10 -0
  122. guldo/_src/solvers/tuned_bkz.py +25 -0
  123. guldo/_src/static_check.py +214 -0
  124. guldo/_src/submit_check.py +166 -0
  125. guldo/_src/svp.py +889 -0
  126. guldo/_src/tensorops.py +304 -0
  127. guldo/_src/tflops.py +453 -0
  128. guldo/_src/tflops_runner.py +134 -0
  129. guldo/cli.py +60 -0
  130. guldo_cli-0.1.0.dist-info/METADATA +30 -0
  131. guldo_cli-0.1.0.dist-info/RECORD +134 -0
  132. guldo_cli-0.1.0.dist-info/WHEEL +5 -0
  133. guldo_cli-0.1.0.dist-info/entry_points.txt +2 -0
  134. guldo_cli-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env python3
2
+ """Tools for a QUALITY challenge (answers are scored, not the clock). Python standard library only; check.py supplies the sandbox, the CPU limits and the verifier.
3
+
4
+ python3 qcheck.py run --seed-file F --solver S.py --out LADDER.jsonl run a solver on every instance of the ladder, sandboxed; write the ladder qscore.py reads
5
+ python3 qcheck.py run --practice --solver S.py --out LADDER.jsonl the same on the public practice seed and sizes (no seed needed)
6
+ python3 qcheck.py verify --seed-file F --size N --idx I --answer JSON {"valid": ..., "quality": ...}; exit 0 if valid
7
+ python3 qcheck.py qrerun --seed-file F --solver S.py --claimed SUB.jsonl --baseline REF.jsonl [-k 5] [--sign KEY --attest-out FILE]
8
+ re-run a random sample of a CLAIMED result on this machine: do the claimed qualities reproduce?
9
+
10
+ Everything else (`info`, `selftest`, `commit`, `derive`, `keygen`, `attest-check`, `log`) is check.py's, and works on quality bundles. `run` and `qrerun` EXECUTE the solver file
11
+ in child processes with a CPU limit equal to the challenge's budget, inside an OS sandbox by default (no network, no writes outside a scratch directory, the seed and your
12
+ keys unreadable); where there is none they refuse unless you pass --sandbox off. It is not a proof of isolation. They also import and run decl.py's verify() and quality()
13
+ in this process: that is the bundle author's code (see check.py's WARNING).
14
+ """
15
+ import argparse
16
+ import hashlib
17
+ import json
18
+ import os
19
+ import statistics
20
+ import sys
21
+ import tempfile
22
+
23
+ HERE = os.path.dirname(os.path.abspath(__file__))
24
+ sys.path.insert(0, HERE)
25
+
26
+ import check as C # noqa: E402
27
+ import qscore as QS # noqa: E402
28
+
29
+ DEFAULT_TOLERANCE = 0.05 # quality points the median claimed-vs-re-measured gap may reach: a randomised solver does not reproduce its own answers exactly
30
+
31
+
32
+ def manifest():
33
+ ch = C.manifest()
34
+ if ch.get("metric") != "quality":
35
+ raise SystemExit("this bundle is a SPEED challenge: use check.py")
36
+ return ch
37
+
38
+
39
+ def solver_scratch(a, deny):
40
+ """-> (prefix, scratch dir). The sandbox runs the solver; no sandbox and no --sandbox off means refuse."""
41
+ import atexit
42
+ import shutil
43
+ scratch = os.path.realpath(tempfile.mkdtemp(prefix="qrun-"))
44
+ atexit.register(shutil.rmtree, scratch, True)
45
+ prefix, why_not = C.working_sandbox(a.sandbox, deny, scratch)
46
+ if prefix is None:
47
+ raise SystemExit("no sandbox is available here (needs macOS sandbox-exec or Linux bwrap" + (f"; the tool exists but cannot run: {why_not}" if why_not else "")
48
+ + "). To run the solver anyway, unsandboxed, as you, pass --sandbox off (only for a solver you have read).")
49
+ return prefix, scratch
50
+
51
+
52
+ def score_run(decl, inst, run):
53
+ """One solver run -> (status, quality). The record's status follows the guldo ladder statuses; anything but a verified answer scores 0."""
54
+ status, ans, cpu, err = run
55
+ if status == "timeout":
56
+ return "timeout", 0.0
57
+ if status != "ran":
58
+ return "crash", 0.0
59
+ try:
60
+ valid, q = C.quality_of(decl, inst, ans)
61
+ except ValueError as e:
62
+ raise SystemExit(f"the declaration is defective, not the solver: {e}")
63
+ if not valid:
64
+ return ("failed" if ans is None else "wrong"), 0.0
65
+ return "solved", q
66
+
67
+
68
+ def over_budget(run, overhead, cap):
69
+ """The solver's CPU past the budget by more than the meter's slack: an answer that came after the cap does not count."""
70
+ return run[2] - overhead > cap * 1.02 + 0.1
71
+
72
+
73
+ def cmd_run(a):
74
+ ch = manifest()
75
+ decl = C.load_decl()
76
+ master = C.master_from(a)
77
+ cap = ch["ladder"]["budget_seconds"]
78
+ sizes = ch["ladder"]["practice_dims"] if a.practice else ch["ladder"]["dims"]
79
+ n = a.n if a.n else (3 if a.practice else ch["ladder"]["n"])
80
+ if a.out and os.path.exists(a.out):
81
+ raise SystemExit(f"{a.out} exists: this tool never overwrites")
82
+ prefix, scratch = solver_scratch(a, [a.seed_file])
83
+ print(f"solver {os.path.basename(a.solver)} sha256 {C.sha256_file(a.solver)[:16]}...; " + ("sandboxed" if prefix else "UNSANDBOXED: the solver runs as you")
84
+ + f"; budget {cap} s per instance; {len(sizes)} sizes x {n} instances" + (" (PRACTICE: not a challenge ladder)" if a.practice or a.n else ""))
85
+ overhead = C.solver_overhead(os.path.join(scratch, "noop.py"), prefix, scratch)
86
+ lines = [json.dumps({"meta": True, "commit": hashlib.sha256(master).hexdigest(), "budget": cap})]
87
+ for size in sizes:
88
+ qs, counts = [], {}
89
+ for idx in range(n):
90
+ inst = C.instance(decl, master, size, idx)
91
+ run = C.run_solver(a.solver, inst["args"], cap, prefix, scratch)
92
+ status, q = score_run(decl, inst, run)
93
+ if status == "solved" and over_budget(run, overhead, cap):
94
+ status, q = "timeout", 0.0
95
+ if status == "solved" and C.hides_cpu(run, run[2]):
96
+ status, q = "crash", 0.0 # waits or forks its work where the CPU meter cannot see it: the budget cannot be enforced, so the answer does not count
97
+ print(f" {size}:{idx}: over a second of wall time but under 30% of it as CPU: the budget cannot be enforced on this run; scored 0")
98
+ counts[status] = counts.get(status, 0) + 1
99
+ qs.append(q)
100
+ lines.append(json.dumps({"id": inst["id"], "dim": size, "status": status, "quality": round(q, 6), "cpu": round(run[2], 3)}))
101
+ print(f" size {size}: mean quality {statistics.fmean(qs):.4f} ({', '.join(f'{k} {v}' for k, v in sorted(counts.items()))})")
102
+ if a.out:
103
+ with open(a.out, "x", encoding="utf-8") as f:
104
+ f.write("\n".join(lines) + "\n")
105
+ print(f"wrote {a.out}")
106
+ return 0
107
+
108
+
109
+ def cmd_verify(a):
110
+ ch = manifest()
111
+ bad = C.size_idx_problem(ch, a.size, a.idx)
112
+ if bad:
113
+ raise SystemExit(bad)
114
+ decl = C.load_decl()
115
+ inst = C.instance(decl, C.master_from(a), a.size, a.idx)
116
+ try:
117
+ valid, q = C.quality_of(decl, inst, C.read_answer(a.answer))
118
+ except ValueError as e:
119
+ raise SystemExit(f"the declaration is defective: {e}")
120
+ print(json.dumps({"valid": valid, "quality": q}))
121
+ return 0 if valid else 1
122
+
123
+
124
+ def ladder_qualities(path, master, ch):
125
+ """{id: quality} of a ladder, refusing one run on a different seed than `master`."""
126
+ try:
127
+ meta, by_dim, _, _, _ = QS.load_ladder(path, ch["ladder"]["budget_seconds"])
128
+ except QS.Refused as e:
129
+ raise SystemExit(f"REFUSED: {e}")
130
+ commit = meta.get("commit")
131
+ if commit is not None and commit != hashlib.sha256(master).hexdigest():
132
+ raise SystemExit(f"{path} was run on a different seed (its commitment is not this seed's sha256)")
133
+ return {i: q for d in by_dim for i, q in by_dim[d].items()}
134
+
135
+
136
+ def cmd_qrerun(a):
137
+ """Re-run a random sample of a claimed result on THIS machine with THIS verifier's own choice of instances, and compare the claimed qualities (solver AND reference)
138
+ with the re-measured ones. A quality typed into a ladder, or a baseline weakened to inflate the gap, shows as a difference."""
139
+ import random
140
+ try:
141
+ import resource # noqa: F401
142
+ except ImportError:
143
+ raise SystemExit("qrerun needs a POSIX system (resource limits)")
144
+ ch = manifest()
145
+ decl = C.load_decl()
146
+ master = C.master_from(a)
147
+ cap = ch["ladder"]["budget_seconds"]
148
+ base, claimed = ladder_qualities(a.baseline, master, ch), ladder_qualities(a.claimed, master, ch)
149
+ ids = sorted(set(base) & set(claimed))
150
+ if not ids:
151
+ raise SystemExit("the two ladders share no instance: nothing to re-run")
152
+ sample_seed = a.sample_seed or os.urandom(8).hex()
153
+ chosen = random.Random(sample_seed).sample(ids, min(a.k, len(ids)))
154
+ print(f"sample seed {sample_seed} (an independent verifier picks their own; the operator must not know it in advance): {len(chosen)} of {len(ids)} instances")
155
+ secret = C.read_key(a.sign) if a.sign else None
156
+ if a.sign and not a.attest_out:
157
+ raise SystemExit("--sign needs --attest-out FILE")
158
+ if a.attest_out and os.path.exists(a.attest_out):
159
+ raise SystemExit(f"{a.attest_out} exists: this tool never overwrites")
160
+ solver_sha = C.sha256_file(a.solver)
161
+ prefix, scratch = solver_scratch(a, [a.seed_file, a.sign])
162
+ print(f"solver {os.path.basename(a.solver)} sha256 {solver_sha[:16]}...; " + ("sandboxed" if prefix else "UNSANDBOXED: the solver runs as you"))
163
+ overhead = C.solver_overhead(os.path.join(scratch, "noop.py"), prefix, scratch)
164
+ ref_path = os.path.join(C.ROOT, ch["reference"]["file"])
165
+ rows, hidden, over = [], [], []
166
+ for iid in chosen:
167
+ size, idx = (int(x) for x in iid.split(":"))
168
+ inst = C.instance(decl, master, size, idx)
169
+ rr, sr = (C.run_solver(p, inst["args"], cap, prefix, scratch) for p in (ref_path, a.solver))
170
+ (rst, rq), (sst, sq) = score_run(decl, inst, rr), score_run(decl, inst, sr)
171
+ if sst == "solved" and C.hides_cpu(sr, sr[2]):
172
+ hidden.append(iid)
173
+ if sst == "solved" and over_budget(sr, overhead, cap):
174
+ over.append(iid)
175
+ rows.append((iid, claimed[iid], sq, base[iid], rq, sst))
176
+ print(f" {iid:>8}: solver claimed {claimed[iid]:.3f}, re-measured {sq:.3f} ({sst}); reference claimed {base[iid]:.3f}, re-measured {rq:.3f} ({rst})")
177
+ if sst not in ("solved", "wrong", "failed") and sr[3]:
178
+ print(f" solver stderr: {sr[3]}" + (" <- the sandbox probably blocked something the solver tried to do" if any(w in sr[3] for w in C.DENIAL_WORDS) else ""))
179
+ solver_gaps = [abs(c - n) for _, c, n, _, _, _ in rows]
180
+ base_gaps = [abs(c - n) for _, _, _, c, n, _ in rows]
181
+ inflated = statistics.fmean(c - n for _, c, n, _, _, _ in rows)
182
+ ok = not hidden and not over and statistics.median(solver_gaps) <= a.tolerance and statistics.median(base_gaps) <= a.tolerance
183
+ print(f"median |claimed - re-measured|: solver {statistics.median(solver_gaps):.3f}, reference {statistics.median(base_gaps):.3f} quality points (tolerance {a.tolerance:g}); "
184
+ f"the solver's claims are {inflated:+.3f} on average above what re-ran here")
185
+ if hidden:
186
+ print(f"FAIL: on {sorted(set(hidden))} the solver ran over a second of wall time but its CPU is under 30% of it: it waits, or its work runs where the CPU meter cannot see it, "
187
+ "so the budget cannot be enforced and the claimed quality is not confirmed")
188
+ if over:
189
+ print(f"FAIL: on {sorted(set(over))} the solver used more CPU than the {cap} s budget here; those answers would not count")
190
+ if statistics.median(base_gaps) > a.tolerance:
191
+ print("FAIL: the REFERENCE's re-measured qualities differ from the baseline ladder's: the baseline was not produced by this reference on this seed, or the reference is randomised")
192
+ print("QRERUN " + ("PASS: the sampled claims reproduce" if ok else "FAIL"))
193
+ if secret:
194
+ import platform
195
+ import time
196
+ statement = {
197
+ "format": C.ATTEST_FORMAT, "kind": "qrerun",
198
+ "challenge": {"name": ch["name"], "version": ch["version"], "challenge_json_sha256": C.sha256_file(os.path.join(C.ROOT, "challenge.json"))},
199
+ "solver_sha256": solver_sha, "claimed_sha256": C.sha256_file(a.claimed), "baseline_sha256": C.sha256_file(a.baseline),
200
+ "seed_commit": hashlib.sha256(master).hexdigest(), "sample_seed": sample_seed, "k": len(chosen), "tolerance_quality": a.tolerance,
201
+ "sandboxed": bool(prefix), "outcome": "PASS" if ok else "FAIL", "median_gap_quality": round(statistics.median(solver_gaps), 4),
202
+ "instances": [{"id": r[0], "claimed_quality": round(r[1], 4), "remeasured_quality": round(r[2], 4), "baseline_claimed": round(r[3], 4), "baseline_remeasured": round(r[4], 4),
203
+ "solver_status": r[5]} for r in rows],
204
+ "machine": {"platform": platform.platform(), "python": platform.python_version(), "processor": platform.processor() or platform.machine()},
205
+ "time_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}
206
+ C.write_attestation(a.attest_out, statement, secret)
207
+ return 0 if ok else 1
208
+
209
+
210
+ def main(argv=None):
211
+ ap = argparse.ArgumentParser(description=__doc__.split("\n")[0], formatter_class=argparse.RawDescriptionHelpFormatter, epilog=__doc__)
212
+ sub = ap.add_subparsers(dest="cmd", required=True)
213
+ sandbox_help = "auto (default): run the solver without network, without writes outside a scratch directory and without reading the seed or keys, or refuse if the system has no sandbox; off: run it as you"
214
+ p = sub.add_parser("run")
215
+ p.add_argument("--seed-file")
216
+ p.add_argument("--practice", action="store_true")
217
+ p.add_argument("--solver", required=True)
218
+ p.add_argument("--out", help="the ladder to write (never overwrites); without it the per-size summary is only printed")
219
+ p.add_argument("--n", type=C.int_arg(1, 1000), help="instances per size (default: the challenge's; 3 with --practice). Anything but the default is NOT a challenge ladder")
220
+ p.add_argument("--sandbox", choices=["auto", "off"], default="auto", help=sandbox_help)
221
+ p = sub.add_parser("verify")
222
+ p.add_argument("--seed-file")
223
+ p.add_argument("--practice", action="store_true")
224
+ p.add_argument("--size", type=C.int_arg(-10 ** 12, 10 ** 12), required=True)
225
+ p.add_argument("--idx", type=C.int_arg(-10 ** 12, 10 ** 12), required=True)
226
+ p.add_argument("--answer", required=True)
227
+ p.add_argument("--sandbox", choices=["auto", "off"], default="auto", help="auto: re-run this command inside the OS sandbox, because it runs decl.py (the author's code)")
228
+ p = sub.add_parser("qrerun")
229
+ p.add_argument("--seed-file")
230
+ p.add_argument("--practice", action="store_true")
231
+ p.add_argument("--solver", required=True)
232
+ p.add_argument("--claimed", required=True, help="the claimed ladder of that solver")
233
+ p.add_argument("--baseline", required=True, help="the claimed ladder of the reference on the same seed")
234
+ p.add_argument("-k", type=C.int_arg(1, 1000), default=5, help="instances to re-run (1..1000, default 5)")
235
+ p.add_argument("--sample-seed", help="fix the sample (default: random, printed)")
236
+ p.add_argument("--tolerance", type=C.float_arg(0, 1), default=DEFAULT_TOLERANCE, help=f"quality points the median claimed-vs-re-measured gap may reach (default {DEFAULT_TOLERANCE})")
237
+ p.add_argument("--sandbox", choices=["auto", "off"], default="auto", help=sandbox_help)
238
+ p.add_argument("--sign", metavar="KEYFILE", help="sign the outcome as an attestation (check.py keygen); needs --attest-out")
239
+ p.add_argument("--attest-out", metavar="FILE")
240
+ a = ap.parse_args(argv)
241
+ if a.cmd == "verify" and a.sandbox == "auto":
242
+ code = C.reexec_sandboxed(argv if argv is not None else sys.argv[1:], os.path.abspath(__file__))
243
+ if code is not None:
244
+ return code
245
+ try:
246
+ return {"run": cmd_run, "verify": cmd_verify, "qrerun": cmd_qrerun}[a.cmd](a)
247
+ except C.FileRefused as e:
248
+ print(f"REFUSED: {e}", file=sys.stderr)
249
+ return 1
250
+
251
+
252
+ if __name__ == "__main__":
253
+ sys.exit(main())