ruxla
ruxla runs reinforcement learning environments at native speed and keeps them compatible with
JAX. Environments written in Rust, or imported from their JAX
implementations (gymnax, Pgx, Jumanji, Craftax, ...) and compiled ahead of time, run as native code on
CPU threads, or inside JAX under jit, vmap, and grad.
Installation
pip install ruxla # ruxla.VecEnv: native environments with NumPy, no JAX
pip install "ruxla[jax]" # also ruxla functions and environments inside JAX, and the exporters
ruxla.compile_env, which compiles environments exported from JAX on the spot, also needs a Rust
toolchain (cargo).
Wheels are built for Linux (x86-64 and AArch64) and macOS on Apple silicon (11 or later); on other
platforms pip builds the sdist, which needs a Rust toolchain (Windows is untested).
Native environments with NumPy
import numpy as np
import ruxla
envs = ruxla.VecEnv("CartPole-v1", num_envs=256, seed=0) # stepped on CPU threads
obs = envs.reset()
actions = np.random.randint(0, envs.num_actions, envs.num_envs)
obs, reward, terminated, truncated, info = envs.step(actions)
VecEnv.step_into writes into arrays you allocate once, such as pinned PyTorch tensors; see
Using ruxla from PyTorch.
Environments imported from JAX
Exporting needs ruxla[jax] and the environment's library (here gymnax); compiling needs cargo.
import numpy as np
import ruxla
# Export gymnax's CartPole (its jaxprs), compile it to native code with cargo, and load it.
compiled = ruxla.compile_env("gymnax:CartPole-v1")
envs = compiled.vec_env("gymnax_cartpole_v1", num_envs=4096, seed=0)
obs = envs.reset()
obs, reward, terminated, truncated, info = envs.step(np.zeros(4096, np.int32))
License
Apache License 2.0; see
NOTICE for the parts derived from JAX and XLA.