Skip to content

Commit fb37742

Browse files
committed
Lock dense calibration and replay analysis
1 parent c981630 commit fb37742

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎active_solvai/scripts/calibrate_dense_models.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
RESPONSES = ACTIVE_ROOT / "results/phase2/dense_responses_calibration.parquet"
2323
PHASE1_PRIORS = ACTIVE_ROOT / "results/phase1/phase1_response_predictions.parquet"
2424
OUT = ACTIVE_ROOT / "release/DENSE_SENTINEL_CALIBRATION_LOCK.json"
25+
OUT_MD = ACTIVE_ROOT / "release/DENSE_SENTINEL_CALIBRATION_LOCK.md"
2526

2627

2728
def load_priors(names: list[str], grid: np.ndarray) -> dict[str, np.ndarray]:
@@ -53,6 +54,13 @@ def nlpd(y: np.ndarray, mean: np.ndarray, variance: np.ndarray) -> float:
5354

5455

5556
def main() -> None:
57+
prospective_energy = list(
58+
(ACTIVE_ROOT / "simulations/dense_pimd2/prospective").glob("**/output/*__SYSTEM.ene")
59+
)
60+
if prospective_energy:
61+
raise AssertionError(
62+
"Prospective sentinel responses already exist; calibration lock must precede them"
63+
)
5664
config = json.loads(CONFIG.read_text())
5765
grid = np.asarray(config["lambda_grid"], dtype=float)
5866
initial = np.array([2, 6, 12], dtype=int)
@@ -150,10 +158,27 @@ def main() -> None:
150158
"calibration_responses": {"path": str(RESPONSES), "sha256": sha256(RESPONSES)},
151159
"phase1_priors": {"path": str(PHASE1_PRIORS), "sha256": sha256(PHASE1_PRIORS)},
152160
"search_table": {"path": str(search_path), "sha256": sha256(search_path)},
161+
"calibration_script": {
162+
"path": str(Path(__file__).resolve()),
163+
"sha256": sha256(Path(__file__).resolve()),
164+
},
153165
},
154166
"note": "No prospective sentinel dense response was generated or read before this lock.",
155167
}
156168
OUT.write_text(json.dumps(payload, indent=2) + "\n")
169+
OUT_MD.write_text(
170+
"# Dense sentinel calibration lock\n\n"
171+
"This file records the automatically selected Gaussian-process settings before any "
172+
"prospective-sentinel dense response was generated. Selection followed the committed "
173+
"protocol in `DENSE_SENTINEL_FREEZE.md`; no setting was selected using endpoint error.\n\n"
174+
f"- Calibration response SHA-256: `{payload['inputs']['calibration_responses']['sha256']}`\n"
175+
f"- Phase 1 prior SHA-256: `{payload['inputs']['phase1_priors']['sha256']}`\n"
176+
f"- Generic prior: length scale `{selected['generic']['lengthscale']}`, noise inflation "
177+
f"`{selected['generic']['noise_inflation']}`, amplitude `{selected['generic']['amplitude']:.8f}` kcal mol^-1.\n"
178+
f"- SolvAI-conditioned prior: length scale `{selected['solvai']['lengthscale']}`, noise inflation "
179+
f"`{selected['solvai']['noise_inflation']}`, amplitude `{selected['solvai']['amplitude']:.8f}` kcal mol^-1.\n"
180+
"- Prospective dense responses available at lock time: `0`.\n"
181+
)
157182
print(json.dumps(payload, indent=2))
158183

159184

‎active_solvai/scripts/collect_dense_sentinel.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,23 @@ def main() -> None:
3636
manifest = pd.read_csv(args.root / "manifest.csv")
3737
if args.role != "all":
3838
manifest = manifest.loc[manifest.role.eq(args.role)]
39+
passed_cases: set[str] = set()
40+
roles = sorted(manifest.loc[~manifest.existing_observation, "role"].unique())
41+
for role in roles:
42+
status_path = args.root / f"run_status_{role}.csv"
43+
if status_path.exists():
44+
status = pd.read_csv(status_path)
45+
passed_cases.update(
46+
status.loc[
47+
status.passed.astype(str).str.lower().eq("true"), "case_directory"
48+
].astype(str)
49+
)
3950
records: list[dict[str, object]] = []
4051
missing: list[str] = []
4152
for row in manifest.to_dict("records"):
53+
if not bool(row["existing_observation"]) and str(row["case_directory"]) not in passed_cases:
54+
missing.append(f"No passed QC record for {row['molecule_name']} lambda={row['lambda']}")
55+
continue
4256
try:
4357
energy = find_energy(row)
4458
except FileNotFoundError as error:

‎active_solvai/scripts/evaluate_dense_sentinel.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def replay_record(
144144
indices = np.asarray(selected, dtype=int)
145145
weights = trapezoid_weights(grid)
146146
true_integral = -float(weights @ truth_curve)
147+
dense_integral_sem = float(np.sqrt(np.sum((weights * sem) ** 2)))
147148
if direct:
148149
curve = observed_pchip(grid, indices, truth_curve[indices])
149150
predicted_integral = -float(weights @ curve)
@@ -175,6 +176,7 @@ def replay_record(
175176
"total_windows": len(indices),
176177
"observed_lambdas": ",".join(f"{grid[index]:g}" for index in indices),
177178
"true_integral_kcal_mol": true_integral,
179+
"dense_integral_sem_kcal_mol": dense_integral_sem,
178180
"predicted_integral_kcal_mol": predicted_integral,
179181
"signed_integral_error_kcal_mol": predicted_integral - true_integral,
180182
"absolute_integral_error_kcal_mol": abs(predicted_integral - true_integral),
@@ -227,9 +229,7 @@ def main() -> None:
227229
solvai_settings["lengthscale"],
228230
local,
229231
)
230-
generic_expected_noise = (
231-
expected_sem**2 * generic_settings["noise_inflation"]
232-
)
232+
generic_expected_noise = expected_sem**2 * generic_settings["noise_inflation"]
233233
solvai_expected_noise = expected_sem**2 * solvai_settings["noise_inflation"]
234234
schedules: list[tuple[str, int, list[int], np.ndarray, np.ndarray, float, bool]] = [
235235
(

0 commit comments

Comments
 (0)