Git Product home page Git Product logo

gym_tcp_api's Introduction

gym-tcp-api

This project provides a distributed infrastructure (TCP API) to the OpenAI Gym toolkit, allowing development in languages other than python.

The server is written in elixir, enabling a distributed infrastructure. Where each node makes use of a limitted set of processes that can be used to perform time consuming tasks (4 python instances per default).

Contents

  1. Dependencies
  2. Installation
  3. Getting started
  4. Demo
  5. Distributed Server
  6. API specification
  7. FAQ

Dependencies

The server has the following dependencies:

Python3
Elixir >= 1.0
OpenAI Gym.

The c++ example agent has the following dependencies:

  Armadillo     >= 4.200.0
  Boost (system, thread, iostreams)
  CMake         >= 2.8.5

Installation

Server

First, checkout the repo and change into the unpacked directory:

  $  git clone https://github.com/zoq/gym_tcp_api.git
  $  cd gym_tcp_api

Then install the elixir dependencies:

  $ mix deps.get

C++ Client

First, checkout the repo and change into the unpacked c++ client directory:

  $  git clone https://github.com/zoq/gym_tcp_api.git
  $  cd gym_tcp_api/cpp/

Then, make a build directory. The directory can have any name, not just 'build', but 'build' is sufficient.

  $ mkdir build
  $ cd build

The next step is to run CMake to configure the project. Running CMake is the equivalent to running ./configure with autotools

  $ cmake ../

Once CMake is configured, building the example agent is as simple as typing 'make'.

  $ make

Getting started

To start the server from the command line:

  • For Python server run:

     $ python python/server.py
    
  • For Elixir server run:

     $ iex -S mix
    

In a separate terminal, you can then run the example agent:

  $ ./example

Demo

The distributed demo server is reachable at kurg.org (port 4040) and can be used for testing. Each node provides access to the Classic control and Atari environments. Note that each node has limited resources so that the response time might vary. If you record your algorithm's performance on an environment you can access the video and metadata at https://kurg.org/media/gym/

breakout sample image sequence breakout sample image sequence breakout sample image sequence

Distributed Server

First, we need to find out the IP addresses of both machines. In this case, the IP address is 192.168.0.103 for the first machine. On the other machine, the IP address is 192.168.0.104.

In the first window:

 $ iex --name [email protected] --cookie "gym" -S mix

In the second window:

$ iex --name [email protected] --cookie "gym" -S mix

In the interactive shell of the second node type:

$ Node.connect :'[email protected]'

API specification

We use JSON as the format to cimmunicate with the server.

Create the specified environment:

{"env" {"name": "CartPole-v0"}}

Close the environment:

{"env" {"action": "close"}}

Reset the state of the environment:

{"env" {"action": "reset"}}

Set the enviroment seed:

{"env" {"seed": "3"}}

Get the action space information:

{"env" {"action": "actionspace"}}

Get observation space information:

{"env" {"action": "observationspace"}}

Get action space sample:

{"env" {"actionspace": "sample"}}

Step though an environment using an action:

{"step" {"action": "1"}}

{"step" {"action": "[0, 1, 0, 0]"}}

Start the record episode statistics:

{"record_episode_stats" {"action": "start"}}

FAQ

1. In the Erlang/OTP 21, erlport may not be compiled, because the latest version was not reflected in the official Erlport GitHub.

  • SOL) Change the version of erlport manually in mix.exs. As of October, 2018, the "0.10.0" version worked. See this https://github.com/hdima/erlport
    defp deps do
        [
          {:erlport, "~> 0.10.0"}, # Choose the version.
          {:poolboy, "~> 1.5"}
        ]
    end
    

2. Failed to fetch record for 'hexpm/poolboy' from registry (using cache)

  • SOL) This was a cache problem, remove the cache file and try again.
    rm "~/.hex/cache.ets"

3. TypeError: super() takes at least 1 argument (0 given) super().init((), np.int64)

  • SOL 1) Using Python3 VirtualEnv (Recommended).

    $ virtualenv -p python3 envname
    
  • SOL 2) Make Python3 as the default Python (since gym is built on Python3).

    $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
    

gym_tcp_api's People

Contributors

ali-hossam avatar dnabanita7 avatar kimsangyeon-dgu avatar lpmi-13 avatar mulx10 avatar nishantkr18 avatar shrit avatar trion129 avatar zoq 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

Watchers

 avatar  avatar  avatar  avatar  avatar

gym_tcp_api's Issues

Error running example

I am using ubuntu 14.04.
The installation of the server went fine. It was listening on port 4040.
But when running ./example from build directory.
terminate called after throwing an instance of 'boost::system::system_error'
what(): Connection refused
netstat output:
Aborted (core dumped)
tcp 0 0 0.0.0.0:4040 0.0.0.0:* LISTEN 6623/beam.smp

Can not start the server

I follow the Installation instruction to try to run the example. The terminal outputs that:

Erlang/OTP 21 [erts-10.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

escript: exception error: no match of right hand side value undefined
  in function  rebar_log:log/3 (/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_log.erl, line 96)
  in call from rebar3:handle_error/2 (/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar3.erl, line 317)
  in call from escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1 
  in call from init:do_boot/3 
** (Mix) Could not compile dependency :erlport, "/Users/username/.mix/rebar3 bare compile --paths "/Users/username/clone/boost/gym_tcp_api/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile erlport", update it with "mix deps.update erlport" or clean it with "mix deps.clean erlport"
  1. I try the suggestion like 'mix deps.compile erlport', 'mix deps.update erlport' etc, it get the same error.
  2. I search the output from Google, I am not familar with mix much, so didn't get too much useful information about it.

Can you kindly help to go through it?

gym/wrappers has removed "Monitors" and are using "RecordEpisodicStatistics"

I got this error while running README.md.
Stack Trace:

iex(1)> 
13:34:16.528 [error] GenServer #PID<0.199.0> terminating
** (stop) {:python, :"builtins.ImportError", 'cannot import name \'Monitor\' from \'gym.wrappers\' (/home/naba/anaconda3/lib/python3.9/site-packages/gym/wrappers/__init__.py)', {:"$erlport.opaque", :python, <<128, 2, 99, 116, 114, 97, 99, 101, 98, 97, 99, 107, 10, 83, 116, 97, 99, 107, 83, 117, 109, 109, 97, 114, 121, 10, 113, 0, 41, 129, 113, 1, 40, 99, 116, 114, 97, 99, 101, 98, 97, 99, 107, ...>>}}
    /home/naba/dev/gym_tcp_api/deps/erlport/src/erlport.erl:234: :[erlport.call/3](http://erlport.call/3)
    (gym_tcp_api 0.1.0) lib/worker.ex:25: GymTcpApi.Worker.handle_call/3
    (stdlib 3.14) gen_server.erl:715: :gen_server.try_handle_call/4
    (stdlib 3.14) gen_server.erl:744: :gen_server.handle_msg/6
    (stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.208.0>): {"{\"env\":{\"name\": \"CartPole-v0\"}}\r\n", #PID<0.207.0>}
State: #PID<0.200.0>
Client #PID<0.208.0> is alive

This states that we can no longer use monitor.hpp. We need to have something similar to RecordEpisodeStatistics.
This issue is helpful.

Import Error 'Cannot import name Monitor'.

Hi @zoq.
I guess the OpenAI gym's interface has been changed. So I downgraded the Gym version to 0.9.5 and It works correctly. (I checked both 0.9.5 and 0.7.4 work correctly.)

pip install gym==0.9.5

mountain_car

kurg.org (port 4040) unreachable

I am trying to run some demo client but the code always throws with no connection to the server.

Is the demo server still running?

mix deps.get error

Hi, I want to use openai gym, but as you know, It provides only python version.

I have searched method to run other languages, more specifically c++ and found this repository.

First of all, thank you for making this.

However, in the middle of installing this program, an error did occur.

I typed mix deps.get in gym_tcp_api directory but below error message did occur.

Failed to fetch record for 'hexpm/poolboy' from registry (using cache)
{:failed_connect, [{:to_address, {'localhost', 4001}}, {:inet, [:inet], :econnrefused}]}
** (Mix) Unknown package poolboy in lockfile

Aborted (core dumped)

Hi, in the middle of connecting from client to server, An error did occur.

According to README.md file, I installed the program correctly.

So, I ran server using command line "iex -S mix"

Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help)

14:51:45.660 [info]  Accepting connections on port 4040
iex(1)> 

And then I ran the client program using command line "./example"
but blew error message was printed...

terminate called after throwing an instance of 'boost::system::system_error'
  what():  Connection refused
Aborted (core dumped)

I don't know why the connection was refused.
I never edited the code and just followed the instruction in README.md

Thank you

Maintenance work for compatibility with the OpenAI gym's latest version.

This is related to #11. The OpenAI gym's interface has been changed since 0.9.5 version. So we have to adjust the code to be compatible with the latest version. You can find the previous and latest gym code in the GitHub. Actually, I thought I can work on this, but unfortunately I can't find time to do. So, if there is anyone who wants to contribute to this, please feel free. :)

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.