Skip to content

Rust API

The generated API documentation (rustdoc) of the library crates is published with this site:

Open the rustdoc of ruxla →

This page gives an overview of the crates and their main items. Most programs depend only on the facade crate ruxla.

Crates

Crate Role rustdoc
ruxla The facade: ruxla-core re-exported at the root (and ruxla::prelude), ruxla::env (ruxla-env), ruxla::nn (ruxla-nn) ruxla
ruxla-core The frontend: Backend, Native, Trace, values, pytrees, control flow, jnp, lax, random, the transformations, and the XLA runtime ruxla_core
ruxla-macros #[derive(Tree)] ruxla_macros
ruxla-env Environment, VecEnv, export to .ruxlapkg, testing tools, the five reference environments, ahead-of-time compilation (compiled), loading imported JAX environments (jax_env) ruxla_env
ruxla-nn Flax-compatible layers, initializers, Optax-like optimizers, weight loading (safetensors, Flax msgpack), ExportedModel ruxla_nn
ruxla-kernels The semantics of the operations on typed slices (elementwise, reductions, dot, gather, scatter, linear algebra, FFT, special functions), following XLA on the CPU ruxla_kernels
ruxla-ir The IR: Function, Eqn, Var, AVal, DType, Params, the Primitive trait, printing (jaxpr format), serialization ruxla_ir
ruxla-prims The primitives: shape inference, evaluation, lowering, batching, and differentiation rules ruxla_prims
ruxla-interp The IR interpreter ruxla_interp
ruxla-transforms vmap, jvp, partial evaluation, transpose, vjp, value_and_grad on IR ruxla_transforms
ruxla-stablehlo Lowering to StableHLO, and linking of modules exported from JAX ruxla_stablehlo
ruxla-pjrt PJRT bindings and execution, FFI handlers (linear algebra, host callbacks) ruxla_pjrt
ruxla-codegen IR optimization and Rust code generation (ahead-of-time compilation), and the runtime the generated code calls (rt) ruxla_codegen
ruxla-build The build-script helper that compiles exported JAX environments into a crate (compile_envs, Builder) ruxla_build
ruxla-import Reading jaxprs exported by ruxla.export_jaxpr (JSON) into IR ruxla_import
ruxla-testing OpInfo, backend agreement checks, XLA differential tests, fuzzing ruxla_testing

Not documented here (generated or Python-only):

  • ruxla-env-aot: the five reference environments compiled ahead of time (modules cartpole, acrobot, pendulum, breakout, tic_tac_toe, each with a unit struct Env), generated by its build script; the template for compiling your own environment;
  • ruxla-env-jax: environments imported from JAX and compiled ahead of time (generated from .cache/jax-envs; MODULES, DATA_DIR, visit), see Importing JAX environments;
  • ruxla-python: the Python extension module ruxla._ruxla (PyO3).

ruxla-core (re-exported by ruxla)

Item Description
Backend, Native, Trace The backend trait and its two implementations
Scalar<B, T>, Array<B, T>, Key<B> Values; aliases F32, F64, I32, I64, U8, U32, Bool, C64, C128
Element, Numeric, Num, Inexact, Float, RealFloat, ComplexFloat, Int Element type traits
Tree, TreeDef, leaves, select_tree Pytrees (#[derive(Tree)])
jnp jax.numpy-like functions, with jnp::linalg and jnp::fft
lax jax.lax-like functions: control flow (select, cond, switch, fori_loop, while_loop, scan, select_with, select_with_operand), custom rules (custom_jvp, custom_vjp, checkpoint), sort, convolutions, windows, lax::linalg
random jax.random-like functions
scipy scipy.special-like functions
jit, Jit, OnDevice, device_put Compilation with XLA
vmap, Vmap Batching
grad, value_and_grad, jvp, vjp Automatic differentiation
make_ir, trace, interpret, Traced Tracing and interpretation
pure_callback Calling native code from generic code
ExternFn Calling functions exported with jax.export (XLA only)
runtime Platform and plugin selection (set_platform, set_plugin_path, Platform)
prelude The common imports

ruxla-env (ruxla::env)

Item Description
Environment The environment trait (gymnax 1.0's API)
Transition, Step, StepInput, StepOf Results of step_env and step
ActionSpace, Actions, ActionValue, MAX_MASK_ACTIONS, choose_legal, unravel_joint, pattern_discrete, pattern_continuous Actions and legal action masks
VecEnv, VecStep, StepBuffers, FlatObs, flat_obs! Parallel native execution
CompiledVecEnv Parallel execution of compiled environments
export, PackageWriter, ExportError, SCHEMA_VERSION Writing .ruxlapkg packages
compiled::{generate, generate_from_functions, EnvFunctions, CompiledEnv, CompiledStep, StepInfo, CompiledAction, Visitor, key, split_key} Ahead-of-time compilation
include_envs!, export_vec_envs!, dylib::{Library, LibVecEnv, VTable, ABI_VERSION} The environments that ruxla-build compiled, and their C ABI in shared libraries
jax_env::{load_functions, LoadError} Reading environments exported by ruxla.export_env (python -m ruxla.export)
testing::{check_backends, check_vmap, Xla, trees_equal} Testing tools
CartPole, Acrobot, Pendulum, Breakout, TicTacToe The reference environments (see Environments)

ruxla-nn (ruxla::nn)

Item Description
Dense, Conv, LayerNorm, max_pool, min_pool, avg_pool, relu, tanh Layers (Flax-compatible)
init::{orthogonal, zeros} Initializers
optim::{GradientTransformation, sgd, adam, adam_with_schedule, ScaleByAdam, clip_by_global_norm, linear_schedule, chain, apply_updates, ...} Optimizers (Optax-compatible)
Weights, WeightsError Loading safetensors and Flax msgpack
ExportedModel, ModelError Models written by ruxla.export_model

Lower-level crates

Crate Main items
ruxla-ir Function, Eqn, Var, Atom, AVal, Shape, DType, Params, HostArray, Primitive, serialize, lowering::Target
ruxla-interp eval(&function, &inputs)
ruxla-transforms vmap, vmap_with_out_axes, jvp, partial_eval, transpose, vjp, value_and_grad
ruxla-stablehlo lower(&function, target), link
ruxla-pjrt Plugin, Client, Device, Buffer, LoadedExecutable, CompileOptions, ElementType
ruxla-codegen compile, compile_with, optimize, Options, emit_function, Signature, ConstPool, rt
ruxla-import from_json
ruxla-testing OpInfo, op_infos, check_op, check_op_xla, check_op_vmap, check_vmap, random_function

Build the rustdoc locally with:

cargo doc --no-deps --open