Skip to content

Commit 2a4a4c7

Browse files
committed
Add SolvAI inference and reproducibility core
0 parents  commit 2a4a4c7

27 files changed

Lines changed: 4006 additions & 0 deletions

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
models/final/*.joblib filter=lfs diff=lfs merge=lfs -text
2+
models/final/*.pt filter=lfs diff=lfs merge=lfs -text
3+
data/processed/*.parquet filter=lfs diff=lfs merge=lfs -text

‎.gitignore‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.venv/
2+
.pytest_cache/
3+
.ruff_cache/
4+
__pycache__/
5+
*.py[cod]
6+
*.egg-info/
7+
.DS_Store
8+
build/
9+
dist/
10+
data/external/
11+
.coverage
12+
paper/*.aux
13+
paper/*.bbl
14+
paper/*.bcf
15+
paper/*.blg
16+
paper/*.fdb_latexmk
17+
paper/*.fls
18+
paper/*.log
19+
paper/*.out
20+
paper/*.run.xml
21+
paper/*.synctex.gz
22+
paper/*.toc

‎LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Gal Oren and Michael Levitt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

‎Makefile‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.PHONY: setup test verify metrics tables figures paper security claims clean
2+
3+
setup:
4+
uv sync --extra dev
5+
6+
test:
7+
uv run pytest -q
8+
9+
metrics:
10+
uv run python scripts/reproduce_metrics.py
11+
12+
verify: metrics
13+
uv run python scripts/audit_leakage.py
14+
uv run python scripts/verify_artifact.py
15+
uv run python scripts/check_claims.py
16+
uv run python scripts/security_scan.py
17+
uv run python scripts/verify_release_manifest.py
18+
19+
tables: metrics
20+
uv run python scripts/make_tables.py
21+
22+
figures: tables
23+
uv run python scripts/make_figures.py
24+
25+
paper: figures
26+
latexmk -pdf -interaction=nonstopmode -halt-on-error -cd paper/main.tex
27+
latexmk -pdf -interaction=nonstopmode -halt-on-error -cd paper/supplementary.tex
28+
29+
security:
30+
uv run python scripts/security_scan.py
31+
32+
claims:
33+
uv run python scripts/check_claims.py
34+
35+
clean:
36+
latexmk -C -cd paper/main.tex
37+
latexmk -C -cd paper/supplementary.tex

‎pyproject.toml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[project]
2+
name = "solv-ai"
3+
version = "1.0.0"
4+
description = "Physics-distilled, structure-only hydration free-energy prediction"
5+
readme = "README.md"
6+
license = "MIT"
7+
requires-python = ">=3.11,<3.12"
8+
authors = [
9+
{ name = "Gal Oren" },
10+
{ name = "Michael Levitt" },
11+
]
12+
dependencies = [
13+
"chemprop==2.2.4",
14+
"joblib==1.5.3",
15+
"lightgbm==4.7.0",
16+
"matplotlib==3.11.1",
17+
"numpy==2.4.6",
18+
"pandas==3.0.5",
19+
"pyarrow==25.0.1",
20+
"rdkit==2026.3.5",
21+
"scikit-learn==1.7.2",
22+
"seaborn==0.13.2",
23+
"torch==2.5.1",
24+
]
25+
26+
[project.optional-dependencies]
27+
dev = [
28+
"pytest==9.1.1",
29+
"ruff==0.16.4",
30+
]
31+
training = [
32+
"openpyxl==3.1.5",
33+
"xgboost==3.2.0",
34+
]
35+
36+
[project.scripts]
37+
solvai = "solv_ai.cli:main"
38+
39+
[build-system]
40+
requires = ["hatchling"]
41+
build-backend = "hatchling.build"
42+
43+
[tool.hatch.build.targets.wheel]
44+
packages = ["solv_ai"]
45+
46+
[tool.ruff]
47+
line-length = 100
48+
49+
[tool.pytest.ini_options]
50+
testpaths = ["tests"]

‎scripts/audit_leakage.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
"""Run the independent release leakage and inference audit."""
3+
4+
import json
5+
6+
from solv_ai.audit import write_leakage_audit
7+
8+
if __name__ == "__main__":
9+
print(json.dumps(write_leakage_audit(), indent=2))

‎scripts/benchmark_inference.py‎

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env python3
2+
"""Benchmark the released SolvAI artifact without fitting or model selection."""
3+
4+
from __future__ import annotations
5+
6+
import argparse
7+
import json
8+
import os
9+
import platform
10+
import statistics
11+
import subprocess
12+
import sys
13+
import tempfile
14+
import time
15+
from pathlib import Path
16+
17+
import chemprop
18+
import joblib
19+
import lightgbm
20+
import numpy
21+
import pandas
22+
import pandas as pd
23+
import rdkit
24+
import sklearn
25+
import torch
26+
27+
from solv_ai import predict_smiles
28+
29+
ROOT = Path(__file__).resolve().parents[1]
30+
31+
32+
def percentile(values: list[float], percentile_value: float) -> float:
33+
ordered = sorted(values)
34+
position = (len(ordered) - 1) * percentile_value / 100.0
35+
lower = int(position)
36+
upper = min(lower + 1, len(ordered) - 1)
37+
fraction = position - lower
38+
return ordered[lower] * (1 - fraction) + ordered[upper] * fraction
39+
40+
41+
def timed_prediction(smiles: list[str]) -> float:
42+
start = time.perf_counter()
43+
predict_smiles(smiles)
44+
return time.perf_counter() - start
45+
46+
47+
def cpu_model() -> str:
48+
for line in Path("/proc/cpuinfo").read_text().splitlines():
49+
if line.startswith("model name"):
50+
return line.split(":", 1)[1].strip()
51+
return platform.processor() or "unknown"
52+
53+
54+
def gpu_model() -> str:
55+
try:
56+
return subprocess.check_output(
57+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], text=True
58+
).strip()
59+
except (FileNotFoundError, subprocess.CalledProcessError):
60+
return "not used / unavailable"
61+
62+
63+
def measured_peak_rss_kib(smiles: str) -> int | None:
64+
executable = Path("/usr/bin/time")
65+
if not executable.is_file():
66+
return None
67+
with tempfile.TemporaryDirectory(prefix="solvai_benchmark_") as directory:
68+
output = Path(directory) / "time.txt"
69+
subprocess.run(
70+
[
71+
str(executable),
72+
"-v",
73+
"-o",
74+
str(output),
75+
sys.executable,
76+
"-m",
77+
"solv_ai.cli",
78+
smiles,
79+
],
80+
cwd=ROOT,
81+
check=True,
82+
capture_output=True,
83+
text=True,
84+
)
85+
for line in output.read_text().splitlines():
86+
if "Maximum resident set size" in line:
87+
return int(line.rsplit(":", 1)[1].strip())
88+
return None
89+
90+
91+
def main() -> None:
92+
parser = argparse.ArgumentParser()
93+
parser.add_argument("--warm-runs", type=int, default=5)
94+
parser.add_argument("--batch-runs", type=int, default=3)
95+
parser.add_argument("--batch-size", type=int, default=32)
96+
args = parser.parse_args()
97+
if args.warm_runs < 3 or args.batch_runs < 3:
98+
raise ValueError("Use at least three repeated measurements")
99+
100+
benchmark = pd.read_parquet(ROOT / "data/benchmark/arrow_solvation_master.parquet")
101+
smiles = benchmark.loc[benchmark.solvent.eq("water"), "canonical_smiles"].tolist()
102+
batch = smiles[: args.batch_size]
103+
104+
cold = timed_prediction(["CCO"])
105+
warm = [timed_prediction(["CCO"]) for _ in range(args.warm_runs)]
106+
batch_times = [timed_prediction(batch) for _ in range(args.batch_runs)]
107+
batch_per_molecule = [value / len(batch) for value in batch_times]
108+
peak_rss = measured_peak_rss_kib("CCO")
109+
110+
# ARROW Supplementary Table 2: 16–18 h per 1 ns PIMD8 window on one
111+
# RTX 2080 Ti + two CPU cores; the published hydration protocol uses 15 windows.
112+
published_total_hours = [15 * 16, 15 * 18]
113+
median_single_seconds = statistics.median(warm)
114+
median_batch_per_molecule_seconds = statistics.median(batch_per_molecule)
115+
result = {
116+
"schema_version": 1,
117+
"artifact": "models/final",
118+
"input": "SMILES",
119+
"hardware": {
120+
"cpu": cpu_model(),
121+
"logical_cpus": os.cpu_count(),
122+
"gpu_present_but_not_used": gpu_model(),
123+
"platform": platform.platform(),
124+
},
125+
"software": {
126+
"python": platform.python_version(),
127+
"chemprop": chemprop.__version__,
128+
"torch": torch.__version__,
129+
"rdkit": rdkit.__version__,
130+
"numpy": numpy.__version__,
131+
"pandas": pandas.__version__,
132+
"scikit_learn": sklearn.__version__,
133+
"lightgbm": lightgbm.__version__,
134+
"joblib": joblib.__version__,
135+
},
136+
"single_molecule": {
137+
"cold_seconds": cold,
138+
"warm_runs_seconds": warm,
139+
"warm_median_seconds": median_single_seconds,
140+
"warm_p95_seconds": percentile(warm, 95),
141+
"peak_rss_kib": peak_rss,
142+
},
143+
"batch": {
144+
"size": len(batch),
145+
"runs_seconds": batch_times,
146+
"median_seconds": statistics.median(batch_times),
147+
"p95_seconds": percentile(batch_times, 95),
148+
"median_seconds_per_molecule": median_batch_per_molecule_seconds,
149+
"molecules_per_second": 1.0 / median_batch_per_molecule_seconds,
150+
},
151+
"published_arrow_pimd8_reference": {
152+
"hardware": "NVIDIA GeForce RTX 2080 Ti + 2 CPU cores",
153+
"hours_per_1ns_window_range": [16, 18],
154+
"windows": 15,
155+
"total_serial_gpu_hours_range": published_total_hours,
156+
"ideal_parallel_wall_hours_range_on_15_gpus": [16, 18],
157+
"source": "Pereyaslavets et al., Nature Communications 13, 414 (2022), Supplementary Table 2",
158+
"doi": "10.1038/s41467-022-28041-0",
159+
},
160+
"derived_comparison": {
161+
"single_warm_total_work_speedup_range": [
162+
published_total_hours[0] * 3600 / median_single_seconds,
163+
published_total_hours[1] * 3600 / median_single_seconds,
164+
],
165+
"batch_amortized_total_work_speedup_range": [
166+
published_total_hours[0] * 3600 / median_batch_per_molecule_seconds,
167+
published_total_hours[1] * 3600 / median_batch_per_molecule_seconds,
168+
],
169+
"caveat": (
170+
"The numerator is a published RTX 2080 Ti simulation estimate and the "
171+
"denominator is measured CPU inference on the release host; this compares "
172+
"total per-molecule work, not same-hardware kernel throughput."
173+
),
174+
},
175+
}
176+
output = ROOT / "results/runtime/runtime_benchmark.json"
177+
output.write_text(json.dumps(result, indent=2) + "\n")
178+
print(json.dumps(result, indent=2))
179+
180+
181+
if __name__ == "__main__":
182+
main()

0 commit comments

Comments
 (0)