Skip to content
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

Headless Rendering within a Docker Container #1629

Open
smmislam opened this issue May 1, 2024 · 0 comments
Open

Headless Rendering within a Docker Container #1629

smmislam opened this issue May 1, 2024 · 0 comments
Labels
question Request for help or information

Comments

@smmislam
Copy link

smmislam commented May 1, 2024

Hi,

I'm a graduate student, using MuJoCo for training RL models. I want to run my models within a docker container.
I'm looking for some help with headless rendering.

First off, below is the docker-file that I'm using to create docker-image.

FROM python:3.8.10

RUN python -m pip install --upgrade pip

RUN pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118

RUN python -m pip install dm_control gymnasium
RUN python -m pip install numpy matplotlib seaborn einops ml_collections 
RUN python -m pip install wandb moviepy imageio

RUN apt-get update
RUN apt-get install -y libglew2.1
RUN apt-get install libgl1-mesa-glx libosmesa6

My script tries to initialize the walker-walk environment and do some training. I have set-up the exact same environment using conda, and everything is fine and working. However, when I try to run the same script from within the docker container I get this error below

/usr/local/lib/python3.8/site-packages/glfw/init.py:914: GLFWError: (65537) b'The GLFW library is not initialized'
warnings.warn(message, GLFWError)
.........
File "/usr/local/lib/python3.8/site-packages/dm_control/suite/wrappers/pixels.py", line 77, in init
pixels = env.physics.render(**render_kwargs)
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/engine.py", line 223, in render
camera = Camera(
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/engine.py", line 711, in init
if self._physics.contexts.mujoco is not None:
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/engine.py", line 533, in contexts
self._make_rendering_contexts()
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/engine.py", line 519, in _make_rendering_contexts
mujoco_context = wrapper.MjrContext(self.model, render_context)
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/wrapper/core.py", line 608, in init
ptr = ctx.call(mujoco.MjrContext, model.ptr, font_scale)
File "/usr/local/lib/python3.8/site-packages/dm_control/_render/executor/render_executor.py", line 138, in call
return func(*args, **kwargs)
mujoco.FatalError: an OpenGL platform library has not been loaded into this process, this most likely means that a valid OpenGL context has not been created before mjr_makeContext was called

To solve this, I changed the environment variable like so
export MUJOCO_GL=egl

And finally, I get the following error
...
from dm_control import suite
File "/usr/local/lib/python3.8/site-packages/dm_control/suite/init.py", line 24, in
from dm_control.suite import acrobot
File "/usr/local/lib/python3.8/site-packages/dm_control/suite/acrobot.py", line 20, in
from dm_control import mujoco
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/init.py", line 18, in
from dm_control.mujoco.engine import action_spec
File "/usr/local/lib/python3.8/site-packages/dm_control/mujoco/engine.py", line 41, in
from dm_control import _render
File "/usr/local/lib/python3.8/site-packages/dm_control/_render/init.py", line 86, in
Renderer = import_func()
File "/usr/local/lib/python3.8/site-packages/dm_control/_render/init.py", line 36, in _import_egl
from dm_control._render.pyopengl.egl_renderer import EGLContext
File "/usr/local/lib/python3.8/site-packages/dm_control/_render/pyopengl/egl_renderer.py", line 39, in
from dm_control._render.pyopengl import egl_ext as EGL
File "/usr/local/lib/python3.8/site-packages/dm_control/_render/pyopengl/egl_ext.py", line 29, in
from OpenGL import EGL
File "/usr/local/lib/python3.8/site-packages/OpenGL/EGL/init.py", line 2, in
from OpenGL.raw.EGL._types import *
File "/usr/local/lib/python3.8/site-packages/OpenGL/raw/EGL/_types.py", line 87, in
raw_eglQueryString = _p.PLATFORM.EGL.eglQueryString
AttributeError: 'NoneType' object has no attribute 'eglQueryString'

I would really appreciate any help or suggestion on how to solve this problem.

Note that I was able to run the script with the X Virtual Framebuffer apprach suggested in issue#350. But, I suspect that the rendering doesn't use GPU and hence quite slow.

@smmislam smmislam added the question Request for help or information label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for help or information
Projects
None yet
Development

No branches or pull requests

1 participant