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

Base class interface for Reinforcement Learning environments. More...

#include <env_base.h>

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

Public Types

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 ~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 void close ()=0
 Close and release any acquired environment resources.
 
virtual time_step_type reset ()=0
 Reset the environment to an initial state using the reset options specified during make.
 
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().
 

Static Public Attributes

static const uint_t DEFAULT_ENV_SEED = 42
 Default seed used in reset() if none provided.
 

Protected Member Functions

 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.
 

Detailed Description

template<typename TimeStepType, typename SpaceType>
class bitrl::envs::EnvBase< TimeStepType, SpaceType >

Base class interface for Reinforcement Learning environments.

This class defines the minimum API contract that any RL environment must implement. It exposes functionality for creating, resetting, and stepping through an environment, while tracking configuration such as version, options, and current state.

Template Parameters
TimeStepTypeType returned after each environment step
SpaceTypeEnvironment's space interface type providing state and action space definitions

Member Typedef Documentation

◆ action_space_type

template<typename TimeStepType , typename SpaceType >
typedef SpaceType::action_space bitrl::envs::EnvBase< TimeStepType, SpaceType >::action_space_type

Type describing the environment action space.

◆ action_type

template<typename TimeStepType , typename SpaceType >
typedef SpaceType::action_type bitrl::envs::EnvBase< TimeStepType, SpaceType >::action_type

Type representing an individual action.

◆ state_space_type

template<typename TimeStepType , typename SpaceType >
typedef SpaceType::state_space bitrl::envs::EnvBase< TimeStepType, SpaceType >::state_space_type

Type describing the environment state space.

◆ state_type

template<typename TimeStepType , typename SpaceType >
typedef SpaceType::state_type bitrl::envs::EnvBase< TimeStepType, SpaceType >::state_type

Type describing an individual state.

◆ time_step_type

template<typename TimeStepType , typename SpaceType >
typedef TimeStepType bitrl::envs::EnvBase< TimeStepType, SpaceType >::time_step_type

Alias for the type returned when stepping the environment.

Constructor & Destructor Documentation

◆ ~EnvBase()

template<typename TimeStepType , typename SpaceType >
virtual bitrl::envs::EnvBase< TimeStepType, SpaceType >::~EnvBase ( )
virtualdefault

Virtual destructor.

◆ EnvBase() [1/2]

template<typename TimeStepType , typename SpaceType >
EnvBase::EnvBase ( const std::string &  idx = bitrl::consts::INVALID_STR,
const std::string &  name = bitrl::consts::INVALID_STR 
)
explicitprotected

Constructor (protected — for subclassing only).

Parameters
cidxCopy index used in multi-environment simulations
nameName of the environment instance

◆ EnvBase() [2/2]

template<typename TimeStepType , typename SpaceType >
EnvBase::EnvBase ( const EnvBase< TimeStepType, SpaceType > &  other)
protected

Copy constructor.

Member Function Documentation

◆ close()

template<typename TimeStepType , typename SpaceType >
void EnvBase::close ( )
pure virtual

Close and release any acquired environment resources.

Implemented in bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousScalarBoundedActionEnv< 3, 1, RealRange<-2.0, 2.0 >, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 8, 2, real_t, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 3, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 6, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 8, 4, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< uint_t > >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< uint_t >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStep< detail_::AcrobotVEnv::state_type >, detail_::AcrobotVEnv >, bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStepType, SpaceType >, bitrl::envs::connect2::Connect2, bitrl::envs::gdrl::GymWalk< state_size >, bitrl::envs::grid_world::Gridworld< side_size_ >, and bitrl::envs::bandits::MultiArmedBandits.

◆ env_name()

template<typename TimeStepType , typename SpaceType >
std::string bitrl::envs::EnvBase< TimeStepType, SpaceType >::env_name ( ) const
inlinenoexcept

Get the name of this environment instance.

Returns
Environment name

◆ get_current_time_step_() [1/2]

template<typename TimeStepType , typename SpaceType >
const time_step_type & bitrl::envs::EnvBase< TimeStepType, SpaceType >::get_current_time_step_ ( ) const
inlineprotectednoexcept

Read-only access to the current time step.

◆ get_current_time_step_() [2/2]

template<typename TimeStepType , typename SpaceType >
time_step_type & bitrl::envs::EnvBase< TimeStepType, SpaceType >::get_current_time_step_ ( )
inlineprotectednoexcept

Mutable access to the current time step.

◆ idx()

template<typename TimeStepType , typename SpaceType >
std::string bitrl::envs::EnvBase< TimeStepType, SpaceType >::idx ( ) const
inlinenoexcept

Get the id identifying this environment within a simulation batch. The id is valid only if make has been called.

Returns
Copy index

◆ invalidate_is_created_flag_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::invalidate_is_created_flag_ ( )
inlineprotectednoexcept

Mark environment as not created.

◆ is_created()

template<typename TimeStepType , typename SpaceType >
bool bitrl::envs::EnvBase< TimeStepType, SpaceType >::is_created ( ) const
inlinenoexcept

Check if make() has successfully initialized the environment.

Returns
True if environment is ready, false otherwise

◆ make()

template<typename TimeStepType , typename SpaceType >
void EnvBase::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 
)
pure virtual

Construct the environment instance.

Parameters
versionVersion string used to control environment variant
make_optionsKey-value configuration options for environment creation.
reset_optionsKey-value configuration how the environment should be reset
Note
Derived classes should use set_version_() and set_make_options_() internally. They may store selected options for later use.

Implemented in bitrl::envs::gymnasium::Taxi, bitrl::envs::gymnasium::Pendulum, bitrl::envs::gymnasium::AcrobotV, bitrl::envs::connect2::Connect2, bitrl::envs::gdrl::GymWalk< state_size >, bitrl::envs::grid_world::Gridworld< side_size_ >, bitrl::envs::gymnasium::lunar_lander_detail::_LunarLanderEnv< TimeStepType, SpaceType >, bitrl::envs::gymnasium::lunar_lander_detail::_LunarLanderEnv< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 8, 2, real_t, real_t > >, bitrl::envs::gymnasium::lunar_lander_detail::_LunarLanderEnv< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 8, 4, 0, real_t > >, bitrl::envs::gymnasium::Acrobot, bitrl::envs::gymnasium::CartPole, bitrl::envs::gymnasium::MountainCar, bitrl::envs::gymnasium::BlackJack, bitrl::envs::gymnasium::CliffWorld, bitrl::envs::gymnasium::FrozenLake< side_size >, bitrl::envs::bandits::MultiArmedBandits, bitrl::envs::gymnasium::GymnasiumVecEnvBase< VectorTimeStepType, SpaceType >, and bitrl::envs::gymnasium::GymnasiumVecEnvBase< VectorTimeStep< detail_::AcrobotVEnv::state_type >, detail_::AcrobotVEnv >.

◆ make_created_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::make_created_ ( )
inlineprotectednoexcept

Mark environment creation as successful.

◆ make_options()

template<typename TimeStepType , typename SpaceType >
const std::unordered_map< std::string, std::any > & bitrl::envs::EnvBase< TimeStepType, SpaceType >::make_options ( ) const
inlinenoexcept

Access the configuration options provided to make().

Returns
Map of option keys and values

◆ read_option()

template<typename TimeStepType , typename SpaceType >
template<typename T >
T EnvBase::read_option ( const std::string &  op_name) const

Read a specific make() option and cast it to the requested type.

Template Parameters
TExpected data type
Parameters
op_nameKey of the option to read
Returns
Requested value if present
Exceptions
std::bad_any_castIf stored type does not match T

◆ reset()

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

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

Returns
Initial time step after reset

Implemented in bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousScalarBoundedActionEnv< 3, 1, RealRange<-2.0, 2.0 >, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 8, 2, real_t, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 3, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 6, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 8, 4, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< uint_t > >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< uint_t >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStep< detail_::AcrobotVEnv::state_type >, detail_::AcrobotVEnv >, bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStepType, SpaceType >, bitrl::envs::connect2::Connect2, bitrl::envs::gdrl::GymWalk< state_size >, bitrl::envs::grid_world::Gridworld< side_size_ >, bitrl::envs::bandits::MultiArmedBandits, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, SpaceType >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousScalarBoundedActionEnv< 3, 1, RealRange<-2.0, 2.0 >, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 8, 2, real_t, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 3, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 6, 2, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 8, 4, 0, real_t > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< std::vector< uint_t > >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStep< uint_t >, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >, bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStep< detail_::AcrobotVEnv::state_type >, detail_::AcrobotVEnv >, and bitrl::envs::gymnasium::GymnasiumEnvBase< VectorTimeStepType, SpaceType >.

◆ reset_options()

template<typename TimeStepType , typename SpaceType >
const std::unordered_map< std::string, std::any > & bitrl::envs::EnvBase< TimeStepType, SpaceType >::reset_options ( ) const
inlinenoexcept

Access the configuration options provided to make().

Returns
Map of option keys and values

◆ set_idx_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::set_idx_ ( const std::string &  idx)
inlineprotectednoexcept

Set the id of the environment.

Parameters
idx

◆ set_make_options_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::set_make_options_ ( const std::unordered_map< std::string, std::any > &  options)
inlineprotectednoexcept

Store options for future access.

◆ set_reset_options_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::set_reset_options_ ( const std::unordered_map< std::string, std::any > &  options)
inlineprotectednoexcept

Store reset options for future access.

◆ set_version_()

template<typename TimeStepType , typename SpaceType >
void bitrl::envs::EnvBase< TimeStepType, SpaceType >::set_version_ ( const std::string &  version)
inlineprotectednoexcept

Set internal version string.

Note
Should be called only inside make()

◆ step()

◆ version()

template<typename TimeStepType , typename SpaceType >
std::string bitrl::envs::EnvBase< TimeStepType, SpaceType >::version ( ) const
inlinenoexcept

Get the environment version set during make().

Returns
Version string

Member Data Documentation

◆ DEFAULT_ENV_SEED

template<typename TimeStepType , typename SpaceType >
const uint_t bitrl::envs::EnvBase< TimeStepType, SpaceType >::DEFAULT_ENV_SEED = 42
static

Default seed used in reset() if none provided.


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