openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.68k stars 8.6k forks source link

Error on Off-Screen Rendering of CarRacing-v0 #1923

Closed rudrapoudel closed 4 years ago

rudrapoudel commented 4 years ago

I am getting following error in one the remote server (it also has monitor attached though), while creating CarRacing-v0 environment. However, my other servers are working fine.

System

Ubuntu 16, gym 0.17.1/2, pyglet 1.5.0

Minimum code

import gym

#env = gym.make("Breakout-v0")
env = gym.make("CarRacing-v0")

obj = env.reset()

Execution Command

xvfb-run -a -s "-screen 0 1400x900x24" python debug-gym.py

Error Message

/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/gym/logger.py:30: UserWarning: WARN: Box bound precision lowered by casting to float32
  warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))
Track generation: 1172..1470 -> 298-tiles track
Traceback (most recent call last):
  File "debug-gym.py", line 11, in <module>
    obj = env.reset()
  File "/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/gym/wrappers/time_limit.py", line 25, in reset
    return self.env.reset(**kwargs)
  File "/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/gym/envs/box2d/car_racing.py", line 311, in reset
    return self.step(None)[0]
  File "/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/gym/envs/box2d/car_racing.py", line 323, in step
    self.state = self.render("state_pixels")
  File "/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/gym/envs/box2d/car_racing.py", line 407, in render
    arr = arr.reshape(VP_H, VP_W, 4)
ValueError: cannot reshape array of size 0 into shape (96,96,4)

Surprising enough, Breakout-v0 works fine as well as CarRacing-v0 on my other server. What might goes wrong?

Thank you so much!

rudrapoudel commented 4 years ago

However, when I remove -a option from xvfb xvfb-run -a -s "-screen 0 1400x900x24" python debug-gym.py

Error message points below,

image_data = pyglet.image.get_buffer_manager().get_color_buffer().get_image_data()
  File "/home/rpoudel/miniconda3/envs/py35/lib/python3.5/site-packages/pyglet/image/__init__.py", line 2035, in get_image_data
    buffer = (GLubyte * (len(self.format) * self.width * self.height))()
ValueError: Array length must be >= 0, not -74645625240420

It would be great if someone can point me the possible source of error, thanks!

christopherhesse commented 4 years ago

The script seemed to work fine on a linux system when I just tested it. Does xvfb-run glxgears work on your broken system?

rudrapoudel commented 4 years ago

Thank you so much @christopherhesse, it's giving following error,

Error: couldn't get an RGB, Double-buffered visual

quantumiracle commented 4 years ago

I met similar problem when deploying CarRacing on a headless server. But I got ValueError: invalid literal for int() with base 10: '' after running xvfb-run -a -s "-screen 0 1400x900x24" python ***py `

rudrapoudel commented 4 years ago

Can't figure out what was the actual problem, however after upgrading to Ubuntu 18.04 solves my problem. Hence, I believe the bug is related with Xorg version/broken. Hence, I am closing the bug.

quantumiracle commented 4 years ago

@rudrapoudel Could you please provide the gym-version you are using, I'm meeting the same problem as you do now?

rudrapoudel commented 4 years ago

I used latest version of gym installed with pip on last Saturday.

pengzhenghao commented 4 years ago

I have the same issue. Exactly what @rudrapoudel met. Anybody know how to run CarRacing-v0 in headless machine without upgrading the system?

pengzhenghao commented 4 years ago

I also observe a weird phenomenon. When self.render() is called in the first time, the memory consumption on my remote server increases drastically (up to 80G for only single CarRacing-v0 environment). I am not sure what this related to the render issue that return wrong data when calling image_data = pyglet.image.get_buffer_manager().get_color_buffer().get_image_data()

rvadaga commented 3 years ago

Anyone find a fix for this? I'm facing the same issue (ValueError: cannot reshape array of size 0 into shape (96,96,4) from this snippet). I've searched around but couldn't find anything useful. Neither does the pyglet website talk about this.

Based on what @rudrapoudel posted above, seems like some system packages are incompatible. Also I'm in a place where I can't update the Linux OS. I've experimented on 2 different systems on the server (one with gpu and the other without, if that matters) and it seems to work fine on the cpu, but not on the gpu machine.

codejamroad commented 3 years ago

Headless servers Opengym AI rendering Error while using ray

While using ray for distributed computation, all the servers are headless (no display). Therefore, using "xvfb-run -s “-screen 0 1400x900x24” to create screen.

Getting error pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to “None”

Without ray using only 1 machine, this command works perfectly. "xvfb-run -s “-screen 0 1400x900x24”

In conclusion, xvfb-run doesn’t work with ray distribution.

Does Ray require extra configuration to achieve this? Is there any other way I can get past this error? I am working on a Car Racing environment from open gym ai which triggers rendering.

qgallouedec commented 1 year ago

Use

xvfb-run python my_script.py

(Instead of just python my_script.py)