Giter VIP home page Giter VIP logo

gym-http-api's Introduction

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

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

See the [contributors page] (https://github.com/openai/gym-http-api/graphs/contributors)

gym-http-api's People

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  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-http-api's Issues

Need update

Can someone update this project for non-Python coder?
For example, support Python3.x, support newer gym version?

python gym_http_client.py

Traceback (most recent call last):
File "gym_http_client.py", line 22, in parse_server_error_or_raise_for_status
j = resp.json()
File "C:\Miniconda3\lib\site-packages\requests\models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Miniconda3\lib\json_init
.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Miniconda3\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Miniconda3\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "gym_http_client.py", line 154, in
obs_info = client.env_observation_space_info(instance_id)
File "gym_http_client.py", line 95, in env_observation_space_info
resp = self._get_request(route)
File "gym_http_client.py", line 44, in _get_request
return self._parse_server_error_or_raise_for_status(resp)
File "gym_http_client.py", line 27, in _parse_server_error_or_raise_for_status
resp.raise_for_status()
File "C:\Miniconda3\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://127.0.0.1:5000/v1/envs/da42e4bc/observation_space/

TypeError: array([-0.83140989]) is not JSON serializable

File "gym_http_server.py", line 282, in env_action_space_sample
return jsonify(action = action)

Error thrown if the action space is an array, need to convert to list.

Fixed with the following code, which is actually in the gym_http_server.py but was overwritten on a recent push:

    def get_action_space_sample(self, instance_id):
        env = self._lookup_env(instance_id)
        action = env.action_space.sample()
        if isinstance(action, (list, tuple)) or ('numpy' in str(type(action))):
            try:
                action = action.tolist()
            except TypeError:
                print(type(action))
                print('TypeError')
        return action

Fixed with 1b42f25

On God

1693990221935.jpg
Can you buy this chicken for $2000

Launching server and client as described in the quickstart fail

 python2 gym_http_server.py                 
[2016-08-10 13:26:44,003] Making new env: CartPole-v0              
[2016-08-10 13:26:44,016] Creating monitor directory /tmp/random-agent-results
[2016-08-10 13:26:44,019] Starting new video recorder writing to /tmp/random-agent-results/openaigym.video.0.1490.video000000.mp4
[2016-08-10 13:26:44,378] ERROR in app: Exception on /v1/envs/2e1c7bd7/reset/ [POST]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 193, in env_reset
    observation = envs.reset(instance_id)
  File "gym_http_server.py", line 54, in reset
    obs = env.reset()
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 124, in reset
    self.monitor._after_reset(observation)
  File "/usr/lib/python2.7/site-packages/gym/monitoring/monitor.py", line 248, in _after_reset
    self.video_recorder.capture_frame()
  File "/usr/lib/python2.7/site-packages/gym/monitoring/video_recorder.py", line 105, in capture_frame
    frame = self.env.render(mode=render_mode)
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 175, in render
    return self._render(mode=mode, close=close)
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/cartpole.py", line 141, in _render
    return self.viewer.get_array()
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/rendering.py", line 107, in get_array
    arr = arr.reshape(self.height, self.width, 4)
ValueError: total size of new array must be unchanged
[2016-08-10 13:26:44,378] Exception on /v1/envs/2e1c7bd7/reset/ [POST]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 193, in env_reset
    observation = envs.reset(instance_id)
  File "gym_http_server.py", line 54, in reset
    obs = env.reset()
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 124, in reset
    self.monitor._after_reset(observation)
  File "/usr/lib/python2.7/site-packages/gym/monitoring/monitor.py", line 248, in _after_reset
    self.video_recorder.capture_frame()
  File "/usr/lib/python2.7/site-packages/gym/monitoring/video_recorder.py", line 105, in capture_frame
    frame = self.env.render(mode=render_mode)
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 175, in render
    return self._render(mode=mode, close=close)
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/cartpole.py", line 141, in _render
    return self.viewer.get_array()
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/rendering.py", line 107, in get_array
    arr = arr.reshape(self.height, self.width, 4)
ValueError: total size of new array must be unchanged
^C[2016-08-10 13:26:53,774] Finished writing results. You can upload them to the scoreboard via gym.upload(u'/tmp/random-agent-results')

Type Error: 4.8000002 is not JSON serializable

Minimal Scala code request

private val contentType = ContentTypes.`application/json` //Data Content Type

  def requestToApi(request: gymApi): HttpResponse = {
  val url = "http://127.0.0.1" + ":" + 5000 + request.url
  val httpRequest = HttpRequest(uri = url).withMethod(request.method).withEntity(HttpEntity(contentType, """{}"""))
  val responseFuture: Future[HttpResponse] = Http().singleRequest(httpRequest)
  Await.result(responseFuture, timeout.second)
}

response match {
  case HttpResponse(StatusCodes.OK, headers, entity, _) => println(entity.toString())
}

Error:

  [2019-03-05 22:25:49,624] ERROR in app: Exception on /v1/envs/5d5aee73/observation_space/ [GET]
Traceback (most recent call last):
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 340, in env_observation_space_info
    return jsonify(info = info)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 266, in jsonify
    (dumps(data, indent=indent, separators=separators), '\n'),
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 126, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 83, in default
    return _json.JSONEncoder.default(self, o)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 4.8000002 is not JSON serializable

Any ideas what problem might be ?

Environments terminate after 200 steps. How to change this behaviour?

Using the latest gym version environments will terminate after 200 time steps. In python I can write

env = gym.make("MountainCar-v0").env to change this behaviour. See also: http://stackoverflow.com/questions/42787924/why-is-episode-done-after-200-time-steps-gym-environment-mountaincar

But how could I get this working using the gym API in R? In the example_agent.R I tried

env_id = "MountainCar-v0.env"
instance_id = env_create(client, env_id)

but this returns an error.

I meet a error

I start the gym_http_server,
when I run example_agent.py,I get the error message on server console

Server starting at: http://127.0.0.1:5000

  • Serving Flask app "gym_http_server" (lazy loading)
  • Environment: production
    WARNING: Do not use the development server in a production environment.
    Use a production WSGI server instead.
  • Debug mode: off
    �[33mWARN: gym.spaces.Box autodetected dtype as <type 'numpy.float32'>. Please provide explicit dtype.�[0m
    [2018-08-25 19:59:14,161] ERROR in app: Exception on /v1/envs/f8c9a1cd/step/ [POST]
    Traceback (most recent call last):
    File "C:\Anaconda2\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
    File "C:\Anaconda2\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File "C:\Anaconda2\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
    File "C:\Anaconda2\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
    File "C:\Anaconda2\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functionsrule.endpoint
    File "gym_http_server.py", line 258, in env_step
    [obs_jsonable, reward, done, info] = envs.step(instance_id, action, render)
    File "gym_http_server.py", line 71, in step
    env.render()
    File "C:\Anaconda2\lib\site-packages\gym\core.py", line 284, in render
    return self.env.render(mode)
    File "C:\Anaconda2\lib\site-packages\gym\core.py", line 284, in render
    return self.env.render(mode)
    File "C:\Anaconda2\lib\site-packages\gym\envs\classic_control\cartpole.py", line 137, in render
    return self.viewer.render(return_rgb_array = mode=='rgb_array')
    File "C:\Anaconda2\lib\site-packages\gym\envs\classic_control\rendering.py", line 82, in render
    glClearColor(1,1,1,1)
    File "C:\Anaconda2\lib\site-packages\pyglet\gl\lib.py", line 105, in errcheck
    raise GLException(msg)

Maintainer status?

Hey @catherio, thanks for all the work you've put into this. I'm wondering if you could tell me how actively OpenAI plans to maintain this repo. If you are all lacking dev-time maybe putting this project on TravisCI and adding a merge-bot, if a current contributor +1s the PR, could help speed things up? (Seeing as there are currently 13 language bindings, I'd guess that this repo requires more than the current number of developers to ensure stability, anyhow).

Fail to run 'HandManipulateBlock-v0'

Thanks for the nice api. I managed to run CartPole-v0 using python example_agent.py command. Now I need to run HandManipulateBlock-v0. But this environment is not available in gym 0.7.4 (specified in requirements.txt). So I changed the versions of numpy, gym and requests in requirements.txt to the following:
numpy==1.15.0,
gym==0.10.5,
requests==2.19.1
Now gym-http-api recognizes HandManipulateBlock-v0 environment. But when I try to run the environment using python example_agent.py, the execution halts with the followint exception:

Traceback (most recent call last):
File "/home/navid/gym-http-api/gym_http_client.py", line 22, in _parse_server_error_or_raise_for_status
j = resp.json()
File "/home/navid/my-gym-http-api/lib/python3.5/site-packages/requests/models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Could anyone give me some hint about how to fix this? Thanks.
Best regards,
Navid

TypeError: 0 is not JSON serializable

I'm using the gym API in R running the example_agent.R file.

When I use the CartPole-v0 environment this works fine, but then I try the "FrozenLake-v0" I get an error: Error: API did not return json when I run

for (i in 1:episode_count) { ob <- env_reset(client, instance_id) for (i in 1:max_steps) { action <- env_action_space_sample(client, instance_id) results <- env_step(client, instance_id, action, render = TRUE) if (results[["done"]]) break } }

and in my WinPython Command Prompt (Python 3.6.0.1Qt5) I get the following error:

TypeError: 0 is not JSON serializable

Hope, someone can help :)

Python client upload() bug

For the /v1/upload API, the request must have a training_dir key. However, the python client erroneously uses a key called directory instead:

data = {'directory': directory,
        'force': force,
        'resume': resume,
        'video_callable': video_callable}
self._post_request(route, data)

The upload() method was probably just never tested before.

Fixing this might save someone a bit of debugging time if they use the Python client as a guide for their own client.

errors in the matlab binding

Hello,
using ML ver 8.5 (R2015a), the required python packages in requirements.txt (python 2.7), there are errors in few calls:
(1) client.env_monitor_start(instance_id, outdir, true);
(2) client.env_monitor_close(instance_id);
(3) client.upload
(see bellow for details).
Could you please provide indications or update the code, also to work with the latest python packages.

I think there is some incompatibility with the "webwrite" matlab function; by now I "resolved" this with catching and ignoring the error in the outermost script (example_agent), and it seems to work, but I'm not sure this is a good solution.

Thanks, Ivilin

-- (1)
Error using readContentFromWebService (line 37)
The server returned the message: "NO CONTENT" for URL, 'http://127.0.0.1:5000/v1/envs/6ecaff44/monitor/start/' (with HTTP response code 204).
Error in webwrite (line 126)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in gym_http_client/post_request (line 25)
resp_data = webwrite(url, req_data, obj.webopt);
Error in gym_http_client/env_monitor_start (line 115)
obj.post_request(route, req_data);
Error in example_agent (line 21)
client.env_monitor_start(instance_id, outdir, true);

-- (2)
Error using readContentFromWebService (line 37)
The server returned the message: "NO CONTENT" for URL, 'http://127.0.0.1:5000/v1/envs/d8d7a341/monitor/close/' (with HTTP response code 204).
Error in webwrite (line 126)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in gym_http_client/post_request (line 25)
resp_data = webwrite(url, req_data, obj.webopt);
Error in gym_http_client/env_monitor_close (line 120)
obj.post_request(route, []);
Error in example_agent (line 46)
client.env_monitor_close(instance_id);

-- (3)
Error using readContentFromWebService (line 37)
The server returned the message: "BAD REQUEST" for URL, 'http://127.0.0.1:5000/v1/upload/' (with HTTP response code 400).
Error in webwrite (line 126)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in gym_http_client/post_request (line 25)
resp_data = webwrite(url, req_data, obj.webopt);
Error in gym_http_client/upload (line 141)
obj.post_request(route, req_data);
Error in example_agent (line 55)
client.upload(outdir);

Launching server and client as described in the quickstart fail

Step to reproduce:
python2 gym_http_server.py
and in another terminal
python2 gym_http_client.py
or
python2 example_agent.py

server terminal output:

[2016-07-02 19:05:15,513] Making new env: CartPole-v0
[2016-07-02 19:05:15,527] Creating monitor directory /tmp/random-agent-results
[2016-07-02 19:05:15,530] Starting new video recorder writing to /tmp/random-agent-results/openaigym.video.0.17805.video000000.mp4
[2016-07-02 19:05:15,918] ERROR in app: Exception on /v1/envs/5bd5d0fb/reset/ [POST]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 189, in env_reset
    observation = envs.reset(instance_id)
  File "gym_http_server.py", line 54, in reset
    obs = env.reset()
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 124, in reset
    self.monitor._after_reset(observation)
  File "/usr/lib/python2.7/site-packages/gym/monitoring/monitor.py", line 248, in _after_reset
    self.video_recorder.capture_frame()
  File "/usr/lib/python2.7/site-packages/gym/monitoring/video_recorder.py", line 105, in capture_frame
    frame = self.env.render(mode=render_mode)
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 175, in render
    return self._render(mode=mode, close=close)
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/cartpole.py", line 141, in _render
    return self.viewer.get_array()
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/rendering.py", line 107, in get_array
    arr = arr.reshape(self.height, self.width, 4)
ValueError: total size of new array must be unchanged
[2016-07-02 19:05:15,918] Exception on /v1/envs/5bd5d0fb/reset/ [POST]
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 189, in env_reset
    observation = envs.reset(instance_id)
  File "gym_http_server.py", line 54, in reset
    obs = env.reset()
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 124, in reset
    self.monitor._after_reset(observation)
  File "/usr/lib/python2.7/site-packages/gym/monitoring/monitor.py", line 248, in _after_reset
    self.video_recorder.capture_frame()
  File "/usr/lib/python2.7/site-packages/gym/monitoring/video_recorder.py", line 105, in capture_frame
    frame = self.env.render(mode=render_mode)
  File "/usr/lib/python2.7/site-packages/gym/core.py", line 175, in render
    return self._render(mode=mode, close=close)
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/cartpole.py", line 141, in _render
    return self.viewer.get_array()
  File "/usr/lib/python2.7/site-packages/gym/envs/classic_control/rendering.py", line 107, in get_array
    arr = arr.reshape(self.height, self.width, 4)
ValueError: total size of new array must be unchanged
^C[2016-07-02 19:05:22,624] Finished writing results. You can upload them to the scoreboard via gym.upload(u'/tmp/random-agent-results')

" Implement 'sample' (and test it) "

I only have to check that my understanding of the task is correct before submitting a pull request.
As far as I can see, the picking of a random action from the action space is done by the example agent and that shouldn't be the case. Instead, this should be done on the "server side" by actually using the sample() method available in the action space of the specific environment, assuming the additional endpoint is provided.

Enhancement: measure latency/performance

Measure latency/performance. How slow is HTTP, Flask? Under what use patterns is HTTP sufficiently performative, and under what use patterns would a user want a faster implementation, for example using ZeroMQ or similar?

get_action_space_info not complete

The function get_action_space_info does not return the action space when the action space contains a Tuple. It will just return {'name': 'Tuple'}. Tested on Copy-v0.

Translate TODOs into issues

@catherio: Can you shed some light on which of these might be outstanding? If we can translate some of these into issues and sort them, myself and other community members might be able to start to tackle them.

Looks done (confirmation would be helpful)

  • Implement 'sample' (and test it)
  • Implement 'contains' (and test it)

TODO

  • Make the directory structure better conform to standard python package structures (http://www.kennethreitz.org/essays/repository-structure-and-python, http://peterdowns.com/posts/first-time-with-pypi.html)
  • Docker integration
  • Handle ResetNeeded while monitor is active
  • Handle APIConnectionError: Unexpected error communicating with OpenAI Gym
  • Check: was anything improved by adding session / socket reuse?
  • Reports of "broken pipe" errors: reproduce and investigate
  • Measure latency/performance. How slow is HTTP, Flask? What is the use case for this implementation, versus a potential future faster ZeroMQ implementation?
  • Make remote environments have the same interface as non-remote environments
  • Get Travis CI working
  • Test all possible environments in integration tests
  • Handle the error thrown if the directory isn't cleared for the monitor
  • Document the fact that two-monitors-open will cause a problem; be clear that this is meant to be one-client

MIT License?

Can you confirm that the code in this repository is under the MIT license like the gym repo?

A commit of a LICENSE file would be great.

Thanks!

Atari render graphics issue

Hey GUYS,

I am trying to render atari game the video game has some issues with the graphics, On classic control are pretty nice I have a problem only with atari does anyone knows why?

gym_http_server py_001

gym_http_server py_002

TypeError: Object of type float32 is not JSON serializable

I get the following error while running a custom made environment or any predefined environment like CartPole-v0 (I am trying to use the CPP binding, but also I get a similar error with "python example_agent.py"):-

./test1

ERROR: bad HTTP response code, and also cannot parse server message:

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

python gym_http_server.py

Server starting at: http://127.0.0.1:5000
[2021-01-21 15:31:17,337] ERROR in app: Exception on /v1/envs/ff0e588b/action_space/ [GET]
Traceback (most recent call last):
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "gym_http_server.py", line 278, in env_action_space_info
return jsonify(info = info)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 266, in jsonify
(dumps(data, indent=indent, separators=separators), '\n'),
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 126, in dumps
rv = _json.dumps(obj, **kwargs)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 83, in default
return _json.JSONEncoder.default(self, o)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type float32 is not JSON serializable

Kindly help me understand the problem and how to solve it.

I have -
Flask 0.11.1
Flask-Compress 1.4.0
Flask-SocketIO 2.9.6
gym 0.12.4
numpy 1.16.3
pip 19.1.1
pytest 6.2.1
requests 2.25.0

AttributeError: module 'gym.wrappers' has no attribute 'Monitor'

I have recently been getting the following error. I am pretty sure that the gym changed the monitoring interface of late, however, I've also been changing workstations, so I'm not sure if this is a bug or if I installed things incorrectly.

The error:

[2017-03-02 15:36:32,956] Exception on /v1/envs/be06fa08/monitor/start/ [POST]
Traceback (most recent call last):
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/stites/.pyenv/versions/gym-http-api/lib/python3.6/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 337, in env_monitor_start
    envs.monitor_start(instance_id, directory, force, resume, video_callable)
  File "gym_http_server.py", line 126, in monitor_start
    self.envs[instance_id] = wrappers.Monitor(env, directory, force=force, resume=resume, video_callable=v_c)
AttributeError: module 'gym.wrappers' has no attribute 'Monitor'

and here's my pip freeze with python 3.6.0:

appdirs==1.4.2
click==6.7
Flask==0.11.1
gym==0.1.7
itsdangerous==0.24
Jinja2==2.9.5
MarkupSafe==0.23
nose2==0.6.5
numpy==1.11.1rc1
packaging==16.8
pyglet==1.2.4
pyparsing==2.1.10
requests==2.11.0
six==1.10.0
Werkzeug==0.11.15

Tuple Spaces do not convert to json properly

Hi. Thanks for making gym available to other languages. I'm currently seeing an error when trying to reset the Blackjack-v0 environment. Here's a reproducible example using curl

# start the server
python gym_http_server.py

# create blackjack instance
curl -d '{"env_id":"Blackjack-v0"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:5000/v1/envs/

# reset instance
curl -X POST http://127.0.0.1:5000/v1/envs/<instance_id>/reset/

The issue I believe is caused when calling env.observation_space.to_jsonable(obs) in reset(). The to_jsonable method expects a list of tuples for Blackjack, not a single tuple.

My current workaround is to check to see if the observation is a tuple and if so, wrap it a list first. This works fine for Blackjack but I haven't tested the other environments.

def reset(self, instance_id):
    env = self._lookup_env(instance_id)
    obs = env.reset()
    if (isinstance(obs, tuple)):
        obs = [obs]
    return env.observation_space.to_jsonable(obs)

Update Rust Dependencies

On linux systems that are using openssl-1.1, compiling the Rust bindings with the dependency versions in Cargo.toml will fail because the hyper version pulls in an old version of openssl bindings that's incompatible with openssl-1.1.

C++-Bindings - Example does not run

After installing all the prerequisites and trying to run the random_agent.cpp in
cpp bindings, it threw an Error, saying it cannot convert a certain value to float.
Changing from Breakout-v0 to CartPole-v0 made it work for the time being.

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.