#!/usr/bin/env python3 """Compare the L116 hash matrix directly with the saved L115 matrix.""" from __future__ import annotations import json import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l116/hashes" BASE = ROOT / "Saved/Linux/l115/hashes" DATASETS = { "owner4": ROOT / "Standalone/data/owner_world.json", "owner2": ROOT / "Standalone/data/regression/owner_world_2strate_l61.json", } BINARIES = { "clang": ROOT / "Saved/Linux/l116/bin/VoxelForgeCoreHeadless-l116-clang", "gcc": ROOT / "Saved/Linux/l116/bin/VoxelForgeCoreHeadless-l116-gcc", } HASH = re.compile(r"^\[Pipeline(?:FullDetailHash|WholeViewHash|LODHash|ExactQueryHash)\].*$", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) def run(dataset: str, recipe: str, workers: int, compiler: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) label = f"{dataset}-{recipe}-w{workers}-{compiler}" log = OUT / f"{label}.log" layout = OUT / f"{label}.layout.json" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[compiler]), str(DATASETS[dataset]), f"--workers={workers}", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--recipe={recipe}", "--stream-hash", f"--resolved-layout-output={layout}", ] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) output = log.read_text(encoding="utf-8", errors="replace") hashes = HASH.findall(output) baseline_log = BASE / f"{label}.log" baseline_hashes = HASH.findall(baseline_log.read_text(encoding="utf-8", errors="replace")) if result.returncode or len(hashes) != 12 or hashes != baseline_hashes: raise SystemExit(f"hash mismatch or incomplete run: {label}; exit={result.returncode} " f"l116={len(hashes)} l115={len(baseline_hashes)} log={log}") row = { "dataset": dataset, "recipe": recipe, "workers": workers, "compiler": compiler, "exit_code": result.returncode, "matches_l115": True, "hashes": hashes, "source_stamp": (STAMP.search(output).group(1) if STAMP.search(output) else None), "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), "l115_log": str(baseline_log.relative_to(ROOT)), } print("[L116HashRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if any(not path.is_file() for path in (*DATASETS.values(), *BINARIES.values())): raise SystemExit("missing L116 hash input") rows = [] recipes = {"owner4": ("surface-world",), "owner2": ("surface-world", "floating-islands")} for dataset, dataset_recipes in recipes.items(): for recipe in dataset_recipes: for workers in (1, 8, 12): for compiler in ("clang", "gcc"): rows.append(run(dataset, recipe, workers, compiler)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = { "runs": rows, "all_hashes_match_l115": all(row["matches_l115"] for row in rows), "owner4_all_four_strata": "owner4/surface-world", "worker_counts": [1, 8, 12], "compilers": ["clang", "gcc"], } (OUT / "summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())