Gymnasium: [Bug Report] mujoco rendering is not deterministic
Describe the bug
Describe the bug Upon initializing a mujoco environment through gym (the issue is with mujoco_py and other packages like metaworld etc as well), when one resets the env and renders it the expected behavior would be that any number of renders would give the same image observation. This is true if the rendering backend is glfw (as on mac), however for other backends egl & omesa this is not true.
Code example
Code example When running a simple code :
import gym
x = gym.make('Humanoid-v2', render_mode='rgb_array')
x.reset(seed=2)
a = x.render()
b = x.render()
print((a!=b).sum())
The expected result should be 0. It is 0 if infact i’m running glfw (either onscreen / ofscreen on mac, or ofscreen with xvfb on headless server). But for egl / omesa backend this is non zero & significantly varies.
System Info
Describe the characteristic of your environment:
- gym version 0.26.2, mujoco 2.1.2.14, mujoco 2.2.0
- OS : CentOS7, Ubuntu 20x (tried on both)
- Python 3.9x
While I’m using gym 0.26.2 primarily, I can confirm this error appears even with latest gymnasium 0.29.1
Checklist
- I have checked that there is no similar issue in the repo
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 18 (8 by maintainers)
It almost certainly can’t be MuJoCo’s code since the code doesn’t even know how the OpenGL context was set up!
Could you please provide pixel diffs so that we know how much things change between renders? (Personally I think striving for pixel-identical 3D rendering is not a worthwhile endeavour)
No, no one’s modified anything in
mujoco_py
for years.BTW the rendering helper in
mujoco
hasn’t relied on GLFW for offscreen rendering on macOS for some time: https://github.com/google-deepmind/mujoco/blob/main/python/mujoco/cgl/__init__.py