├── gym ├── LICENSE ├── .gitignore ├── tests │ ├── testthat.R │ └── testthat │ │ ├── test-api.R │ │ ├── test-utils.R │ │ └── test-agents.R ├── R │ ├── gym.R │ ├── agents.R │ ├── utils.R │ └── api.R ├── .Rbuildignore ├── cran-comments.md ├── man │ ├── gym.Rd │ ├── random_discrete_agent.Rd │ ├── GymClient.Rd │ ├── env_list_all.Rd │ ├── shutdown_server.Rd │ ├── create_GymClient.Rd │ ├── print.GymClient.Rd │ ├── env_close.Rd │ ├── env_monitor_close.Rd │ ├── parse_server_error_or_raise_for_status.Rd │ ├── get_request.Rd │ ├── env_reset.Rd │ ├── upload.Rd │ ├── post_request.Rd │ ├── env_action_space_sample.Rd │ ├── env_create.Rd │ ├── env_action_space_info.Rd │ ├── env_observation_space_info.Rd │ ├── env_action_space_contains.Rd │ ├── env_monitor_start.Rd │ └── env_step.Rd ├── .travis.yml ├── NEWS.md ├── NAMESPACE ├── DESCRIPTION ├── appveyor.yml ├── README.md └── README.Rmd ├── docs ├── LICENSE ├── link.svg ├── pkgdown.js ├── jquery.sticky-kit.min.js ├── pkgdown.css ├── LICENSE.html ├── authors.html ├── reference │ ├── gym.html │ ├── random_discrete_agent.html │ ├── GymClient.html │ ├── create_GymClient.html │ ├── shutdown_server.html │ ├── env_list_all.html │ ├── print.GymClient.html │ ├── env_close.html │ ├── parse_server_error_or_raise_for_status.html │ ├── env_monitor_close.html │ ├── get_request.html │ ├── env_create.html │ ├── env_reset.html │ ├── env_action_space_sample.html │ ├── upload.html │ ├── env_action_space_info.html │ ├── env_observation_space_info.html │ ├── post_request.html │ ├── env_action_space_contains.html │ ├── env_step.html │ ├── env_monitor_start.html │ └── index.html ├── news │ └── index.html └── index.html ├── .gitignore ├── example_agent.R └── README.md /gym/LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016 2 | COPYRIGHT HOLDER: Paul Hendricks 3 | -------------------------------------------------------------------------------- /docs/LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2016 2 | COPYRIGHT HOLDER: Paul Hendricks 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | **/.DS_Store 6 | -------------------------------------------------------------------------------- /gym/.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | gym.Rproj 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /gym/tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(gym) 3 | 4 | test_check("gym") 5 | -------------------------------------------------------------------------------- /gym/R/gym.R: -------------------------------------------------------------------------------- 1 | #' gym: Provides Access to the OpenAI Gym API 2 | #' 3 | #' @docType package 4 | #' @name gym 5 | NULL 6 | -------------------------------------------------------------------------------- /gym/tests/testthat/test-api.R: -------------------------------------------------------------------------------- 1 | library(gym) 2 | context("api") 3 | 4 | test_that("Test api.", { 5 | expect_equal(1, 1) 6 | }) 7 | -------------------------------------------------------------------------------- /gym/tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | library(gym) 2 | context("utils") 3 | 4 | test_that("Test utils.", { 5 | expect_equal(1, 1) 6 | }) 7 | -------------------------------------------------------------------------------- /gym/tests/testthat/test-agents.R: -------------------------------------------------------------------------------- 1 | library(gym) 2 | context("agents") 3 | 4 | test_that("Test agents.", { 5 | expect_equal(1, 1) 6 | }) 7 | -------------------------------------------------------------------------------- /gym/.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^appveyor\.yml$ 5 | ^NEWS\.md$ 6 | ^cran-comments\.md$ 7 | ^README\.Rmd$ 8 | ^\./docs$ 9 | -------------------------------------------------------------------------------- /gym/cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * local OS X install, R 3.3.1 3 | * ubuntu 12.04 (on travis-ci), R 3.3.1 4 | * win-builder (devel and release) 5 | 6 | ## R CMD check results 7 | There were no ERRORs, WARNINGs, or NOTEs. 8 | -------------------------------------------------------------------------------- /gym/R/agents.R: -------------------------------------------------------------------------------- 1 | #' A sample random discrete agent. 2 | #' 3 | #' @param n The number of discrete action spaces available. 4 | #' @return NULL. 5 | #' @examples 6 | #' agent <- random_discrete_agent(10) 7 | #' @export 8 | random_discrete_agent <- function(n) { 9 | invisible() 10 | } 11 | -------------------------------------------------------------------------------- /gym/man/gym.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gym.R 3 | \docType{package} 4 | \name{gym} 5 | \alias{gym} 6 | \alias{gym-package} 7 | \title{gym: Provides Access to the OpenAI Gym API} 8 | \description{ 9 | gym: Provides Access to the OpenAI Gym API 10 | } 11 | 12 | -------------------------------------------------------------------------------- /gym/.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | 3 | # Be strict when checking our package 4 | warnings_are_errors: true 5 | 6 | # Sudo is required 7 | sudo: required 8 | 9 | # System dependencies for HTTP calling 10 | apt_packages: 11 | - libcurl4-openssl-dev 12 | - libxml2-dev 13 | 14 | r_binary_packages: 15 | - testthat 16 | 17 | r_github_packages: 18 | - jimhester/covr 19 | - jimhester/lintr 20 | 21 | after_success: 22 | - Rscript -e 'covr::codecov()' 23 | - Rscript -e 'lintr::lint_package()' 24 | -------------------------------------------------------------------------------- /gym/NEWS.md: -------------------------------------------------------------------------------- 1 | # gym 0.1.1 2 | 3 | ## Improvements 4 | 5 | * Improved documentation. 6 | * Added unit tests. 7 | * Added a `GymClient` function to create instances of the class `GymClient` e.g. `client = GymClient(remote_base)`. 8 | * Added Travis CI, Appevyor, and Codecov to ensure code quality. 9 | 10 | ## Bug fixes 11 | 12 | * None. 13 | 14 | # gym 0.1.0 15 | 16 | ## Improvements 17 | 18 | * `gym` provides access to current version of OpenAI Gym API. 19 | 20 | ## Bug fixes 21 | 22 | * None. 23 | -------------------------------------------------------------------------------- /gym/man/random_discrete_agent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agents.R 3 | \name{random_discrete_agent} 4 | \alias{random_discrete_agent} 5 | \title{A sample random discrete agent.} 6 | \usage{ 7 | random_discrete_agent(n) 8 | } 9 | \arguments{ 10 | \item{n}{The number of discrete action spaces available.} 11 | } 12 | \value{ 13 | NULL. 14 | } 15 | \description{ 16 | A sample random discrete agent. 17 | } 18 | \examples{ 19 | agent <- random_discrete_agent(10) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /gym/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,GymClient) 4 | export(GymClient) 5 | export(create_GymClient) 6 | export(env_action_space_contains) 7 | export(env_action_space_info) 8 | export(env_action_space_sample) 9 | export(env_close) 10 | export(env_create) 11 | export(env_list_all) 12 | export(env_monitor_close) 13 | export(env_monitor_start) 14 | export(env_observation_space_info) 15 | export(env_reset) 16 | export(env_step) 17 | export(get_request) 18 | export(parse_server_error_or_raise_for_status) 19 | export(post_request) 20 | export(random_discrete_agent) 21 | export(shutdown_server) 22 | export(upload) 23 | -------------------------------------------------------------------------------- /gym/man/GymClient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{GymClient} 4 | \alias{GymClient} 5 | \title{Create a GymClient instance.} 6 | \usage{ 7 | GymClient(remote_base) 8 | } 9 | \arguments{ 10 | \item{remote_base}{The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000".} 11 | } 12 | \value{ 13 | An instance of class "GymClient"; this object has "remote_base" as an attribute. 14 | } 15 | \description{ 16 | This function instantiates a GymClient instance to integrate with an OpenAI Gym server. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | remote_base <- "http://127.0.0.1:5000" 21 | client <- GymClient(remote_base) 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /gym/man/env_list_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_list_all} 4 | \alias{env_list_all} 5 | \title{List all environments running on the server.} 6 | \usage{ 7 | env_list_all(x) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | } 12 | \value{ 13 | A list mapping instance_id to env_id e.g. \code{list("3c657dbc" = "CartPole-v0")} for every env on the server. 14 | } 15 | \description{ 16 | List all environments running on the server. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | remote_base <- "http://127.0.0.1:5000" 21 | client <- create_GymClient(remote_base) 22 | env_list_all(client) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /gym/man/shutdown_server.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{shutdown_server} 4 | \alias{shutdown_server} 5 | \title{Request a server shutdown.} 6 | \usage{ 7 | shutdown_server(x) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | } 12 | \value{ 13 | NULL Currently used by the integration tests to repeatedly create and destroy fresh copies of the server running in a separate thread. 14 | } 15 | \description{ 16 | Request a server shutdown. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | remote_base <- "http://127.0.0.1:5000" 21 | client <- create_GymClient(remote_base) 22 | shutdown_server(client) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /gym/man/create_GymClient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{create_GymClient} 4 | \alias{create_GymClient} 5 | \title{Create a GymClient instance.} 6 | \usage{ 7 | create_GymClient(remote_base) 8 | } 9 | \arguments{ 10 | \item{remote_base}{The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000".} 11 | } 12 | \value{ 13 | An instance of class "GymClient"; this object has "remote_base" as an attribute. 14 | } 15 | \description{ 16 | This function instantiates a GymClient instance to integrate with an OpenAI Gym server. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | remote_base <- "http://127.0.0.1:5000" 21 | client <- create_GymClient(remote_base) 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /gym/man/print.GymClient.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{print.GymClient} 4 | \alias{print.GymClient} 5 | \title{Represent a GymClient instance on the command line.} 6 | \usage{ 7 | \method{print}{GymClient}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{...}{Further arguments passed to or from other methods.} 13 | } 14 | \value{ 15 | x A GymClient instance. 16 | } 17 | \description{ 18 | Represent a GymClient instance on the command line. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | print(client) 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /gym/man/env_close.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_close} 4 | \alias{env_close} 5 | \title{Flush all monitor data to disk.} 6 | \usage{ 7 | env_close(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | NULL. 16 | } 17 | \description{ 18 | Flush all monitor data to disk. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_close(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gym/man/env_monitor_close.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_monitor_close} 4 | \alias{env_monitor_close} 5 | \title{Flush all monitor data to disk.} 6 | \usage{ 7 | env_monitor_close(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | NULL. 16 | } 17 | \description{ 18 | Flush all monitor data to disk. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_monitor_close(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /gym/man/parse_server_error_or_raise_for_status.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{parse_server_error_or_raise_for_status} 4 | \alias{parse_server_error_or_raise_for_status} 5 | \title{Parse the server error or raise for status.} 6 | \usage{ 7 | parse_server_error_or_raise_for_status(response) 8 | } 9 | \arguments{ 10 | \item{response}{A response object from \code{httr::POST} or \code{httr::GET}.} 11 | } 12 | \value{ 13 | If the response code is 200 or 204, a parsed response. Else, a server error or raised exception. 14 | } 15 | \description{ 16 | Parse the server error or raise for status. 17 | } 18 | \examples{ 19 | \dontrun{ 20 | b2 <- "http://httpbin.org/post" 21 | response <- httr::POST(b2, body = "A simple text string") 22 | parse_server_error_or_raise_for_status(response) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /gym/man/get_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{get_request} 4 | \alias{get_request} 5 | \title{Submit a GET request to an OpenAI Gym server.} 6 | \usage{ 7 | get_request(x, route, data = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{route}{The URL path or endpoint.} 13 | 14 | \item{data}{URL query arguments. Default value is NULL.} 15 | } 16 | \value{ 17 | If the response code is 200 or 204, a parsed response. Else, a server error or raised exception. 18 | } 19 | \description{ 20 | Submit a GET request to an OpenAI Gym server. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | remote_base <- "http://127.0.0.1:5000" 25 | client <- create_GymClient(remote_base) 26 | route <- "/v1/envs/" 27 | get_request(client, route) 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /gym/man/env_reset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_reset} 4 | \alias{env_reset} 5 | \title{Reset the state of the environment and return an initial observation.} 6 | \usage{ 7 | env_reset(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | The initial observation of the space. 16 | } 17 | \description{ 18 | Reset the state of the environment and return an initial observation. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_reset(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gym/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: gym 2 | Version: 0.1.0 3 | Title: Provides Access to the OpenAI Gym API 4 | Description: OpenAI Gym is a open-source Python toolkit for developing and comparing 5 | reinforcement learning algorithms. This is a wrapper for the OpenAI Gym API, 6 | and enables access to an ever-growing variety of environments. 7 | For more details on OpenAI Gym, please see here: . 8 | For more details on the OpenAI Gym API specification, please see here: 9 | . 10 | Authors@R: person("Paul", "Hendricks", email = "paul.hendricks.2013@owu.edu", role = c("aut", "cre")) 11 | License: MIT + file LICENSE 12 | LazyData: true 13 | Depends: 14 | R (>= 3.3.1) 15 | Imports: 16 | httr, 17 | jsonlite 18 | URL: https://github.com/paulhendricks/gym-R 19 | BugReports: https://github.com/paulhendricks/gym-R/issues 20 | RoxygenNote: 5.0.1 21 | Suggests: testthat 22 | -------------------------------------------------------------------------------- /gym/man/upload.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{upload} 4 | \alias{upload} 5 | \title{Flush all monitor data to disk.} 6 | \usage{ 7 | upload(x, training_dir, api_key = NULL, algorithm_id = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{training_dir}{A directory containing the results of a training run.} 13 | 14 | \item{api_key}{Your OpenAI API key.} 15 | 16 | \item{algorithm_id}{An arbitrary string indicating the paricular version of the algorithm (including choices of parameters) you are running.} 17 | } 18 | \value{ 19 | NULL. 20 | } 21 | \description{ 22 | Flush all monitor data to disk. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | remote_base <- "http://127.0.0.1:5000" 27 | client <- create_GymClient(remote_base) 28 | outdir <- "/tmp/random-agent-results" 29 | upload(client, outdir) 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /gym/man/post_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{post_request} 4 | \alias{post_request} 5 | \title{Submit a POST request to an OpenAI Gym server.} 6 | \usage{ 7 | post_request(x, route, data = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{route}{The URL path or endpoint.} 13 | 14 | \item{data}{URL query arguments. Default value is NULL.} 15 | } 16 | \value{ 17 | If the response code is 200 or 204, a parsed response. Else, a server error or raised exception. 18 | } 19 | \description{ 20 | Submit a POST request to an OpenAI Gym server. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | remote_base <- "http://127.0.0.1:5000" 25 | client <- create_GymClient(remote_base) 26 | route <- "/v1/envs/" 27 | env_id <- "CartPole-v0" 28 | data <- list(env_id = env_id) 29 | post_request(client, route, data) 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /gym/appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | install: 10 | ps: Bootstrap 11 | 12 | # Adapt as necessary starting from here 13 | 14 | build_script: 15 | - travis-tool.sh install_deps 16 | 17 | test_script: 18 | - travis-tool.sh run_tests 19 | 20 | on_failure: 21 | - travis-tool.sh dump_logs 22 | 23 | artifacts: 24 | - path: '*.Rcheck\**\*.log' 25 | name: Logs 26 | 27 | - path: '*.Rcheck\**\*.out' 28 | name: Logs 29 | 30 | - path: '*.Rcheck\**\*.fail' 31 | name: Logs 32 | 33 | - path: '*.Rcheck\**\*.Rout' 34 | name: Logs 35 | 36 | - path: '\*_*.tar.gz' 37 | name: Bits 38 | 39 | - path: '\*_*.zip' 40 | name: Bits 41 | -------------------------------------------------------------------------------- /gym/man/env_action_space_sample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_action_space_sample} 4 | \alias{env_action_space_sample} 5 | \title{Sample an action from the environments's action space.} 6 | \usage{ 7 | env_action_space_sample(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | An action sampled from a space (such as "Discrete"), which varies from space to space. 16 | } 17 | \description{ 18 | Sample an action from the environments's action space. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_action_space_sample(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gym/man/env_create.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_create} 4 | \alias{env_create} 5 | \title{Create an instance of the specified environment.} 6 | \usage{ 7 | env_create(x, env_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{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.} 13 | } 14 | \value{ 15 | 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. 16 | } 17 | \description{ 18 | Create an instance of the specified environment. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | env_create(client, env_id) 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /gym/man/env_action_space_info.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_action_space_info} 4 | \alias{env_action_space_info} 5 | \title{Get information (name and dimensions/bounds) of the environments's action space.} 6 | \usage{ 7 | env_action_space_info(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space. 16 | } 17 | \description{ 18 | Get information (name and dimensions/bounds) of the environments's action space. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_action_space_info(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gym/man/env_observation_space_info.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_observation_space_info} 4 | \alias{env_observation_space_info} 5 | \title{Get information (name and dimensions/bounds) of the environment's observation space.} 6 | \usage{ 7 | env_observation_space_info(x, instance_id) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | } 14 | \value{ 15 | A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space. 16 | } 17 | \description{ 18 | Get information (name and dimensions/bounds) of the environment's observation space. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | remote_base <- "http://127.0.0.1:5000" 23 | client <- create_GymClient(remote_base) 24 | env_id <- "CartPole-v0" 25 | instance_id <- env_create(client, env_id) 26 | env_observation_space_info(client, instance_id) 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /example_agent.R: -------------------------------------------------------------------------------- 1 | library(gym) 2 | 3 | remote_base <- "http://127.0.0.1:5000" 4 | client <- create_GymClient(remote_base) 5 | print(client) 6 | 7 | # Create environment 8 | env_id <- "CartPole-v0" 9 | instance_id <- env_create(client, env_id) 10 | print(instance_id) 11 | 12 | # List all environments 13 | all_envs <- env_list_all(client) 14 | print(all_envs) 15 | 16 | # Set up agent 17 | action_space_info <- env_action_space_info(client, instance_id) 18 | print(action_space_info) 19 | agent <- random_discrete_agent(action_space_info[["n"]]) 20 | 21 | # Run experiment, with monitor 22 | outdir <- "/tmp/random-agent-results" 23 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 24 | 25 | episode_count <- 100 26 | max_steps <- 200 27 | reward <- 0 28 | done <- FALSE 29 | 30 | for (i in 1:episode_count) { 31 | ob <- env_reset(client, instance_id) 32 | for (i in 1:max_steps) { 33 | action <- env_action_space_sample(client, instance_id) 34 | results <- env_step(client, instance_id, action, render = TRUE) 35 | if (results[["done"]]) break 36 | } 37 | } 38 | 39 | # Dump result info to disk 40 | env_monitor_close(client, instance_id) 41 | -------------------------------------------------------------------------------- /gym/man/env_action_space_contains.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_action_space_contains} 4 | \alias{env_action_space_contains} 5 | \title{Evaluate whether an action is a member of an environments's action space.} 6 | \usage{ 7 | env_action_space_contains(x, instance_id, action) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | 14 | \item{action}{An action to take in the environment.} 15 | } 16 | \value{ 17 | A boolean atomic vector of length one indicating if the action is a member of an environments's action space. 18 | } 19 | \description{ 20 | Evaluate whether an action is a member of an environments's action space. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | remote_base <- "http://127.0.0.1:5000" 25 | client <- create_GymClient(remote_base) 26 | env_id <- "CartPole-v0" 27 | instance_id <- env_create(client, env_id) 28 | action <- env_action_space_sample(client, instance_id) 29 | env_action_space_contains(client, instance_id, action) 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | $("#sidebar").stick_in_parent({offset_top: 40}); 3 | $('body').scrollspy({ 4 | target: '#sidebar', 5 | offset: 60 6 | }); 7 | 8 | var cur_path = paths(location.pathname); 9 | $("#navbar ul li a").each(function(index, value) { 10 | if (value.text == "Home") 11 | return; 12 | if (value.getAttribute("href") === "#") 13 | return; 14 | 15 | var path = paths(value.pathname); 16 | if (is_prefix(cur_path, path)) { 17 | // Add class to parent
  • , and enclosing
  • if in dropdown 18 | var menu_anchor = $(value); 19 | menu_anchor.parent().addClass("active"); 20 | menu_anchor.closest("li.dropdown").addClass("active"); 21 | } 22 | }); 23 | }); 24 | 25 | function paths(pathname) { 26 | var pieces = pathname.split("/"); 27 | pieces.shift(); // always starts with / 28 | 29 | var end = pieces[pieces.length - 1]; 30 | if (end === "index.html" || end === "") 31 | pieces.pop(); 32 | return(pieces); 33 | } 34 | 35 | function is_prefix(needle, haystack) { 36 | if (needle.length > haystack.lengh) 37 | return(false); 38 | 39 | for (var i = 0; i < haystack.length; i++) { 40 | if (needle[i] != haystack[i]) 41 | return(false); 42 | } 43 | 44 | return(true); 45 | } 46 | -------------------------------------------------------------------------------- /gym/man/env_monitor_start.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_monitor_start} 4 | \alias{env_monitor_start} 5 | \title{Start monitoring.} 6 | \usage{ 7 | env_monitor_start(x, instance_id, directory, force = FALSE, resume = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | 14 | \item{directory}{The directory to write the training data to. Defaults to FALSE.} 15 | 16 | \item{force}{Clear out existing training data from this directory (by deleting every file prefixed with "openaigym"). Defaults to NULL.} 17 | 18 | \item{resume}{Retain the training data already in this directory, which will be merged with our new data. Defaults to FALSE.} 19 | } 20 | \value{ 21 | NULL. 22 | } 23 | \description{ 24 | Start monitoring. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | remote_base <- "http://127.0.0.1:5000" 29 | client <- create_GymClient(remote_base) 30 | env_id <- "CartPole-v0" 31 | instance_id <- env_create(client, env_id) 32 | outdir <- "/tmp/random-agent-results" 33 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /gym/man/env_step.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/api.R 3 | \name{env_step} 4 | \alias{env_step} 5 | \title{Step though an environment using an action.} 6 | \usage{ 7 | env_step(x, instance_id, action, render = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{An instance of class "GymClient"; this object has "remote_base" as an attribute.} 11 | 12 | \item{instance_id}{A short identifier (such as "3c657dbc") for the environment instance.} 13 | 14 | \item{action}{An action to take in the environment.} 15 | 16 | \item{render}{Whether to render the environment. Defaults to FALSE.} 17 | } 18 | \value{ 19 | 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. 20 | } 21 | \description{ 22 | Step though an environment using an action. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | remote_base <- "http://127.0.0.1:5000" 27 | client <- create_GymClient(remote_base) 28 | env_id <- "CartPole-v0" 29 | instance_id <- env_create(client, env_id) 30 | action <- env_action_space_sample(client, instance_id) 31 | env_step(client, instance_id, action) 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /docs/jquery.sticky-kit.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net 3 | */ 4 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); 5 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
    "))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, 6 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), 8 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", 9 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n", 28 | httr::status_code(response), 29 | parsed$message, 30 | parsed$documentation_url 31 | ), 32 | call. = FALSE 33 | ) 34 | } 35 | 36 | parsed 37 | } 38 | 39 | #' Submit a POST request to an OpenAI Gym server. 40 | #' 41 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 42 | #' @param route The URL path or endpoint. 43 | #' @param data URL query arguments. Default value is NULL. 44 | #' @return If the response code is 200 or 204, a parsed response. Else, a server error or raised exception. 45 | #' @examples 46 | #' \dontrun{ 47 | #' remote_base <- "http://127.0.0.1:5000" 48 | #' client <- create_GymClient(remote_base) 49 | #' route <- "/v1/envs/" 50 | #' env_id <- "CartPole-v0" 51 | #' data <- list(env_id = env_id) 52 | #' post_request(client, route, data) 53 | #' } 54 | #' @export 55 | post_request <- function(x, route, data = NULL) { 56 | url <- httr::modify_url(x$remote_base, path = route) 57 | response <- httr::POST(url, body = data, encode = "json") 58 | parse_server_error_or_raise_for_status(response) 59 | } 60 | 61 | #' Submit a GET request to an OpenAI Gym server. 62 | #' 63 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 64 | #' @param route The URL path or endpoint. 65 | #' @param data URL query arguments. Default value is NULL. 66 | #' @return If the response code is 200 or 204, a parsed response. Else, a server error or raised exception. 67 | #' @examples 68 | #' \dontrun{ 69 | #' remote_base <- "http://127.0.0.1:5000" 70 | #' client <- create_GymClient(remote_base) 71 | #' route <- "/v1/envs/" 72 | #' get_request(client, route) 73 | #' } 74 | #' @export 75 | get_request <- function(x, route, data = NULL) { 76 | url <- httr::modify_url(x$remote_base, path = route) 77 | response <- httr::GET(url, body = data, encode = "json") 78 | parse_server_error_or_raise_for_status(response) 79 | } 80 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticker footer */ 2 | body > .container { 3 | display: flex; 4 | padding-top: 60px; 5 | min-height: calc(100vh); 6 | flex-direction: column; 7 | } 8 | 9 | body > .container .row { 10 | flex: 1; 11 | } 12 | 13 | footer { 14 | margin-top: 45px; 15 | padding: 35px 0 36px; 16 | border-top: 1px solid #e5e5e5; 17 | color: #666; 18 | display: flex; 19 | } 20 | footer p { 21 | margin-bottom: 0; 22 | } 23 | footer div { 24 | flex: 1; 25 | } 26 | footer .pkgdown { 27 | text-align: right; 28 | } 29 | footer p { 30 | margin-bottom: 0; 31 | } 32 | 33 | img.icon { 34 | float: right; 35 | } 36 | 37 | img { 38 | max-width: 100%; 39 | } 40 | 41 | /* Section anchors ---------------------------------*/ 42 | 43 | a.anchor { 44 | margin-left: -30px; 45 | display:inline-block; 46 | width: 30px; 47 | height: 30px; 48 | visibility: hidden; 49 | 50 | background-image: url(./link.svg); 51 | background-repeat: no-repeat; 52 | background-size: 20px 20px; 53 | background-position: center center; 54 | } 55 | 56 | .hasAnchor:hover a.anchor { 57 | visibility: visible; 58 | } 59 | 60 | @media (max-width: 767px) { 61 | .hasAnchor:hover a.anchor { 62 | visibility: hidden; 63 | } 64 | } 65 | 66 | 67 | /* Fixes for fixed navbar --------------------------*/ 68 | 69 | .contents h1, .contents h2, .contents h3, .contents h4 { 70 | padding-top: 60px; 71 | margin-top: -60px; 72 | } 73 | 74 | /* Static header placement on mobile devices */ 75 | @media (max-width: 767px) { 76 | .navbar-fixed-top { 77 | position: absolute; 78 | } 79 | .navbar { 80 | padding: 0; 81 | } 82 | } 83 | 84 | 85 | /* Sidebar --------------------------*/ 86 | 87 | #sidebar { 88 | margin-top: 30px; 89 | } 90 | #sidebar h2 { 91 | font-size: 1.5em; 92 | margin-top: 1em; 93 | } 94 | 95 | #sidebar h2:first-child { 96 | margin-top: 0; 97 | } 98 | 99 | #sidebar .list-unstyled li { 100 | margin-bottom: 0.5em; 101 | } 102 | 103 | /* Reference index & topics ----------------------------------------------- */ 104 | 105 | .ref-index th {font-weight: normal;} 106 | .ref-index h2 {font-size: 20px;} 107 | 108 | .ref-index td {vertical-align: top;} 109 | .ref-index .alias {width: 40%;} 110 | .ref-index .title {width: 60%;} 111 | 112 | .ref-index .alias {width: 40%;} 113 | .ref-index .title {width: 60%;} 114 | 115 | .ref-arguments th {text-align: right; padding-right: 10px;} 116 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 117 | .ref-arguments .name {width: 20%;} 118 | .ref-arguments .desc {width: 80%;} 119 | 120 | /* Nice scrolling for wide elements --------------------------------------- */ 121 | 122 | table { 123 | display: block; 124 | overflow: auto; 125 | } 126 | 127 | /* Syntax highlighting ---------------------------------------------------- */ 128 | 129 | pre { 130 | word-wrap: normal; 131 | word-break: normal; 132 | border: 1px solid #eee; 133 | } 134 | 135 | pre, code { 136 | background-color: #f8f8f8; 137 | color: #333; 138 | } 139 | 140 | pre .img { 141 | margin: 5px 0; 142 | } 143 | 144 | pre .img img { 145 | background-color: #fff; 146 | display: block; 147 | height: auto; 148 | } 149 | 150 | code a, pre a { 151 | color: #375f84; 152 | } 153 | 154 | .fl {color: #1514b5;} 155 | .fu {color: #000000;} /* function */ 156 | .ch,.st {color: #036a07;} /* string */ 157 | .kw {color: #264D66;} /* keyword */ 158 | .co {color: #888888;} /* comment */ 159 | 160 | .message { color: black; font-weight: bolder;} 161 | .error { color: orange; font-weight: bolder;} 162 | .warning { color: #6A0366; font-weight: bolder;} 163 | 164 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 |
    YEAR: 2016
     90 | COPYRIGHT HOLDER: Paul Hendricks
     91 | 
    92 | 93 |
    94 | 95 |
    96 | 97 | 98 |
    99 | 102 | 103 |
    104 |

    Site built with pkgdown.

    105 |
    106 | 107 |
    108 |
    109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 |
      90 |
    • 91 |

      Paul Hendricks. Author, maintainer. 92 |

      93 |
    • 94 |
    95 | 96 |
    97 | 98 |
    99 | 100 | 101 |
    102 | 105 | 106 |
    107 |

    Site built with pkgdown.

    108 |
    109 | 110 |
    111 |
    112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | gym 4 | === 5 | 6 | [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/gym)](http://cran.r-project.org/package=gym) [![Downloads from the RStudio CRAN mirror](http://cranlogs.r-pkg.org/badges/gym)](http://cran.rstudio.com/package=gym) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) 7 | 8 | [OpenAI Gym](https://github.com/openai/gym) is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This R package is a wrapper for the [OpenAI Gym API](https://github.com/openai/gym-http-api), and enables access to an ever-growing variety of environments. 9 | 10 | Installation 11 | ------------ 12 | 13 | You can install the latest development version from CRAN: 14 | 15 | ``` r 16 | install.packages("gym") 17 | ``` 18 | 19 | Or from GitHub with: 20 | 21 | ``` r 22 | if (packageVersion("devtools") < 1.6) { 23 | install.packages("devtools") 24 | } 25 | devtools::install_github("paulhendricks/gym-R", subdir = "R") 26 | ``` 27 | 28 | If you encounter a clear bug, please file a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on [GitHub](https://github.com/paulhendricks/gym/issues). 29 | 30 | Getting started 31 | --------------- 32 | 33 | ### Setting up the server 34 | 35 | To download the code and install the requirements, you can run the following shell commands: 36 | 37 | ``` bash 38 | git clone https://github.com/openai/gym-http-api 39 | cd gym-http-api 40 | pip install -r requirements.txt 41 | ``` 42 | 43 | This code is intended to be run locally by a single user. The server runs in python. 44 | 45 | To start the server from the command line, run this: 46 | 47 | ``` bash 48 | python gym_http_server.py 49 | ``` 50 | 51 | For more details, please see here: . 52 | 53 | ### Running an example in R 54 | 55 | In a separate R terminal, you can then try running the example agent and see what happens: 56 | 57 | ``` r 58 | library(gym) 59 | 60 | remote_base <- "http://127.0.0.1:5000" 61 | client <- create_GymClient(remote_base) 62 | print(client) 63 | 64 | # Create environment 65 | env_id <- "CartPole-v0" 66 | instance_id <- env_create(client, env_id) 67 | print(instance_id) 68 | 69 | # List all environments 70 | all_envs <- env_list_all(client) 71 | print(all_envs) 72 | 73 | # Set up agent 74 | action_space_info <- env_action_space_info(client, instance_id) 75 | print(action_space_info) 76 | agent <- random_discrete_agent(action_space_info[["n"]]) 77 | 78 | # Run experiment, with monitor 79 | outdir <- "/tmp/random-agent-results" 80 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 81 | 82 | episode_count <- 100 83 | max_steps <- 200 84 | reward <- 0 85 | done <- FALSE 86 | 87 | for (i in 1:episode_count) { 88 | ob <- env_reset(client, instance_id) 89 | for (i in 1:max_steps) { 90 | action <- env_action_space_sample(client, instance_id) 91 | results <- env_step(client, instance_id, action, render = TRUE) 92 | if (results[["done"]]) break 93 | } 94 | } 95 | 96 | # Dump result info to disk 97 | env_monitor_close(client, instance_id) 98 | ``` 99 | 100 | Citation 101 | -------- 102 | 103 | To cite package ‘gym’ in publications use: 104 | 105 | Paul Hendricks (2016). gym: Provides Access to the OpenAI Gym API. R package version 0.1.0. https://CRAN.R-project.org/package=gym 106 | 107 | A BibTeX entry for LaTeX users is 108 | 109 | @Manual{, 110 | title = {gym: Provides Access to the OpenAI Gym API}, 111 | author = {Paul Hendricks}, 112 | year = {2016}, 113 | note = {R package version 0.1.0}, 114 | url = {https://CRAN.R-project.org/package=gym}, 115 | } 116 | -------------------------------------------------------------------------------- /gym/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | gym 4 | === 5 | 6 | [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/gym)](http://cran.r-project.org/package=gym) [![Downloads from the RStudio CRAN mirror](http://cranlogs.r-pkg.org/badges/gym)](http://cran.rstudio.com/package=gym) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) 7 | 8 | [OpenAI Gym](https://github.com/openai/gym) is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This R package is a wrapper for the [OpenAI Gym API](https://github.com/openai/gym-http-api), and enables access to an ever-growing variety of environments. 9 | 10 | Installation 11 | ------------ 12 | 13 | You can install the latest development version from CRAN: 14 | 15 | ``` r 16 | install.packages("gym") 17 | ``` 18 | 19 | Or from GitHub with: 20 | 21 | ``` r 22 | if (packageVersion("devtools") < 1.6) { 23 | install.packages("devtools") 24 | } 25 | devtools::install_github("paulhendricks/gym-R", subdir = "R") 26 | ``` 27 | 28 | If you encounter a clear bug, please file a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on [GitHub](https://github.com/paulhendricks/gym/issues). 29 | 30 | Getting started 31 | --------------- 32 | 33 | ### Setting up the server 34 | 35 | To download the code and install the requirements, you can run the following shell commands: 36 | 37 | ``` bash 38 | git clone https://github.com/openai/gym-http-api 39 | cd gym-http-api 40 | pip install -r requirements.txt 41 | ``` 42 | 43 | This code is intended to be run locally by a single user. The server runs in python. 44 | 45 | To start the server from the command line, run this: 46 | 47 | ``` bash 48 | python gym_http_server.py 49 | ``` 50 | 51 | For more details, please see here: . 52 | 53 | ### Running an example in R 54 | 55 | In a separate R terminal, you can then try running the example agent and see what happens: 56 | 57 | ``` r 58 | library(gym) 59 | 60 | remote_base <- "http://127.0.0.1:5000" 61 | client <- create_GymClient(remote_base) 62 | print(client) 63 | 64 | # Create environment 65 | env_id <- "CartPole-v0" 66 | instance_id <- env_create(client, env_id) 67 | print(instance_id) 68 | 69 | # List all environments 70 | all_envs <- env_list_all(client) 71 | print(all_envs) 72 | 73 | # Set up agent 74 | action_space_info <- env_action_space_info(client, instance_id) 75 | print(action_space_info) 76 | agent <- random_discrete_agent(action_space_info[["n"]]) 77 | 78 | # Run experiment, with monitor 79 | outdir <- "/tmp/random-agent-results" 80 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 81 | 82 | episode_count <- 100 83 | max_steps <- 200 84 | reward <- 0 85 | done <- FALSE 86 | 87 | for (i in 1:episode_count) { 88 | ob <- env_reset(client, instance_id) 89 | for (i in 1:max_steps) { 90 | action <- env_action_space_sample(client, instance_id) 91 | results <- env_step(client, instance_id, action, render = TRUE) 92 | if (results[["done"]]) break 93 | } 94 | } 95 | 96 | # Dump result info to disk 97 | env_monitor_close(client, instance_id) 98 | ``` 99 | 100 | Citation 101 | -------- 102 | 103 | To cite package ‘gym’ in publications use: 104 | 105 | Paul Hendricks (2016). gym: Provides Access to the OpenAI Gym API. R package version 0.1.0. https://CRAN.R-project.org/package=gym 106 | 107 | A BibTeX entry for LaTeX users is 108 | 109 | @Manual{, 110 | title = {gym: Provides Access to the OpenAI Gym API}, 111 | author = {Paul Hendricks}, 112 | year = {2016}, 113 | note = {R package version 0.1.0}, 114 | url = {https://CRAN.R-project.org/package=gym}, 115 | } 116 | -------------------------------------------------------------------------------- /docs/reference/gym.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | gym: Provides Access to the OpenAI Gym API — gym • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    gym: Provides Access to the OpenAI Gym API

    91 | 92 | 93 | 94 | 95 |
    96 | 102 |
    103 | 104 |
    105 | 108 | 109 |
    110 |

    Site built with pkgdown.

    111 |
    112 | 113 |
    114 |
    115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /gym/README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | github_document 4 | --- 5 | 6 | 7 | 8 | ```{r, echo = FALSE} 9 | knitr::opts_chunk$set( 10 | collapse = TRUE, 11 | comment = "#>", 12 | fig.path = "README-" 13 | ) 14 | ``` 15 | 16 | # gym 17 | 18 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/gym)](http://cran.r-project.org/package=gym) 19 | [![Downloads from the RStudio CRAN mirror](http://cranlogs.r-pkg.org/badges/gym)](http://cran.rstudio.com/package=gym) 20 | [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) 21 | 22 | [OpenAI Gym](https://github.com/openai/gym) is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This R package is a wrapper for the [OpenAI Gym API](https://github.com/openai/gym-http-api), and enables access to an ever-growing variety of environments. 23 | 24 | ## Installation 25 | 26 | You can install the latest development version from CRAN: 27 | 28 | ```R 29 | install.packages("gym") 30 | ```` 31 | 32 | Or from GitHub with: 33 | 34 | ```R 35 | if (packageVersion("devtools") < 1.6) { 36 | install.packages("devtools") 37 | } 38 | devtools::install_github("paulhendricks/gym-R", subdir = "R") 39 | ``` 40 | 41 | If you encounter a clear bug, please file a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on [GitHub](https://github.com/paulhendricks/gym/issues). 42 | 43 | ## Getting started 44 | 45 | ### Setting up the server 46 | 47 | To download the code and install the requirements, you can run the following shell commands: 48 | 49 | ```bash 50 | git clone https://github.com/openai/gym-http-api 51 | cd gym-http-api 52 | pip install -r requirements.txt 53 | ``` 54 | 55 | This code is intended to be run locally by a single user. The server runs in python. 56 | 57 | To start the server from the command line, run this: 58 | 59 | ```bash 60 | python gym_http_server.py 61 | ``` 62 | 63 | For more details, please see here: https://github.com/openai/gym-http-api. 64 | 65 | ### Running an example in R 66 | 67 | In a separate R terminal, you can then try running the example agent and see what happens: 68 | 69 | ```R 70 | library(gym) 71 | 72 | remote_base <- "http://127.0.0.1:5000" 73 | client <- create_GymClient(remote_base) 74 | print(client) 75 | 76 | # Create environment 77 | env_id <- "CartPole-v0" 78 | instance_id <- env_create(client, env_id) 79 | print(instance_id) 80 | 81 | # List all environments 82 | all_envs <- env_list_all(client) 83 | print(all_envs) 84 | 85 | # Set up agent 86 | action_space_info <- env_action_space_info(client, instance_id) 87 | print(action_space_info) 88 | agent <- random_discrete_agent(action_space_info[["n"]]) 89 | 90 | # Run experiment, with monitor 91 | outdir <- "/tmp/random-agent-results" 92 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 93 | 94 | episode_count <- 100 95 | max_steps <- 200 96 | reward <- 0 97 | done <- FALSE 98 | 99 | for (i in 1:episode_count) { 100 | ob <- env_reset(client, instance_id) 101 | for (i in 1:max_steps) { 102 | action <- env_action_space_sample(client, instance_id) 103 | results <- env_step(client, instance_id, action, render = TRUE) 104 | if (results[["done"]]) break 105 | } 106 | } 107 | 108 | # Dump result info to disk 109 | env_monitor_close(client, instance_id) 110 | ``` 111 | 112 | ## Citation 113 | 114 | To cite package ‘gym’ in publications use: 115 | 116 | ``` 117 | Paul Hendricks (2016). gym: Provides Access to the OpenAI Gym API. R package version 0.1.0. https://CRAN.R-project.org/package=gym 118 | ``` 119 | 120 | A BibTeX entry for LaTeX users is 121 | 122 | ``` 123 | @Manual{, 124 | title = {gym: Provides Access to the OpenAI Gym API}, 125 | author = {Paul Hendricks}, 126 | year = {2016}, 127 | note = {R package version 0.1.0}, 128 | url = {https://CRAN.R-project.org/package=gym}, 129 | } 130 | ``` 131 | -------------------------------------------------------------------------------- /docs/reference/random_discrete_agent.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A sample random discrete agent. — random_discrete_agent • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    A sample random discrete agent.

    91 | 92 | 93 |
    random_discrete_agent(n)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    n

    The number of discrete action spaces available.

    103 | 104 |

    Value

    105 | 106 |

    NULL.

    107 | 108 | 109 |

    Examples

    110 |
    agent <- random_discrete_agent(10)
    111 |
    112 | 123 |
    124 | 125 |
    126 | 129 | 130 |
    131 |

    Site built with pkgdown.

    132 |
    133 | 134 |
    135 |
    136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /docs/reference/GymClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Create a GymClient instance. — GymClient • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    This function instantiates a GymClient instance to integrate with an OpenAI Gym server.

    91 | 92 | 93 |
    GymClient(remote_base)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    remote_base

    The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000".

    103 | 104 |

    Value

    105 | 106 |

    An instance of class "GymClient"; this object has "remote_base" as an attribute.

    107 | 108 | 109 |

    Examples

    110 |
    # NOT RUN {
    111 | remote_base <- "http://127.0.0.1:5000"
    112 | client <- GymClient(remote_base)
    113 | # }
    114 |
    115 | 126 |
    127 | 128 |
    129 | 132 | 133 |
    134 |

    Site built with pkgdown.

    135 |
    136 | 137 |
    138 |
    139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /docs/reference/create_GymClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Create a GymClient instance. — create_GymClient • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    This function instantiates a GymClient instance to integrate with an OpenAI Gym server.

    91 | 92 | 93 |
    create_GymClient(remote_base)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    remote_base

    The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000".

    103 | 104 |

    Value

    105 | 106 |

    An instance of class "GymClient"; this object has "remote_base" as an attribute.

    107 | 108 | 109 |

    Examples

    110 |
    # NOT RUN {
    111 | remote_base <- "http://127.0.0.1:5000"
    112 | client <- create_GymClient(remote_base)
    113 | # }
    114 |
    115 | 126 |
    127 | 128 |
    129 | 132 | 133 |
    134 |

    Site built with pkgdown.

    135 |
    136 | 137 |
    138 |
    139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /docs/reference/shutdown_server.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Request a server shutdown. — shutdown_server • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Request a server shutdown.

    91 | 92 | 93 |
    shutdown_server(x)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    x

    An instance of class "GymClient"; this object has "remote_base" as an attribute.

    103 | 104 |

    Value

    105 | 106 |

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

    107 | 108 | 109 |

    Examples

    110 |
    # NOT RUN {
    111 | remote_base <- "http://127.0.0.1:5000"
    112 | client <- create_GymClient(remote_base)
    113 | shutdown_server(client)
    114 | # }
    115 |
    116 | 127 |
    128 | 129 |
    130 | 133 | 134 |
    135 |

    Site built with pkgdown.

    136 |
    137 | 138 |
    139 |
    140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | All news • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 | 85 |
    86 | 89 | 90 |
    91 |
    92 |

    93 | gym 0.1.1

    94 |
    95 |

    96 | Improvements

    97 |
      98 |
    • Improved documentation.
    • 99 |
    • Added unit tests.
    • 100 |
    • Added a GymClient function to create instances of the class GymClient e.g. client = GymClient(remote_base).
    • 101 |
    • Added Travis CI, Appevyor, and Codecov to ensure code quality.
    • 102 |
    103 |
    104 |
    105 |

    106 | Bug fixes

    107 |
      108 |
    • None.
    • 109 |
    110 |
    111 |
    112 |
    113 |

    114 | gym 0.1.0

    115 |
    116 |

    117 | Improvements

    118 |
      119 |
    • 120 | gym provides access to current version of OpenAI Gym API.
    • 121 |
    122 |
    123 |
    124 |

    125 | Bug fixes

    126 |
      127 |
    • None.
    • 128 |
    129 |
    130 |
    131 |
    132 |
    133 | 134 | 143 | 144 |
    145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown.

    153 |
    154 | 155 |
    156 |
    157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /docs/reference/env_list_all.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | List all environments running on the server. — env_list_all • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    List all environments running on the server.

    91 | 92 | 93 |
    env_list_all(x)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    x

    An instance of class "GymClient"; this object has "remote_base" as an attribute.

    103 | 104 |

    Value

    105 | 106 |

    A list mapping instance_id to env_id e.g. list("3c657dbc" = "CartPole-v0") for every env on the server.

    107 | 108 | 109 |

    Examples

    110 |
    # NOT RUN {
    111 | remote_base <- "http://127.0.0.1:5000"
    112 | client <- create_GymClient(remote_base)
    113 | env_list_all(client)
    114 | # }
    115 |
    116 | 127 |
    128 | 129 |
    130 | 133 | 134 |
    135 |

    Site built with pkgdown.

    136 |
    137 | 138 |
    139 |
    140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /docs/reference/print.GymClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Represent a GymClient instance on the command line. — print.GymClient • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Represent a GymClient instance on the command line.

    91 | 92 | 93 |
    # S3 method for GymClient
     94 | print(x, ...)
    95 | 96 |

    Arguments

    97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
    x

    An instance of class "GymClient"; this object has "remote_base" as an attribute.

    ...

    Further arguments passed to or from other methods.

    108 | 109 |

    Value

    110 | 111 |

    x A GymClient instance.

    112 | 113 | 114 |

    Examples

    115 |
    # NOT RUN {
    116 | remote_base <- "http://127.0.0.1:5000"
    117 | client <- create_GymClient(remote_base)
    118 | print(client)
    119 | # }
    120 |
    121 | 132 |
    133 | 134 |
    135 | 138 | 139 |
    140 |

    Site built with pkgdown.

    141 |
    142 | 143 |
    144 |
    145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/env_close.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Flush all monitor data to disk. — env_close • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Flush all monitor data to disk.

    91 | 92 | 93 |
    env_close(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    NULL.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_close(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/parse_server_error_or_raise_for_status.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Parse the server error or raise for status. — parse_server_error_or_raise_for_status • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Parse the server error or raise for status.

    91 | 92 | 93 |
    parse_server_error_or_raise_for_status(response)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 |
    response

    A response object from httr::POST or httr::GET.

    103 | 104 |

    Value

    105 | 106 |

    If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.

    107 | 108 | 109 |

    Examples

    110 |
    # NOT RUN {
    111 | b2 <- "http://httpbin.org/post"
    112 | response <- httr::POST(b2, body = "A simple text string")
    113 | parse_server_error_or_raise_for_status(response)
    114 | # }
    115 |
    116 | 127 |
    128 | 129 |
    130 | 133 | 134 |
    135 |

    Site built with pkgdown.

    136 |
    137 | 138 |
    139 |
    140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /docs/reference/env_monitor_close.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Flush all monitor data to disk. — env_monitor_close • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Flush all monitor data to disk.

    91 | 92 | 93 |
    env_monitor_close(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    NULL.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_monitor_close(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/get_request.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Submit a GET request to an OpenAI Gym server. — get_request • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Submit a GET request to an OpenAI Gym server.

    91 | 92 | 93 |
    get_request(x, route, data = NULL)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
    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.

    111 | 112 |

    Value

    113 | 114 |

    If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.

    115 | 116 | 117 |

    Examples

    118 |
    # NOT RUN {
    119 | remote_base <- "http://127.0.0.1:5000"
    120 | client <- create_GymClient(remote_base)
    121 | route <- "/v1/envs/"
    122 | get_request(client, route)
    123 | # }
    124 |
    125 | 136 |
    137 | 138 |
    139 | 142 | 143 |
    144 |

    Site built with pkgdown.

    145 |
    146 | 147 |
    148 |
    149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /docs/reference/env_create.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Create an instance of the specified environment. — env_create • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Create an instance of the specified environment.

    91 | 92 | 93 |
    env_create(x, env_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    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.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | env_create(client, env_id)
    119 | # }
    120 |
    121 | 132 |
    133 | 134 |
    135 | 138 | 139 |
    140 |

    Site built with pkgdown.

    141 |
    142 | 143 |
    144 |
    145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/env_reset.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Reset the state of the environment and return an initial observation. — env_reset • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Reset the state of the environment and return an initial observation.

    91 | 92 | 93 |
    env_reset(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    The initial observation of the space.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_reset(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/env_action_space_sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Sample an action from the environments's action space. — env_action_space_sample • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Sample an action from the environments's action space.

    91 | 92 | 93 |
    env_action_space_sample(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    An action sampled from a space (such as "Discrete"), which varies from space to space.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_action_space_sample(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Flush all monitor data to disk. — upload • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Flush all monitor data to disk.

    91 | 92 | 93 |
    upload(x, training_dir, api_key = NULL, algorithm_id = NULL)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 |
    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.

    115 | 116 |

    Value

    117 | 118 |

    NULL.

    119 | 120 | 121 |

    Examples

    122 |
    # NOT RUN {
    123 | remote_base <- "http://127.0.0.1:5000"
    124 | client <- create_GymClient(remote_base)
    125 | outdir <- "/tmp/random-agent-results"
    126 | upload(client, outdir)
    127 | # }
    128 |
    129 | 140 |
    141 | 142 |
    143 | 146 | 147 |
    148 |

    Site built with pkgdown.

    149 |
    150 | 151 |
    152 |
    153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/reference/env_action_space_info.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get information (name and dimensions/bounds) of the environments's action space. — env_action_space_info • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Get information (name and dimensions/bounds) of the environments's action space.

    91 | 92 | 93 |
    env_action_space_info(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_action_space_info(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/env_observation_space_info.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get information (name and dimensions/bounds) of the environment's observation space. — env_observation_space_info • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Get information (name and dimensions/bounds) of the environment's observation space.

    91 | 92 | 93 |
    env_observation_space_info(x, instance_id)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
    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.

    107 | 108 |

    Value

    109 | 110 |

    A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space.

    111 | 112 | 113 |

    Examples

    114 |
    # NOT RUN {
    115 | remote_base <- "http://127.0.0.1:5000"
    116 | client <- create_GymClient(remote_base)
    117 | env_id <- "CartPole-v0"
    118 | instance_id <- env_create(client, env_id)
    119 | env_observation_space_info(client, instance_id)
    120 | # }
    121 |
    122 | 133 |
    134 | 135 |
    136 | 139 | 140 |
    141 |

    Site built with pkgdown.

    142 |
    143 | 144 |
    145 |
    146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/post_request.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Submit a POST request to an OpenAI Gym server. — post_request • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Submit a POST request to an OpenAI Gym server.

    91 | 92 | 93 |
    post_request(x, route, data = NULL)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
    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.

    111 | 112 |

    Value

    113 | 114 |

    If the response code is 200 or 204, a parsed response. Else, a server error or raised exception.

    115 | 116 | 117 |

    Examples

    118 |
    # NOT RUN {
    119 | remote_base <- "http://127.0.0.1:5000"
    120 | client <- create_GymClient(remote_base)
    121 | route <- "/v1/envs/"
    122 | env_id <- "CartPole-v0"
    123 | data <- list(env_id = env_id)
    124 | post_request(client, route, data)
    125 | # }
    126 |
    127 | 138 |
    139 | 140 |
    141 | 144 | 145 |
    146 |

    Site built with pkgdown.

    147 |
    148 | 149 |
    150 |
    151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /docs/reference/env_action_space_contains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Evaluate whether an action is a member of an environments's action space. — env_action_space_contains • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Evaluate whether an action is a member of an environments's action space.

    91 | 92 | 93 |
    env_action_space_contains(x, instance_id, action)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
    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.

    111 | 112 |

    Value

    113 | 114 |

    A boolean atomic vector of length one indicating if the action is a member of an environments's action space.

    115 | 116 | 117 |

    Examples

    118 |
    # NOT RUN {
    119 | remote_base <- "http://127.0.0.1:5000"
    120 | client <- create_GymClient(remote_base)
    121 | env_id <- "CartPole-v0"
    122 | instance_id <- env_create(client, env_id)
    123 | action <- env_action_space_sample(client, instance_id)
    124 | env_action_space_contains(client, instance_id, action)
    125 | # }
    126 |
    127 | 138 |
    139 | 140 |
    141 | 144 | 145 |
    146 |

    Site built with pkgdown.

    147 |
    148 | 149 |
    150 |
    151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /docs/reference/env_step.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Step though an environment using an action. — env_step • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Step though an environment using an action.

    91 | 92 | 93 |
    env_step(x, instance_id, action, render = FALSE)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 |
    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.

    115 | 116 |

    Value

    117 | 118 |

    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.

    119 | 120 | 121 |

    Examples

    122 |
    # NOT RUN {
    123 | remote_base <- "http://127.0.0.1:5000"
    124 | client <- create_GymClient(remote_base)
    125 | env_id <- "CartPole-v0"
    126 | instance_id <- env_create(client, env_id)
    127 | action <- env_action_space_sample(client, instance_id)
    128 | env_step(client, instance_id, action)
    129 | # }
    130 |
    131 | 142 |
    143 | 144 |
    145 | 148 | 149 |
    150 |

    Site built with pkgdown.

    151 |
    152 | 153 |
    154 |
    155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/reference/env_monitor_start.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Start monitoring. — env_monitor_start • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 88 | 89 | 90 |

    Start monitoring.

    91 | 92 | 93 |
    env_monitor_start(x, instance_id, directory, force = FALSE, resume = FALSE)
    94 | 95 |

    Arguments

    96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 |
    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.

    119 | 120 |

    Value

    121 | 122 |

    NULL.

    123 | 124 | 125 |

    Examples

    126 |
    # NOT RUN {
    127 | remote_base <- "http://127.0.0.1:5000"
    128 | client <- create_GymClient(remote_base)
    129 | env_id <- "CartPole-v0"
    130 | instance_id <- env_create(client, env_id)
    131 | outdir <- "/tmp/random-agent-results"
    132 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE)
    133 | # }
    134 |
    135 | 146 |
    147 | 148 |
    149 | 152 | 153 |
    154 |

    Site built with pkgdown.

    155 |
    156 | 157 |
    158 |
    159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • gym 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 |
    41 |
    42 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | 91 | 92 |
    93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 106 | 107 | 108 | 109 | 112 | 113 | 114 | 115 | 118 | 119 | 120 | 121 | 124 | 125 | 126 | 127 | 130 | 131 | 132 | 133 | 136 | 137 | 138 | 139 | 142 | 143 | 144 | 145 | 148 | 149 | 150 | 151 | 154 | 155 | 156 | 157 | 160 | 161 | 162 | 163 | 166 | 167 | 168 | 169 | 172 | 173 | 174 | 175 | 178 | 179 | 180 | 181 | 184 | 185 | 186 | 187 | 190 | 191 | 192 | 193 | 196 | 197 | 198 | 199 | 202 | 203 | 204 | 205 | 208 | 209 | 210 | 211 | 214 | 215 | 216 | 217 | 220 | 221 | 222 | 223 | 226 | 227 | 228 | 229 | 232 | 233 | 234 | 235 |
    103 |

    All functions

    104 |

    105 |
    110 |

    create_GymClient

    111 |

    Create a GymClient instance.

    116 |

    env_action_space_contains

    117 |

    Evaluate whether an action is a member of an environments's action space.

    122 |

    env_action_space_info

    123 |

    Get information (name and dimensions/bounds) of the environments's action space.

    128 |

    env_action_space_sample

    129 |

    Sample an action from the environments's action space.

    134 |

    env_close

    135 |

    Flush all monitor data to disk.

    140 |

    env_create

    141 |

    Create an instance of the specified environment.

    146 |

    env_list_all

    147 |

    List all environments running on the server.

    152 |

    env_monitor_close

    153 |

    Flush all monitor data to disk.

    158 |

    env_monitor_start

    159 |

    Start monitoring.

    164 |

    env_observation_space_info

    165 |

    Get information (name and dimensions/bounds) of the environment's observation space.

    170 |

    env_reset

    171 |

    Reset the state of the environment and return an initial observation.

    176 |

    env_step

    177 |

    Step though an environment using an action.

    182 |

    get_request

    183 |

    Submit a GET request to an OpenAI Gym server.

    188 |

    189 |

    gym: Provides Access to the OpenAI Gym API

    194 |

    GymClient

    195 |

    Create a GymClient instance.

    200 |

    parse_server_error_or_raise_for_status

    201 |

    Parse the server error or raise for status.

    206 |

    post_request

    207 |

    Submit a POST request to an OpenAI Gym server.

    212 |

    print

    213 |

    Represent a GymClient instance on the command line.

    218 |

    random_discrete_agent

    219 |

    A sample random discrete agent.

    224 |

    shutdown_server

    225 |

    Request a server shutdown.

    230 |

    upload

    231 |

    Flush all monitor data to disk.

    236 |
    237 |
    238 | 239 | 245 |
    246 | 247 |
    248 | 251 | 252 |
    253 |

    Site built with pkgdown.

    254 |
    255 | 256 |
    257 |
    258 | 259 | 260 | 261 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Provides Access to the OpenAI Gym API • gym 9 | 10 | 11 | 12 | 16 | 17 | 18 |
    19 |
    57 | 58 | 59 | 60 |
    61 |
    62 | 63 | 64 | 65 | 66 |
    67 | 68 |
    69 | 71 | 72 |

    OpenAI Gym is a open-source Python toolkit for developing and comparing reinforcement learning algorithms. This R package is a wrapper for the OpenAI Gym API, and enables access to an ever-growing variety of environments.

    73 |
    74 |

    75 | Installation

    76 |

    You can install the latest development version from CRAN:

    77 |
    install.packages("gym")
    78 |

    Or from GitHub with:

    79 |
    if (packageVersion("devtools") < 1.6) {
     80 |   install.packages("devtools")
     81 | }
     82 | devtools::install_github("paulhendricks/gym-R", subdir = "R")
    83 |

    If you encounter a clear bug, please file a minimal reproducible example on GitHub.

    84 |
    85 |
    86 |

    87 | Getting started

    88 |
    89 |

    90 | Setting up the server

    91 |

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

    92 |
    git clone https://github.com/openai/gym-http-api
     93 | cd gym-http-api
     94 | pip install -r requirements.txt
    95 |

    This code is intended to be run locally by a single user. The server runs in python.

    96 |

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

    97 |
    python gym_http_server.py
    98 |

    For more details, please see here: https://github.com/openai/gym-http-api.

    99 |
    100 |
    101 |

    102 | Running an example in R

    103 |

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

    104 |
    library(gym)
    105 | 
    106 | remote_base <- "http://127.0.0.1:5000"
    107 | client <- create_GymClient(remote_base)
    108 | print(client)
    109 | 
    110 | # Create environment
    111 | env_id <- "CartPole-v0"
    112 | instance_id <- env_create(client, env_id)
    113 | print(instance_id)
    114 | 
    115 | # List all environments
    116 | all_envs <- env_list_all(client)
    117 | print(all_envs)
    118 | 
    119 | # Set up agent
    120 | action_space_info <- env_action_space_info(client, instance_id)
    121 | print(action_space_info)
    122 | agent <- random_discrete_agent(action_space_info[["n"]])
    123 | 
    124 | # Run experiment, with monitor
    125 | outdir <- "/tmp/random-agent-results"
    126 | env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE)
    127 | 
    128 | episode_count <- 100
    129 | max_steps <- 200
    130 | reward <- 0
    131 | done <- FALSE
    132 | 
    133 | for (i in 1:episode_count) {
    134 |   ob <- env_reset(client, instance_id)
    135 |   for (i in 1:max_steps) {
    136 |     action <- env_action_space_sample(client, instance_id)
    137 |     results <- env_step(client, instance_id, action, render = TRUE)
    138 |     if (results[["done"]]) break
    139 |   }
    140 | }
    141 | 
    142 | # Dump result info to disk
    143 | env_monitor_close(client, instance_id)
    144 |
    145 |
    146 |
    147 |

    148 | Citation

    149 |

    To cite package ‘gym’ in publications use:

    150 |
    Paul Hendricks (2016). gym: Provides Access to the OpenAI Gym API. R package version 0.1.0. https://CRAN.R-project.org/package=gym
    151 |

    A BibTeX entry for LaTeX users is

    152 |
    @Manual{,
    153 |   title = {gym: Provides Access to the OpenAI Gym API},
    154 |   author = {Paul Hendricks},
    155 |   year = {2016},
    156 |   note = {R package version 0.1.0},
    157 |   url = {https://CRAN.R-project.org/package=gym},
    158 | }
    159 |
    160 |
    161 |
    162 |
    163 | 164 | 188 | 189 |
    190 | 191 | 192 |
    195 | 196 |
    197 |

    Site built with pkgdown.

    198 |
    199 | 200 |
    201 |
    202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /gym/R/api.R: -------------------------------------------------------------------------------- 1 | #' Create a GymClient instance. 2 | #' 3 | #' This function instantiates a GymClient instance to integrate with an OpenAI Gym server. 4 | #' 5 | #' @param remote_base The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000". 6 | #' @return An instance of class "GymClient"; this object has "remote_base" as an attribute. 7 | #' @examples 8 | #' \dontrun{ 9 | #' remote_base <- "http://127.0.0.1:5000" 10 | #' client <- create_GymClient(remote_base) 11 | #' } 12 | #' @export 13 | create_GymClient <- function(remote_base) { 14 | GymClient(remote_base) 15 | } 16 | 17 | #' Create a GymClient instance. 18 | #' 19 | #' This function instantiates a GymClient instance to integrate with an OpenAI Gym server. 20 | #' 21 | #' @param remote_base The URL of the OpenAI gym server. This value is usually "http://127.0.0.1:5000". 22 | #' @return An instance of class "GymClient"; this object has "remote_base" as an attribute. 23 | #' @examples 24 | #' \dontrun{ 25 | #' remote_base <- "http://127.0.0.1:5000" 26 | #' client <- GymClient(remote_base) 27 | #' } 28 | #' @export 29 | GymClient <- function(remote_base) { 30 | structure(list(remote_base = remote_base), class = "GymClient") 31 | } 32 | 33 | #' Represent a GymClient instance on the command line. 34 | #' 35 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 36 | #' @param ... Further arguments passed to or from other methods. 37 | #' @return x A GymClient instance. 38 | #' @examples 39 | #' \dontrun{ 40 | #' remote_base <- "http://127.0.0.1:5000" 41 | #' client <- create_GymClient(remote_base) 42 | #' print(client) 43 | #' } 44 | #' @export 45 | print.GymClient <- function(x, ...) { 46 | cat("\n", sep = "") 47 | invisible(x) 48 | } 49 | 50 | #' Create an instance of the specified environment. 51 | #' 52 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 53 | #' @param 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. 54 | #' @return 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. 55 | #' @examples 56 | #' \dontrun{ 57 | #' remote_base <- "http://127.0.0.1:5000" 58 | #' client <- create_GymClient(remote_base) 59 | #' env_id <- "CartPole-v0" 60 | #' env_create(client, env_id) 61 | #' } 62 | #' @export 63 | env_create <- function(x, env_id) { 64 | route <- "/v1/envs/" 65 | data <- list(env_id = env_id) 66 | response <- post_request(x, route, data) 67 | instance_id <- response[["instance_id"]] 68 | instance_id 69 | } 70 | 71 | #' List all environments running on the server. 72 | #' 73 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 74 | #' @return A list mapping instance_id to env_id e.g. \code{list("3c657dbc" = "CartPole-v0")} for every env on the server. 75 | #' @examples 76 | #' \dontrun{ 77 | #' remote_base <- "http://127.0.0.1:5000" 78 | #' client <- create_GymClient(remote_base) 79 | #' env_list_all(client) 80 | #' } 81 | #' @export 82 | env_list_all <- function(x) { 83 | route <- "/v1/envs/" 84 | response <- get_request(x, route) 85 | all_envs <- response[["all_envs"]] 86 | all_envs 87 | } 88 | 89 | #' Reset the state of the environment and return an initial observation. 90 | #' 91 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 92 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 93 | #' @return The initial observation of the space. 94 | #' @examples 95 | #' \dontrun{ 96 | #' remote_base <- "http://127.0.0.1:5000" 97 | #' client <- create_GymClient(remote_base) 98 | #' env_id <- "CartPole-v0" 99 | #' instance_id <- env_create(client, env_id) 100 | #' env_reset(client, instance_id) 101 | #' } 102 | #' @export 103 | env_reset <- function(x, instance_id) { 104 | route <- paste0("/v1/envs/", instance_id, "/reset/", sep = "") 105 | response <- post_request(x, route) 106 | observation <- response[["observation"]] 107 | observation 108 | } 109 | 110 | #' Step though an environment using an action. 111 | #' 112 | #' 113 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 114 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 115 | #' @param action An action to take in the environment. 116 | #' @param render Whether to render the environment. Defaults to FALSE. 117 | #' @return 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. 118 | #' @examples 119 | #' \dontrun{ 120 | #' remote_base <- "http://127.0.0.1:5000" 121 | #' client <- create_GymClient(remote_base) 122 | #' env_id <- "CartPole-v0" 123 | #' instance_id <- env_create(client, env_id) 124 | #' action <- env_action_space_sample(client, instance_id) 125 | #' env_step(client, instance_id, action) 126 | #' } 127 | #' @export 128 | env_step <- function(x, instance_id, action, render = FALSE) { 129 | route <- paste0("/v1/envs/", instance_id, "/step/", sep = "") 130 | data <- list(instance_id = instance_id, action = action, render = render) 131 | response <- post_request(x, route, data) 132 | observation <- response[["observation"]] 133 | reward <- response[["reward"]] 134 | done <- response[["done"]] 135 | info <- response[["info"]] 136 | list(observation = observation, 137 | reward = reward, 138 | done = done, 139 | info = info) 140 | } 141 | 142 | #' Get information (name and dimensions/bounds) of the environments's action space. 143 | #' 144 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 145 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 146 | #' @return A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space. 147 | #' @examples 148 | #' \dontrun{ 149 | #' remote_base <- "http://127.0.0.1:5000" 150 | #' client <- create_GymClient(remote_base) 151 | #' env_id <- "CartPole-v0" 152 | #' instance_id <- env_create(client, env_id) 153 | #' env_action_space_info(client, instance_id) 154 | #' } 155 | #' @export 156 | env_action_space_info <- function(x, instance_id) { 157 | route <- paste0("/v1/envs/", instance_id, "/action_space/", sep = "") 158 | response <- get_request(x, route) 159 | info <- response[["info"]] 160 | info 161 | } 162 | 163 | #' Sample an action from the environments's action space. 164 | #' 165 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 166 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 167 | #' @return An action sampled from a space (such as "Discrete"), which varies from space to space. 168 | #' @examples 169 | #' \dontrun{ 170 | #' remote_base <- "http://127.0.0.1:5000" 171 | #' client <- create_GymClient(remote_base) 172 | #' env_id <- "CartPole-v0" 173 | #' instance_id <- env_create(client, env_id) 174 | #' env_action_space_sample(client, instance_id) 175 | #' } 176 | #' @export 177 | env_action_space_sample <- function(x, instance_id) { 178 | route <- paste0("/v1/envs/", instance_id, "/action_space/sample", sep = "") 179 | response <- get_request(x, route) 180 | action <- response[["action"]] 181 | action 182 | } 183 | 184 | #' Evaluate whether an action is a member of an environments's action space. 185 | #' 186 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 187 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 188 | #' @param action An action to take in the environment. 189 | #' @return A boolean atomic vector of length one indicating if the action is a member of an environments's action space. 190 | #' @examples 191 | #' \dontrun{ 192 | #' remote_base <- "http://127.0.0.1:5000" 193 | #' client <- create_GymClient(remote_base) 194 | #' env_id <- "CartPole-v0" 195 | #' instance_id <- env_create(client, env_id) 196 | #' action <- env_action_space_sample(client, instance_id) 197 | #' env_action_space_contains(client, instance_id, action) 198 | #' } 199 | #' @export 200 | env_action_space_contains <- function(x, instance_id, action) { 201 | route <- paste0("/v1/envs/", instance_id, "/action_space/contains/", 202 | action, "/", sep = "") 203 | response <- get_request(x, route) 204 | member <- response[["member"]] 205 | member 206 | } 207 | 208 | #' Get information (name and dimensions/bounds) of the environment's observation space. 209 | #' 210 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 211 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 212 | #' @return A list containing "name" (such as "Discrete"), and additional dimensional info (such as "n") which varies from space to space. 213 | #' @examples 214 | #' \dontrun{ 215 | #' remote_base <- "http://127.0.0.1:5000" 216 | #' client <- create_GymClient(remote_base) 217 | #' env_id <- "CartPole-v0" 218 | #' instance_id <- env_create(client, env_id) 219 | #' env_observation_space_info(client, instance_id) 220 | #' } 221 | #' @export 222 | env_observation_space_info <- function(x, instance_id) { 223 | route <- paste0("/v1/envs/", instance_id, "/observation_space/", sep = "") 224 | response <- get_request(x, route) 225 | info <- response[["info"]] 226 | info 227 | } 228 | 229 | #' Start monitoring. 230 | #' 231 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 232 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 233 | #' @param directory The directory to write the training data to. Defaults to FALSE. 234 | #' @param force Clear out existing training data from this directory (by deleting every file prefixed with "openaigym"). Defaults to NULL. 235 | #' @param resume Retain the training data already in this directory, which will be merged with our new data. Defaults to FALSE. 236 | #' @return NULL. 237 | #' @examples 238 | #' \dontrun{ 239 | #' remote_base <- "http://127.0.0.1:5000" 240 | #' client <- create_GymClient(remote_base) 241 | #' env_id <- "CartPole-v0" 242 | #' instance_id <- env_create(client, env_id) 243 | #' outdir <- "/tmp/random-agent-results" 244 | #' env_monitor_start(client, instance_id, outdir, force = TRUE, resume = FALSE) 245 | #' } 246 | #' @export 247 | env_monitor_start <- function(x, instance_id, directory, force = FALSE, resume = FALSE) { 248 | route <- paste0("/v1/envs/", instance_id, "/monitor/start/", sep = "") 249 | data <- list(directory = directory, force = force, 250 | resume = resume) 251 | response <- post_request(x, route, data) 252 | invisible() 253 | } 254 | 255 | #' Flush all monitor data to disk. 256 | #' 257 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 258 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 259 | #' @return NULL. 260 | #' @examples 261 | #' \dontrun{ 262 | #' remote_base <- "http://127.0.0.1:5000" 263 | #' client <- create_GymClient(remote_base) 264 | #' env_id <- "CartPole-v0" 265 | #' instance_id <- env_create(client, env_id) 266 | #' env_monitor_close(client, instance_id) 267 | #' } 268 | #' @export 269 | env_monitor_close <- function(x, instance_id) { 270 | route <- paste0("/v1/envs/", instance_id, "/monitor/close/", sep = "") 271 | response <- post_request(x, route) 272 | invisible() 273 | } 274 | 275 | #' Flush all monitor data to disk. 276 | #' 277 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 278 | #' @param instance_id A short identifier (such as "3c657dbc") for the environment instance. 279 | #' @return NULL. 280 | #' @examples 281 | #' \dontrun{ 282 | #' remote_base <- "http://127.0.0.1:5000" 283 | #' client <- create_GymClient(remote_base) 284 | #' env_id <- "CartPole-v0" 285 | #' instance_id <- env_create(client, env_id) 286 | #' env_close(client, instance_id) 287 | #' } 288 | #' @export 289 | env_close <- function(x, instance_id) { 290 | route <- paste0("/v1/envs/", instance_id, "/close/", sep = "") 291 | response <- post_request(x, route) 292 | invisible() 293 | } 294 | 295 | #' Flush all monitor data to disk. 296 | #' 297 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 298 | #' @param training_dir A directory containing the results of a training run. 299 | #' @param api_key Your OpenAI API key. 300 | #' @param algorithm_id An arbitrary string indicating the paricular version of the algorithm (including choices of parameters) you are running. 301 | #' @return NULL. 302 | #' @examples 303 | #' \dontrun{ 304 | #' remote_base <- "http://127.0.0.1:5000" 305 | #' client <- create_GymClient(remote_base) 306 | #' outdir <- "/tmp/random-agent-results" 307 | #' upload(client, outdir) 308 | #' } 309 | #' @export 310 | upload <- function(x, training_dir, api_key = NULL, algorithm_id = NULL) { 311 | if (is.null(api_key)) { 312 | api_key <- Sys.getenv("OPENAI_GYM_API_KEY") 313 | } 314 | 315 | route <- "/v1/upload/" 316 | data = list(training_dir = training_dir, 317 | algorithm_id = algorithm_id, 318 | api_key = api_key) 319 | response <- post_request(x, route, data) 320 | invisible() 321 | } 322 | 323 | #' Request a server shutdown. 324 | #' 325 | #' @param x An instance of class "GymClient"; this object has "remote_base" as an attribute. 326 | #' @return NULL Currently used by the integration tests to repeatedly create and destroy fresh copies of the server running in a separate thread. 327 | #' @examples 328 | #' \dontrun{ 329 | #' remote_base <- "http://127.0.0.1:5000" 330 | #' client <- create_GymClient(remote_base) 331 | #' shutdown_server(client) 332 | #' } 333 | #' @export 334 | shutdown_server <- function(x) { 335 | route <- "/v1/shutdown/" 336 | response <- post_request(x, route) 337 | invisible() 338 | } 339 | --------------------------------------------------------------------------------