NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MainStep Class Reference

Main step to manage an algorithm executable. More...

#include <MainStep.hpp>

Inheritance diagram for MainStep:
Collaboration diagram for MainStep:

Public Member Functions

 MainStep ()
 Constructor. More...
 
 ~MainStep ()
 Destructor. More...
 
void setParamFileName (const std::string &paramFileName)
 
void setAllParameters (const std::shared_ptr< AllParameters > &allParams)
 
void setEvaluator (std::unique_ptr< Evaluator > ev)
 
std::shared_ptr< SubproblemgetCurrentSubproblem () const
 Get the subproblem that is currently treated. More...
 
void addAlgo (const std::shared_ptr< Step > algo)
 
void clearAlgos ()
 
void start () override
 Start NOMAD. More...
 
bool run () override
 
void end () override
 
void displayUsage (const char *exeName)
 Helper function called by the code main function if necessary. More...
 
void displayVersion ()
 Helper function called by the code main function if necessary. More...
 
void displayInfo ()
 Helper function called by the code main function if necessary. More...
 
void displayHelp (const std::string &helpSubject="all", bool devHelp=false)
 Helper function called by the code main function if necessary. More...
 
void hotRestartOnUserInterrupt () override
 
- Public Member Functions inherited from Step
 Step ()
 Constructor #1 for MainStep (no parent) More...
 
 Step (const Step *parentStep, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #2 for child step of a parent sharing the same stopReason. More...
 
 Step (const Step *parentStep, std::shared_ptr< AllStopReasons > stopReasons, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
 Constructor #3: for a child Step with a provided stopReason (such as an algorithm) More...
 
virtual ~Step ()
 Destructor. More...
 
const StepgetParentStep () const
 Get the parent step. More...
 
virtual const std::string getName () const
 Get the name of this step. More...
 
void setName (const std::string &name)
 Set the name of this step. More...
 
std::shared_ptr< AllStopReasonsgetAllStopReasons () const
 
void addCallback (const NOMAD::CallbackType &callbackType, const NOMAD::StepEndCbFunc &stepEndCbFunc)
 Set user callback. More...
 
void addCallback (const NOMAD::CallbackType &callbackType, const NOMAD::HotRestartCbFunc &hotRestartCbFunc)
 
void AddOutputInfo (const std::string &s, bool isBlockStart, bool isBlockEnd) const
 display output More...
 
void AddOutputInfo (const std::string &s, OutputLevel outputLevel=OutputLevel::LEVEL_INFO) const
 
void AddOutputError (const std::string &s) const
 
void AddOutputWarning (const std::string &s) const
 
void AddOutputVeryHigh (const std::string &s) const
 
void AddOutputHigh (const std::string &s) const
 
void AddOutputDebug (const std::string &s) const
 
void AddOutputInfo (OutputInfo outputInfo) const
 
template<typename T >
const StepgetParentOfType (const bool stopAtAlgo=true) const
 Template function to get the parent of given type. More...
 
bool isAnAlgorithm () const
 
const std::shared_ptr< MeshBasegetIterationMesh () const
 
const std::shared_ptr< EvalPointgetIterationFrameCenter () const
 
const std::shared_ptr< BarriergetMegaIterationBarrier () const
 
Point getSubFixedVariable () const
 

Static Public Member Functions

static void setAlgoComment (const std::string &algoComment)
 
static const std::string & getAlgoComment ()
 
static void resetPreviousAlgoComment ()
 
- Static Public Member Functions inherited from Step
static bool getUserTerminate ()
 Interruption call by user. More...
 
static void setUserTerminate ()
 Interruption requested. More...
 
static void userInterrupt (int signalValue)
 Interruption call by user with a signal value. More...
 
static bool getUserInterrupt ()
 
static void runCallback (NOMAD::CallbackType callbackType, const NOMAD::Step &step, bool &stop)
 Run user callback. More...
 
static void runCallback (NOMAD::CallbackType callbackType, std::vector< std::string > &paramLines)
 

Private Member Functions

void init ()
 Helper for constructor. More...
 
int getNumThreads () const
 Helper function when creating the evaluator. More...
 
void setNumThreads () const
 Set the number of threads for the evaluator. More...
 
void printNumThreads () const
 
bool detectPhaseOne ()
 Detect if a Phase One search is required. More...
 
void createCache () const
 Helper for start. More...
 
void updateX0sFromCache () const
 Helper for start. More...
 

Private Attributes

std::string _paramFileName
 The file containing the parameters. More...
 
std::shared_ptr< AllParameters_allParams
 
std::unique_ptr< Evaluator_evaluator
 Used in library running mode (not batch mode) More...
 
std::vector< std::shared_ptr
< Step > > 
_algos
 
std::vector< Subproblem_subproblems
 Subproblem definition. More...
 

Static Private Attributes

static std::string _algoComment
 Comment to appear in the stats, e.g. "Phase One". More...
 
static std::string _prevAlgoComment
 Comment to appear in the stats. Used when going back to the main algo after running a sub-algo. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Step
void verifyParentNotNull ()
 Helper for constructors. More...
 
void verifyGenerateAllPointsBeforeEval (const std::string &method, const bool expected) const
 Helper for validating steps depending on parameter GENERATE_ALL_POINTS_BEFORE_EVAL. More...
 
void init ()
 Helper for constructors. More...
 
void defaultStart ()
 
bool defaultRun ()
 
void defaultEnd ()
 
void hotRestartBeginHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 
void hotRestartEndHelper ()
 Helpers for hot restart, to be called at the start and end of any override. More...
 
- Protected Attributes inherited from Step
const Step_parentStep
 The parent of this step. More...
 
std::string _name
 The name of this step. More...
 
std::shared_ptr< AllStopReasons_stopReasons
 The stop reasons of an algorithm. More...
 
std::shared_ptr< RunParameters_runParams
 The run parameters that control a step. More...
 
std::shared_ptr< PbParameters_pbParams
 The problem parameters that control a step. More...
 
- Static Protected Attributes inherited from Step
static bool _userInterrupt
 Interrupt NOMAD if Ctrl-C is pressed. More...
 
static bool _userTerminate
 Terminate NOMAD if Ctrl-C is pressed again. More...
 
static NOMAD::StepEndCbFunc _cbIterationEnd
 
static NOMAD::StepEndCbFunc _cbMegaIterationEnd
 
static NOMAD::HotRestartCbFunc _cbHotRestart
 

Detailed Description

Main step to manage an algorithm executable.

MainStep is the root step of an executable running an algorithm. Think of it as a wrapper around the algorithm. MainStep manages all algorithm needs: Parameters, Evaluator and has utility functions (ex. displayUsage). MainStep takes care of the OpenMP parallelism.

Definition at line 27 of file MainStep.hpp.

Constructor & Destructor Documentation

MainStep::MainStep ( )
inlineexplicit

Constructor.

Definition at line 46 of file MainStep.hpp.

47  : Step( ),
48  _paramFileName(""),
49  _evaluator(nullptr),
50  _algos(),
51  _subproblems()
52  {
53  init();
54  }
void init()
Helper for constructor.
Step()
Constructor #1 for MainStep (no parent)
Definition: Step.hpp:51
std::vector< std::shared_ptr< Step > > _algos
Definition: MainStep.hpp:33
std::string _paramFileName
The file containing the parameters.
Definition: MainStep.hpp:30
std::unique_ptr< Evaluator > _evaluator
Used in library running mode (not batch mode)
Definition: MainStep.hpp:32
std::vector< Subproblem > _subproblems
Subproblem definition.
Definition: MainStep.hpp:41
MainStep::~MainStep ( )

Destructor.

Member Function Documentation

void MainStep::addAlgo ( const std::shared_ptr< Step algo)
inline

Once all algos have been added are executed (call start, run and end for each algo) in the MainStep::run.

Definition at line 99 of file MainStep.hpp.

99 { _algos.push_back(algo); }
std::vector< std::shared_ptr< Step > > _algos
Definition: MainStep.hpp:33
void MainStep::clearAlgos ( )
inline

Definition at line 101 of file MainStep.hpp.

101 { _algos.clear(); }
std::vector< std::shared_ptr< Step > > _algos
Definition: MainStep.hpp:33
void MainStep::createCache ( ) const
private

Helper for start.

bool MainStep::detectPhaseOne ( )
private

Detect if a Phase One search is required.

A phase one search is required if an EB type constraint is not feasible for X0.

void MainStep::displayHelp ( const std::string &  helpSubject = "all",
bool  devHelp = false 
)

Helper function called by the code main function if necessary.

void MainStep::displayInfo ( )

Helper function called by the code main function if necessary.

void MainStep::displayUsage ( const char *  exeName)

Helper function called by the code main function if necessary.

void MainStep::displayVersion ( )

Helper function called by the code main function if necessary.

void MainStep::end ( )
overridevirtual

Calls the default end of a step.

Reimplemented from Step.

static const std::string& MainStep::getAlgoComment ( )
inlinestatic

Definition at line 82 of file MainStep.hpp.

82 { return _algoComment; }
static std::string _algoComment
Comment to appear in the stats, e.g. &quot;Phase One&quot;.
Definition: MainStep.hpp:34
std::shared_ptr<Subproblem> MainStep::getCurrentSubproblem ( ) const

Get the subproblem that is currently treated.

Currently, there is only one.

Todo:
Generalize subproblem management.
int MainStep::getNumThreads ( ) const
private

Helper function when creating the evaluator.

void MainStep::hotRestartOnUserInterrupt ( )
overridevirtual

The user has requested a hot restart. Update the parameters with the changes requested by the user (read file or set inline).

Reimplemented from Step.

void MainStep::init ( )
private

Helper for constructor.

void MainStep::printNumThreads ( ) const
private
static void MainStep::resetPreviousAlgoComment ( )
inlinestatic

Definition at line 103 of file MainStep.hpp.

104  {
106  }
static std::string _prevAlgoComment
Comment to appear in the stats. Used when going back to the main algo after running a sub-algo...
Definition: MainStep.hpp:35
static std::string _algoComment
Comment to appear in the stats, e.g. &quot;Phase One&quot;.
Definition: MainStep.hpp:34
bool MainStep::run ( )
overridevirtual

Once all algos have been added are executed (call start, run and end for each algo) in the MainStep::run.
If a stop reason (not the default STARTED) is propagated to the MainStep, the sequence of algos is stopped.

Reimplemented from Step.

static void MainStep::setAlgoComment ( const std::string &  algoComment)
inlinestatic

Definition at line 76 of file MainStep.hpp.

77  {
79  _algoComment = algoComment;
80  }
static std::string _prevAlgoComment
Comment to appear in the stats. Used when going back to the main algo after running a sub-algo...
Definition: MainStep.hpp:35
static std::string _algoComment
Comment to appear in the stats, e.g. &quot;Phase One&quot;.
Definition: MainStep.hpp:34
void MainStep::setAllParameters ( const std::shared_ptr< AllParameters > &  allParams)
void MainStep::setEvaluator ( std::unique_ptr< Evaluator ev)
inline

The evaluator is unique. All algorithms must use the same evaluator.

Definition at line 74 of file MainStep.hpp.

74 { _evaluator = std::move(ev);}
std::unique_ptr< Evaluator > _evaluator
Used in library running mode (not batch mode)
Definition: MainStep.hpp:32
void MainStep::setNumThreads ( ) const
private

Set the number of threads for the evaluator.

void MainStep::setParamFileName ( const std::string &  paramFileName)
inline

In batch mode: Set the parameter file name, which will be read in start(). In library mode: Set the parameters directly using set_PARAM_NAME(...). In library mode, it is also possible to read a parameter file.

Definition at line 67 of file MainStep.hpp.

67 { _paramFileName = paramFileName;}
std::string _paramFileName
The file containing the parameters.
Definition: MainStep.hpp:30
void MainStep::start ( )
overridevirtual

Start NOMAD.

During the main step start, the parameters are read (if parameter file is available), the cache, the evaluator and the evaluator control are created. If an algorithm is set for run in the parameter file, it is added ( MainStep::addAlgo ).

Reimplemented from Step.

void MainStep::updateX0sFromCache ( ) const
private

Helper for start.

Member Data Documentation

std::string MainStep::_algoComment
staticprivate

Comment to appear in the stats, e.g. "Phase One".

Definition at line 34 of file MainStep.hpp.

std::vector<std::shared_ptr<Step> > MainStep::_algos
private

Definition at line 33 of file MainStep.hpp.

std::shared_ptr<AllParameters> MainStep::_allParams
private

Definition at line 31 of file MainStep.hpp.

std::unique_ptr<Evaluator> MainStep::_evaluator
private

Used in library running mode (not batch mode)

Definition at line 32 of file MainStep.hpp.

std::string MainStep::_paramFileName
private

The file containing the parameters.

Definition at line 30 of file MainStep.hpp.

std::string MainStep::_prevAlgoComment
staticprivate

Comment to appear in the stats. Used when going back to the main algo after running a sub-algo.

Definition at line 35 of file MainStep.hpp.

std::vector<Subproblem> MainStep::_subproblems
private

Subproblem definition.

Todo:
Generalize / make an array to handle multiple subproblems

Definition at line 41 of file MainStep.hpp.


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