openai /gym
A toolkit for developing and comparing reinforcement learning algorithms.
★ 37,234⑂ 8,664👁 47⑃ 1,468● 1,839▤ 19◈ 0
37,234
stars
+1+3+-14
8,664
forks
47
watchers
1,468
prs
1,839
issues
19
releases
0
discussions
README
Important Notice
The team that has been maintaining Gym since 2021 has moved all future development to Gymnasium, a drop in replacement for Gym (import gymnasium as gym), and Gym will not be receiving any future updates. Please switch over to Gymnasium as soon as you're able to do so. If you'd like to read more about the story behind this switch, please check out this blog post.
Gym
Gym is an open source Python library for developing and comparing reinforcement learning algorithms by providing a standard API to communicate between learning algorithms and environments, as well as a standard set of environments compliant with that API. Since its release, Gym's API has become the field standard for doing this.
Gym documentation website is at https://www.gymlibrary.dev/, and you can propose fixes and changes to it here.
Gym also has a discord server for development purposes that you can join here: https://discord.gg/nHg2JRN489
Installation
To install the base Gym library, use pip install gym.
This does not include dependencies for all families of environments (there's a massive number, and some can be problematic to install on certain systems). You can install these dependencies for one family like pip install gym[atari] or use pip install gym[all] to install all dependencies.
We support Python 3.7, 3.8, 3.9 and 3.10 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it.
API
The Gym API's API models environments as simple Python env classes. Creating environment instances and interacting with them is very simple- here's an example using the "CartPole-v1" environment:
python
import gym
env = gym.make("CartPole-v1")
observation, info = env.reset(seed=42)
for _ in range(1000):
action = env.action_space.sample()
observation, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
observation, info = env.reset()
env.close()
Notable Related Libraries
Please note that this is an incomplete list, and just includes libraries that the maintainers most commonly point newcommers to when asked for recommendations.
CleanRL is a learning library based on the Gym API. It is designed to cater to newer people in the field and provides very good reference implementations.
Tianshou is a learning library that's geared towards very experienced users and is design to allow for ease in complex algorithm modifications.
RLlib is a learning library that allows for distributed training and inferencing and supports an extraordinarily large number of features throughout the reinforcement learning space.
PettingZoo is like Gym, but for environments with multiple agents.
Environment Versioning
Gym keeps strict versioning for reproducibility reasons. All environments end in a suffix like "\_v0". When changes are made to environments that might impact learning results, the number is increased by one to prevent potential confusion.
MuJoCo Environments
The latest "\_v4Top issues
#3170[Question] stucking when running pip install `gym[accept-rom-license]==0.21.0`60 comments · 2023-01-09#2279Discussion of Vector Environment API Breaking Changes31 comments · 2021-07-31#3143 Failed building wheel for box2d-py29 comments · 2022-11-02#3102[Bug Report] TimeLimit wrapper logic has changed18 comments · 2022-09-27#3201ALE Namespace does not exist.17 comments · 2023-03-28#3031[Bug Report] CartPole env.render() kills JupyterLab kernel15 comments · 2022-08-16#2734[Proposal] Add test coverage15 comments · 2022-04-06#3200[Bug Report] Gym==0.21 not installing anymore14 comments · 2023-03-23
Latest release
0.26.2 0.26.2 2022-10-04Release notes This is another very minor bug release. Bugs Fixes As reset now returns (obs, info) then in the vector environments, this caused the final step's info to be overwritten. Now, the final observation and info are contained within the info as "final_observation" and "final_info" @pseudo-rnd-thoughts Adds warnings when trying to render without specifying the render_mode @younik Updates Atari Preprocessing such that the wrapper can be pickled @vermouth1992 Github CI was hardened to such that the CI just has read permissions @sashashura Clarify and fix typo in Grap