0

I am playing with the RL colab that uses CartPole-v0 from gym. I opened the iPython notebook through jupyter connected to a remote centOS 7.3 server (not google drive). The following code renders the cartpole diagram correctly under google colab, but not with my jupyter setup:

!pip install gym[classic_control]
import gym
env = gym.make('CartPole-v0')
env.reset()
img = env.render('rgb_array')
plt.imshow(img)

Here is how I started my jupyter notebook:

xvfb-run -a -s "-screen 0 1400x900x24" jupyter notebook

Apparently the rendered image has either uninitialized dimensions or 0 dimensions. This is True whether using Jupyter or not.

Here is the full error: enter image description here

I printed out the line just before the error in pyglet/image/__init__.py

def get_image_data(self):
    # xxx = GLubyte * (len(self.format) * self.width * self.height)
    print(GLubyte, len(self.format), self.width, self.height)  # my code
    buffer = (GLubyte * (len(self.format) * self.width * self.height))()

The results are either (4 0 0) or (4 1551512832 274094153), from which I infer the width and height are uninitialized. But I don't understand the internal well enough to debug further. In the former case, MemoryError becomes something error that says cannot render an image of size zero.

Any insight is appreciated. Here are some relevant threads:

How to run OpenAI Gym .render() over a server

https://blog.csdn.net/chestnutss/article/details/100734523

John Jiang
  • 827
  • 1
  • 9
  • 19

1 Answers1

0

I managed to solve the environment issue with the following series of commands:

sudo yum install python-xvfbwrapper.noarch
sudo yum install mesa-dri-drivers
sudo yum install xorg-devel libglu1-mesa libgl1-mesa-devel libxinerama1 libxcursor1
sudo yum install glxinfo
sudo yum -y install freeglut-devel

Then the following rendering works in a jupyter browser notebook connected to the server

import gym
import matplotlib.pyplot as plt

env = gym.make('CartPole-v0')
env.reset()
img = env.render('rgb_array')
plt.imshow(img)

enter image description here

John Jiang
  • 827
  • 1
  • 9
  • 19