Metadata-Version: 2.4
Name: olinda
Version: 1.4.1
Summary: Distil a slow chemistry model into one fast, self-describing ONNX file
Author-email: Ersilia Open Source Initiative <hello@ersilia.io>
License-Expression: GPL-3.0-only
Project-URL: Homepage, https://ersilia.io
Project-URL: Repository, https://github.com/ersilia-os/olinda
Project-URL: Issues, https://github.com/ersilia-os/olinda/issues
Keywords: drug-discovery,machine-learning,model-distillation,cheminformatics,ersilia,open-science,global-health,onnx
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Chemistry
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy==2.1.3
Requires-Dist: onnxruntime==1.20.1
Requires-Dist: wasmtime==49.0.0
Provides-Extra: cli
Requires-Dist: click==8.4.2; extra == "cli"
Requires-Dist: loguru==0.7.3; extra == "cli"
Requires-Dist: rich==14.1.0; extra == "cli"
Requires-Dist: rich-click==1.9.8; extra == "cli"
Requires-Dist: tqdm==4.68.3; extra == "cli"
Provides-Extra: report
Requires-Dist: olinda[cli]==1.4.1; extra == "report"
Requires-Dist: matplotlib==3.11.0; extra == "report"
Requires-Dist: onnx==1.22.0; extra == "report"
Requires-Dist: pandas==2.3.0; extra == "report"
Requires-Dist: pyarrow==24.0.0; extra == "report"
Requires-Dist: stylia==1.0.1; extra == "report"
Provides-Extra: train
Requires-Dist: olinda[report]==1.4.1; extra == "train"
Requires-Dist: h5py==3.14.0; extra == "train"
Requires-Dist: lazyqsar[fit]==3.4.2; extra == "train"
Requires-Dist: lightgbm==4.6.0; extra == "train"
Requires-Dist: onnxmltools==1.16.0; extra == "train"
Requires-Dist: psutil==7.0.0; extra == "train"
Requires-Dist: xgboost==3.2.0; extra == "train"
Provides-Extra: dev
Requires-Dist: pytest==9.1.1; extra == "dev"
Requires-Dist: rdkit==2026.9.1; extra == "dev"
Requires-Dist: ruff==0.15.20; extra == "dev"
Dynamic: license-file

# Olinda, model distillation for chemistry

Some ML-for-chemistry models are too slow to run on a million compounds. Olinda makes a fast one that behaves like
them: score the slow model once over a reference library of ~1.4M molecules, train a compact
gradient-boosting student to reproduce it, and ship the result as a single ONNX file.

## Installation

Olinda is pip-installable:

```bash
pip install olinda                 # run models from Python: numpy, onnxruntime, wasmtime
pip install "olinda[cli]"          # + the `olinda` command: click, rich-click, rich, loguru, tqdm
pip install "olinda[report]"       # + `olinda validate` and its figures: pandas, pyarrow, matplotlib, onnx, stylia
pip install "olinda[train]"        # + distillation: XGBoost, LightGBM, lazy-qsar, onnxmltools, h5py
```

Each extra includes the one above it, so `olinda[train]` installs everything. No install needs RDKit:
Olinda featurizes molecules with RDKit compiled to WebAssembly, which ships inside the package.

Check that the command-line tool is installed (it needs `olinda[cli]` or above):

```bash
olinda --help
```

Before distilling, download the pre-calculated fingerprints of the reference library (1.4M compounds; 2.8GB):

```bash
olinda setup
```

## Running a model at inference time

A distilled model is one self-describing ONNX file. You can load and run the model in Python:

```python
from olinda import OlindaArtifact

model = OlindaArtifact("model.onnx")
model.run(["CCO", "c1ccccc1"])  # one row per molecule, one column per task (model.columns)
```

Alternatively, you can use the CLI:

```bash
olinda predict --model-onnx model.onnx --input my_smiles.csv --output my_output.csv
```

Or, with nothing installed, in the browser at [ersilia-os.github.io/olinda](https://ersilia-os.github.io/olinda/):
upload the `model.onnx`, paste SMILES, and get the predictions as a table. It all runs locally in the browser;
the model and the molecules never leave your machine.

## Distilling a model

### Getting your soft labels

Olinda relies on a reference library that is [maintained](https://github.com/ersilia-os/ersilia-model-hub-maintained-inputs) by the Ersilia team.

Use the following command to obtain a 1-column file with the SMILES structures of the reference library:

```bash
olinda library -o ersilia_reference_library.csv
```

Use this file to make predictions with your model of choice. Feel free to explore models from the [Ersilia Model Hub](https://catalog.ersilia.io), or models trained with [ZairaChem](https://github.com/ersilia-os/zaira-chem). We refer to the result of these predictions as **soft labels**.

### Training a distilled model

Assuming you have your soft labels calculated, you can simply get a distilled (surrogate model) as follows:

```bash
olinda fit --soft-labels my_soft_labels.csv --model-onnx my_model.onnx
```

Optionally, you can provide **hard labels** (ground truth) if you have them. Hard labels can be binary (1/0) or continuous measurements; olinda detects which per column (`--task` overrides). A continuous head is capped at a lower blend weight than a binary one (0.25 against 0.4), a provisional figure that has not yet been validated against real measurements.

```bash
olinda fit --soft-labels my_soft_labels.csv --hard-labels my_hard_labels.csv --model-onnx my_model.onnx
```

### Evaluating a distilled model

The easiest way to evaluate a distilled model is to pass an additional set of soft-labels (and optionally hard labels):

```bash
olinda validate --soft-labels my_validation_soft_labels.csv --model-onnx my_model.onnx --output-dir my_report_folder
```

## Commands

The `olinda` command comes with `olinda[cli]`; `validate` also needs `olinda[report]`, and the distilling
commands need `olinda[train]`.

| Command | What it does |
|---|---|
| `setup` | Download the reference library's Morgan fingerprints |
| `library` | Write the reference library's SMILES to a CSV |
| `fit` | Distil a teacher into a student end-to-end |
| `predict` | Run a distilled `model.onnx` on SMILES |
| `validate` | Score a model against labelled data and write a report |

`fit` drives the step-by-step pipeline below; run the steps yourself to inspect or redo one of them.

| Command | What it does |
|---|---|
| `prepare` | Set up a run directory from the soft (and hard) labels |
| `learn-soft` | Train the surrogate on the teacher's soft labels |
| `learn-hard` | Train on hard labels and calibrate onto the soft-label scale |
| `export` | Rebuild `model.onnx` for a trained run |
| `clean` | Move the model out of the run and delete the working folder |

## About the Ersilia Open Source Initiative

The [Ersilia Open Source Initiative](https://ersilia.io) is a tech-nonprofit organization fueling sustainable research in the Global South. Ersilia's main asset is the [Ersilia Model Hub](https://github.com/ersilia-os/ersilia), an open-source repository of AI/ML models for antimicrobial drug discovery.

![Ersilia Logo](assets/Ersilia_Brand.png)
