Search code examples
reinforcement-learningopenai-gym

Get name / id of a OpenAI Gym environment


Given:

import gym
env = gym.make('CartPole-v0')

How do I get CartPole-v0 in a way that works across any Gym env?


Solution

  • Unwrap the environment and get the id from the spec

    name = env.unwrapped.spec.id
    
    print(name)
    # 'CartPole-v0'
    

    In vectorized environments, access the first sub-environment:

    name = env.envs[0].unwrapped.spec.id