#!/usr/bin/env python3 """Compare L149 hashes and layout identity at Clang/GCC W1, W8, and W12.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path from MouthAudit import audit_layout ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l149/determinism" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "clang": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l149-clang", "gcc": ROOT / "Standalone/bin/linux/VoxelForgeCoreHeadless-l149-gcc", } STAMP = "19dbe26ab76a629baadc54bb0ab93eaa22d6f878e6946df2b71509c12c9524e4" CAMERA = "-20.062500,-5.068359,-900.353516,0,0" HASH_RE = re.compile( r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) STAMP_RE = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=([0-9a-f]+)$", re.M) def main() -> int: if any(not path.is_file() for path in (DATA, *BINARIES.values())): raise SystemExit("missing L149 Clang/GCC binary or composed owner fixture") OUT.mkdir(parents=True, exist_ok=True) rows = [] partial = OUT / "runs-partial.json" for compiler, binary in BINARIES.items(): for workers in (1, 8, 12): name = f"determinism-{compiler}-w{workers}" log, layout = OUT / f"{name}.log", OUT / f"{name}.json" command = ["taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(binary), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=0", f"--camera={CAMERA}", "--stream-hash", "--force-generate", "--seed=2", "--recipe=surface-world", "--render-distance-chunks=0", "--density-dispatch-report", f"--resolved-layout-output={layout}"] started = time.monotonic() with log.open("w", encoding="utf-8") as output: proc = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") stamp_match = STAMP_RE.search(content) stamp = stamp_match.group(1) if stamp_match else None hashes = tuple(HASH_RE.findall(content)) identity = (json.loads(layout.read_text(encoding="utf-8")).get("stable_identity") if layout.is_file() else None) mouth_audit = audit_layout(layout) if layout.is_file() else None row = {"compiler": compiler, "workers": workers, "exit": proc.returncode, "stamp": stamp, "source_stamp_matches": stamp == STAMP, "hash_lines": len(hashes), "hashes": hashes, "layout_identity": identity, "mouth_audit": mouth_audit, "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), "layout": str(layout.relative_to(ROOT))} rows.append(row) partial.write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") print("[L149DeterminismRun] " + json.dumps(row, sort_keys=True), flush=True) valid = [row for row in rows if row["source_stamp_matches"] and row["hash_lines"] == 12 and row["layout_identity"]] reference_hashes = valid[0]["hashes"] if valid else [] reference_identity = valid[0]["layout_identity"] if valid else None deterministic = len(valid) == 6 and all( row["hashes"] == reference_hashes and row["layout_identity"] == reference_identity for row in valid) mouth_geometry = all(row["mouth_audit"] and row["mouth_audit"]["continuity"] and row["mouth_audit"]["negative_controls_pass"] for row in rows) no_backtrack = all(row["mouth_audit"] and row["mouth_audit"]["no_backtrack_12m"] for row in rows) summary = {"status": "PASS" if deterministic else "FAIL", "deterministic": deterministic, "mouth_geometry_pass": mouth_geometry, "no_backtrack_12m": no_backtrack, "source_stamp": STAMP, "layout_identity": reference_identity, "runs": rows} (OUT / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") print(f"[L149DeterminismSummary] runs={len(rows)} deterministic=" f"{'PASS' if deterministic else 'FAIL'} mouth_geometry=" f"{'PASS' if mouth_geometry else 'FAIL'} no_backtrack_12m=" f"{'PASS' if no_backtrack else 'FAIL'} status={summary['status']}", flush=True) return 0 if summary["status"] == "PASS" else 1 if __name__ == "__main__": raise SystemExit(main())