#!/usr/bin/env python3 """Keep the L74 false-solid TN lattice sample under a permanent block audit.""" from __future__ import annotations import json import os import re 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" PROBE = (-80, -20, -3218) EXPECTED_DENSITY = 0.063384 CAMERA_METERS = (19.266015625, -14.1001953125, -753.3740234375) REGRESSION = re.compile(r"\[L75TNBlockRegression\] (.*)") AUDIT = re.compile(r"\[UniformBlockProofAudit\] checked_blocks=(\d+) checked_samples=(\d+) " r"fallback_blocks=(\d+) unknown_blocks=(\d+) violations=(\d+)") PAIR = re.compile(r"([a-zA-Z0-9_]+)=([^ ]+)") def main() -> int: if not DATA.is_file() or not BIN.is_file(): raise SystemExit("missing owner world or L75 Clang headless binary") OUT.mkdir(parents=True, exist_ok=True) camera = ",".join(f"{value:.12f}" for value in CAMERA_METERS) + ",0,0" log = OUT / "tn-block-regression.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BIN), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--stream-hash-tiles", "--audit-uniform-block-proofs", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", ] environment = os.environ.copy() environment["VOXELFORGE_L75_TN_BLOCK_REGRESSION"] = "1" started = time.monotonic() with log.open("w", encoding="utf-8") as output: result = subprocess.run(command, cwd=ROOT, env=environment, stdout=output, stderr=subprocess.STDOUT, check=False, timeout=1740) content = log.read_text(encoding="utf-8", errors="replace") probes = [] for line in content.splitlines(): match = REGRESSION.search(line) if match: row = dict(PAIR.findall(match.group(1))) row.update(density=float(row["density"]), proof_safe=int(row["proof_safe"])) row["tile_origin"] = tuple(int(value) for value in row["tile_origin"].strip("()").split(",")) probes.append(row) audit_match = AUDIT.search(content) if not probes or audit_match is None: raise SystemExit(f"TN regression did not cover the target lattice sample; see {log}") checked, samples, fallback, unknown, violations = map(int, audit_match.groups()) density_matches = all(abs(row["density"] - EXPECTED_DENSITY) <= 1.0e-6 for row in probes) false_solid_proofs = sum(row["proof_safe"] and row["verdict"] == "solid" for row in probes) row = { "probe": PROBE, "expected_density": EXPECTED_DENSITY, "observed_densities": [probe["density"] for probe in probes], "block_intervals": [{key: probe[key] for key in ("tile_origin", "step", "block", "verdict", "proof_safe", "unknown")} for probe in probes], "checked_blocks": checked, "checked_samples": samples, "fallback_blocks": fallback, "unknown_blocks": unknown, "violations": violations, "false_solid_proofs": false_solid_proofs, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), } (OUT / "tn-block-regression.json").write_text(json.dumps(row, indent=2) + "\n", encoding="utf-8") print("[L75TNRegression] " + json.dumps(row, sort_keys=True), flush=True) if result.returncode != 0 or not density_matches or false_solid_proofs or violations: raise SystemExit(f"TN block regression failed; see {log}") return 0 if __name__ == "__main__": raise SystemExit(main())