Getting started
This is a brief introduction on how to set up torchquad.
Prerequisites
torchquad is built with
autoray, which means the implemented quadrature supports NumPy and can be used for machine learning with modules such as PyTorch, JAX and Tensorflow, where it is fully differentiable
torchquad has no backend pinned as a hard dependency — install the numerical backend(s) you want alongside it, or use NumPy alone. Any of pip, uv, or conda works. Note that torchquad also works on the CPU; however, it is optimized for GPU usage. GPU support is tested only on NVIDIA cards with CUDA. For GPU installs, follow each framework’s own install guide — the CPU-only convenience extras below cannot select GPU wheels, and JAX/TensorFlow GPU builds are Linux/WSL2-only.
For a detailed list of required packages and packages for numerical backends, please refer to the conda environment files environment.yml and environment_all_backends.yml. torchquad requires Python 3.10 or newer. Its CI suite runs on Python 3.12 with JAX 0.4.35, NumPy 2.3, PyTorch 2.5 and TensorFlow 2.18; other versions of the backends should work as well.
Installation
Install torchquad from PyPI:
pip install torchquad # or, with uv: uv pip install torchquad
It is also available on conda-forge:
conda install torchquad -c conda-forge
Adding a backend. torchquad ships convenience extras that pull a backend
from the default package index. jax and tensorflow install CPU builds;
torch resolves to the CUDA build on Linux (that is what PyTorch publishes to
PyPI), and CPU on macOS/Windows. For a guaranteed-CPU torch, install it from the
PyTorch CPU index first.
pip install "torchquad[torch]" # PyTorch (CUDA on Linux, CPU elsewhere) pip install "torchquad[jax]" # JAX (CPU) pip install "torchquad[tensorflow]" # TensorFlow (CPU) pip install "torchquad[all]" # all three
Adding a backend (GPU). These extras cannot select GPU wheels (a Python
package cannot encode the CUDA-specific index URLs each framework needs), so for
GPU support install the backend from its own guide first, then
pip install torchquad:
JAX (Linux/WSL2 only): https://docs.jax.dev/en/latest/installation.html
TensorFlow (Linux/WSL2 only): https://www.tensorflow.org/install/gpu
For a full multi-backend setup, the conda file environment_all_backends.yml installs every backend (CPU) in one step:
conda env create -f environment_all_backends.yml conda activate torchquad
Usage
Now you are ready to use torchquad. A brief example of how torchquad can be used to compute a simple integral can be found on our GitHub. For a more thorough introduction, please refer to the tutorial.