Below is the driver code.
#include <any>
#include <iostream>
#include <string>
#include <unordered_map>
{
const std::string
SERVER_URL =
"http://0.0.0.0:8001/api";
{
<< std::endl;
FrozenLake<4> env(server);
std::cout << "Is environment registered: " << server.is_env_registered(env.env_name())
<< std::endl;
std::cout << "Environment URL: " << env.get_url() << std::endl;
std::unordered_map<std::string, std::any> make_ops;
make_ops.insert({"is_slippery", false});
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({
"seed",
static_cast<uint_t>(42)});
env.make(
"v1", make_ops, reset_ops);
std::cout <<
"Environment version: " <<
env.version() << std::endl;
std::cout <<
"Environment idx is: " <<
env.idx() << std::endl;
std::cout <<
"Is environment created? " <<
env.is_created() << std::endl;
std::cout <<
"Is environment alive? " <<
env.is_alive() << std::endl;
std::cout <<
"Number of valid actions? " <<
env.n_actions() << std::endl;
std::cout <<
"Number of states? " <<
env.n_states() << std::endl;
auto n_copies =
env.n_copies();
std::cout << "n_copies: " << n_copies << std::endl;
auto time_step =
env.reset();
std::cout << "Reward on reset: " << time_step.reward() << std::endl;
std::cout << "Observation on reset: " << time_step.observation() << std::endl;
std::cout << "Is terminal state: " << time_step.done() << std::endl;
std::cout << time_step << std::endl;
auto new_time_step =
env.step(2);
std::cout << new_time_step << std::endl;
std::cout <<
"Dynamics for state=" <<
state <<
" and action=" <<
action << std::endl;
{
std::cout << std::get<0>(item) << std::endl;
std::cout << std::get<1>(item) << std::endl;
std::cout << std::get<2>(item) << std::endl;
std::cout << std::get<3>(item) << std::endl;
}
std::cout <<
"Action sampled: " <<
action << std::endl;
new_time_step =
env.step(action);
std::cout << new_time_step << std::endl;
}
{
<< std::endl;
std::cout <<
"Environment URL: " <<
env.get_url() << std::endl;
std::unordered_map<std::string, std::any> make_ops;
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({
"seed",
static_cast<uint_t>(42)});
env.make(
"v3", make_ops, reset_ops);
std::cout <<
"Environment version: " <<
env.version() << std::endl;
std::cout <<
"Environment idx is: " <<
env.idx() << std::endl;
std::cout <<
"Is environment created? " <<
env.is_created() << std::endl;
std::cout <<
"Is environment alive? " <<
env.is_alive() << std::endl;
std::cout <<
"Number of valid actions? " <<
env.n_actions() << std::endl;
std::cout <<
"Number of states? " <<
env.n_states() << std::endl;
auto time_step =
env.reset();
std::cout << "Reward on reset: " << time_step.reward() << std::endl;
std::cout << "Observation on reset: " << time_step.observation() << std::endl;
std::cout << "Is terminal state: " << time_step.done() << std::endl;
std::cout << time_step << std::endl;
auto new_time_step =
env.step(2);
std::cout << new_time_step << std::endl;
std::cout <<
"Dynamics for state=" <<
state <<
" and action=" <<
action << std::endl;
{
std::cout << std::get<0>(item) << std::endl;
std::cout << std::get<1>(item) << std::endl;
std::cout << std::get<2>(item) << std::endl;
std::cout << std::get<3>(item) << std::endl;
}
}
{
std::unordered_map<std::string, std::any> options;
options["natural"] = true;
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({
"seed",
static_cast<uint_t>(42)});
std::cout << "Environment created..." << std::endl;
env.make(
"v1", options, reset_ops);
std::cout << "Environment reset..." << std::endl;
std::cout << "Environment step..." << std::endl;
}
{
std::cout <<
"Environment URL: " <<
env.get_url() << std::endl;
std::unordered_map<std::string, std::any> options;
options[
"max_episode_steps"] = std::any(
static_cast<bitsim::uint_t>(10));
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({
"seed",
static_cast<uint_t>(42)});
env.make(
"v1", options, reset_ops);
std::cout <<
"Environment version: " <<
env.version() << std::endl;
std::cout <<
"Environment idx is: " <<
env.idx() << std::endl;
std::cout <<
"Is environment created? " <<
env.is_created() << std::endl;
std::cout <<
"Is environment alive? " <<
env.is_alive() << std::endl;
std::cout <<
"Number of valid actions? " <<
env.n_actions() << std::endl;
std::cout <<
"Number of states? " <<
env.n_states() << std::endl;
auto n_copies =
env.n_copies();
std::cout << "n_copies: " << n_copies << std::endl;
auto time_step =
env.reset();
std::cout << "Reward on reset: " << time_step.reward() << std::endl;
std::cout << "Observation on reset: " << time_step.observation() << std::endl;
std::cout << "Is terminal state: " << time_step.done() << std::endl;
std::cout << time_step << std::endl;
auto new_time_step =
env.step(0);
std::cout << new_time_step << std::endl;
std::cout <<
"Dynamics for state=" <<
state <<
" and action=" <<
action << std::endl;
{
std::cout << std::get<0>(item) << std::endl;
std::cout << std::get<1>(item) << std::endl;
std::cout << std::get<2>(item) << std::endl;
std::cout << std::get<3>(item) << std::endl;
}
}
}
{
std::cout << "Testing FrozenLake..." << std::endl;
std::cout << "====================" << std::endl;
std::cout << "Testing Taxi..." << std::endl;
std::cout << "====================" << std::endl;
std::cout << "Testing BlackJack..." << std::endl;
std::cout << "====================" << std::endl;
std::cout << "Testing CliffWorld..." << std::endl;
std::cout << "====================" << std::endl;
return 0;
}
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
Definition black_jack_env.h:66
The CliffWorld class.
Definition cliff_world_env.h:59
Definition frozen_lake_env.h:104
The Taxi class.
Definition taxi_env.h:24
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
Definition rest_rl_env_client.h:28
bool is_env_registered(const std::string &env_name) const noexcept
static const std::string name
name
Definition frozen_lake_env.h:109
int main()
Definition discounted_returns.cpp:19
Models of how things move: wheeled robots, a bicycle, a quadrotor and a fixed wing aircraft,...
Definition bicycle_vehicle_model_dynamics.cpp:10
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
Definition gymnasium_part_1.cpp:14
const std::string SERVER_URL
Definition gymnasium_part_1.cpp:17
void test_taxi(RESTRLEnvClient &server)
Definition gymnasium_part_1.cpp:111
void test_cliff_world(RESTRLEnvClient &server)
Definition gymnasium_part_1.cpp:206
void test_frozen_lake(RESTRLEnvClient &server)
Definition gymnasium_part_1.cpp:25
void test_black_jack(RESTRLEnvClient &server)
Definition gymnasium_part_1.cpp:179
dict action
Definition play.py:46
state
Definition play.py:39