#!/usr/bin/env python3 """Three interleaved L77 passage-share censuses for L98 and L99, all four 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/l99/census" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "L98": ROOT / "Saved/Linux/l98/profile-post-bin/VoxelForgeCoreHeadless-l98-post-profile", "L99": ROOT / "Saved/Linux/l99/profile-bin/VoxelForgeCoreHeadless-l99-profile-clang", } CAMERAS = { "SW": (8.0, 16.0, -372.2626953125), "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), "VS": (-20.0625, -5.068359375, -900.353515625), } SAMPLE = re.compile( r"^\[L77Sample\] pc=(0x\w+) lod=(\d+) .*?phase=(\S+) .*?weight=(\d+)$", re.M) SAMPLER = re.compile( r"^\[L77Sampler\] action=stop .*?samples=(\d+).*?status=PASS$", re.M) def run(strate: str, label: str, rep: int) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"{label.lower()}-{strate.lower()}-r{rep}.log" camera = ",".join(f"{value:.12f}" for value in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[label]), 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", "--linux77-profile", ] 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") samples = [(int(lod), phase, int(weight)) for _pc, lod, phase, weight in SAMPLE.findall(output)] sampler = SAMPLER.search(output) if result.returncode or not samples or sampler is None: raise RuntimeError(f"L77 census failed: exit={result.returncode} {log}") near = [row for row in samples if row[0] <= 2] passage = sum(weight for _, phase, weight in near if phase == "passages") total = sum(weight for _, _, weight in near) row = { "strate": strate, "binary": label, "replicate": rep, "exit_code": result.returncode, "wall_s": round(time.monotonic() - start, 3), "sampler_samples": int(sampler.group(1)), "near_lod_samples": len(near), "near_lod_weighted_ticks": total, "near_lod_passage_weighted_ticks": passage, "near_lod_passage_share_pct": 100.0 * passage / total, "log": str(log.relative_to(ROOT)), } print("[L99CensusRun] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: for binary in (*BINARIES.values(), DATA): if not binary.is_file(): raise SystemExit(f"missing input: {binary}") rows = [] orders = (("L98", "L99"), ("L99", "L98"), ("L98", "L99")) for rep, order in enumerate(orders, 1): for label in order: for strate in CAMERAS: rows.append(run(strate, label, rep)) (OUT / "runs-partial.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") summary = [] for strate in CAMERAS: item = {"strate": strate, "pairs": 3} for label in BINARIES: subset = [row for row in rows if row["strate"] == strate and row["binary"] == label] values = [row["near_lod_passage_share_pct"] for row in subset] item[f"{label}_runs_pct"] = values item[f"{label}_mean_pct"] = statistics.mean(values) item["change_pp"] = item["L99_mean_pct"] - item["L98_mean_pct"] summary.append(item) (OUT / "summary.json").write_text(json.dumps( {"runs": rows, "near_lod_passage_share": summary}, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())