-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect number of arguments from call to env.step(action) #119
Comments
It would appear that the issue stems from a mismatch in the expected return from env.step. gym/wrappers/time_limit.py returns 5 parameters (observation, reward, terminated, truncated, info) but the invocation is only expecting 4 (observation, reward, terminated, info) Likely related to: Kautenja/nes-py#85 |
I'm having the same issue what is the fix? |
Try to use gym==0.25.1, it works for me |
With v0.26 you can use this code 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:
state = env.reset()
env.close() You can read about the migration guide for the new API https://gymnasium.farama.org/content/migration-guide/ |
I've debugged the step functions and it seems that nes-py returns 4 or 5 length tuple. I adapted the snipped and set truncated to False as a default: def step(self, action):
"""Steps through the environment and if the number of steps elapsed exceeds ``max_episode_steps`` then truncate.
Args:
action: The environment step action
Returns:
The environment step ``(observation, reward, terminated, truncated, info)`` with `truncated=True`
if the number of steps elapsed >= max episode steps
"""
truncated = False
result = self.env.step(action)
if (len(result) == 4):
observation, reward, terminated, info = self.env.step(action)
elif (len(result) == 5):
observation, reward, terminated, truncated, info = self.env.step(action)
else:
raise Exception('Tupel length of step return was neither 4 nore 5. Stop run.')
self._elapsed_steps += 1
if self._elapsed_steps >= self._max_episode_steps:
truncated = True
return observation, reward, terminated, truncated, info so instead of just reading 5 every time I do the same check and this works fine. |
I just installed gym-super-mario-bros and I've attempted to run the gym using a number of methods including the provided sample code:
... as well as from the command line using:
In both cases, the gym attempts to render the first frame of the game and then I receive the following error:
My library versions are as follows:
Running Python 3.9
Any help would be appreciated
The text was updated successfully, but these errors were encountered: