Giter VIP home page Giter VIP logo

gym-recording's Introduction

Status: Archive (code is provided as-is, no updates expected)

gym-recording

A Python package to capture the sequences of actions and observations on a Gym environment by wrapping it in a TraceRecordingWrapper, like this:

import gym
from gym_recording.wrappers import TraceRecordingWrapper

def main():
    env = gym.make('CartPole-v0')
    env = TraceRecordingWrapper(env)
    # ... exercise the environment

It will save recorded traces in a directory, which it will print with logging. You can get the directory name from your code as env.directory.

Later you can play back the recording with code like the following, which runs a callback for every episode.

from gym_recording import playback

def handle_ep(observations, actions, rewards):
  # ... learn a model

playback.scan_recorded_traces(directory, handle_ep)

You can also use the storage_s3 module to upload and download traces from S3, so you it can run across machines.

from gym_recording import playback, storage_s3

def main():
    env = gym.make('CartPole-v0')
    env = TraceRecordingWrapper(env)
    # ... exercise the environment

    s3url = storage_s3.upload_recording(env.directory, env.spec.id, 'openai-example-traces')
    # ... store s3url in a database

    # ... Switch to another machine

    # ... load s3url from a database

    def handle_ep(observations, actions, rewards):
      # ... learn a model
    playback.scan_recorded_traces(storage_s3.download_recording(s3url), handle_ep)

gym-recording's People

Contributors

christopherhesse avatar rmoehn avatar tlbtlbtlb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gym-recording's Issues

I

Purple prose repose root

ModuleNotFoundError: No module named 'gym_recording'

Hi, I need to record my Gym environment so I've put on my code:

import gym
from gym_recording.wrappers import TraceRecordingWrapper

When I run my code, I get: ModuleNotFoundError: No module named 'gym_recording'

I've done from prompt: pip install gym_recording

Everything goes well but when I run the code, I still get the same error.

What should I do?

Segmentation fault with playback.scan_recorded_traces

The following code results in a segmentation fault:

ep = {}
def handle_ep(o, a, r):
  ep['r'] = r

playback.scan_recorded_traces(directory)

print(len(ep['r'])) # OK
print(ep['r']) # Segfault

However, when I just copy over the body from playback.scan_recorded_traces and run this code without closing the reader first, it works just fine. The segfault results from closing the reader (i.e. its open binary files).

Edit: As I suspected, after reading around a bit this seems intended behaviour as the numpy arrays map directly into mmaps. Copying the arrays is sufficient to keep them around after closing the reader. I will leave this issue here for someone else to close, just in case this is not entirely intended.

Does this work with SubprocVecEnv

The openai baselines create multiple stacked environments for training a model and use the wrap_deepmind function. Is it possible to use the gym-recording module with the models created using the openai baselines?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.