GYMNASIUM /// REINFORCEMENT LEARNING /// ENV.STEP() /// OBS, REWARD, TERMINATED /// GYMNASIUM ///

OpenAI Gym (Gymnasium)

The standard API for reinforcement learning. Connect your agents to simulated worlds effortlessly.

agent.py
1 / 7
12345
🤖

Tutor:Reinforcement Learning algorithms need a world to interact with. Gymnasium (formerly OpenAI Gym) provides this standard API.

Architecture

UNLOCK MODULES TO PROCEED.

Concept: Environments

System Check

What function creates a new instance of a Gymnasium environment?

Mastering The Gymnasium API

"Standardization breeds innovation." The Gym API became the absolute standard for Reinforcement Learning. Gymnasium continues this legacy by refining the interface for modern ML needs.

Environments & Spaces

An environment (env) represents the world your agent operates in. It defines the rules, physics, and goals. Before interacting, you must understand its Spaces.

  • Observation Space: What the agent can "see". It could be an array of numbers (e.g., joint angles) or images (pixels).
  • Action Space: What the agent can "do". Discrete(4) means 4 distinct buttons. Box means continuous control (like a steering wheel).

Terminated vs Truncated

A major update when OpenAI Gym transitioned to the Farama Foundation's Gymnasium was splitting the done flag into two specific flags:

Terminated: The episode ended naturally due to the environment logic (e.g., reaching the goal, or dying).

Truncated: The episode ended artificially (e.g., hitting a 500-step time limit to prevent infinite loops).

Frequently Asked Questions

Why did OpenAI Gym change to Gymnasium?

OpenAI handed maintenance of the Gym library to the Farama Foundation. It was renamed to Gymnasium to reflect a stricter API standard, better maintenance, and the introduction of the terminated/truncated distinction.

How do I install Gymnasium?

Simply run pip install gymnasium. If you need specific environments like Atari or Box2D, run pip install "gymnasium[atari, accept-rom-license]".

API Glossary

gym.make()
Instantiates an environment by its ID (e.g., 'CartPole-v1').
env.reset()
Resets the environment to a starting state. Returns (obs, info).
env.step()
Applies an action. Returns (obs, reward, terminated, truncated, info).
env.close()
Closes the environment and shuts down any render windows.