Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/research/om-bench/bench/materialize.py # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / research / om-bench / bench / materialize.py` 112 lines ยท 4285 bytes Raw Blame History 1 """Materialize om-bench tasks to disk and hash them. 2 3 usage: materialize.py PUBLIC_OUT SEALED_OUT [MANIFEST_OUT] 4 Writes ///{statement.txt, NN.in, NN.out, meta.json}; cases 00-01 are the visible 5 examples, the rest hidden. Fails closed: any oracle exception, nondeterminism, oversized input or 6 duplicate input inside a task is a fatal error (exit 1), never a skipped task. 7 """ 8 import hashlib, json, os, sys 9 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) 10 import benchlib, families_public as P 11 sys.path.insert(0, benchlib.SEALED) 12 13 MAX_IN = 65536 14 15 16 def sha(bs): 17 return hashlib.sha256(bs).hexdigest() 18 19 20 def build(builders, split_of): 21 tasks = [] 22 for fam, fn in builders.items(): 23 ts = fn() 24 if len(ts) != 4: 25 sys.exit(f"FATAL {fam}: {len(ts)} variants, want 4") 26 for t in ts: 27 tasks.append((split_of[fam], t)) 28 return tasks 29 30 31 def write_task(root, split, t): 32 d = os.path.join(root, split, t.tid) 33 os.makedirs(d, exist_ok=True) 34 stmt = (t.statement + "\n").encode() 35 files = {"statement.txt": stmt} 36 cases = [] 37 seen = set() 38 for k, inp in enumerate(t.examples + t.hidden): 39 if len(inp) > MAX_IN: 40 sys.exit(f"FATAL {t.tid} case {k}: input {len(inp)} bytes > {MAX_IN}") 41 if inp in seen: 42 continue 43 seen.add(inp) 44 o1, e1 = t.oracle(inp) 45 o2, e2 = t.oracle(inp) 46 if (o1, e1) != (o2, e2): 47 sys.exit(f"FATAL {t.tid} case {k}: oracle nondeterministic") 48 n = len(cases) 49 files[f"{n:02d}.in"] = inp 50 files[f"{n:02d}.out"] = o1 51 cases.append({"n": n, "visible": k < len(t.examples), "exit": e1}) 52 if sum(1 for c in cases if c["visible"]) != 2 or len(cases) < 5: 53 sys.exit(f"FATAL {t.tid}: visible={sum(c['visible'] for c in cases)} cases={len(cases)}") 54 meta = {"tid": t.tid, "family": t.family, "split": split, "cases": cases} 55 files["meta.json"] = (json.dumps(meta, indent=1, sort_keys=True) + "\n").encode() 56 hashes = {} 57 for name, data in files.items(): 58 with open(os.path.join(d, name), "wb") as f: 59 f.write(data) 60 hashes[name] = sha(data) 61 return {"tid": t.tid, "family": t.family, "split": split, "n_cases": len(cases), 62 "statement_sha256": hashes["statement.txt"], 63 "task_sha256": sha("".join(f"{k} {hashes[k]}\n" for k in sorted(hashes)).encode()), 64 "files": hashes} 65 66 67 def write_manifest(path, rows): 68 """Public manifest: every public file hash; for sealed tasks only a keyed opaque id and one commitment 69 (task_sha256 = sha256 of the sorted 'name hash' list), never per-file hashes (see CONTRACT.md).""" 70 pub, sealed = [], [] 71 for r in sorted(rows, key=lambda r: (r["split"], r["tid"])): 72 if r["split"] in ("train", "dev"): 73 pub.append(r) 74 else: 75 sealed.append({"task": benchlib.opaque(r["split"], r["tid"]), "split": r["split"], 76 "task_sha256": r["task_sha256"]}) 77 sealed.sort(key=lambda r: (r["split"], r["task"])) 78 counts = {} 79 for r in rows: 80 counts[r["split"]] = counts.get(r["split"], 0) + 1 81 with open(path, "w") as f: 82 json.dump({"tasks_by_split": counts, "public": pub, "sealed": sealed}, f, indent=1, sort_keys=True) 83 f.write("\n") 84 85 86 def main(): 87 pub, sealed = sys.argv[1], sys.argv[2] 88 import families_sealed as S 89 rows = [] 90 for split, t in build(P.BUILDERS, P.SPLIT): 91 rows.append(write_task(pub, split, t)) 92 for split, t in build(S.BUILDERS, S.SPLIT): 93 rows.append(write_task(sealed, split, t)) 94 fams = {} 95 for r in rows: 96 fams.setdefault(r["family"], set()).add(r["split"]) 97 for f, s in fams.items(): 98 if len(s) != 1: 99 sys.exit(f"FATAL family {f} in splits {s}") 100 with open(os.path.join(sealed, "index.json"), "w") as f: 101 json.dump(rows, f, indent=1, sort_keys=True) 102 if len(sys.argv) > 3: 103 write_manifest(sys.argv[3], rows) 104 counts = {} 105 for r in rows: 106 counts[r["split"]] = counts.get(r["split"], 0) + 1 107 print("tasks", len(rows), "by split", json.dumps(counts, sort_keys=True), 108 "cases", sum(r["n_cases"] for r in rows)) 109 110 111 if __name__ == "__main__": 112 main()