GithubHelp home page GithubHelp logo

alexxnica / gym-http-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openai/gym-http-api

0.0 1.0 0.0 141 KB

API to access OpenAI Gym from other languages via HTTP

License: MIT License

R 1.10% Ruby 4.34% Clojure 3.37% C++ 12.00% Haskell 9.88% JavaScript 1.35% Shell 0.35% TypeScript 9.03% Lua 9.56% MATLAB 6.68% Rust 9.12% Python 33.20%

gym-http-api's Introduction

gym-http-api

This project provides a local REST API to the gym open-source library, allowing development in languages other than python.

A python client is included, to demonstrate how to interact with the server.

Contributions of clients in other languages are welcomed!

Installation

To download the code and install the requirements, you can run the following shell commands:

git clone https://github.com/openai/gym-http-api
cd gym-http-api
pip install -r requirements.txt

Getting started

This code is intended to be run locally by a single user. The server runs in python. You can implement your own HTTP clients using any language; a demo client written in python is provided to demonstrate the idea.

To start the server from the command line, run this:

python gym_http_server.py

In a separate terminal, you can then try running the example python agent and see what happens:

python example_agent.py  

The example lua agent behaves very similarly:

cd binding-lua
lua example_agent.lua

You can also write code like this to create your own client, and test it out by creating a new environment. For example, in python:

remote_base = 'http://127.0.0.1:5000'
client = Client(remote_base)

env_id = 'CartPole-v0'
instance_id = client.env_create(env_id)
client.env_step(instance_id, 0)

Testing

This repository contains integration tests, using the python client implementation to send requests to the local server. They can be run using the nose2 framework. From a shell (such as bash) you can run nose2 directly:

cd gym-http-api
nose2

API specification

  • POST /v1/envs/

    • Create an instance of the specified environment
    • param: env_id -- gym environment ID string, such as 'CartPole-v0'
    • returns: instance_id -- a short identifier (such as '3c657dbc') for the created environment instance. The instance_id is used in future API calls to identify the environment to be manipulated
  • GET /v1/envs/

    • List all environments running on the server
    • returns: envs -- dict mapping instance_id to env_id (e.g. {'3c657dbc': 'CartPole-v0'}) for every env on the server
  • POST /v1/envs/<instance_id>/reset/

    • Reset the state of the environment and return an initial observation.
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
    • returns: observation -- the initial observation of the space
  • POST /v1/envs/<instance_id>/step/

    • Step though an environment using an action.
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
    • param: action -- an action to take in the environment
    • returns: observation -- agent's observation of the current environment
    • returns: reward -- amount of reward returned after previous action
    • returns: done -- whether the episode has ended
    • returns: info -- a dict containing auxiliary diagnostic information
  • GET /v1/envs/<instance_id>/action_space/

    • Get information (name and dimensions/bounds) of the env's action_space
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
    • returns: info -- a dict containing 'name' (such as 'Discrete'), and additional dimensional info (such as 'n') which varies from space to space
  • GET /v1/envs/<instance_id>/observation_space/

    • Get information (name and dimensions/bounds) of the env's observation_space
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
    • returns: info -- a dict containing 'name' (such as 'Discrete'), and additional dimensional info (such as 'n') which varies from space to space
  • POST /v1/envs/<instance_id>/monitor/start/

    • Start monitoring
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
    • param: force (default=False) -- Clear out existing training data from this directory (by deleting every file prefixed with "openaigym.")
    • param: resume (default=False) -- Retain the training data already in this directory, which will be merged with our new data
    • (NOTE: the video_callable parameter from the native env.monitor.start function is NOT implemented)
  • POST /v1/envs/<instance_id>/monitor/close/

    • Flush all monitor data to disk
    • param: instance_id -- a short identifier (such as '3c657dbc') for the environment instance
  • POST /v1/upload/

    • Flush all monitor data to disk
    • param: training_dir -- A directory containing the results of a training run.
    • param: api_key -- Your OpenAI API key
    • param: algorithm_id (default=None) -- An arbitrary string indicating the paricular version of the algorithm (including choices of parameters) you are running.
  • POST /v1/shutdown/

    • Request a server shutdown
    • Currently used by the integration tests to repeatedly create and destroy fresh copies of the server running in a separate thread

Contributors

  • Catherine Olsson
  • Jie Tang
  • Greg Brockman
  • Paul Hendricks
  • Flavio Truzzi
  • Oleg Klimov
  • Jess Smith
  • Kory Mathewson
  • Leonardo Araujo dos Santos
  • Paul Anton
  • Ruben Fiszel
  • Niven Achenjang
  • David Savage
  • Matthias Richard

gym-http-api's People

Contributors

appoll avatar benkant avatar catherio avatar davemssavage avatar gdb avatar jbarnold avatar korymath avatar leonardoaraujosantos avatar lucsanszky avatar matthiasrms avatar nivent avatar olegklimov avatar paulhendricks avatar smithjessk avatar

Watchers

 avatar

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.