Step 2 of the Python-first, declarative core. - core/spec/game.yaml: the game as data: every decision and its options, every roll and the earlier steps its odds may depend on, every bonding encounter, and the flow of a run from the entrance to the dragons (set / keep / drop / go / end / encounter). Also how the form's coded answers map onto the game. - core/atlas/model.py: what each coded run reveals about each step, count tables, empirical-Bayes shrinkage, and the posterior draws (same random numbers as before, reproducible from the seed). - core/atlas/solver.py: one interpreter of game.yaml used three ways (solve, evaluate a fixed policy, export the published tree) instead of the tree written out five times. Vectorised over the 200 posterior draws: the build takes about 2 minutes instead of 4, with no memory flag. - planner/build_policy.py and policy_report.py replace the JS build and report. Checked against the JavaScript model: every number in policy.json agrees to within 4e-12 (last-digit differences in log/cos). Three "still best" shares differ by one draw in 200, at near-ties under the "eventually" objective. POLICY.md is otherwise identical. tests/parity/compare_solver.py keeps checking JS against Python in CI until the site's JS advisor replaces solver.js; tests/core/test_game.py checks game.yaml is complete and consistent. Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
"""The Python route model (core/atlas/solver.py, built from core/spec/game.yaml) must give the same policy as the
|
|
JavaScript one the site and the bot still use (core/solver.js): same choices everywhere, same numbers.
|
|
|
|
A quick version for CI: one colour, both samples' coding, 3 posterior draws.
|
|
python tests/parity/compare_solver.py
|
|
"""
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "core"))
|
|
sys.path.insert(0, str(ROOT / "planner"))
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
import build_policy # noqa: E402
|
|
from atlas import solver # noqa: E402
|
|
from compare_policy import compare # noqa: E402
|
|
|
|
COLOURS, DRAWS = ["Blue"], 3
|
|
runs = build_policy.coded_runs(ROOT / "data/public/form_responses.json")
|
|
py = build_policy.clean(solver.build_policy(runs, draws=DRAWS, colours=COLOURS))
|
|
js = json.loads(subprocess.check_output(["node", "-e", f"""
|
|
const S=require('./core/solver.js'),E=require('./core/engine.js'),fs=require('fs');
|
|
const raw=JSON.parse(fs.readFileSync('data/public/form_responses.json'));const {{runs}}=E.codeRows(raw.rows,raw.headers);
|
|
console.log(JSON.stringify(S.buildPolicy(runs,{{draws:{DRAWS},colours:{json.dumps(COLOURS)}}})));"""], cwd=ROOT))
|
|
with tempfile.TemporaryDirectory() as d:
|
|
a, b = Path(d, "js.json"), Path(d, "py.json")
|
|
a.write_text(json.dumps(js))
|
|
b.write_text(json.dumps(py))
|
|
o = compare(a, b, 1e-9)
|
|
bad = o["keys"] + o["other"] + o["numbers"]
|
|
print(f"route model ({', '.join(COLOURS)}, {DRAWS} draws): " + ("ALL MATCH" if not bad else f"{len(bad)} DIFFER"), f"(largest relative difference {o['max']:.2g})")
|
|
for x in bad[:10]:
|
|
print(" ", x)
|
|
sys.exit(1 if bad else 0)
|