Farama-Foundation / Minigrid

Simple and easily configurable grid world environments for reinforcement learning
https://minigrid.farama.org/
Other
2.09k stars 604 forks source link

[Bug Report] Minigrid environment fails to step when SymbolicObsWrapper is used #278

Closed zidanwang2025 closed 1 year ago

zidanwang2025 commented 1 year ago

Describe the bug

The Minigrid environment fails to step when SymbolicObsWrapper is used.

Code example

import gymnasium as gym
from minigrid.wrappers import RGBImgObsWrapper, SymbolicObsWrapper, ImgObsWrapper
env = gym.make('MiniGrid-Empty-8x8-v0')
env = SymbolicObsWrapper(env)
obs, info = env.reset()
count = 0
for i in range(10000):
    action = env.action_space.sample()
    next_obs, reward, terminated, truncated, info = env.step(action)
    if (next_obs['image'] != obs['image']).any():
        count += 1
        obs = next_obs
print(count)

The count I got from this code is 0. While next_obs['direction'] changes,next_obs['image'] stays the same when env.step(action) is called. This does not happen when RGBImgObsWrapper(env) is used instead.

System Info

Checklist

rodrigodelazcano commented 1 year ago

Thank you for finding this, I got to replicate it and I'll fix it soon.

rodrigodelazcano commented 1 year ago

@zidanwang2025 UPDATE: the wrapper is actually correct. The issue is that the encoded observation doesn't include the agent, and the map is static. If you try your code with a dynamic environment like MiniGrid-Dynamic-Obstacles-5x5-v0 you'll find that the Symbolic observation is different.

However, I'll modify the wrapper to include the agent in order to have the complete state of the environment.

zidanwang2025 commented 1 year ago

Thanks for the update!!