#!/usr/bin/env python3 """Three interleaved L80-protocol W8 readiness pairs for L82 vs final L83.""" 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/readiness" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "L82": ROOT / "Saved/Linux/l82/bin/VoxelForgeCoreHeadless-clang19", "L83": ROOT / "Saved/Linux/l83/bin/VoxelForgeCoreHeadless-l83-clang19", } 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) EXPECTED_STAMPS = { "L82": "99fcbd2fd46e0bb3e250f3ad67e98ade0545e419193f987550356015714c6f1b", "L83": "08af4e98c86a69477cc79e21463d8c93bcd11ebe0f077d7c11519031d9141fa9", } def run(strate: int, version: str, phase: str, rep: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"s{strate}-{version.lower()}-{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(BINARIES[version]), 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() 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) != EXPECTED_STAMPS[version]: raise RuntimeError(f"source stamp mismatch in {log}") 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, "version": version, "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")), "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, "source_stamp": stamp_match.group(1), "log": str(log.relative_to(ROOT)), } print("[L83ReadinessRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: for path in (*BINARIES.values(), DATA): if not path.is_file(): raise SystemExit(f"missing input: {path}") for strate in range(4): for version in ("L82", "L83"): run(strate, version, "warmup", 0) rows = [] orders = (("L82", "L83"), ("L83", "L82"), ("L82", "L83")) for strate in range(4): for rep, order in enumerate(orders, 1): for version in order: rows.append(run(strate, version, "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 version in ("L82", "L83"): subset = [row for row in group if row["version"] == version] for metric in ("lod02_ready_s", "whole_view_ready_s", "shape_s"): values = [row[metric] for row in subset] item[f"{version}_{metric}"] = values item[f"{version}_{metric}_median"] = statistics.median(values) for metric in ("lod02_ready_s", "whole_view_ready_s"): by_pair = {rep: {row["version"]: row[metric] for row in group if row["phase"] == "measured" and row["replicate"] == rep} for rep in (1, 2, 3)} deltas = [by_pair[rep]["L83"] - by_pair[rep]["L82"] for rep in (1, 2, 3)] item[f"paired_{metric}_delta_s"] = deltas item[f"paired_{metric}_delta_median_s"] = statistics.median(deltas) 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())