omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / train / omega-llm / tools / combined / experiment / audit.py
| 1 | """Audit the published per-task comparison and replay final grades without model weights.""" |
| 2 | import argparse |
| 3 | from collections import Counter |
| 4 | import json |
| 5 | import tempfile |
| 6 | from concurrent.futures import ThreadPoolExecutor |
| 7 | from pathlib import Path |
| 8 | |
| 9 | import fixture |
| 10 | from measure import digest, score |
| 11 | from engines import Engines, ComponentFailure |
| 12 | from selection import choose |
| 13 | |
| 14 | |
| 15 | def require(condition, message): |
| 16 | if not condition: |
| 17 | raise ValueError(message) |
| 18 | |
| 19 | |
| 20 | def replay_selection(task, row, kit): |
| 21 | # Consume the sealed transcript in order. An unexpected new question stops replay. |
| 22 | answers = iter(row["queries"]) |
| 23 | def recorded(x): |
| 24 | entry = next(answers, None) |
| 25 | require(entry is not None and tuple(entry[0]) == x, (task["id"], "query diverged")) |
| 26 | return tuple(entry[1]) |
| 27 | |
| 28 | with tempfile.TemporaryDirectory() as scratch: |
| 29 | engine = Engines(kit, scratch, task["prompt"]) |
| 30 | try: |
| 31 | body, route, rounds = choose(engine, task["fixed"], task["pool"], recorded, |
| 32 | row["mode"] == "adaptive") |
| 33 | except ComponentFailure as error: |
| 34 | require(error.details == row.get("error"), (task["id"], "component exit differs")) |
| 35 | else: |
| 36 | require(not row.get("error"), (task["id"], "missing component failure")) |
| 37 | require((body.decode() if body else None) == row["program"], (task["id"], "selected body")) |
| 38 | require((route, rounds) == (row["route"], row["rounds"]), (task["id"], "selection trace")) |
| 39 | require(next(answers, None) is None, (task["id"], "unused answers")) |
| 40 | |
| 41 | |
| 42 | def main(): |
| 43 | p=argparse.ArgumentParser(description=__doc__) |
| 44 | p.add_argument("receipt",type=Path) |
| 45 | p.add_argument("kit",type=Path,help="public kit containing the seeded omc and predict instrument") |
| 46 | p.add_argument("--replay-selection", action="store_true", help="also reproduce every fixed and adaptive symbolic decision from its sealed answers") |
| 47 | p.add_argument("--jobs", type=int, default=1) |
| 48 | args=p.parse_args() |
| 49 | require(digest(args.receipt) in args.receipt.name,"receipt digest") |
| 50 | report=json.loads(args.receipt.read_text()) |
| 51 | pins=report["inputs"] |
| 52 | require(digest(fixture.MANIFEST)==pins["manifest"],"task manifest digest") |
| 53 | require(digest(Path(fixture.__file__))==pins["fixture"],"reference digest") |
| 54 | for name in ("omc","predict"): |
| 55 | require(digest(args.kit/name)==pins["kits"]["baseline"][name],name+" digest") |
| 56 | tasks=list(fixture.tasks("eval")) |
| 57 | for arm,rows in report["evaluation"].items(): |
| 58 | require([r["id"] for r in rows]==[t["id"] for t in tasks],"task IDs") |
| 59 | totals=Counter() |
| 60 | for task,row in zip(tasks,rows,strict=True): |
| 61 | queried=[tuple(x) for x,_ in row["queries"]] |
| 62 | require(len(set(queried))==row["query_count"]==len(queried)<=8,"query budget") |
| 63 | require(set(queried)<=set(task["pool"]),"outside input pool") |
| 64 | fixed=task["fixed"][:4 if arm=="adaptive" else 8] |
| 65 | require(queried[:len(fixed)]==fixed,"opening queries") |
| 66 | for x,y in row["queries"]: |
| 67 | require(tuple(y)==fixture.ref(task,x),"query label") |
| 68 | if row.get("error"): |
| 69 | require(row["verdict"]=="error" and row["program"] is None,"component failure") |
| 70 | else: |
| 71 | require(len(queried)==8,"incomplete successful selection") |
| 72 | replay=score(task,row,args.kit) |
| 73 | require(replay["verdict"]==row["verdict"],(task["id"],"held-out grade")) |
| 74 | require(json.loads(json.dumps(replay["first_mismatch"]))==row["first_mismatch"],"mismatch") |
| 75 | totals[row["verdict"]]+=1 |
| 76 | require(dict(totals)==report["summary"]["arms"][arm]["verdicts"],"reported totals") |
| 77 | if args.replay_selection and arm in ("fixed", "adaptive"): |
| 78 | for name in ("om_formalize", "om_sketch", "om_synth"): |
| 79 | require(digest(args.kit/name)==pins["kits"][arm][name], name+" digest") |
| 80 | with ThreadPoolExecutor(max_workers=args.jobs) as workers: |
| 81 | list(workers.map(lambda t,r: replay_selection(t,r,args.kit), tasks, rows)) |
| 82 | print(arm,"PASS sealed query sequence and selection trace") |
| 83 | print(arm,dict(totals)) |
| 84 | print("PASS public task inputs, charged answers, all emitted programs and reported totals") |
| 85 | |
| 86 | |
| 87 | if __name__=="__main__": |
| 88 | main() |