Matthew Ford commited on
Commit
2ff3288
·
1 Parent(s): 5131a8b

feat: freeze representation validation gate

Browse files

Former-commit-id: cba5c0c4668a075841e657ce7a4bb4381cd6471b
Former-commit-id: 283db0e617f67b58706af0afb4ba13c297909a2a

TODO.md CHANGED
@@ -31,11 +31,11 @@ applicable) are committed. Results are recorded even when they are negative.
31
 
32
  ## Completion evidence
33
 
34
- - [ ] Frozen-feature ablation manifest and report:
35
  `artifacts/representation_ablation/`
36
- - [ ] Discordant triplet manifest and report:
37
  `data/benchmarks/substitution_triplets/`
38
- - [ ] Prospective formula manifest and blinded evaluation package:
39
  `data/benchmarks/prospective_formulas/`
40
- - [ ] Training-readiness gate report:
41
  `artifacts/training_readiness.json`
 
31
 
32
  ## Completion evidence
33
 
34
+ - [x] Frozen-feature ablation manifest and report (blocked; no real POM asset):
35
  `artifacts/representation_ablation/`
36
+ - [x] Discordant triplet manifest and report (zero admitted; independent labels required):
37
  `data/benchmarks/substitution_triplets/`
38
+ - [x] Prospective formula protocol and blinded evaluation package (formula design pending):
39
  `data/benchmarks/prospective_formulas/`
40
+ - [x] Training-readiness gate report (currently `DO_NOT_TRAIN`):
41
  `artifacts/training_readiness.json`
artifacts/representation_ablation/manifest.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "exclusions": [
3
+ {
4
+ "feature": "aroma_chemicals.openpom_embedding",
5
+ "reason": "no provenance field or real model asset; implementation generates 128-bit Morgan plus 10 physicochemical descriptors"
6
+ }
7
+ ],
8
+ "frozen_at": "2026-07-16T00:00:00+00:00",
9
+ "frozen_method": {
10
+ "folds": "five deterministic grouped folds; CAS and formula families may not cross folds",
11
+ "metrics": "Spearman rho/MAE for continuous; macro-F1/AUROC for categorical",
12
+ "missing_values": "exclude a row from all representations if any preregistered input is missing",
13
+ "probe": "standardized ridge regression for continuous targets; logistic ridge for categorical targets",
14
+ "row_policy": "complete-case intersection per task, fixed before representation access",
15
+ "selection": "regularization selected by nested CV using training folds only",
16
+ "uncertainty": "paired fold deltas with percentile bootstrap 95% CI"
17
+ },
18
+ "representations": {
19
+ "morgan": {
20
+ "available": true,
21
+ "definition": "RDKit Morgan radius=2"
22
+ },
23
+ "pom_plus_physics": {
24
+ "available": false,
25
+ "definition": "real_pom concatenated with preregistered physical features"
26
+ },
27
+ "real_pom": {
28
+ "available": false,
29
+ "definition": "independently loaded pretrained POM model output"
30
+ }
31
+ },
32
+ "results": null,
33
+ "schema_version": 1,
34
+ "status": "blocked_missing_real_pom",
35
+ "tasks": [
36
+ "descriptor",
37
+ "odor_threshold",
38
+ "substantivity",
39
+ "substitution"
40
+ ]
41
+ }
artifacts/representation_ablation/report.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Frozen representation ablation
2
+
3
+ Status: **blocked — real POM unavailable**.
4
+
5
+ The row/fold/probe/missingness protocol is frozen in `manifest.json`. No metrics were computed because the repository's `openpom_embedding` values are an unprovenanced Morgan-plus-physicochemical fallback. Reporting them as POM would invalidate every paired comparison.
artifacts/training_readiness.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "blockers": [
3
+ "real_pom_available",
4
+ "ablation_complete",
5
+ "triplet_count_positive",
6
+ "prospective_formula_count_30_to_50"
7
+ ],
8
+ "checks": {
9
+ "ablation_complete": false,
10
+ "prospective_formula_count_30_to_50": false,
11
+ "prospective_labels_sequestered": true,
12
+ "real_pom_available": false,
13
+ "triplet_count_positive": false
14
+ },
15
+ "decision": "DO_NOT_TRAIN",
16
+ "generated_at": "2026-07-16T00:00:00+00:00",
17
+ "ready_for_training": false,
18
+ "schema_version": 1
19
+ }
data/benchmarks/prospective_formulas/assessor_protocol.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "assessor_package_must_omit": [
3
+ "model identity",
4
+ "predictions",
5
+ "training membership"
6
+ ],
7
+ "assessors": "independent blinded assessors",
8
+ "labels_file": "labels.private.jsonl (must remain outside training/model-selection inputs)",
9
+ "outcomes": [
10
+ "target_attribute_accuracy",
11
+ "balance",
12
+ "diffusion",
13
+ "drydown_fidelity"
14
+ ],
15
+ "randomization": "independent concealed code and randomized presentation order",
16
+ "reporting": "all pass, fail, missing, and inconclusive outcomes",
17
+ "timepoints": [
18
+ "blotter_initial",
19
+ "blotter_2h",
20
+ "blotter_24h"
21
+ ]
22
+ }
data/benchmarks/prospective_formulas/formulas.jsonl ADDED
File without changes
data/benchmarks/prospective_formulas/labels.private.template.jsonl ADDED
File without changes
data/benchmarks/prospective_formulas/manifest.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "blinding": {
3
+ "assessor_package_must_omit": [
4
+ "model identity",
5
+ "predictions",
6
+ "training membership"
7
+ ],
8
+ "labels_file": "labels.private.jsonl (must remain outside training/model-selection inputs)",
9
+ "randomization": "independent concealed code and randomized presentation order"
10
+ },
11
+ "design_requirements": [
12
+ "formula identity",
13
+ "design rationale",
14
+ "target attributes",
15
+ "pass/fail rules"
16
+ ],
17
+ "evaluation": {
18
+ "assessors": "independent blinded assessors",
19
+ "outcomes": [
20
+ "target_attribute_accuracy",
21
+ "balance",
22
+ "diffusion",
23
+ "drydown_fidelity"
24
+ ],
25
+ "reporting": "all pass, fail, missing, and inconclusive outcomes",
26
+ "timepoints": [
27
+ "blotter_initial",
28
+ "blotter_2h",
29
+ "blotter_24h"
30
+ ]
31
+ },
32
+ "formula_count": 0,
33
+ "frozen_at": "2026-07-16T00:00:00+00:00",
34
+ "required_formula_count": {
35
+ "maximum": 50,
36
+ "minimum": 30
37
+ },
38
+ "schema_version": 1,
39
+ "status": "protocol_frozen_formulas_pending"
40
+ }
data/benchmarks/substitution_triplets/manifest.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "admission": {
3
+ "discordance_rule": "Morgan/Tanimoto(target,distractor) must exceed Morgan/Tanimoto(target,preferred)",
4
+ "identity_rule": "all three identities require CAS or canonical SMILES",
5
+ "preference_rule": "independent comparative perceptual evidence must prefer substitute over distractor",
6
+ "required_fields": [
7
+ "target",
8
+ "preferred_substitute",
9
+ "structural_distractor",
10
+ "preference_provenance"
11
+ ]
12
+ },
13
+ "admitted_triplet_count": 0,
14
+ "frozen_at": "2026-07-16T00:00:00+00:00",
15
+ "label_access": "evaluation_only; forbidden in training and model selection",
16
+ "reason": "Existing substitution pairs do not include independently evidenced comparative distractors.",
17
+ "schema_version": 1,
18
+ "status": "blocked_no_admissible_triplets"
19
+ }
data/benchmarks/substitution_triplets/report.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Discordant substitution triplets
2
+
3
+ Status: **blocked**. Zero triplets were admitted. The existing pairwise supplier claims cannot establish that a particular structurally closer distractor is perceptually worse.
data/benchmarks/substitution_triplets/triplets.jsonl ADDED
File without changes
scripts/freeze_representation_validation.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Freeze representation-validation protocols and compute the readiness gate.
3
+
4
+ This intentionally never invents labels or treats fallback fingerprints as POM.
5
+ It is safe to rerun: output is deterministic apart from ``generated_at``.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import hashlib
11
+ import json
12
+ from datetime import datetime, timezone
13
+ from pathlib import Path
14
+ from typing import Any
15
+
16
+ ROOT = Path(__file__).resolve().parents[1]
17
+
18
+
19
+ def digest(path: Path) -> str:
20
+ return hashlib.sha256(path.read_bytes()).hexdigest()
21
+
22
+
23
+ def write_json(path: Path, value: Any) -> None:
24
+ path.parent.mkdir(parents=True, exist_ok=True)
25
+ path.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n")
26
+
27
+
28
+ def freeze(now: str) -> dict[str, Any]:
29
+ ablation_dir = ROOT / "artifacts/representation_ablation"
30
+ triplet_dir = ROOT / "data/benchmarks/substitution_triplets"
31
+ formula_dir = ROOT / "data/benchmarks/prospective_formulas"
32
+
33
+ ablation = {
34
+ "schema_version": 1,
35
+ "frozen_at": now,
36
+ "status": "blocked_missing_real_pom",
37
+ "representations": {
38
+ "morgan": {"definition": "RDKit Morgan radius=2", "available": True},
39
+ "real_pom": {"definition": "independently loaded pretrained POM model output", "available": False},
40
+ "pom_plus_physics": {"definition": "real_pom concatenated with preregistered physical features", "available": False},
41
+ },
42
+ "tasks": ["descriptor", "odor_threshold", "substantivity", "substitution"],
43
+ "frozen_method": {
44
+ "row_policy": "complete-case intersection per task, fixed before representation access",
45
+ "folds": "five deterministic grouped folds; CAS and formula families may not cross folds",
46
+ "probe": "standardized ridge regression for continuous targets; logistic ridge for categorical targets",
47
+ "selection": "regularization selected by nested CV using training folds only",
48
+ "metrics": "Spearman rho/MAE for continuous; macro-F1/AUROC for categorical",
49
+ "uncertainty": "paired fold deltas with percentile bootstrap 95% CI",
50
+ "missing_values": "exclude a row from all representations if any preregistered input is missing",
51
+ },
52
+ "exclusions": [{
53
+ "feature": "aroma_chemicals.openpom_embedding",
54
+ "reason": "no provenance field or real model asset; implementation generates 128-bit Morgan plus 10 physicochemical descriptors",
55
+ }],
56
+ "results": None,
57
+ }
58
+ write_json(ablation_dir / "manifest.json", ablation)
59
+ (ablation_dir / "report.md").write_text(
60
+ "# Frozen representation ablation\n\n"
61
+ "Status: **blocked — real POM unavailable**.\n\n"
62
+ "The row/fold/probe/missingness protocol is frozen in `manifest.json`. No metrics "
63
+ "were computed because the repository's `openpom_embedding` values are an unprovenanced "
64
+ "Morgan-plus-physicochemical fallback. Reporting them as POM would invalidate every paired comparison.\n"
65
+ )
66
+
67
+ triplets = {
68
+ "schema_version": 1,
69
+ "frozen_at": now,
70
+ "status": "blocked_no_admissible_triplets",
71
+ "label_access": "evaluation_only; forbidden in training and model selection",
72
+ "admission": {
73
+ "required_fields": ["target", "preferred_substitute", "structural_distractor", "preference_provenance"],
74
+ "preference_rule": "independent comparative perceptual evidence must prefer substitute over distractor",
75
+ "discordance_rule": "Morgan/Tanimoto(target,distractor) must exceed Morgan/Tanimoto(target,preferred)",
76
+ "identity_rule": "all three identities require CAS or canonical SMILES",
77
+ },
78
+ "admitted_triplet_count": 0,
79
+ "reason": "Existing substitution pairs do not include independently evidenced comparative distractors.",
80
+ }
81
+ write_json(triplet_dir / "manifest.json", triplets)
82
+ (triplet_dir / "triplets.jsonl").write_text("")
83
+ (triplet_dir / "report.md").write_text(
84
+ "# Discordant substitution triplets\n\nStatus: **blocked**. Zero triplets were admitted. "
85
+ "The existing pairwise supplier claims cannot establish that a particular structurally closer distractor is perceptually worse.\n"
86
+ )
87
+
88
+ formula_protocol = {
89
+ "schema_version": 1,
90
+ "frozen_at": now,
91
+ "status": "protocol_frozen_formulas_pending",
92
+ "required_formula_count": {"minimum": 30, "maximum": 50},
93
+ "design_requirements": ["formula identity", "design rationale", "target attributes", "pass/fail rules"],
94
+ "blinding": {
95
+ "assessor_package_must_omit": ["model identity", "predictions", "training membership"],
96
+ "randomization": "independent concealed code and randomized presentation order",
97
+ "labels_file": "labels.private.jsonl (must remain outside training/model-selection inputs)",
98
+ },
99
+ "evaluation": {
100
+ "assessors": "independent blinded assessors",
101
+ "timepoints": ["blotter_initial", "blotter_2h", "blotter_24h"],
102
+ "outcomes": ["target_attribute_accuracy", "balance", "diffusion", "drydown_fidelity"],
103
+ "reporting": "all pass, fail, missing, and inconclusive outcomes",
104
+ },
105
+ "formula_count": 0,
106
+ }
107
+ write_json(formula_dir / "manifest.json", formula_protocol)
108
+ (formula_dir / "formulas.jsonl").write_text("")
109
+ (formula_dir / "labels.private.template.jsonl").write_text("")
110
+ write_json(formula_dir / "assessor_protocol.json", formula_protocol["evaluation"] | formula_protocol["blinding"])
111
+
112
+ checks = {
113
+ "real_pom_available": False,
114
+ "ablation_complete": False,
115
+ "triplet_count_positive": False,
116
+ "prospective_formula_count_30_to_50": False,
117
+ "prospective_labels_sequestered": True,
118
+ }
119
+ gate = {
120
+ "schema_version": 1,
121
+ "generated_at": now,
122
+ "ready_for_training": all(checks.values()),
123
+ "checks": checks,
124
+ "decision": "DO_NOT_TRAIN",
125
+ "blockers": [name for name, passed in checks.items() if not passed],
126
+ }
127
+ write_json(ROOT / "artifacts/training_readiness.json", gate)
128
+ return gate
129
+
130
+
131
+ def main() -> int:
132
+ parser = argparse.ArgumentParser()
133
+ parser.add_argument("--timestamp", help="ISO-8601 timestamp for reproducible freezing")
134
+ args = parser.parse_args()
135
+ now = args.timestamp or datetime.now(timezone.utc).isoformat()
136
+ gate = freeze(now)
137
+ print(json.dumps(gate, indent=2, sort_keys=True))
138
+ return 0 if gate["ready_for_training"] else 2
139
+
140
+
141
+ if __name__ == "__main__":
142
+ raise SystemExit(main())
src/pino/embeddings.py CHANGED
@@ -14,6 +14,10 @@ from .thermo.naturals import OPENPOM_DIM, SHAPE_DIM, resolve_natural_oil_vectors
14
 
15
  logger = logging.getLogger("pino.embeddings")
16
 
 
 
 
 
17
  STRUCTURAL_DIM = OPENPOM_DIM # 138
18
  SHAPE_DIM = SHAPE_DIM # 7
19
  PHYSICAL_DIM = 2 # molecular_weight, logp
@@ -108,9 +112,11 @@ class OlfactoryEmbeddingEngine:
108
  return float(np.median([r[0] for r in rows]))
109
 
110
  def _initialize_real_openpom(self) -> None:
111
- # Placeholder for future on-disk GNN model loading.
112
- logger.warning("Real OpenPOM model not available; enabling fallback automatically")
113
- self.use_fallback = True
 
 
114
 
115
  def _normalized_cas(self, cas: str | None) -> str:
116
  return str(cas).replace("NATURAL:", "").strip() if cas else ""
 
14
 
15
  logger = logging.getLogger("pino.embeddings")
16
 
17
+
18
+ class RealOpenPOMUnavailableError(RuntimeError):
19
+ """Raised when a caller requires real POM features but no model is loaded."""
20
+
21
  STRUCTURAL_DIM = OPENPOM_DIM # 138
22
  SHAPE_DIM = SHAPE_DIM # 7
23
  PHYSICAL_DIM = 2 # molecular_weight, logp
 
112
  return float(np.median([r[0] for r in rows]))
113
 
114
  def _initialize_real_openpom(self) -> None:
115
+ # Fail closed. Silently substituting Morgan features here makes a
116
+ # Morgan-vs-POM ablation compare the same representation under two names.
117
+ raise RealOpenPOMUnavailableError(
118
+ "Real OpenPOM model is not configured; use_fallback=False cannot be satisfied"
119
+ )
120
 
121
  def _normalized_cas(self, cas: str | None) -> str:
122
  return str(cas).replace("NATURAL:", "").strip() if cas else ""
tests/test_representation_validation.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import subprocess
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ import pytest
7
+
8
+ from pino.embeddings import OlfactoryEmbeddingEngine, RealOpenPOMUnavailableError
9
+
10
+
11
+ ROOT = Path(__file__).resolve().parents[1]
12
+
13
+
14
+ def test_real_pom_requirement_fails_closed():
15
+ with pytest.raises(RealOpenPOMUnavailableError, match="not configured"):
16
+ OlfactoryEmbeddingEngine(use_fallback=False)
17
+
18
+
19
+ def test_freeze_protocol_emits_failed_gate():
20
+ result = subprocess.run(
21
+ [sys.executable, "scripts/freeze_representation_validation.py", "--timestamp", "2026-07-16T00:00:00+00:00"],
22
+ cwd=ROOT,
23
+ text=True,
24
+ capture_output=True,
25
+ )
26
+ assert result.returncode == 2
27
+ gate = json.loads((ROOT / "artifacts/training_readiness.json").read_text())
28
+ assert gate["ready_for_training"] is False
29
+ assert gate["decision"] == "DO_NOT_TRAIN"
30
+ manifest = json.loads((ROOT / "artifacts/representation_ablation/manifest.json").read_text())
31
+ assert manifest["representations"]["real_pom"]["available"] is False
32
+ assert manifest["results"] is None