#!/usr/bin/env python3 """L80-protocol cold readiness comparison for the exact passage cut.""" from __future__ import annotations import json import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l81/readiness" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l81/bin/VoxelForgeCoreHeadless-l81-clang" CAMERAS = { 0: (8.0, 16.0, -372.2626953125), 1: (25.8369140625, 3.19921875, -737.0), 2: (19.166015625, -14.2001953125, -753.3740234375), 3: (-20.0625, -5.068359375, -900.353515625), } MODES = (("full", "inf"), ("exact", "0")) PIPELINE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") NEAR = re.compile(r"^\[WorldAssemblerNearLODReady\] lods=0-2 tiles=(\d+)/(\d+) " r"cold_ready_s=([0-9.]+)$", re.M) def run(strate: int, mode: str, padding: str, phase: str, rep: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) label = f"s{strate}-{mode}-{phase}{rep}" log = OUT / f"{label}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "env", f"VOXELFORGE_L81_PASSAGE_BOUND_PADDING_VOXELS={padding}", "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", "--stream-scheduler-policy=3", ] start = time.monotonic() try: with log.open("w", encoding="utf-8") as stream: proc = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) except subprocess.TimeoutExpired as exc: raise RuntimeError(f"readiness run exceeded 1,740 seconds: {log}") from exc content = log.read_text(encoding="utf-8", errors="replace") pipeline_match = PIPELINE.search(content) near_match = NEAR.search(content) if proc.returncode or not pipeline_match or not near_match: raise RuntimeError(f"readiness run failed exit={proc.returncode}: {log}") pipeline = dict(FIELDS.findall(pipeline_match.group(1))) row = { "strate": strate, "mode": mode, "padding_voxels": padding, "phase": phase, "replicate": rep, "exit_code": proc.returncode, "wall_s": round(time.monotonic() - start, 3), "lod02_ready_s": float(near_match.group(3)), "whole_view_ready_s": float(pipeline["whole_view_ready"].removesuffix("s")), "whole_tiles": int(pipeline["whole_tiles"].split("/")[0]), "log": str(log.relative_to(ROOT)), } print("[L81ReadinessRun] " + 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 = [] for strate in range(4): for mode, padding in MODES: run(strate, mode, padding, "warmup", 0) orders = (("full", "exact"), ("exact", "full"), ("full", "exact")) for strate in range(4): for rep, order in enumerate(orders, 1): for mode in order: padding = dict(MODES)[mode] rows.append(run(strate, mode, padding, "measured", rep)) (OUT / "runs-partial.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = [] for strate in range(4): group = [row for row in rows if row["strate"] == strate] item = {"strate": strate, "measured_pairs": 3} for mode, _ in MODES: subset = [row for row in group if row["mode"] == mode] item[f"{mode}_lod02_s"] = [row["lod02_ready_s"] for row in subset] item[f"{mode}_lod02_median_s"] = statistics.median( row["lod02_ready_s"] for row in subset) item[f"{mode}_whole_s"] = [row["whole_view_ready_s"] for row in subset] item[f"{mode}_whole_median_s"] = statistics.median( row["whole_view_ready_s"] for row in subset) summary.append(item) (OUT / "summary.json").write_text(json.dumps({"runs": rows, "summary": summary}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())