survivalGPU has two parts to install: the R package itself, from CRAN, and the Python libraries it uses behind the scenes (via the reticulate R package).
You need R >= 4.1 and Python >= 3.10. The R package itself has no compiled code, but the WCE model needs a C++ compiler:
| System | Install first |
|---|---|
| Linux | Nothing for the Cox model. For the WCE model, a C++ compiler,
usually already there. If not, on Debian/Ubuntu:
sudo apt install build-essential
|
| macOS | Nothing for the Cox model. For the WCE model, Apple’s compiler: run
xcode-select --install in a terminal, and also
brew install libomp (needs Homebrew). |
| Windows | Nothing. |
The compiler is used by the WCE model, which compiles its routines the first time it runs.
If you don’t have Python >= 3.10, reticulate can install it for
you: reticulate::install_python("3.11").
install.packages("survivalGPU")To install the development version from GitHub instead:
install.packages("remotes")
remotes::install_github("jeanfeydy/survivalGPU", subdir = "R")The R package has no compiled code, so this doesn’t need a compiler.
Create a Python environment called survivalGPU, and
install the libraries in it. You only do this once; PyTorch is a large
download, so it takes a few minutes.
library(reticulate)
virtualenv_create("survivalGPU", version = ">=3.10")
virtualenv_install("survivalGPU", c("numpy", "torch", "pandas", "scipy",
"matplotlib", "beartype", "jaxtyping"))
# Only for the WCE model, wceGPU() -- not available on Windows:
virtualenv_install("survivalGPU", "pykeops")At the start of each R session, select the Python environment before loading survivalGPU:
library(reticulate)
use_virtualenv("survivalGPU")
library(survivalGPU)
use_cuda() # TRUE if a GPU is detected; FALSE means survivalGPU runs on CPUThen use coxphGPU() and wceGPU(): see
vignette("coxPH", package = "survivalGPU") and
vignette("WCE", package = "survivalGPU") for examples.
Windows: the Cox model (coxphGPU())
works, but the WCE model (wceGPU()) doesn’t: it needs
pykeops, which doesn’t support Windows. Skip the
pykeops line above. To use WCE on Windows, install R inside
WSL2 and
follow the Linux instructions.
macOS: there’s no NVIDIA GPU on Macs, so survivalGPU runs on CPU.
GPU on Windows: the PyTorch installed by default on Windows only uses the CPU. To use an NVIDIA GPU, reinstall PyTorch from its GPU package index, with the CUDA version that matches your setup (see pytorch.org), for example:
reticulate::virtualenv_install("survivalGPU", "torch",
pip_options = "--index-url https://download.pytorch.org/whl/cu124")GPU and the WCE model: to run
wceGPU() on an NVIDIA GPU, KeOps also needs the
CUDA toolkit (nvcc), not only the GPU
driver.
virtualenv_create() fails with
“Suitable Python installation for creating a venv not found”? The Python
it picked can’t create virtual environments (e.g. on Ubuntu, without the
python3.X-venv package). Give it another Python
explicitly:
virtualenv_create("survivalGPU", python = "/usr/bin/python3.10")
# or: virtualenv_create("survivalGPU", python = install_python("3.11"))