Environment check error in Stable Baselines 3 when using marlenv and gymnasium

69 Views Asked by At

marlenv.py

import gymnasium as gym
from gymnasium.spaces import Discrete, Box, Dict
from stable_baselines3.common.env_checker import check_env
import numpy as np

from pprint import pprint

class MyMultiAgentEnv(gym.Env):
    def __init__(self, config):
        super(MyMultiAgentEnv, self).__init__()

        self.config = config
...
    def reset(self, *, seed=None, options=None):
      ...
...
    def step(self, action_dict):
      ...
...

When I run check_env() on the class, I get the infamous AssertionError: Your environment must inherit from the gymnasium.Env class cf. https://gymnasium.farama.org/api/env/. Here's how I'm doing check_env():

train.py

from marlenv import MyMultiAgentEnv
import gymnasium as gym
from gymnasium.envs.registration import register

from stable_baselines3.common.env_util import make_vec_env
from stable_baselines3.common.env_checker import check_env
from stable_baselines3.common.vec_env import VecNormalize

register(
    id="marlenv-v0",
    entry_point="marlenv:MyMultiAgentEnv",
)
env = gym.make('marlenv-v0', config=exp_config)
env = make_vec_env(lambda: env)
env = VecNormalize(env)

check_env(env, warn=True)

This is the information on versions:

Python 3.11.5 (Through Anaconda)

gymnasium 0.29.1

SB3 2.2.1

Most of the answers online say that you have to import gymnasium and not gym, which is something I have done here. Please advise/guide me on how I could proceed!

0

There are 0 best solutions below