Farama-Foundation / Metaworld

Collections of robotics environments geared towards benchmarking multi-task and meta reinforcement learning
https://metaworld.farama.org/
MIT License
1.28k stars 274 forks source link

TypeError: render() got an unexpected keyword argument 'offscreen' #479

Closed Taskii-Lei closed 6 months ago

Taskii-Lei commented 6 months ago

Thanks for your great work! I love the Metaworld! I want to render the env, and resize it to (64,64). But when I run env.render(offscreen=True, resolution=(64,64), camera_name="corner"), it raises error: TypeError: render() got an unexpected keyword argument 'offscreen'. And so do the parameter 'resolution' . I have tried https://github.com/Farama-Foundation/Metaworld/issues/34, but it doesn't work for me.

The Virtual Env: I followed the manual configuration, ran pip install -e . and succeeded. And I have apt install xvfb

Machine: I run it on a remote machine.

Codes:

import metaworld
benchmark = metaworld.ML1("pick-place-v2")
env = benchmark.train_classes["pick-place-v2"]()
image = env.render(offscreen=True, resolution=(64,64), camera_name="corner")
print(image.shape)

ERROR: File "/xxx/x/xxxx/test.py", line 4, in env.render(offscreen=True, resolution=(64,64), camera_name="corner").shape TypeError: MujocoEnv.render() got an unexpected keyword argument 'offscreen'

I was so confused if it's because any lib is missing or not installed? or versions mismatch?

BTW, the env.step(a) is not correct, cuz. I found the output is a 5-tuple, not 4-tuple. I read the source code and found it should be (see Metaworld/metaworld/envs/mujoco/sawyer_xyz/sawyer_xyz_env.py:614~620):

obs, reward, False, truncate, info = env.step(a)

The truncate is set as a done-flag, and the third one, which should be done-flag is set always False. The https://github.com/Farama-Foundation/Metaworld?tab=readme-ov-file#using-the-benchmark in README.md should be corrected or at least should be illustrated because it's a little bit misleading. Thank you !!

reginald-mclean commented 6 months ago

Hi @Taskii-Lei. Thank you for opening this issue. You are correct that the README.md needs to be updated :)

The API has changed slightly, it should now be something like:

env = benchmark.train_classes["pick-place-v2"](render_mode='rgb_array', camera_name='corner') We don't get pass any height or width fields to the Gymnasium MujocoEnv class as of right now, so you will need to modify the Sawyer_XYZ base class as well:

mjenv_gym.__init__( self, model_name, frame_skip=frame_skip, observation_space=self.sawyer_observation_space, render_mode=render_mode, camera_name=camera_name, camera_id=camera_id, height = X, width = X, )

where X and Y are your desired render sizes. Let me know if that doesn't work!

Taskii-Lei commented 6 months ago

I modified some parameters of related classes according to your tips, and now it runs very well! Thank you so much!

reginald-mclean commented 6 months ago

I'm going to close this issue, but feel free to open it if you find any other issues!