fix(data,verifier): key trajectories by CAS and read precomputed targets
Browse files- FragranceTrajectoryDataset now prefers record['objective_targets'] and
record['psychometric_targets'] when present.
- Verifier now keys trajectory step dicts by CAS, matching the dataset lookup.
- Add scripts/inspect_thermo_env.py to audit registry/VLE interfaces.
- scripts/inspect_thermo_env.py +88 -0
- src/pino/pimt_model.py +13 -3
- src/pino/verifier.py +2 -2
scripts/inspect_thermo_env.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import json
|
| 5 |
+
import sqlite3
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
| 10 |
+
|
| 11 |
+
from pino.thermo import vle as vle_module
|
| 12 |
+
from pino.registry import AromaRegistry
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main() -> None:
|
| 16 |
+
print("=" * 60)
|
| 17 |
+
print("PINO Thermodynamic Environment Audit")
|
| 18 |
+
print("=" * 60)
|
| 19 |
+
|
| 20 |
+
# 1. Registry source and format
|
| 21 |
+
print("\n[1] Registry Source")
|
| 22 |
+
aroma_jsonl = Path("data/aroma_chemicals.jsonl")
|
| 23 |
+
registry_db = Path("src/pino/registry.db")
|
| 24 |
+
|
| 25 |
+
if aroma_jsonl.exists():
|
| 26 |
+
print(f" - Found {aroma_jsonl} ({aroma_jsonl.stat().st_size / 1024:.1f} KB)")
|
| 27 |
+
with aroma_jsonl.open("r") as f:
|
| 28 |
+
line = f.readline().strip()
|
| 29 |
+
sample = json.loads(line)
|
| 30 |
+
print(f" - Top-level keys: {sorted(sample.keys())}")
|
| 31 |
+
else:
|
| 32 |
+
print(f" - {aroma_jsonl} NOT FOUND")
|
| 33 |
+
|
| 34 |
+
if registry_db.exists():
|
| 35 |
+
print(f" - Found {registry_db} ({registry_db.stat().st_size / 1024:.1f} KB)")
|
| 36 |
+
conn = sqlite3.connect(registry_db)
|
| 37 |
+
conn.row_factory = sqlite3.Row
|
| 38 |
+
rows = conn.execute("PRAGMA table_info(aroma_chemicals)").fetchall()
|
| 39 |
+
print(" - SQLite columns:")
|
| 40 |
+
for row in rows:
|
| 41 |
+
print(f" {row['name']}: {row['type']}")
|
| 42 |
+
count = conn.execute("SELECT COUNT(*) FROM aroma_chemicals").fetchone()[0]
|
| 43 |
+
print(f" - Row count: {count}")
|
| 44 |
+
else:
|
| 45 |
+
print(f" - {registry_db} NOT FOUND")
|
| 46 |
+
|
| 47 |
+
# 2. VLE module interface
|
| 48 |
+
print("\n[2] VLE Module Interface")
|
| 49 |
+
for name, obj in inspect.getmembers(vle_module):
|
| 50 |
+
if inspect.isclass(obj):
|
| 51 |
+
print(f" - class {name}")
|
| 52 |
+
for method_name, method in inspect.getmembers(obj, predicate=inspect.isfunction):
|
| 53 |
+
sig = inspect.signature(method)
|
| 54 |
+
print(f" {method_name}{sig}")
|
| 55 |
+
|
| 56 |
+
# 3. AromaRegistry interface
|
| 57 |
+
print("\n[3] AromaRegistry Interface")
|
| 58 |
+
registry = AromaRegistry()
|
| 59 |
+
print(f" - db_path: {registry.path}")
|
| 60 |
+
methods = [
|
| 61 |
+
name
|
| 62 |
+
for name in dir(registry)
|
| 63 |
+
if not name.startswith("_") and callable(getattr(registry, name))
|
| 64 |
+
]
|
| 65 |
+
print(f" - Public methods: {methods}")
|
| 66 |
+
|
| 67 |
+
# 4. Sample rows
|
| 68 |
+
print("\n[4] Sample Registry Rows")
|
| 69 |
+
sample_rows = registry._conn.execute("SELECT * FROM aroma_chemicals LIMIT 3").fetchall()
|
| 70 |
+
for row in sample_rows:
|
| 71 |
+
record = dict(row)
|
| 72 |
+
record["unifac_groups"] = json.loads(record.get("unifac_groups") or "{}")
|
| 73 |
+
record["openpom_embedding"] = json.loads(record.get("openpom_embedding") or "[]")
|
| 74 |
+
record["shape_3d_features"] = json.loads(record.get("shape_3d_features") or "[]")
|
| 75 |
+
print(f" - {record.get('cas')}: {record.keys()}")
|
| 76 |
+
print(f" name={record.get('name')}")
|
| 77 |
+
print(f" smiles={record.get('smiles')}")
|
| 78 |
+
print(f" openpom_len={len(record.get('openpom_embedding', []))}")
|
| 79 |
+
print(f" shape_3d_len={len(record.get('shape_3d_features', []))}")
|
| 80 |
+
print(f" unifac_groups={record.get('unifac_groups')}")
|
| 81 |
+
|
| 82 |
+
print("\n" + "=" * 60)
|
| 83 |
+
print("Audit complete.")
|
| 84 |
+
print("=" * 60)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
main()
|
src/pino/pimt_model.py
CHANGED
|
@@ -105,9 +105,19 @@ class FragranceTrajectoryDataset(Dataset):
|
|
| 105 |
states[t, j, 1] = np.log10(max(oav, 1e-10))
|
| 106 |
|
| 107 |
strategy = record.get("metadata", {}).get("generation_strategy", "wildcard")
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
from .semantics import get_psychometric_targets
|
| 112 |
psychometric_targets = get_psychometric_targets(strategy)
|
| 113 |
|
|
|
|
| 105 |
states[t, j, 1] = np.log10(max(oav, 1e-10))
|
| 106 |
|
| 107 |
strategy = record.get("metadata", {}).get("generation_strategy", "wildcard")
|
| 108 |
+
|
| 109 |
+
# Prefer precomputed empirical targets when present; otherwise fall back to
|
| 110 |
+
# the synthetic genre-based generators.
|
| 111 |
+
if "objective_targets" in record:
|
| 112 |
+
objective_targets = np.array(record["objective_targets"], dtype=np.float32)
|
| 113 |
+
else:
|
| 114 |
+
objective_targets = get_objective_targets(strategy, t_steps)
|
| 115 |
+
|
| 116 |
+
if "psychometric_targets" in record:
|
| 117 |
+
psychometric_targets = np.array(record["psychometric_targets"], dtype=np.float32)
|
| 118 |
+
elif self.label_noise:
|
| 119 |
+
psychometric_targets = sample_noisy_psychometric_targets(strategy)
|
| 120 |
+
else:
|
| 121 |
from .semantics import get_psychometric_targets
|
| 122 |
psychometric_targets = get_psychometric_targets(strategy)
|
| 123 |
|
src/pino/verifier.py
CHANGED
|
@@ -183,9 +183,9 @@ class FragrancePipelineVerifier:
|
|
| 183 |
|
| 184 |
@staticmethod
|
| 185 |
def _trajectory_to_records(trajectory: Trajectory) -> list[dict[str, Any]]:
|
| 186 |
-
"""Convert a Trajectory object into a list of JSON-serializable records."""
|
| 187 |
records: list[dict[str, Any]] = []
|
| 188 |
-
species = [ing.
|
| 189 |
for i, t in enumerate(trajectory.t):
|
| 190 |
records.append({
|
| 191 |
"t_s": float(t),
|
|
|
|
| 183 |
|
| 184 |
@staticmethod
|
| 185 |
def _trajectory_to_records(trajectory: Trajectory) -> list[dict[str, Any]]:
|
| 186 |
+
"""Convert a Trajectory object into a list of JSON-serializable records keyed by CAS."""
|
| 187 |
records: list[dict[str, Any]] = []
|
| 188 |
+
species = [ing.cas for ing in trajectory.formula.ingredients]
|
| 189 |
for i, t in enumerate(trajectory.t):
|
| 190 |
records.append({
|
| 191 |
"t_s": float(t),
|