-
-
Notifications
You must be signed in to change notification settings - Fork 838
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
[Bug Report] gymnasium.utils.play
for gymnasium-robotics environments
#920
Comments
Edit: I am an idiot 🥇 , I confused the repositories, reopening issue Spoiler warningFrom what I can tell, this also fails with gymnasium environments, so it is not an issue with `gymnasium_robotics`, you should report it to `gymnasium`, ```py import gymnasium as gym import numpy as np from gymnasium.utils.play import playenv = gym.make("InvertedPendulum-v5", render_mode="rgb_array")
|
Also fails for import gymnasium as gym
import numpy as np
from gymnasium.utils.play import play
env = gym.make("InvertedPendulum-v5", render_mode="rgb_array")
print(env.action_space)
play(
env,
keys_to_action={
"a": np.array([1], dtype=np.float32),
},
noop=np.array([0], dtype=np.float32),
) |
Very strange, I dont get an issue with MacOS For the warning, I don't think we should be normalising the arr, if the dtype is uint8 assert keys_to_action is not None
# validate the `keys_to_action` set provided
assert isinstance(keys_to_action, dict)
for key, action in keys_to_action.items():
if isinstance(key, tuple):
assert len(key) > 0
assert all(isinstance(k, (str, int)) for k in key)
else:
assert isinstance(key, (str, int))
assert action in env.action_space |
@pseudo-rnd-thoughts do the rendered window work? and do you get any warnings printed on the terminal? $ py test2.py
Box(-3.0, 3.0, (1,), float32)
/home/master-andreas/gym/cartpole/Gymnasium/gymnasium/utils/play.py:137: RuntimeWarning: invalid value encountered in divide
arr = 255.0 * (arr - arr_min) / (arr_max - arr_min)
/home/master-andreas/.local/lib/python3.11/site-packages/pygame/surfarray.py:123: RuntimeWarning: invalid value encountered in cast
array = array.round(0).astype(numpy_uint32) |
Yes and no Might be because I'm on mac, I can also interact with the environment and its works |
I have the same issue:
For BreakoutNoFrameskip-v4 (without custom keybindings, as they are present there), it works OS: Ubuntu 22.04 The game window for this environment opens, but it is completely black, and the terminal shows that there were same errors with division etc, as described here by other users. For BreakoutNoFrameskip-v4, there are no errors and the game is playable |
I have a similar issue, except even after fixing the normalization issue, pygame still displays a black screen only for mujoco tasks (renders nothing even though the image received is displayed fine if displayed via matplotlib). Has there been any updates to this issue? |
Could you include a script to test with? Also, what OS are you using? |
OS: Ubuntu 20.04.6 LTS Yes, below I have attached a test script along with a conda environment. The test script proves, on my setup, the original issue and the issue of not being able to render to PyGame screen even if the original issue is avoided. I left some comments within the From what I can tell, as soon as you call After digging around more, I believe my issues are related to gym issue and this Gymnasium merge. |
Can you produce a minimally working example such that I don't need to download anything? |
Env
Code
|
@Bpoole908 Can you test with |
I have a similar issue, I am trying to render a custom mujoco environment using the dm_robotics package and a camera sensor, and I am trying to use the play() method. I get a black screen on pygame, but if I stick a cv.imshow in my render() I can see the frames are being rendered fine. Similarly, I can follow the debugger into the play() method and see that the rendered image returned is in an appropriate range. Maybe this is some subtle incompatibility between pygame and mujoco, and it's not a gymnasium issue? |
Could you provide a script to test with? |
I agree with this analysis after diving deeper into the issue. It seems to be some incompatibility with screen allocation between PyGame and Mujoco. I was hoping PyGame with SDL 2 might alleviate the issue but no luck as of yet.
I have tested this with the |
It is likely a mujoco and pygame issue but without someone doing a deep dive we can't be certain. |
Describe the bug
I am trying to use the function
gymnasium.utils.play.play
with mujoco-based environments. However, I get this error.It appears that after initializing the pygame display, (https://github.com/Farama-Foundation/Gymnasium/blob/main/gymnasium/utils/play.py#L65)
the mujoco rendering (https://github.com/Farama-Foundation/Gymnasium/blob/main/gymnasium/envs/mujoco/mujoco_rendering.py#L232) returns all zeros.
Any ideas how to resolve this?
Code example
System info
Ubuntu 22.04.3 LTS
python 3.10.13
gymnasium==0.28.1
gymnasium-robotics==1.2.2
mujoco==2.3.3
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: