Farama-Foundation / Arcade-Learning-Environment

The Arcade Learning Environment (ALE) -- a platform for AI research.
GNU General Public License v2.0
2.12k stars 420 forks source link

[BUG] Atari envs don't define `self.render_mode` for compatibility with gym 0.26 #471

Closed RedTachyon closed 1 year ago

RedTachyon commented 1 year ago

In gym 0.26, we use a standard approach of setting self.render_mode during initialization, which is then mostly for internal management by the env, but it is also used by some wrappers, e.g. VideoRecorder.

With the current version of ALE, this doesn't work. Consider this snippet:

import gym
from gym.wrappers import RecordVideo

env = gym.make('ALE/MontezumaRevenge-v5', render_mode='rgb_array')

env.unwrapped.render_mode = env.unwrapped._render_mode

env = RecordVideo(env, video_folder='videos')
state, info = env.reset()
done = False
while not done:
    action = env.action_space.sample()
    state, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated
env.close()

This throws up a warning that recording is disabled because the environment has not been defined with an appropriate render_mode.

The reason is that ALE internally records the render mode as self._render_mode, so the wrapper doesn't pick it up.

I'm pretty sure the only needed fix is replacing _render_mode with render_mode, I can contribute a PR if that'd be useful.

JesseFarebro commented 1 year ago

Hi @RedTachyon, this wasn't made clear in the last Gym release. I would suggest adding it to the env checker: https://github.com/openai/gym/blob/master/gym/utils/env_checker.py as that's what I check against.

If you want to make a PR that would be great. I would prefer that you keep _render_mode and just create a property via the decorator named render_mode. Thanks!

JesseFarebro commented 1 year ago

This is fixed as of v0.8.1 for the legacy Gym environment.