#!/usr/bin/env python3 """Run five interleaved W12 whole-view pairs against the final L30 binary.""" import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l31" OUT.mkdir(parents=True, exist_ok=True) BINARIES = { "l30": ROOT / "Saved/Linux/l30/bin/VoxelForgeCoreHeadless-linux30-speed-fade", "l31": OUT / "bin/VoxelForgeCoreHeadless-linux31-clang", } ORDERS = (("l30", "l31"), ("l31", "l30"), ("l30", "l31"), ("l31", "l30"), ("l30", "l31")) READY = re.compile(r"\bwhole_view_ready=([0-9.]+)s") rows = [] failed = False for recipe in ("surface-world", "floating-islands"): for pair, order in enumerate(ORDERS, 1): for build in order: name = f"cost-{recipe}-pair{pair}-{build}" logfile = OUT / f"{name}.log" command = [ str(BINARIES[build]), str(ROOT / "Standalone/data/owner_world.json"), "--workers=12", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=-1", f"--recipe={recipe}", ] started = time.monotonic() try: with logfile.open("w", encoding="utf-8") as stream: result = subprocess.run(command, stdout=stream, stderr=subprocess.STDOUT, timeout=1800, check=False) except subprocess.TimeoutExpired: result = None elapsed = time.monotonic() - started text = logfile.read_text(encoding="utf-8", errors="replace") matches = READY.findall(text) if build == "l31": stamps = re.findall( r"^\[WorldAssemblerRecipeAudit\] requested=([^ ]+) actual=([^ ]+).*status=([^ ]+)$", text, re.M) actual_recipe = stamps[0][1] if len(stamps) == 1 else "missing" stamp_ok = stamps == [(recipe, recipe, "PASS")] else: configured = re.findall( r"^\[HeadlessConfig\].*\brecipe=([^\s]+)", text, re.M) actual_recipe = configured[0] if len(configured) == 1 else "missing" floating_plan = "[FloatingIslandWorldAssembly]" in text surface_plan = "[WorldAssemblerPrototype]" in text plan_matches = ((actual_recipe == "floating-islands" and floating_plan) or (actual_recipe == "surface-world" and not floating_plan and surface_plan)) marker = (f"[L31BaselineRecipeAudit] requested={recipe} actual={actual_recipe} " f"headless_recipe={configured[0] if len(configured) == 1 else 'missing'} " f"floating_island_plan={'present' if floating_plan else 'absent'} " f"surface_world_plan={'present' if surface_plan else 'absent'} " f"status={'PASS' if actual_recipe == recipe and plan_matches else 'FAIL'}\n") with logfile.open("a", encoding="utf-8") as stream: stream.write(marker) text += marker stamp_ok = (actual_recipe == recipe and plan_matches and len(configured) == 1) valid = (result is not None and result.returncode == 0 and len(matches) == 1 and "hash=off" in text and "cache_hits=0" in text) if build == "l31": valid = valid and stamp_ok and actual_recipe == recipe else: valid = valid and stamp_ok and "status=PASS" in marker ready = float(matches[0]) if len(matches) == 1 else float("nan") rows.append((recipe, pair, build, ready, elapsed, result.returncode if result else "TIMEOUT", valid)) print(f"{recipe} pair={pair} build={build} whole_view_ready={ready:.3f}s " f"process_elapsed={elapsed:.1f}s {'PASS' if valid else 'FAIL'}", flush=True) failed |= not valid summary = OUT / "cost-runs.csv" summary.write_text( "recipe,pair,build,whole_view_ready_seconds,process_elapsed_seconds,exit_code,status\n" + "".join(f"{recipe},{pair},{build},{ready:.6f},{elapsed:.3f},{code}," f"{'PASS' if ok else 'FAIL'}\n" for recipe, pair, build, ready, elapsed, code, ok in rows), encoding="utf-8") for recipe in ("surface-world", "floating-islands"): by_build = {build: [row[3] for row in rows if row[0] == recipe and row[2] == build] for build in BINARIES} l30 = statistics.median(by_build["l30"]) l31 = statistics.median(by_build["l31"]) paired = [] for pair in range(1, 6): values = {row[2]: row[3] for row in rows if row[0] == recipe and row[1] == pair} paired.append((values["l31"] - values["l30"]) / values["l30"] * 100.0) print(f"[L31CostSummary] recipe={recipe} pairs=5 median_l30_s={l30:.3f} " f"median_l31_s={l31:.3f} median_change_pct={(l31/l30-1)*100.0:+.2f} " f"paired_change_pct={','.join(f'{value:+.2f}' for value in paired)}", flush=True) print(f"[L31Cost] runs={len(rows)} status={'FAIL' if failed else 'PASS'} summary={summary}", flush=True) raise SystemExit(1 if failed or len(rows) != 20 else 0)