2022-09-13 20:27:34 +01:00
---
hide-toc: true
firstpage:
lastpage:
---
2023-04-02 14:07:31 +02:00
< center >
< h1 >
Gymnasium is a standard API for reinforcement learning, and a diverse collection of reference environments.
< / h1 >
< / center >
2022-09-13 20:27:34 +01:00
2023-04-02 14:07:31 +02:00
< center >
< p > Note: The video includes clips with trained agents from Stable Baselines3. (< a href = "https://huggingface.co/sb3" > Link< / a > )< / p >
< video autoplay loop muted inline width = "450" src = "_static/videos/environments-demo.mp4" type = "video/mp4" > < / video >
< / center >
2022-09-13 20:27:34 +01:00
2023-04-02 14:07:31 +02:00
Gymnasium is a maintained fork of OpenAI’ s Gym library. It provides a user-friendly, pythonic interface for creating and interacting with reinforcement learning environments. With Gymnasium, you can access a diverse collection of environments, as well as represent your own custom RL environments. If you require an environment that is only available in the old Gym, you can use the [compatibility wrapper ](content/gym_compatibility ).
2022-09-13 20:27:34 +01:00
2023-04-02 14:07:31 +02:00
Here is a minimal code example to run an environment:
2022-09-13 20:27:34 +01:00
2023-04-02 14:07:31 +02:00
```{code-block} python
2022-09-19 21:14:09 +01:00
import gymnasium as gym
2023-04-02 14:07:31 +02:00
env = gym.make("CartPole-v1", render_mode="human")
observation, info = env.reset(seed=42) # get the first observation
for step in range(1000):
2023-04-25 06:07:37 -04:00
# here you can use your policy to get an action based on the observation
action = env.action_space.sample()
2023-04-02 14:07:31 +02:00
2023-04-25 06:07:37 -04:00
# execute the action in the environment
observation, reward, terminated, truncated, info = env.step(action)
2023-04-02 14:07:31 +02:00
2023-04-25 06:07:37 -04:00
if terminated or truncated:
observation, info = env.reset()
2022-09-13 20:27:34 +01:00
env.close()
2022-10-03 19:01:14 +01:00
```
2022-09-13 20:27:34 +01:00
```{toctree}
:hidden:
:caption: Introduction
content/basic_usage
2022-10-12 15:58:28 +01:00
content/gym_compatibility
2022-10-24 22:44:08 +01:00
content/migration-guide
2022-09-13 20:27:34 +01:00
```
```{toctree}
:hidden:
:caption: API
2022-10-12 15:58:01 +01:00
api/env
api/registry
2022-09-13 20:27:34 +01:00
api/spaces
api/wrappers
api/vector
api/utils
2022-11-29 23:37:53 +00:00
api/experimental
2022-09-13 20:27:34 +01:00
```
```{toctree}
:hidden:
:caption: Environments
2022-10-03 19:01:14 +01:00
environments/classic_control
environments/box2d
2022-10-12 15:58:01 +01:00
environments/toy_text
environments/mujoco
environments/atari
2022-10-03 19:01:14 +01:00
environments/third_party_environments
2022-09-13 20:27:34 +01:00
```
```{toctree}
:hidden:
2022-10-16 14:54:03 +01:00
:glob:
2022-09-13 20:27:34 +01:00
:caption: Tutorials
2023-01-11 14:00:51 -06:00
tutorials/**/index
2023-02-01 22:30:49 +00:00
Comet Tutorial < https: / / www . comet . com / docs / v2 / integrations / ml-frameworks / gymnasium / ? utm_source = gymnasium&utm_medium=partner&utm_campaign=partner_gymnasium_2023&utm_content=docs_gymnasium >
2022-09-13 20:27:34 +01:00
```
```{toctree}
:hidden:
:caption: Development
2022-09-16 14:00:12 +01:00
Github < https: / / github . com / Farama-Foundation / Gymnasium >
2023-03-25 11:32:36 +00:00
gymnasium_release_notes/index
gym_release_notes/index
2022-10-25 11:38:43 +01:00
Contribute to the Docs < https: / / github . com / Farama-Foundation / Gymnasium / blob / main / docs / README . md >
2022-09-13 20:27:34 +01:00
```