5#ifndef LUNAR_LANDER_ENV_H
6#define LUNAR_LANDER_ENV_H
13#include "bitsim/extern/nlohmann/json/json.hpp"
21template <
typename TimeStepType,
typename SpaceType>
62 const std::string &uri);
78 make(
const std::string &
version,
const std::unordered_map<std::string, std::any> &options,
79 const std::unordered_map<std::string, std::any> &
reset_options)
override final;
99template <
typename TimeStepType,
typename SpaceType>
101 const std::string &name,
102 const std::string &uri)
108template <
typename TimeStepType,
typename SpaceType>
115template <
typename TimeStepType,
typename SpaceType>
117 const std::string &
version,
const std::unordered_map<std::string, std::any> &options,
118 const std::unordered_map<std::string, std::any> &
reset_options)
127 if (
auto gravity_itr = options.find(
"gravity"); gravity_itr != options.end())
129 auto gravity = std::any_cast<real_t>(gravity_itr->second);
130 ops[
"gravity"] = gravity;
133 if (
auto enable_wind_itr = options.find(
"enable_wind"); enable_wind_itr != options.end())
135 auto wind = std::any_cast<bool>(enable_wind_itr->second);
136 ops[
"enable_wind"] = wind;
139 if (
auto wind_power_itr = options.find(
"wind_power"); wind_power_itr != options.end())
141 auto wind_power = std::any_cast<real_t>(wind_power_itr->second);
142 ops[
"wind_power"] = wind_power;
145 if (
auto turbulence_power_itr = options.find(
"turbulence_power");
146 turbulence_power_itr != options.end())
148 auto turbulence_power = std::any_cast<real_t>(turbulence_power_itr->second);
149 ops[
"turbulence_power"] = turbulence_power;
154 auto idx = response[
"idx"];
160template <
typename TimeStepType,
typename SpaceType>
166 assert(this->
is_created() &&
"Environment has not been created");
171 return this->
reset();
180template <
typename TimeStepType,
typename SpaceType>
183 const nlohmann::json &response)
const
185 auto step_type = response[
"time_step"][
"step_type"].template get<uint_t>();
186 auto reward = response[
"time_step"][
"reward"];
187 auto discount = response[
"time_step"][
"discount"];
188 auto obs = response[
"time_step"][
"observation"];
189 auto info = response[
"time_step"][
"info"];
191 discount, std::unordered_map<std::string, std::any>());
201 TimeStep<std::vector<real_t>>, ContinuousVectorStateDiscreteActionEnv<8, 4, 0, real_t>>
212 static const std::string
URI;
269 TimeStep<std::vector<real_t>>,
270 ContinuousVectorStateContinuousVectorActionEnv<8, 2, real_t, real_t>>
281 static const std::string
URI;
Forward declaration.
Definition time_step.h:22
SpaceType::state_space state_space_type
Type describing the environment state space.
Definition env_base.h:45
SpaceType::state_type state_type
Type describing an individual state.
Definition env_base.h:48
const std::unordered_map< std::string, std::any > & reset_options() const noexcept
Access the configuration options provided to make().
Definition env_base.h:105
void set_idx_(const std::string &idx) noexcept
Set the id of the environment.
Definition env_base.h:175
SpaceType::action_space action_space_type
Type describing the environment action space.
Definition env_base.h:51
TimeStepType time_step_type
Alias for the type returned when stepping the environment.
Definition env_base.h:42
SpaceType::action_type action_type
Type representing an individual action.
Definition env_base.h:54
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.
Definition env_base.h:259
std::string version() const noexcept
Get the environment version set during make().
Definition env_base.h:143
time_step_type & get_current_time_step_() noexcept
Mutable access to the current time step.
Definition env_base.h:209
std::string idx() const noexcept
Get the id identifying this environment within a simulation batch. The id is valid only if make has b...
Definition env_base.h:125
void make_created_() noexcept
Mark environment creation as successful.
Definition env_base.h:206
bool is_created() const noexcept
Check if make() has successfully initialized the environment.
Definition env_base.h:131
std::string env_name() const noexcept
Get the name of this environment instance.
Definition env_base.h:137
GymnasiumEnvBase(network::RESTRLEnvClient &api_server, const std::string &name)
Constructor.
Definition gymnasium_env_base.h:139
EnvBase< TimeStepType, SpaceType > base_type
Base environment type alias.
Definition gymnasium_env_base.h:44
virtual time_step_type reset() override
Reset the environment to an initial state using the reset options specified during make.
Definition gymnasium_env_base.h:193
network::RESTRLEnvClient & get_api_server() const
Retrieve the REST API wrapper instance used for communication.
Definition gymnasium_env_base.h:98
base_type::action_space_type action_space_type
The type of the action space for the environment.
Definition lunar_lander_env.h:305
base_type::state_type state_type
The type of the state.
Definition lunar_lander_env.h:315
LunarLanderContinuousEnv(network::RESTRLEnvClient &api_server)
LunarLanderContinuousEnv(const LunarLanderContinuousEnv &other)
base_type::state_space_type state_space_type
The type describing the state space for the environment.
Definition lunar_lander_env.h:300
lunar_lander_detail::_LunarLanderEnv< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 8, 2, real_t, real_t > > base_type
Base class type.
Definition lunar_lander_env.h:289
base_type::action_type action_type
The type of the action to be undertaken in the environment.
Definition lunar_lander_env.h:310
~LunarLanderContinuousEnv() override=default
~Pendulum. Destructor
static const std::string name
name
Definition lunar_lander_env.h:276
base_type::time_step_type time_step_type
The time step type we return every time a step in the environment is performed.
Definition lunar_lander_env.h:295
static const std::string URI
The URI for accessing the environment.
Definition lunar_lander_env.h:281
base_type::state_type state_type
The type of the state.
Definition lunar_lander_env.h:245
static const std::string name
name
Definition lunar_lander_env.h:207
base_type::state_space_type state_space_type
The type describing the state space for the environment.
Definition lunar_lander_env.h:230
LunarLanderDiscreteEnv(network::RESTRLEnvClient &api_server)
lunar_lander_detail::_LunarLanderEnv< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 8, 4, 0, real_t > > base_type
Base class type.
Definition lunar_lander_env.h:219
base_type::time_step_type time_step_type
The time step type we return every time a step in the environment is performed.
Definition lunar_lander_env.h:225
~LunarLanderDiscreteEnv() override=default
~Pendulum. Destructor
base_type::action_space_type action_space_type
The type of the action space for the environment.
Definition lunar_lander_env.h:235
static const std::string URI
The URI for accessing the environment.
Definition lunar_lander_env.h:212
LunarLanderDiscreteEnv(const LunarLanderDiscreteEnv &other)
base_type::action_type action_type
The type of the action to be undertaken in the environment.
Definition lunar_lander_env.h:240
Definition lunar_lander_env.h:23
base_type::state_type state_type
The type of the state.
Definition lunar_lander_env.h:54
_LunarLanderEnv(const _LunarLanderEnv &other)
Definition lunar_lander_env.h:109
base_type::time_step_type time_step_type
The time step type we return every time a step in the environment is performed.
Definition lunar_lander_env.h:34
virtual time_step_type step(const action_type &action) override final
step. Step in the environment following the given action
Definition lunar_lander_env.h:162
~_LunarLanderEnv()=default
~Pendulum. Destructor
base_type::action_space_type action_space_type
The type of the action space for the environment.
Definition lunar_lander_env.h:44
uint_t n_actions() const noexcept
n_actions. Returns the number of actions
Definition lunar_lander_env.h:89
base_type::action_type action_type
The type of the action to be undertaken in the environment.
Definition lunar_lander_env.h:49
virtual time_step_type create_time_step_from_response_(const nlohmann::json &response) const override
build the time step from the server response
Definition lunar_lander_env.h:182
_LunarLanderEnv(network::RESTRLEnvClient &api_server, const std::string &name, const std::string &uri)
Definition lunar_lander_env.h:100
base_type::state_space_type state_space_type
The type describing the state space for the environment.
Definition lunar_lander_env.h:39
GymnasiumEnvBase< TimeStepType, SpaceType >::base_type base_type
Base class type.
Definition lunar_lander_env.h:28
virtual void make(const std::string &version, const std::unordered_map< std::string, std::any > &options, const std::unordered_map< std::string, std::any > &reset_options) override final
make. Build the environment
Definition lunar_lander_env.h:116
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
Definition rest_rl_env_client.h:28
void register_if_not(const std::string &name, const std::string &uri)
Same as register_new but swallows the thrown exception.
Definition lunar_lander_env.h:20
Definition lunar_lander_env.h:18
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
static TimeStepTp time_step_type_from_int(int aidx)
Definition env_types.h:106
Definition env_types.h:67