Files
mcm-26-b/scripts/run_q3_seven_practice.py
T
2026-09-11 03:26:20 +08:00

54 lines
2.4 KiB
Python

"""Run SevenBatch on an already authorized official Q3 practice session.
Does not start a practice/formal test. All actions use the documented HTTP API.
"""
import argparse
from dataclasses import asdict, replace
from datetime import datetime
import hashlib
import json
from pathlib import Path
import time
from benchmark_q3_search import SevenBatch, seven_points
from mcm26b.config import ProblemConfig
from mcm26b.protocol.client import SimulatorClient
from mcm26b.protocol.log import SessionLog
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--robot-id", required=True)
parser.add_argument("--practice-confirmed", action="store_true", required=True)
parser.add_argument("--base-url", default="http://127.0.0.1:2026")
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
args.output.mkdir(parents=True, exist_ok=False)
config = ProblemConfig()
config = replace(config, session=replace(config.session, base_url=args.base_url))
root = Path(__file__).resolve().parents[1]
paths = [Path(__file__).resolve(), root / "scripts/benchmark_q3_search.py",
*sorted((root / "src/mcm26b").rglob("*.py"))]
metadata = {"source": "official_practice", "problem": 3,
"strategy": "seven_batch", "started_local": datetime.now().astimezone().isoformat(),
"config": asdict(config), "coverage_points": seven_points(),
"source_sha256": {str(p.relative_to(root)): hashlib.sha256(p.read_bytes()).hexdigest()
for p in paths}}
def save(name, value):
(args.output / name).write_text(json.dumps(value, ensure_ascii=False, indent=2,
allow_nan=False) + "\n", encoding="utf-8")
save("run_metadata.json", metadata)
log = SessionLog(path=args.output / "session.jsonl")
client = SimulatorClient(args.robot_id, config=config, log=log)
started = time.perf_counter()
summary = SevenBatch(client, config).run()
summary.update(robot_id=args.robot_id, strategy="seven_batch",
real_wall_s=time.perf_counter()-started)
save("summary.json", summary)
print(json.dumps(summary, ensure_ascii=False, indent=2))
return 0 if summary["completed"] and summary["exit_reason"] == "user_exit" else 1
if __name__ == "__main__":
raise SystemExit(main())