Skip to content

Environments

ruxla ships a small set of reference environments written with ruxla, and runs any other gymnax, Pgx, or Jumanji environment by importing the original JAX implementation.

Reference environments

The crate ruxla-env (ruxla::env) contains five ports. They are examples of how to write an environment and the subjects of the agreement tests: each uses the same operations, dtypes, and random number draws as the original, and reproduces it step by step, bit for bit for integer and boolean state and to the last bits of rounding for float physics.

Rust Original Python name (alias) Actions Notes
CartPole gymnax CartPole-v1 CartPole-v1 (cartpole) Discrete(2) f32[4] observations
Acrobot gymnax Acrobot-v1 Acrobot-v1 (acrobot) Discrete(3) f32[6] observations
Pendulum gymnax Pendulum-v1 Pendulum-v1 (pendulum) Box([-2], [2]) Continuous actions
Breakout gymnax Breakout-MinAtar Breakout-MinAtar (breakout) Discrete(3) MinAtar, f32[10, 10, 4] observations
TicTacToe Pgx tic_tac_toe tic_tac_toe Discrete(9) Legal action mask

Each reference environment is available:

Pgx has no automatic reset and per-player rewards; TicTacToe wraps it in the form of pgx.experimental.auto_reset: the observation is Pgx's observation (from the player to move), the reward is the acting player's reward, and an illegal action ends the episode with Pgx's penalty.

Importing other environments

Every other gymnax (1.0), Pgx (2.6), and Jumanji (1.1) environment can be used without rewriting it: python -m ruxla.export exports the original's reset and step from their jaxprs, and the crate ruxla-env-jax compiles them ahead of time to native code.

JAX_PLATFORMS=cpu .venv/bin/python -m ruxla.export gymnax:Catch-bsuite pgx:go_9x9 jumanji:Snake-v1
cargo run --release -p ruxla-env-jax --example run -- pgx_go_9x9

A library name alone (gymnax, pgx, jumanji) selects all of its environments. Imported environments are named <library>_<name>, lowercased, with runs of non-alphanumeric characters replaced by _ (gymnax_catch_bsuite, pgx_go_9x9, jumanji_snake_v1). They step natively with CompiledVecEnv, and from Python with ruxla.VecEnv when the extension is built with the feature jax-envs. See Importing JAX environments.

The script also exports Craftax, Brax, MuJoCo Playground, NAVIX, XLand-MiniGrid, JaxMARL, and Waymax environments when they are named (craftax, brax:ant, waymax, ...); their packages are installed separately, and Waymax needs its dataset (Optional libraries). The same mechanism imported 71 gymnax, Pgx, and Jumanji environments and 151 environments of NAVIX, XLand-MiniGrid, and JaxMARL for the paper (Benchmarks). Other libraries need a small wrapper that writes reset(key) -> (obs, state) and step(key, state, action) with the automatic reset, passed to ruxla.export_env (Exporting an environment).

Writing your own

An environment written in Rust implements the Environment trait (gymnax's API) with code generic over the backend; the same code then runs natively, compiled ahead of time, with XLA, and inside JAX. See Writing environments, and the sources of the reference environments in crates/ruxla-env/src/ as examples.