OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Sampler Class Reference

#include <Sampler.h>

Inheritance diagram for Sampler:
Collaboration diagram for Sampler:

Public Types

typedef std::vector< SampleIndividualSolutionState_t
 type used in solution state exchange with other optimizers
typedef std::vector< std::pair< double, double > > bounds_t
 type of bounds for design variables

Public Member Functions

 Sampler (Expressions::Named_t objectives, Expressions::Named_t constraints, DVarContainer_t dvars, size_t dim, Comm::Bundle_t comms, CmdArguments_t args, std::vector< double > hypervolRef, int nrWorkerGroups)
 Sampler (const std::map< std::string, std::shared_ptr< SamplingMethod > > &sampleMethods, Expressions::Named_t objectives, DVarContainer_t dvars, Comm::Bundle_t comms, CmdArguments_t args)
virtual void initialize ()
 Initialization and start algorithm.

Protected Member Functions

bool onMessage (MPI_Status status, size_t length)
void postPoll ()
 executed after handling (if any) new request
void setupPoll ()
 executed before starting polling loop
void prePoll ()
 executed before checking for new request
void onStop ()
 enable implementation to react to STOP tag
void dispatch_forward_solves ()
virtual void run ()

Protected Attributes

MPI_Comm comm_m
 communicator the poller listens to requests
bool is_running_
double last_polled_
 time of last MPI_Test
double poll_delay_
 delay in seconds between polls

Private Types

enum  State { SUBMIT , STOP , TERMINATE }
typedef SampleIndividual Individual_t

Private Member Functions

void writeJsonHeader ()
void dumpIndividualsToJSON ()
void addIndividualToJSON (const std::shared_ptr< Individual_t > &ind)
void runStateMachine ()
void createNewIndividual ()

Private Attributes

std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
int gid
int my_local_pid_
Comm::Bundle_t comms_
 communicator bundle for the optimizer
std::map< size_t, std::shared_ptr< Individual_t > > jobmapping_m
 mapping from unique job ID to individual
std::queue< std::shared_ptr< Individual_t > > individuals_m
bounds_t dVarBounds_m
 bounds on each specified gene
DVarContainer_t dvars_m
 design variables
Expressions::Named_t objectives_m
 objectives
int nSamples_m
CmdArguments_t args_
 command line arguments specified by the user
int act_sample_m
 current generation
int done_sample_m
State curState_m
std::size_t jsonDumpFreq_m
 Dumps id, design variables and bound.
std::string jsonFname_m
std::list< Individual_tindividualsToDump_m

Detailed Description

Definition at line 50 of file Sampler.h.

Member Typedef Documentation

◆ bounds_t

typedef std::vector< std::pair<double, double> > Optimizer::bounds_t
inherited

type of bounds for design variables

Definition at line 39 of file Optimizer.h.

◆ Individual_t

Definition at line 116 of file Sampler.h.

◆ SolutionState_t

type used in solution state exchange with other optimizers

Definition at line 90 of file Sampler.h.

Member Enumeration Documentation

◆ State

enum Sampler::State
private
Enumerator
SUBMIT 
STOP 
TERMINATE 

Definition at line 146 of file Sampler.h.

Constructor & Destructor Documentation

◆ Sampler() [1/2]

Sampler::Sampler ( Expressions::Named_t objectives,
Expressions::Named_t constraints,
DVarContainer_t dvars,
size_t dim,
Comm::Bundle_t comms,
CmdArguments_t args,
std::vector< double > hypervolRef,
int nrWorkerGroups )

This constructor should never be called. It's provided due to the inheritance of SamplePilot from Pilot

Definition at line 38 of file Sampler.cpp.

References Optimizer::Optimizer().

Here is the call graph for this function:

◆ Sampler() [2/2]

Sampler::Sampler ( const std::map< std::string, std::shared_ptr< SamplingMethod > > & sampleMethods,
Expressions::Named_t objectives,
DVarContainer_t dvars,
Comm::Bundle_t comms,
CmdArguments_t args )

Retrieves all (for the sampler) relevant arguments specified on the command line, initializes the variator and sets up statistics and debug traces.

Parameters
[in]sampleMethodsper design variable (dvar)
[in]dvarsof sampling
[in]commsavailable to the sampler
[in]argsthe user passed on the command line

Definition at line 52 of file Sampler.cpp.

References args_, comms_, dVarBounds_m, dvars_m, CmdArguments::getArg(), jsonDumpFreq_m, jsonFname_m, my_local_pid_, objectives_m, Optimizer::Optimizer(), sampleMethods_m, and writeJsonHeader().

Here is the call graph for this function:

Member Function Documentation

◆ addIndividualToJSON()

void Sampler::addIndividualToJSON ( const std::shared_ptr< Individual_t > & ind)
private

Definition at line 294 of file Sampler.cpp.

References dumpIndividualsToJSON(), individualsToDump_m, and jsonDumpFreq_m.

Referenced by onMessage().

Here is the call graph for this function:

◆ createNewIndividual()

void Sampler::createNewIndividual ( )
private

Definition at line 192 of file Sampler.cpp.

References dvars_m, gid, individuals_m, and sampleMethods_m.

Referenced by postPoll().

◆ dispatch_forward_solves()

void Sampler::dispatch_forward_solves ( )
protected

Definition at line 339 of file Sampler.cpp.

References act_sample_m, comms_, dvars_m, individuals_m, jobmapping_m, MPI_Send_params(), and OPT_NEW_JOB_TAG.

Referenced by runStateMachine().

Here is the call graph for this function:

◆ dumpIndividualsToJSON()

void Sampler::dumpIndividualsToJSON ( )
private

Definition at line 241 of file Sampler.cpp.

References dvars_m, SampleIndividual::genes, SampleIndividual::getIndex(), SampleIndividual::id, individualsToDump_m, jsonFname_m, name, SampleIndividual::objectives, and objectives_m.

Referenced by addIndividualToJSON(), and runStateMachine().

Here is the call graph for this function:

◆ initialize()

void Sampler::initialize ( )
virtual

Initialization and start algorithm.

Implements Optimizer.

Definition at line 94 of file Sampler.cpp.

References act_sample_m, args_, comms_, curState_m, done_sample_m, gid, nSamples_m, Poller::run(), and SUBMIT.

Here is the call graph for this function:

◆ onMessage()

bool Sampler::onMessage ( MPI_Status status,
size_t recv_value )
protectedvirtual

User specific behavior on receiving a message.

Returns
boolean indicating if Irecv has to be re-posted

Implements Optimizer.

Definition at line 131 of file Sampler.cpp.

References addIndividualToJSON(), comms_, done_sample_m, jobmapping_m, MPI_Recv_reqvars(), and REQUEST_FINISHED.

Here is the call graph for this function:

◆ onStop()

void Sampler::onStop ( )
inlineprotectedvirtual

enable implementation to react to STOP tag

Implements Optimizer.

Definition at line 100 of file Sampler.h.

◆ postPoll()

void Sampler::postPoll ( )
protectedvirtual

executed after handling (if any) new request

Implements Optimizer.

Definition at line 182 of file Sampler.cpp.

References act_sample_m, createNewIndividual(), nSamples_m, and runStateMachine().

Here is the call graph for this function:

◆ prePoll()

void Sampler::prePoll ( )
inlineprotectedvirtual

executed before checking for new request

Implements Optimizer.

Definition at line 99 of file Sampler.h.

◆ run()

virtual void Poller::run ( )
inlineprotectedvirtualinherited

The poll loop stops when receiving a 'MPI_STOP_TAG' otherwise passes message to user.

Reimplemented in Pilot< Opt_t, Sim_t, SolPropagationGraph_t, Comm_t >.

Definition at line 79 of file Poller.h.

References comm_m, is_running_, last_polled_, MPI_STOP_TAG, onMessage(), onStop(), poll_delay_, postPoll(), prePoll(), and setupPoll().

Referenced by Sampler::initialize(), SampleWorker< Sim_t >::SampleWorker(), and Worker< Sim_t >::Worker().

Here is the call graph for this function:

◆ runStateMachine()

void Sampler::runStateMachine ( )
private

Definition at line 303 of file Sampler.cpp.

References act_sample_m, comms_, curState_m, dispatch_forward_solves(), done_sample_m, dumpIndividualsToJSON(), MPI_OPT_CONVERGED_TAG, nSamples_m, STOP, SUBMIT, and TERMINATE.

Referenced by postPoll().

Here is the call graph for this function:

◆ setupPoll()

void Sampler::setupPoll ( )
inlineprotectedvirtual

executed before starting polling loop

Implements Optimizer.

Definition at line 98 of file Sampler.h.

◆ writeJsonHeader()

void Sampler::writeJsonHeader ( )
private

Definition at line 217 of file Sampler.cpp.

References bounds(), dVarBounds_m, dvars_m, Util::getGitRevision(), and jsonFname_m.

Referenced by Sampler().

Here is the call graph for this function:

Member Data Documentation

◆ act_sample_m

int Sampler::act_sample_m
private

current generation

Definition at line 142 of file Sampler.h.

Referenced by dispatch_forward_solves(), initialize(), postPoll(), and runStateMachine().

◆ args_

CmdArguments_t Sampler::args_
private

command line arguments specified by the user

Definition at line 139 of file Sampler.h.

Referenced by initialize(), and Sampler().

◆ comm_m

MPI_Comm Poller::comm_m
protectedinherited

◆ comms_

Comm::Bundle_t Sampler::comms_
private

communicator bundle for the optimizer

Definition at line 119 of file Sampler.h.

Referenced by dispatch_forward_solves(), initialize(), onMessage(), runStateMachine(), and Sampler().

◆ curState_m

State Sampler::curState_m
private

Definition at line 152 of file Sampler.h.

Referenced by initialize(), and runStateMachine().

◆ done_sample_m

int Sampler::done_sample_m
private

Definition at line 144 of file Sampler.h.

Referenced by initialize(), onMessage(), and runStateMachine().

◆ dVarBounds_m

bounds_t Sampler::dVarBounds_m
private

bounds on each specified gene

Definition at line 127 of file Sampler.h.

Referenced by Sampler(), and writeJsonHeader().

◆ dvars_m

DVarContainer_t Sampler::dvars_m
private

design variables

Definition at line 130 of file Sampler.h.

Referenced by createNewIndividual(), dispatch_forward_solves(), dumpIndividualsToJSON(), Sampler(), and writeJsonHeader().

◆ gid

int Sampler::gid
private

Definition at line 112 of file Sampler.h.

Referenced by createNewIndividual(), and initialize().

◆ individuals_m

std::queue<std::shared_ptr<Individual_t> > Sampler::individuals_m
private

Definition at line 124 of file Sampler.h.

Referenced by createNewIndividual(), and dispatch_forward_solves().

◆ individualsToDump_m

std::list<Individual_t> Sampler::individualsToDump_m
private

Definition at line 158 of file Sampler.h.

Referenced by addIndividualToJSON(), and dumpIndividualsToJSON().

◆ is_running_

bool Poller::is_running_
protectedinherited

◆ jobmapping_m

std::map<size_t, std::shared_ptr<Individual_t> > Sampler::jobmapping_m
private

mapping from unique job ID to individual

Definition at line 122 of file Sampler.h.

Referenced by dispatch_forward_solves(), and onMessage().

◆ jsonDumpFreq_m

std::size_t Sampler::jsonDumpFreq_m
private

Dumps id, design variables and bound.

Definition at line 155 of file Sampler.h.

Referenced by addIndividualToJSON(), and Sampler().

◆ jsonFname_m

std::string Sampler::jsonFname_m
private

Definition at line 156 of file Sampler.h.

Referenced by dumpIndividualsToJSON(), Sampler(), and writeJsonHeader().

◆ last_polled_

double Poller::last_polled_
protectedinherited

time of last MPI_Test

Definition at line 57 of file Poller.h.

Referenced by Poller(), and run().

◆ my_local_pid_

int Sampler::my_local_pid_
private

Definition at line 114 of file Sampler.h.

Referenced by Sampler().

◆ nSamples_m

int Sampler::nSamples_m
private

Definition at line 135 of file Sampler.h.

Referenced by initialize(), postPoll(), and runStateMachine().

◆ objectives_m

Expressions::Named_t Sampler::objectives_m
private

objectives

Definition at line 133 of file Sampler.h.

Referenced by dumpIndividualsToJSON(), and Sampler().

◆ poll_delay_

double Poller::poll_delay_
protectedinherited

delay in seconds between polls

Definition at line 59 of file Poller.h.

Referenced by Poller(), and run().

◆ sampleMethods_m

std::map<std::string, std::shared_ptr<SamplingMethod> > Sampler::sampleMethods_m
private

Definition at line 109 of file Sampler.h.

Referenced by createNewIndividual(), and Sampler().


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