bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
ppo_parallel_rollouts::ParallelEnvs< EnvType > Class Template Reference

Several copies of an environment, stepped at the same time on the threads of a bitsim::utils::concurrency::ThreadPool. More...

#include <parallel_envs.h>

Public Types

typedef EnvType env_type
typedef EnvType::time_step_type time_step_type
typedef EnvType::state_type state_type
typedef EnvType::action_type action_type

Public Member Functions

template<typename... Args>
 ParallelEnvs (uint_t n, Args &&...args)
 n copies, each built with args
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)
 Make every copy with the same options; copy i resets first with the seed task_seed(seed, i), where seed is the reset option "seed" (42 if not given).
const std::vector< time_step_type > & reset ()
 Start a new episode in every copy, each with its next seed.
const std::vector< time_step_type > & step (const std::vector< action_type > &actions)
 Step every copy whose episode is not over with its action.
uint_t size () const noexcept
bool done (uint_t i) const
 Whether the episode of copy i is over.
bool all_done () const
 Whether the episode of every copy is over.
const std::vector< time_step_type > & time_steps () const noexcept
EnvType & env (uint_t i)
const EnvType & env (uint_t i) const
void set_pool (bitsim::utils::concurrency::ThreadPool &pool) noexcept
 Step on the threads of pool, the default pool if not set.
void use_threads (bool threads) noexcept
 Step on threads, or on this thread one copy after the other.
bool is_created () const noexcept
void close ()
 Close every copy.

Detailed Description

template<typename EnvType>
class ppo_parallel_rollouts::ParallelEnvs< EnvType >

Several copies of an environment, stepped at the same time on the threads of a bitsim::utils::concurrency::ThreadPool.

step() takes an action per copy and steps every copy whose episode is not over; a copy whose episode is over keeps its last time step, and ignores its action, until the next reset(). Every copy is an environment of its own, so the copies share nothing, and what they do does not depend on the threads: a run with one thread is the same as one with many.

Stepping on threads pays off for environments that take time: a physics engine, a server over the network. For a cheap environment, step them on this thread, with use_threads(false); what is left to gain then is in acting for all the copies at once, as ParallelPPOSolver does.

Template Parameters
EnvTypean environment in the form of bitrl::envs::EnvBase

Member Typedef Documentation

◆ action_type

template<typename EnvType>
typedef EnvType::action_type bitrl::envs::ParallelEnvs< EnvType >::action_type

◆ env_type

template<typename EnvType>
typedef EnvType bitrl::envs::ParallelEnvs< EnvType >::env_type

◆ state_type

template<typename EnvType>
typedef EnvType::state_type bitrl::envs::ParallelEnvs< EnvType >::state_type

◆ time_step_type

template<typename EnvType>
typedef EnvType::time_step_type bitrl::envs::ParallelEnvs< EnvType >::time_step_type

Constructor & Destructor Documentation

◆ ParallelEnvs()

template<typename EnvType>
template<typename... Args>
bitrl::envs::ParallelEnvs< EnvType >::ParallelEnvs ( uint_t n,
Args &&... args )
explicit

n copies, each built with args

Member Function Documentation

◆ all_done()

template<typename EnvType>
bool bitrl::envs::ParallelEnvs< EnvType >::all_done ( ) const

Whether the episode of every copy is over.

◆ close()

template<typename EnvType>
void bitrl::envs::ParallelEnvs< EnvType >::close ( )

Close every copy.

◆ done()

template<typename EnvType>
bool bitrl::envs::ParallelEnvs< EnvType >::done ( uint_t i) const
inline

Whether the episode of copy i is over.

◆ env() [1/2]

template<typename EnvType>
EnvType & bitrl::envs::ParallelEnvs< EnvType >::env ( uint_t i)
inline

◆ env() [2/2]

template<typename EnvType>
const EnvType & bitrl::envs::ParallelEnvs< EnvType >::env ( uint_t i) const
inline

◆ is_created()

template<typename EnvType>
bool bitrl::envs::ParallelEnvs< EnvType >::is_created ( ) const
inlinenoexcept

◆ make()

template<typename EnvType>
void bitrl::envs::ParallelEnvs< EnvType >::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 )

Make every copy with the same options; copy i resets first with the seed task_seed(seed, i), where seed is the reset option "seed" (42 if not given).

◆ reset()

template<typename EnvType>
const std::vector< typename ParallelEnvs< EnvType >::time_step_type > & bitrl::envs::ParallelEnvs< EnvType >::reset ( )

Start a new episode in every copy, each with its next seed.

◆ set_pool()

template<typename EnvType>
void bitrl::envs::ParallelEnvs< EnvType >::set_pool ( bitsim::utils::concurrency::ThreadPool & pool)
inlinenoexcept

Step on the threads of pool, the default pool if not set.

◆ size()

template<typename EnvType>
uint_t bitrl::envs::ParallelEnvs< EnvType >::size ( ) const
inlinenoexcept

◆ step()

template<typename EnvType>
const std::vector< typename ParallelEnvs< EnvType >::time_step_type > & bitrl::envs::ParallelEnvs< EnvType >::step ( const std::vector< action_type > & actions)

Step every copy whose episode is not over with its action.

◆ time_steps()

template<typename EnvType>
const std::vector< time_step_type > & bitrl::envs::ParallelEnvs< EnvType >::time_steps ( ) const
inlinenoexcept

◆ use_threads()

template<typename EnvType>
void bitrl::envs::ParallelEnvs< EnvType >::use_threads ( bool threads)
inlinenoexcept

Step on threads, or on this thread one copy after the other.


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