"""Floor-to-ceiling method comparison: the keynote figure. Two stages so the data is inspectable before it's drawn: 1. build -> out/plots/floor_ceiling.csv (one row per arm/anchor, with SOURCE and STATUS columns; every provisional/missing value is flagged, not silently filled) 2. plot -> out/plots/floor_ceiling.{pdf,png} Run `uv run python -m scripts.plot_floor_ceiling` to do both; it prints a TODO/FIXME summary of any provisional or missing cells before plotting. THE GOAL: place each gradient-routing arm on a floor->ceiling scale so "how much of the achievable range did it capture" is read at a glance, and show that the quarantine (knob) is what removes the hack, not a train/test artifact. TWO METRICS, two anchor pairs (right/down = better): hack removed = (vanilla_hack - arm_hack) / vanilla_hack 1.0 = no hack solve recovered = (arm_solve - base_solve) / (ceiling - base_solve) 1.0 = no-loophole ceiling TWO VIEWS of the same arms: A. normalized floor->ceiling bars, HEADLINE deploy (knob-off, test n=119, recency-clean). Source per arm: out/runs//deploy_test.json. B. the KNOB effect: arrow knob-ON -> knob-OFF on the SAME held-out val split (n=32), so it isolates the quarantine from the train/test memorization gap. Source per arm: out/runs//eval_curve.jsonl, where the file's `train_*`/`deploy_*` prefixes denote KNOB STATE (on/off), not the problem set (always val here). L5 = mean of last 5 evals. DATA GAPS (see STATUS column in the csv): - solve ceiling: provisional = paper 0.223 until job 24 (out/runs/*noloophole*) lands. FIXME. - prog_wide arm uses contaminated pairs; job 28 (prog_wide_clean) will replace it. TODO. - full-env (paper-scale) panel: no method runs exist, only paper anchors. Out of scope here. """ from __future__ import annotations import json from pathlib import Path import polars as pl import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt RED, GREEN, GREY = "#c0392b", "#1e8449", "#9aa0a6" RUNS = Path("out/runs") OUT = Path("out/figs") CSV = OUT / "floor_ceiling.csv" PAPER_CEILING = 0.223 # Ariahw et al. no-loophole solve -- provisional fast-env ceiling # arm display order, identified by a substring of the run's out_tag (seed-43 fast runs) ARMS = [ ("routeV per-token", "_dir6_routeV_pertoken_s43", "ok"), ("routeV authored", "_dir8_routeV_authored_perroll_s43", "ok"), ("routeV prog_wide", "_dir6_routeV_s43", "TODO: contaminated pairs -> job 28 prog_wide_clean"), ("routeV random-V", "_dir6_routeV_random_s43", "ok (directionality control)"), ("vanilla GRPO", "_dir8_vanilla_s43", "ok (defines hack-worst anchor)"), ] def _find_run(tag: str) -> Path: cands = sorted(d for d in RUNS.iterdir() if d.name.endswith(tag) and (d / "deploy_test.json").exists()) if not cands: raise FileNotFoundError(f"no run dir ending '{tag}' with a deploy_test.json") return cands[-1] # latest timestamp wins def _l5(rows: list[dict], k: str) -> float: v = [r[k] for r in rows[-5:]] return sum(v) / len(v) # ── stage 1: build the inspectable csv ────────────────────────────────────── def build_csv() -> pl.DataFrame: rows = [] for label, tag, status in ARMS: run = _find_run(tag) dep = json.loads((run / "deploy_test.json").read_text()) ev = [json.loads(l) for l in (run / "eval_curve.jsonl").read_text().splitlines()] rows.append(dict( label=label, kind="method", hack_deploy=round(dep["deploy_hack"], 4), solve_deploy=round(dep["deploy_solve"], 4), hack_on=round(_l5(ev, "train_hack"), 4), hack_off=round(_l5(ev, "deploy_hack"), 4), solve_on=round(_l5(ev, "train_solve"), 4), solve_off=round(_l5(ev, "deploy_solve"), 4), source=f"{run.name}/[deploy_test.json + eval_curve.jsonl]", status=status)) base = json.loads((_find_run("_dir8_baseline_s43") / "deploy_test.json").read_text()) rows.append(dict(label="base (floor)", kind="anchor_floor", hack_deploy=round(base["deploy_hack"], 4), solve_deploy=round(base["deploy_solve"], 4), hack_on=None, hack_off=None, solve_on=None, solve_off=None, source="*_dir8_baseline_s43/deploy_test.json", status="ok (base model; steps=0)")) ceil_path = next(RUNS.glob("*noloophole*/deploy_test.json"), None) if ceil_path: ceil_solve, status = round(json.loads(ceil_path.read_text())["deploy_solve"], 4), "ok" source = f"{ceil_path.parent.name}/deploy_test.json" else: ceil_solve, status = PAPER_CEILING, "FIXME: PROVISIONAL paper 0.223 -- awaiting job 24 (no-loophole ceiling)" source = "Ariahw et al. 2025 (paper), NOT our run" rows.append(dict(label="ceiling", kind="anchor_ceiling", hack_deploy=0.0, solve_deploy=ceil_solve, hack_on=None, hack_off=None, solve_on=None, solve_off=None, source=source, status=status)) df = pl.DataFrame(rows) OUT.mkdir(parents=True, exist_ok=True) df.write_csv(CSV) return df # ── stage 2: plot from the csv ────────────────────────────────────────────── # The reference paper (Ariahw et al. 2025) IS the axis: its No-Intervention run (hack ~79%) is # the floor and its no-loophole RL-Baseline is the ceiling. So the comparison-to-paper is "how # far up the paper's own floor->ceiling range did our no-cheat method climb." We do NOT plot the # paper's intervention bars, for two different reasons (the disqualifier is oracle/ground-truth- # LABEL leakage, NOT "a monitor ran"): # - GT monitor (+70/90% variants) and the probe (trained on oracle-labelled in-env RH data, # footnote 12) both need the env oracle to exist -- they cannot be built on a new env with no # oracle, so they are cheats for our transfer claim. # - LLM judge is the legitimate external peer (generic model, no oracle, ~50% acc yet protective # via penalty) -- but it has no clean single fast-env number on our axis (paper figures only, # different training regime), so we have no honest point to plot for it. # - inoculation prompting (no monitor) has no clean number either (prose: incomplete, high- # variance -- some seeds ~0 hack, some ~full hack). # So: nothing with a comparable single number to plot; the paper enters only as floor/ceiling. GOLD, DARK = "#c8920a", "#3a3a3a" def _anchors(df: pl.DataFrame) -> dict: g = lambda kind, col: df.filter(pl.col("kind") == kind)[col][0] ceil_status = g("anchor_ceiling", "status") return dict(base_solve=g("anchor_floor", "solve_deploy"), vanilla_hack=df.filter(pl.col("label") == "vanilla GRPO")["hack_deploy"][0], ceiling=g("anchor_ceiling", "solve_deploy"), provisional=ceil_status.startswith("FIXME")) def _bars(ax, rows, key, raws, title, xlabel, xlo): """One floor->ceiling panel: horizontal bars in [xlo,1], 0=floor, 1.0=ceiling.""" for yi, (lab, val, raw, col) in enumerate(rows): ax.barh(yi, val, height=0.55, color=col, alpha=0.9, hatch="//" if col == GREY else None, edgecolor="white") # grey = approx reference tip = f"{val*100:+.0f}%" if xlo < 0 else f"{val*100:.0f}%" rawtxt = f" ({raw})" if raw else "" ax.text(val + (0.02 if val >= 0 else -0.02), yi, tip + rawtxt, va="center", ha="left" if val >= 0 else "right", fontsize=8.5, color=col) ax.axvline(0, color=GREY, lw=1.0) # floor (labelled in xlabel) ax.axvline(1.0, color=GREY, lw=1.0, ls=":") # ceiling ax.set_yticks(range(len(rows))); ax.set_yticklabels([r[0] for r in rows], fontsize=8.5) ax.set_xlim(xlo, 1.4); ax.set_xlabel(xlabel, fontsize=8.5) # hi=1.4 fits GT solve overshoot (+125%) ax.set_title(title, fontsize=10, loc="left") for s in ("top", "right", "left"): ax.spines[s].set_visible(False) ax.tick_params(left=False) def plot(df: pl.DataFrame) -> None: a = _anchors(df) base, vh, ceil = a["base_solve"], a["vanilla_hack"], a["ceiling"] pick = lambda lab: df.filter(pl.col("label") == lab).to_dicts()[0] best, rand = pick("routeV per-token"), pick("routeV random-V") def hsupp(r): return (vh - r["hack_deploy"]) / vh def suplift(r): return (r["solve_deploy"] - base) / (ceil - base) # Ariahw 2025 interventions on the hack panel, normalized to the PAPER's own floor # (No-Intervention 0.791 hack, Fig 9). Read off Fig 9 deploy hack rate: # GT penalty ~0.0 (needs oracle), probe penalty 0.0 (oracle-trained labels), # LLM-judge PENALTY 0.001 -- NO oracle, ~full suppression, perf 16.2% (the honest peer: # a no-oracle method ALREADY suppresses hacking; our novelty is the MECHANISM, not that). # LLM-judge SCREENING 0.157 is the weaker no-oracle point (2/3 runs broke out). # Scale caveat: paper bars are full-scale converged (paper floor 0.791); routeV is our # 60-step fast surrogate (floor 0.613). Suppression FRACTION is comparable; regimes differ. BLUE = "#3b5bdb" # no-oracle EXTERNAL peer (not a cheat -> not grey) PAPER_FLOOR = 0.791 psupp = lambda hack: (PAPER_FLOOR - hack) / PAPER_FLOOR hack_rows = [ ("Ariahw GT penalty\n(needs oracle)", psupp(0.001), "0.001", GREY), ("Ariahw probe\n(oracle-trained)", psupp(0.0), "0.000", GREY), ("Ariahw LLM-judge pen.\n(NO oracle, ext. peer)", psupp(0.001), "0.001", BLUE), ("routeV random-V\n(direction control)", hsupp(rand), f"{rand['hack_deploy']:.3f}", DARK), ("routeV per-token\n(best, NO oracle)", hsupp(best), f"{best['hack_deploy']:.3f}", GOLD), ] # SAME methods on the solve panel (symmetry -- the paper bars belong on both axes). # Paper performance from Fig 5, normalized to the PAPER's own base->ceiling # (11.5% -> 22.3%): GT penalty 25.0% (overshoots ceiling -- it beat the RL baseline), # probe 19.4%, LLM-judge penalty 16.2%. routeV uses our base->ceiling. puplift = lambda perf: (perf - 0.115) / (0.223 - 0.115) solve_rows = [ ("Ariahw GT penalty\n(needs oracle)", puplift(0.250), "0.250", GREY), ("Ariahw probe\n(oracle-trained)", puplift(0.194), "0.194", GREY), ("Ariahw LLM-judge pen.\n(NO oracle, ext. peer)", puplift(0.162), "0.162", BLUE), ("routeV random-V\n(direction control)", suplift(rand), f"{rand['solve_deploy']:.3f}", DARK), ("routeV per-token\n(best, NO oracle)", suplift(best), f"{best['solve_deploy']:.3f}", GOLD), ] prov = " (ceiling PROVISIONAL=0.223, FIXME job 24)" if a["provisional"] else "" fig, (axl, axr) = plt.subplots(1, 2, figsize=(11.5, 5.0), sharey=False) _bars(axl, hack_rows, "hack", None, "hack suppressed", "floor → ceiling (no hack) · right = better", 0.0) _bars(axr, solve_rows, "solve", None, "solve gained", f"floor (base 0.126) → ceiling{prov} · right = better", -0.55) fig.suptitle("vGROUT floor→ceiling: routeV (no oracle, gradient-level) vs Ariahw 2025 monitors (test n=119, seed 43, 60-step fast)", fontsize=10.5, x=0.01, ha="left") fig.text(0.01, 0.015, "Ariahw bars from Fig 5 (full-scale CONVERGED, normalized to paper base/floor/ceiling); routeV is our 60-step UNCONVERGED surrogate " "(our base/floor/ceiling) -- comparison is DIRECTIONAL only, not like-for-like. The LLM-judge penalty already suppresses with NO oracle (0.1% hack, 16.2% solve), " "so 'no-oracle suppression' isn't routeV's novelty -- the mechanism is (no live judge each step; fixed authored-pair direction).", fontsize=6.8, color=GREY, va="bottom") fig.tight_layout(rect=(0, 0.07, 1, 0.94)) for ext in ("pdf", "png"): fig.savefig(OUT / f"floor_ceiling.{ext}", dpi=150, bbox_inches="tight") def main() -> None: df = build_csv() flags = df.filter(~pl.col("status").str.starts_with("ok")) print(f"wrote {CSV}") if len(flags): print("\n=== TODO/FIXME in data ===") for r in flags.to_dicts(): print(f" [{r['label']}] {r['status']}") plot(df) print(f"\nwrote {OUT}/floor_ceiling.pdf and .png") if __name__ == "__main__": main()