Title: | Provides Access to the OpenAI Gym API |
---|---|
Description: | OpenAI Gym is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This is a wrapper for the OpenAI Gym API, and enables access to an ever-growing variety of environments. For more details on OpenAI Gym, please see here: <https://github.com/openai/gym>. For more details on the OpenAI Gym API specification, please see here: <https://github.com/openai/gym-http-api>. |
Authors: | Paul Hendricks [aut, cre] |
Maintainer: | Paul Hendricks <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-26 02:50:45 UTC |
Source: | https://github.com/paulhendricks/gym-r |
This function instantiates a GymClient instance to integrate with an OpenAI Gym server.
create_GymClient(remote_base)
create_GymClient(remote_base)
remote_base |
The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000". |
An instance of class "GymClient"; this object has "remote_base" as an attribute.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) ## End(Not run)
Evaluate whether an action is a member of an environments's action space.
env_action_space_contains(x, instance_id, action)
env_action_space_contains(x, instance_id, action)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
action |
An action to take in the environment. |
A boolean atomic vector of length one indicating if the action is a member of an environments's action space.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) action <- env_action_space_sample(client, instance_id) env_action_space_contains(client, instance_id, action) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) action <- env_action_space_sample(client, instance_id) env_action_space_contains(client, instance_id, action) ## End(Not run)
Get information (name and dimensions/bounds) of the environments's action space.
env_action_space_info(x, instance_id)
env_action_space_info(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_action_space_info(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_action_space_info(client, instance_id) ## End(Not run)
Sample an action from the environments's action space.
env_action_space_sample(x, instance_id)
env_action_space_sample(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
An action sampled from a space (such as "Discrete"), which varies from space to space.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_action_space_sample(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_action_space_sample(client, instance_id) ## End(Not run)
Flush all monitor data to disk.
env_close(x, instance_id)
env_close(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
NULL.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_close(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_close(client, instance_id) ## End(Not run)
Create an instance of the specified environment.
env_create(x, env_id)
env_create(x, env_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
env_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. |
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.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" env_create(client, env_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" env_create(client, env_id) ## End(Not run)
List all environments running on the server.
env_list_all(x)
env_list_all(x)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
A list mapping instance_id to env_id e.g. list("3c657dbc" = "CartPole-v0")
for every env on the server.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_list_all(client) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_list_all(client) ## End(Not run)
Flush all monitor data to disk.
env_monitor_close(x, instance_id)
env_monitor_close(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
NULL.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_monitor_close(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_monitor_close(client, instance_id) ## End(Not run)
Start monitoring.
env_monitor_start(x, instance_id, directory, force = FALSE, resume = FALSE)
env_monitor_start(x, instance_id, directory, force = FALSE, resume = FALSE)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
directory |
The directory to write the training data to. Defaults to FALSE. |
force |
Clear out existing training data from this directory (by deleting every file prefixed with "openaigym"). Defaults to NULL. |
resume |
Retain the training data already in this directory, which will be merged with our new data. Defaults to FALSE. |
NULL.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) outdir <- "/tmp/random-agent-results" env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) outdir <- "/tmp/random-agent-results" env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) ## End(Not run)
Get information (name and dimensions/bounds) of the environment's observation space.
env_observation_space_info(x, instance_id)
env_observation_space_info(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_observation_space_info(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_observation_space_info(client, instance_id) ## End(Not run)
Reset the state of the environment and return an initial observation.
env_reset(x, instance_id)
env_reset(x, instance_id)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
The initial observation of the space.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_reset(client, instance_id) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) env_reset(client, instance_id) ## End(Not run)
Step though an environment using an action.
env_step(x, instance_id, action, render = FALSE)
env_step(x, instance_id, action, render = FALSE)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
instance_id |
A short identifier (such as "3c657dbc") for the environment instance. |
action |
An action to take in the environment. |
render |
Whether to render the environment. Defaults to FALSE. |
A list consisting of the following: action; an action to take in the environment, observation; an agent's observation of the current environment, reward; the amount of reward returned after previous action, done; whether the episode has ended, and info; a list containing auxiliary diagnostic information.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) action <- env_action_space_sample(client, instance_id) env_step(client, instance_id, action) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) env_id <- "CartPole-v0" instance_id <- env_create(client, env_id) action <- env_action_space_sample(client, instance_id) env_step(client, instance_id, action) ## End(Not run)
Submit a GET request to an OpenAI Gym server.
get_request(x, route, data = NULL)
get_request(x, route, data = NULL)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
route |
The URL path or endpoint. |
data |
URL query arguments. Default value is NULL. |
If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) route <- "/v1/envs/" get_request(client, route) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) route <- "/v1/envs/" get_request(client, route) ## End(Not run)
This function instantiates a GymClient instance to integrate with an OpenAI Gym server.
GymClient(remote_base)
GymClient(remote_base)
remote_base |
The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000". |
An instance of class "GymClient"; this object has "remote_base" as an attribute.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- GymClient(remote_base) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- GymClient(remote_base) ## End(Not run)
Parse the server error or raise for status.
parse_server_error_or_raise_for_status(response)
parse_server_error_or_raise_for_status(response)
response |
A response object from |
If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.
## Not run: b2 <- "http://httpbin.org/post" response <- httr::POST(b2, body = "A simple text string") parse_server_error_or_raise_for_status(response) ## End(Not run)
## Not run: b2 <- "http://httpbin.org/post" response <- httr::POST(b2, body = "A simple text string") parse_server_error_or_raise_for_status(response) ## End(Not run)
Submit a POST request to an OpenAI Gym server.
post_request(x, route, data = NULL)
post_request(x, route, data = NULL)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
route |
The URL path or endpoint. |
data |
URL query arguments. Default value is NULL. |
If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) route <- "/v1/envs/" env_id <- "CartPole-v0" data <- list(env_id = env_id) post_request(client, route, data) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) route <- "/v1/envs/" env_id <- "CartPole-v0" data <- list(env_id = env_id) post_request(client, route, data) ## End(Not run)
Represent a GymClient instance on the command line.
## S3 method for class 'GymClient' print(x, ...)
## S3 method for class 'GymClient' print(x, ...)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
... |
Further arguments passed to or from other methods. |
x A GymClient instance.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) print(client) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) print(client) ## End(Not run)
A sample random discrete agent.
random_discrete_agent(n)
random_discrete_agent(n)
n |
The number of discrete action spaces available. |
NULL.
agent <- random_discrete_agent(10)
agent <- random_discrete_agent(10)
Request a server shutdown.
shutdown_server(x)
shutdown_server(x)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
NULL Currently used by the integration tests to repeatedly create and destroy fresh copies of the server running in a separate thread.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) shutdown_server(client) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) shutdown_server(client) ## End(Not run)
Flush all monitor data to disk.
upload(x, training_dir, api_key = NULL, algorithm_id = NULL)
upload(x, training_dir, api_key = NULL, algorithm_id = NULL)
x |
An instance of class "GymClient"; this object has "remote_base" as an attribute. |
training_dir |
A directory containing the results of a training run. |
api_key |
Your OpenAI API key. |
algorithm_id |
An arbitrary string indicating the paricular version of the algorithm (including choices of parameters) you are running. |
NULL.
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) outdir <- "/tmp/random-agent-results" upload(client, outdir) ## End(Not run)
## Not run: remote_base <- "http://127.0.0.1:5000" client <- create_GymClient(remote_base) outdir <- "/tmp/random-agent-results" upload(client, outdir) ## End(Not run)