gym icon indicating copy to clipboard operation
gym copied to clipboard

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

Open AchillesPlight opened this issue 2 years ago • 7 comments

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:

!pip3 install gym-super-mario-bros nes_py !pip3 install gym

from nes_py.wrappers import JoypadSpace import gym_super_mario_bros from gym_super_mario_bros.actions import SIMPLE_MOVEMENT env = gym_super_mario_bros.make('SuperMarioBros-v0') env = JoypadSpace(env, SIMPLE_MOVEMENT)

done = True for step in range(5000): if done: state = env.reset() state, reward, done, info = env.step(env.action_space.sample()) env.render()

env.close()

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)

  • [x] I have checked that there is no similar [issue]

AchillesPlight avatar Oct 25 '22 15:10 AchillesPlight

Hey, we just launched gymnasium, a fork of Gym by the maintainers of Gym for the past 18 months where all maintenance and improvements will happen moving forward. Could you please move this over to the new repo?

If you'd like to read more about the story behind the backstory behind this and our plans going forward, click here.

pseudo-rnd-thoughts avatar Oct 25 '22 17:10 pseudo-rnd-thoughts

Of course! I'm sorry for adding this in the wrong repo. Thank you for your assistance!

AchillesPlight avatar Oct 26 '22 01:10 AchillesPlight

Have you solved the problem now? I have encountered the same problem

brucecui1998 avatar Oct 29 '22 09:10 brucecui1998

The gymnasium issue 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()

pseudo-rnd-thoughts avatar Oct 29 '22 12:10 pseudo-rnd-thoughts

Try this, they update prob if the library supports it.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Games Environments """"""""""""""""""""""""""""""""""""""""""""""""""""""""" env = gym.make("ALE/KungFuMaster-v5", render_mode='human') n_outputs = env.action_space.n obs = env.reset() observation, reward, done, info, prob = env.step(1)

jkaewprateep avatar Nov 10 '22 01:11 jkaewprateep

@jkaewprateep This code is incorrect! For Gym v26, the correct code is

env = gym.make("ALE/KungFuMaster-v5", render_mode='human')
n_outputs = env.action_space.n
obs, info = env.reset()
observation, reward, terminated, truncated, info = env.step(1)

pseudo-rnd-thoughts avatar Nov 10 '22 12:11 pseudo-rnd-thoughts

That is the variable name. 01

jkaewprateep avatar Nov 11 '22 01:11 jkaewprateep