QMCPACK
HybridEngine Class Reference
+ Collaboration diagram for HybridEngine:

Public Member Functions

 HybridEngine (Communicate *comm, const xmlNodePtr cur)
 
 HybridEngine ()
 
xmlNodePtr getSelectedXML ()
 
void incrementStepCounter ()
 
bool queryStore (int store_num, OptimizerType method_type) const
 
void addMethod (OptimizerType method)
 
void addUpdates (int num_steps)
 

Private Types

using FullPrecValueType = qmcplusplus::QMCTraits::FullPrecValueType
 
using ValueType = qmcplusplus::QMCTraits::ValueType
 

Private Member Functions

bool processXML (const xmlNodePtr cur)
 process xml node More...
 
int identifyMethodIndex () const
 

Private Attributes

CommunicatemyComm
 
int step_num_
 number of optimization steps taken More...
 
std::vector< OptimizerTypeopt_methods_
 list of methods known by hybrid More...
 
std::vector< xmlNodePtr > saved_xml_opt_methods_
 xml saved node More...
 
std::vector< int > num_updates_opt_methods_
 

Detailed Description

Definition at line 28 of file HybridEngine.h.

Member Typedef Documentation

◆ FullPrecValueType

◆ ValueType

Definition at line 31 of file HybridEngine.h.

Constructor & Destructor Documentation

◆ HybridEngine() [1/2]

HybridEngine ( Communicate comm,
const xmlNodePtr  cur 
)

Definition at line 24 of file HybridEngine.cpp.

References HybridEngine::processXML(), and HybridEngine::step_num_.

24  : myComm(comm)
25 {
26  step_num_ = -1;
27  processXML(cur);
28 }
int step_num_
number of optimization steps taken
Definition: HybridEngine.h:38
bool processXML(const xmlNodePtr cur)
process xml node

◆ HybridEngine() [2/2]

HybridEngine ( )
inline

Definition at line 60 of file HybridEngine.h.

References HybridEngine::step_num_.

60 { step_num_ = 0; }
int step_num_
number of optimization steps taken
Definition: HybridEngine.h:38

Member Function Documentation

◆ addMethod()

void addMethod ( OptimizerType  method)
inline

Definition at line 72 of file HybridEngine.h.

References HybridEngine::opt_methods_.

72 { opt_methods_.push_back(method); }
std::vector< OptimizerType > opt_methods_
list of methods known by hybrid
Definition: HybridEngine.h:44

◆ addUpdates()

void addUpdates ( int  num_steps)
inline

Definition at line 75 of file HybridEngine.h.

References HybridEngine::num_updates_opt_methods_.

75 { num_updates_opt_methods_.push_back(num_steps); }
std::vector< int > num_updates_opt_methods_
Definition: HybridEngine.h:50

◆ getSelectedXML()

xmlNodePtr getSelectedXML ( )

Definition at line 69 of file HybridEngine.cpp.

References HybridEngine::identifyMethodIndex(), and HybridEngine::saved_xml_opt_methods_.

70 {
72 }
std::vector< xmlNodePtr > saved_xml_opt_methods_
xml saved node
Definition: HybridEngine.h:47

◆ identifyMethodIndex()

int identifyMethodIndex ( ) const
private

Definition at line 109 of file HybridEngine.cpp.

References HybridEngine::num_updates_opt_methods_, and HybridEngine::step_num_.

Referenced by HybridEngine::getSelectedXML().

110 {
111  const int tot_micro_it = std::accumulate(num_updates_opt_methods_.begin(), num_updates_opt_methods_.end(), 0);
112  const int pos = step_num_ % tot_micro_it;
113 
114  int run_sum = 0;
115  int select_idx = 0;
116 
117  //Compare pos to running sum of microiterations of different methods to determine which method is being used
118  for (int i = 0; i < num_updates_opt_methods_.size(); i++)
119  {
120  run_sum += num_updates_opt_methods_[i];
121  if (run_sum > pos)
122  {
123  select_idx = i;
124  break;
125  }
126  }
127 
128  return select_idx;
129 }
std::vector< int > num_updates_opt_methods_
Definition: HybridEngine.h:50
int step_num_
number of optimization steps taken
Definition: HybridEngine.h:38

◆ incrementStepCounter()

void incrementStepCounter ( )
inline

Definition at line 66 of file HybridEngine.h.

References HybridEngine::step_num_.

66 {step_num_++;}
int step_num_
number of optimization steps taken
Definition: HybridEngine.h:38

◆ processXML()

bool processXML ( const xmlNodePtr  cur)
private

process xml node

Definition at line 31 of file HybridEngine.cpp.

References ParameterSet::add(), qmcplusplus::app_log(), getXMLAttributeValue(), HybridEngine::num_updates_opt_methods_, HybridEngine::opt_methods_, qmcplusplus::OptimizerNames, ParameterSet::put(), and HybridEngine::saved_xml_opt_methods_.

Referenced by HybridEngine::HybridEngine().

32 {
33  opt_methods_.clear();
34  saved_xml_opt_methods_.clear();
36 
37  xmlNodePtr cur = opt_xml->children;
38  while (cur != NULL)
39  {
40  std::string cname((const char*)(cur->name));
41  if (cname == "optimizer")
42  {
43  std::string children_MinMethod;
44  ParameterSet m_param;
45  m_param.add(children_MinMethod, "MinMethod");
46  m_param.put(cur);
47 
48  if (children_MinMethod.empty())
49  throw std::runtime_error("MinMethod must be given!\n");
50  std::string updates_string(getXMLAttributeValue(cur, "num_updates"));
51  app_log() << "HybridEngine saved MinMethod " << children_MinMethod << " num_updates = " << updates_string << '\n';
52  auto iter = OptimizerNames.find(children_MinMethod);
53  if (iter == OptimizerNames.end())
54  throw std::runtime_error("Unknown MinMethod!\n");
55  opt_methods_.push_back(iter->second);
56  saved_xml_opt_methods_.push_back(cur);
57  num_updates_opt_methods_.push_back(std::stoi(updates_string));
58  }
59  cur = cur->next;
60  }
61 
62  if (saved_xml_opt_methods_.size() != 2)
63  throw std::runtime_error("MinMethod hybrid needs two optimizer input blocks!\n");
64 
65  return true;
66 }
std::vector< xmlNodePtr > saved_xml_opt_methods_
xml saved node
Definition: HybridEngine.h:47
const std::map< std::string, OptimizerType > OptimizerNames
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< int > num_updates_opt_methods_
Definition: HybridEngine.h:50
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
class to handle a set of parameters
Definition: ParameterSet.h:27
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
std::vector< OptimizerType > opt_methods_
list of methods known by hybrid
Definition: HybridEngine.h:44

◆ queryStore()

bool queryStore ( int  store_num,
OptimizerType  method_type 
) const

Definition at line 75 of file HybridEngine.cpp.

References qmcplusplus::app_log(), HybridEngine::num_updates_opt_methods_, HybridEngine::opt_methods_, and HybridEngine::step_num_.

76 {
77  bool store = false;
78 
79  int idx = 0;
80 
81  auto iter = std::find(opt_methods_.begin(), opt_methods_.end(), method);
82  if (iter == opt_methods_.end())
83  throw std::runtime_error("Unknown MinMethod!\n");
84  else
85  idx = std::distance(opt_methods_.begin(), iter);
86 
87 
88  const int tot_micro_it = std::accumulate(num_updates_opt_methods_.begin(), num_updates_opt_methods_.end(), 0);
89  const int pos = step_num_ % tot_micro_it;
90  //interval is the number of steps between stores based on the number of stores desired
91  int interval = num_updates_opt_methods_[idx] / store_num;
92 
93  if (interval == 0)
94  {
95  app_log()
96  << "Requested Number of Stored Vectors greater than number of descent steps. Storing a vector on each step."
97  << std::endl;
98  interval = 1;
99  }
100  if ((pos + 1) % interval == 0)
101  {
102  store = true;
103  }
104 
105  return store;
106 }
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< int > num_updates_opt_methods_
Definition: HybridEngine.h:50
int step_num_
number of optimization steps taken
Definition: HybridEngine.h:38
std::vector< OptimizerType > opt_methods_
list of methods known by hybrid
Definition: HybridEngine.h:44

Member Data Documentation

◆ myComm

Communicate* myComm
private

Definition at line 34 of file HybridEngine.h.

◆ num_updates_opt_methods_

std::vector<int> num_updates_opt_methods_
private

◆ opt_methods_

std::vector<OptimizerType> opt_methods_
private

list of methods known by hybrid

Definition at line 44 of file HybridEngine.h.

Referenced by HybridEngine::addMethod(), HybridEngine::processXML(), and HybridEngine::queryStore().

◆ saved_xml_opt_methods_

std::vector<xmlNodePtr> saved_xml_opt_methods_
private

xml saved node

Definition at line 47 of file HybridEngine.h.

Referenced by HybridEngine::getSelectedXML(), and HybridEngine::processXML().

◆ step_num_

int step_num_
private

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