bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
bitrl::network::RESTRLEnvClient Class Reference

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
 

Detailed Description

Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.

Constructor & Destructor Documentation

◆ RESTRLEnvClient()

bitrl::network::RESTRLEnvClient::RESTRLEnvClient ( const std::string &  url = "http://0.0.0.0:8001/api",
const bool  initialize = true 
)
explicit

Constructor.

Member Function Documentation

◆ close()

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.

◆ dynamics()

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.

◆ get_env_url()

std::string bitrl::network::RESTRLEnvClient::get_env_url ( const std::string &  name) const
noexcept

Return the url for the environment with the given name.

◆ get_uri()

std::string bitrl::network::RESTRLEnvClient::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.

◆ get_url()

std::string bitrl::network::RESTRLEnvClient::get_url ( ) const
inlinenoexcept

Returns the remote url.

◆ gymnasium_envs()

std::vector< std::string > bitrl::network::RESTRLEnvClient::gymnasium_envs ( ) const

◆ has_gymnasium()

bool bitrl::network::RESTRLEnvClient::has_gymnasium ( ) const

◆ is_alive()

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.

◆ is_env_registered()

bool bitrl::network::RESTRLEnvClient::is_env_registered ( const std::string &  env_name) const
noexcept

Returns true if the environment with the given name is registered

Parameters
env_nameThe environment name to query
Returns

◆ is_inisialised()

bool bitrl::network::RESTRLEnvClient::is_inisialised ( ) const
inlinenoexcept

Returns true if the server is initialised.

◆ make()

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.

◆ n_copies()

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

Parameters
name
Returns

◆ register_if_not()

void bitrl::network::RESTRLEnvClient::register_if_not ( const std::string &  name,
const std::string &  uri 
)

Same as register_new but swallows the thrown exception.

◆ register_new()

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.

◆ reset()

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.

◆ step()

template<typename ActionType >
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.


The documentation for this class was generated from the following files: