#!/usr/bin/env python3 """Audit certified legacy density blocks across 20 deterministic camera positions per stratum.""" 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/l75/logs" DATA = ROOT / "Standalone/data/owner_world.json" BIN = ROOT / "Saved/Linux/l75/bin/VoxelForgeCoreHeadless-l75-clang" 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), } OFFSETS = [(x, y) for y in (0.1, 4.1, 8.1, 12.1) for x in (0.1, 4.1, 8.1, 12.1, 16.1)] AUDIT = re.compile( r"\[UniformBlockProofAudit\] checked_blocks=(\d+) checked_samples=(\d+) " r"fallback_blocks=(\d+) unknown_blocks=(\d+) violations=(\d+)" ) TILE = re.compile( r"\[WorldAssemblerTilePipeline\] .*?solid_boxes=(\d+) air_boxes=(\d+) " r"mixed_boxes=(\d+) unknown_boxes=(\d+) whole_tile_skips=(\d+).*?" r"classification_worker_ms=([0-9.]+)" ) VIOLATION = re.compile(r"\[UniformBlockProofViolation\]") def run(view: int, position: int, offset: tuple[int, int]) -> dict: base = CAMERAS[view] camera = ",".join(f"{value:.12f}" for value in (base[0] + offset[0], base[1] + offset[1], base[2])) + ",0,0" log = OUT / f"audit-s{view}-p{position:02d}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BIN), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--audit-uniform-block-proofs", "--profile-lod-work", ] started = time.monotonic() with log.open("w", encoding="utf-8") as output: result = subprocess.run(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") audit = AUDIT.search(content) tile = TILE.search(content) if result.returncode != 0 or audit is None or tile is None: raise SystemExit(f"audit run failed or summary is missing; see {log}") checked, samples, fallback, unknown, violations = map(int, audit.groups()) solid, air, mixed, tile_unknown, tile_skips = map(int, tile.groups()[:5]) classifier_ms = float(tile.group(6)) violation_lines = len(VIOLATION.findall(content)) row = { "strate": view, "position": position, "offset_m": list(offset), "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "checked_blocks": checked, "checked_samples": samples, "fallback_blocks": fallback, "unknown_blocks": unknown, "violations": violations + violation_lines, "block_proof_hit_pct": round(100.0 * checked / max(checked + fallback, 1), 2), "tile_solid_boxes": solid, "tile_air_boxes": air, "tile_mixed_boxes": mixed, "tile_unknown_boxes": tile_unknown, "tile_whole_skips": tile_skips, "classification_worker_ms": classifier_ms, "log": str(log.relative_to(ROOT)), } print("[L75AuditSweepRun] " + json.dumps(row, sort_keys=True), flush=True) if row["violations"] != 0: raise SystemExit(f"uniform block proof violation; see {log}") return row def main() -> int: OUT.mkdir(parents=True, exist_ok=True) if not DATA.is_file() or not BIN.is_file(): raise SystemExit("missing owner world or L75 Clang headless binary") rows = [run(view, index, offset) for view in range(4) for index, offset in enumerate(OFFSETS)] summary = [] for view in range(4): group = [row for row in rows if row["strate"] == view] checked = sum(row["checked_blocks"] for row in group) fallback = sum(row["fallback_blocks"] for row in group) costs = [row["classification_worker_ms"] for row in group] summary.append({ "strate": view, "positions": len(group), "violations": sum( row["violations"] for row in group), "checked_blocks": checked, "fallback_blocks": fallback, "proof_hit_pct": round( 100.0 * checked / max(checked + fallback, 1), 2), "classifier_ms_p50": round(statistics.median(costs), 3), "classifier_ms_p95": round(sorted(costs)[int(0.95 * (len(costs) - 1))], 3), }) if any(row["checked_blocks"] == 0 for row in summary): raise SystemExit("block interval audit did not check a proof block for every strate") result = {"runs": rows, "summary": summary} (OUT / "audit-sweep.json").write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") for row in summary: print("[L75AuditSweepSummary] " + json.dumps(row, sort_keys=True), flush=True) return 0 if __name__ == "__main__": raise SystemExit(main())