#!/usr/bin/env python3 """Combine the initial and repeat L31 interleaved cost batches.""" import csv import statistics from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l31" sources = ( ("first", 0, OUT / "cost-first/cost-runs.csv"), ("repeat", 5, OUT / "cost-runs.csv"), ) rows = [] for batch, offset, path in sources: with path.open(newline="", encoding="utf-8") as stream: for row in csv.DictReader(stream): row["pair"] = str(int(row["pair"]) + offset) row["source_batch"] = batch rows.append(row) with (OUT / "cost-combined.csv").open("w", newline="", encoding="utf-8") as stream: writer = csv.DictWriter(stream, fieldnames=( "recipe", "pair", "build", "whole_view_ready_seconds", "process_elapsed_seconds", "exit_code", "status", "source_batch")) writer.writeheader() writer.writerows(rows) print("recipe pairs median_l30_s median_l31_s median_change_pct paired_median_pct range_pct") failed = False for recipe in ("surface-world", "floating-islands"): by_build = { build: [float(row["whole_view_ready_seconds"]) for row in rows if row["recipe"] == recipe and row["build"] == build] for build in ("l30", "l31") } paired = [] for pair in range(1, 11): times = { row["build"]: float(row["whole_view_ready_seconds"]) for row in rows if row["recipe"] == recipe and int(row["pair"]) == pair } paired.append((times["l31"] / times["l30"] - 1.0) * 100.0) median_l30 = statistics.median(by_build["l30"]) median_l31 = statistics.median(by_build["l31"]) median_change = (median_l31 / median_l30 - 1.0) * 100.0 print(f"{recipe} 10 {median_l30:.3f} {median_l31:.3f} {median_change:+.2f} " f"{statistics.median(paired):+.2f} {min(paired):+.2f}..{max(paired):+.2f}") failed |= len(by_build["l30"]) != 10 or len(by_build["l31"]) != 10 print(f"[L31CostCombined] pairs_per_recipe=10 runs={len(rows)} " f"status={'FAIL' if failed else 'PASS'} summary={OUT / 'cost-combined.csv'}") raise SystemExit(1 if failed or len(rows) != 40 else 0)