Archive 4 checkpoints (1-4)
Browse files- paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_figure4_sources.py +52 -0
- paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_figure5_details.py +26 -0
- paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_import_scsemi_legacy.py +103 -0
- paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_legacy_export_dispatch.py +37 -0
paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_figure4_sources.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Legacy contrast files must not silently stand in for corrected Figure 4 data."""
|
| 2 |
+
import importlib.util
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
PATH = Path(__file__).resolve().parents[1] / "tools/build_results_figures.py"
|
| 11 |
+
spec = importlib.util.spec_from_file_location("figure4_sources", PATH)
|
| 12 |
+
figures = importlib.util.module_from_spec(spec)
|
| 13 |
+
spec.loader.exec_module(figures)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_missing_corrected_signal_renders_pending_even_if_legacy_headline_exists(tmp_path, monkeypatch):
|
| 17 |
+
monkeypatch.setattr(figures, "ROOT", tmp_path)
|
| 18 |
+
old = tmp_path / "source_data/fig4_strict_contrast.csv"
|
| 19 |
+
old.parent.mkdir()
|
| 20 |
+
old.write_text("cohort,arm,partial_r\nye2026_sepsis,lora,0.99\n")
|
| 21 |
+
saved = []
|
| 22 |
+
def save(fig, name):
|
| 23 |
+
saved.append(name)
|
| 24 |
+
figures.plt.close(fig)
|
| 25 |
+
monkeypatch.setattr(figures, "save", save)
|
| 26 |
+
rows, reasons = figures.donor_signal_panels({c: [] for c in figures.COHORTS})
|
| 27 |
+
assert not rows and reasons
|
| 28 |
+
assert len(saved) == 4
|
| 29 |
+
assert "fig4_disease_signal_strict" in saved
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def test_corrected_provenance_must_cover_all_twenty_canonical_supports(tmp_path, monkeypatch):
|
| 33 |
+
monkeypatch.setattr(figures, "ROOT", tmp_path)
|
| 34 |
+
path = tmp_path / "source_data/fig4_donor_aware_provenance.json"
|
| 35 |
+
path.parent.mkdir()
|
| 36 |
+
path.write_text(json.dumps({"schema": "pbisc.fig4.donor-aware-signal.v1", "status": "complete", "units": {}}))
|
| 37 |
+
with pytest.raises(ValueError, match="support differs"):
|
| 38 |
+
figures.donor_signal_panels({c: [] for c in figures.COHORTS})
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def test_actual_historical_comparison_uses_real_bulk_lora_and_scsemi_and_excludes_giroux_sex_genes():
|
| 42 |
+
rows, gaps = figures.historical_fivefold_rows()
|
| 43 |
+
assert not gaps
|
| 44 |
+
assert len(rows) == 16
|
| 45 |
+
for cohort in figures.COHORTS:
|
| 46 |
+
sub = [r for r in rows if r["cohort"] == cohort]
|
| 47 |
+
pair = {r["arm"]: r for r in sub}
|
| 48 |
+
assert pair["lora"]["source_arm"] == "real_lora__raw"
|
| 49 |
+
assert pair["scsemi"]["source_arm"] == "scsemi__raw"
|
| 50 |
+
assert pair["lora"]["reference_sha256"] == pair["scsemi"]["reference_sha256"]
|
| 51 |
+
if cohort == "giroux2022":
|
| 52 |
+
assert all("scores_nosex" in r["source"] and r["gene_exclusion_sha256"] for r in sub)
|
paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_figure5_details.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
import sys
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools'))
|
| 7 |
+
from figure5_details import all_state_metrics
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_zero_states_remain_detection_outcomes_not_abundance_auc():
|
| 11 |
+
base = dict(cohort='a',unit='draw0',arm='lora',state='rare')
|
| 12 |
+
donor = pd.DataFrame([{**base,'donor_id':'A','obs_state':2,'gen_state':0},
|
| 13 |
+
{**base,'donor_id':'B','obs_state':0,'gen_state':1},
|
| 14 |
+
{**base,'donor_id':'C','obs_state':1,'gen_state':1}])
|
| 15 |
+
summary = pd.DataFrame([{**base,'high_low_abundance_auroc':.7}])
|
| 16 |
+
row = all_state_metrics(donor,summary).iloc[0]
|
| 17 |
+
assert row.missed_observed_fraction == .5
|
| 18 |
+
assert row.generated_in_observed_zero_fraction == 1
|
| 19 |
+
assert row.high_low_abundance_auroc == .7
|
| 20 |
+
assert row.n_evaluable_donors == 3
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_visits_cannot_be_counted_as_donors():
|
| 24 |
+
base = dict(cohort='a',unit='draw0',arm='lora',state='rare',donor_id='A',obs_state=1,gen_state=0)
|
| 25 |
+
with pytest.raises(ValueError,match='repeated visits'):
|
| 26 |
+
all_state_metrics(pd.DataFrame([base,base]),pd.DataFrame())
|
paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_import_scsemi_legacy.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regression gates for adopting a prior five-pair scSemi sepsis run."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 11 |
+
SPEC = importlib.util.spec_from_file_location("import_scsemi_legacy", ROOT / "tools/import_scsemi_legacy.py")
|
| 12 |
+
assert SPEC and SPEC.loader
|
| 13 |
+
I = importlib.util.module_from_spec(SPEC)
|
| 14 |
+
SPEC.loader.exec_module(I)
|
| 15 |
+
SUPPORT = ROOT / "protocol/splits/ye2026_sepsis/disease/draw0/support.json"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_only_canonical_sepsis_disease_draw_is_accepted(tmp_path: Path) -> None:
|
| 19 |
+
assert I.paths(SUPPORT)[0]["unit"] == "draw0_n5"
|
| 20 |
+
copied = tmp_path / "support.json"
|
| 21 |
+
copied.write_text(SUPPORT.read_text())
|
| 22 |
+
with pytest.raises(ValueError, match="noncanonical"):
|
| 23 |
+
I.paths(copied)
|
| 24 |
+
other = ROOT / "protocol/splits/ji2025_chili/disease/draw0/support.json"
|
| 25 |
+
with pytest.raises(ValueError, match="limited to five sepsis"):
|
| 26 |
+
I.paths(other)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_draw0_exact_five_own_hvg_and_source_receipts() -> None:
|
| 30 |
+
proof = I.verify(SUPPORT)
|
| 31 |
+
assert proof["status"] == "verified_source_not_native_strict_run"
|
| 32 |
+
assert len(proof["model_sha256"]) == 10
|
| 33 |
+
assert len(proof["target_shard_sha256"]) == 77
|
| 34 |
+
assert len(proof["prepared_assets_equal"]) == 15
|
| 35 |
+
assert "hvset.npy" in proof["prepared_assets_equal"]
|
| 36 |
+
assert len(proof["source_sample_sc_cleaned_after_training"]) == 5
|
| 37 |
+
assert proof["source_provenance"]["approved_migration"] is not None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_reuse_cv_metadata_fails_closed(monkeypatch) -> None:
|
| 41 |
+
original = I.read
|
| 42 |
+
old = I.paths(SUPPORT)[1]
|
| 43 |
+
source_inputs = old / "inputs/inputs_manifest.json"
|
| 44 |
+
|
| 45 |
+
def altered(path: Path) -> dict:
|
| 46 |
+
value = original(path)
|
| 47 |
+
if path == source_inputs:
|
| 48 |
+
return {**value, "reuse_cv": "/larger/reference"}
|
| 49 |
+
return value
|
| 50 |
+
|
| 51 |
+
monkeypatch.setattr(I, "read", altered)
|
| 52 |
+
with pytest.raises(ValueError, match="reused another run"):
|
| 53 |
+
I.verify(SUPPORT)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_all_five_exports_are_source_bound_and_independently_validated() -> None:
|
| 57 |
+
for draw in range(5):
|
| 58 |
+
support = ROOT / f"protocol/splits/ye2026_sepsis/disease/draw{draw}/support.json"
|
| 59 |
+
s, source_work, strict_work, source_output = I.paths(support)
|
| 60 |
+
adoption_path = strict_work / "adopted_legacy/ADOPTION.json"
|
| 61 |
+
adoption = json.loads(adoption_path.read_text())
|
| 62 |
+
output = ROOT / f"generated/ye2026_sepsis/disease/draw{draw}/scsemi.npz"
|
| 63 |
+
receipt = json.loads(output.with_suffix(".log").read_text())
|
| 64 |
+
validation = json.loads(output.with_suffix(".validation.json").read_text())
|
| 65 |
+
assert output.samefile(source_output)
|
| 66 |
+
assert adoption["status"] == "verified_source_not_native_strict_run"
|
| 67 |
+
assert adoption["support_sha256"] == s["sha256"]
|
| 68 |
+
assert len(adoption["model_sha256"]) == 10
|
| 69 |
+
assert len(adoption["target_shard_sha256"]) == len(s["test_sample_ids"]) == 77
|
| 70 |
+
assert receipt["schema"] == "pbisc.scsemi.adopted-output.v1"
|
| 71 |
+
assert receipt["source_work"] == str(source_work)
|
| 72 |
+
assert receipt["source_output"] == str(source_output)
|
| 73 |
+
assert receipt["output_sha256"] == I.sha(output)
|
| 74 |
+
assert validation["passed"] is True
|
| 75 |
+
assert validation["npz_sha256"] == receipt["output_sha256"]
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_adopted_generation_returns_strict_scorer_binding() -> None:
|
| 79 |
+
support = json.loads(SUPPORT.read_text())
|
| 80 |
+
output = ROOT / "generated/ye2026_sepsis/disease/draw0/scsemi.npz"
|
| 81 |
+
binding = I.validate_adopted_generation(output, support)
|
| 82 |
+
assert binding["arm"] == "scsemi"
|
| 83 |
+
assert binding["source_kind"] == "verified_legacy_scsemi_adoption"
|
| 84 |
+
assert binding["support_sha256"] == support["sha256"]
|
| 85 |
+
assert binding["source_binding"].endswith("/adopted_legacy/ADOPTION.json")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_adopted_generation_rejects_wrong_path_or_receipt(monkeypatch) -> None:
|
| 89 |
+
support = json.loads(SUPPORT.read_text())
|
| 90 |
+
output = ROOT / "generated/ye2026_sepsis/disease/draw0/scsemi.npz"
|
| 91 |
+
with pytest.raises(ValueError, match="canonical adopted output"):
|
| 92 |
+
I.validate_adopted_generation(ROOT / "generated/ye2026_sepsis/disease/draw1/scsemi.npz", support)
|
| 93 |
+
original = I.read
|
| 94 |
+
|
| 95 |
+
def altered(path: Path) -> dict:
|
| 96 |
+
record = original(path)
|
| 97 |
+
if path == output.with_suffix(".log"):
|
| 98 |
+
return {**record, "condition_sha256": "0" * 64}
|
| 99 |
+
return record
|
| 100 |
+
|
| 101 |
+
monkeypatch.setattr(I, "read", altered)
|
| 102 |
+
with pytest.raises(ValueError, match="adopted output receipt differs"):
|
| 103 |
+
I.validate_adopted_generation(output, support)
|
paper-releases/pbisc-diffusion/updates/20261012T130738Z-strictpairs-implementation/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/archive/20261012T130738Z-strictpairs-implementation/snapshot/tests/test_legacy_export_dispatch.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.util
|
| 2 |
+
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import unittest
|
| 5 |
+
|
| 6 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 7 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 8 |
+
LEGACY = ROOT.parent / "paired_finetune_intradataset_20260927/scsemi/tools/export_npz.py"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class DispatchTests(unittest.TestCase):
|
| 12 |
+
def module(self):
|
| 13 |
+
spec = importlib.util.spec_from_file_location("legacy_export_dispatch", LEGACY)
|
| 14 |
+
mod = importlib.util.module_from_spec(spec)
|
| 15 |
+
spec.loader.exec_module(mod)
|
| 16 |
+
self.assertTrue(hasattr(mod, "strict_export_arguments"), "strict mode has no safe exporter dispatch")
|
| 17 |
+
return mod
|
| 18 |
+
|
| 19 |
+
def test_legacy_modes_stay_on_original_exporter(self):
|
| 20 |
+
mod = self.module()
|
| 21 |
+
for mode in ("fewshot", "cv", "budget"):
|
| 22 |
+
self.assertIsNone(mod.strict_export_arguments({"mode": mode}, Path("work"), Path("out.npz")))
|
| 23 |
+
|
| 24 |
+
def test_strict_support_path_comes_from_bound_condition_location(self):
|
| 25 |
+
mod = self.module()
|
| 26 |
+
cond = ROOT / "data/immicro/healthy/fold0/n5/test_raw.npz"
|
| 27 |
+
args = mod.strict_export_arguments({"mode": "strict", "condition_npz": str(cond)}, ROOT / "scsemi/x", ROOT / "g.npz")
|
| 28 |
+
self.assertEqual(args[-1], str(ROOT / "protocol/splits/immicro/healthy/fold0/n5/support.json"))
|
| 29 |
+
|
| 30 |
+
def test_unrelated_condition_cannot_dispatch_to_strict_plan(self):
|
| 31 |
+
mod = self.module()
|
| 32 |
+
with self.assertRaises(ValueError):
|
| 33 |
+
mod.strict_export_arguments({"mode": "strict", "condition_npz": "/tmp/unbound.npz"}, Path("work"), Path("out"))
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
unittest.main()
|