iglu-contest / gridworld

A reinforcement learning environment for the IGLU 2022 at NeurIPS
GNU Affero General Public License v3.0
32 stars 12 forks source link

ContextException: Could not create GL context #16

Open ChengHSUHSU opened 2 years ago

ChengHSUHSU commented 2 years ago

The below is your example code, but I got problem after run it.

import gym
import gridworld
from gridworld.tasks import DUMMY_TASK

env = gym.make('IGLUGridworld-v0')
env.set_task(DUMMY_TASK)
done = False
obs = env.reset()
while not done:
  action = env.action_space.sample()
  obs, reward, done, info = env.step(action)

I got the error message : ContextException: Could not create GL context

my python version is 3.7

artemZholus commented 2 years ago

Hey,

Can you please share

1) the output of echo $IGLU_HEADLESS (better to run run_env.py again to make sure the error reproduces) 2) your os, if Linux, the output of glxinfo and apt list --installed | grep gl 3) if you are able to reproduce the issue in the docker container. Try using this image: iglucontest/gridworld_env:latest

ChengHSUHSU commented 2 years ago

Hi, thank your reply soon, first, I introduce my dev env. I use the Dockerfile [https://github.com/iglu-contest/gridworld/blob/master/docker/Dockerfile], and then build container. Additionally, I only add (pip install jupyterlab) and I run these code on jupyter-lab.

1. the output of echo $IGLU_HEADLESS (better to run run_env.py again to make sure the error reproduces)
=> I run IGLU_HEADLESS in terminal, it output blank.
2. your os, if Linux, the output of glxinfo and apt list --installed | grep gl
=> 
root@R995_87:/tmp/home# glxinfo 
Error: unable to open display 
3. if you are able to reproduce the issue in the docker container. Try using this image: iglucontest/gridworld_env:latest
=> my dev env should be builded by this image.
artemZholus commented 2 years ago

I just checked and the snippet you've shared works for me in the docker container where I launched the jupyter lab. Can you please try a fresh container:

docker pull iglucontest/gridworld_env:latest
docker run --network host --rm -it iglucontest/gridworld_env:latest pip install jupyterlab && jupyter lab --port 22009 --NotebookApp.token='' --no-browser --allow-root

then login to localhost:22009 and paste and run the snipped you shared.

artemZholus commented 2 years ago

I have created a list of known workarounds, which we will update as soon as we find solutions for certain hardware constraints. Please check if a suggested solution works for you: https://github.com/iglu-contest/gridworld/blob/master/README.md#known-issues

seungeunrho commented 2 years ago

@artemZholus Same problem here. I have headless ubuntu server with A100 GPUs. I want to get obs["pov"] but, if I run the code with render=False, there is no pov in obs. So I run with render=True, then the following error message pops out ; pyglet.gl.ContextException: Could not create GL context

FYI,

  1. output of echo $IGLU_HEADLESS none.
  2. output of glxinfo Error: unable to open display

I need your help.

artemZholus commented 2 years ago

Hi @seungeunrho,

Does this happen in the docker container? In particular, can you try running a container with image iglucontest/gridworld_env:latest (better to pull it before running as it was updated recently)?

artemZholus commented 2 years ago

@seungeunrho, @ChengHSUHSU, I need more information to help you.

Please do the following (in the same environment where you get the error):

1) send the full output of EGL_LOG_LEVEL=debug python run_env.py 2) send the output of apt list --installed | grep gl 3) try running 1) inside/outside of the container (to see if the message is the same)

seungeunrho commented 2 years ago

@artemZholus Yup! This happens in the docker container. I tried with both my own docker container and iglucontest/gridworld_env:latest . Here, I will give you the full output of suggested commands.

1. full output of EGL_LOG_LEVEL=debug python run_env.py


libEGL debug: MESA-LOADER: dlopen(/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)

libEGL debug: found extension `DRI_Core'
libEGL info: found extension DRI_Core version 2
libEGL debug: found extension `DRI_SWRast'
libEGL info: found extension DRI_SWRast version 4
libEGL debug: found extension `DRI_CopySubBuffer'
libEGL debug: found extension `DRI_ConfigOptions'
libEGL debug: found extension `DRI_Core'
libEGL debug: found extension `DRI_SWRast'
libEGL debug: found extension `DRI_CopySubBuffer'
libEGL debug: found extension `DRI_ConfigOptions'
libEGL info: found extension DRI_ConfigOptions version 2
libEGL debug: found extension `DRI_TexBuffer'
libEGL info: found extension DRI_TexBuffer version 2
libEGL debug: found extension `DRI_RENDERER_QUERY'
libEGL debug: found extension `DRI_CONFIG_QUERY'
libEGL debug: found extension `DRI2_Fence'
libEGL debug: found extension `DRI_NoError'
libEGL debug: found extension `DRI_IMAGE'
libEGL debug: found extension `DRI_FlushControl'
libEGL debug: found extension `DRI_TexBuffer'
libEGL debug: found extension `DRI_RENDERER_QUERY'
libEGL info: found extension DRI_RENDERER_QUERY version 1
libEGL debug: found extension `DRI_CONFIG_QUERY'
libEGL info: found extension DRI_CONFIG_QUERY version 1
libEGL debug: found extension `DRI2_Fence'
libEGL info: found extension DRI2_Fence version 2
libEGL debug: found extension `DRI_NoError'
libEGL info: found extension DRI_NoError version 1
libEGL debug: found extension `DRI_IMAGE'
libEGL info: found extension DRI_IMAGE version 6
libEGL debug: found extension `DRI_FlushControl'
libEGL info: found extension DRI_FlushControl version 1
libEGL debug: did not find optional extension DRI_Robustness version 1
libEGL debug: did not find optional extension DRI2_BufferDamage version 1
libEGL debug: did not find optional extension DRI2_Interop version 1
libEGL debug: did not find optional extension DRI2_Blob version 1
libEGL debug: did not find optional extension DRI_MutableRenderBufferDriver version 1
libEGL debug: No DRI config supports native format A2RGB10
libEGL debug: No DRI config supports native format X2RGB10
libEGL debug: bad context attribute 0x31b1
libEGL debug: EGL user error 0x3004 (EGL_BAD_ATTRIBUTE) in eglCreateContext

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    env = gym.make('IGLUGridworld-v0')
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 235, in make
    return registry.make(id, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 129, in make
    env = spec.make(**kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 90, in make
    env = cls(**_kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gridworld-0.1rc1-py3.7.egg/gridworld/env.py", line 310, in create_env
    action_space=action_space, fake=fake
  File "/opt/conda/lib/python3.7/site-packages/gridworld-0.1rc1-py3.7.egg/gridworld/env.py", line 102, in __init__
    from gridworld.render import Renderer, setup
  File "/opt/conda/lib/python3.7/site-packages/gridworld-0.1rc1-py3.7.egg/gridworld/render.py", line 8, in <module>
    from pyglet.window import Window
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/__init__.py", line 1918, in <module>
    gl._create_shadow_window()
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/__init__.py", line 206, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/headless/__init__.py", line 60, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/__init__.py", line 615, in __init__
    context = config.create_context(gl.current_context)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/headless.py", line 123, in create_context
    return HeadlessContext(self, share)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/headless.py", line 134, in __init__
    raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context
libEGL debug: MESA-LOADER: dlopen(/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)

libEGL debug: found extension `DRI_Core'
libEGL info: found extension DRI_Core version 2
libEGL debug: found extension `DRI_SWRast'
libEGL info: found extension DRI_SWRast version 4
libEGL debug: found extension `DRI_CopySubBuffer'
libEGL debug: found extension `DRI_ConfigOptions'
libEGL debug: found extension `DRI_Core'
libEGL debug: found extension `DRI_SWRast'
libEGL debug: found extension `DRI_CopySubBuffer'
libEGL debug: found extension `DRI_ConfigOptions'
libEGL info: found extension DRI_ConfigOptions version 2
libEGL debug: found extension `DRI_TexBuffer'
libEGL info: found extension DRI_TexBuffer version 2
libEGL debug: found extension `DRI_RENDERER_QUERY'
libEGL debug: found extension `DRI_CONFIG_QUERY'
libEGL debug: found extension `DRI2_Fence'
libEGL debug: found extension `DRI_NoError'
libEGL debug: found extension `DRI_IMAGE'
libEGL debug: found extension `DRI_FlushControl'
libEGL debug: found extension `DRI_TexBuffer'
libEGL debug: found extension `DRI_RENDERER_QUERY'
libEGL info: found extension DRI_RENDERER_QUERY version 1
libEGL debug: found extension `DRI_CONFIG_QUERY'
libEGL info: found extension DRI_CONFIG_QUERY version 1
libEGL debug: found extension `DRI2_Fence'
libEGL info: found extension DRI2_Fence version 2
libEGL debug: found extension `DRI_NoError'
libEGL info: found extension DRI_NoError version 1
libEGL debug: found extension `DRI_IMAGE'
libEGL info: found extension DRI_IMAGE version 6
libEGL debug: found extension `DRI_FlushControl'
libEGL info: found extension DRI_FlushControl version 1
libEGL debug: did not find optional extension DRI_Robustness version 1
libEGL debug: did not find optional extension DRI2_BufferDamage version 1
libEGL debug: did not find optional extension DRI2_Interop version 1
libEGL debug: did not find optional extension DRI2_Blob version 1
libEGL debug: did not find optional extension DRI_MutableRenderBufferDriver version 1
libEGL debug: No DRI config supports native format A2RGB10
libEGL debug: No DRI config supports native format X2RGB10
libEGL debug: bad context attribute 0x31b1
libEGL debug: EGL user error 0x3004 (EGL_BAD_ATTRIBUTE) in eglCreateContext

Traceback (most recent call last):
  File "/data/private/test/brain_agent_public/test.py", line 7, in <module>
    env = gym.make('IGLUGridworld-v0')
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 235, in make
    return registry.make(id, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 129, in make
    env = spec.make(**kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gym/envs/registration.py", line 90, in make
    env = cls(**_kwargs)
  File "/opt/conda/lib/python3.7/site-packages/gridworld/env.py", line 310, in create_env
    action_space=action_space, fake=fake
  File "/opt/conda/lib/python3.7/site-packages/gridworld/env.py", line 102, in __init__
    from gridworld.render import Renderer, setup
  File "/opt/conda/lib/python3.7/site-packages/gridworld/render.py", line 8, in <module>
    from pyglet.window import Window
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/__init__.py", line 1918, in <module>
    gl._create_shadow_window()
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/__init__.py", line 206, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/headless/__init__.py", line 60, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/window/__init__.py", line 615, in __init__
    context = config.create_context(gl.current_context)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/headless.py", line 123, in create_context
    return HeadlessContext(self, share)
  File "/opt/conda/lib/python3.7/site-packages/pyglet/gl/headless.py", line 134, in __init__
    raise gl.ContextException('Could not create GL context')
pyglet.gl.ContextException: Could not create GL context

2. output of apt list --installed | grep gl

freeglut3/now 2.8.1-3 amd64 [installed,local]
freeglut3-dev/now 2.8.1-3 amd64 [installed,local]
gir1.2-glib-2.0/now 1.56.1-1 amd64 [installed,local]
libegl-mesa0/now 20.0.8-0ubuntu1~18.04.1 i386 [installed,local]
libegl1/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libegl1-mesa-dev/now 20.0.8-0ubuntu1~18.04.1 i386 [installed,local]
libgl1/now 1.0.0-2ubuntu2.3 amd64 [installed,local]
libgl1-mesa-dev/now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,local]
libgl1-mesa-dri/now 20.0.8-0ubuntu1~18.04.1 i386 [installed,local]
libgl1-mesa-glx/now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,local]
libglapi-mesa/now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,local]
libgles1/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libgles2/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libgles2-mesa-dev/now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,local]
libglib2.0-0/now 2.56.4-0ubuntu0.18.04.9 amd64 [installed,local]
libglu1-mesa/now 9.0.0-2.1build1 amd64 [installed,local]
libglu1-mesa-dev/now 9.0.0-2.1build1 amd64 [installed,local]
libglvnd-core-dev/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libglvnd-dev/now 1.0.0-2ubuntu2.3 amd64 [installed,local]
libglvnd0/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libglx-mesa0/now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,local]
libglx0/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libopengl0/now 1.0.0-2ubuntu2.3 i386 [installed,local]
libwayland-egl1/now 1.16.0-1ubuntu1.1~18.04.3 i386 [installed,local]
libxcb-glx0/now 1.13-2~ubuntu18.04 amd64 [installed,local]
libxcb-glx0-dev/now 1.13-2~ubuntu18.04 i386 [installed,local]
freeglut3/bionic,now 2.8.1-3 amd64 [installed,automatic]
freeglut3-dev/bionic,now 2.8.1-3 amd64 [installed]
gir1.2-glib-2.0/bionic,now 1.56.1-1 amd64 [installed,automatic]
libegl-mesa0/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,automatic]
libegl1/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libgl1/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libgl1-mesa-dev/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,automatic]
libgl1-mesa-dri/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,automatic]
libgl1-mesa-glx/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed]
libglapi-mesa/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,automatic]
libgles1/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libgles2/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libglib2.0-0/bionic-updates,bionic-security,now 2.56.4-0ubuntu0.18.04.9 amd64 [installed,automatic]
libglib2.0-data/bionic-updates,bionic-security,now 2.56.4-0ubuntu0.18.04.9 all [installed,automatic]
libglu1-mesa/bionic,now 9.0.0-2.1build1 amd64 [installed,automatic]
libglu1-mesa-dev/bionic,now 9.0.0-2.1build1 amd64 [installed,automatic]
libglvnd-core-dev/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libglvnd-dev/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libglvnd0/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libglx-mesa0/bionic-updates,now 20.0.8-0ubuntu1~18.04.1 amd64 [installed,automatic]
libglx0/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libopengl0/bionic-updates,now 1.0.0-2ubuntu2.3 amd64 [installed,automatic]
libxcb-glx0/bionic-updates,now 1.13-2~ubuntu18.04 amd64 [installed,automatic]
libxcb-glx0-dev/bionic-updates,now 1.13-2~ubuntu18.04 amd64 [installed,automatic]

' ' '

In my opinion, I'm running these command on ths OS ubuntu-server-18.04 which has no default libraries for display. Maybe that's the problem..?

artemZholus commented 2 years ago

@seungeunrho I think the problem is due to a wrong GPU driver being loaded. You mentioned that you have an A100 nvidia GPU, however your logs suggest that an the swrast driver is being used (libEGL debug: MESA-LOADER: dlopen(/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so)) both in/outside of a container.

Try this: 1) install the latest nvidia gpu driver 2) install e.g. pytorch to check if driver/cuda work. 3) once everything is installed/working, try running the env again. Nvidia driver seems to have no logging so you can just run python run_env.py. Also, you may need to run export NVIDIA_DRIVER_CAPABILITIES=all before your script.

ChengHSUHSU commented 2 years ago

Hi @artemZholus

After some investigation, we found that it cause "ContextException: Could not create GL context", it is because "gl.current_context : None". Could you give us some solutions to make gl.current_context is not None???

BTW, I can run below code in my mac env, but it cannot run in linux docker env

Screen Shot 2022-08-13 at 5 23 32 PM
artemZholus commented 2 years ago

Hi @ChengHSUHSU .

Please share more details on your case. In particular, please send the info collected using this instruction https://github.com/iglu-contest/gridworld/issues/16#issuecomment-1207239246

artemZholus commented 2 years ago

Hi, @ChengHSUHSU , @seungeunrho .

I have just fixed the headed rendering which may help in your case as well. (see #18).

Please install the latest master and try running the env in headed mode (in case there is a monitor on system). Make sure to do export IGLU_HEADLESS=0