0Pricing
Learn AI with Python · Lesson

Custom Gymnasium Environments

gym.Env subclass, observation/action spaces, step/reset/render, registering custom env.

What is Gymnasium?

Gymnasium (the maintained successor to OpenAI Gym) is the standard API for RL environments. Any agent that follows its interface works with any compatible environment, so building your own unlocks RL for custom problems.

pip install gymnasium

import gymnasium as gym

Subclassing gymnasium.Env

A custom environment subclasses gymnasium.Env and implements four things: the action and observation spaces, plus reset and step. That contract is all an agent needs.

class GridWorld(gym.Env):
    def __init__(self):
        super().__init__()

All lessons in this course

  1. Policy Gradient Methods: REINFORCE
  2. Actor-Critic Methods (A2C)
  3. Proximal Policy Optimization (PPO)
  4. Custom Gymnasium Environments
← Back to Learn AI with Python