Installation¶
M3 is installed from PyPI as m3-sc and imported as import m3. It is
tested on Python 3.10 – 3.12 on Linux and macOS.
TL;DR
Step 1 — Create an isolated environment¶
Step 2 — PyTorch (usually nothing to do)¶
M3's training engine runs on PyTorch, which pip install m3-sc pulls in
automatically as a dependency of captum. Most people can skip straight to
Step 3.
Verify, once Step 3 is done:
Step 3 — Install M3¶
Installing m3-sc pulls in its runtime dependencies:
| Package | Used for |
|---|---|
numpy |
array math |
scipy |
sparse count matrices |
pandas |
metadata I/O |
anndata |
.h5ad reading |
h5py |
paper-format expression matrix I/O |
scikit-learn |
internal PCA / scaling in the engine |
scanpy |
neighbours / UMAP used by the engine |
tqdm |
training progress bars |
captum |
integrated-gradients attribution — brings torch with it |
PyTorch therefore arrives automatically, so a plain pip install m3-sc gives you
everything the training engine needs. Install torch yourself only if you want a
build matched to a specific CUDA version (Step 2).
Step 4 — Tutorial extras (nothing to do)¶
The tutorial notebooks plot UMAPs
and ROC curves with scanpy, umap-learn and matplotlib. All three arrive with
m3-sc: scanpy is a declared dependency, and it requires umap-learn and
matplotlib itself. There is nothing extra to install.
Step 5 — Verify the install¶
Expected output: the installed version string (e.g. 0.3.0). If a version
prints, the API is reachable.
The demo dataset used throughout the tutorials is built into the wheel — no download or preprocessing step:
import m3
data = m3.datasets.liu_demo()
print(data)
# Dataset(n_cells=30534, batches=['B1', 'B2', 'B3'], modalities=[rna:1000, adt:192])
You're ready for the Quickstart.
Installing the R package¶
The R interface lives in the same repository (the m3-r/ directory) and wraps
the identical engine, so R and Python produce the same results. It installs
straight from GitHub — no Bioconductor/CRAN step:
You do not install Python or PyTorch yourself — on first use the R package provisions its own engine environment through basilisk. Verify:
See the R tutorials and the R API.
GPU notes¶
- If a CUDA-enabled
torchis detected, M3 uses it automatically — no.to("cuda")calls anywhere in the user-facing API. - For the built-in demo, CPU is fine. For full real-data scale (≥ 100 k cells,
max_epochs=500), a GPU saves roughly 10× wall time. - On Apple Silicon, M3 runs on the CPU backend — the engine selects CUDA when a GPU is present and otherwise CPU (MPS acceleration is not yet enabled).
Input data format¶
M3 takes raw counts — it normalises internally, so do not pre–log-normalise.
Each batch is a multimodal table (RNA and/or ADT and/or ATAC) plus per-cell
metadata with at least a donor / sample column, a cell-type column, a
condition / phenotype column, and a batch column. Load batches with
m3.read_h5, m3.read_h5ad, or
m3.from_anndata, and combine them with
m3.concat. See the API reference for exact signatures.
Troubleshooting¶
Stuck on install?
- GPU / CUDA mismatch error at
import torch -
The pre-built
torchwheel does not match your CUDA toolkit. Reinstall via the PyTorch selector with the correct--index-url. condasolver hangs for > 2 minutes-
Switch to mamba:
conda install -n base -c conda-forge mamba, then re-create the env withmamba. Orconda config --set solver libmambato use libmamba globally. ModuleNotFoundError: No module named 'torch'when youimport m3-
m3-scnormally brings PyTorch with it, so this points at a broken or partial environment.pip install --force-reinstall torchinto the same environment, and check you are not in a different env than you installed into. - Still broken?
-
Open an issue and paste the output of
python -c "import m3; print(m3.__version__)"plus yourpip freeze.
Next: the Quickstart.