bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
ppo_distributed Namespace Reference

Classes

struct  ActorImpl
struct  CriticImpl
struct  Networks
struct  Rank
class  ParallelEnvs
 Several copies of an environment, stepped at the same time on the threads of a bitsim::utils::concurrency::ThreadPool. More...
class  CartPole
 The cart-pole of Barto, Sutton and Anderson, simulated in this process with bitsim::dynamics::CartPoleDynamics. More...
class  TorchCategorical
class  Communicator
 How the ranks of a distributed training exchange numbers. More...
class  TCPStoreCommunicator
 A Communicator through c10d::TCPStore, the key-value store that comes with libtorch. More...

Typedefs

using steady = std::chrono::steady_clock
using real_t
 real_t
typedef torch::Tensor torch_tensor_t
 torch_tensor_t
using uint_t
 uint_t

Functions

 TORCH_MODULE (Actor)
 TORCH_MODULE (Critic)
pg::PPOConfig ppo_config (uint_t n_rounds)
real_t greedy_return (Actor &actor)
real_t seconds (steady::duration d)
real_t tail_mean (const std::vector< real_t > &v)
Rank train_rank (Communicator &communicator, Networks &nets, uint_t n_rounds, uint_t n_copies)
Rank one_thread (uint_t n_rounds, uint_t n_copies)
void report (const std::string &name, const Rank &r)
bool compare (const std::string &title, uint_t n_episodes, uint_t n_ranks, uint_t n_copies, uint_t port)
int run_threads (uint_t n_episodes, uint_t n_ranks, uint_t n_copies, uint_t port)
int run_rank (uint_t rank, uint_t n_episodes, uint_t n_ranks, uint_t n_copies, const std::string &host, uint_t port)
uint_t task_seed (uint_t base_seed, uint_t task) noexcept
 A seed for task task, made from base_seed.

Variables

const uint_t SEED = 42
const uint_t MAX_STEPS = 500
const real_t LEARNING_RATE = 0.001

Typedef Documentation

◆ real_t

◆ steady

using ppo_distributed::steady = std::chrono::steady_clock

◆ torch_tensor_t

typedef torch::Tensor bitrl::torch_tensor_t

◆ uint_t

Function Documentation

◆ compare()

bool ppo_distributed::compare ( const std::string & title,
uint_t n_episodes,
uint_t n_ranks,
uint_t n_copies,
uint_t port )

◆ greedy_return()

real_t ppo_distributed::greedy_return ( Actor & actor)

◆ one_thread()

Rank ppo_distributed::one_thread ( uint_t n_rounds,
uint_t n_copies )

◆ ppo_config()

pg::PPOConfig ppo_distributed::ppo_config ( uint_t n_rounds)

◆ report()

void ppo_distributed::report ( const std::string & name,
const Rank & r )

◆ run_rank()

int ppo_distributed::run_rank ( uint_t rank,
uint_t n_episodes,
uint_t n_ranks,
uint_t n_copies,
const std::string & host,
uint_t port )

◆ run_threads()

int ppo_distributed::run_threads ( uint_t n_episodes,
uint_t n_ranks,
uint_t n_copies,
uint_t port )

◆ seconds()

real_t ppo_distributed::seconds ( steady::duration d)

◆ tail_mean()

real_t ppo_distributed::tail_mean ( const std::vector< real_t > & v)

◆ task_seed()

uint_t bitsim::utils::concurrency::task_seed ( uint_t base_seed,
uint_t task )
inlinenoexcept

A seed for task task, made from base_seed.

Tasks that draw random numbers need a generator each, since sharing one between threads is a data race. Seeding them with base_seed + task gives generators whose first numbers are alike; this mixes the two numbers with SplitMix64, so that every task gets an unrelated seed that still depends only on base_seed and task.

◆ TORCH_MODULE() [1/2]

ppo_distributed::TORCH_MODULE ( Actor )

◆ TORCH_MODULE() [2/2]

ppo_distributed::TORCH_MODULE ( Critic )

◆ train_rank()

Rank ppo_distributed::train_rank ( Communicator & communicator,
Networks & nets,
uint_t n_rounds,
uint_t n_copies )

Variable Documentation

◆ LEARNING_RATE

const real_t ppo_distributed::LEARNING_RATE = 0.001

◆ MAX_STEPS

const uint_t ppo_distributed::MAX_STEPS = 500

◆ SEED

const uint_t ppo_distributed::SEED = 42