"OpenAIGym" (Reinforcement Learning Environments)

"OpenAIGym" provides an interface to the Python OpenAI Gym reinforcement learning environments package.

To use "OpenAIGym", the OpenAI Gym Python package must be installed.

The OpenAI Gym Python package is only officially supported on Linux and macOS platforms. Additionally, several different families of environments are available. Examples on this page use the "Atari" family of environments. This family can be installed from the command line using (additional detailed installation instructions are available here):

$ pip install "gym[atari]"

ExternalEvaluate is used to interface with this Python package. It is up to the user to ensure that ExternalEvaluate is set up with a Python environment with Gym installed. A simple test to ensure that Gym is correctly set up is to run the following:

ExternalEvaluate["Python", "import gym"]
CarRacing-v0 environment from the OpenAI Gym

Examples

Basic Examples  (2)

Open the "Atlantis-v0" Atari environment:

In[1]:=
Click for copyable input
Out[1]=

Observe the initial state:

In[2]:=
Click for copyable input
Out[2]=

In this case, the "ObservedState" is an array of pixel values. Visualize this as an image:

In[3]:=
Click for copyable input
Out[3]=

Obtain a random action:

In[4]:=
Click for copyable input
Out[4]=

Take the random action:

In[5]:=
Click for copyable input
Out[5]=

Taking an action usually modifies the "ObservedState":

In[6]:=
Click for copyable input
Out[6]=

Reset the environment to an initial state. The initial "ObservedState" is returned:

In[7]:=
Click for copyable input
Out[7]=

Close the environment:

In[8]:=
Click for copyable input

Open the "Breakout-v0" environment:

In[1]:=
Click for copyable input
Out[1]=

Visualize a random agent playing Breakout:

In[2]:=
Click for copyable input
Out[2]=

Close the environment:

In[3]:=
Click for copyable input