Arcade-Learning-Environment icon indicating copy to clipboard operation
Arcade-Learning-Environment copied to clipboard

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

Open RedTachyon opened this issue 3 years ago • 1 comments

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.

RedTachyon avatar Oct 07 '22 14:10 RedTachyon

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 avatar Oct 12 '22 14:10 JesseFarebro

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

JesseFarebro avatar Feb 17 '23 06:02 JesseFarebro