Skip to content

Installation

The Python package is on PyPI and the Rust crates are on crates.io:

pip install ruxla        # Python: ruxla.VecEnv with NumPy (add the extra `jax` for JAX)
cargo add ruxla          # Rust: the facade crate

Both can also be built from a clone of the repository (below). The packages: PyPI, crates.io, and the Rust API reference on docs.rs.

Platforms

Platform Python wheel Tested in CI Prebuilt PJRT CPU plugin CUDA
Linux x86-64 yes (manylinux_2_28) yes yes yes (jax[cuda13])
Linux AArch64 yes (manylinux_2_28) yes yes no
macOS on Apple silicon (11 or later) yes yes yes no
Windows, Intel macOS no: from source no no no

Everything except XLA from Rust works without a plugin: native execution and VecEnv (Rust and Python), environments compiled ahead of time, ruxla.compile_env and ruxla-build (with a Rust toolchain), and ruxla functions and environments inside JAX (ruxla_call, load_env; JAX compiles them with its own XLA). Running programs with XLA from Rust (jit, call_xla) needs a PJRT plugin: ruxla downloads a prebuilt CPU plugin on the platforms marked above, and elsewhere needs one given with ruxla::runtime::set_plugin_path or RUXLA_PJRT_CPU_PLUGIN (XLA and PJRT). The CI runs the PJRT and GPU tests on Linux x86-64 only. Windows may build from source but is untested.

Rust

Toolchain

The workspace uses the Rust 2024 edition and needs Rust 1.94 or newer (rust-version in the workspace Cargo.toml). Install a recent stable toolchain with rustup:

rustup toolchain install stable

Using ruxla from your crate

Add the facade crate ruxla:

cargo add ruxla

ruxla re-exports the frontend (ruxla-core) at its root and in ruxla::prelude, the environments as ruxla::env (ruxla-env), and the neural network layers and optimizers as ruxla::nn (ruxla-nn). The other library crates are published too, for example ruxla-env, ruxla-codegen, and ruxla-ir, which the code compiled ahead of time refers to, and ruxla-build, which compiles environments exported from JAX in a build script:

cargo add ruxla-env ruxla-codegen ruxla-ir
cargo add --build ruxla-build

Note

The API still changes between 0.x versions. To follow the development version instead, use the repository: ruxla = { git = "https://github.com/ymgaq/ruxla" } (pin a rev for reproducible builds).

Working on the repository

git clone https://github.com/ymgaq/ruxla
cd ruxla
cargo test

cargo test runs the default members of the workspace, including the reference environments compiled ahead of time (ruxla-env-aot). ruxla-env-jax, which compiles environments exported from JAX, is not a default member; see Importing JAX environments. The full set of development commands is in CONTRIBUTING.md.

Memory

Compiling generated environment code can take several GB per rustc process. On a machine with limited memory, reduce the parallelism (cargo build -j 4).

Optional: PJRT plugins for XLA

Running programs with XLA from Rust (jit, call_xla, the XLA comparisons of the tests) needs a PJRT plugin. Outside a clone, ruxla finds one by itself: it downloads the CPU plugin into ~/.cache/ruxla/pjrt on first use (x86-64 and AArch64 Linux, Apple silicon macOS) and uses the CUDA plugin of an installed jax[cuda13] on Linux (XLA and PJRT). In a clone, the script scripts/fetch-pjrt-plugins.sh puts them in .cache/pjrt/, where the tests look:

  • CPU: downloads a prebuilt libpjrt_cpu.so (libpjrt_cpu.dylib on macOS, from zml/pjrt-artifacts) and checks its pinned SHA-256 checksum;
  • CUDA: creates a symbolic link to the xla_cuda_plugin.so of the JAX installed in .venv (jax[cuda13]), if there is one.
scripts/fetch-pjrt-plugins.sh

The tests that need a plugin are marked #[ignore]; run them with:

cargo test --workspace -- --ignored --skip cuda

At run time, ruxla finds the plugin as described in XLA and PJRT (ruxla::runtime::set_plugin_path, RUXLA_PJRT_CPU_PLUGIN, RUXLA_PJRT_CUDA_PLUGIN, RUXLA_PJRT_PLUGIN_DIR, then the cache, an installed JAX, and the download).

Python

pip install ruxla                 # ruxla.VecEnv, ruxla.gymnasium: NumPy only, no JAX
pip install "ruxla[jax]"          # also ruxla_call, load_env, load, and the exporters (JAX 0.12)
pip install "ruxla[export]"       # also ruxla.export_model (safetensors, flatbuffers)

The package needs Python 3.10 or newer; the extra jax pins JAX 0.12.x (jax>=0.12,<0.13). Wheels are built for Linux (x86-64 and AArch64) and macOS on Apple silicon (Platforms); elsewhere pip builds the source distribution, which needs a Rust toolchain. Use jax[cuda13] for JAX on the GPU. ruxla.compile_env also needs a Rust toolchain (cargo), since it compiles the exported environments on the spot.

From source

The package (in python/) is a PyO3 extension module built with maturin. The commands below use uv with Python 3.13.

Create the environment

From the repository root:

uv venv .venv --python 3.13
uv pip install --python .venv "jax==0.12.*" maturin
uv venv .venv --python 3.13
uv pip install --python .venv "jax[cuda13]==0.12.*" maturin

safetensors and flatbuffers are needed to export JAX models for Rust (ruxla.export_model):

uv pip install --python .venv safetensors flatbuffers

Build the extension module

cd python && VIRTUAL_ENV=$PWD/../.venv ../.venv/bin/maturin develop --release

Rebuild it whenever the Rust side changes. Add --features jax-envs to include environments imported from JAX (export them first).

import ruxla

envs = ruxla.VecEnv("CartPole-v1", num_envs=4)
print(envs)

import ruxla does not import JAX: only the parts that use JAX (load_env, load, export_model, export_jaxpr, export_env) import it on first use.

Test dependencies

The Python tests compare ruxla with gymnax (and with Pgx, if installed). gymnax 1.0 asks for an older JAX than 0.12, so install its dependencies with JAX pinned first and then gymnax without dependencies:

uv pip install --python .venv "jax==0.12.*" maturin pytest flax optax distrax gymnasium six
uv pip install --python .venv --no-deps "gymnax==1.0.*"
.venv/bin/python -m pytest python/tests

Use jax[cuda13] instead of jax for the GPU. The tests call cargo run to write the environment packages they load, so they need the Rust toolchain too.