Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)
https://gymnasium.farama.org
MIT License
7k stars 781 forks source link

[Bug Report] Value Error: env.step(action) #3138 #95

Closed brucecui1998 closed 1 year ago

brucecui1998 commented 1 year ago

Describe the bug

When setting up my envs, I get Value Error messages for my env.step(env.action_space.sample()) If you can help that will be greatly appreciated! (Mac OS, Jupyter Lab)

Here's the Code:

Code example

import gym_super_mario_bros
import gymnasium as gym
from nes_py.wrappers import JoypadSpace
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT

env = gym_super_mario_bros.make('SuperMarioBros-v0')
env = JoypadSpace(env, SIMPLE_MOVEMENT)

# Create a flag - restart or not
done = True
for step in range(100000):
    if done:
        env.reset()
        # do random actions
    state, reward, done, info = env.step(env.action_space.sample())
    # show the game on the screen
    env.render()
env.close()

System info

pip3 install gym-super-mario-bros==7.3.0 nes_py gymnasium.version = 0.26.3 python==3.7.0

Additional context

Error Message: ValueError Traceback (most recent call last) Cell In [45], line 5 3 if done: 4 state = env.reset() ----> 5 state, reward, done, info = env.step(env.action_space.sample()) 6 env.render() 8 env.close()

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nes_py/wrappers/joypad_space.py:74, in JoypadSpace.step(self, action) 59 """ 60 Take a step using the given action. 61 (...) 71 72 """ 73 # take the step and record the output ---> 74 return self.env.step(self._action_map[action])

File /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gym/wrappers/time_limit.py:50, in TimeLimit.step(self, action) 39 def step(self, action): 40 """Steps through the environment and if the number of steps elapsed exceeds max_episode_steps then truncate. 41 42 Args: (...) 48 49 """ ---> 50 observation, reward, terminated, truncated, info = self.env.step(action) 51 self._elapsed_steps += 1 53 if self._elapsed_steps >= self._max_episode_steps:

ValueError: not enough values to unpack (expected 5, got 4)

Checklist

pseudo-rnd-thoughts commented 1 year ago

Please see https://github.com/Farama-Foundation/Gymnasium/issues/77

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
import gym

env = gym.make('SuperMarioBros-v0', apply_api_compatibility=True, render_mode="human")
env = JoypadSpace(env, SIMPLE_MOVEMENT)

done = True
env.reset()
for step in range(5000):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated

    if done:
       env.reset()

env.close()