|
bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
|
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers. More...
#include <rest_rl_env_client.h>
Public Member Functions | |
| RESTRLEnvClient (const std::string &url="http://0.0.0.0:8001/api", const bool initialize=true) | |
| Constructor. | |
| bool | is_inisialised () const noexcept |
| Returns true if the server is initialised. | |
| std::string | get_url () const noexcept |
| Returns the remote url. | |
| bool | is_env_registered (const std::string &env_name) const noexcept |
| std::string | get_env_url (const std::string &name) const noexcept |
| Return the url for the environment with the given name. | |
| std::string | get_uri (const std::string &name) const noexcept |
| Returns the URI of the environment with the given name Returns INVALID_STR if the environment is not registered. | |
| void | register_new (const std::string &name, const std::string &uri) |
| Register a new environment. Throws std::logic_error if the environment name already exists. | |
| void | register_if_not (const std::string &name, const std::string &uri) |
| Same as register_new but swallows the thrown exception. | |
| nlohmann::json | n_copies (const std::string &name, const std::string &version=bitrl::consts::INVALID_STR) const |
| nlohmann::json | is_alive (const std::string &env_name, const std::string &idx) const |
| Queries the remote server if the environment with the given cidx is alive Throws std::logic_error is the environment is not registered. | |
| nlohmann::json | close (const std::string &env_name, const std::string &idx) const |
| Close the environment with the given name. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201. | |
| template<typename ActionType > | |
| nlohmann::json | step (const std::string &env_name, const std::string &idx, const ActionType &action) const |
| Step in the environment with the given name and the given copy index executing action. ActionType has to be JSON serializable Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201. | |
| nlohmann::json | reset (const std::string &env_name, const std::string &idx, const uint_t seed, const nlohmann::json &options) const |
| Reset the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202. | |
| nlohmann::json | make (const std::string &env_name, const std::string &version, const nlohmann::json &options) const |
| Make the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202. | |
| nlohmann::json | dynamics (const std::string &env_name, const std::string &idx, const uint_t sidx, const uint_t aidx) const |
| Get the dynamics of the environment. If the environment does not expose such an endpoint it returns 404. | |
| bool | has_gymnasium () const |
| std::vector< std::string > | gymnasium_envs () const |
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
|
explicit |
Constructor.
| nlohmann::json bitrl::network::RESTRLEnvClient::close | ( | const std::string & | env_name, |
| const std::string & | idx | ||
| ) | const |
Close the environment with the given name. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201.
| nlohmann::json bitrl::network::RESTRLEnvClient::dynamics | ( | const std::string & | env_name, |
| const std::string & | idx, | ||
| const uint_t | sidx, | ||
| const uint_t | aidx | ||
| ) | const |
Get the dynamics of the environment. If the environment does not expose such an endpoint it returns 404.
|
noexcept |
Return the url for the environment with the given name.
|
noexcept |
Returns the URI of the environment with the given name Returns INVALID_STR if the environment is not registered.
|
inlinenoexcept |
Returns the remote url.
| std::vector< std::string > bitrl::network::RESTRLEnvClient::gymnasium_envs | ( | ) | const |
| bool bitrl::network::RESTRLEnvClient::has_gymnasium | ( | ) | const |
| nlohmann::json bitrl::network::RESTRLEnvClient::is_alive | ( | const std::string & | env_name, |
| const std::string & | idx | ||
| ) | const |
Queries the remote server if the environment with the given cidx is alive Throws std::logic_error is the environment is not registered.
|
noexcept |
Returns true if the environment with the given name is registered
| env_name | The environment name to query |
|
inlinenoexcept |
Returns true if the server is initialised.
| nlohmann::json bitrl::network::RESTRLEnvClient::make | ( | const std::string & | env_name, |
| const std::string & | version, | ||
| const nlohmann::json & | options | ||
| ) | const |
Make the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202.
| nlohmann::json bitrl::network::RESTRLEnvClient::n_copies | ( | const std::string & | name, |
| const std::string & | version = bitrl::consts::INVALID_STR |
||
| ) | const |
Return the number of copies of the environment with the given name
| name |
| void bitrl::network::RESTRLEnvClient::register_if_not | ( | const std::string & | name, |
| const std::string & | uri | ||
| ) |
Same as register_new but swallows the thrown exception.
| void bitrl::network::RESTRLEnvClient::register_new | ( | const std::string & | name, |
| const std::string & | uri | ||
| ) |
Register a new environment. Throws std::logic_error if the environment name already exists.
| nlohmann::json bitrl::network::RESTRLEnvClient::reset | ( | const std::string & | env_name, |
| const std::string & | idx, | ||
| const uint_t | seed, | ||
| const nlohmann::json & | options | ||
| ) | const |
Reset the the environment with the given name and the given copy index executing action. Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 202.
| nlohmann::json bitrl::network::RESTRLEnvClient::step | ( | const std::string & | env_name, |
| const std::string & | idx, | ||
| const ActionType & | action | ||
| ) | const |
Step in the environment with the given name and the given copy index executing action. ActionType has to be JSON serializable Throws std::logic_error is the environment is not registered Throws std::runtime_error if the server response is not 201.