QMCPACK
BranchIO< SFNB > Class Template Reference
+ Collaboration diagram for BranchIO< SFNB >:

Public Types

using RealType = typename SFNB::RealType
 
using BranchModeType = typename SFNB::BranchModeType
 
using IParamType = typename SFNB::IParamType
 
using VParamType = typename SFNB::VParamType
 

Public Member Functions

 BranchIO (SFNB &source, Communicate *c)
 
bool write (const std::string &fname)
 
bool read (const std::string &fname)
 
void bcast_state ()
 

Static Public Member Functions

static void initAttributes ()
 

Public Attributes

SFNB & ref
 
CommunicatemyComm
 

Static Public Attributes

static std::vector< std::string > vParamName
 
static std::vector< std::string > iParamName
 

Detailed Description

template<class SFNB>
class qmcplusplus::BranchIO< SFNB >

Definition at line 22 of file BranchIO.h.

Member Typedef Documentation

◆ BranchModeType

using BranchModeType = typename SFNB::BranchModeType

Definition at line 26 of file BranchIO.h.

◆ IParamType

using IParamType = typename SFNB::IParamType

Definition at line 27 of file BranchIO.h.

◆ RealType

using RealType = typename SFNB::RealType

Definition at line 25 of file BranchIO.h.

◆ VParamType

using VParamType = typename SFNB::VParamType

Definition at line 28 of file BranchIO.h.

Constructor & Destructor Documentation

◆ BranchIO()

BranchIO ( SFNB &  source,
Communicate c 
)
inline

Definition at line 32 of file BranchIO.h.

32 : ref(source), myComm(c) {}
Communicate * myComm
Definition: BranchIO.h:31

Member Function Documentation

◆ bcast_state()

void bcast_state ( )

Definition at line 210 of file BranchIO.cpp.

References copy(), and qmcplusplus::n.

211 {
212  int n = ref.vParam.size() + ref.iParam.size();
213  std::vector<RealType> pdata(n + 1 + 16, -1);
214 
215  if (myComm->rank() == 0)
216  {
217  copy(ref.vParam.begin(), ref.vParam.end(), pdata.begin());
218  copy(ref.iParam.begin(), ref.iParam.end(), pdata.begin() + ref.vParam.size());
219  int offset = n;
220  pdata[offset++] = ref.BranchMode.to_ulong();
221  copy(ref.EnergyHist.properties, ref.EnergyHist.properties + 4, pdata.begin() + offset);
222  offset += 4;
223  copy(ref.VarianceHist.properties, ref.VarianceHist.properties + 4, pdata.begin() + offset);
224  offset += 4;
225  copy(ref.R2Accepted.properties, ref.R2Accepted.properties + 4, pdata.begin() + offset);
226  offset += 4;
227  copy(ref.R2Proposed.properties, ref.R2Proposed.properties + 4, pdata.begin() + offset);
228  }
229 
230  //broadcast to the nodes : need to add a namespace mpi::
231  myComm->bcast(pdata);
232 
233  if (myComm->rank())
234  {
235  int ii = 0;
236  for (auto& vpar : ref.vParam)
237  vpar = pdata[ii++];
238  for (int i = 0; i < ref.iParam.size(); ++i, ++ii)
239  ref.iParam[i] = static_cast<int>(pdata[ii]);
240  ref.BranchMode = static_cast<unsigned long>(pdata[ii]);
241  }
242  {
243  //update historgram
244  int ii = n + 1;
245  ref.EnergyHist.reset(pdata[ii], pdata[ii + 1], pdata[ii + 2]);
246  ii += 4;
247  ref.VarianceHist.reset(pdata[ii], pdata[ii + 1], pdata[ii + 2]);
248  ii += 4;
249  ref.R2Accepted.reset(pdata[ii], pdata[ii + 1], pdata[ii + 2]);
250  ii += 4;
251  ref.R2Proposed.reset(pdata[ii], pdata[ii + 1], pdata[ii + 2]);
252  }
253 }
int rank() const
return the rank
Definition: Communicate.h:116
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
Communicate * myComm
Definition: BranchIO.h:31
void bcast(T &)

◆ initAttributes()

void initAttributes ( )
static

Definition at line 82 of file BranchIO.cpp.

83 {
84  if (vParamName.size())
85  return;
86  vParamName.resize(10);
87  vParamName[0] = "tau";
88  vParamName[1] = "taueff";
89  vParamName[2] = "etrial";
90  vParamName[3] = "eref";
91  vParamName[4] = "branchmax";
92  vParamName[5] = "branchcutoff";
93  vParamName[6] = "branchfilter";
94  vParamName[7] = "sigma";
95  vParamName[8] = "acc_energy";
96  vParamName[9] = "acc_samples";
97 
98  iParamName.resize(7);
99  iParamName[0] = "warmupsteps";
100  iParamName[1] = "energyupdateinterval";
101  iParamName[2] = "counter";
102  iParamName[3] = "targetwalkers";
103  iParamName[4] = "maxwalkers";
104  iParamName[5] = "minwalkers";
105  iParamName[6] = "brnachinterval";
106 }
static std::vector< std::string > iParamName
Definition: BranchIO.h:40
static std::vector< std::string > vParamName
Definition: BranchIO.h:39

◆ read()

bool read ( const std::string &  fname)

Definition at line 166 of file BranchIO.cpp.

167 {
168  int found_config = 0;
169 
170  if (myComm->rank() == 0)
171  {
172  initAttributes();
173  using boost::property_tree::ptree;
174  ptree pt;
175  std::string xname = fname + ".qmc.xml";
176  read_xml(xname, pt);
177  if (!pt.empty())
178  {
179  ref.BranchMode = pt.get<BranchModeType>("state.branchmode");
180 
181  get_histogram("state.energy", ref.EnergyHist, pt);
182  get_histogram("state.variance", ref.VarianceHist, pt);
183  get_histogram("state.r2accepted", ref.R2Accepted, pt);
184  get_histogram("state.r2proposed", ref.R2Proposed, pt);
185 
186  int i = 0;
187  BOOST_FOREACH (const ptree::value_type& v, pt.get_child("state.iparam"))
188  {
189  ref.iParam[i++] = v.second.get_value<int>();
190  }
191  auto it_vparam = ref.vParam.begin();
192  BOOST_FOREACH (const ptree::value_type& v, pt.get_child("state.vparam"))
193  {
194  *(it_vparam++) = v.second.get_value<double>();
195  }
196  found_config = 1;
197  }
198  }
199  myComm->bcast(found_config);
200 
201  if (!found_config)
202  return false;
203 
204  bcast_state();
205 
206  return true;
207 }
int rank() const
return the rank
Definition: Communicate.h:116
static void initAttributes()
Definition: BranchIO.cpp:82
typename SFNB::BranchModeType BranchModeType
Definition: BranchIO.h:26
Communicate * myComm
Definition: BranchIO.h:31
void bcast(T &)
QMCTraits::FullPrecRealType value_type

◆ write()

bool write ( const std::string &  fname)

Definition at line 109 of file BranchIO.cpp.

References hdf_archive::create(), qmcplusplus::hdf::main_state, hdf_archive::push(), qmcplusplus::hdf::qmc_status, and hdf_archive::write().

Referenced by SimpleFixedNodeBranch::write().

110 {
111  if (myComm->rank())
112  return true;
113 
114 #if defined(HAVE_LIBBOOST)
115  initAttributes();
116  using boost::property_tree::ptree;
117  ptree pt;
118 
119  // Put log filename in property tree
120  pt.put("state.branchmode", ref.BranchMode);
121 
122  auto it_vparam = ref.vParam.begin();
123  for (auto& name : vParamName)
124  pt.put("state.vparam." + name, *(it_vparam++));
125  for (int i = 0; i < iParamName.size(); ++i)
126  pt.put("state.iparam." + iParamName[i], ref.iParam[i]);
127 
128  put_histogram("state.energy", ref.EnergyHist, pt);
129  put_histogram("state.variance", ref.VarianceHist, pt);
130  put_histogram("state.r2accepted", ref.R2Accepted, pt);
131  put_histogram("state.r2proposed", ref.R2Proposed, pt);
132  std::string xname = fname + ".qmc.xml";
133  write_xml(xname, pt);
134 #else
135  //append .qmc.h5 if missing
136  std::string h5name(fname);
137  if (fname.find("qmc.h5") >= fname.size())
138  h5name.append(".qmc.h5");
139  hdf_archive dump(myComm);
140  hid_t fid = dump.create(h5name);
141  dump.push(hdf::main_state);
142  dump.push(hdf::qmc_status);
143  std::string v_header("tau:taueff:etrial:eref:branchmax:branchcutoff:branchfilter:sigma:acc_energy:acc_samples");
144  std::string i_header("warmupsteps:energyupdateinterval:counter:targetwalkers:maxwalkers:minwalkers:branchinterval");
145  dump.write(v_header, "vparam_def");
146  dump.write(i_header, "iparam_def");
147  dump.write(ref.vParam, "vparam");
148  dump.write(ref.iParam, "iparam");
149  dump.write(ref.BranchMode, "branchmode");
150  dump.push("histogram");
151  dump.write(ref.EnergyHist, "energy");
152  dump.write(ref.VarianceHist, "variance");
153  dump.write(ref.R2Accepted, "r2accepted");
154  dump.write(ref.R2Proposed, "r2proposed");
155  //PopHist is not being used in 2010-10-19
156  //if(ref.BranchMode[SimpleFixedNodeBranch::B_DMC])
157  //{
158  // dump.push("population");
159  // dump.write(ref.PopHist.myData,"histogram");
160  //}
161 #endif
162  return true;
163 }
int rank() const
return the rank
Definition: Communicate.h:116
static void initAttributes()
Definition: BranchIO.cpp:82
Communicate * myComm
Definition: BranchIO.h:31
const char qmc_status[]
Definition: HDFVersion.h:41
static std::vector< std::string > iParamName
Definition: BranchIO.h:40
const char main_state[]
Definition: HDFVersion.h:31
static std::vector< std::string > vParamName
Definition: BranchIO.h:39

Member Data Documentation

◆ iParamName

std::vector< std::string > iParamName
static

Definition at line 40 of file BranchIO.h.

◆ myComm

Communicate* myComm

Definition at line 31 of file BranchIO.h.

◆ ref

SFNB& ref

Definition at line 30 of file BranchIO.h.

◆ vParamName

std::vector< std::string > vParamName
static

Definition at line 39 of file BranchIO.h.


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