yardenas / safety-gym

MIT License
0 stars 2 forks source link

Argument 'sim' has incorrect type (expected mujoco_py.cymj.MjSim, got Physics) #1

Closed SHITIANYU-hue closed 1 year ago

SHITIANYU-hue commented 1 year ago

Hello when i run https://github.com/yardenas/la-mbda, i tried to install this safety-gym environment, but i occurred this issue:

Traceback (most recent call last): File "experiments/train.py", line 7, in train_utils.train(config, LAMBDA) File "/media/changquan/data0/sty/la-mbda/experiments/train_utils.py", line 139, in train on_episode_end=lambda episode_summary, steps_count: on_episode_end( File "/media/changquan/data0/sty/la-mbda/la_mbda/utils.py", line 101, in interact pbar, len(episodes) < config.render_episodes and not training) File "/media/changquan/data0/sty/la-mbda/la_mbda/utils.py", line 63, in do_episode observation = environment.reset() if reset_function is None else reset_function() File "/home/changquan/anaconda3/envs/lambda/lib/python3.7/site-packages/gym/core.py", line 259, in reset observation = self.env.reset(kwargs) File "/home/changquan/anaconda3/envs/lambda/lib/python3.7/site-packages/gym/core.py", line 284, in reset return self.env.reset(kwargs) File "/home/changquan/anaconda3/envs/lambda/lib/python3.7/site-packages/gym/core.py", line 232, in reset return self.env.reset(kwargs) File "/home/changquan/anaconda3/envs/lambda/lib/python3.7/site-packages/gym/wrappers/time_limit.py", line 25, in reset return self.env.reset(kwargs) File "/media/changquan/data0/sty/la-mbda/safety-gym/safety_gym/envs/engine.py", line 887, in reset self.build() File "/media/changquan/data0/sty/la-mbda/safety-gym/safety_gym/envs/engine.py", line 863, in build self.world.reset() File "/media/changquan/data0/sty/la-mbda/safety-gym/safety_gym/envs/world.py", line 324, in reset self.build() File "/media/changquan/data0/sty/la-mbda/safety-gym/safety_gym/envs/world.py", line 299, in build render_context = MjRenderContextOffscreen(self.sim, device_id=-1, quiet=True) TypeError: Argument 'sim' has incorrect type (expected mujoco_py.cymj.MjSim, got Physics)

yardenas commented 1 year ago

Hi @SHITIANYU-hue, thanks for your interest in la-mbda :) Seems like an off-screen rendering issue. For some reason, it seems like your la-mbda installation didn't use the correct branch (dm_hack) when installing safety-gym (see more details here). To give some context: what this branch does is replacing the default mujoco-py backend with dm-control backend to use mujoco. The reason for that is exactly because I was facing issues with off-screen rendering when I used mujoco-py.

I'd suggest two ways to move forward with this issue:

  1. Clone my fork of safety-gym, change branch to dm_hack, and run pip install -e .
  2. Debug why your la-mbda installation and figure out why it doesn't install the correct branch.

Hope this helps!

SHITIANYU-hue commented 1 year ago

Hello, thanks for you reply!

I tried to switch to your branch, and install mujoco-py again, it will have this error: /tmp/pip-install-z2umchxi/mujoco-py_a423904d938b4189baba78cf038f2e6e/mujoco_py/gl/osmesashim.c:1:10: fatal error: GL/osmesa.h: No such file or directory 1 | #include <GL/osmesa.h> | ^~~~~ compilation terminated. error: command '/usr/bin/gcc' failed with exit code 1 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mujoco-py Failed to build mujoco-py ERROR: Could not build wheels for mujoco-py, which is required to install pyproject.toml-based projects

image
yardenas commented 1 year ago

Thanks for the update. Two questions back:

  1. Are you using a GPU for rendering? If that's the case, make sure to export MUJOCO_GL=egl before running experiments. This will make rendering use OpenGL rendering (which uses GPUs) instead of OSMesa (which runs on CPUs, and from my experience is quite slow)
  2. Not sure why it's trying to compile mujoco-py but the failure happens there. I'd try compiling it before running LAMBDA. For example, run
    
    import gym

env = gym.make("InvertedPendulum-v1")

Should be building mujoco-py as it loads the mujoco bindings for the first time



Let me know if that helped
yardenas commented 1 year ago

Closing for now, feel free to reopen