Expand description
Native-speed reinforcement learning environments that stay compatible with JAX.
Environments are written once in Rust with code generic over a backend:
they run as native code (Native), compiled ahead of time to Rust, or as
IR (Trace) exported into JAX programs. Environments written in JAX can be
imported from their jaxprs and compiled to Rust as well.
The frontend, the backends, and the transformations are re-exported at the
root (ruxla-core); the environments are ruxla::env (ruxla-env) and the
models ruxla::nn (ruxla-nn). The guides are in the repository’s
site/docs (https://github.com/ymgaq/ruxla).
Re-exports§
Modules§
- indexing
- NumPy-style indexing:
Array::ireads elements andArray::atreturns an array with some elements updated, likex[...]andx.at[...].set(...)in JAX. - jnp
- Functions following
jax.numpy, with NumPy’s broadcasting. - lax
- Operations following
jax.lax: control flow, and primitives on arrays with strict shapes and types (operands of binary operations have the same shape). - prelude
- The items most programs use:
use ruxla_core::prelude::*;(orruxla::prelude::*). - runtime
- The XLA runtime: PJRT clients and the cache of compiled functions.
- scipy
- Functions following
jax.scipy.
Structs§
- Array
- An array of element type
Ton backendB, with a shape known at run time (and fixed within a traced program). - Complex
- A complex number with real and imaginary parts of type
F. - Extern
Fn - A StableHLO module written by another program, called like a function
from traced programs: XLA links it with the caller and compiles them
together (
extern_call). The interpreter and the native backend cannot run it, so programs that call it run withjit. - Grad
- See
grad. - Jit
- A function compiled with XLA; see
jit. - Jvp
- See
jvp. - Key
- A random key: two
u32words (or an array of keys, shape[..., 2]). - Native
- The native backend: programs run as native code compiled by rustc.
Scalars are Rust values, arrays are
NativeArrays, and control flow is real branches and loops. - Native
Array - An array of the
Nativebackend: its elements (shared if large) and a shape. - OnDevice
- A pytree whose arrays are on the device of the runtime’s platform, made
by
device_putor returned byJit::call_on_device. - Scalar
- A scalar of element type
Ton backendB. - Shape
- The dimension sizes of an array, in row-major order.
- Trace
- The tracing backend: programs record their operations as IR. Values are
TraceRefs into the trace in progress. - Trace
Ref - A value of the
Tracebackend: an entry of a trace frame. - Traced
- A traced program: the IR and the structures of its input and output.
- Value
AndGrad - See
value_and_grad. - VjpFn
- See
vjp. - Vmap
- A batched function; see
vmap. - bf16
- A 16-bit floating point type implementing the
bfloat16format. - f16
- A 16-bit floating point type implementing the IEEE 754-2008 standard
binary16a.k.a “half” format.
Enums§
- Axes
- Axes of a reduction: all of them, or a list (negative values count from the end).
- DType
- The element type of a value.
- Extern
Error - An error from reading a module for
ExternFn. - ToReal
- An operation with a real result from (complex) numbers.
- TreeDef
- A description of a pytree’s structure, for writing it out to other languages (the field names of structs, for example).
Constants§
- ALL
- Every axis.
Traits§
- Array
Like - Something that can be an operand of an array operation: an array, a scalar, or a Rust value.
- Backend
- A backend: what values are and how operations run.
- Complex
Float - Element types that are complex numbers, whose parts are
Floats. - Element
- A Rust type that is an element type of ruxla. It is implemented for
bool, the integer types,f16,bf16,f32,f64,c64, andc128. - Float
- Element types that are floating point numbers.
- Inexact
- Element types that are floats or complex numbers (NumPy’s
inexact). They have the transcendental functions that complex numbers share with floats (exp,ln,sqrt,sin, …), and derivatives. - Int
- Element types that are integers.
- Linalg
Float - The real element types of linear algebra (
lax::linalg,jnp::linalg):f32andf64. - Linalg
Scalar - The element types of the linear algebra primitives (
lax::linalg):f32,f64,c64, andc128. The eigenvalues ofeighand the singular values ofsvdhave the real typeReal. - Num
- Element types that are real numbers (integers and floats; not
boolor complex numbers). - Numeric
- Element types that are numbers: integers, floats, and complex numbers
(NumPy’s
number). They have arithmetic. - Real
Float - The floats that complex numbers are made of (
f32andf64), with their complex type (the result ofrfft). - Tree
- A pytree: a structure of scalars and arrays on backend
B.
Functions§
- device_
put - Copies a pytree of
Nativevalues to the device of the runtime’s platform. - grad
- Returns a function that computes the gradient of
f(params, args)with respect toparams, likejax.grad. Seevalue_and_gradfor whatftakes and returns (auxiliary outputs are dropped). - interpret
- Traces
fand runs the IR with the interpreter oninput, returning the output asNativevalues. Useful to check that a program gives the same results natively and as IR. - is_
tracing - Returns whether a trace is in progress on this thread.
- jit
- Returns
fcompiled with XLA, likejax.jit. - jvp
- Returns a function that computes
f(primals)and its derivative in the direction oftangents(forward mode), likejax.jvp. - leaves
- Returns the leaves of a pytree.
- leaves_
as - Returns the leaves of a pytree as arrays of element type
T(scalars as arrays of rank 0), for code that treats every leaf alike, such as optimizers. - make_ir
- Returns the IR of
ftraced on values shaped likeexample, likejax.make_jaxpr. - pure_
callback - Calls the native function
foninputfrom code of any backend, as JAX’spure_callback: natively,fruns directly; in a trace, the call is ahost_callbackequation, which the interpreter and ruxla’s XLA runtime (CPU, and CUDA around copies to the host) run by callingfon the host.likegives the structure and types of the results (its values are not used). Code that cannot be written for every backend (external libraries, arbitrary data structures) can thus run insidejit,vmap(a loop over the examples), and the programs of environments. - select_
tree - Selects
on_trueoron_falseleaf by leaf (jax.tree.mapoflax.select). - trace
- Traces
fonTracevalues shaped likeexample(aNativepytree) and returns the IR with the structures of the input and output. - unflatten_
arrays - Builds a pytree with the structure of
likefrom arrays, one per leaf (the inverse ofleaves_as). - value_
and_ grad - Returns a function that computes
f(params, args)and its gradient with respect toparams, likejax.value_and_grad(f, has_aux=True). - vjp
- Returns a function that computes
f(primals)and the cotangents of the inputs for given cotangents of the outputs (reverse mode), like calling the function thatjax.vjpreturns. - vmap
- Returns
fbatched over examples, likejax.vmapwith every input and output batched at dimension 0.
Type Aliases§
- Bool
- A
boolscalar. - C64
- A
c64(complex64) scalar. - C128
- A
c128(complex128) scalar. - F32
- An
f32scalar. - F64
- An
f64scalar. - I32
- An
i32scalar. - I64
- An
i64scalar. - U8
- A
u8scalar. - U32
- A
u32scalar. - c64
- A complex number made of two
f32s (complex64). - c128
- A complex number made of two
f64s (complex128).
Derive Macros§
- Tree
- Derives
Tree<B>for a struct with named fields whose first type parameter is the backendB.