Skip to content

Commit

Permalink
Granular construction of SipOptionsValues
Browse files Browse the repository at this point in the history
Refactor in support of libqueso#569 to enable various layered
phases of constructing SipOptionsValues.  This mirrors work done in
EnvOptionsValues.

Also minor cleanup in EnvOptionsValues.
  • Loading branch information
briadam committed Oct 16, 2017
1 parent ecf0fa6 commit 3fa8b99
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 92 deletions.
5 changes: 1 addition & 4 deletions src/core/src/EnvironmentOptions.C
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ namespace QUESO {
EnvOptionsValues::EnvOptionsValues()
:
m_env(NULL)
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
, m_parser()
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
{
this->set_defaults();
this->set_prefix("");
Expand Down Expand Up @@ -264,7 +261,7 @@ EnvOptionsValues::parse(const BaseEnvironment& env, const std::string& prefix)
m_parser->scanInputFile();

// Retrieve parsed options
m_parser->getOption<std::string >(m_option_help, m_help);
m_parser->getOption<std::string>(m_option_help, m_help);
m_parser->getOption<unsigned int>(m_option_numSubEnvironments, m_numSubEnvironments);
m_parser->getOption<std::string>(m_option_subDisplayFileName, m_subDisplayFileName);
m_parser->getOption<bool>(m_option_subDisplayAllowAll, m_subDisplayAllowAll);
Expand Down
9 changes: 9 additions & 0 deletions src/stats/inc/StatisticalInverseProblemOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ class SipOptionsValues
/*! It assigns the same options values from \c src to \c this.*/
SipOptionsValues (const SipOptionsValues& src);

//! Set parameter option names to begin with prefix
void set_prefix(const std::string& prefix);

//! Set default values for parameter options
void set_defaults();

//! Given prefix, read the input file for parameters named "prefix"+*
void parse(const BaseEnvironment& env, const std::string& prefix);

//! Destructor
virtual ~SipOptionsValues ();
//@}
Expand Down
204 changes: 116 additions & 88 deletions src/stats/src/StatisticalInverseProblemOptions.C
Original file line number Diff line number Diff line change
Expand Up @@ -43,99 +43,18 @@ namespace QUESO {

// Default constructor -----------------------------
SipOptionsValues::SipOptionsValues()
:
m_prefix("ip_"),
m_help(UQ_SIP_HELP),
m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR),
m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR),
//m_dataOutputAllowedSet(),
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_parser(),
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_option_help (m_prefix + "help" ),
m_option_computeSolution (m_prefix + "computeSolution" ),
m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_option_solver (m_prefix + "solver" ),
m_solverString (UQ_SIP_SOLVER_ODV)
#endif
m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
{
this->set_defaults();
this->set_prefix("");
}

SipOptionsValues::SipOptionsValues(const BaseEnvironment * env, const char *
prefix)
:
m_prefix((std::string)(prefix) + "ip_"),
m_help(UQ_SIP_HELP),
m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR),
m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR),
//m_dataOutputAllowedSet(),
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_option_help (m_prefix + "help" ),
m_option_computeSolution (m_prefix + "computeSolution" ),
m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_option_solver (m_prefix + "solver" ),
m_solverString (UQ_SIP_SOLVER_ODV)
#endif
m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
SipOptionsValues::SipOptionsValues(const BaseEnvironment* env,
const char* prefix)
{
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_parser->registerOption<std::string>(m_option_help, UQ_SIP_HELP, "produce help message for statistical inverse problem");
m_parser->registerOption<bool >(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV , "compute solution process" );
m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_parser->registerOption<std::string>(m_option_solver, UQ_SIP_SOLVER_ODV , "algorithm for calibration" );
#endif
m_parser->registerOption<bool >(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR , "toggle for seeding chain at MAP" );
m_parser->registerOption<bool >(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR , "toggle for using optimizer monitor (prints diagnostics");

m_parser->scanInputFile();

m_parser->getOption<std::string>(m_option_help, m_help);
m_parser->getOption<bool >(m_option_computeSolution, m_computeSolution);
m_parser->getOption<std::string>(m_option_dataOutputFileName, m_dataOutputFileName);
m_parser->getOption<std::set<unsigned int> >(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet);
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_parser->getOption<std::string>(m_option_solver, m_solver);
#endif
m_parser->getOption<bool >(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator);
m_parser->getOption<bool >(m_option_useOptimizerMonitor, m_useOptimizerMonitor);
#else
m_help = env->input()(m_option_help, UQ_SIP_HELP);
m_computeSolution = env->input()(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV);
m_dataOutputFileName = env->input()(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV);

// UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default
unsigned int size = env->input().vector_variable_size(m_option_dataOutputAllowedSet);
for (unsigned int i = 0; i < size; i++) {
// We default to empty set, so the default values are actually never
// used here
unsigned int allowed = env->input()(m_option_dataOutputAllowedSet, i, i);
m_dataOutputAllowedSet.insert(allowed);
}

#ifdef UQ_SIP_READS_SOLVER_OPTION
m_solver = env->input()(m_option_solver, UQ_SIP_SOLVER_ODV);
#endif
m_seedWithMAPEstimator = env->input()(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR);
m_useOptimizerMonitor = env->input()(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR);
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

checkOptions();
this->set_defaults();
this->parse(*env, prefix);
}

// Copy constructor - -----------------------------
SipOptionsValues::SipOptionsValues(const SipOptionsValues& src)
{
Expand Down Expand Up @@ -189,4 +108,113 @@ operator<<(std::ostream& os, const SipOptionsValues & obj)
return os;
}


void
SipOptionsValues::set_defaults()
{
m_help = UQ_SIP_HELP;
m_computeSolution = UQ_SIP_COMPUTE_SOLUTION_ODV;
m_dataOutputFileName = UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV;
m_seedWithMAPEstimator = UQ_SIP_SEEDWITHMAPESTIMATOR;
m_useOptimizerMonitor = UQ_SIP_USEOPTIMIZERMONITOR;
//m_dataOutputAllowedSet()
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_solverString = UQ_SIP_SOLVER_ODV;
#endif
}

void
SipOptionsValues::set_prefix(const std::string& prefix)
{
m_prefix = prefix + "ip_";

m_option_help = m_prefix + "help";
m_option_computeSolution = m_prefix + "computeSolution";
m_option_dataOutputFileName = m_prefix + "dataOutputFileName";
m_option_dataOutputAllowedSet = m_prefix + "dataOutputAllowedSet";
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_option_solver = m_prefix + "solver";
#endif
m_option_seedWithMAPEstimator = m_prefix + "seedWithMAPEstimator";
m_option_useOptimizerMonitor = m_prefix + "useOptimizerMonitor";
}

void
SipOptionsValues::parse(const BaseEnvironment& env, const std::string& prefix)
{
this->set_prefix(prefix);

#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

m_parser.reset(new BoostInputOptionsParser(env.optionsInputFileName()));

m_parser->registerOption<std::string>
(m_option_help, m_help,
"produce help message for statistical inverse problem");
m_parser->registerOption<bool>
(m_option_computeSolution, m_computeSolution,
"compute solution process");
m_parser->registerOption<std::string>
(m_option_dataOutputFileName, m_dataOutputFileName,
"name of data output file");
m_parser->registerOption<std::string>
(m_option_dataOutputAllowedSet, container_to_string(m_dataOutputAllowedSet),
"subEnvs that will write to data output file");
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_parser->registerOption<std::string>
(m_option_solver, m_solver,
"algorithm for calibration");
#endif
m_parser->registerOption<bool>
(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator,
"toggle for seeding chain at MAP");
m_parser->registerOption<bool>
(m_option_useOptimizerMonitor, m_useOptimizerMonitor,
"toggle for using optimizer monitor (prints diagnostics");

m_parser->scanInputFile();

m_parser->getOption<std::string>(m_option_help, m_help);
m_parser->getOption<bool>(m_option_computeSolution, m_computeSolution);
m_parser->getOption<std::string>
(m_option_dataOutputFileName, m_dataOutputFileName);
m_parser->getOption<std::set<unsigned int> >
(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet);
#ifdef UQ_SIP_READS_SOLVER_OPTION
m_parser->getOption<std::string>(m_option_solver, m_solver);
#endif
m_parser->getOption<bool>
(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator);
m_parser->getOption<bool>
(m_option_useOptimizerMonitor, m_useOptimizerMonitor);

#else

m_help = env.input()(m_option_help, m_help);
m_computeSolution = env.input()(m_option_computeSolution, m_computeSolution);
m_dataOutputFileName = env.input()
(m_option_dataOutputFileName, m_dataOutputFileName);

// UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default
unsigned int size =
env.input().vector_variable_size(m_option_dataOutputAllowedSet);
for (unsigned int i = 0; i < size; i++) {
// We default to empty set, so the default values are actually never
// used here
unsigned int allowed = env.input()(m_option_dataOutputAllowedSet, i, i);
m_dataOutputAllowedSet.insert(allowed);
}

#ifdef UQ_SIP_READS_SOLVER_OPTION
m_solver = env.input()(m_option_solver, m_solver);
#endif
m_seedWithMAPEstimator = env.input()
(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator);
m_useOptimizerMonitor = env.input()
(m_option_useOptimizerMonitor, m_useOptimizerMonitor);
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

checkOptions();
}

} // End namespace QUESO

0 comments on commit 3fa8b99

Please sign in to comment.