proef 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proef/__init__.py +25 -0
- proef/acquisition.py +244 -0
- proef/ad.py +159 -0
- proef/adapters/__init__.py +0 -0
- proef/adapters/admet.py +196 -0
- proef/adapters/bio/__init__.py +0 -0
- proef/adapters/bio/rdkit_ops.py +52 -0
- proef/adapters/bio/safety_rules.json +146 -0
- proef/adapters/bio/seq_alerts.py +79 -0
- proef/adapters/bio/structure_score.py +85 -0
- proef/adapters/bio/tox_alerts.py +99 -0
- proef/adapters/data/__init__.py +0 -0
- proef/adapters/data/admet.py +62 -0
- proef/adapters/data/chembl.py +110 -0
- proef/adapters/data/frozen/admet/MANIFEST.json +48 -0
- proef/adapters/data/frozen/admet/bbb_martins/test.csv +407 -0
- proef/adapters/data/frozen/admet/bbb_martins/train_val.csv +1625 -0
- proef/adapters/data/frozen/admet/caco2_wang/test.csv +183 -0
- proef/adapters/data/frozen/admet/caco2_wang/train_val.csv +729 -0
- proef/adapters/data/frozen/admet/hia_hou/test.csv +118 -0
- proef/adapters/data/frozen/admet/hia_hou/train_val.csv +462 -0
- proef/adapters/data/moleculenet.py +60 -0
- proef/adapters/databases/__init__.py +0 -0
- proef/adapters/databases/chembl_gates.py +121 -0
- proef/adapters/databases/chembl_lookup.py +35 -0
- proef/adapters/databases/open_targets.py +102 -0
- proef/adapters/databases/pubmed.py +94 -0
- proef/adapters/devices/__init__.py +0 -0
- proef/adapters/devices/ezo_ph.py +251 -0
- proef/adapters/devices/hcs_microscope.py +143 -0
- proef/adapters/devices/lcms.py +123 -0
- proef/adapters/devices/scheduler.py +84 -0
- proef/adapters/devices/sila2.py +134 -0
- proef/adapters/genomics/alphagenome.py +146 -0
- proef/adapters/lab/__init__.py +0 -0
- proef/adapters/lab/bioprocess.py +32 -0
- proef/adapters/lab/devices.py +170 -0
- proef/adapters/lab/imaging.py +226 -0
- proef/adapters/lab/mhs_driver.py +124 -0
- proef/adapters/lab/opentrons.py +222 -0
- proef/adapters/lab/ot2_sim.py +174 -0
- proef/adapters/lab/plate_reader_share.py +108 -0
- proef/adapters/lab/protein_design.py +199 -0
- proef/adapters/lab/recording.py +119 -0
- proef/adapters/lab/replay.py +107 -0
- proef/adapters/lab/simulator.py +282 -0
- proef/adapters/lab/synthesis.py +92 -0
- proef/adapters/models/__init__.py +0 -0
- proef/adapters/models/anthropic_provider.py +157 -0
- proef/adapters/models/assayloop_ranker.py +67 -0
- proef/adapters/models/from_env.py +93 -0
- proef/adapters/models/gp_policy.py +93 -0
- proef/adapters/models/gp_policy_gp.py +36 -0
- proef/adapters/models/llm_policy.py +187 -0
- proef/adapters/models/openai_compat.py +150 -0
- proef/adapters/models/sklearn_policy.py +65 -0
- proef/adapters/retrosynthesis.py +247 -0
- proef/adapters/sandbox/__init__.py +20 -0
- proef/adapters/sandbox/agentenv.py +145 -0
- proef/adapters/sandbox/docker.py +217 -0
- proef/adapters/sandbox/local.py +164 -0
- proef/adapters/sandbox/opensandbox.py +122 -0
- proef/adapters/store/__init__.py +0 -0
- proef/adapters/store/sqlite.py +207 -0
- proef/adaptive.py +108 -0
- proef/advisory.py +76 -0
- proef/analysis_profiles/__init__.py +8 -0
- proef/analysis_profiles/measurements.py +266 -0
- proef/analysis_profiles/plate_assay.py +316 -0
- proef/analysis_report.py +195 -0
- proef/analysis_store.py +183 -0
- proef/anchor.py +154 -0
- proef/api/app.py +107 -0
- proef/api/launch.py +170 -0
- proef/api/v1/__init__.py +29 -0
- proef/api/v1/analyses.py +367 -0
- proef/api/v1/campaigns.py +802 -0
- proef/api/v1/deps.py +10 -0
- proef/api/v1/evals.py +16 -0
- proef/api/v1/evidence.py +132 -0
- proef/api/v1/governance.py +35 -0
- proef/api/v1/inbox.py +119 -0
- proef/api/v1/lab.py +110 -0
- proef/api/v1/pauses.py +77 -0
- proef/api/v1/programs.py +397 -0
- proef/api/v1/results.py +147 -0
- proef/api/v1/schemas.py +932 -0
- proef/api/v1/system.py +79 -0
- proef/api/v1/trees.py +216 -0
- proef/api/wizard_sessions.py +253 -0
- proef/approvals.py +102 -0
- proef/assays/__init__.py +15 -0
- proef/assays/dls.py +114 -0
- proef/assays/dsf.py +81 -0
- proef/assays/elisa.py +58 -0
- proef/assays/properties.py +65 -0
- proef/assays/simulate.py +157 -0
- proef/audit.py +152 -0
- proef/autoloop.py +1620 -0
- proef/benchmark.py +442 -0
- proef/campaign_fsm.py +151 -0
- proef/citations.py +141 -0
- proef/cli.py +1249 -0
- proef/connect.py +74 -0
- proef/core/__init__.py +0 -0
- proef/core/contracts/__init__.py +35 -0
- proef/core/contracts/analysis.py +100 -0
- proef/core/contracts/models.py +395 -0
- proef/core/device_card.py +125 -0
- proef/core/hypothesis.py +720 -0
- proef/core/interfaces.py +164 -0
- proef/core/registry.py +123 -0
- proef/core/safety.py +324 -0
- proef/core/workflow.py +159 -0
- proef/critic.py +62 -0
- proef/demo.py +164 -0
- proef/derivation.py +128 -0
- proef/diary.py +301 -0
- proef/eln.py +87 -0
- proef/evals/__init__.py +1 -0
- proef/evals/hallucination.py +86 -0
- proef/evals/harness.py +358 -0
- proef/evals/orchestration.py +254 -0
- proef/evals/tasks.py +1010 -0
- proef/evals/toolcalls.py +425 -0
- proef/experiment.py +172 -0
- proef/experiment_analysis.py +114 -0
- proef/experiments/__init__.py +0 -0
- proef/experiments/grounding_exp.py +689 -0
- proef/figures.py +218 -0
- proef/fitting.py +309 -0
- proef/fixtures.py +140 -0
- proef/flywheel.py +125 -0
- proef/followup.py +126 -0
- proef/governance.py +290 -0
- proef/groundedness.py +361 -0
- proef/grounding.py +202 -0
- proef/hypothesis_agent.py +369 -0
- proef/ingest.py +157 -0
- proef/instruments.json +173 -0
- proef/interpret.py +95 -0
- proef/kinetic.py +102 -0
- proef/labread/__init__.py +45 -0
- proef/labread/analysis.py +428 -0
- proef/labread/common.py +153 -0
- proef/labread/formats.py +190 -0
- proef/labread/layout.py +168 -0
- proef/labread/pubchem.py +179 -0
- proef/labselect.py +431 -0
- proef/materials.py +140 -0
- proef/mcp_instrument.py +396 -0
- proef/mcp_server.py +283 -0
- proef/modality.py +111 -0
- proef/model_guard.py +245 -0
- proef/output_blocks.py +183 -0
- proef/paths.py +32 -0
- proef/physfail.py +55 -0
- proef/plan.py +160 -0
- proef/plots.py +123 -0
- proef/predictors.py +217 -0
- proef/probes.py +79 -0
- proef/problem_tree.py +581 -0
- proef/program.py +308 -0
- proef/protocol_design.py +42 -0
- proef/proxy.py +78 -0
- proef/readiness.py +259 -0
- proef/reliability.py +49 -0
- proef/report.py +117 -0
- proef/reproduce.py +310 -0
- proef/reviewer.py +254 -0
- proef/sandbox_session.py +247 -0
- proef/sandboxd.py +109 -0
- proef/scaffold.py +195 -0
- proef/series.py +327 -0
- proef/skills.py +203 -0
- proef/sweep.py +83 -0
- proef/taste.py +177 -0
- proef/templates/confirmatory-followup.json +34 -0
- proef/templates/dose-response-screen.json +39 -0
- proef/templates/sar-exploration.json +38 -0
- proef/templates.py +124 -0
- proef/toolkit.py +433 -0
- proef/toolloop.py +133 -0
- proef/tools.py +441 -0
- proef/tpp.py +185 -0
- proef/views/__init__.py +14 -0
- proef/views/counts.py +102 -0
- proef/views/experiment.py +154 -0
- proef/views/ids.py +49 -0
- proef/views/narrative.py +294 -0
- proef/views/pipeline.py +370 -0
- proef/vision.py +165 -0
- proef/watch.py +790 -0
- proef/wizard_chain.py +25 -0
- proef/wizard_store.py +373 -0
- proef-0.2.0.dist-info/METADATA +662 -0
- proef-0.2.0.dist-info/RECORD +200 -0
- proef-0.2.0.dist-info/WHEEL +4 -0
- proef-0.2.0.dist-info/entry_points.txt +14 -0
- proef-0.2.0.dist-info/licenses/LICENSE +202 -0
proef/readiness.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""ExperimentReadinessReview — decide whether an experiment, if it succeeds,
|
|
2
|
+
would support its claim.
|
|
3
|
+
|
|
4
|
+
The review runs BEFORE the lab is engaged. It separates:
|
|
5
|
+
|
|
6
|
+
blockers the result would be uninterpretable or unsafe; the experiment
|
|
7
|
+
must be redesigned, not merely re-run
|
|
8
|
+
warnings interpretability caveats attached to the result
|
|
9
|
+
passes structural checks that cleared
|
|
10
|
+
|
|
11
|
+
This is the scientific counterpart of the SafetyEngine: the SafetyEngine
|
|
12
|
+
decides whether an action is *allowed*; the readiness review decides whether
|
|
13
|
+
the action is *worth running* given the claim it is supposed to support.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from enum import Enum
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, Field
|
|
21
|
+
|
|
22
|
+
from proef.core.contracts import Envelope, EventType
|
|
23
|
+
from proef.core.interfaces import ProvenanceStore, record_for
|
|
24
|
+
from proef.experiment import (
|
|
25
|
+
ClaimType,
|
|
26
|
+
ExperimentDefinition,
|
|
27
|
+
ReadoutCapability,
|
|
28
|
+
)
|
|
29
|
+
from proef.kinetic import InteinPairConfig, check_intein_pair
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ReviewVerdict(str, Enum):
|
|
33
|
+
ready = "ready"
|
|
34
|
+
ready_with_warnings = "ready_with_warnings"
|
|
35
|
+
blocked = "blocked"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ReadinessFinding(BaseModel):
|
|
39
|
+
check: str
|
|
40
|
+
severity: str # "pass" | "warning" | "blocker"
|
|
41
|
+
message: str
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ExperimentReadinessReview(BaseModel):
|
|
45
|
+
experiment_id: str | None = None
|
|
46
|
+
hypothesis_id: str | None = None
|
|
47
|
+
verdict: ReviewVerdict
|
|
48
|
+
findings: list[ReadinessFinding] = Field(default_factory=list)
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def blockers(self) -> list[ReadinessFinding]:
|
|
52
|
+
return [f for f in self.findings if f.severity == "blocker"]
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def warnings(self) -> list[ReadinessFinding]:
|
|
56
|
+
return [f for f in self.findings if f.severity == "warning"]
|
|
57
|
+
|
|
58
|
+
def summary(self) -> str:
|
|
59
|
+
lines = [f"verdict: {self.verdict.value}"]
|
|
60
|
+
for f in self.findings:
|
|
61
|
+
lines.append(f" [{f.severity}] {f.check}: {f.message}")
|
|
62
|
+
return "\n".join(lines)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# --------------------------------------------------------------- the review
|
|
66
|
+
|
|
67
|
+
# Claims that require the readout to distinguish edited from unedited target
|
|
68
|
+
# (the "missing denominator" problem).
|
|
69
|
+
_DENOMINATOR_CLAIMS = {
|
|
70
|
+
ClaimType.loss_of_function,
|
|
71
|
+
ClaimType.causal_modification,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Claims that require an authentic modification, not a phosphomimetic or
|
|
75
|
+
# other surrogate.
|
|
76
|
+
_AUTHENTIC_MODIFICATION_CLAIMS = {
|
|
77
|
+
ClaimType.causal_modification,
|
|
78
|
+
ClaimType.occupancy_vs_catalysis,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def review_experiment(defn: ExperimentDefinition,
|
|
83
|
+
available_caps: dict | None = None) -> ExperimentReadinessReview:
|
|
84
|
+
findings: list[ReadinessFinding] = []
|
|
85
|
+
|
|
86
|
+
def add(check: str, ok: bool, warning_only: bool, message: str) -> None:
|
|
87
|
+
if ok:
|
|
88
|
+
findings.append(ReadinessFinding(check=check, severity="pass", message=message))
|
|
89
|
+
elif warning_only:
|
|
90
|
+
findings.append(ReadinessFinding(check=check, severity="warning", message=message))
|
|
91
|
+
else:
|
|
92
|
+
findings.append(ReadinessFinding(check=check, severity="blocker", message=message))
|
|
93
|
+
|
|
94
|
+
# 1. the claim must be statable
|
|
95
|
+
add("scientific_question", bool(defn.scientific_question.strip()), False,
|
|
96
|
+
"scientific question is stated" if defn.scientific_question.strip()
|
|
97
|
+
else "no scientific question is stated")
|
|
98
|
+
|
|
99
|
+
# 2. the readout must be able to support the claim type
|
|
100
|
+
r = defn.readout
|
|
101
|
+
if defn.claim_type in _DENOMINATOR_CLAIMS and not r.measures_edited_fraction:
|
|
102
|
+
add("edited_fraction_denominator", False, False,
|
|
103
|
+
"claim requires an edited-vs-unedited denominator, but the readout "
|
|
104
|
+
"does not quantify the edited fraction; negative results would be "
|
|
105
|
+
"uninterpretable")
|
|
106
|
+
else:
|
|
107
|
+
add("edited_fraction_denominator", True, True,
|
|
108
|
+
"edited fraction accounted for" if r.measures_edited_fraction
|
|
109
|
+
else "not required for this claim type")
|
|
110
|
+
|
|
111
|
+
if defn.claim_type in _AUTHENTIC_MODIFICATION_CLAIMS and \
|
|
112
|
+
not r.distinguishes_modified_from_mimetic:
|
|
113
|
+
add("authentic_modification", False, False,
|
|
114
|
+
"claim requires an authentic modification, but the readout cannot "
|
|
115
|
+
"distinguish it from a mimetic")
|
|
116
|
+
else:
|
|
117
|
+
add("authentic_modification", True, True,
|
|
118
|
+
"authentic modification distinguishable" if defn.claim_type in
|
|
119
|
+
_AUTHENTIC_MODIFICATION_CLAIMS else "not required for this claim type")
|
|
120
|
+
|
|
121
|
+
# 3. kinetic compatibility: target turnover vs experiment window
|
|
122
|
+
half_life = defn.system.target_half_life_min
|
|
123
|
+
if half_life is not None and half_life < 30 and \
|
|
124
|
+
defn.claim_type == ClaimType.turnover_or_pulse_cohort:
|
|
125
|
+
add("turnover_window", False, True,
|
|
126
|
+
f"target half-life ({half_life} min) is comparable to the editing "
|
|
127
|
+
"window; survivorship bias expected — pulse-cohort claims are "
|
|
128
|
+
"marginal")
|
|
129
|
+
elif half_life is not None and half_life < 30:
|
|
130
|
+
add("turnover_window", True, True,
|
|
131
|
+
f"target half-life ({half_life} min) is short; expect survivorship "
|
|
132
|
+
"bias in edited cohorts")
|
|
133
|
+
else:
|
|
134
|
+
add("turnover_window", True, True, "no turnover conflict declared")
|
|
135
|
+
|
|
136
|
+
# 4. delivery variance
|
|
137
|
+
if defn.delivery.method and not defn.delivery.per_cell_loading_measured:
|
|
138
|
+
add("delivery_variance", True, True,
|
|
139
|
+
"per-cell loading not measured; time-resolved claims carry "
|
|
140
|
+
"unmeasured delivery variance")
|
|
141
|
+
else:
|
|
142
|
+
add("delivery_variance", True, True, "no delivery variance concern declared")
|
|
143
|
+
|
|
144
|
+
# 5. acceptor-bearing state (the cassette burden) — BLOCKER when
|
|
145
|
+
# historical controls are absent and cassette is a significant fraction
|
|
146
|
+
meta = defn.metadata or {}
|
|
147
|
+
hist_controls = meta.get("historical_controls", [])
|
|
148
|
+
if defn.intervention.requires_prior_genome_edit:
|
|
149
|
+
kda = defn.intervention.construct_size_kda
|
|
150
|
+
has_hist_data = bool(hist_controls)
|
|
151
|
+
if kda is not None and kda > 15 and not has_hist_data:
|
|
152
|
+
add("cassette_burden", False, False,
|
|
153
|
+
f"acceptor cassette is {kda} kDa (significant fraction of target "
|
|
154
|
+
f"mass) and no historical control data is declared. A "
|
|
155
|
+
f"cycloheximide chase or interactome comparison is required to "
|
|
156
|
+
f"verify the acceptor-bearing state does not alter baseline "
|
|
157
|
+
f"biology before the edit can be attributed causally")
|
|
158
|
+
else:
|
|
159
|
+
add("cassette_burden", True, True,
|
|
160
|
+
f"cassette burden assessed: {kda or 'unknown'} kDa, "
|
|
161
|
+
f"historical controls {'declared' if has_hist_data else 'not required'}")
|
|
162
|
+
|
|
163
|
+
# 5b. kinetic matching for split-intein pairs
|
|
164
|
+
meta = defn.metadata or {}
|
|
165
|
+
intein_pair = meta.get("intein_pair")
|
|
166
|
+
if intein_pair:
|
|
167
|
+
from proef.kinetic import InteinPairConfig, check_intein_pair
|
|
168
|
+
pair_cfg = InteinPairConfig(**intein_pair) if isinstance(intein_pair, dict) else intein_pair
|
|
169
|
+
result = check_intein_pair(pair_cfg)
|
|
170
|
+
if not result.compatible:
|
|
171
|
+
add("kinetic_matching", False, False,
|
|
172
|
+
f"intein pair rate mismatch: {result.details}; "
|
|
173
|
+
f"intermediates will accumulate — slow one domain or choose "
|
|
174
|
+
f"a matched pair")
|
|
175
|
+
else:
|
|
176
|
+
add("kinetic_matching", True, True,
|
|
177
|
+
f"rates matched (ratio {result.rate_ratio}x)")
|
|
178
|
+
|
|
179
|
+
# 6. controls
|
|
180
|
+
add("controls", bool(defn.controls), True,
|
|
181
|
+
f"{len(defn.controls)} control(s) declared" if defn.controls
|
|
182
|
+
else "no controls declared")
|
|
183
|
+
|
|
184
|
+
# 7. denominators for interpretable negative results
|
|
185
|
+
add("denominators", bool(defn.denominators), True,
|
|
186
|
+
f"{len(defn.denominators)} denominator(s) declared" if defn.denominators
|
|
187
|
+
else "no denominators declared; negative results are weaker")
|
|
188
|
+
|
|
189
|
+
# 8. readout capabilities cover the claim's resolution needs
|
|
190
|
+
if defn.claim_type == ClaimType.detection_or_pulldown and \
|
|
191
|
+
ReadoutCapability.signal_present not in r.capabilities and \
|
|
192
|
+
ReadoutCapability.edited_vs_unedited not in r.capabilities:
|
|
193
|
+
add("readout_capability", False, False,
|
|
194
|
+
"detection/pulldown claim requires at least signal detection")
|
|
195
|
+
else:
|
|
196
|
+
add("readout_capability", True, True, "readout capabilities adequate")
|
|
197
|
+
# 8b. fence: do the PERMITTED instruments declare these capabilities?
|
|
198
|
+
# (available_caps = union of the program fence's declared readouts;
|
|
199
|
+
# absent -> no fence check, nothing inferred)
|
|
200
|
+
if available_caps is not None:
|
|
201
|
+
declared = {c.value if hasattr(c, "value") else str(c)
|
|
202
|
+
for c in defn.readout.capabilities}
|
|
203
|
+
unmet = sorted(declared - set(available_caps.get("readouts") or []))
|
|
204
|
+
add("fence_capability", not unmet, False,
|
|
205
|
+
("fence: permitted instruments declare the needed readout"
|
|
206
|
+
if not unmet else
|
|
207
|
+
"fence: no permitted instrument declares readout capability: "
|
|
208
|
+
+ ", ".join(unmet)))
|
|
209
|
+
|
|
210
|
+
# 9. synthesis feasibility (if the intervention produces a compound)
|
|
211
|
+
meta = defn.metadata or {}
|
|
212
|
+
if meta.get("synthesis_check") and meta.get("synthesis_route"):
|
|
213
|
+
route = meta["synthesis_route"]
|
|
214
|
+
if not route.get("feasible", True):
|
|
215
|
+
add("synthesis_feasibility", False, False,
|
|
216
|
+
f"no viable synthesis route: {route.get('notes', '')}")
|
|
217
|
+
elif route.get("num_steps", 0) > 12:
|
|
218
|
+
add("synthesis_feasibility", True, True,
|
|
219
|
+
f"long route ({route['num_steps']} steps) — consider simplification")
|
|
220
|
+
else:
|
|
221
|
+
add("synthesis_feasibility", True, True,
|
|
222
|
+
f"viable route ({route.get('num_steps', '?')} steps)")
|
|
223
|
+
else:
|
|
224
|
+
add("synthesis_feasibility", True, True,
|
|
225
|
+
"not assessed (no synthesis route provided)")
|
|
226
|
+
|
|
227
|
+
blockers = [f for f in findings if f.severity == "blocker"]
|
|
228
|
+
if blockers:
|
|
229
|
+
verdict = ReviewVerdict.blocked
|
|
230
|
+
elif any(f.severity == "warning" for f in findings):
|
|
231
|
+
verdict = ReviewVerdict.ready_with_warnings
|
|
232
|
+
else:
|
|
233
|
+
verdict = ReviewVerdict.ready
|
|
234
|
+
return ExperimentReadinessReview(
|
|
235
|
+
experiment_id=defn.experiment_id,
|
|
236
|
+
hypothesis_id=defn.hypothesis_id,
|
|
237
|
+
verdict=verdict,
|
|
238
|
+
findings=findings,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def review_and_record(
|
|
243
|
+
store: ProvenanceStore,
|
|
244
|
+
envelope: Envelope,
|
|
245
|
+
actor: Any,
|
|
246
|
+
defn: ExperimentDefinition,
|
|
247
|
+
) -> tuple[ExperimentReadinessReview, Any]:
|
|
248
|
+
"""Run the readiness review and append it to the provenance chain."""
|
|
249
|
+
review = review_experiment(defn)
|
|
250
|
+
store.append(record_for(
|
|
251
|
+
envelope, EventType.experiment_readiness_reviewed, actor,
|
|
252
|
+
decision={
|
|
253
|
+
"experiment_id": defn.experiment_id,
|
|
254
|
+
"hypothesis_id": defn.hypothesis_id,
|
|
255
|
+
"verdict": review.verdict.value,
|
|
256
|
+
"blockers": [b.message for b in review.blockers],
|
|
257
|
+
"warnings": [w.message for w in review.warnings],
|
|
258
|
+
}))
|
|
259
|
+
return review
|
proef/reliability.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Model-variance reporting — a verdict from one seed is a sample, not a fact.
|
|
2
|
+
|
|
3
|
+
Runs the same campaign spec across N lab seeds and reports verdict stability.
|
|
4
|
+
Unstable verdicts are the honest signal that the evidence is borderline —
|
|
5
|
+
the UI shows the spread instead of hiding it.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import shutil
|
|
10
|
+
from collections import Counter
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def verdict_spread(specs: list[dict], threshold_um: float, k: int,
|
|
15
|
+
lab_seed: int = 5,
|
|
16
|
+
noise_variants: tuple[int, ...] = (0, 1, 2),
|
|
17
|
+
inbox: str | Path = ".data/variance-inbox") -> dict:
|
|
18
|
+
"""Same ground truth (one lab seed), N measurement-noise draws. A verdict
|
|
19
|
+
that flips across noise variants is BORDERLINE EVIDENCE, not a flaky
|
|
20
|
+
pipeline — that is the number a scientist should see."""
|
|
21
|
+
from proef.adapters.lab.simulator import SimulatorLab
|
|
22
|
+
from proef.adapters.store.sqlite import SqliteProvenanceStore
|
|
23
|
+
from proef.autoloop import CampaignConfig, run_campaign
|
|
24
|
+
from proef.core.hypothesis import Constraint, ProblemStatement
|
|
25
|
+
|
|
26
|
+
per: dict[str, list[str | None]] = {}
|
|
27
|
+
for nv in noise_variants:
|
|
28
|
+
box = Path(inbox)
|
|
29
|
+
shutil.rmtree(box, ignore_errors=True)
|
|
30
|
+
box.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
problem = ProblemStatement(
|
|
32
|
+
objective="variance probe",
|
|
33
|
+
problem_id=f"var-{nv}",
|
|
34
|
+
constraints=[Constraint(name="potency", description="d",
|
|
35
|
+
kind="hard", limit=threshold_um,
|
|
36
|
+
unit="uM")])
|
|
37
|
+
cfg = CampaignConfig(
|
|
38
|
+
problem=problem, hypotheses=[dict(s) for s in specs], k=k,
|
|
39
|
+
autonomy="act", inbox=str(box), poll_secs=0.05,
|
|
40
|
+
noise_variant=nv)
|
|
41
|
+
report = run_campaign(cfg, SimulatorLab(seed=lab_seed),
|
|
42
|
+
SqliteProvenanceStore())
|
|
43
|
+
for cand in [s["candidate"] for s in specs]:
|
|
44
|
+
per.setdefault(cand, []).append(report.verdicts.get(cand))
|
|
45
|
+
stable = {c: (len(set(v)) == 1) for c, v in per.items()}
|
|
46
|
+
frac = (sum(stable.values()) / len(stable)) if stable else 0.0
|
|
47
|
+
return {"per_candidate": per, "stable": stable,
|
|
48
|
+
"stability": round(frac, 3), "lab_seed": lab_seed,
|
|
49
|
+
"noise_variants": list(noise_variants)}
|
proef/report.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Self-contained HTML campaign report (shareable artifact).
|
|
2
|
+
|
|
3
|
+
`proef prove <branch> --html report.html` renders the provenance chain, chain
|
|
4
|
+
verification, hypothesis verdicts, and any artifacts (IND package, dossiers)
|
|
5
|
+
into one dark-blueprint HTML file with no external dependencies.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import html as _html
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
TEMPLATE = """<!DOCTYPE html>
|
|
15
|
+
<html lang="en"><head><meta charset="utf-8">
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
17
|
+
<title>Proef Report — {branch}</title>
|
|
18
|
+
<style>
|
|
19
|
+
:root {{ --bg:#f3f1ea; --grid:#e3ded2; --paper:#faf8f2; --line:#c9c2b0;
|
|
20
|
+
--ink:#2a2823; --dim:#6b6558; --green:#2f6b38; --red:#8a4034; --amber:#8a6a2c;
|
|
21
|
+
--mono:'IBM Plex Mono','SFMono-Regular',Consolas,monospace; }}
|
|
22
|
+
* {{ box-sizing:border-box; }}
|
|
23
|
+
body {{ margin:0; background:var(--bg); color:var(--ink);
|
|
24
|
+
background-image:linear-gradient(var(--grid) 1px,transparent 1px),
|
|
25
|
+
linear-gradient(90deg,var(--grid) 1px,transparent 1px); background-size:28px 28px;
|
|
26
|
+
font-family:-apple-system,'Segoe UI',sans-serif; padding:40px 20px 80px; }}
|
|
27
|
+
.wrap {{ max-width:980px; margin:0 auto; }}
|
|
28
|
+
h1 {{ font-size:24px; margin:0 0 4px; letter-spacing:-0.01em; }}
|
|
29
|
+
.eyebrow {{ font-family:var(--mono); font-size:11px; letter-spacing:.14em;
|
|
30
|
+
text-transform:uppercase; color:var(--dim); margin-bottom:24px; }}
|
|
31
|
+
table {{ width:100%; border-collapse:collapse; background:var(--paper);
|
|
32
|
+
border:1px solid var(--line); font-size:13px; }}
|
|
33
|
+
th,td {{ text-align:left; padding:8px 12px; border-bottom:1px solid var(--line); }}
|
|
34
|
+
th {{ font-family:var(--mono); font-size:11px; letter-spacing:.06em;
|
|
35
|
+
text-transform:uppercase; color:var(--dim); }}
|
|
36
|
+
td.mono, code {{ font-family:var(--mono); font-size:12px; }}
|
|
37
|
+
.ok {{ color:var(--green); font-weight:600; }}
|
|
38
|
+
.bad {{ color:var(--red); font-weight:600; }}
|
|
39
|
+
.section {{ margin-top:32px; }}
|
|
40
|
+
pre {{ background:var(--paper); border:1px solid var(--line); padding:14px;
|
|
41
|
+
font-family:var(--mono); font-size:12px; overflow-x:auto; }}
|
|
42
|
+
.stats {{ display:flex; gap:14px; flex-wrap:wrap; margin-top:16px; }}
|
|
43
|
+
.stat {{ background:var(--paper); border:1px solid var(--line); padding:12px 18px; }}
|
|
44
|
+
.stat b {{ display:block; font-size:20px; }}
|
|
45
|
+
.stat span {{ font-family:var(--mono); font-size:11px; color:var(--dim); }}
|
|
46
|
+
</style></head><body><div class="wrap">
|
|
47
|
+
<p class="eyebrow">Proef · Campaign Report</p>
|
|
48
|
+
<h1>Provenance — {branch}</h1>
|
|
49
|
+
<div class="stats">{stats}</div>
|
|
50
|
+
<div class="section"><table>
|
|
51
|
+
<tr><th>#</th><th>Event</th><th>Detail</th><th>Hash</th><th>Chain</th></tr>
|
|
52
|
+
{rows}
|
|
53
|
+
</table></div>
|
|
54
|
+
<div class="section"><pre>{artifacts}</pre></div>
|
|
55
|
+
<p class="eyebrow" style="margin-top:32px">generated by proef · records hash-chained (sha256), hashes RECOMPUTED from content when this report was rendered · external integrity via a published `proef anchor` root</p>
|
|
56
|
+
</div></body></html>
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def build_report(records: list[Any]) -> str:
|
|
61
|
+
from proef.adapters.store.sqlite import SqliteProvenanceStore
|
|
62
|
+
prev_ok = True
|
|
63
|
+
prev_hash = None
|
|
64
|
+
edited = 0
|
|
65
|
+
rows = []
|
|
66
|
+
artifacts: list[dict[str, Any]] = []
|
|
67
|
+
for i, r in enumerate(records, 1):
|
|
68
|
+
hash_ok = SqliteProvenanceStore._hash(r) == (r.record_hash or "")
|
|
69
|
+
if not hash_ok:
|
|
70
|
+
edited += 1
|
|
71
|
+
ok = (r.prev_record_hash == prev_hash) and hash_ok
|
|
72
|
+
prev_ok &= ok
|
|
73
|
+
detail = ""
|
|
74
|
+
if r.decision:
|
|
75
|
+
detail = _html.escape(json.dumps(r.decision)[:120])
|
|
76
|
+
elif r.artifact:
|
|
77
|
+
detail = _html.escape(f"{r.artifact.kind.value}: {r.artifact.artifact_id}")
|
|
78
|
+
if r.artifact and r.artifact.metadata:
|
|
79
|
+
artifacts.append(r.artifact.model_dump())
|
|
80
|
+
rows.append(
|
|
81
|
+
f"<tr><td class='mono'>{i}</td>"
|
|
82
|
+
f"<td>{_html.escape(r.event_type.value)}</td>"
|
|
83
|
+
f"<td class='mono'>{detail}</td>"
|
|
84
|
+
f"<td class='mono'>{(r.record_hash or '')[:12]}…</td>"
|
|
85
|
+
f"<td class='{'ok' if ok else 'bad'}'>"
|
|
86
|
+
f"{'ok' if ok else ('EDITED' if not hash_ok else 'BROKEN')}"
|
|
87
|
+
f"</td></tr>"
|
|
88
|
+
)
|
|
89
|
+
prev_hash = r.record_hash
|
|
90
|
+
events = [r.event_type.value for r in records]
|
|
91
|
+
stats = "".join(
|
|
92
|
+
f"<div class='stat'><b>{v}</b><span>{k}</span></div>"
|
|
93
|
+
for k, v in {
|
|
94
|
+
"records": len(records),
|
|
95
|
+
"hypotheses": sum(1 for e in events if e.startswith("hypothesis")),
|
|
96
|
+
"validated": sum(1 for e in events if e == "hypothesis_validated"),
|
|
97
|
+
"invalidated": sum(1 for e in events if e == "hypothesis_invalidated"),
|
|
98
|
+
"inconclusive": sum(1 for e in events
|
|
99
|
+
if e == "hypothesis_inconclusive"),
|
|
100
|
+
"gates": sum(1 for e in events if e == "gate_decision"),
|
|
101
|
+
"lab runs": sum(1 for e in events if e == "lab_run"),
|
|
102
|
+
"chain": ("intact (recomputed)" if prev_ok and not edited
|
|
103
|
+
else "BROKEN" if not prev_ok else "EDITED"),
|
|
104
|
+
}.items()
|
|
105
|
+
)
|
|
106
|
+
return TEMPLATE.format(
|
|
107
|
+
branch=_html.escape(records[0].envelope.experiment_branch_id if records else "?"),
|
|
108
|
+
stats=stats,
|
|
109
|
+
rows="\n".join(rows),
|
|
110
|
+
artifacts=_html.escape(json.dumps(artifacts, indent=1)[:4000] or "{}"),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def write_report(records: list[Any], path: str | Path) -> Path:
|
|
115
|
+
p = Path(path)
|
|
116
|
+
p.write_text(build_report(records))
|
|
117
|
+
return p
|