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 / evidence / OMEGALLM-FRONTIER-20261123 / replay_samples.py
| 1 | """Replay the separate 36-task diagnostic using its recorded inputs and both native engines.""" |
| 2 | import argparse |
| 3 | from collections import Counter |
| 4 | from pathlib import Path |
| 5 | import hashlib |
| 6 | import json |
| 7 | import subprocess |
| 8 | import sys |
| 9 | import tempfile |
| 10 | |
| 11 | sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "train/omega-llm/tools/combined/experiment")) |
| 12 | from engines import Engines |
| 13 | |
| 14 | |
| 15 | def check_binary(binary, expected): |
| 16 | with binary.open("rb") as stream: |
| 17 | if hashlib.file_digest(stream, "sha256").hexdigest() != expected: |
| 18 | raise ValueError(f"{binary.name} digest differs") |
| 19 | |
| 20 | |
| 21 | def replay(samples, previous, kit): |
| 22 | check_binary(kit / "omc", samples["meta"]["omc"]) |
| 23 | for label, binary in (("prev", previous), ("corr", kit / "om_synth")): |
| 24 | check_binary(binary, samples["meta"][label]) |
| 25 | counts = Counter() |
| 26 | for task, versions in zip(samples["tasks"], samples["results"], strict=True): |
| 27 | expected = versions[label] |
| 28 | with tempfile.TemporaryDirectory() as tmp: |
| 29 | directory = Path(tmp) |
| 30 | spec, output = directory / "spec", directory / "function" |
| 31 | lines = [f"arity {task['arity']}", f"depth {samples['depth']}"] |
| 32 | for args, value in task["sup"]: |
| 33 | lines.append("case " + " ".join(map(str, [*args, value]))) |
| 34 | spec.write_text("\n".join(lines) + "\n") |
| 35 | run = subprocess.run([binary, "solve", spec, output], capture_output=True, timeout=240) |
| 36 | if run.returncode != expected["rc"] or run.stdout.decode().strip() != expected["stdout"]: |
| 37 | raise ValueError((task["id"], label, "solver result")) |
| 38 | counts[run.returncode] += 1 |
| 39 | if run.returncode: |
| 40 | if output.exists() or expected["prog"] is not None: |
| 41 | raise ValueError((task["id"], label, "unexpected program")) |
| 42 | continue |
| 43 | program = output.read_text() |
| 44 | if program != expected["prog"]: |
| 45 | raise ValueError((task["id"], label, "program")) |
| 46 | header, body = program.split("\n", 1) |
| 47 | engine = Engines(kit, directory, "note evaluate the expression\n" + header + "\n") |
| 48 | for field, grade in (("sup", "sup_ok"), ("hold", "hold_ok")): |
| 49 | xs, ys = zip(*task[field], strict=True) |
| 50 | answers = engine.predict(body.encode(), xs) |
| 51 | matches = sum(value == (want,) for value, want in zip(answers, ys, strict=True)) |
| 52 | if matches != expected[grade]: |
| 53 | raise ValueError((task["id"], label, field, "grade")) |
| 54 | counts["correct"] += expected["hold_ok"] == len(task["hold"]) |
| 55 | print(label, dict(counts)) |
| 56 | |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | parser = argparse.ArgumentParser(description=__doc__) |
| 60 | parser.add_argument("receipt", type=Path) |
| 61 | parser.add_argument("previous_synth", type=Path) |
| 62 | parser.add_argument("kit", type=Path) |
| 63 | args = parser.parse_args() |
| 64 | replay(json.loads(args.receipt.read_text())["independent_samples"], args.previous_synth.resolve(), args.kit.resolve()) |