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.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e0431d69077560357a40687b5ec0703721b2f1b28e359edb085896f14a8bf9c |
|
MD5 | 665b7a2a1e5f0586a1fef430246ac858 |
|
BLAKE2b-256 | 8e841e6a67a2107dbbdf5ed4dbff4fe6ab5d6f4b265601dbd92db5b7baf206ee |