Gymnasium Basics¶
The aim of these tutorials is to showcase the fundamental API of Gymnasium to help users implement it.
Each tutorial is a self-contained Python script: its page shows the code next to the output, and the script can be downloaded from the same page to run and modify locally.
What the tutorials cover¶
Make your own custom environment - generate a new environment from the Farama
gymnasium-env-templatewith Copier, then implement its spaces, transitions, rendering, registration and tests.Implementing custom wrappers - subclass
ObservationWrapper,ActionWrapper,RewardWrapperandWrapperto change the observations, actions or rewards of an existing environment, and where to find the function-based and vector wrappers.Handling time limits - the difference between
terminatedandtruncated, why bootstrapping should stop only onterminated, and how this works with vector environments.Load custom quadruped robot environments - pass an MJCF or URDF model to a MuJoCo environment with the
xml_fileargument, then tune its simulation, termination, reward and observation parameters.
Requirements¶
The tutorials require Python 3.11 or newer with gymnasium installed:
pip install gymnasium
Three of the tutorials also use optional dependencies:
pip install copier "gymnasium[classic-control]"for Make your own custom environment, which walks through the Copier template and renders the example environment withpygame.pip install "gymnasium[box2d,mujoco]"for Implementing custom wrappers, which wrapsLunarLanderContinuous-v3andReacher-v5.pip install "gymnasium[mujoco]"for Load custom quadruped robot environments, which wrapsAnt-v5.
Running a tutorial locally¶
Every tutorial page ends with a Download Python source code link. Save the file and run it from a terminal, for example:
python implementing_custom_wrappers.py
The tutorials are written to be read as much as run: the printed output and figures are part of the explanation, so the rendered page is the primary reference and the script is there to experiment with.
Where to go next¶
Basic usage introduces the
reset/steploop, spaces and wrappers that every tutorial builds on.The API reference documents the environment API in full.