#!/usr/bin/env python3 """Repeat the L77 FI/TN phase census on the L82 passage implementation.""" 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/l82/census" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l82/profile-bin/VoxelForgeCoreHeadless-clang19" CAMERAS = { "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), } SAMPLE = re.compile(r"^\[L77Sample\] .*?lod=(\d+) .*?phase=(\S+) .*?weight=(\d+)$", re.M) SAMPLER = re.compile(r"^\[L77Sampler\] action=stop .*?samples=(\d+).*?status=PASS$", re.M) def run(world: str, rep: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"l82-phase-{world.lower()}-r{rep}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[world]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "env", "VOXELFORGE_L81_PASSAGE_BOUND_PADDING_VOXELS=0", "timeout", "1740s", str(BINARY), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-lod-work", "--linux77-profile", ] start = 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") matches = [(int(lod), phase, int(weight)) for lod, phase, weight in SAMPLE.findall(output)] sampler = SAMPLER.search(output) if result.returncode or not matches or sampler is None: raise RuntimeError(f"census failed: exit={result.returncode} {log}") near = [row for row in matches if row[0] <= 2] passage = sum(weight for _, phase, weight in near if phase == "passages") total = sum(weight for _, _, weight in near) row = { "world": world, "replicate": rep, "exit_code": result.returncode, "wall_s": round(time.monotonic() - start, 3), "sampler_samples": int(sampler.group(1)), "near_lod_samples": len(near), "near_lod_weighted_ticks": total, "near_lod_passage_weighted_ticks": passage, "near_lod_passage_share_pct": 100.0 * passage / total if total else 0.0, "log": str(log.relative_to(ROOT)), } print("[L82CensusRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if not BINARY.is_file() or not DATA.is_file(): raise SystemExit(f"missing input: {BINARY} or {DATA}") rows = [run(world, rep) for world in CAMERAS for rep in (1, 2, 3)] by_world = {} for world in CAMERAS: values = [row["near_lod_passage_share_pct"] for row in rows if row["world"] == world] by_world[world] = {"runs_pct": values, "mean_pct": sum(values) / len(values)} (OUT / "summary.json").write_text(json.dumps( {"runs": rows, "near_lod_passage_share": by_world}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())