https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
GenericActiveLearningSampler Class Reference

A generic sampler to support parallel active learning. More...

#include <GenericActiveLearningSampler.h>

Inheritance diagram for GenericActiveLearningSampler:
[legend]

Public Types

enum  SampleMode { SampleMode::GLOBAL, SampleMode::LOCAL }
 
typedef DataFileName DataFileParameterType
 

Public Member Functions

 GenericActiveLearningSampler (const InputParameters &parameters)
 
const std::vector< std::vector< Real > > & getSampleTries () const
 Return random samples for the GP to try in the reporter class. More...
 
dof_id_type getNumParallelProposals () const
 Return the number of parallel proposals. More...
 
std::vector< RealgetNextLocalRow ()
 
dof_id_type getNumberOfRows () const
 
dof_id_type getNumberOfCols () const
 
dof_id_type getNumberOfLocalRows () const
 
const LocalRankConfiggetRankConfig (bool batch_mode) const
 
virtual bool isAdaptiveSamplingCompleted () const
 
libMesh::Parallel::CommunicatorgetLocalComm ()
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool haveParameter (const std::string &name) const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void jacobianSetup ()
 
virtual void residualSetup ()
 
virtual void subdomainSetup ()
 
virtual void customSetup (const ExecFlagType &)
 
const ExecFlagEnumgetExecuteOnEnum () const
 
PerfGraphperfGraph ()
 
TgetSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
TgetSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name, bool needs_broadcast) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const VectorPostprocessorValuegetVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name, bool needs_broadcast) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValue (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOld (const std::string &param_name, const std::string &vector_name) const
 
const ScatterVectorPostprocessorValuegetScatterVectorPostprocessorValueOldByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name, const std::string &vector_name) const
 
bool hasVectorPostprocessor (const std::string &param_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name, const std::string &vector_name) const
 
bool hasVectorPostprocessorByName (const VectorPostprocessorName &name) const
 
const VectorPostprocessorName & getVectorPostprocessorName (const std::string &param_name) const
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetGlobalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
DenseMatrix< RealgetLocalSamples ()
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowBegin () const
 
dof_id_type getLocalRowEnd () const
 
dof_id_type getLocalRowEnd () const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistribution (const std::string &name) const
 
const TgetDistribution (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
const DistributiongetDistributionByName (const DistributionName &name) const
 
const TgetDistributionByName (const std::string &name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributed (const std::string &param_name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
bool isVectorPostprocessorDistributedByName (const VectorPostprocessorName &name) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
bool isImplicit ()
 
Moose::StateArg determineState () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 

Protected Member Functions

virtual void executeSetUp () override
 Gather all the samples. More...
 
virtual Real computeSample (dof_id_type row_index, dof_id_type col_index) override
 Return the sample for the given row and column. More...
 
void setNumberOfRandomSeeds (std::size_t number)
 
Real getRand (std::size_t n, unsigned int index=0) const
 
unsigned int getRandl (std::size_t n, unsigned int lower, unsigned int upper, unsigned int index=0) const
 
virtual LocalRankConfig constructRankConfig (bool batch_mode) const
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 
std::string timedSectionName (const std::string &section_name) const
 
virtual void addVectorPostprocessorDependencyHelper (const VectorPostprocessorName &) const
 
const ReporterContextBasegetReporterContextBaseByName (const ReporterName &reporter_name) const
 
const ReporterNamegetReporterName (const std::string &param_name) const
 
virtual void addReporterDependencyHelper (const ReporterName &)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfRows (dof_id_type n_rows)
 
void setNumberOfCols (dof_id_type n_cols)
 
void setNumberOfCols (dof_id_type n_cols)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeLocalSampleMatrix (DenseMatrix< Real > &matrix)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void computeSampleRow (dof_id_type i, std::vector< Real > &data)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerators (const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
virtual void advanceGenerator (const unsigned int seed_index, const dof_id_type count)
 
void setAutoAdvanceGenerators (const bool state)
 
void setAutoAdvanceGenerators (const bool state)
 
virtual void executeTearDown ()
 
virtual void executeTearDown ()
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, const std::size_t time_index=0)
 
const TgetReporterValue (const std::string &param_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, const std::size_t time_index=0)
 
const TgetReporterValueByName (const ReporterName &reporter_name, ReporterMode mode, const std::size_t time_index=0)
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValue (const std::string &param_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 
bool hasReporterValueByName (const ReporterName &reporter_name) const
 

Protected Attributes

std::vector< Distribution const * > _distributions
 Storage for distribution objects to be utilized. More...
 
const unsigned int _num_parallel_proposals
 Number of parallel proposals to be made and subApps to be executed. More...
 
const std::vector< unsigned int > & _sorted_indices
 The selected sample indices to evaluate the subApp. More...
 
const std::vector< Real > & _initial_values
 Initial values of the input params to get the MCMC scheme started. More...
 
std::vector< std::vector< Real > > _new_samples
 Vectors of new proposed samples. More...
 
const dof_id_type _min_procs_per_row
 
const dof_id_type _max_procs_per_row
 
libMesh::Parallel::Communicator _local_comm
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
const ExecFlagEnum_execute_enum
 
const ExecFlagType_current_execute_flag
 
MooseApp_pg_moose_app
 
const std::string _prefix
 
const Parallel::Communicator & _communicator
 
const InputParameters_ti_params
 
FEProblemBase_ti_feproblem
 
bool _is_implicit
 
Real_t
 
const Real_t_old
 
int_t_step
 
Real_dt
 
Real_dt_old
 
bool _is_transient
 

Private Attributes

const unsigned int _num_tries
 Number of samples to propose in each iteration (not all are sent for subApp evals) More...
 
std::vector< std::vector< Real > > _inputs_all
 Storage for all the proposed samples. More...
 

Detailed Description

A generic sampler to support parallel active learning.

Definition at line 19 of file GenericActiveLearningSampler.h.

Constructor & Destructor Documentation

◆ GenericActiveLearningSampler()

GenericActiveLearningSampler::GenericActiveLearningSampler ( const InputParameters parameters)

Definition at line 44 of file GenericActiveLearningSampler.C.

46  TransientInterface(this),
47  _num_parallel_proposals(getParam<unsigned int>("num_parallel_proposals")),
48  _sorted_indices(getReporterValue<std::vector<unsigned int>>("sorted_indices")),
49  _initial_values(getParam<std::vector<Real>>("initial_values")),
50  _num_tries(getParam<unsigned int>("num_tries"))
51 {
52  // Filling the `distributions` vector with the user-provided distributions.
53  for (const DistributionName & name : getParam<std::vector<DistributionName>>("distributions"))
55 
56  // Setting the number of sampler rows to be equal to the number of parallel proposals
58 
59  // Setting the number of columns in the sampler matrix (equal to the number of distributions)
61 
62  // Setting the sizes for the different vectors enabling sampling and selection
63  _inputs_all.resize(_num_tries, std::vector<Real>(_distributions.size(), 0.0));
65 
66  setNumberOfRandomSeeds(getParam<unsigned int>("num_random_seeds"));
68 }
void setNumberOfRows(dof_id_type n_rows)
const std::vector< unsigned int > & _sorted_indices
The selected sample indices to evaluate the subApp.
const T & getParam(const std::string &name) const
const InputParameters & parameters() const
Sampler(const InputParameters &parameters)
const T & getReporterValue(const std::string &param_name, const std::size_t time_index=0)
TransientInterface(const MooseObject *moose_object)
const std::string & name() const
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
const Distribution & getDistributionByName(const DistributionName &name) const
void setAutoAdvanceGenerators(const bool state)
void setNumberOfCols(dof_id_type n_cols)
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
std::vector< std::vector< Real > > _inputs_all
Storage for all the proposed samples.
const unsigned int _num_tries
Number of samples to propose in each iteration (not all are sent for subApp evals) ...
void setNumberOfRandomSeeds(std::size_t number)
std::vector< Distribution const * > _distributions
Storage for distribution objects to be utilized.

Member Function Documentation

◆ computeSample()

Real GenericActiveLearningSampler::computeSample ( dof_id_type  row_index,
dof_id_type  col_index 
)
overrideprotectedvirtual

Return the sample for the given row and column.

Implements Sampler.

Definition at line 104 of file GenericActiveLearningSampler.C.

105 {
106  if (_t_step < 1)
107  for (unsigned int i = 0; i < _num_parallel_proposals; ++i)
109 
110  return _new_samples[row_index][col_index];
111 }
const std::vector< Real > & _initial_values
Initial values of the input params to get the MCMC scheme started.
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.

◆ executeSetUp()

void GenericActiveLearningSampler::executeSetUp ( )
overrideprotectedvirtual

Gather all the samples.

Reimplemented from Sampler.

Definition at line 77 of file GenericActiveLearningSampler.C.

78 {
79  std::size_t rand_index = 0;
80  auto fill_vector = [&](std::vector<Real> & vector)
81  {
82  vector.resize(getNumberOfCols());
83  for (const auto j : make_range(getNumberOfCols()))
84  vector[j] = _distributions[j]->quantile(getRand(rand_index++, _t_step + 1));
85  };
86 
87  /* If step is 1, randomly generate the samples.
88  Else, generate the samples informed by the GP from the reporter "sorted_indices" */
89  for (const auto i : make_range(getNumberOfRows()))
90  {
91  if (_t_step <= 0)
92  fill_vector(_new_samples[i]);
93  else
95  }
96 
97  /* Finally, generate several new samples randomly for the GP to try and pass it to the
98  reporter */
99  for (const auto i : make_range(_num_tries))
100  fill_vector(_inputs_all[i]);
101 }
const std::vector< unsigned int > & _sorted_indices
The selected sample indices to evaluate the subApp.
Real getRand(std::size_t n, unsigned int index=0) const
dof_id_type getNumberOfRows() const
IntRange< T > make_range(T beg, T end)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
std::vector< std::vector< Real > > _new_samples
Vectors of new proposed samples.
dof_id_type getNumberOfCols() const
std::vector< std::vector< Real > > _inputs_all
Storage for all the proposed samples.
const unsigned int _num_tries
Number of samples to propose in each iteration (not all are sent for subApp evals) ...
std::vector< Distribution const * > _distributions
Storage for distribution objects to be utilized.

◆ getNumParallelProposals()

dof_id_type GenericActiveLearningSampler::getNumParallelProposals ( ) const
inline

Return the number of parallel proposals.

Definition at line 34 of file GenericActiveLearningSampler.h.

34 { return _num_parallel_proposals; }
const unsigned int _num_parallel_proposals
Number of parallel proposals to be made and subApps to be executed.

◆ getSampleTries()

const std::vector< std::vector< Real > > & GenericActiveLearningSampler::getSampleTries ( ) const

Return random samples for the GP to try in the reporter class.

Definition at line 71 of file GenericActiveLearningSampler.C.

72 {
73  return _inputs_all;
74 }
std::vector< std::vector< Real > > _inputs_all
Storage for all the proposed samples.

◆ validParams()

InputParameters GenericActiveLearningSampler::validParams ( )
static

Definition at line 17 of file GenericActiveLearningSampler.C.

18 {
20  params.addClassDescription("A generic sampler to support parallel active learning.");
21  params.addRequiredParam<unsigned int>(
22  "num_parallel_proposals",
23  "Number of proposals to make and corresponding subApps executed in "
24  "parallel.");
25  params.addRequiredParam<std::vector<DistributionName>>(
26  "distributions",
27  "The distribution names to be sampled, the number of distributions provided defines the "
28  "number of columns per matrix.");
30  "sorted_indices", "The sorted sample indices in order of importance to evaluate the subApp.");
31  params.addRequiredRangeCheckedParam<unsigned int>(
32  "num_tries",
33  "num_tries>0",
34  "Number of samples to propose in each iteration (not all are sent for subApp evals).");
35  params.addRequiredParam<std::vector<Real>>("initial_values",
36  "The starting values of the inputs to be calibrated.");
37  params.addParam<unsigned int>(
38  "num_random_seeds",
39  100000,
40  "Initialize a certain number of random seeds. Change from the default only if you have to.");
41  return params;
42 }
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _distributions

std::vector<Distribution const *> GenericActiveLearningSampler::_distributions
protected

Storage for distribution objects to be utilized.

Definition at line 43 of file GenericActiveLearningSampler.h.

Referenced by executeSetUp(), and GenericActiveLearningSampler().

◆ _initial_values

const std::vector<Real>& GenericActiveLearningSampler::_initial_values
protected

Initial values of the input params to get the MCMC scheme started.

Definition at line 52 of file GenericActiveLearningSampler.h.

Referenced by computeSample().

◆ _inputs_all

std::vector<std::vector<Real> > GenericActiveLearningSampler::_inputs_all
private

Storage for all the proposed samples.

Definition at line 62 of file GenericActiveLearningSampler.h.

Referenced by executeSetUp(), GenericActiveLearningSampler(), and getSampleTries().

◆ _new_samples

std::vector<std::vector<Real> > GenericActiveLearningSampler::_new_samples
protected

Vectors of new proposed samples.

Definition at line 55 of file GenericActiveLearningSampler.h.

Referenced by computeSample(), executeSetUp(), and GenericActiveLearningSampler().

◆ _num_parallel_proposals

const unsigned int GenericActiveLearningSampler::_num_parallel_proposals
protected

Number of parallel proposals to be made and subApps to be executed.

Definition at line 46 of file GenericActiveLearningSampler.h.

Referenced by computeSample(), GenericActiveLearningSampler(), and getNumParallelProposals().

◆ _num_tries

const unsigned int GenericActiveLearningSampler::_num_tries
private

Number of samples to propose in each iteration (not all are sent for subApp evals)

Definition at line 59 of file GenericActiveLearningSampler.h.

Referenced by executeSetUp(), and GenericActiveLearningSampler().

◆ _sorted_indices

const std::vector<unsigned int>& GenericActiveLearningSampler::_sorted_indices
protected

The selected sample indices to evaluate the subApp.

Definition at line 49 of file GenericActiveLearningSampler.h.

Referenced by executeSetUp().


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