#!/usr/bin/env python3 """L80-protocol near and whole-view readiness at W8/W12 for all owner strata.""" 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/l103/readiness" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l101/bin/VoxelForgeCoreHeadless-l101-clang" STRATA = { "SW": {"camera": (8.0, 16.0, -372.2626953125), "near": 1408, "whole": 2850}, "FI": {"camera": (25.8369140625, 3.19921875, -737.0), "near": 1216, "whole": 2249}, "TN": {"camera": (19.166015625, -14.2001953125, -753.3740234375), "near": 1344, "whole": 2233}, "VS": {"camera": (-20.0625, -5.068359375, -900.353515625), "near": 1344, "whole": 2329}, } NEAR = re.compile(r"^\[WorldAssemblerNearLODReady\] lods=0-2 tiles=(\d+)/(\d+) cold_ready_s=([0-9.]+)$", re.M) PUBLISHED = re.compile(r"^\[WorldAssemblerNearLODPublished\] lods=0-2 tiles=(\d+)/(\d+) cold_ready_s=([0-9.]+)$", re.M) PIPELINE_READY = re.compile(r"^\[WorldAssemblerNearLODPipelineReady\] lods=0-2 tiles=(\d+)/(\d+) cold_ready_s=([0-9.]+)$", re.M) PIPELINE = re.compile(r"^\[StreamPipeline\] (.*)$", re.M) CONFIG = re.compile(r"^\[HeadlessConfig\] (.*)$", re.M) STAMP = re.compile(r"^\[VoxelForgeSourceStamp\] sha256=(\S+)$", re.M) FIELDS = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") def run(stratum: str, workers: int, phase: str, replicate: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) suffix = f"-r{replicate}" if phase == "measured" else "" log = OUT / f"{stratum.lower()}-w{workers}-{phase}{suffix}.log" camera = ",".join(f"{value:.12f}" for value in STRATA[stratum]["camera"]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "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) content = log.read_text(encoding="utf-8", errors="replace") near, published, pipeline_ready = (NEAR.search(content), PUBLISHED.search(content), PIPELINE_READY.search(content)) pipeline, config, stamp = PIPELINE.search(content), CONFIG.search(content), STAMP.search(content) if result.returncode or not all((near, published, pipeline_ready, pipeline, config, stamp)): raise RuntimeError(f"readiness run failed or markers missing: {log}; exit={result.returncode}") fields = dict(FIELDS.findall(pipeline.group(1))) config_fields = dict(FIELDS.findall(config.group(1))) spec = STRATA[stratum] if int(config_fields["workers"]) != workers: raise RuntimeError(f"worker mismatch: {log}") if stamp.group(1) != "c5f49a45f51856b857a1ee8877b7d777208e67daf64281caefc7ef84e8006410": raise RuntimeError(f"source stamp mismatch: {log}: {stamp.group(1)}") for marker in (near, published, pipeline_ready): if (int(marker.group(1)), int(marker.group(2))) != (spec["near"], spec["near"]): raise RuntimeError(f"incomplete near set: {log}: {marker.group(1)}/{marker.group(2)}") whole_done, whole_total = (int(value) for value in fields["whole_tiles"].split("/")) if (whole_done, whole_total) != (spec["whole"], spec["whole"]): raise RuntimeError(f"incomplete whole set: {log}: {whole_done}/{whole_total}") row = { "stratum": stratum, "workers": workers, "phase": phase, "replicate": replicate, "exit_code": result.returncode, "source_stamp": stamp.group(1), "near_tiles": spec["near"], "whole_tiles": spec["whole"], "lod02_ready_s": float(near.group(3)), "lod02_published_s": float(published.group(3)), "lod02_pipeline_ready_s": float(pipeline_ready.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")), "wall_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), } print("[L103ReadinessRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if not DATA.is_file() or not BINARY.is_file(): raise SystemExit(f"missing input: {DATA} or {BINARY}") for stratum in ("VS", "TN", "FI", "SW"): for workers in (12, 8): run(stratum, workers, "warmup", 0) schedules = ( (("SW", 8), ("SW", 12), ("FI", 8), ("FI", 12), ("TN", 8), ("TN", 12), ("VS", 8), ("VS", 12)), (("VS", 12), ("VS", 8), ("TN", 12), ("TN", 8), ("FI", 12), ("FI", 8), ("SW", 12), ("SW", 8)), (("FI", 8), ("FI", 12), ("SW", 8), ("SW", 12), ("VS", 8), ("VS", 12), ("TN", 8), ("TN", 12)), ) rows = [] for replicate, schedule in enumerate(schedules, 1): for stratum, workers in schedule: rows.append(run(stratum, workers, "measured", replicate)) (OUT / "runs-partial.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = [] for stratum in STRATA: for workers in (8, 12): group = [row for row in rows if row["stratum"] == stratum and row["workers"] == workers] if len(group) != 3: raise RuntimeError(f"expected three measured runs: {stratum} W{workers}") summary.append({ "stratum": stratum, "workers": workers, "measured_runs": 3, **{metric: [row[metric] for row in group] for metric in ("lod02_ready_s", "lod02_published_s", "lod02_pipeline_ready_s", "whole_view_ready_s")}, **{f"{metric}_median": statistics.median(row[metric] for row in group) for metric in ("lod02_ready_s", "lod02_published_s", "lod02_pipeline_ready_s", "whole_view_ready_s")}, }) (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())