#!/usr/bin/env python3 """L80-protocol cold readiness scaling at 4, 8, 12, and 16 workers.""" 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/l83/scaling" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l83/bin/VoxelForgeCoreHeadless-l83-clang19" WORKERS = (4, 8, 12, 16) 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+) " r"cold_ready_s=([0-9.]+)$", re.M) SHAPE_FREE = re.compile(r"^\[ShapeReadiness\] shape_free_desired=(\d+)/(\d+) " r"near_ring=(\d+)/27", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) SOURCE_STAMP = "08af4e98c86a69477cc79e21463d8c93bcd11ebe0f077d7c11519031d9141fa9" def run(strate: int, workers: int, phase: str, rep: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"s{strate}-w{workers}-{phase}{rep}.log" camera = ",".join(f"{v:.12f}" for v in CAMERAS[strate]) + ",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", f"--workers={workers}", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-lod-work", "--stream-scheduler-policy=3", ] 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") pipeline_match, near_match = PIPELINE.search(output), NEAR.search(output) shape_free_match, stamp_match = SHAPE_FREE.search(output), STAMP.search(output) if result.returncode or pipeline_match is None or near_match is None: raise RuntimeError(f"readiness run failed: exit={result.returncode} {log}") if stamp_match is None or stamp_match.group(1) != SOURCE_STAMP: raise RuntimeError(f"source stamp mismatch in {log}: {stamp_match.group(1) if stamp_match else 'missing'}") pipeline = dict(FIELDS.findall(pipeline_match.group(1))) near_done, near_total = int(near_match.group(1)), int(near_match.group(2)) whole_done, whole_total = (int(v) for v in pipeline["whole_tiles"].split("/")) if near_done != near_total or near_total != EXPECTED_NEAR[strate]: raise RuntimeError(f"near readiness incomplete in {log}: {near_done}/{near_total}") if whole_done != whole_total or whole_total != EXPECTED_WHOLE[strate]: raise RuntimeError(f"whole readiness incomplete in {log}: {whole_done}/{whole_total}") row = { "strate": strate, "workers": workers, "phase": phase, "replicate": rep, "exit_code": result.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")), "shape_s": float(pipeline["shape"].removesuffix("s")), "first_tile_ready_s": float(pipeline["first_tile_ready"].removesuffix("s")), "neighborhood_ready_s": float(pipeline["neighborhood_ready"].removesuffix("s")), "full_detail_ready_s": float(pipeline["full_detail_ready"].removesuffix("s")), "near_tiles": near_total, "whole_tiles": whole_total, "shape_free_desired": int(shape_free_match.group(1)) if shape_free_match else None, "shape_free_near_ring": int(shape_free_match.group(3)) if shape_free_match else None, "log": str(log.relative_to(ROOT)), } print("[L83ScalingRun] " + 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}") for strate in range(4): for workers in WORKERS: run(strate, workers, "warmup", 0) rows = [] orders = ( WORKERS, (16, 12, 8, 4), (8, 16, 4, 12), ) for strate in range(4): for rep, order in enumerate(orders, 1): for workers in order: rows.append(run(strate, workers, "measured", rep)) (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", "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())