cellscreen 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {cellscreen-0.1.0 → cellscreen-0.2.0}/.agents/skills/cellscreen/SKILL.md +13 -2
- {cellscreen-0.1.0 → cellscreen-0.2.0}/.agents/skills/cellscreen/references/reference.md +24 -5
- {cellscreen-0.1.0 → cellscreen-0.2.0}/.claude/skills/cellscreen/SKILL.md +13 -2
- cellscreen-0.2.0/CHANGELOG.md +62 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/PKG-INFO +38 -6
- {cellscreen-0.1.0 → cellscreen-0.2.0}/README.md +27 -5
- {cellscreen-0.1.0 → cellscreen-0.2.0}/docs/guide.md +45 -8
- {cellscreen-0.1.0 → cellscreen-0.2.0}/pyproject.toml +14 -1
- cellscreen-0.2.0/scripts/benchmark_cpu_npz.py +196 -0
- cellscreen-0.2.0/scripts/benchmark_plate_pilot.py +123 -0
- cellscreen-0.2.0/scripts/install_skills.sh +31 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/src/cellscreen/__init__.py +1 -1
- cellscreen-0.2.0/src/cellscreen/analytics.py +1070 -0
- cellscreen-0.2.0/src/cellscreen/assets.py +268 -0
- cellscreen-0.2.0/src/cellscreen/cli.py +1257 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/src/cellscreen/constants.py +43 -0
- cellscreen-0.2.0/src/cellscreen/controls.py +1788 -0
- cellscreen-0.2.0/src/cellscreen/decoder.py +331 -0
- cellscreen-0.2.0/src/cellscreen/epistasis.py +1548 -0
- cellscreen-0.2.0/src/cellscreen/eval.py +1369 -0
- cellscreen-0.2.0/src/cellscreen/export.py +272 -0
- cellscreen-0.2.0/src/cellscreen/fanner.py +818 -0
- cellscreen-0.2.0/src/cellscreen/match.py +467 -0
- cellscreen-0.2.0/src/cellscreen/panels.py +880 -0
- cellscreen-0.2.0/src/cellscreen/plate.py +1710 -0
- cellscreen-0.2.0/src/cellscreen/preflight.py +548 -0
- cellscreen-0.2.0/src/cellscreen/priors.py +809 -0
- cellscreen-0.2.0/src/cellscreen/prompts.py +307 -0
- cellscreen-0.2.0/src/cellscreen/report.py +2859 -0
- cellscreen-0.2.0/src/cellscreen/schemas.py +649 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/src/cellscreen/server.py +112 -23
- cellscreen-0.2.0/src/cellscreen/store.py +1795 -0
- cellscreen-0.2.0/src/cellscreen/triage.py +971 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_end_to_end_stateless.py +1 -0
- cellscreen-0.2.0/tests/test_gate1_parity_integrity_analytics.py +1087 -0
- cellscreen-0.2.0/tests/test_gate2_identity_preflight_telemetry.py +1329 -0
- cellscreen-0.2.0/tests/test_gate3_match_eval_priors_controls.py +1598 -0
- cellscreen-0.2.0/tests/test_gate4_triage_panels_epistasis_plate.py +1309 -0
- cellscreen-0.1.0/CHANGELOG.md +0 -29
- cellscreen-0.1.0/src/cellscreen/assets.py +0 -125
- cellscreen-0.1.0/src/cellscreen/cli.py +0 -513
- cellscreen-0.1.0/src/cellscreen/decoder.py +0 -222
- cellscreen-0.1.0/src/cellscreen/fanner.py +0 -366
- cellscreen-0.1.0/src/cellscreen/prompts.py +0 -142
- cellscreen-0.1.0/src/cellscreen/report.py +0 -1359
- cellscreen-0.1.0/src/cellscreen/schemas.py +0 -217
- cellscreen-0.1.0/src/cellscreen/store.py +0 -313
- {cellscreen-0.1.0 → cellscreen-0.2.0}/.gitignore +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/LICENSE +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/NOTICE +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/examples/k562_crispr.json +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/examples/tahoe_drugs.json +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/src/cellscreen/bundled.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/src/cellscreen/quantize.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_bundled_and_packaging.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_health_and_defaults.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_prompts_and_decoder.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_quantize.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_report_escaping.py +0 -0
- {cellscreen-0.1.0 → cellscreen-0.2.0}/tests/test_server_mlx_engine.py +0 -0
|
@@ -30,22 +30,33 @@ uv run cellscreen health --json # works for MLX, mock, and vLLM servers
|
|
|
30
30
|
- **NVIDIA GPU:** run vLLM with the flags in `docs/guide.md`.
|
|
31
31
|
- **Dry run with no model:** `uv run cellscreen serve --mock --port 8410`.
|
|
32
32
|
|
|
33
|
-
## 3. Create or resume the run
|
|
33
|
+
## 3. Create, preflight, or resume the run
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
36
|
uv run cellscreen init runs/<run_id> --from <spec.json>
|
|
37
|
+
uv run cellscreen preflight runs/<run_id> --max-model-len 12992
|
|
37
38
|
uv run cellscreen run runs/<run_id> # resumes; finished items are skipped
|
|
38
39
|
uv run cellscreen run runs/<run_id> --limit 3 # quick pilot
|
|
39
40
|
uv run cellscreen run runs/<run_id> --retry-errors
|
|
40
41
|
```
|
|
41
42
|
|
|
43
|
+
Optional custom controls import: `uv run cellscreen controls import <file> --dataset <ds> --output controls_pack.json` and pass `--controls-file controls_pack.json` to `init`.
|
|
44
|
+
|
|
42
45
|
Each perturbation generates up to 8,192 tokens and takes minutes (`--timeout` defaults to `1800` s;
|
|
43
46
|
raise it if needed). Pick the decoder (`dataset`) that matches the assay:
|
|
44
47
|
`uv run cellscreen list-decoders`.
|
|
45
48
|
|
|
46
|
-
## 4.
|
|
49
|
+
## 4. Downstream CPU analysis, report, and handoff
|
|
47
50
|
|
|
48
51
|
```bash
|
|
52
|
+
uv run cellscreen match --signature <sig.json> runs/<run_id>
|
|
53
|
+
uv run cellscreen eval runs/<tahoe> runs/<sciplex> --truth <truth.json> --train <train.json>
|
|
54
|
+
uv run cellscreen export-h5ad runs/<run_id> --output runs/<run_id>/screen.h5ad
|
|
55
|
+
uv run cellscreen expand-panel runs/<base> --out runs/<panel> --cell-indices 0,1 --seeds 0,1,2,3,4 --temperature 0.7 --preflight
|
|
56
|
+
uv run cellscreen stability runs/<panel> --json
|
|
57
|
+
uv run cellscreen epistasis runs/<run_id> --json
|
|
58
|
+
uv run cellscreen triage runs/<short> --full-run runs/<full> --measured-json <meas.json>
|
|
59
|
+
uv run cellscreen plate runs/<run_id> --format 96-well --seed 42
|
|
49
60
|
uv run cellscreen report runs/<run_id>
|
|
50
61
|
uv run cellscreen handoff runs/<run_id> --write
|
|
51
62
|
```
|
|
@@ -34,14 +34,27 @@
|
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
### Single CRISPR Knockdown (auto-hydrates from `kg_sentences.json`)
|
|
37
|
+
### Single CRISPR Knockdown / Activation (auto-hydrates from `kg_sentences.json`)
|
|
38
38
|
```json
|
|
39
39
|
{
|
|
40
40
|
"label": "MYC knockdown",
|
|
41
41
|
"modality": "crispr",
|
|
42
|
-
"gene": "MYC"
|
|
42
|
+
"gene": "MYC",
|
|
43
|
+
"direction": "knockdown"
|
|
43
44
|
}
|
|
44
45
|
```
|
|
46
|
+
> `direction` defaults automatically by dataset (`activation` for `norman` CRISPRa; `knockdown` for CRISPRi datasets).
|
|
47
|
+
|
|
48
|
+
### Optional Per-Item Fields & Metadata
|
|
49
|
+
Any perturbation spec may also set:
|
|
50
|
+
- `cell_idx`: per-item control cell index (overrides manifest `cell_idx`)
|
|
51
|
+
- `seed`: per-item integer sampling seed (included in condition `item_id`)
|
|
52
|
+
- `generation`: partial per-item overrides (`temperature`, `max_new_tokens`, `top_p`, `top_k`)
|
|
53
|
+
- `metadata`: typed context fields such as `compound_id`, `exposure_hours`, `vehicle`, `bio_prep_id`, `target_genes`
|
|
54
|
+
|
|
55
|
+
### Optional Extras
|
|
56
|
+
- `cellscreen[anndata]`: enables `cellscreen export-h5ad` (`anndata`, `h5py`, `pandas`)
|
|
57
|
+
- `cellscreen[ingest]`: enables `.h5ad` and `.parquet` inputs in `cellscreen controls import` (`pyarrow` + `[anndata]`)
|
|
45
58
|
|
|
46
59
|
### Cytokine (auto-hydrates from `kg_sentences.json`)
|
|
47
60
|
```json
|
|
@@ -77,10 +90,16 @@
|
|
|
77
90
|
|
|
78
91
|
```text
|
|
79
92
|
runs/<run_id>/
|
|
80
|
-
├── manifest.json # Immutable run spec +
|
|
93
|
+
├── manifest.json # Immutable run spec + condition-hashed item_ids (schema v1.1)
|
|
94
|
+
├── controls_pack.json # Optional portable same-assay controls pack + measured-feature mask
|
|
81
95
|
├── results.jsonl # Append-only fsync'd records (source of truth for resume)
|
|
82
|
-
├── vectors
|
|
83
|
-
├──
|
|
96
|
+
├── vectors/*.npz # Immutable per-execution float32 ctrl/baseline/predicted/LFC arrays
|
|
97
|
+
├── analysis.json # Linearly decomposable cancer programs & Szalai covariates
|
|
98
|
+
├── telemetry.json # Boundary-separated server lock-wait, service & HTTP attempt timings
|
|
99
|
+
├── plate_plan.json # Optional CPU 96/24-well randomized validation plate plan
|
|
100
|
+
├── plate_map.csv # Paired RFC-4180 formula-safe well map (shared layout_sha256)
|
|
101
|
+
├── shortlist.json # Optional Stage-1 triage shortlist / calibration output
|
|
102
|
+
├── report.html # Offline interactive report (full NPZ contrasts + Decision Dossier)
|
|
84
103
|
├── HANDOFF.md # Optional cross-agent summary (`cellscreen handoff --write`)
|
|
85
104
|
└── .run.lock # OS advisory flock (auto-released on crash/exit)
|
|
86
105
|
```
|
|
@@ -30,22 +30,33 @@ uv run cellscreen health --json # works for MLX, mock, and vLLM servers
|
|
|
30
30
|
- **NVIDIA GPU:** run vLLM with the flags in `docs/guide.md`.
|
|
31
31
|
- **Dry run with no model:** `uv run cellscreen serve --mock --port 8410`.
|
|
32
32
|
|
|
33
|
-
## 3. Create or resume the run
|
|
33
|
+
## 3. Create, preflight, or resume the run
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
36
|
uv run cellscreen init runs/<run_id> --from <spec.json>
|
|
37
|
+
uv run cellscreen preflight runs/<run_id> --max-model-len 12992
|
|
37
38
|
uv run cellscreen run runs/<run_id> # resumes; finished items are skipped
|
|
38
39
|
uv run cellscreen run runs/<run_id> --limit 3 # quick pilot
|
|
39
40
|
uv run cellscreen run runs/<run_id> --retry-errors
|
|
40
41
|
```
|
|
41
42
|
|
|
43
|
+
Optional custom controls import: `uv run cellscreen controls import <file> --dataset <ds> --output controls_pack.json` and pass `--controls-file controls_pack.json` to `init`.
|
|
44
|
+
|
|
42
45
|
Each perturbation generates up to 8,192 tokens and takes minutes (`--timeout` defaults to `1800` s;
|
|
43
46
|
raise it if needed). Pick the decoder (`dataset`) that matches the assay:
|
|
44
47
|
`uv run cellscreen list-decoders`.
|
|
45
48
|
|
|
46
|
-
## 4.
|
|
49
|
+
## 4. Downstream CPU analysis, report, and handoff
|
|
47
50
|
|
|
48
51
|
```bash
|
|
52
|
+
uv run cellscreen match --signature <sig.json> runs/<run_id>
|
|
53
|
+
uv run cellscreen eval runs/<tahoe> runs/<sciplex> --truth <truth.json> --train <train.json>
|
|
54
|
+
uv run cellscreen export-h5ad runs/<run_id> --output runs/<run_id>/screen.h5ad
|
|
55
|
+
uv run cellscreen expand-panel runs/<base> --out runs/<panel> --cell-indices 0,1 --seeds 0,1,2,3,4 --temperature 0.7 --preflight
|
|
56
|
+
uv run cellscreen stability runs/<panel> --json
|
|
57
|
+
uv run cellscreen epistasis runs/<run_id> --json
|
|
58
|
+
uv run cellscreen triage runs/<short> --full-run runs/<full> --measured-json <meas.json>
|
|
59
|
+
uv run cellscreen plate runs/<run_id> --format 96-well --seed 42
|
|
49
60
|
uv run cellscreen report runs/<run_id>
|
|
50
61
|
uv run cellscreen handoff runs/<run_id> --write
|
|
51
62
|
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to CellScreen are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.2.0] — 2026-12-04
|
|
6
|
+
|
|
7
|
+
Major translational oncology, integrity, and offline analysis upgrade over `0.1.0`.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- **Upstream Parity, Replay Integrity & Linear Cancer Programs:**
|
|
11
|
+
- Unified NPZ vector validation across `status`, `run`, `analyze`, `report`, and downstream tools (`p - c == (p - b) + (b - c)` within `1e-6`).
|
|
12
|
+
- Upstream-matching prompt sorting (`upstream_parity` vs `legacy_v1`), repeat-preserving parsing (`upstream_repeats` vs `legacy_dedup_v1`), explicit collision policies (`first_occurrence`, `drop_ambiguous`, `legacy_last_write`), and dataset-aware CRISPR direction (`Gene activation:` for `norman` CRISPRa).
|
|
13
|
+
- Fixed-universe linearly decomposable cancer programs (`HALLMARK_INTERFERON_ALPHA_RESPONSE`, `HALLMARK_APOPTOSIS`, `HALLMARK_G2M_CHECKPOINT`) with Szalai death/proliferation scatter plots and overlap-excluded ($T \setminus D$) sensitivity checks.
|
|
14
|
+
- Full-vector Python-side `report.html` with `p - b` / `p - c` / `b - c` contrast toggles, bounded within-sign rank percentiles, explicit cell missingness states, and multi-context `(cell_idx, cell_line, seed)` row labels.
|
|
15
|
+
- **Execution Identity, Immutable Storage, Preflight & Telemetry:**
|
|
16
|
+
- Condition `item_id` separated from `execution_fingerprint` so hybrid Mac (MLX) ↔ GPU (vLLM) resume preserves item identity without overwriting prior NPZ publications.
|
|
17
|
+
- Per-item `seed` and `generation` overrides wired end-to-end into `/v1/completions` and `results.jsonl`.
|
|
18
|
+
- Tokenizer-only `cellscreen preflight` checking context limits (e.g., 4,800-token L4 boundary), wire compatibility (`--no-top-k`, `--served-model-name`), and local PLE RAM guidance.
|
|
19
|
+
- Boundary-separated `telemetry.json` separating native server `gpu_lock` wait, engine service time, and per-HTTP-attempt timings, plus deterministic full-weight `checkpoint_sha256` hashing on MLX checkpoints.
|
|
20
|
+
- **Signature Reversal, `.h5ad` Export, Eval, Priors & Portable Controls:**
|
|
21
|
+
- Two-pass bounded-memory `cellscreen match` implementing Chen et al. (2017) `sRGES` + linear reversal with Szalai viability flags.
|
|
22
|
+
- `cellscreen export-h5ad` (`[anndata]` extra) exporting validated `X`, 6 expression/contrast/mask layers, and control/perturbation metadata for `scanpy`, `pertpy`, and `cell-eval2`.
|
|
23
|
+
- `cellscreen eval` held-out benchmark mode comparing predictions against identity ($p=c$), mean-shift ($p=b$), and a disjoint training-only Ridge baseline.
|
|
24
|
+
- Auditable Phase A prior loaders (`HGNCResolver`, GMT parser, `DepMap24Q4Store` with `CVCL`–`ACH` crosswalk).
|
|
25
|
+
- `cellscreen controls import` (`[ingest]` extra for `.h5ad`/Parquet) importing same-assay controls into portable `controls_pack.json` packs with measured-feature masks, plus offline dose-response grouping and matched-context contrast.
|
|
26
|
+
- **Triage Calibration, Multi-Context Panels/Stability, Signed Epistasis & CPU Plates:**
|
|
27
|
+
- `cellscreen triage` writing atomic `shortlist.json` sidecars and calibrating `2048` vs `8192` short-cap triage stratified by `early_stop` vs `at_cap`.
|
|
28
|
+
- `cellscreen expand-panel` expanding manifests across cell indices and seeds while distinguishing technical cell profiles from independent biological units, plus `cellscreen stability` evaluating $K=5$ sampling stability at $T=0.7$ per frozen configuration.
|
|
29
|
+
- `cellscreen epistasis` computing signed prior-corrected combination contrast $\Delta - (c - b) = r_{AB} - r_A - r_B$, pre-average per-arm zero-floor flags, per-arm `at_token_cap` / `finish_reason` flags, 3-arm replicate SE, and Norman `seen1`/`seen2` split evaluation.
|
|
30
|
+
- `cellscreen plate` designing randomized 96-well (36 perimeter PBS + controls + 25×2 reps) and 24-well (9×2 reps) validation layouts (`plate_plan.json`, Unicode-NFKC formula-safe `plate_map.csv` with shared `layout_sha256`, and embedded `report.html` Wet-Lab Decision Dossier), plus reproducible pilot benchmark runner `scripts/benchmark_plate_pilot.py`.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
- Eliminated 52/96 false-zero heatmap cells and negative salience values in `report.html`.
|
|
34
|
+
- Fixed dual-sign `+G`/`-G` silent last-write overwrite in `ExpressionDecoder.reconstruct`.
|
|
35
|
+
- Fixed `norman` CRISPRa prompts emitting `Gene knockdown:` instead of `Gene activation:`.
|
|
36
|
+
- Fixed concurrent `init --overwrite` locking and protected active controls packs from outer/nested run clobbering.
|
|
37
|
+
|
|
38
|
+
## [0.1.0] — 2026-12-02
|
|
39
|
+
|
|
40
|
+
Initial open-source release of CellScreen.
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
- **PLE-safe Apple MLX quantizer (`cellscreen quantize`)** with `ple_q8` (for 16 GB Macs) and
|
|
44
|
+
`ple_bf16` (for 24 GB+ Macs) recipes, executing conversion on CPU to avoid macOS Metal GPU
|
|
45
|
+
watchdogs on external/swapped volumes.
|
|
46
|
+
- **Stateless local MLX inference server (`cellscreen serve`)** exposing OpenAI-compatible
|
|
47
|
+
`/v1/completions`, `/v1/models`, `/health`, and `/metrics`, running model load and generation
|
|
48
|
+
on a dedicated MLX thread, plus a `--mock` backend for zero-download dry runs.
|
|
49
|
+
- **Exact CellGemma E4B two-stage pipeline:** verbatim model-card prompt formatting for small
|
|
50
|
+
molecules, CRISPR knockdowns, cytokines, clinical treatments, and combinatorial perturbations
|
|
51
|
+
(with `stop_token_ids` for vLLM compatibility) plus pure-NumPy Stage-2 `ExpressionDecoder`
|
|
52
|
+
reconstruction for all 13 pretrained decoders.
|
|
53
|
+
- **Stateless run store & async fanner (`cellscreen init`, `run`, `status`, `handoff`)** using
|
|
54
|
+
`manifest.json` + fsync-flushed append-only `results.jsonl` + `vectors/*.npz` + OS advisory
|
|
55
|
+
locking for seamless pause/resume across machines and coding agents.
|
|
56
|
+
- **Offline interactive HTML report (`cellscreen report`)** with rank-salience volcano plot,
|
|
57
|
+
cross-perturbation LFC heatmap, sortable/filterable candidate table, dark-mode toggle,
|
|
58
|
+
escaped DOM rendering, and CSV/JSON export.
|
|
59
|
+
- **vLLM & OpenAI-compatible server health fallback** in `cellscreen health` and 1,800 s
|
|
60
|
+
default per-request timeout.
|
|
61
|
+
- **Bundled package ergonomics:** `cellscreen examples`, `cellscreen init --example tahoe|k562`,
|
|
62
|
+
and `cellscreen install-skills` for Claude Code, Codex, and Antigravity.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cellscreen
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Run in silico perturbation screens with CellGemma E4B on Apple MLX or a vLLM GPU server
|
|
5
5
|
Project-URL: Homepage, https://github.com/ayushgml/cellscreen
|
|
6
6
|
Project-URL: Repository, https://github.com/ayushgml/cellscreen
|
|
@@ -32,12 +32,22 @@ Requires-Dist: numpy>=1.26.0
|
|
|
32
32
|
Requires-Dist: pydantic>=2.10.0
|
|
33
33
|
Requires-Dist: rich>=13.9.0
|
|
34
34
|
Requires-Dist: safetensors>=0.5.0
|
|
35
|
+
Requires-Dist: tokenizers>=0.20.0
|
|
35
36
|
Requires-Dist: typer>=0.15.0
|
|
36
37
|
Requires-Dist: uvicorn>=0.34.0
|
|
38
|
+
Provides-Extra: anndata
|
|
39
|
+
Requires-Dist: anndata>=0.10.0; extra == 'anndata'
|
|
40
|
+
Requires-Dist: h5py>=3.11.0; extra == 'anndata'
|
|
41
|
+
Requires-Dist: pandas>=2.2.0; extra == 'anndata'
|
|
37
42
|
Provides-Extra: dev
|
|
38
43
|
Requires-Dist: pytest-asyncio>=0.25.0; extra == 'dev'
|
|
39
44
|
Requires-Dist: pytest>=8.3.0; extra == 'dev'
|
|
40
45
|
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
46
|
+
Provides-Extra: ingest
|
|
47
|
+
Requires-Dist: anndata>=0.10.0; extra == 'ingest'
|
|
48
|
+
Requires-Dist: h5py>=3.11.0; extra == 'ingest'
|
|
49
|
+
Requires-Dist: pandas>=2.2.0; extra == 'ingest'
|
|
50
|
+
Requires-Dist: pyarrow>=17.0.0; extra == 'ingest'
|
|
41
51
|
Description-Content-Type: text/markdown
|
|
42
52
|
|
|
43
53
|
<p align="center">
|
|
@@ -79,8 +89,16 @@ writes everything to a folder you can resume, share or open as an interactive re
|
|
|
79
89
|
MLP weights to 4-bit but keeps Gemma 4's Per-Layer Embeddings at 8-bit or bf16.
|
|
80
90
|
- **Resumable by design.** All state lives in the run folder. Stop, restart, move machines or
|
|
81
91
|
switch coding agents, and `cellscreen run` picks up where it stopped.
|
|
82
|
-
- **An offline report.** One self-contained HTML file with
|
|
83
|
-
|
|
92
|
+
- **An offline report.** One self-contained HTML file with full-vector NPZ contrasts (`p - b`,
|
|
93
|
+
`p - c`, `b - c`), bounded within-sign rank percentiles, linearly decomposable cancer programs
|
|
94
|
+
and Szalai death/proliferation plots, an embedded Wet-Lab Decision Dossier, a sortable table,
|
|
95
|
+
and formula-safe CSV/JSON export.
|
|
96
|
+
- **Translational oncology toolkit (CPU).** Run tokenizer preflight (`preflight`), import
|
|
97
|
+
portable same-assay controls (`controls import`), match external resistance signatures
|
|
98
|
+
(`match`), benchmark against identity/mean-shift/Ridge (`eval`), export `.h5ad` (`export-h5ad`),
|
|
99
|
+
calibrate short-cap triage (`triage`), expand multi-context/multi-seed panels (`expand-panel`),
|
|
100
|
+
evaluate sampling stability (`stability`) and signed prior-corrected epistasis (`epistasis`),
|
|
101
|
+
and design randomized 24/96-well validation plates (`plate`).
|
|
84
102
|
- **Agent skills included.** Run `cellscreen install-skills` to install bundled skills for
|
|
85
103
|
Claude Code, Codex and Antigravity without cloning the repo.
|
|
86
104
|
|
|
@@ -93,6 +111,10 @@ uv tool install cellscreen
|
|
|
93
111
|
# pip
|
|
94
112
|
pip install cellscreen
|
|
95
113
|
|
|
114
|
+
# Optional extras for AnnData .h5ad export or Parquet/.h5ad controls ingestion
|
|
115
|
+
pip install "cellscreen[anndata]"
|
|
116
|
+
pip install "cellscreen[ingest]"
|
|
117
|
+
|
|
96
118
|
# Homebrew (macOS)
|
|
97
119
|
brew install ayushgml/tap/cellscreen
|
|
98
120
|
```
|
|
@@ -167,10 +189,20 @@ genes against the bf16 GPU run, compared to `0.21–0.51` between different drug
|
|
|
167
189
|
| `cellscreen health` | Check a local MLX or vLLM server and its status |
|
|
168
190
|
| `cellscreen list-decoders` | List the 13 Stage-2 decoders |
|
|
169
191
|
| `cellscreen examples` | List or inspect bundled example screen JSONs (`tahoe`, `k562`) |
|
|
170
|
-
| `cellscreen init` | Create a run folder from `--from <file>` or `--example <name>` |
|
|
192
|
+
| `cellscreen init` | Create a run folder from `--from <file>` or `--example <name>` (with optional `--controls-file`) |
|
|
193
|
+
| `cellscreen preflight` | Tokenizer-only context-limit, wire-compatibility, and PLE RAM check before inference |
|
|
171
194
|
| `cellscreen run` | Run or resume pending perturbations and refresh the report |
|
|
172
|
-
| `cellscreen status` | Show progress and top genes from disk |
|
|
173
|
-
| `cellscreen report` | Rebuild `report.html` |
|
|
195
|
+
| `cellscreen status` | Show progress, integrity audit, and top genes from disk |
|
|
196
|
+
| `cellscreen report` | Rebuild `report.html` (including Decision Dossier if `plate_plan.json` exists) |
|
|
197
|
+
| `cellscreen controls import` | Import `.h5ad`/CSV/JSON/Parquet controls into a portable `controls_pack.json` |
|
|
198
|
+
| `cellscreen match` | Zero-LLM signature reversal (`sRGES`/linear) across runs with Szalai viability flags |
|
|
199
|
+
| `cellscreen eval` | Held-out evaluation vs identity, mean-shift, and training-only Ridge baseline |
|
|
200
|
+
| `cellscreen export-h5ad` | Export validated vectors and layers to AnnData `.h5ad` (`[anndata]` extra) |
|
|
201
|
+
| `cellscreen triage` | Export Stage-1 `shortlist.json` or run stratified short-cap (`2048` vs `8192`) calibration |
|
|
202
|
+
| `cellscreen expand-panel` | Expand a manifest across control cell indices and/or sampling seeds |
|
|
203
|
+
| `cellscreen stability` | Evaluate K=5 sampling stability at T=0.7 per frozen backend/checkpoint/control |
|
|
204
|
+
| `cellscreen epistasis` | Compute signed prior-corrected epistasis `Delta - (c - b)` and Norman split eval |
|
|
205
|
+
| `cellscreen plate` | Build randomized 96-well or 24-well validation layouts (`plate_plan.json` + `plate_map.csv`) |
|
|
174
206
|
| `cellscreen handoff` | Write a short summary for another agent |
|
|
175
207
|
| `cellscreen install-skills` | Install bundled skills for Claude Code, Codex, and Antigravity |
|
|
176
208
|
|
|
@@ -37,8 +37,16 @@ writes everything to a folder you can resume, share or open as an interactive re
|
|
|
37
37
|
MLP weights to 4-bit but keeps Gemma 4's Per-Layer Embeddings at 8-bit or bf16.
|
|
38
38
|
- **Resumable by design.** All state lives in the run folder. Stop, restart, move machines or
|
|
39
39
|
switch coding agents, and `cellscreen run` picks up where it stopped.
|
|
40
|
-
- **An offline report.** One self-contained HTML file with
|
|
41
|
-
|
|
40
|
+
- **An offline report.** One self-contained HTML file with full-vector NPZ contrasts (`p - b`,
|
|
41
|
+
`p - c`, `b - c`), bounded within-sign rank percentiles, linearly decomposable cancer programs
|
|
42
|
+
and Szalai death/proliferation plots, an embedded Wet-Lab Decision Dossier, a sortable table,
|
|
43
|
+
and formula-safe CSV/JSON export.
|
|
44
|
+
- **Translational oncology toolkit (CPU).** Run tokenizer preflight (`preflight`), import
|
|
45
|
+
portable same-assay controls (`controls import`), match external resistance signatures
|
|
46
|
+
(`match`), benchmark against identity/mean-shift/Ridge (`eval`), export `.h5ad` (`export-h5ad`),
|
|
47
|
+
calibrate short-cap triage (`triage`), expand multi-context/multi-seed panels (`expand-panel`),
|
|
48
|
+
evaluate sampling stability (`stability`) and signed prior-corrected epistasis (`epistasis`),
|
|
49
|
+
and design randomized 24/96-well validation plates (`plate`).
|
|
42
50
|
- **Agent skills included.** Run `cellscreen install-skills` to install bundled skills for
|
|
43
51
|
Claude Code, Codex and Antigravity without cloning the repo.
|
|
44
52
|
|
|
@@ -51,6 +59,10 @@ uv tool install cellscreen
|
|
|
51
59
|
# pip
|
|
52
60
|
pip install cellscreen
|
|
53
61
|
|
|
62
|
+
# Optional extras for AnnData .h5ad export or Parquet/.h5ad controls ingestion
|
|
63
|
+
pip install "cellscreen[anndata]"
|
|
64
|
+
pip install "cellscreen[ingest]"
|
|
65
|
+
|
|
54
66
|
# Homebrew (macOS)
|
|
55
67
|
brew install ayushgml/tap/cellscreen
|
|
56
68
|
```
|
|
@@ -125,10 +137,20 @@ genes against the bf16 GPU run, compared to `0.21–0.51` between different drug
|
|
|
125
137
|
| `cellscreen health` | Check a local MLX or vLLM server and its status |
|
|
126
138
|
| `cellscreen list-decoders` | List the 13 Stage-2 decoders |
|
|
127
139
|
| `cellscreen examples` | List or inspect bundled example screen JSONs (`tahoe`, `k562`) |
|
|
128
|
-
| `cellscreen init` | Create a run folder from `--from <file>` or `--example <name>` |
|
|
140
|
+
| `cellscreen init` | Create a run folder from `--from <file>` or `--example <name>` (with optional `--controls-file`) |
|
|
141
|
+
| `cellscreen preflight` | Tokenizer-only context-limit, wire-compatibility, and PLE RAM check before inference |
|
|
129
142
|
| `cellscreen run` | Run or resume pending perturbations and refresh the report |
|
|
130
|
-
| `cellscreen status` | Show progress and top genes from disk |
|
|
131
|
-
| `cellscreen report` | Rebuild `report.html` |
|
|
143
|
+
| `cellscreen status` | Show progress, integrity audit, and top genes from disk |
|
|
144
|
+
| `cellscreen report` | Rebuild `report.html` (including Decision Dossier if `plate_plan.json` exists) |
|
|
145
|
+
| `cellscreen controls import` | Import `.h5ad`/CSV/JSON/Parquet controls into a portable `controls_pack.json` |
|
|
146
|
+
| `cellscreen match` | Zero-LLM signature reversal (`sRGES`/linear) across runs with Szalai viability flags |
|
|
147
|
+
| `cellscreen eval` | Held-out evaluation vs identity, mean-shift, and training-only Ridge baseline |
|
|
148
|
+
| `cellscreen export-h5ad` | Export validated vectors and layers to AnnData `.h5ad` (`[anndata]` extra) |
|
|
149
|
+
| `cellscreen triage` | Export Stage-1 `shortlist.json` or run stratified short-cap (`2048` vs `8192`) calibration |
|
|
150
|
+
| `cellscreen expand-panel` | Expand a manifest across control cell indices and/or sampling seeds |
|
|
151
|
+
| `cellscreen stability` | Evaluate K=5 sampling stability at T=0.7 per frozen backend/checkpoint/control |
|
|
152
|
+
| `cellscreen epistasis` | Compute signed prior-corrected epistasis `Delta - (c - b)` and Norman split eval |
|
|
153
|
+
| `cellscreen plate` | Build randomized 96-well or 24-well validation layouts (`plate_plan.json` + `plate_map.csv`) |
|
|
132
154
|
| `cellscreen handoff` | Write a short summary for another agent |
|
|
133
155
|
| `cellscreen install-skills` | Install bundled skills for Claude Code, Codex, and Antigravity |
|
|
134
156
|
|
|
@@ -228,19 +228,56 @@ it stopped.
|
|
|
228
228
|
|
|
229
229
|
```text
|
|
230
230
|
runs/<id>/
|
|
231
|
-
├── manifest.json # the screen spec, with
|
|
231
|
+
├── manifest.json # the screen spec, with condition item_id and execution policy
|
|
232
|
+
├── controls_pack.json # optional portable same-assay controls pack + measured-feature mask
|
|
232
233
|
├── results.jsonl # one line per finished perturbation, appended as they complete
|
|
233
|
-
├── vectors
|
|
234
|
-
├──
|
|
234
|
+
├── vectors/*.npz # immutable per-execution predicted expression, baseline, ctrl & LFC arrays
|
|
235
|
+
├── analysis.json # linearly decomposable program scores, Szalai covariates & contrasts
|
|
236
|
+
├── telemetry.json # boundary-separated server lock-wait, service & HTTP attempt timings
|
|
237
|
+
├── plate_plan.json # optional CPU 96/24-well randomized validation plate plan
|
|
238
|
+
├── plate_map.csv # paired RFC-4180 formula-safe well layout (shared layout_sha256)
|
|
239
|
+
├── shortlist.json # optional Stage-1 triage shortlist / Endpoint 5 calibration output
|
|
240
|
+
├── report.html # offline interactive report (full NPZ contrasts + Decision Dossier)
|
|
235
241
|
└── HANDOFF.md # optional summary for another agent (cellscreen handoff --write)
|
|
236
242
|
```
|
|
237
243
|
|
|
238
|
-
Each line of `results.jsonl` records the raw model output,
|
|
239
|
-
|
|
244
|
+
Each line of `results.jsonl` records the raw model output, parsed up/down genes, execution
|
|
245
|
+
fingerprint, vector SHA-256, `finish_reason`, `at_token_cap`, token counts, and separated
|
|
246
|
+
queue/service timings.
|
|
240
247
|
|
|
241
|
-
`report.html` works offline. It
|
|
242
|
-
|
|
243
|
-
|
|
248
|
+
`report.html` works offline. It includes `p - b` / `p - c` / `b - c` contrast toggles backed
|
|
249
|
+
directly by `vectors/*.npz`, bounded within-sign rank percentiles, linearly decomposable cancer
|
|
250
|
+
programs with Szalai death/proliferation scatter plots, an embedded Wet-Lab Decision Dossier
|
|
251
|
+
when `plate_plan.json` is present, a sortable table, and formula-safe CSV/JSON export.
|
|
252
|
+
|
|
253
|
+
## Translational oncology & validation workflows (CPU)
|
|
254
|
+
|
|
255
|
+
All downstream analysis commands run purely on CPU from saved run folders:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# 1. Check tokenizer context limits (e.g. 4,800 input limit on 24 GB L4) before running
|
|
259
|
+
uv run cellscreen preflight runs/<id> --max-model-len 12992
|
|
260
|
+
|
|
261
|
+
# 2. Import custom same-assay controls (.h5ad / CSV / JSON / Parquet) into a portable pack
|
|
262
|
+
uv run cellscreen controls import my_controls.h5ad --dataset sciplex --output controls_pack.json
|
|
263
|
+
uv run cellscreen init runs/<id> --from panel.json --controls-file controls_pack.json --allow-unvalidated-reference
|
|
264
|
+
|
|
265
|
+
# 3. Reverse an external disease/resistance signature across runs (zero LLM calls)
|
|
266
|
+
uv run cellscreen match --signature resistance.json runs/<id>
|
|
267
|
+
|
|
268
|
+
# 4. Evaluate held-out predictions against identity, mean-shift, and training-only Ridge
|
|
269
|
+
uv run cellscreen eval runs/<tahoe> runs/<sciplex> --truth truth.json --train train.json
|
|
270
|
+
|
|
271
|
+
# 5. Export AnnData .h5ad for scanpy / pertpy / cell-eval2 (requires `uv sync --extra anndata`)
|
|
272
|
+
uv run cellscreen export-h5ad runs/<id> --output runs/<id>/screen.h5ad
|
|
273
|
+
|
|
274
|
+
# 6. Multi-context/seed panels, stability, signed epistasis, triage, and 24/96-well plates
|
|
275
|
+
uv run cellscreen expand-panel runs/<base> --out runs/<panel> --cell-indices 0,1 --seeds 0,1,2,3,4 --temperature 0.7 --preflight
|
|
276
|
+
uv run cellscreen stability runs/<panel> --json
|
|
277
|
+
uv run cellscreen epistasis runs/<combo_run> --output runs/<combo_run>/epistasis.json
|
|
278
|
+
uv run cellscreen triage runs/<short_2048> --full-run runs/<full_8192> --measured-json measured.json
|
|
279
|
+
uv run cellscreen plate runs/<id> --format 96-well --seed 42
|
|
280
|
+
```
|
|
244
281
|
|
|
245
282
|
## Use with coding agents
|
|
246
283
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cellscreen"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Run in silico perturbation screens with CellGemma E4B on Apple MLX or a vLLM GPU server"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -44,6 +44,7 @@ dependencies = [
|
|
|
44
44
|
"pydantic>=2.10.0",
|
|
45
45
|
"rich>=13.9.0",
|
|
46
46
|
"safetensors>=0.5.0",
|
|
47
|
+
"tokenizers>=0.20.0",
|
|
47
48
|
"typer>=0.15.0",
|
|
48
49
|
"uvicorn>=0.34.0",
|
|
49
50
|
]
|
|
@@ -56,6 +57,17 @@ Changelog = "https://github.com/ayushgml/cellscreen/blob/main/CHANGELOG.md"
|
|
|
56
57
|
Issues = "https://github.com/ayushgml/cellscreen/issues"
|
|
57
58
|
|
|
58
59
|
[project.optional-dependencies]
|
|
60
|
+
anndata = [
|
|
61
|
+
"anndata>=0.10.0",
|
|
62
|
+
"h5py>=3.11.0",
|
|
63
|
+
"pandas>=2.2.0",
|
|
64
|
+
]
|
|
65
|
+
ingest = [
|
|
66
|
+
"anndata>=0.10.0",
|
|
67
|
+
"h5py>=3.11.0",
|
|
68
|
+
"pandas>=2.2.0",
|
|
69
|
+
"pyarrow>=17.0.0",
|
|
70
|
+
]
|
|
59
71
|
dev = [
|
|
60
72
|
"pytest>=8.3.0",
|
|
61
73
|
"pytest-asyncio>=0.25.0",
|
|
@@ -83,6 +95,7 @@ include = [
|
|
|
83
95
|
"/.agents/skills/cellscreen",
|
|
84
96
|
"/.claude/skills/cellscreen",
|
|
85
97
|
"/docs",
|
|
98
|
+
"/scripts",
|
|
86
99
|
"/README.md",
|
|
87
100
|
"/CHANGELOG.md",
|
|
88
101
|
"/LICENSE",
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Reproducible cold NPZ + CPU linear-program & report benchmark for CellScreen (WS-4).
|
|
3
|
+
|
|
4
|
+
Measures wall-clock latency and peak RSS in a fresh Python process for:
|
|
5
|
+
1. NPZ vector validation + loading across all completed items in a run directory.
|
|
6
|
+
2. Offline WS-2 fixed-universe linear program & Szalai sensitivity decomposition.
|
|
7
|
+
3. Full interactive HTML report generation (`report.html` byte size & build time).
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
uv run python scripts/benchmark_cpu_npz.py runs/tahoe-local-q8
|
|
11
|
+
uv run python scripts/benchmark_cpu_npz.py --synthetic 100
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import json
|
|
18
|
+
import resource
|
|
19
|
+
import subprocess
|
|
20
|
+
import sys
|
|
21
|
+
import tempfile
|
|
22
|
+
import time
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
from cellscreen.analytics import analyze_run
|
|
28
|
+
from cellscreen.report import MAX_REPORT_BYTES_100_ITEMS, generate_report
|
|
29
|
+
from cellscreen.schemas import (
|
|
30
|
+
PerturbationSpec,
|
|
31
|
+
RunManifest,
|
|
32
|
+
ScreenResultRecord,
|
|
33
|
+
compute_condition_digest,
|
|
34
|
+
compute_config_fingerprint,
|
|
35
|
+
)
|
|
36
|
+
from cellscreen.store import RunStore, compute_gene_order_sha256
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _peak_rss_mb() -> float:
|
|
40
|
+
usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
|
41
|
+
divisor = (1024 * 1024) if sys.platform == "darwin" else 1024
|
|
42
|
+
return round(usage / divisor, 2)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _create_synthetic_run(run_dir: Path, n_items: int, n_genes: int = 19_720) -> RunStore:
|
|
46
|
+
if n_genes < 4:
|
|
47
|
+
raise ValueError(f"--genes must be >= 4 (got {n_genes})")
|
|
48
|
+
rng = np.random.default_rng(42)
|
|
49
|
+
genes = [f"GENE{i}" for i in range(n_genes)]
|
|
50
|
+
genes[0], genes[1], genes[2], genes[3] = "ISG15", "IFIT2", "BAX", "MKI67"
|
|
51
|
+
specs = [
|
|
52
|
+
PerturbationSpec(
|
|
53
|
+
label=f"Compound {i}",
|
|
54
|
+
modality="small_molecule",
|
|
55
|
+
drug_name=f"Comp{i}",
|
|
56
|
+
smiles="CCO",
|
|
57
|
+
concentration=f"{i + 1} uM",
|
|
58
|
+
)
|
|
59
|
+
for i in range(n_items)
|
|
60
|
+
]
|
|
61
|
+
manifest = RunManifest(
|
|
62
|
+
run_id=f"bench-{n_items}",
|
|
63
|
+
dataset="tahoe",
|
|
64
|
+
asset_repo_id="mock/synthetic-benchmark",
|
|
65
|
+
expected_genes_sha256=compute_gene_order_sha256(genes),
|
|
66
|
+
perturbations=specs,
|
|
67
|
+
)
|
|
68
|
+
store = RunStore(run_dir)
|
|
69
|
+
store.init(manifest)
|
|
70
|
+
ctrl = rng.uniform(0.0, 3.0, size=n_genes).astype(np.float32)
|
|
71
|
+
base = np.maximum(0.0, ctrl + rng.normal(0.0, 0.1, size=n_genes)).astype(np.float32)
|
|
72
|
+
k_pert = min(40, n_genes)
|
|
73
|
+
for spec in manifest.perturbations:
|
|
74
|
+
pred = base.copy()
|
|
75
|
+
pred[:k_pert] = np.maximum(
|
|
76
|
+
0.0, base[:k_pert] + rng.normal(0.0, 0.4, size=k_pert)
|
|
77
|
+
).astype(np.float32)
|
|
78
|
+
lfc = (pred - ctrl).astype(np.float32)
|
|
79
|
+
cfg_fp = compute_config_fingerprint(manifest, spec)
|
|
80
|
+
cond_sha = compute_condition_digest(manifest, spec)
|
|
81
|
+
rel_path = store.allocate_immutable_vector_path(spec.item_id, cfg_fp)
|
|
82
|
+
rel, sha = store.save_vectors_with_digest(
|
|
83
|
+
spec.item_id, genes, ctrl, base, pred, lfc, rel_path=rel_path, allow_overwrite=False
|
|
84
|
+
)
|
|
85
|
+
store.append_result(
|
|
86
|
+
ScreenResultRecord(
|
|
87
|
+
item_id=spec.item_id,
|
|
88
|
+
label=spec.label,
|
|
89
|
+
modality=spec.modality,
|
|
90
|
+
dataset="tahoe",
|
|
91
|
+
cell_idx=0,
|
|
92
|
+
status="ok",
|
|
93
|
+
raw_text="+ISG15 -IFIT2",
|
|
94
|
+
up_genes=["ISG15"],
|
|
95
|
+
down_genes=["IFIT2"],
|
|
96
|
+
n_up=1,
|
|
97
|
+
n_down=1,
|
|
98
|
+
max_abs_lfc=float(np.max(np.abs(lfc))),
|
|
99
|
+
max_abs_model_increment=float(np.max(np.abs(pred - base))),
|
|
100
|
+
l2_lfc=float(np.linalg.norm(lfc.astype(np.float64))),
|
|
101
|
+
l2_model_increment=float(np.linalg.norm((pred - base).astype(np.float64))),
|
|
102
|
+
condition_sha256=cond_sha,
|
|
103
|
+
execution_fingerprint=cfg_fp,
|
|
104
|
+
config_fingerprint=cfg_fp,
|
|
105
|
+
vector_file=rel,
|
|
106
|
+
vector_sha256=sha,
|
|
107
|
+
provenance_status="recorded",
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
return store
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def benchmark_run(run_dir: Path, *, expected_items: int | None = None) -> dict[str, object]:
|
|
114
|
+
store = RunStore(run_dir)
|
|
115
|
+
manifest = store.load_manifest()
|
|
116
|
+
expected_ids = {spec.item_id for spec in manifest.perturbations}
|
|
117
|
+
if expected_items is not None and len(expected_ids) != expected_items:
|
|
118
|
+
raise RuntimeError(
|
|
119
|
+
f"Manifest item count mismatch: expected {expected_items}, got {len(expected_ids)}."
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
t0 = time.perf_counter()
|
|
123
|
+
latest = store.load_latest_results(require_valid_vectors=True)
|
|
124
|
+
validated_ids = {item_id for item_id, rec in latest.items() if rec.status == "ok"}
|
|
125
|
+
n_valid = len(validated_ids)
|
|
126
|
+
t_validate_ms = round((time.perf_counter() - t0) * 1000.0, 2)
|
|
127
|
+
|
|
128
|
+
if validated_ids != expected_ids:
|
|
129
|
+
missing = sorted(expected_ids - validated_ids)
|
|
130
|
+
extra = sorted(validated_ids - expected_ids)
|
|
131
|
+
raise RuntimeError(
|
|
132
|
+
f"Benchmark validation failed: validated IDs ({n_valid}) != expected manifest IDs "
|
|
133
|
+
f"({len(expected_ids)}); missing={missing[:5]}, extra={extra[:5]}."
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
t1 = time.perf_counter()
|
|
137
|
+
analyze_run(store, records_snapshot=latest, write_sidecar=False)
|
|
138
|
+
t_analyze_ms = round((time.perf_counter() - t1) * 1000.0, 2)
|
|
139
|
+
|
|
140
|
+
with tempfile.TemporaryDirectory() as tmp_out:
|
|
141
|
+
out_html = Path(tmp_out) / "report.html"
|
|
142
|
+
t2 = time.perf_counter()
|
|
143
|
+
generate_report(run_dir, output_path=out_html)
|
|
144
|
+
t_report_ms = round((time.perf_counter() - t2) * 1000.0, 2)
|
|
145
|
+
report_bytes = out_html.stat().st_size
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
"run_id": manifest.run_id,
|
|
149
|
+
"dataset": manifest.dataset,
|
|
150
|
+
"timing_mode": "fresh_process_warm_os_page_cache",
|
|
151
|
+
"n_valid_items": n_valid,
|
|
152
|
+
"validate_and_load_ms": t_validate_ms,
|
|
153
|
+
"analyze_programs_ms": t_analyze_ms,
|
|
154
|
+
"generate_report_ms": t_report_ms,
|
|
155
|
+
"report_bytes": report_bytes,
|
|
156
|
+
"within_100_item_ceiling": report_bytes <= MAX_REPORT_BYTES_100_ITEMS,
|
|
157
|
+
"peak_rss_mb": _peak_rss_mb(),
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def main() -> None:
|
|
162
|
+
parser = argparse.ArgumentParser(
|
|
163
|
+
description="Benchmark NPZ validation, WS-2 analytics, and report generation in a fresh process."
|
|
164
|
+
)
|
|
165
|
+
parser.add_argument("run_dir", nargs="?", help="Existing run directory to benchmark")
|
|
166
|
+
parser.add_argument("--synthetic", type=int, default=None, help="Generate & benchmark a synthetic N-item run")
|
|
167
|
+
parser.add_argument("--genes", type=int, default=19_720, help="Gene count for synthetic benchmark (>= 4)")
|
|
168
|
+
parser.add_argument("--expected-items", type=int, default=None, help=argparse.SUPPRESS)
|
|
169
|
+
args = parser.parse_args()
|
|
170
|
+
|
|
171
|
+
if args.synthetic is not None:
|
|
172
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
173
|
+
bench_dir = Path(tmp) / "synthetic-bench"
|
|
174
|
+
_create_synthetic_run(bench_dir, args.synthetic, args.genes)
|
|
175
|
+
# Run measurement inside a fresh child Python process so no in-process caches carry over
|
|
176
|
+
out = subprocess.check_output(
|
|
177
|
+
[
|
|
178
|
+
sys.executable,
|
|
179
|
+
str(Path(__file__).resolve()),
|
|
180
|
+
str(bench_dir),
|
|
181
|
+
"--expected-items",
|
|
182
|
+
str(args.synthetic),
|
|
183
|
+
],
|
|
184
|
+
text=True,
|
|
185
|
+
)
|
|
186
|
+
print(out.strip())
|
|
187
|
+
return
|
|
188
|
+
if args.run_dir:
|
|
189
|
+
result = benchmark_run(Path(args.run_dir), expected_items=args.expected_items)
|
|
190
|
+
print(json.dumps(result, indent=2))
|
|
191
|
+
return
|
|
192
|
+
parser.error("Provide either <run_dir> or --synthetic N")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
if __name__ == "__main__":
|
|
196
|
+
main()
|