bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end > Class Template Reference

ToyTextEnvBase class. Base class for toy environments from Gymnasium. These environments have a discrete action and state spaces. More...

#include <toy_text_base.h>

Inheritance diagram for bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >:
Collaboration diagram for bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >:

Public Types

typedef GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >::base_type base_type
 The base_type.
typedef base_type::time_step_type time_step_type
 The time step type we return every time a step in the environment is performed.
typedef base_type::state_space_type state_space_type
 The type describing the state space for the environment.
typedef base_type::action_space_type action_space_type
 The type of the action space for the environment.
typedef base_type::action_type action_type
 The type of the action to be undertaken in the environment.
typedef base_type::state_type state_type
 The type of the state.
typedef std::vector< std::tuple< real_t, uint_t, real_t, bool > > dynamics_t
 dynamics_t
Public Types inherited from bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
typedef EnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > > 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, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
typedef TimeStepType time_step_type
 Alias for the type returned when stepping the environment.
typedef ScalarDiscreteEnv< state_end, action_end, 0, 0 >::state_space state_space_type
 Type describing the environment state space.
typedef ScalarDiscreteEnv< state_end, action_end, 0, 0 >::state_type state_type
 Type describing an individual state.
typedef ScalarDiscreteEnv< state_end, action_end, 0, 0 >::action_space action_space_type
 Type describing the environment action space.
typedef ScalarDiscreteEnv< state_end, action_end, 0, 0 >::action_type action_type
 Type representing an individual action.
Public Types inherited from bitrl::envs::ScalarDiscreteEnv< state_end, action_end, 0, 0 >
typedef ScalarDiscreteSpace< state_start, state_end > state_space
 item_t
typedef state_space::space_item_type state_type
 the State type
typedef ScalarDiscreteSpace< action_start, action_end > action_space
 the action space type
typedef action_space::space_item_type action_type
 the Action type

Public Member Functions

virtual ~ToyTextEnvBase ()=default
 ~FrozenLake. Destructor.
dynamics_t p (uint_t sidx, uint_t aidx) const
 P.
uint_t n_actions () const noexcept
 n_actions. Returns the number of actions
uint_t n_states () const noexcept
 Number of states.
Public Member Functions inherited from bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
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::RESTRLEnvClient & get_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.
Public Member Functions inherited from bitrl::envs::EnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
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().
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().
uint_t last_reset_seed () const noexcept
 The seed of the latest reset(), for the environments that take one. The first reset after make() uses the "seed" reset option, or DEFAULT_ENV_SEED, and every reset after it the next seed, so that the episodes start differently and a run is the same every time.

Protected Member Functions

 ToyTextEnvBase (network::RESTRLEnvClient &api_server, const std::string &name)
 Constructor.
 ToyTextEnvBase (const ToyTextEnvBase &other)
 Copy constructor.
virtual dynamics_t build_dynamics_from_response_ (const nlohmann::json &response) const
 build the dynamics from response
Protected Member Functions inherited from bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
 GymnasiumEnvBase (network::RESTRLEnvClient &api_server, const std::string &name)
 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, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
 EnvBase (const std::string &idx=bitsim::consts::INVALID_STR, const std::string &name=bitsim::consts::INVALID_STR)
 Constructor (protected — for subclassing only).
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.
uint_t next_reset_seed_ ()
 The seed for the next reset: the "seed" reset option, or DEFAULT_ENV_SEED, plus the number of resets since make().
void invalidate_is_created_flag_ () noexcept
 Mark environment as not created.
void make_created_ () noexcept
 Mark environment creation as successful.
time_step_type & get_current_time_step_ () noexcept
 Mutable access to the current time step.

Additional Inherited Members

Static Public Member Functions inherited from bitrl::envs::ScalarDiscreteEnv< state_end, action_end, 0, 0 >
static action_type sample_action ()
 sample
Static Public Attributes inherited from bitrl::envs::EnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
static constexpr uint_t DEFAULT_ENV_SEED
 Default seed used in reset() if none provided.
Static Public Attributes inherited from bitrl::envs::ScalarDiscreteEnv< state_end, action_end, 0, 0 >
static constexpr uint_t STATE_SPACE_SIZE
 state space size
static constexpr uint_t ACTION_SPACE_SIZE
 action space size
Protected Attributes inherited from bitrl::envs::gymnasium::GymnasiumEnvBase< TimeStepType, ScalarDiscreteEnv< state_end, action_end, 0, 0 > >
network::RESTRLEnvClient * api_server_
 Server wrapper handling communication with remote Gymnasium environment.

Detailed Description

template<typename TimeStepType, uint_t state_end, uint_t action_end>
class bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >

ToyTextEnvBase class. Base class for toy environments from Gymnasium. These environments have a discrete action and state spaces.

Member Typedef Documentation

◆ action_space_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef base_type::action_space_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::action_space_type

The type of the action space for the environment.

◆ action_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef base_type::action_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::action_type

The type of the action to be undertaken in the environment.

◆ base_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef GymnasiumEnvBase<TimeStepType,ScalarDiscreteEnv<state_end,action_end,0,0>>::base_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::base_type

The base_type.

◆ dynamics_t

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef std::vector<std::tuple<real_t, uint_t, real_t, bool> > bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::dynamics_t

◆ state_space_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef base_type::state_space_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::state_space_type

The type describing the state space for the environment.

◆ state_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef base_type::state_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::state_type

The type of the state.

◆ time_step_type

template<typename TimeStepType, uint_t state_end, uint_t action_end>
typedef base_type::time_step_type bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::time_step_type

The time step type we return every time a step in the environment is performed.

Constructor & Destructor Documentation

◆ ~ToyTextEnvBase()

template<typename TimeStepType, uint_t state_end, uint_t action_end>
virtual bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::~ToyTextEnvBase ( )
virtualdefault

~FrozenLake. Destructor.

◆ ToyTextEnvBase() [1/2]

template<typename TimeStepType, uint_t state_end, uint_t action_end>
bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::ToyTextEnvBase ( network::RESTRLEnvClient & api_server,
const std::string & name )
protected

Constructor.

◆ ToyTextEnvBase() [2/2]

template<typename TimeStepType, uint_t state_end, uint_t action_end>
bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::ToyTextEnvBase ( const ToyTextEnvBase< TimeStepType, state_end, action_end > & other)
protected

Copy constructor.

Member Function Documentation

◆ build_dynamics_from_response_()

template<typename TimeStepType, uint_t state_end, uint_t action_end>
ToyTextEnvBase< TimeStepType, state_end, action_end >::dynamics_t bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::build_dynamics_from_response_ ( const nlohmann::json & response) const
protectedvirtual

build the dynamics from response

Reimplemented in bitrl::envs::gymnasium::BlackJack, and gymnasium_part_1::BlackJack.

◆ n_actions()

template<typename TimeStepType, uint_t state_end, uint_t action_end>
uint_t bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::n_actions ( ) const
inlinenoexcept

n_actions. Returns the number of actions

◆ n_states()

template<typename TimeStepType, uint_t state_end, uint_t action_end>
uint_t bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::n_states ( ) const
inlinenoexcept

Number of states.

◆ p()

template<typename TimeStepType, uint_t state_end, uint_t action_end>
ToyTextEnvBase< TimeStepType, state_end, action_end >::dynamics_t bitrl::envs::gymnasium::ToyTextEnvBase< TimeStepType, state_end, action_end >::p ( uint_t sidx,
uint_t aidx ) const

P.

Parameters
sidx
aidx

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