Home
Login

Gym is a toolkit for developing and comparing reinforcement learning algorithms. It supports teaching agents how to make decisions in a variety of simulated environments.

NOASSERTIONPython 36.1kopenai Last Updated: 2024-10-11

OpenAI Gym Project Details

Project Overview

OpenAI Gym is an open-source Python library specifically designed for developing and comparing reinforcement learning algorithms. It connects learning algorithms and environments through a standardized API and provides a collection of environments that conform to this API standard. Since its release, the Gym API has become a standard in the field of reinforcement learning.

⚠️ Important Notice

Project Maintenance Status Change: The team that has been maintaining Gym since 2021 has transferred all future development efforts to Gymnasium, which is a direct replacement for Gym (usable with import gymnasium as gym). Gym will no longer receive any future updates, and users are advised to switch to Gymnasium as soon as possible.

Core Features

Standardized API

  • Provides a unified interface for communication between reinforcement learning algorithms and environments.
  • Simplifies the environment creation and interaction process.
  • Has become the API standard in the field of reinforcement learning.

Rich Environment Library

  • Contains a large number of pre-defined reinforcement learning environments.
  • Supports various types of tasks and challenges.
  • Environments adhere to a unified interface standard.

Installation Instructions

Basic Installation

pip install gym

Specific Environment Family Installation

# Install Atari environment dependencies
pip install gym[atari]

# Install all environment dependencies
pip install gym[all]

# Install MuJoCo environment dependencies (latest version)
pip install gym[mujoco]

# Install MuJoCo environment dependencies (older version)
pip install gym[mujoco_py]

System Support

  • Python Versions: Supports Python 3.7, 3.8, 3.9, 3.10
  • Operating Systems: Officially supports Linux and macOS
  • Windows: Accepts related PRs but does not provide official support

Basic Usage Example

import gym

# Create environment
env = gym.make("CartPole-v1")

# Reset environment
observation, info = env.reset(seed=42)

# Environment interaction loop
for _ in range(1000):
    # Randomly select action
    action = env.action_space.sample()
    
    # Execute action
    observation, reward, terminated, truncated, info = env.step(action)
    
    # Check if reset is needed
    if terminated or truncated:
        observation, info = env.reset()

# Close environment
env.close()

Related Ecosystem

Recommended Learning Libraries

  1. CleanRL - Learning library based on the Gym API

    • Aimed at reinforcement learning beginners
    • Provides excellent reference implementations
  2. Tianshou - Learning library for experienced users

    • Supports complex algorithm modifications
    • Flexible design
  3. RLlib - Learning library that supports distributed training

    • Supports distributed training and inference
    • Extremely rich in features
  4. PettingZoo - Multi-agent environment library

    • Similar to Gym but supports multi-agent environments

Version Management

Gym employs strict version control to ensure reproducibility:

  • All environments end with a version suffix (e.g., "_v0")
  • When environment changes may affect learning results, the version number is incremented
  • Ensures the reproducibility and consistency of experiments

MuJoCo Environment Updates

  • The latest "_v4" and future versions no longer depend on mujoco-py
  • Instead, they use mujoco as a required dependency
  • Older versions of the environment are retained but no longer maintained

Documentation and Resources

Academic Citation

The project whitepaper is available on arXiv, citation format:

@misc{1606.01540,
  Author = {Greg Brockman and Vicki Cheung and Ludwig Pettersson and Jonas Schneider and John Schulman and Jie Tang and Wojciech Zaremba},
  Title = {OpenAI Gym},
  Year = {2016},
  Eprint = {arXiv:1606.01540},
}

Project Status Summary

OpenAI Gym, as a pioneering tool in the field of reinforcement learning, has established industry standards and fostered a vast ecosystem. Although the original project is no longer actively maintained, its successor, Gymnasium, inherits all core functionalities, ensuring the continued development of the community. For new projects, it is strongly recommended to use Gymnasium directly to obtain the latest features and ongoing support.