Reputation: 1149
I am trying to use a Reinforcement Learning tutorial using OpenAI gym in a Google Colab environment. I am using the strategy of creating a virtual display and then using matplotlib to display the environment that is being rendered.
This works nicely when I use the "CartPole-v0" or the 'LunarLander-v2' environment but is giving an error when I use "Taxi-v3" environment.
Notebook cells are as follows:
# install required system dependencies
!apt-get install -y xvfb x11-utils > /dev/null
!pip install gym[box2d] pyvirtualdisplay PyOpenGL PyOpenGL-accelerate > /dev/null
import pyvirtualdisplay
_display = pyvirtualdisplay.Display(visible=False,size=(1400, 900)) # use False with Xvfb
_ = _display.start()
!echo $DISPLAY
import gym
import matplotlib.pyplot as plt
import numpy as np
from IPython import display
env = gym.make("Taxi-v3").env
#env = gym.make("CartPole-v0").env
#env = gym.make('LunarLander-v2')
env.reset()
fig, ax = plt.subplots(figsize=(20, 10))
ax.axis('off')
img = ax.imshow(env.render(mode='rgb_array'))
#img.set_data(env.render(mode='rgb_array'))
display.display(plt.gcf())
display.clear_output(wait=True)
the error is as follows :
Exception in callback BaseAsyncIOLoop._handle_events(18, 1)
handle: <Handle BaseAsyncIOLoop._handle_events(18, 1)>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
-------- ------- ---- etc etc
File "/usr/local/lib/python3.6/dist-packages/ipykernel/iostream.py", line 339, in flush
if self.pub_thread.thread.is_alive():
AttributeError: 'NoneType' object has no attribute 'thread'
As noted earlier, the error happens ONLY when I use the Taxi-v3 environment. I have two questions
Any guidance or suggestion would be welcome.
Upvotes: 1
Views: 3479
Reputation: 1149
Taxi-v3 is an environment that generates text output! So pushing it into matplotlib is causing the error! This code works!
env = gym.make("Taxi-v3").env
env.reset()
env.render()
and generates
+---------+
|R: | : :G|
| : | : : |
| : : : : |
| | : | : |
|Y| : |B: |
+---------+
in colour!
Upvotes: 1