- scripts/11: check_rids guard; scripts 14/15 accept the protocol_p2r main grid (realizations 8-15) only when protocol_p2r and its inputs match the locked SHA-256 - scripts/run_p2r_main.sh: per-regime pipelines (posterior then training) on cuda:0/cuda:1 - scripts/18_summarize_p2r.py: H2a / H2b / H3 / sigma_a verdicts per the locked rules - docs/plan.md, report.html: H2a and H2b pass, sigma_a arm fails, no Pivot 1 - logs/index.csv: run records of the P2r grid Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import yaml
|
|
|
|
from ml_porosity.paths import REPO_ROOT
|
|
|
|
CONFIGS = REPO_ROOT / "configs"
|
|
|
|
|
|
def test_d2_p2r_generator_matches_p2():
|
|
"""protocol_p2r uses the protocol_p2 D2 generator: only the regimes block may be added."""
|
|
p2 = yaml.safe_load((CONFIGS / "d2_synth.yaml").read_text())
|
|
p2r = yaml.safe_load((CONFIGS / "d2_synth_p2r.yaml").read_text())
|
|
regimes = p2r.pop("regimes")
|
|
assert p2r == p2
|
|
assert all(set(r) == {"snr_db", "anchor_density"} for r in regimes.values())
|
|
|
|
|
|
def test_p2r_regimes_and_realizations():
|
|
P = yaml.safe_load((CONFIGS / "protocol_p2r.yaml").read_text())
|
|
regimes = yaml.safe_load((REPO_ROOT / P["inputs"]["d2_config"]["path"]).read_text())["regimes"]
|
|
assert set(P["grid"]["regimes"]) <= set(regimes)
|
|
p2 = yaml.safe_load((CONFIGS / "protocol_p2.yaml").read_text())["grid"]
|
|
used = set(p2["realizations"]) | set(p2["dev_realizations"])
|
|
assert not used & set(P["grid"]["realizations"])
|
|
|
|
|
|
def test_locked_protocols_match_sha256():
|
|
"""Locked protocols must not change after locking (a change needs a new version)."""
|
|
import hashlib
|
|
|
|
for name in ["protocol_p2", "protocol_p2r"]:
|
|
sha, path = (CONFIGS / f"{name}.sha256").read_text().split()
|
|
assert hashlib.sha256((REPO_ROOT / path).read_bytes()).hexdigest() == sha
|
|
|
|
|
|
def test_p2r_inputs_match_sha256():
|
|
import hashlib
|
|
|
|
P = yaml.safe_load((CONFIGS / "protocol_p2r.yaml").read_text())
|
|
for key in ["d2_config", "budgets", "warp_prior", "wavelet"]:
|
|
f = REPO_ROOT / P["inputs"][key]["path"]
|
|
if not f.exists(): # outputs/ is not versioned
|
|
continue
|
|
assert hashlib.sha256(f.read_bytes()).hexdigest() == P["inputs"][key]["sha256"], key
|
|
|
|
|
|
def test_check_rids_guards_main_grids():
|
|
"""Scripts 14/15 refuse protocol_p2 main-grid realizations and never mix the protocol_p2r main grid with dev."""
|
|
import importlib.util
|
|
|
|
import pytest
|
|
|
|
spec = importlib.util.spec_from_file_location("run_d2", REPO_ROOT / "scripts" / "11_run_d2.py")
|
|
run_d2 = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(run_d2)
|
|
P = yaml.safe_load((CONFIGS / "protocol_p2.yaml").read_text())
|
|
assert run_d2.check_rids([900, 901], P) is None
|
|
for rids in ([0], [8, 900]):
|
|
with pytest.raises(SystemExit):
|
|
run_d2.check_rids(rids, P)
|