SPB Git

spb/wp30_uqo

Public
2.5 KB · 36 lines python
1"""Minimal reproduction profile: rerun a fixed small subset from a clean process and compare deterministic outputs2(greedy decoding) with the original records; rebuild analysis tables from raw records without inference."""3from __future__ import annotations4import json, yaml, subprocess, sys, shutil, time5from pathlib import Path6from .util import ROOT, read_jsonl, write_json, utc_now78def main(profile: str) -> int:9    prof = yaml.safe_load(open(profile))10    report = {"started_utc": utc_now(), "profile": prof, "steps": []}11    # 1. inference reproduction: run the profile config into a fresh experiment id, then compare predictions by trial key12    cfg_path = ROOT / prof["config"]; cfg = yaml.safe_load(open(cfg_path))13    orig = {r["trial_id"]: r for r in read_jsonl(ROOT / "runs/raw" / f"{cfg['experiment_id']}.jsonl")} if (ROOT / "runs/raw" / f"{cfg['experiment_id']}.jsonl").exists() else {}14    tmp_cfg = dict(cfg); tmp_cfg["experiment_id"] = cfg["experiment_id"] + "_repro"15    # keep trial keys identical: trial_key uses experiment_id -> compute keys with original id by passing an override16    tmp_cfg["trial_key_experiment_id"] = cfg["experiment_id"]17    tmp_path = ROOT / "reproduction" / "_repro_config.yaml"; yaml.safe_dump(tmp_cfg, open(tmp_path, "w"))18    out = ROOT / "runs/raw" / f"{tmp_cfg['experiment_id']}.jsonl"19    if out.exists(): out.unlink()20    t0 = time.time()21    rc = subprocess.call([sys.executable, "-m", "wp30", "run", "--config", str(tmp_path)], cwd=ROOT)22    rep = {r["trial_id"]: r for r in read_jsonl(out)}23    matched = sum(1 for k, r in rep.items() if k in orig and orig[k]["output_hash"] == r["output_hash"])24    compared = sum(1 for k in rep if k in orig)25    score_match = sum(1 for k, r in rep.items() if k in orig and json.dumps(orig[k]["task_scores"], sort_keys=True) == json.dumps(r["task_scores"], sort_keys=True))26    report["steps"].append({"step": "inference_rerun", "exit_code": rc, "seconds": time.time() - t0, "reran": len(rep), "compared_with_original": compared,27                            "identical_output_hash": matched, "identical_task_scores": score_match})28    # 2. analysis-only reproduction29    t0 = time.time()30    rc2 = subprocess.call([sys.executable, "-m", "wp30", "analyze", "--protocol", "protocol/frozen.json"], cwd=ROOT)31    report["steps"].append({"step": "analysis_rebuild", "exit_code": rc2, "seconds": time.time() - t0})32    report["finished_utc"] = utc_now()33    write_json(ROOT / "reproduction/report.json", report)34    print(json.dumps(report["steps"], indent=1))35    return 0 if rc == 0 and rc2 == 0 else 136
Files · 53ae960640251cd8de4e48bd47b17d011ba87dbe
Menu

Theme