#!/usr/bin/env python3 """Measure the passage-disabled best-case ceiling using the L80 interleaved protocol.""" 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/l86/ceiling" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l86/bin/VoxelForgeCoreHeadless-clang19" WORKERS = (8, 12) 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), } EXPECTED_NEAR = {0: 1408, 1: 1216, 2: 1344, 3: 1344} EXPECTED_WHOLE = {0: 2850, 1: 2249, 2: 2233, 3: 2329} 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+) cold_ready_s=([0-9.]+)$", re.M, ) def run(strate: int, workers: int, phase: str, replicate: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) label = f"s{strate}-w{workers}-{phase}{replicate}" 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", "VOXELFORGE_L81_PASSAGE_BOUND_PADDING_VOXELS=0", "VOXELFORGE_L86_DISABLE_PASSAGE_COMPOSITION=1", "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=8", f"--camera={camera}", "--profile-lod-work", "--stream-scheduler-policy=3", ] 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") pipeline_match, near_match = PIPELINE.search(output), NEAR.search(output) if result.returncode or pipeline_match is None or near_match is None: raise RuntimeError(f"ceiling run failed: exit={result.returncode} {log}") near_done, near_total = int(near_match.group(1)), int(near_match.group(2)) if (near_done, near_total) != (EXPECTED_NEAR[strate], EXPECTED_NEAR[strate]): raise RuntimeError(f"incomplete near set in {log}: {near_done}/{near_total}") fields = dict(FIELDS.findall(pipeline_match.group(1))) whole_done, whole_total = (int(value) for value in fields["whole_tiles"].split("/")) if (whole_done, whole_total) != (EXPECTED_WHOLE[strate], EXPECTED_WHOLE[strate]): raise RuntimeError(f"incomplete whole set in {log}: {whole_done}/{whole_total}") row = { "strate": strate, "workers": workers, "phase": phase, "replicate": replicate, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "lod02_ready_s": float(near_match.group(3)), "whole_view_ready_s": float(fields["whole_view_ready"].removesuffix("s")), "shape_s": float(fields["shape"].removesuffix("s")), "far_shape_s": float(fields["far_shape"].removesuffix("s")), "first_tile_ready_s": float(fields["first_tile_ready"].removesuffix("s")), "neighborhood_ready_s": float(fields["neighborhood_ready"].removesuffix("s")), "full_detail_ready_s": float(fields["full_detail_ready"].removesuffix("s")), "near_tiles": near_total, "whole_tiles": whole_total, "log": str(log.relative_to(ROOT)), } print("[L86CeilingRun] " + 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 workers in WORKERS: run(strate, workers, "warmup", 0) for replicate, order in enumerate(((8, 12), (12, 8), (8, 12)), 1): for workers in order: rows.append(run(strate, workers, "measured", replicate)) (OUT / "runs-partial.json").write_text( json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = [] for strate in range(4): for workers in WORKERS: subset = [row for row in rows if row["strate"] == strate and row["workers"] == workers] item = {"strate": strate, "workers": workers, "measured_runs": len(subset)} for metric in ( "lod02_ready_s", "whole_view_ready_s", "shape_s", "far_shape_s", "first_tile_ready_s", "neighborhood_ready_s", "full_detail_ready_s", ): values = [row[metric] for row in subset] item[metric] = values item[f"{metric}_median"] = statistics.median(values) item[f"{metric}_min"] = min(values) item[f"{metric}_max"] = max(values) 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())