QMCPACK
WalkerLogCollector Class Reference

Crowd-level resource for walker log collection. More...

+ Collaboration diagram for WalkerLogCollector:

Public Member Functions

 WalkerLogCollector ()
 
 WalkerLogCollector (const WalkerLogState &state_)
 
void startBlock ()
 resize buffers to zero rows at beginning of each MC block More...
 
void collect (const MCPWalker &walker, const ParticleSet &pset, const TrialWaveFunction &wfn, const QMCHamiltonian &ham, int step=-1)
 collect all data for one walker into the data buffers More...
 
void checkBuffers ()
 Check that all buffers have the same number of rows. More...
 

Public Attributes

std::vector< size_t > steps
 MC step information for each walker throughout the MC block. More...
 
std::vector< WLog::Realenergies
 LocalEnergy information for each walker throughout the MC block. More...
 
WalkerLogBuffer< WLog::Intwalker_property_int_buffer
 buffer containing integer walker properties More...
 
WalkerLogBuffer< WLog::Realwalker_property_real_buffer
 buffer containing real-valued walker properties More...
 
WalkerLogBuffer< WLog::Realwalker_particle_real_buffer
 buffer containing per-particle walker data More...
 
std::unordered_set< std::string > properties_include
 ParticleSet::PropertyList quantities to include. More...
 
std::vector< size_t > property_indices
 indices in ParticleSet::PropertyList for included quantities More...
 
int energy_index
 location of LocalEnergy in ParticleSet::PropertyList More...
 
WalkerLogState state
 state data set by WalkerLogManager More...
 

Private Member Functions

void init ()
 shared variable setting in constructors More...
 
void resetBuffers ()
 resize buffers to zero rows More...
 

Private Attributes

Array< WLog::Real, 2 > Rtmp
 tmp storage for walker positions More...
 
Array< WLog::Real, 1 > Stmp
 tmp storage for walker spins More...
 
Array< WLog::PsiVal, 2 > Gtmp
 tmp storage for walker wavefunction gradients More...
 
Array< WLog::PsiVal, 1 > Ltmp
 tmp storage for walker wavefunciton laplacians More...
 

Detailed Description

Crowd-level resource for walker log collection.

Contains data buffers for walker properties and walker particle data. Data buffers are resized to zero at the start of an MC block. Data for all walkers is collected into the buffers each MC step in an MC block. This class is not responsible for I/O.

Definition at line 49 of file WalkerLogCollector.h.

Constructor & Destructor Documentation

◆ WalkerLogCollector() [1/2]

Definition at line 27 of file WalkerLogCollector.cpp.

References WalkerLogCollector::init().

28 {
29  init();
30 }
void init()
shared variable setting in constructors

◆ WalkerLogCollector() [2/2]

WalkerLogCollector ( const WalkerLogState state_)

Definition at line 33 of file WalkerLogCollector.cpp.

References WalkerLogCollector::init(), and WalkerLogCollector::state.

34 {
35  init();
36  state = state_;
37 }
void init()
shared variable setting in constructors
WalkerLogState state
state data set by WalkerLogManager

Member Function Documentation

◆ checkBuffers()

void checkBuffers ( )

Check that all buffers have the same number of rows.

This ensures that the full data for a given walker can be reconstructed due to enforced data alignment in the buffers.

Definition at line 187 of file WalkerLogCollector.cpp.

References qmcplusplus::app_log(), WalkerLogCollector::energies, WalkerLogBuffer< T >::nrows(), WalkerLogCollector::state, WalkerLogCollector::steps, WalkerLogState::verbose, WalkerLogCollector::walker_particle_real_buffer, WalkerLogCollector::walker_property_int_buffer, and WalkerLogCollector::walker_property_real_buffer.

188 {
189  if (state.verbose)
190  app_log() << "WalkerLogCollector::checkBuffers" << std::endl;
191  size_t nrows = walker_property_int_buffer.nrows();
192  auto prop_real_bad = walker_property_real_buffer.nrows() != nrows;
193  auto part_real_bad = walker_particle_real_buffer.nrows() != nrows;
194  auto steps_bad = steps.size() != nrows;
195  auto energies_bad = energies.size() != nrows;
196  auto any_bad = prop_real_bad || part_real_bad || steps_bad || energies_bad;
197 
198  if (prop_real_bad)
199  app_log() << "WalkerLogCollector::checkBuffers walker_property_real_buffer row count does not match\n";
200  if (part_real_bad)
201  app_log() << "WalkerLogCollector::checkBuffers walker_particle_real_buffer row count does not match\n";
202  if (steps_bad)
203  app_log() << "WalkerLogCollector::checkBuffers steps entry count does not match\n";
204  if (energies_bad)
205  app_log() << "WalkerLogCollector::checkBuffers energies entry count does not match\n";
206  if (any_bad)
207  throw std::runtime_error("WalkerLogCollector::checkBuffers buffer lengths do not match");
208 }
WalkerLogBuffer< WLog::Int > walker_property_int_buffer
buffer containing integer walker properties
WalkerLogBuffer< WLog::Real > walker_property_real_buffer
buffer containing real-valued walker properties
WalkerLogBuffer< WLog::Real > walker_particle_real_buffer
buffer containing per-particle walker data
bool verbose
controls verbosity of log file writes
std::vector< size_t > steps
MC step information for each walker throughout the MC block.
size_t nrows()
current number of rows in the data buffer
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< WLog::Real > energies
LocalEnergy information for each walker throughout the MC block.
WalkerLogState state
state data set by WalkerLogManager

◆ collect()

void collect ( const MCPWalker walker,
const ParticleSet pset,
const TrialWaveFunction wfn,
const QMCHamiltonian ham,
int  step = -1 
)

collect all data for one walker into the data buffers

Definition at line 65 of file WalkerLogCollector.cpp.

References qmcplusplus::abs(), qmcplusplus::Units::pressure::bar, WalkerLogCollector::energies, WalkerLogCollector::energy_index, TrialWaveFunction::getLogPsi(), TrialWaveFunction::getPhase(), WalkerLogCollector::Gtmp, qmcplusplus::if(), qmcplusplus::imag(), WalkerLogState::logs_active, WalkerLogCollector::Ltmp, omptarget::min(), qmcplusplus::n, WalkerLogCollector::properties_include, WalkerLogCollector::property_indices, qmcplusplus::pset, Array< T, D, ALLOC >::resize(), WalkerLogCollector::Rtmp, WalkerLogCollector::state, WalkerLogState::step_period, WalkerLogCollector::steps, WalkerLogCollector::Stmp, Array< T, D, ALLOC >::storage(), qmcplusplus::walker, WalkerLogCollector::walker_particle_real_buffer, WalkerLogCollector::walker_property_int_buffer, and WalkerLogCollector::walker_property_real_buffer.

Referenced by DMCUpdatePbyPWithRejectionFast::advanceWalker(), VMCUpdatePbyP::advanceWalker(), Crowd::collectStepWalkerLog(), and qmcplusplus::TEST_CASE().

70 {
71  if (!state.logs_active)
72  return; // no-op for driver if logs are inactive
73 
74  // only collect walker data at steps matching the period (default 1)
75  int current_step = (step == -1) ? pset.current_step : step;
76  if (current_step % state.step_period != 0)
77  return;
78 
79  auto& bsi = walker_property_int_buffer;
80  auto& bsr = walker_property_real_buffer;
82 
83  // collect per-particle walker quantities
84  size_t nparticles = walker.R.size();
85  size_t ndim = walker.R[0].size();
86  // per-particle positions (walker.R)
87  Rtmp.resize(nparticles, ndim);
88  for (size_t p = 0; p < nparticles; ++p)
89  for (size_t d = 0; d < ndim; ++d)
90  Rtmp(p, d) = (WLog::Real)walker.R[p][d];
91  bar.collect("R", Rtmp);
92  // per-particle "spin" (walker.spins)
93  if (pset.isSpinor())
94  {
95  Stmp.resize(nparticles);
96  for (size_t p = 0; p < nparticles; ++p)
97  Stmp(p) = (WLog::Real)walker.spins[p];
98  bar.collect("S", Stmp);
99  }
100  // per-particle gradient(log(psi)) (pset.G)
101  Gtmp.resize(nparticles, ndim);
102  for (size_t p = 0; p < nparticles; ++p)
103  for (size_t d = 0; d < ndim; ++d)
104  Gtmp(p, d) = (WLog::PsiVal)pset.G[p][d];
105  bar.collect("G", Gtmp);
106  // per-particle laplacian(log(psi)) (pset.L)
107  Ltmp.resize(nparticles);
108  for (size_t p = 0; p < nparticles; ++p)
109  Ltmp(p) = (WLog::PsiVal)pset.L[p];
110  bar.collect("L", Ltmp);
111  bar.resetCollect();
112 
113  // collect integer walker properties
114  bsi.collect("step", (WLog::Int)current_step);
115  bsi.collect("id", (WLog::Int)walker.getWalkerID());
116  bsi.collect("parent_id", (WLog::Int)walker.getParentID());
117  bsi.collect("age", (WLog::Int)walker.Age);
118  bsi.resetCollect();
119 
120  // collect real walker properties
121  bsr.collect("weight", (WLog::Real)walker.Weight);
122  bsr.collect("multiplicity", (WLog::Real)walker.Multiplicity);
123  bsr.collect("logpsi", (WLog::Real)wfn.getLogPsi());
124  bsr.collect("phase", (WLog::Real)wfn.getPhase());
125  // from PropertyList
126  if (bsr.first_collect)
127  {
128  for (size_t n = 0; n < pset.PropertyList.size(); ++n)
129  {
130  auto& name = pset.PropertyList.Names[n];
131  auto& value = walker.Properties(0, n);
132  if (properties_include.find(name) != properties_include.end())
133  {
134  bsr.collect(name, (WLog::Real)value);
135  property_indices.push_back(n);
136  }
137  if (name == "LocalEnergy")
138  energy_index = n;
139  }
140  if (energy_index < 0)
141  throw std::runtime_error("LogCollector::collect energy_index must not be negative");
142  }
143  else
144  for (auto n : property_indices)
145  {
146  auto& name = pset.PropertyList.Names[n];
147  auto& value = walker.Properties(0, n);
148  bsr.collect(name, (WLog::Real)value);
149  }
150  // nodal proximity measures
151  auto& gv = Gtmp.storage();
152  WLog::Real dr = std::numeric_limits<WLog::Real>::max();
153  for (size_t n = 0; n < gv.size(); ++n)
154  dr = std::min(dr, std::abs(1. / std::real(gv[n])));
155  auto dr_node_min = dr;
156  WLog::Real dlogpsi2 = 0.;
157  for (size_t n = 0; n < gv.size(); ++n)
158  dlogpsi2 += std::real(gv[n]) * std::real(gv[n]);
159  WLog::Real dphase2 = 0.;
160  for (size_t n = 0; n < gv.size(); ++n)
161  dphase2 += std::imag(gv[n]) * std::imag(gv[n]);
162  bsr.collect("dr_node_min", dr_node_min);
163  bsr.collect("dlogpsi2", dlogpsi2); // dr_node = 1/sqrt(dlogpsi2)
164  bsr.collect("dphase2", dphase2); // dr_node = 1/sqrt(dphase2)
165  bsr.resetCollect();
166 
167  // save the energy of this walker
168  steps.push_back((size_t)current_step);
169  energies.push_back((WLog::Real)walker.Properties(0, energy_index));
170 }
T min(T a, T b)
Array< WLog::Real, 1 > Stmp
tmp storage for walker spins
std::vector< size_t > property_indices
indices in ParticleSet::PropertyList for included quantities
Array< WLog::Real, 2 > Rtmp
tmp storage for walker positions
Container_t & storage()
Definition: OhmmsArray.h:60
bool logs_active
whether logs are active in the current driver
int energy_index
location of LocalEnergy in ParticleSet::PropertyList
WalkerLogBuffer< WLog::Int > walker_property_int_buffer
buffer containing integer walker properties
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
WalkerLogBuffer< WLog::Real > walker_property_real_buffer
buffer containing real-valued walker properties
WalkerLogBuffer< WLog::Real > walker_particle_real_buffer
buffer containing per-particle walker data
int step_period
period between MC steps for data collection
OHMMS_PRECISION_FULL Real
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
Array< WLog::PsiVal, 1 > Ltmp
tmp storage for walker wavefunciton laplacians
QMCTraits::RealType real
std::vector< size_t > steps
MC step information for each walker throughout the MC block.
Array< WLog::PsiVal, 2 > Gtmp
tmp storage for walker wavefunction gradients
if(c->rank()==0)
std::unordered_set< std::string > properties_include
ParticleSet::PropertyList quantities to include.
std::vector< WLog::Real > energies
LocalEnergy information for each walker throughout the MC block.
WalkerLogState state
state data set by WalkerLogManager
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)

◆ init()

void init ( )
private

shared variable setting in constructors

Definition at line 40 of file WalkerLogCollector.cpp.

References WalkerLogCollector::energies, WalkerLogCollector::energy_index, WalkerLogBuffer< T >::label, WalkerLogCollector::properties_include, WalkerLogCollector::steps, WalkerLogCollector::walker_particle_real_buffer, WalkerLogCollector::walker_property_int_buffer, and WalkerLogCollector::walker_property_real_buffer.

Referenced by WalkerLogCollector::WalkerLogCollector().

41 {
42  properties_include = {"R2Accepted", "R2Proposed", "LocalEnergy", "LocalPotential", "Kinetic",
43  "ElecElec", "ElecIon", "LocalECP", "NonLocalECP"};
44  energy_index = -1;
45  // empty walker steps and energy vectors for the MC block
46  steps.resize(0);
47  energies.resize(0);
48  // label the buffers for HDF file write
49  walker_property_int_buffer.label = "walker_property_int";
50  walker_property_real_buffer.label = "walker_property_real";
51  walker_particle_real_buffer.label = "walker_particle_real";
52 }
std::string label
label for this data in HDF file
int energy_index
location of LocalEnergy in ParticleSet::PropertyList
WalkerLogBuffer< WLog::Int > walker_property_int_buffer
buffer containing integer walker properties
WalkerLogBuffer< WLog::Real > walker_property_real_buffer
buffer containing real-valued walker properties
WalkerLogBuffer< WLog::Real > walker_particle_real_buffer
buffer containing per-particle walker data
std::vector< size_t > steps
MC step information for each walker throughout the MC block.
std::unordered_set< std::string > properties_include
ParticleSet::PropertyList quantities to include.
std::vector< WLog::Real > energies
LocalEnergy information for each walker throughout the MC block.

◆ resetBuffers()

void resetBuffers ( )
private

resize buffers to zero rows

Definition at line 173 of file WalkerLogCollector.cpp.

References qmcplusplus::app_log(), WalkerLogCollector::energies, WalkerLogBuffer< T >::resetBuffer(), WalkerLogCollector::state, WalkerLogCollector::steps, WalkerLogState::verbose, WalkerLogCollector::walker_particle_real_buffer, WalkerLogCollector::walker_property_int_buffer, and WalkerLogCollector::walker_property_real_buffer.

Referenced by WalkerLogCollector::startBlock().

174 {
175  if (state.verbose)
176  app_log() << "WalkerLogCollector::reset_buffers" << std::endl;
177  // resize all buffers to zero rows
181  // similar for step/energy vectors
182  steps.resize(0);
183  energies.resize(0);
184 }
void resetBuffer()
resize the buffer to zero
WalkerLogBuffer< WLog::Int > walker_property_int_buffer
buffer containing integer walker properties
WalkerLogBuffer< WLog::Real > walker_property_real_buffer
buffer containing real-valued walker properties
WalkerLogBuffer< WLog::Real > walker_particle_real_buffer
buffer containing per-particle walker data
bool verbose
controls verbosity of log file writes
std::vector< size_t > steps
MC step information for each walker throughout the MC block.
std::ostream & app_log()
Definition: OutputManager.h:65
std::vector< WLog::Real > energies
LocalEnergy information for each walker throughout the MC block.
WalkerLogState state
state data set by WalkerLogManager

◆ startBlock()

void startBlock ( )

resize buffers to zero rows at beginning of each MC block

Definition at line 55 of file WalkerLogCollector.cpp.

References qmcplusplus::app_log(), WalkerLogState::logs_active, WalkerLogCollector::resetBuffers(), WalkerLogCollector::state, and WalkerLogState::verbose.

Referenced by Crowd::startBlock(), and QMCUpdateBase::startBlock().

56 {
57  if (!state.logs_active)
58  return; // no-op for driver if logs are inactive
59  if (state.verbose)
60  app_log() << "WalkerLogCollector::startBlock " << std::endl;
61  resetBuffers(); // resize buffers to zero rows
62 }
bool logs_active
whether logs are active in the current driver
void resetBuffers()
resize buffers to zero rows
bool verbose
controls verbosity of log file writes
std::ostream & app_log()
Definition: OutputManager.h:65
WalkerLogState state
state data set by WalkerLogManager

Member Data Documentation

◆ energies

std::vector<WLog::Real> energies

LocalEnergy information for each walker throughout the MC block.

Definition at line 55 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::checkBuffers(), WalkerLogCollector::collect(), WalkerLogCollector::init(), and WalkerLogCollector::resetBuffers().

◆ energy_index

int energy_index

location of LocalEnergy in ParticleSet::PropertyList

Definition at line 68 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect(), and WalkerLogCollector::init().

◆ Gtmp

Array<WLog::PsiVal, 2> Gtmp
private

tmp storage for walker wavefunction gradients

Definition at line 80 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect().

◆ Ltmp

Array<WLog::PsiVal, 1> Ltmp
private

tmp storage for walker wavefunciton laplacians

Definition at line 82 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect().

◆ properties_include

std::unordered_set<std::string> properties_include

ParticleSet::PropertyList quantities to include.

Definition at line 64 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect(), and WalkerLogCollector::init().

◆ property_indices

std::vector<size_t> property_indices

indices in ParticleSet::PropertyList for included quantities

Definition at line 66 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect().

◆ Rtmp

Array<WLog::Real, 2> Rtmp
private

tmp storage for walker positions

Definition at line 76 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect().

◆ state

◆ steps

std::vector<size_t> steps

MC step information for each walker throughout the MC block.

Definition at line 53 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::checkBuffers(), WalkerLogCollector::collect(), WalkerLogCollector::init(), and WalkerLogCollector::resetBuffers().

◆ Stmp

Array<WLog::Real, 1> Stmp
private

tmp storage for walker spins

Definition at line 78 of file WalkerLogCollector.h.

Referenced by WalkerLogCollector::collect().

◆ walker_particle_real_buffer

◆ walker_property_int_buffer

◆ walker_property_real_buffer


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