P2 diagnosis on dev, P3 dev experiments, lock protocol_p3

- P2: SMC tie posterior (numpy + torch), RML/soft-DTW losses, bank training,
  D2 synthetic generator, scripts 09-13, protocol_p2 (locked) and its outcome
  (G-B failed; H1 not rejected, H3 rejected, H4 not rejected).
- Diagnosis on dev realizations 900/901 only (scripts 14-17, run_p3_dev.sh):
  posterior screen, SMC stability (P = 1024, K = 1), sigma_a misspecification
  stress and training, H3 with the SMC posterior, F3 placement on sigma_post.
- protocol_p3: H2 split into H2a (posterior-mean labels vs point ties) and
  H2b (RML vs posterior mean as a function of sigma_post); H3 descriptive only;
  sigma_a arm; new D2 config d2_synth_p3.yaml; main grid on realizations 8-15.
  Locked by configs/protocol_p3.sha256 and tag protocol-p3.
- runlog: per-run logs and runtime index (logs/index.csv).
- Docs: plan §12 items 10-11, theory, technical overview, report; wording
  aligned with Gunning & Glinsky (2006): the tie posterior is not claimed as new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 06:03:33 +00:00
parent a76e61398a
commit cee2ff0859
84 changed files with 8793 additions and 460 deletions

43
tests/test_protocol.py Normal file
View File

@@ -0,0 +1,43 @@
import yaml
from ml_porosity.paths import REPO_ROOT
CONFIGS = REPO_ROOT / "configs"
def test_d2_p3_generator_matches_p2():
"""protocol_p3 uses the protocol_p2 D2 generator: only the regimes block may be added."""
p2 = yaml.safe_load((CONFIGS / "d2_synth.yaml").read_text())
p3 = yaml.safe_load((CONFIGS / "d2_synth_p3.yaml").read_text())
regimes = p3.pop("regimes")
assert p3 == p2
assert all(set(r) == {"snr_db", "anchor_density"} for r in regimes.values())
def test_p3_regimes_and_realizations():
P = yaml.safe_load((CONFIGS / "protocol_p3.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_p3"]:
sha, path = (CONFIGS / f"{name}.sha256").read_text().split()
assert hashlib.sha256((REPO_ROOT / path).read_bytes()).hexdigest() == sha
def test_p3_inputs_match_sha256():
import hashlib
P = yaml.safe_load((CONFIGS / "protocol_p3.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