Skip to content

How ruxla works

ruxla connects JAX and Rust through one intermediate representation (IR). This page shows the pieces and the two workflows they support.

flowchart LR
  subgraph Sources
    J["JAX environment<br/>(jaxpr)"]
    R["Rust environment<br/>generic over B"]
  end
  IR["ruxla IR<br/>128 primitives with JAX's semantics<br/>batching, JVP, transpose rules"]
  J -- "import" --> IR
  R -- "trace (B = Trace)" --> IR
  R -. "B = Native: reference execution" .-> N["eager native<br/>(testing, debugging)"]
  IR --> G["generated Rust<br/>compiled by rustc"]
  IR --> K["native kernels<br/>(interpreter)"]
  IR --> X["XLA via PJRT<br/>(CPU, GPU)"]
  IR -- "export" --> C["ruxla_call<br/>inside a JAX program"]
  G --> V["vectorized environment<br/>Rust or Python (NumPy)"]

Two workflows

JAX to native. An existing JAX environment is exported from Python (python -m ruxla.export), read into the IR, and compiled ahead of time to Rust (Importing JAX environments). The generated code follows the original's trajectories and runs 5–11× faster than JAX on the CPU (Benchmarks). Imported programs keep JAX's primal semantics and batching; custom derivative rules are not imported (Compatibility and limits).

Rust to JAX. An environment written in Rust, generic over a backend B, is traced into the IR and written as a package; in Python it becomes an object with gymnax's interface whose functions call the JAX primitive ruxla_call (ruxla environments in JAX). JAX's jit, vmap and grad apply to it, because the primitive's rules are ruxla's own transformations, and XLA compiles it together with the rest of the program on CPU or GPU.

The pieces

Piece Crate Role
Front end ruxla-core values (F32<B>, Array<B, T>), operations mirroring jax.numpy / jax.lax, pytrees, random keys
IR and primitives ruxla-ir, ruxla-prims the 128 primitives with abstract evaluation, kernels, lowering, and batching / JVP / transpose rules
Transformations ruxla-transforms vmap, jvp, vjp, grad, custom derivatives, checkpoint
Kernels and interpreter ruxla-kernels, ruxla-interp eager execution with XLA's semantics
XLA ruxla-stablehlo, ruxla-pjrt lowering to StableHLO and execution through PJRT plugins
Code generation ruxla-codegen IR to Rust for ahead-of-time compilation
Import ruxla-import jaxprs to the IR
Environments ruxla-env the environment trait, vectorized environments, packages for JAX, compiled and imported environments, the reference environments
Compiled environments ruxla-env-aot, ruxla-env-jax the reference environments compiled ahead of time; environments imported from JAX and compiled ahead of time
Python python/ruxla, ruxla-python load_env, ruxla_call, VecEnv, export helpers

See the Rust API overview for the crates in more detail, Ahead-of-time compilation for what the code generator does, and the developer guide for how the pieces fit together inside.