Skip to main content

Crate gymnasia

Crate gymnasia 

Source
Expand description

A Rust implementation of OpenAI’s Gymnasium environments.

§Architecture

Unlike Python Gymnasium, gymnasia separates simulation from rendering.

The crate is organized into layers:

  1. core::Env — pure simulation. step() and reset() perform physics only. No feature flags, no rendering code, no graphics imports.

  2. core::Renderable — a trait that produces a render::draw::DrawList (a backend-agnostic list of draw commands) from the current state. Always compiled — DrawList has zero graphics dependencies.

  3. RenderEnv (requires render feature) — a wrapper that composes an Env + Renderable with a macroquad-backed screen. Implements Env so it participates in wrapper chains.

  4. wrappers — composable behavior wrappers (TimeLimit, RecordEpisodeStatistics, NormalizeObservation, etc.) that implement Env via generic delegation.

This means the simulation compiles and runs with zero dependencies on any graphics library. Rendering is opt-in via --features render.

§Quick start

use gymnasia::core::Env;
use gymnasia::envs::classical_control::cartpole::CartPoleEnv;

let mut env = CartPoleEnv::new();
env.reset(None, Default::default());
let result = env.step(1);

Modules§

core
Core traits and types: Env, StepResult, Flatten, Renderable.
envs
Concrete environment implementations.
render
Drawing, rendering backend, and the RenderEnv wrapper.
spaces
Space descriptors: Discrete, BoxSpace, etc.
utils
Shared utilities: seeding, clip, etc.
wrappers
Composable environment wrappers. Composable environment wrappers.

Macros§

delegate_env
Implements Env for a wrapper by delegating all methods to self.env.