bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType > Class Template Referenceabstract

Base class for all Gymnasium environment wrappers. More...

#include <gymnasium_env_base.h>

Inheritance diagram for bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >:
Collaboration diagram for bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >:

Public Types

typedef EnvBase< TimeStepType, SpaceType > base_type
 Base environment type alias.
 
typedef base_type::time_step_type time_step_type
 Time step returned at each environment step.
 
typedef base_type::state_space_type state_space_type
 Type describing the observation/state space of the environment.
 
typedef base_type::action_space_type action_space_type
 Type describing the action space of the environment.
 
typedef base_type::action_type action_type
 Type representing a valid action to execute.
 
typedef base_type::state_type state_type
 Type representing a state/observation returned by the environment.
 
- Public Types inherited from bitrl::envs::EnvBase< TimeStepType, SpaceType >
typedef TimeStepType time_step_type
 Alias for the type returned when stepping the environment.
 
typedef SpaceType::state_space state_space_type
 Type describing the environment state space.
 
typedef SpaceType::state_type state_type
 Type describing an individual state.
 
typedef SpaceType::action_space action_space_type
 Type describing the environment action space.
 
typedef SpaceType::action_type action_type
 Type representing an individual action.
 

Public Member Functions

virtual ~GymnasiumEnvBase ()
 Virtual destructor.
 
virtual bool is_alive () const
 Check whether the environment is still alive/connected.
 
virtual void close () override
 Close the environment on the server and release any resources.
 
virtual time_step_type reset () override
 Reset the environment to an initial state using the reset options specified during make.
 
uint_t n_copies () const
 
network::RESTRLEnvClientget_api_server () const
 Retrieve the REST API wrapper instance used for communication.
 
std::string get_url () const
 Get the full URL for this environment endpoint on the server.
 
virtual time_step_type reset ()=0
 Import the reset() overloads from the base class.
 
- Public Member Functions inherited from bitrl::envs::EnvBase< TimeStepType, SpaceType >
virtual ~EnvBase ()=default
 Virtual destructor.
 
virtual void make (const std::string &version, const std::unordered_map< std::string, std::any > &make_options, const std::unordered_map< std::string, std::any > &reset_options)=0
 Construct the environment instance.
 
virtual time_step_type step (const action_type &action)=0
 Perform one step in the environment using an action.
 
const std::unordered_map< std::string, std::any > & make_options () const noexcept
 Access the configuration options provided to make().
 
const std::unordered_map< std::string, std::any > & reset_options () const noexcept
 Access the configuration options provided to make().
 
template<typename T >
read_option (const std::string &op_name) const
 Read a specific make() option and cast it to the requested type.
 
std::string idx () const noexcept
 Get the id identifying this environment within a simulation batch. The id is valid only if make has been called.
 
bool is_created () const noexcept
 Check if make() has successfully initialized the environment.
 
std::string env_name () const noexcept
 Get the name of this environment instance.
 
std::string version () const noexcept
 Get the environment version set during make().
 

Protected Member Functions

 GymnasiumEnvBase (network::RESTRLEnvClient &api_server, const std::string &name)
 Constructor.
 
 GymnasiumEnvBase (const GymnasiumEnvBase &)
 Copy constructor.
 
virtual time_step_type create_time_step_from_response_ (const nlohmann::json &response) const =0
 Build a TimeStepType instance from a server JSON response.
 
- Protected Member Functions inherited from bitrl::envs::EnvBase< TimeStepType, SpaceType >
 EnvBase (const std::string &idx=bitrl::consts::INVALID_STR, const std::string &name=bitrl::consts::INVALID_STR)
 Constructor (protected — for subclassing only).
 
 EnvBase (const EnvBase &)
 Copy constructor.
 
void set_version_ (const std::string &version) noexcept
 Set internal version string.
 
void set_idx_ (const std::string &idx) noexcept
 Set the id of the environment.
 
void set_make_options_ (const std::unordered_map< std::string, std::any > &options) noexcept
 Store options for future access.
 
void set_reset_options_ (const std::unordered_map< std::string, std::any > &options) noexcept
 Store reset options for future access.
 
void invalidate_is_created_flag_ () noexcept
 Mark environment as not created.
 
void make_created_ () noexcept
 Mark environment creation as successful.
 
time_step_typeget_current_time_step_ () noexcept
 Mutable access to the current time step.
 
const time_step_typeget_current_time_step_ () const noexcept
 Read-only access to the current time step.
 

Protected Attributes

network::RESTRLEnvClientapi_server_
 Server wrapper handling communication with remote Gymnasium environment.
 

Additional Inherited Members

- Static Public Attributes inherited from bitrl::envs::EnvBase< TimeStepType, SpaceType >
static const uint_t DEFAULT_ENV_SEED = 42
 Default seed used in reset() if none provided.
 

Detailed Description

template<typename TimeStepType, typename SpaceType>
class bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >

Base class for all Gymnasium environment wrappers.

This template wraps a remote Gymnasium-compatible environment served through a REST API. It extends EnvBase and provides the common logic for environment reset, closing, and time-step handling via HTTP communication.

Template Parameters
TimeStepTypeThe type representing one interaction step with the environment.
SpaceTypeThe type describing the observation and action spaces.

Member Typedef Documentation

◆ action_space_type

template<typename TimeStepType , typename SpaceType >
typedef base_type::action_space_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::action_space_type

Type describing the action space of the environment.

◆ action_type

template<typename TimeStepType , typename SpaceType >
typedef base_type::action_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::action_type

Type representing a valid action to execute.

◆ base_type

template<typename TimeStepType , typename SpaceType >
typedef EnvBase<TimeStepType, SpaceType> bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::base_type

Base environment type alias.

◆ state_space_type

template<typename TimeStepType , typename SpaceType >
typedef base_type::state_space_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::state_space_type

Type describing the observation/state space of the environment.

◆ state_type

template<typename TimeStepType , typename SpaceType >
typedef base_type::state_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::state_type

Type representing a state/observation returned by the environment.

◆ time_step_type

template<typename TimeStepType , typename SpaceType >
typedef base_type::time_step_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::time_step_type

Time step returned at each environment step.

Constructor & Destructor Documentation

◆ ~GymnasiumEnvBase()

template<typename TimeStepType , typename SpaceType >
bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::~GymnasiumEnvBase ( )
virtual

Virtual destructor.

◆ GymnasiumEnvBase() [1/2]

template<typename TimeStepType , typename SpaceType >
bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::GymnasiumEnvBase ( network::RESTRLEnvClient api_server,
const std::string &  name 
)
protected

Constructor.

Parameters
api_serverA reference to the REST server wrapper handling communication.
cidxIndex of this environment instance within a simulation.
nameName of the environment.

◆ GymnasiumEnvBase() [2/2]

template<typename TimeStepType , typename SpaceType >
bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::GymnasiumEnvBase ( const GymnasiumEnvBase< TimeStepType, SpaceType > &  other)
protected

Copy constructor.

Member Function Documentation

◆ close()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::close ( )
overridevirtual

Close the environment on the server and release any resources.

Implements bitrl::envs::EnvBase< TimeStepType, SpaceType >.

◆ create_time_step_from_response_()

◆ get_api_server()

template<typename TimeStepType , typename SpaceType >
network::RESTRLEnvClient & bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::get_api_server ( ) const
inline

Retrieve the REST API wrapper instance used for communication.

Returns
Read-only reference to the server wrapper.

◆ get_url()

template<typename TimeStepType , typename SpaceType >
std::string bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::get_url ( ) const

Get the full URL for this environment endpoint on the server.

Returns
Environment URL string.

◆ is_alive()

template<typename TimeStepType , typename SpaceType >
bool bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::is_alive ( ) const
virtual

Check whether the environment is still alive/connected.

Returns
True if the wrapper can still communicate with the server.

◆ n_copies()

template<typename TimeStepType , typename SpaceType >
uint_t bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::n_copies ( ) const

Get the number of copies on the server for this environment

Returns

◆ reset() [1/2]

template<typename TimeStepType , typename SpaceType >
GymnasiumEnvBase< TimeStepType, SpaceType >::time_step_type bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::reset ( )
overridevirtual

Reset the environment to an initial state using the reset options specified during make.

Returns
Initial time step after reset

Implements bitrl::envs::EnvBase< TimeStepType, SpaceType >.

◆ reset() [2/2]

template<typename TimeStepType , typename SpaceType >
virtual time_step_type bitrl::envs::EnvBase< TimeStepType, SpaceType >::reset ( )
virtual

Import the reset() overloads from the base class.

Implements bitrl::envs::EnvBase< TimeStepType, SpaceType >.

Member Data Documentation

◆ api_server_

template<typename TimeStepType , typename SpaceType >
network::RESTRLEnvClient* bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >::api_server_
protected

Server wrapper handling communication with remote Gymnasium environment.


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