Wrapper for running/rendering OpenAI Gym on Jupyter Notebook
Project description
Gym-Notebook-Wrapper
Gym-Notebook-Wrapper provides small wrappers for running and rendering OpenAI Gym on Jupyter Notebook or similar (e.g. Google Corab).
Requirement
- Linux
- Xvfb
- On Ubuntu, you can install
sudo apt update && sudo apt install xvfb
.
- On Ubuntu, you can install
- Open GL (for some environment)
- On Ubuntu, you can install
sudo apt update && sudo apt install python-opengl
- On Ubuntu, you can install
Installation
You can install from
PyPI with pip install gym-notebook-wrapper
Usage
Two classes are implemented in gnrwapper
module in this
gym-notebook-wrapper package.
Simple One Shot Animation
Wrap gym.Env
class with gnwrapper.Animation
. That's all! The
render()
method shows the environment on its output. An example code
is following;
Code
import gnwrapper
import gym
env = gnwrapper.Animation(gym.make('CartPole-v1'))
obs = env.reset()
for _ in range(1000):
next_obs, reward, done, info = env.step(env.action_space.sample())
env.render()
obs = next_obs
if done:
obs = env.reset()
Limitation
- Calling
render()
method delete the other output for the same cell. - The output image is shown only once.
Loop Animation
Wrap gym.Env
class with gnwrapper.LoopAnimation
. This wrapper
stores display image when render()
methos is called and shows the
loop animation by display(dpi=72,interval=50)
methos.
Code
import gnwrapper
import gym
env = gnwrapper.LoopAnimation(gym.make('CartPole-v1'))
obs = env.reset()
for _ in range(100):
next_obs, reward, done, info = env.step(env.action_space.sample())
env.render()
obs = next_obs
if done:
obs = env.reset()
env.display()
Limitation
- Require a lot of memory to store and display large steps of display
- Can raise memory error
Notes
gnwrapper.Animation
and gnwrapper.LoopAnimation
inherit from
gym.Wrapper
, so that it can access any fields or mothods of
gym.Env
and gym.Wrapper
(e.g. action_space
).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for gym_notebook_wrapper-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae6c52609d6e615c64903a5d1d9a78429b7b03cdfcbdf5a1f082968c03b19af6 |
|
MD5 | 585e9999274ad5209911798b96751de5 |
|
BLAKE2b-256 | 52256787f127c23590c1b76622aeb25131bba92b7a267ba79b2aa0b40c9d1bc2 |