QMCPACK
ProjectData Class Reference

class ProjectData More...

+ Collaboration diagram for ProjectData:

Public Types

enum  DriverVersion { LEGACY, BATCH }
 Enum for global scope switch of design from legacy driver based to batch driver based. More...
 

Public Member Functions

 ProjectData (const std::string &atitle="", DriverVersion de=DriverVersion::LEGACY)
 constructor More...
 
bool get (std::ostream &os) const
 
bool put (std::istream &is)
 
bool put (xmlNodePtr cur)
 
void reset ()
 Construct the root name with title_ and m_series. More...
 
void advance ()
 increment a series number and reset project_root_ More...
 
void rewind ()
 roll-back a series number and reset project_root_ by one More...
 
void setCommunicator (Communicate *c)
 
const std::string & getTitle () const noexcept
 returns the title of the project <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to title_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers" More...
 
const std::string & currentMainRoot () const noexcept
 returns the projectmain of the project, the series id is incremented at every QMC section <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to project_main_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers.s000" More...
 
const std::string & nextRoot () const noexcept
 returns the nextroot of the project, the series id is incremented at every QMC section <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to project_main_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers.s001" More...
 
bool previousRoot (std::string &oldroot) const
 return the root of the previous sequence More...
 
int getSeriesIndex () const noexcept
 
int getMaxCPUSeconds () const noexcept
 
DriverVersion getDriverVersion () const noexcept
 
bool isComplex () const noexcept
 
const RuntimeOptionsgetRuntimeOptions () const noexcept
 

Static Private Member Functions

static DriverVersion lookupDriverVersion (const std::string &enum_value)
 

Private Attributes

std::string title_
 title of the project More...
 
std::string host_
 name of the host where the job is running More...
 
std::string date_
 date when the job is executed More...
 
std::string project_main_
 main root for all the output engines More...
 
std::string project_root_
 processor-dependent root for all the output engines More...
 
std::string next_root_
 root for the next run More...
 
int series_
 series index More...
 
Communicatemy_comm_
 communicator More...
 
xmlNodePtr cur_
 the xml node for <Project> More...
 
int max_cpu_secs_
 max cpu seconds More...
 
DriverVersion driver_version_
 
RuntimeOptions runtime_options_
 

Static Private Attributes

static const std::unordered_map< std::string, DriverVersionlookup_input_enum_value
 

Detailed Description

class ProjectData

Encapsulate data for a project

Default: title_ = getDateAndTime("%Y%m%dT%H%M")

Todo:
This shouldn't contain MPI information it is only used to calculate the path information and the communication parameters should just be input params to that call.

This reduce the internal state.

Definition at line 36 of file ProjectData.h.

Member Enumeration Documentation

◆ DriverVersion

enum DriverVersion
strong

Enum for global scope switch of design from legacy driver based to batch driver based.

This effects more than just which drivers are used. Currently it just effects the meaning of qmc section vmc, dmc, linear name attributes.

Enumerator
LEGACY 
BATCH 

Definition at line 43 of file ProjectData.h.

44  {
45  LEGACY,
46  BATCH
47  };

Constructor & Destructor Documentation

◆ ProjectData()

ProjectData ( const std::string &  atitle = "",
ProjectData::DriverVersion  driver_version = DriverVersion::LEGACY 
)

constructor

Definition at line 35 of file ProjectData.cpp.

References OHMMS::Controller, getDateAndTime(), ProjectData::my_comm_, and ProjectData::title_.

36  : title_(atitle),
37  host_("none"),
38  date_("none"),
39  series_(0),
40  cur_(NULL),
41  max_cpu_secs_(360000),
42  driver_version_(driver_version),
43  runtime_options_(RuntimeOptions())
44 {
46  if (title_.empty())
47  title_ = getDateAndTime("%Y%m%dT%H%M");
48 }
DriverVersion driver_version_
Definition: ProjectData.h:147
string getDateAndTime()
Definition: sysutil.cpp:31
int series_
series index
Definition: ProjectData.h:135
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Communicate * my_comm_
communicator
Definition: ProjectData.h:138
std::string date_
date when the job is executed
Definition: ProjectData.h:123
int max_cpu_secs_
max cpu seconds
Definition: ProjectData.h:144
xmlNodePtr cur_
the xml node for <Project>
Definition: ProjectData.h:141
std::string host_
name of the host where the job is running
Definition: ProjectData.h:120
RuntimeOptions runtime_options_
Definition: ProjectData.h:150
std::string title_
title of the project
Definition: ProjectData.h:117

Member Function Documentation

◆ advance()

void advance ( )

increment a series number and reset project_root_

Definition at line 81 of file ProjectData.cpp.

References ProjectData::reset(), and ProjectData::series_.

Referenced by QMCMain::runQMC().

82 {
83  series_++;
84  reset();
85 }
int series_
series index
Definition: ProjectData.h:135
void reset()
Construct the root name with title_ and m_series.
Definition: ProjectData.cpp:97

◆ currentMainRoot()

const std::string & currentMainRoot ( ) const
noexcept

returns the projectmain of the project, the series id is incremented at every QMC section <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to project_main_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers.s000"

Definition at line 253 of file ProjectData.cpp.

References ProjectData::project_main_.

Referenced by QMCMain::execute(), QMCDriverNew::get_root_name(), QMCMain::runQMC(), and QMCAppBase::saveXml().

253 { return project_main_; }
std::string project_main_
main root for all the output engines
Definition: ProjectData.h:126

◆ get()

bool get ( std::ostream &  os) const

Definition at line 52 of file ProjectData.cpp.

References getDateAndTime(), ProjectData::host_, and ProjectData::title_.

Referenced by QMCMain::validateXML().

53 {
54  os << " Project = " << title_ << "\n";
55  os << " date = " << getDateAndTime("%Y-%m-%d %H:%M:%S %Z\n");
56  os << " host = " << host_ << "\n";
57  return true;
58 }
string getDateAndTime()
Definition: sysutil.cpp:31
std::string host_
name of the host where the job is running
Definition: ProjectData.h:120
std::string title_
title of the project
Definition: ProjectData.h:117

◆ getDriverVersion()

ProjectData::DriverVersion getDriverVersion ( ) const
noexcept

Definition at line 261 of file ProjectData.cpp.

References ProjectData::driver_version_.

Referenced by QMCDriverFactory::readSection(), and qmcplusplus::TEST_CASE().

261 { return driver_version_; }
DriverVersion driver_version_
Definition: ProjectData.h:147

◆ getMaxCPUSeconds()

int getMaxCPUSeconds ( ) const
noexcept

Definition at line 259 of file ProjectData.cpp.

References ProjectData::max_cpu_secs_.

Referenced by VMCBatched::run(), and DMCBatched::run().

259 { return max_cpu_secs_; }
int max_cpu_secs_
max cpu seconds
Definition: ProjectData.h:144

◆ getRuntimeOptions()

const RuntimeOptions & getRuntimeOptions ( ) const
noexcept

◆ getSeriesIndex()

int getSeriesIndex ( ) const
noexcept

Definition at line 257 of file ProjectData.cpp.

References ProjectData::series_.

Referenced by VMCBatched::run(), and qmcplusplus::TEST_CASE().

257 { return series_; }
int series_
series index
Definition: ProjectData.h:135

◆ getTitle()

const std::string & getTitle ( ) const
noexcept

returns the title of the project <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to title_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers"

Definition at line 251 of file ProjectData.cpp.

References ProjectData::title_.

Referenced by QMCAppBase::getTitle(), VMCBatched::run(), DMCBatched::run(), and qmcplusplus::TEST_CASE().

251 { return title_; }
std::string title_
title of the project
Definition: ProjectData.h:117

◆ isComplex()

bool isComplex ( ) const
noexcept

◆ lookupDriverVersion()

ProjectData::DriverVersion lookupDriverVersion ( const std::string &  enum_value)
staticprivate

Definition at line 268 of file ProjectData.cpp.

References ProjectData::lookup_input_enum_value, and qmcplusplus::lowerCase().

Referenced by ProjectData::put().

269 {
270  std::string enum_value_str(lowerCase(enum_value));
271  try
272  {
273  return lookup_input_enum_value.at(enum_value_str);
274  }
275  catch (std::out_of_range& oor_exc)
276  {
277  throw UniformCommunicateError("bad_enum_tag_value: " + enum_value_str);
278  }
279 }
static const std::unordered_map< std::string, DriverVersion > lookup_input_enum_value
Definition: ProjectData.h:50
std::string lowerCase(const std::string_view s)
++17

◆ nextRoot()

const std::string & nextRoot ( ) const
noexcept

returns the nextroot of the project, the series id is incremented at every QMC section <project id="det_qmc_short_sdbatch_vmcbatch_mwalkers" series="0"> translate to project_main_ = "det_qmc_short_sdbatch_vmcbatch_mwalkers.s001"

Definition at line 255 of file ProjectData.cpp.

References ProjectData::next_root_.

255 { return next_root_; }
std::string next_root_
root for the next run
Definition: ProjectData.h:132

◆ previousRoot()

bool previousRoot ( std::string &  oldroot) const

return the root of the previous sequence

Parameters
oldrootis composed by the title_ and series_

Definition at line 158 of file ProjectData.cpp.

References Communicate::getGroupID(), QMCState::mpi_groups, ProjectData::my_comm_, qmcplusplus::qmc_common, Communicate::rank(), ProjectData::series_, Communicate::size(), and ProjectData::title_.

159 {
160  oldroot.clear();
161  if (series_)
162  {
163  //int nproc_g = OHMMS::Controller->size();
164  int nproc = my_comm_->size();
165  int nodeid = my_comm_->rank();
166  int groupid = my_comm_->getGroupID();
167  bool no_gtag = (qmc_common.mpi_groups == 1);
168  std::array<char, 128> fileroot;
169  int file_len{0};
170  if (no_gtag)
171  {
172  if (nproc > 1)
173  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".s%03d.p%03d", series_ - 1, nodeid);
174  else
175  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".s%03d", series_ - 1);
176  }
177  else
178  {
179  if (nproc > 1)
180  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".g%03d.s%03d.p%03d", groupid, series_ - 1, nodeid);
181  else
182  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".g%03d.s%03d", groupid, series_ - 1);
183  }
184  if (file_len < 0)
185  throw std::runtime_error("Error generating olfroot");
186  oldroot = title_;
187  oldroot.append(fileroot.data(), file_len);
188  return true;
189  }
190  else
191  {
192  return false;
193  }
194 }
int rank() const
return the rank
Definition: Communicate.h:116
int series_
series index
Definition: ProjectData.h:135
int size() const
return the number of tasks
Definition: Communicate.h:118
Communicate * my_comm_
communicator
Definition: ProjectData.h:138
int getGroupID() const
return the group id
Definition: Communicate.h:121
int mpi_groups
number of mpi groups
Definition: qmc_common.h:33
QMCState qmc_common
a unique QMCState during a run
Definition: qmc_common.cpp:111
std::string title_
title of the project
Definition: ProjectData.h:117

◆ put() [1/2]

bool put ( std::istream &  is)

Definition at line 60 of file ProjectData.cpp.

References ProjectData::date_, ProjectData::host_, ProjectData::reset(), ProjectData::series_, and ProjectData::title_.

Referenced by qmcplusplus::TEST_CASE(), and QMCMain::validateXML().

61 {
62  std::string t1;
63  while (!is.eof())
64  {
65  if (isdigit(t1[0]))
66  series_ = atoi(t1.c_str());
67  is >> t1;
68  if (t1 == "series")
69  is >> series_;
70  else if (t1 == "host")
71  is >> host_;
72  else if (t1 == "date")
73  is >> date_;
74  else
75  title_ = t1;
76  }
77  reset();
78  return true;
79 }
int series_
series index
Definition: ProjectData.h:135
std::string date_
date when the job is executed
Definition: ProjectData.h:123
std::string host_
name of the host where the job is running
Definition: ProjectData.h:120
std::string title_
title of the project
Definition: ProjectData.h:117
void reset()
Construct the root name with title_ and m_series.
Definition: ProjectData.cpp:97

◆ put() [2/2]

bool put ( xmlNodePtr  cur)

first, overwrite the existing xml nodes

second, add xml nodes, if missing

Definition at line 196 of file ProjectData.cpp.

References ParameterSet::add(), ProjectData::cur_, ProjectData::date_, ProjectData::driver_version_, getDateAndTime(), getHostName(), getXMLAttributeValue(), ProjectData::host_, ProjectData::lookupDriverVersion(), ProjectData::max_cpu_secs_, ParameterSet::put(), ProjectData::reset(), ProjectData::series_, XMLNodeString::setXMLNodeContent(), and ProjectData::title_.

197 {
198  cur_ = cur;
199  title_ = getXMLAttributeValue(cur, "id");
200  const std::string series_str(getXMLAttributeValue(cur, "series"));
201  if (!series_str.empty())
202  series_ = std::stoi(series_str);
203 
204  std::string driver_version_str;
205  ParameterSet m_param;
206  m_param.add(max_cpu_secs_, "max_seconds");
207  m_param.add(driver_version_str, "driver_version");
208  m_param.put(cur);
209 
210  if (!driver_version_str.empty())
211  driver_version_ = lookupDriverVersion(driver_version_str);
212 
213  ///first, overwrite the existing xml nodes
214  cur = cur->xmlChildrenNode;
215  while (cur != NULL)
216  {
217  std::string cname((const char*)(cur->name));
218  if (cname == "user")
219  {
220  // Removed
221  }
222  if (cname == "host")
223  {
224  host_ = getHostName();
225  const XMLNodeString node_string(host_);
226  node_string.setXMLNodeContent(cur);
227  }
228  if (cname == "date")
229  {
230  date_ = getDateAndTime();
231  const XMLNodeString node_string(date_);
232  node_string.setXMLNodeContent(cur);
233  }
234  cur = cur->next;
235  }
236  ///second, add xml nodes, if missing
237  if (host_ == "none")
238  {
239  host_ = getHostName();
240  xmlNewChild(cur_, cur_->ns, (const xmlChar*)"host", (const xmlChar*)(host_.c_str()));
241  }
242  if (date_ == "none")
243  {
244  date_ = getDateAndTime();
245  xmlNewChild(cur_, cur_->ns, (const xmlChar*)"date", (const xmlChar*)(date_.c_str()));
246  }
247  reset();
248  return true;
249 }
DriverVersion driver_version_
Definition: ProjectData.h:147
string getDateAndTime()
Definition: sysutil.cpp:31
int series_
series index
Definition: ProjectData.h:135
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
std::string date_
date when the job is executed
Definition: ProjectData.h:123
class to handle a set of parameters
Definition: ParameterSet.h:27
int max_cpu_secs_
max cpu seconds
Definition: ProjectData.h:144
xmlNodePtr cur_
the xml node for <Project>
Definition: ProjectData.h:141
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...
string getHostName()
< return the host name
Definition: sysutil.cpp:24
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>
convert xmlNode contents into a std::string
std::string host_
name of the host where the job is running
Definition: ProjectData.h:120
static DriverVersion lookupDriverVersion(const std::string &enum_value)
std::string title_
title of the project
Definition: ProjectData.h:117
void reset()
Construct the root name with title_ and m_series.
Definition: ProjectData.cpp:97

◆ reset()

void reset ( )

Construct the root name with title_ and m_series.

Definition at line 97 of file ProjectData.cpp.

References ProjectData::cur_, Communicate::getGroupID(), QMCState::mpi_groups, ProjectData::my_comm_, ProjectData::next_root_, ProjectData::project_main_, ProjectData::project_root_, qmcplusplus::qmc_common, Communicate::rank(), qmcplusplus::Units::time::s, ProjectData::series_, Communicate::setName(), Communicate::size(), and ProjectData::title_.

Referenced by ProjectData::advance(), ProjectData::put(), ProjectData::rewind(), and QMCMain::validateXML().

98 {
99  //int nproc_g = OHMMS::Controller->size();
100  int nproc = my_comm_->size();
101  int nodeid = my_comm_->rank();
102  int groupid = my_comm_->getGroupID();
103  std::array<char, 256> fileroot;
104  std::array<char, 256> nextroot;
105 
106  bool no_gtag = (qmc_common.mpi_groups == 1);
107  int file_len{0};
108  if (no_gtag) //qnproc_g == nproc)
109  file_len = std::snprintf(fileroot.data(), fileroot.size(), "%s.s%03d", title_.c_str(), series_);
110  else
111  file_len = std::snprintf(fileroot.data(), fileroot.size(), "%s.g%03d.s%03d", title_.c_str(), groupid, series_);
112 
113  project_main_ = std::string(fileroot.data(), file_len);
114  //set the communicator name
115  my_comm_->setName(fileroot.data(), file_len);
116  int next_len{0};
117  if (no_gtag)
118  {
119  if (nproc > 1)
120  {
121  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".s%03d.p%03d", series_, nodeid);
122  next_len = std::snprintf(nextroot.data(), nextroot.size(), ".s%03d.p%03d", series_ + 1, nodeid);
123  }
124  else
125  {
126  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".s%03d", series_);
127  next_len = std::snprintf(nextroot.data(), nextroot.size(), ".s%03d", series_ + 1);
128  }
129  }
130  else
131  {
132  if (nproc > 1)
133  {
134  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".g%03d.s%03d.p%03d", groupid, series_, nodeid);
135  next_len = std::snprintf(nextroot.data(), nextroot.size(), ".g%03d.s%03d.p%03d", groupid, series_ + 1, nodeid);
136  }
137  else
138  {
139  file_len = std::snprintf(fileroot.data(), fileroot.size(), ".g%03d.s%03d", groupid, series_);
140  next_len = std::snprintf(nextroot.data(), nextroot.size(), ".g%03d.s%03d", groupid, series_ + 1);
141  }
142  }
143  if (file_len < 0)
144  throw std::runtime_error("Error generating project_root");
145  if (next_len < 0)
146  throw std::runtime_error("Error generating next_root");
147 
149  project_root_.append(fileroot.data(), file_len);
150  next_root_ = title_;
151  next_root_.append(nextroot.data(), next_len);
152  std::stringstream s;
153  s << series_ + 1;
154  if (cur_)
155  xmlSetProp(cur_, (const xmlChar*)"series", (const xmlChar*)(s.str().c_str()));
156 }
int rank() const
return the rank
Definition: Communicate.h:116
int series_
series index
Definition: ProjectData.h:135
int size() const
return the number of tasks
Definition: Communicate.h:118
std::string next_root_
root for the next run
Definition: ProjectData.h:132
Communicate * my_comm_
communicator
Definition: ProjectData.h:138
int getGroupID() const
return the group id
Definition: Communicate.h:121
std::string project_main_
main root for all the output engines
Definition: ProjectData.h:126
std::string project_root_
processor-dependent root for all the output engines
Definition: ProjectData.h:129
xmlNodePtr cur_
the xml node for <Project>
Definition: ProjectData.h:141
void setName(const std::string &aname)
Definition: Communicate.h:129
int mpi_groups
number of mpi groups
Definition: qmc_common.h:33
QMCState qmc_common
a unique QMCState during a run
Definition: qmc_common.cpp:111
std::string title_
title of the project
Definition: ProjectData.h:117

◆ rewind()

void rewind ( )

roll-back a series number and reset project_root_ by one

Definition at line 87 of file ProjectData.cpp.

References ProjectData::reset(), and ProjectData::series_.

88 {
89  if (series_ > 0)
90  series_--;
91  reset();
92 }
int series_
series index
Definition: ProjectData.h:135
void reset()
Construct the root name with title_ and m_series.
Definition: ProjectData.cpp:97

◆ setCommunicator()

void setCommunicator ( Communicate c)

Definition at line 50 of file ProjectData.cpp.

References ProjectData::my_comm_.

Referenced by QMCMain::validateXML().

50 { my_comm_ = c; }
Communicate * my_comm_
communicator
Definition: ProjectData.h:138

Member Data Documentation

◆ cur_

xmlNodePtr cur_
private

the xml node for <Project>

Definition at line 141 of file ProjectData.h.

Referenced by ProjectData::put(), and ProjectData::reset().

◆ date_

std::string date_
private

date when the job is executed

Definition at line 123 of file ProjectData.h.

Referenced by ProjectData::put().

◆ driver_version_

DriverVersion driver_version_
private

Definition at line 147 of file ProjectData.h.

Referenced by ProjectData::getDriverVersion(), and ProjectData::put().

◆ host_

std::string host_
private

name of the host where the job is running

Definition at line 120 of file ProjectData.h.

Referenced by ProjectData::get(), and ProjectData::put().

◆ lookup_input_enum_value

const std::unordered_map<std::string, DriverVersion> lookup_input_enum_value
inlinestaticprivate
Initial value:
{{"legacy",
{"batch",
{"batched",
}

Definition at line 50 of file ProjectData.h.

Referenced by ProjectData::lookupDriverVersion().

◆ max_cpu_secs_

int max_cpu_secs_
private

max cpu seconds

Definition at line 144 of file ProjectData.h.

Referenced by ProjectData::getMaxCPUSeconds(), and ProjectData::put().

◆ my_comm_

Communicate* my_comm_
private

◆ next_root_

std::string next_root_
private

root for the next run

Definition at line 132 of file ProjectData.h.

Referenced by ProjectData::nextRoot(), and ProjectData::reset().

◆ project_main_

std::string project_main_
private

main root for all the output engines

Definition at line 126 of file ProjectData.h.

Referenced by ProjectData::currentMainRoot(), and ProjectData::reset().

◆ project_root_

std::string project_root_
private

processor-dependent root for all the output engines

Definition at line 129 of file ProjectData.h.

Referenced by ProjectData::reset().

◆ runtime_options_

RuntimeOptions runtime_options_
private

Definition at line 150 of file ProjectData.h.

Referenced by ProjectData::getRuntimeOptions(), and ProjectData::isComplex().

◆ series_

◆ title_

std::string title_
private

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