#!/usr/bin/env python3 """BASE_TOPUP deliverable 2 (owner-simplified 2026-09-25 20:55Z): is every task's `mpcd` H-grid COMPLETE at 3 training x 3 eval seeds for DINO-WM, LeWM and DF? The owner's simplification removed the read-out re-implementation; what is left is a COMPLETENESS question, and the only honest way to answer it is to count the cells the table builder itself would read. So: no hand-rolled loader -- flagship_latex is imported FIRST (it sets RSM_EXTRA_EPOCHS, without which every threading cell is dropped), then verdict_table.cells(), and the proposer filter is flagship_latex.proposer_ok, i.e. the row's PINNED proposer, because that is the only cell set the flagship column can ever read. Output: status/basetopup/mpcd_inventory.json + .md -- per (task, scorer, H): #cells, #distinct (pseed,eseed) pairs, and the missing pairs, so a top-up launcher can consume it directly. """ import json, os, re, sys from collections import defaultdict ROOT = "/proj/dmfexp/zwhong/rsm_rise" sys.path.insert(0, f"{ROOT}/scripts") sys.path.insert(0, f"{ROOT}/scripts/flagtopup") import flagship_latex as F # noqa: F401 -- MUST precede the loader import verdict_table as V assert "500" in (os.environ.get("RSM_EXTRA_EPOCHS") or ""), "threading cells would be dropped" TASKS = ["square_sub_20100", "square_expert_play", "two_piece_expert_suboptimal", "two_piece_expert_play", "mug_expert_suboptimal", "threading_expert_play", "two_piece_expert_play_tipping"] SCORERS = ["wm:dinowm", "wm:lewm", "wm:df"] HGRID = [10, 20, 50, 100, 200] # DF's training-seed axis is the WORLD-MODEL seed; the flagship column is the base W3 model. DF_BASE_MODEL = "W3" def h_of(rec): m = re.match(r"H(\d+)\s", rec + " ") return int(m.group(1)) if m else None def model_of(rec): m = re.search(r"\[([A-Za-z0-9_]+)@s([A-Za-z0-9_]+)\]$", rec) return m.group(1) if m else None def main(): inv, md = {}, [] md.append("# `mpcd` H-grid completeness -- DINO-WM / LeWM / DF, pinned proposer, 3x3 seeds") md.append("") md.append("Counted with `verdict_table.cells()` under `flagship_latex.proposer_ok` (the row's PINNED " "proposer), horizon 400 + canonical region + task success criteria applied by the loader. " "`9/9` = complete arm. For DF only the **base world model `W3`** is counted: the replicate " "seeds W3s1/W3s2 are a seed axis, not an arm axis (gen_q#284).") md.append("") for t in TASKS: c = V.cells(t) inv[t] = {} rows = [] for sc in SCORERS: inv[t][sc] = {} for H in HGRID: # every mpcd arm of this scorer at this H, on the pinned proposer pairs = defaultdict(set) # recipe -> {(pseed, eseed)} ncell = defaultdict(int) for (arm, p, ps, es), v in c.items(): if arm[0] != sc: continue rec = arm[1] if h_of(rec) != H or "mpcd" not in rec.split(): continue if not F.proposer_ok(t, p): continue if sc == "wm:df" and model_of(rec) != DF_BASE_MODEL: continue pairs[rec].add((ps, es)) ncell[rec] += len(v) if not pairs: inv[t][sc][H] = dict(arms={}, best=0, missing="ALL 9") rows.append((sc, H, "--", 0, "no arm")) continue best_rec = max(pairs, key=lambda r: len(pairs[r])) have = pairs[best_rec] # the 3x3 target grid: this task's three policy seeds x eval seeds 0/1/2. The policy # seeds are read off the cells this scorer actually has on this task (never guessed), # falling back to 0/1/2 when a scorer has none at this H. pseeds = sorted({k[0] for r in pairs for k in pairs[r]}) or [0, 1, 2] allp = {(ps, es) for ps in pseeds[:3] for es in (0, 1, 2)} miss = sorted(allp - have) if len(have) < 9 else [] inv[t][sc][H] = dict( arms={r: sorted(f"{a}|{b}" for a, b in pairs[r]) for r in pairs}, best_recipe=best_rec, n_pairs=len(have), n_episodes=ncell[best_rec], missing=[f"{a}|{b}" for a, b in miss]) rows.append((sc, H, best_rec, len(have), "COMPLETE" if len(have) >= 9 else f"{len(have)}/9")) md.append(f"## {t} (proposer `{F.proposer_for(t)}`)") md.append("") md.append("| scorer | H | best mpcd arm | pairs | state |") md.append("|---|---|---|---|---|") for sc, H, rec, n, st in rows: md.append(f"| {sc} | {H} | `{rec}` | {n} | {st} |") md.append("") # the headline: how many of the 7x3x5 = 105 (task, scorer, H) cells are complete tot = comp = 0 for t in inv: for sc in inv[t]: for H in inv[t][sc]: tot += 1 comp += 1 if inv[t][sc][H].get("n_pairs", 0) >= 9 else 0 md.insert(3, f"**{comp} / {tot} (task, scorer, H) mpcd arms are complete at 9 pairs.**") md.insert(4, "") json.dump(inv, open(f"{ROOT}/status/basetopup/mpcd_inventory.json", "w"), indent=1) open(f"{ROOT}/status/basetopup/MPCD_INVENTORY.md", "w").write("\n".join(md) + "\n") print(f"{comp}/{tot} complete") print("\n".join(md)) if __name__ == "__main__": main()