QMCPACK
EstimatorManagerNew Class Reference

Class to manage a set of ScalarEstimators As a manager, this class handles the aggregation of data from crowds, MPI ranks and I/O logics. More...

+ Collaboration diagram for EstimatorManagerNew:

Public Types

using RealType = QMCTraits::FullPrecRealType
 This is to deal with vague expression of precision in legacy code. Don't use in new code. More...
 
using FullPrecRealType = QMCTraits::FullPrecRealType
 
using QMCT = QMCTraits
 
using FPRBuffer = std::vector< FullPrecRealType >
 
using MCPWalker = Walker< QMCTraits, PtclOnLatticeTraits >
 

Public Member Functions

 EstimatorManagerNew (const QMCHamiltonian &ham, Communicate *comm)
 default constructor More...
 
 EstimatorManagerNew (EstimatorManagerNew &em)=delete
 copy constructor, deleted More...
 
 EstimatorManagerNew (Communicate *comm, EstimatorManagerInput &&emi, const QMCHamiltonian &H, const ParticleSet &pset, const TrialWaveFunction &twf)
 Batched version constructor. More...
 
 ~EstimatorManagerNew ()
 destructor More...
 
int addEstOperator (OperatorEstBase &op_est)
 add a "non" physical operator estimator More...
 
bool put (QMCHamiltonian &H, const ParticleSet &pset, const TrialWaveFunction &twf, xmlNodePtr cur)
 process xml tag associated with estimators More...
 
void startDriverRun ()
 Start the manager at the beginning of a driver run(). More...
 
void stopDriverRun ()
 Stop the manager at the end of a driver run(). More...
 
void startBlock (int steps)
 start a block More...
 
void stopBlock (unsigned long accept, unsigned long reject, RealType block_weight)
 unified: stop a block More...
 
void collectMainEstimators (const RefVector< ScalarEstimatorBase > &scalar_estimators)
 At end of block collect the main scalar estimators for the entire rank. More...
 
void collectScalarEstimators (const std::vector< RefVector< ScalarEstimatorBase >> &scalar_ests)
 Deals with possible free form scalar estimators. More...
 
void collectOperatorEstimators (const std::vector< RefVector< OperatorEstBase >> &op_ests)
 Reduces OperatorEstimator data from Crowds to the manager's OperatorEstimator data. More...
 
void getApproximateEnergyVariance (RealType &e, RealType &var)
 get the average of per-block energy and variance of all the blocks Note: this is not weighted average. More...
 
auto & get_AverageCache ()
 
std::size_t getNumEstimators ()
 
std::size_t getNumScalarEstimators ()
 
bool areThereListeners () const
 Do any of the instantiated estimators in operator_ests_ listen to per particle hamiltonian values? Listeners are lambda functions captured from crowd scope estimators and passed to QMCHamiltonian leaders. More...
 

Private Member Functions

template<typename EstInputType , typename... Args>
bool createEstimator (EstimatorInput &input, Args &&... args)
 Construct estimator of type matching the underlying EstimatorInput type Consumer and push its its unique_ptr onto operator_ests_. More...
 
template<typename EstInputType , typename... Args>
bool createScalarEstimator (ScalarEstimatorInput &input, Args &&... args)
 Construct scalar estimator of type matching the underlying ScalarEstimatorInput type Consumer and push its its unique_ptr onto operator_ests_. More...
 
void makeConfigReport (std::ostream &os) const
 Return a string with information about which estimators estimator manager is holding. More...
 
void reset ()
 reset the estimator More...
 
int addScalarEstimator (std::unique_ptr< ScalarEstimatorBase > &&estimator)
 add an Estimator More...
 
void addMainEstimator (std::unique_ptr< ScalarEstimatorBase > &&estimator)
 
void makeBlockAverages (unsigned long accept, unsigned long reject)
 collect data and write More...
 
void writeScalarH5 ()
 write scalars to scalar.dat and h5 More...
 
void reduceOperatorEstimators ()
 do the rank wise reduction of the OperatorEstimators More...
 
void writeOperatorEstimators ()
 Write OperatorEstimator data to *.stat.h5. More...
 
void zeroOperatorEstimators ()
 OperatorEstimators need to be zeroed out after the block is finished. More...
 
void addHeader (std::ostream &o)
 add header to an std::ostream More...
 

Private Attributes

int RecordCount
 number of records in a block More...
 
int weightInd
 index for the block weight PropertyCache(weightInd) More...
 
int cpuInd
 index for the block cpu PropertyCache(cpuInd) More...
 
int acceptRatioInd
 index for the accept counter PropertyCache(acceptInd) More...
 
std::unique_ptr< hdf_archiveh_file
 hdf5 handler More...
 
std::unique_ptr< std::ofstream > Archive
 file handler to write data More...
 
std::unique_ptr< std::ofstream > DebugArchive
 file handler to write data for debugging More...
 
Communicatemy_comm_
 communicator to handle communication More...
 
ScalarEstimatorBase::accumulator_type energyAccumulator
 accumulator for the energy More...
 
ScalarEstimatorBase::accumulator_type varAccumulator
 accumulator for the variance More...
 
Vector< RealTypeAverageCache
 cached block averages of the values More...
 
Vector< RealTypePropertyCache
 cached block averages of properties, e.g. BlockCPU More...
 
RecordNamedProperty< RealTypeBlockAverages
 manager of scalar data More...
 
RecordNamedProperty< RealTypeBlockProperties
 manager of property data More...
 
UPtr< ScalarEstimatorBasemain_estimator_
 main estimator i.e. some version of a local energy estimator. More...
 
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
 non main scalar estimators collecting simple scalars, are there any? with the removal of collectables these don't seem used or needed. More...
 
std::vector< ObservableHelperh5desc
 convenient descriptors for hdf5 More...
 
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
 OperatorEst Observables. More...
 
Timer block_timer_
 block timer More...
 
int max4ascii
 number of maximum data for a scalar.dat More...
 
size_t FieldWidth
 

Static Private Attributes

static constexpr std::string_view error_tag_ {"EstimatorManagerNew "}
 

Friends

class EstimatorManagerCrowd
 
class qmcplusplus::testing::EstimatorManagerNewTest
 
class qmcplusplus::testing::EstimatorManagerNewTestAccess
 

Detailed Description

Class to manage a set of ScalarEstimators As a manager, this class handles the aggregation of data from crowds, MPI ranks and I/O logics.

The actually per-crowd data accumulation is done by EstimatorManagerCrowd.

Definition at line 45 of file EstimatorManagerNew.h.

Member Typedef Documentation

◆ FPRBuffer

using FPRBuffer = std::vector<FullPrecRealType>

Definition at line 53 of file EstimatorManagerNew.h.

◆ FullPrecRealType

◆ MCPWalker

Definition at line 54 of file EstimatorManagerNew.h.

◆ QMCT

using QMCT = QMCTraits

Definition at line 52 of file EstimatorManagerNew.h.

◆ RealType

This is to deal with vague expression of precision in legacy code. Don't use in new code.

Definition at line 49 of file EstimatorManagerNew.h.

Constructor & Destructor Documentation

◆ EstimatorManagerNew() [1/3]

EstimatorManagerNew ( const QMCHamiltonian ham,
Communicate comm 
)

default constructor

Definition at line 50 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::addMainEstimator(), qmcplusplus::app_log(), qmcplusplus::ham, EstimatorManagerNew::max4ascii, and QMCHamiltonian::sizeOfObservables().

51  : RecordCount(0), my_comm_(c), max4ascii(8), FieldWidth(20)
52 {
53  app_log() << " Legacy constructor adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
55  addMainEstimator(std::make_unique<LocalEnergyEstimator>(ham, true));
56 }
int max4ascii
number of maximum data for a scalar.dat
std::ostream & app_log()
Definition: OutputManager.h:65
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
int RecordCount
number of records in a block
int sizeOfObservables() const
return the size of observables
Communicate * my_comm_
communicator to handle communication

◆ EstimatorManagerNew() [2/3]

copy constructor, deleted

◆ EstimatorManagerNew() [3/3]

EstimatorManagerNew ( Communicate comm,
EstimatorManagerInput &&  emi,
const QMCHamiltonian H,
const ParticleSet pset,
const TrialWaveFunction twf 
)

Batched version constructor.

Parameters
[in]emiEstimatorManagerInput consisting of merged global and local estimator definitions. Moved from!
[in]HFully Constructed Golden Hamiltonian.
[in]psetThe electron or equiv. pset
[in]twfThe fully constructed TrialWaveFunction.

Definition at line 95 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::addMainEstimator(), qmcplusplus::app_log(), qmcplusplus::emi(), EstimatorManagerNew::error_tag_, EstimatorManagerInput::get_estimator_inputs(), EstimatorManagerInput::get_scalar_estimator_inputs(), EstimatorManagerNew::main_estimator_, EstimatorManagerNew::makeConfigReport(), EstimatorManagerNew::max4ascii, EstimatorManagerNew::my_comm_, qmcplusplus::pset, Communicate::rank(), QMCHamiltonian::sizeOfObservables(), and qmcplusplus::twf.

100  : RecordCount(0), my_comm_(c), max4ascii(8), FieldWidth(20)
101 {
102  for (auto& est_input : emi.get_estimator_inputs())
103  if (!(createEstimator<SpinDensityInput>(est_input, pset.getLattice(), pset.getSpeciesSet()) ||
104  createEstimator<MomentumDistributionInput>(est_input, pset.getTotalNum(), pset.getTwist(),
105  pset.getLattice()) ||
106  createEstimator<SelfHealingOverlapInput>(est_input,twf) ||
107  createEstimator<OneBodyDensityMatricesInput>(est_input, pset.getLattice(), pset.getSpeciesSet(),
108  twf.getSPOMap(), pset) ||
109  createEstimator<MagnetizationDensityInput>(est_input, pset.getLattice()) ||
110  createEstimator<PerParticleHamiltonianLoggerInput>(est_input, my_comm_->rank())))
111  throw UniformCommunicateError(std::string(error_tag_) +
112  "cannot construct an estimator from estimator input object.");
113 
115  if (!(createScalarEstimator<LocalEnergyInput>(scalar_input, H) ||
116  createScalarEstimator<CSLocalEnergyInput>(scalar_input, H) ||
117  createScalarEstimator<RMCLocalEnergyInput>(scalar_input, H)))
118  throw UniformCommunicateError(std::string(error_tag_) +
119  "cannot construct a scalar estimator from scalar estimator input object.");
120 
121  if (main_estimator_ == nullptr)
122  {
123  app_log() << " Adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
124  max4ascii = H.sizeOfObservables() + 3;
125  addMainEstimator(std::make_unique<LocalEnergyEstimator>(H, true));
126  }
127 
129 }
ScalarEstimatorInputs & get_scalar_estimator_inputs()
int rank() const
return the rank
Definition: Communicate.h:116
int max4ascii
number of maximum data for a scalar.dat
std::ostream & app_log()
Definition: OutputManager.h:65
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
static constexpr std::string_view error_tag_
int RecordCount
number of records in a block
EstimatorManagerInput emi(estimators_doc.getRoot())
void makeConfigReport(std::ostream &os) const
Return a string with information about which estimators estimator manager is holding.
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
Communicate * my_comm_
communicator to handle communication
testing::ValidScalarEstimatorInput scalar_input

◆ ~EstimatorManagerNew()

~EstimatorManagerNew ( )
default

destructor

Member Function Documentation

◆ addEstOperator()

int addEstOperator ( OperatorEstBase op_est)

add a "non" physical operator estimator

this is a dratically reduced version of OperatorBase right now it just supports what the SpinDensityNew estimator needs

What is actually important is that it has its own locality aware data and EstimatorManagerNew doesn't know about or manage that data.

◆ addHeader()

void addHeader ( std::ostream &  o)
private

add header to an std::ostream

Definition at line 179 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::BlockAverages, EstimatorManagerNew::BlockProperties, EstimatorManagerNew::FieldWidth, EstimatorManagerNew::max4ascii, omptarget::min(), RecordNamedProperty< T >::Names, and RecordNamedProperty< T >::size().

Referenced by EstimatorManagerNew::startDriverRun().

180 {
181  o.setf(std::ios::scientific, std::ios::floatfield);
182  o.setf(std::ios::left, std::ios::adjustfield);
183  o.precision(10);
184  for (int i = 0; i < BlockAverages.size(); i++)
185  FieldWidth = std::max(FieldWidth, BlockAverages.Names[i].size() + 2);
186  for (int i = 0; i < BlockProperties.size(); i++)
187  FieldWidth = std::max(FieldWidth, BlockProperties.Names[i].size() + 2);
188  int maxobjs = std::min(BlockAverages.size(), max4ascii);
189  o << "# index ";
190  for (int i = 0; i < maxobjs; i++)
191  o << std::setw(FieldWidth) << BlockAverages.Names[i];
192  for (int i = 0; i < BlockProperties.size(); i++)
193  o << std::setw(FieldWidth) << BlockProperties.Names[i];
194  o << std::endl;
195  o.setf(std::ios::right, std::ios::adjustfield);
196 }
int max4ascii
number of maximum data for a scalar.dat
T min(T a, T b)
std::vector< std::string > Names
RecordNamedProperty< RealType > BlockAverages
manager of scalar data
RecordNamedProperty< RealType > BlockProperties
manager of property data

◆ addMainEstimator()

void addMainEstimator ( std::unique_ptr< ScalarEstimatorBase > &&  estimator)
private

Definition at line 551 of file EstimatorManagerNew.cpp.

References qmcplusplus::app_log(), and EstimatorManagerNew::main_estimator_.

Referenced by EstimatorManagerNew::createScalarEstimator(), EstimatorManagerNew::EstimatorManagerNew(), EstimatorManagerNew::put(), and EstimatorManagerNewTest::testReplaceMainEstimator().

552 {
553  if (main_estimator_ != nullptr)
554  app_log() << " EstimatorManagerNew replaced its main estimator with " << estimator->getSubTypeStr()
555  << " estimator." << std::endl;
556  main_estimator_ = std::move(estimator);
557 }
std::ostream & app_log()
Definition: OutputManager.h:65
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.

◆ addScalarEstimator()

int addScalarEstimator ( std::unique_ptr< ScalarEstimatorBase > &&  estimator)
private

add an Estimator

Parameters
[in]estimatorNew Estimator
Returns
index of newestimator

Definition at line 559 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::scalar_ests_.

Referenced by EstimatorManagerNewTest::fakeScalarSamplesAndCollect().

560 {
561  scalar_ests_.push_back(std::move(estimator));
562  return scalar_ests_.size() - 1;
563 }
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ areThereListeners()

bool areThereListeners ( ) const

Do any of the instantiated estimators in operator_ests_ listen to per particle hamiltonian values? Listeners are lambda functions captured from crowd scope estimators and passed to QMCHamiltonian leaders.

Definition at line 58 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::operator_ests_.

Referenced by Crowd::Crowd().

59 {
60  return std::any_of(operator_ests_.begin(), operator_ests_.end(),
61  [](auto& oper_est) { return oper_est->isListenerRequired(); });
62 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.

◆ collectMainEstimators()

void collectMainEstimators ( const RefVector< ScalarEstimatorBase > &  scalar_estimators)

At end of block collect the main scalar estimators for the entire rank.

One per crowd over multiple walkers

Definition at line 264 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::AverageCache, and Vector< T, Alloc >::begin().

Referenced by EstimatorManagerNewTest::collectMainEstimators(), and EstimatorManagerNewTest::testMakeBlockAverages().

265 {
266  AverageCache = 0.0;
267  for (ScalarEstimatorBase& est : main_estimators)
268  est.addAccumulated(AverageCache.begin());
269 }
Vector< RealType > AverageCache
cached block averages of the values

◆ collectOperatorEstimators()

void collectOperatorEstimators ( const std::vector< RefVector< OperatorEstBase >> &  op_ests)

Reduces OperatorEstimator data from Crowds to the manager's OperatorEstimator data.

Parameters
[in]op_ests- vector of each crowds vector of references to their OperatorEstimators.

A particular OperatorEstimators reduction via a call to collect may be straight forward if the crowd context OperatorEstimator holds a copy of the estimator data structure or more complex if it just collects for instance a list of writes to locations in the data structure.

Definition at line 287 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::operator_ests_.

288 {
289  for (int iop = 0; iop < operator_ests_.size(); ++iop)
290  {
291  RefVector<OperatorEstBase> this_op_est_for_all_crowds;
292  for (int icrowd = 0; icrowd < crowd_op_ests.size(); ++icrowd)
293  this_op_est_for_all_crowds.emplace_back(crowd_op_ests[icrowd][iop]);
294  operator_ests_[iop]->collect(this_op_est_for_all_crowds);
295  }
296 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.

◆ collectScalarEstimators()

void collectScalarEstimators ( const std::vector< RefVector< ScalarEstimatorBase >> &  scalar_ests)

Deals with possible free form scalar estimators.

Parameters
[in]scalar_ests- vector of each crowds vector of references to their OperatorEstimators. Still looking for actual use case.

Definition at line 271 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::AverageCache, Vector< T, Alloc >::begin(), and EstimatorManagerNew::scalar_ests_.

Referenced by EstimatorManagerNewTest::fakeScalarSamplesAndCollect().

272 {
273  assert(crowd_scalar_ests[0].size() == scalar_ests_.size());
274  for (int iop = 0; iop < scalar_ests_.size(); ++iop)
275  {
276  RefVector<ScalarEstimatorBase> this_scalar_est_for_all_crowds;
277  for (int icrowd = 0; icrowd < crowd_scalar_ests.size(); ++icrowd)
278  this_scalar_est_for_all_crowds.emplace_back(crowd_scalar_ests[icrowd][iop]);
279  // There is actually state in each Scalar estimator that tells it what it's "first" index in the AverageCache
280  // is, It's quite unclear to me if that would really work so I'm doing this in anticipation of having to rework that
281  // if we don't drop multiple scalar estimators per crowd all together.
282  for (ScalarEstimatorBase& est : this_scalar_est_for_all_crowds)
283  est.addAccumulated(AverageCache.begin());
284  }
285 }
Vector< RealType > AverageCache
cached block averages of the values
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ createEstimator()

bool createEstimator ( EstimatorInput input,
Args &&...  args 
)
private

Construct estimator of type matching the underlying EstimatorInput type Consumer and push its its unique_ptr onto operator_ests_.

Definition at line 65 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::operator_ests_.

66 {
67  if (has<EstInputType>(input))
68  {
69  operator_ests_.push_back(std::make_unique<typename EstInputType::Consumer>(std::move(std::get<EstInputType>(input)),
70  std::forward<Args>(args)...));
71  return true;
72  }
73  else
74  return false;
75 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
testing::ValidSpinDensityInput input

◆ createScalarEstimator()

bool createScalarEstimator ( ScalarEstimatorInput input,
Args &&...  args 
)
private

Construct scalar estimator of type matching the underlying ScalarEstimatorInput type Consumer and push its its unique_ptr onto operator_ests_.

Definition at line 78 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::addMainEstimator(), and EstimatorManagerNew::scalar_ests_.

79 {
80  if (has<EstInputType>(input))
81  {
82  auto estimator = std::make_unique<typename EstInputType::Consumer>(std::move(std::get<EstInputType>(input)),
83  std::forward<Args>(args)...);
84  if (estimator->isMainEstimator())
85  addMainEstimator(std::move(estimator));
86  else
87  scalar_ests_.push_back(std::move(estimator));
88  return true;
89  }
90  else
91  return false;
92 }
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
testing::ValidSpinDensityInput input
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ get_AverageCache()

auto& get_AverageCache ( )
inline

◆ getApproximateEnergyVariance()

void getApproximateEnergyVariance ( RealType e,
RealType var 
)

get the average of per-block energy and variance of all the blocks Note: this is not weighted average.

It can be the same as weighted average only when block weights are identical.

Definition at line 437 of file EstimatorManagerNew.cpp.

References Communicate::bcast(), accumulator_set< T, typename >::count(), qmcplusplus::Units::charge::e, EstimatorManagerNew::energyAccumulator, EstimatorManagerNew::my_comm_, accumulator_set< T, typename >::result(), and EstimatorManagerNew::varAccumulator.

438 {
439  RealType tmp[3];
440  tmp[0] = energyAccumulator.count();
441  tmp[1] = energyAccumulator.result();
442  tmp[2] = varAccumulator.result();
443  my_comm_->bcast(tmp, 3);
444  e = tmp[1] / tmp[0];
445  var = tmp[2] / tmp[0] - e * e;
446 }
ScalarEstimatorBase::accumulator_type energyAccumulator
accumulator for the energy
ScalarEstimatorBase::accumulator_type varAccumulator
accumulator for the variance
QMCTraits::RealType RealType
return_type result() const
return the sum
Definition: accumulators.h:108
Communicate * my_comm_
communicator to handle communication
return_type count() const
return the count
Definition: accumulators.h:116
void bcast(T &)

◆ getNumEstimators()

std::size_t getNumEstimators ( )
inline

Definition at line 146 of file EstimatorManagerNew.h.

References EstimatorManagerNew::operator_ests_.

Referenced by qmcplusplus::TEST_CASE().

146 { return operator_ests_.size(); }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.

◆ getNumScalarEstimators()

std::size_t getNumScalarEstimators ( )
inline

Definition at line 147 of file EstimatorManagerNew.h.

References EstimatorManagerNew::scalar_ests_.

Referenced by qmcplusplus::TEST_CASE().

147 { return scalar_ests_.size(); }
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ makeBlockAverages()

void makeBlockAverages ( unsigned long  accept,
unsigned long  reject 
)
private

collect data and write

Definition at line 298 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::acceptRatioInd, Communicate::allreduce(), EstimatorManagerNew::AverageCache, Vector< T, Alloc >::begin(), copy(), Vector< T, Alloc >::end(), EstimatorManagerNew::energyAccumulator, EstimatorManagerNew::my_comm_, EstimatorManagerNew::PropertyCache, Communicate::rank(), Communicate::size(), Vector< T, Alloc >::size(), EstimatorManagerNew::varAccumulator, and EstimatorManagerNew::weightInd.

Referenced by EstimatorManagerNew::stopBlock(), and EstimatorManagerNewTest::testMakeBlockAverages().

299 {
300  // accumulate unsigned long counters over ranks.
301  // Blocks ends are infrequent, two MPI transfers to preserve type
302  // these could be replaced with a singple call MPI_struct_type some packing scheme or even
303  // a pack into and out of an fp type that can be assured to hold the integral type exactly
304  // IMHO they should not be primarily stored in a vector with magic indexes
305  std::vector<unsigned long> accepts_and_rejects(my_comm_->size() * 2, 0);
306  accepts_and_rejects[my_comm_->rank()] = accepts;
307  accepts_and_rejects[my_comm_->size() + my_comm_->rank()] = rejects;
308  my_comm_->allreduce(accepts_and_rejects);
309  int64_t total_block_accept =
310  std::accumulate(accepts_and_rejects.begin(), accepts_and_rejects.begin() + my_comm_->size(), int64_t(0));
311  int64_t total_block_reject = std::accumulate(accepts_and_rejects.begin() + my_comm_->size(),
312  accepts_and_rejects.begin() + my_comm_->size() * 2, int64_t(0));
313 
314  //Transfer FullPrecisionRead data
315  const size_t n1 = AverageCache.size();
316  const size_t n2 = n1 + PropertyCache.size();
317 
318  // This is a hack but it needs to be the correct size
319 
320  std::vector<double> reduce_buffer(n2, 0.0);
321  {
322  auto cur = reduce_buffer.begin();
324  copy(PropertyCache.begin(), PropertyCache.end(), cur + n1);
325  }
326 
327  // This is necessary to use mpi3's C++ style reduce
328 #ifdef HAVE_MPI
329  my_comm_->comm.reduce_in_place_n(reduce_buffer.begin(), reduce_buffer.size(), std::plus<>{});
330 #endif
331  if (my_comm_->rank() == 0)
332  {
333  auto cur = reduce_buffer.begin();
334  copy(cur, cur + n1, AverageCache.begin());
335  copy(cur + n1, cur + n2, PropertyCache.begin());
336  const RealType invTotWgt = 1.0 / PropertyCache[weightInd];
337  AverageCache *= invTotWgt;
338  //do not weight weightInd i.e. its index 0!
339  for (int i = 1; i < PropertyCache.size(); i++)
340  PropertyCache[i] *= invTotWgt;
341  }
342 
343  // now we put the correct accept ratio in
344  PropertyCache[acceptRatioInd] = static_cast<FullPrecRealType>(total_block_accept) /
345  static_cast<FullPrecRealType>(total_block_accept + total_block_reject);
346 
347  //add the block average to summarize
350 }
int rank() const
return the rank
Definition: Communicate.h:116
Vector< RealType > AverageCache
cached block averages of the values
int weightInd
index for the block weight PropertyCache(weightInd)
int size() const
return the number of tasks
Definition: Communicate.h:118
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
void allreduce(T &)
size_type size() const
return the current size
Definition: OhmmsVector.h:162
int acceptRatioInd
index for the accept counter PropertyCache(acceptInd)
ScalarEstimatorBase::accumulator_type energyAccumulator
accumulator for the energy
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU
ScalarEstimatorBase::accumulator_type varAccumulator
accumulator for the variance
QMCTraits::RealType RealType
Communicate * my_comm_
communicator to handle communication
QMCTraits::FullPrecRealType FullPrecRealType

◆ makeConfigReport()

void makeConfigReport ( std::ostream &  os) const
private

Return a string with information about which estimators estimator manager is holding.

Definition at line 161 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::main_estimator_, EstimatorManagerNew::operator_ests_, and EstimatorManagerNew::scalar_ests_.

Referenced by EstimatorManagerNew::EstimatorManagerNew().

162 {
163  os << "EstimatorManager setup for this section:\n"
164  << " Main Estimator: " << main_estimator_->getSubTypeStr() << '\n';
165  if (scalar_ests_.size() > 0)
166  {
167  os << " ScalarEstimators:\n";
168  for (auto& scalar_est : scalar_ests_)
169  os << " " << scalar_est->getSubTypeStr() << '\n';
170  }
171  if (operator_ests_.size() > 0)
172  {
173  os << " General Estimators:\n";
174  for (auto& est : operator_ests_)
175  os << " " << est->get_my_name() << '\n';
176  }
177 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ put()

bool put ( QMCHamiltonian H,
const ParticleSet pset,
const TrialWaveFunction twf,
xmlNodePtr  cur 
)

process xml tag associated with estimators

Definition at line 448 of file EstimatorManagerNew.cpp.

References OhmmsAttributeSet::add(), EstimatorManagerNew::addMainEstimator(), qmcplusplus::app_log(), qmcplusplus::crowd, CrystalLattice< T, D >::explicitly_defined, SpinDensityInput::get_cell(), SpinDensityInput::get_save_memory(), EstimatorManagerNew::main_estimator_, EstimatorManagerNew::max4ascii, qmcplusplus::obdmi, EstimatorManagerNew::operator_ests_, qmcplusplus::pset, qmcplusplus::pset_target, OhmmsAttributeSet::put(), qmcplusplus::rank, QMCHamiltonian::sizeOfObservables(), and qmcplusplus::twf.

449 {
450  std::vector<std::string> extra_types;
451  std::vector<std::string> extra_names;
452  cur = cur->children;
453  std::string MainEstimatorName("LocalEnergy");
454  while (cur != NULL)
455  {
456  std::string cname((const char*)(cur->name));
457  if (cname == "estimator")
458  {
459  std::string est_type("none");
460  std::string est_name(MainEstimatorName);
461  std::string use_hdf5("yes");
462  OhmmsAttributeSet hAttrib;
463  hAttrib.add(est_type, "type");
464  hAttrib.add(est_name, "name");
465  hAttrib.add(use_hdf5, "hdf5");
466  hAttrib.put(cur);
467  if ((est_name == MainEstimatorName) || (est_name == "elocal"))
468  {
469  max4ascii = H.sizeOfObservables() + 3;
470  addMainEstimator(std::make_unique<LocalEnergyEstimator>(H, use_hdf5 == "yes"));
471  }
472  else if (est_name == "RMC")
473  {
474  int nobs(20);
475  OhmmsAttributeSet hAttrib;
476  hAttrib.add(nobs, "nobs");
477  hAttrib.put(cur);
478  max4ascii = nobs * H.sizeOfObservables() + 3;
479  addMainEstimator(std::make_unique<RMCLocalEnergyEstimator>(H, nobs));
480  }
481  else if (est_name == "CSLocalEnergy")
482  {
483  OhmmsAttributeSet hAttrib;
484  int nPsi = 1;
485  hAttrib.add(nPsi, "nPsi");
486  hAttrib.put(cur);
487  addMainEstimator(std::make_unique<CSEnergyEstimator>(H, nPsi));
488  app_log() << " Adding a CSLocalEnergy estimator for the MainEstimator " << std::endl;
489  }
490  else if (est_name == "SpinDensityNew")
491  {
492  SpinDensityInput spdi(cur);
494  if (spdi.get_save_memory())
495  dl = DataLocality::rank;
496  if (spdi.get_cell().explicitly_defined)
497  operator_ests_.emplace_back(std::make_unique<SpinDensityNew>(std::move(spdi), pset.getSpeciesSet(), dl));
498  else
499  operator_ests_.emplace_back(
500  std::make_unique<SpinDensityNew>(std::move(spdi), pset.getLattice(), pset.getSpeciesSet(), dl));
501  }
502  else if (est_type == "MomentumDistribution")
503  {
504  MomentumDistributionInput mdi(cur);
506  operator_ests_.emplace_back(std::make_unique<MomentumDistribution>(std::move(mdi), pset.getTotalNum(),
507  pset.getTwist(), pset.getLattice(), dl));
508  }
509  else if (est_type == "OneBodyDensityMatrices")
510  {
511  OneBodyDensityMatricesInput obdmi(cur);
512  // happens once insures golden particle set is not abused.
513  ParticleSet pset_target(pset);
514  operator_ests_.emplace_back(std::make_unique<OneBodyDensityMatrices>(std::move(obdmi), pset.getLattice(),
515  pset.getSpeciesSet(), twf.getSPOMap(),
516  pset_target));
517  }
518  else if (est_type == "MagnetizationDensity")
519  {
520  MagnetizationDensityInput magdensinput(cur);
521  ParticleSet pset_target(pset);
522  operator_ests_.emplace_back(std::make_unique<MagnetizationDensity>(std::move(magdensinput), pset.getLattice()));
523  }
524  else
525  {
526  extra_types.push_back(est_type);
527  extra_names.push_back(est_name);
528  }
529  }
530  cur = cur->next;
531  }
532  if (main_estimator_ == nullptr)
533  {
534  app_log() << " ::put Adding a default LocalEnergyEstimator for the MainEstimator " << std::endl;
535  max4ascii = H.sizeOfObservables() + 3;
536  addMainEstimator(std::make_unique<LocalEnergyEstimator>(H, true));
537  }
538  if (!extra_types.empty())
539  {
540  app_log() << "\nUnrecognized estimators in input:" << std::endl;
541  for (int i = 0; i < extra_types.size(); i++)
542  {
543  app_log() << " type: " << extra_types[i] << " name: " << extra_names[i] << std::endl;
544  }
545  app_log() << std::endl;
546  throw UniformCommunicateError("Unrecognized estimators encountered in input. See log message for more details.");
547  }
548  return true;
549 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
int max4ascii
number of maximum data for a scalar.dat
std::ostream & app_log()
Definition: OutputManager.h:65
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
OneBodyDensityMatricesInput obdmi(node)
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
DataLocality
data locality with respect to walker buffer
Definition: DataLocality.h:19
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42

◆ reduceOperatorEstimators()

void reduceOperatorEstimators ( )
private

do the rank wise reduction of the OperatorEstimators

Why do this here?

  1. Operator estimators don't know about the concurrency model
  2. EstimatorManager owns the resources: send & receive buffers
  3. The operation is generic as long as OperatorEstimator satisfies the requirement that get_data_ref() returns a reference to std::vector<RealType>

Implementation makes the assumption that sending each OperatorEstimator separately is the correct memory use vs. mpi message balance.

Definition at line 375 of file EstimatorManagerNew.cpp.

References qmcplusplus::convertUPtrToRefVector(), qmcplusplus::syclBLAS::copy_n(), EstimatorManagerNew::my_comm_, EstimatorManagerNew::operator_ests_, and Communicate::rank().

Referenced by EstimatorManagerNew::stopBlock(), and EstimatorManagerNewTest::testReduceOperatorEstimators().

376 {
377  if (operator_ests_.size() > 0)
378  {
379  std::vector<size_t> operator_data_sizes(operator_ests_.size());
380  RefVector<OperatorEstBase> ref_op_ests = convertUPtrToRefVector(operator_ests_);
381  for (int iop = 0; iop < operator_data_sizes.size(); ++iop)
382  {
383  operator_data_sizes[iop] = operator_ests_[iop]->get_data().size();
384  }
385  // 1 larger because we put the weight in to avoid dependence of the Scalar estimators being reduced firt.
386  size_t nops = *(std::max_element(operator_data_sizes.begin(), operator_data_sizes.end())) + 1;
387  std::vector<RealType> operator_send_buffer;
388  std::vector<RealType> operator_recv_buffer;
389  operator_send_buffer.reserve(nops);
390  operator_recv_buffer.reserve(nops);
391  for (int iop = 0; iop < operator_ests_.size(); ++iop)
392  {
393  auto& estimator = *operator_ests_[iop];
394  auto& data = estimator.get_data();
395  size_t adjusted_size = data.size() + 1;
396  operator_send_buffer.resize(adjusted_size, 0.0);
397  operator_recv_buffer.resize(adjusted_size, 0.0);
398  std::copy_n(data.begin(), data.size(), operator_send_buffer.begin());
399  operator_send_buffer[data.size()] = estimator.get_walkers_weight();
400  // This is necessary to use mpi3's C++ style reduce
401 #ifdef HAVE_MPI
402  my_comm_->comm.reduce_n(operator_send_buffer.begin(), adjusted_size, operator_recv_buffer.begin(), std::plus<>{},
403  0);
404 #else
405  operator_recv_buffer = operator_send_buffer;
406 #endif
407  if (my_comm_->rank() == 0)
408  {
409  std::copy_n(operator_recv_buffer.begin(), data.size(), data.begin());
410  size_t reduced_walker_weights = operator_recv_buffer[data.size()];
411  RealType invTotWgt = 1.0 / static_cast<QMCT::RealType>(reduced_walker_weights);
412  operator_ests_[iop]->normalize(invTotWgt);
413  }
414  }
415  }
416 }
int rank() const
return the rank
Definition: Communicate.h:116
QTBase::RealType RealType
Definition: Configuration.h:58
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
static RefVector< T > convertUPtrToRefVector(const UPtrVector< T > &ptr_list)
convert a vector of std::unique_ptrs<T> to a refvector<T>
QMCTraits::RealType RealType
sycl::event copy_n(sycl::queue &aq, const T1 *restrict VA, size_t array_size, T2 *restrict VC, const std::vector< sycl::event > &events)
Definition: syclBLAS.cpp:548
Communicate * my_comm_
communicator to handle communication

◆ reset()

void reset ( )
private

reset the estimator

reset names of the properties

Todo:
this should be in in constructor object shouldn't be reused Warning this is different from some "resets" in the code, it does not clear the object

The number of estimators and their order can vary from the previous state. reinitialized properties before setting up a new BlockAverage data list.

The object is still not completely valid.

Definition at line 144 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::acceptRatioInd, RecordNamedProperty< T >::add(), EstimatorManagerNew::BlockAverages, EstimatorManagerNew::BlockProperties, RecordNamedProperty< T >::clear(), EstimatorManagerNew::cpuInd, EstimatorManagerNew::main_estimator_, EstimatorManagerNew::max4ascii, EstimatorManagerNew::scalar_ests_, RecordNamedProperty< T >::size(), and EstimatorManagerNew::weightInd.

Referenced by EstimatorManagerNew::startDriverRun().

145 {
146  //It's essential that this one is first, other code assumes weightInd always == 0
147  weightInd = BlockProperties.add("BlockWeight");
148  assert(weightInd == 0);
149  cpuInd = BlockProperties.add("BlockCPU");
150  acceptRatioInd = BlockProperties.add("AcceptRatio");
151  BlockAverages.clear(); //cleaup the records
152  // Side effect of this is that BlockAverages becomes size to number of scalar values tracked by all the
153  // scalar estimators
154  main_estimator_->add2Record(BlockAverages);
155  for (int i = 0; i < scalar_ests_.size(); i++)
156  scalar_ests_[i]->add2Record(BlockAverages);
157  // possibly redundant variable
159 }
int max4ascii
number of maximum data for a scalar.dat
int weightInd
index for the block weight PropertyCache(weightInd)
int acceptRatioInd
index for the accept counter PropertyCache(acceptInd)
int add(const std::string &aname)
int cpuInd
index for the block cpu PropertyCache(cpuInd)
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
RecordNamedProperty< RealType > BlockAverages
manager of scalar data
RecordNamedProperty< RealType > BlockProperties
manager of property data
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ startBlock()

void startBlock ( int  steps)

start a block

Parameters
stepsnumber of steps in a block

Definition at line 244 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::block_timer_, and Timer::restart().

◆ startDriverRun()

void startDriverRun ( )

Start the manager at the beginning of a driver run().

Open files. Setting zeros.

Parameters
blocksnumber of blocks
recordif true, will write to a file

Replace reportHeader and reset functon.

Todo:
clean up this method its a mess

Definition at line 199 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::addHeader(), EstimatorManagerNew::Archive, EstimatorManagerNew::AverageCache, EstimatorManagerNew::BlockAverages, EstimatorManagerNew::BlockProperties, accumulator_set< T, typename >::clear(), EstimatorManagerNew::DebugArchive, EstimatorManagerNew::energyAccumulator, Communicate::getName(), EstimatorManagerNew::h5desc, EstimatorManagerNew::h_file, EstimatorManagerNew::main_estimator_, EstimatorManagerNew::my_comm_, EstimatorManagerNew::operator_ests_, EstimatorManagerNew::PropertyCache, Communicate::rank(), EstimatorManagerNew::RecordCount, EstimatorManagerNew::reset(), Vector< T, Alloc >::resize(), EstimatorManagerNew::scalar_ests_, RecordNamedProperty< T >::setValues(), RecordNamedProperty< T >::size(), and EstimatorManagerNew::varAccumulator.

200 {
201  reset();
202  RecordCount = 0;
208  // Now Estimatormanager New is actually valid i.e. in the state you would expect after the constructor.
209  // Until the put is dropped this isn't feasible to fix.
210 #if defined(DEBUG_ESTIMATOR_ARCHIVE)
211  if (!DebugArchive)
212  {
213  std::array<char, 128> fname;
214  if (std::snprintf(fname.data(), fname.size(), "%s.p%03d.scalar.dat", my_comm_->getName().c_str(),
215  my_comm_->rank()) < 0)
216  throw std::runtime_error("Error generating filename");
217  DebugArchive = std::make_unique<std::ofstream>(fname.data());
219  }
220 #endif
221  if (my_comm_->rank() == 0)
222  {
223  std::filesystem::path fname(my_comm_->getName());
224  fname.concat(".scalar.dat");
225  Archive = std::make_unique<std::ofstream>(fname);
226  addHeader(*Archive);
227  if (h5desc.size())
228  {
229  h5desc.clear();
230  }
231  fname = my_comm_->getName() + ".stat.h5";
232  h_file = std::make_unique<hdf_archive>();
233  h_file->create(fname);
234  main_estimator_->registerObservables(h5desc, *h_file);
235  for (int i = 0; i < scalar_ests_.size(); i++)
236  scalar_ests_[i]->registerObservables(h5desc, *h_file);
237  for (auto& uope : operator_ests_)
238  uope->registerOperatorEstimator(*h_file);
239  }
240 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
std::unique_ptr< std::ofstream > Archive
file handler to write data
int rank() const
return the rank
Definition: Communicate.h:116
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
Vector< RealType > AverageCache
cached block averages of the values
std::vector< ObservableHelper > h5desc
convenient descriptors for hdf5
std::unique_ptr< std::ofstream > DebugArchive
file handler to write data for debugging
int RecordCount
number of records in a block
const std::string & getName() const
Definition: Communicate.h:131
ScalarEstimatorBase::accumulator_type energyAccumulator
accumulator for the energy
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU
ScalarEstimatorBase::accumulator_type varAccumulator
accumulator for the variance
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
RecordNamedProperty< RealType > BlockAverages
manager of scalar data
void reset()
reset the estimator
std::unique_ptr< hdf_archive > h_file
hdf5 handler
Communicate * my_comm_
communicator to handle communication
void addHeader(std::ostream &o)
add header to an std::ostream
RecordNamedProperty< RealType > BlockProperties
manager of property data
std::vector< UPtr< ScalarEstimatorBase > > scalar_ests_
non main scalar estimators collecting simple scalars, are there any? with the removal of collectables...

◆ stopBlock()

void stopBlock ( unsigned long  accept,
unsigned long  reject,
RealType  block_weight 
)

unified: stop a block

Parameters
acceptacceptance rate of this block
[in]accept
[in]reject
[in]block_weight

Definition at line 246 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::block_timer_, EstimatorManagerNew::cpuInd, Timer::elapsed(), EstimatorManagerNew::makeBlockAverages(), EstimatorManagerNew::PropertyCache, EstimatorManagerNew::RecordCount, EstimatorManagerNew::reduceOperatorEstimators(), EstimatorManagerNew::weightInd, EstimatorManagerNew::writeOperatorEstimators(), EstimatorManagerNew::writeScalarH5(), and EstimatorManagerNew::zeroOperatorEstimators().

247 {
248  /* Need a redesign of how accept, reject and block_weight are handled from driver to this manager.
249  * DMC needs to add non-local move counters.
250  * also need to add num_samples which differs from block_weight
251  */
252  //take block averages and update properties per block
253  PropertyCache[weightInd] = block_weight;
254  makeBlockAverages(accept, reject);
258  // intentionally put after all the estimator I/O
260  writeScalarH5();
261  RecordCount++;
262 }
double elapsed() const
Definition: Timer.h:30
void zeroOperatorEstimators()
OperatorEstimators need to be zeroed out after the block is finished.
void makeBlockAverages(unsigned long accept, unsigned long reject)
collect data and write
void writeOperatorEstimators()
Write OperatorEstimator data to *.stat.h5.
int weightInd
index for the block weight PropertyCache(weightInd)
int RecordCount
number of records in a block
void writeScalarH5()
write scalars to scalar.dat and h5
void reduceOperatorEstimators()
do the rank wise reduction of the OperatorEstimators
int cpuInd
index for the block cpu PropertyCache(cpuInd)
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU

◆ stopDriverRun()

void stopDriverRun ( )

Stop the manager at the end of a driver run().

Flush/close files.

Definition at line 242 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::h_file.

242 { h_file.reset(); }
std::unique_ptr< hdf_archive > h_file
hdf5 handler

◆ writeOperatorEstimators()

void writeOperatorEstimators ( )
private

Write OperatorEstimator data to *.stat.h5.

Note that OperatorEstimator owns its own observable_helpers

Definition at line 418 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::h_file, EstimatorManagerNew::my_comm_, EstimatorManagerNew::operator_ests_, and Communicate::rank().

Referenced by EstimatorManagerNew::stopBlock().

419 {
420  if (my_comm_->rank() == 0)
421  {
422  if (h_file)
423  {
424  for (auto& op_est : operator_ests_)
425  op_est->write(*h_file);
426  h_file->flush();
427  }
428  }
429 }
int rank() const
return the rank
Definition: Communicate.h:116
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
std::unique_ptr< hdf_archive > h_file
hdf5 handler
Communicate * my_comm_
communicator to handle communication

◆ writeScalarH5()

void writeScalarH5 ( )
private

write scalars to scalar.dat and h5

Definition at line 352 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::Archive, EstimatorManagerNew::AverageCache, EstimatorManagerNew::BlockAverages, Vector< T, Alloc >::data(), EstimatorManagerNew::FieldWidth, EstimatorManagerNew::h5desc, EstimatorManagerNew::h_file, EstimatorManagerNew::max4ascii, omptarget::min(), EstimatorManagerNew::PropertyCache, EstimatorManagerNew::RecordCount, Vector< T, Alloc >::size(), and RecordNamedProperty< T >::size().

Referenced by EstimatorManagerNew::stopBlock().

353 {
354  //Do not assume h_file is valid
355  if (h_file)
356  {
357  for (int o = 0; o < h5desc.size(); ++o)
358  // cheating here, remove SquaredAverageCache from API
359  h5desc[o].write(AverageCache.data(), *h_file);
360  h_file->flush();
361  }
362 
363  if (Archive)
364  {
365  *Archive << std::setw(10) << RecordCount;
366  int maxobjs = std::min(BlockAverages.size(), max4ascii);
367  for (int j = 0; j < maxobjs; j++)
368  *Archive << std::setw(FieldWidth) << AverageCache[j];
369  for (int j = 0; j < PropertyCache.size(); j++)
370  *Archive << std::setw(FieldWidth) << PropertyCache[j];
371  *Archive << std::endl;
372  }
373 }
std::unique_ptr< std::ofstream > Archive
file handler to write data
int max4ascii
number of maximum data for a scalar.dat
Vector< RealType > AverageCache
cached block averages of the values
std::vector< ObservableHelper > h5desc
convenient descriptors for hdf5
int RecordCount
number of records in a block
T min(T a, T b)
size_type size() const
return the current size
Definition: OhmmsVector.h:162
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU
RecordNamedProperty< RealType > BlockAverages
manager of scalar data
std::unique_ptr< hdf_archive > h_file
hdf5 handler

◆ zeroOperatorEstimators()

void zeroOperatorEstimators ( )
private

OperatorEstimators need to be zeroed out after the block is finished.

Definition at line 431 of file EstimatorManagerNew.cpp.

References EstimatorManagerNew::operator_ests_.

Referenced by EstimatorManagerNew::stopBlock().

432 {
433  for (auto& op_est : operator_ests_)
434  op_est->zero();
435 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.

Friends And Related Function Documentation

◆ EstimatorManagerCrowd

friend class EstimatorManagerCrowd
friend

Definition at line 276 of file EstimatorManagerNew.h.

◆ qmcplusplus::testing::EstimatorManagerNewTest

Definition at line 277 of file EstimatorManagerNew.h.

◆ qmcplusplus::testing::EstimatorManagerNewTestAccess

Definition at line 278 of file EstimatorManagerNew.h.

Member Data Documentation

◆ acceptRatioInd

int acceptRatioInd
private

index for the accept counter PropertyCache(acceptInd)

Definition at line 222 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::makeBlockAverages(), EstimatorManagerNew::reset(), and EstimatorManagerNewTest::testMakeBlockAverages().

◆ Archive

std::unique_ptr<std::ofstream> Archive
private

file handler to write data

Definition at line 226 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::startDriverRun(), and EstimatorManagerNew::writeScalarH5().

◆ AverageCache

◆ block_timer_

Timer block_timer_
private

block timer

Definition at line 265 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::startBlock(), and EstimatorManagerNew::stopBlock().

◆ BlockAverages

◆ BlockProperties

◆ cpuInd

int cpuInd
private

index for the block cpu PropertyCache(cpuInd)

Definition at line 220 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::reset(), EstimatorManagerNew::stopBlock(), and EstimatorManagerNewTest::testMakeBlockAverages().

◆ DebugArchive

std::unique_ptr<std::ofstream> DebugArchive
private

file handler to write data for debugging

Definition at line 228 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::startDriverRun().

◆ energyAccumulator

ScalarEstimatorBase::accumulator_type energyAccumulator
private

accumulator for the energy

Todo:
expand it for all the scalar observables to report the final results

Definition at line 235 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::getApproximateEnergyVariance(), EstimatorManagerNew::makeBlockAverages(), and EstimatorManagerNew::startDriverRun().

◆ error_tag_

constexpr std::string_view error_tag_ {"EstimatorManagerNew "}
staticprivate

Definition at line 274 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::EstimatorManagerNew().

◆ FieldWidth

size_t FieldWidth
private

◆ h5desc

std::vector<ObservableHelper> h5desc
private

convenient descriptors for hdf5

Definition at line 254 of file EstimatorManagerNew.h.

Referenced by EstimatorManagerNew::startDriverRun(), and EstimatorManagerNew::writeScalarH5().

◆ h_file

◆ main_estimator_

◆ max4ascii

◆ my_comm_

◆ operator_ests_

◆ PropertyCache

◆ RecordCount

int RecordCount
private

◆ scalar_ests_

◆ varAccumulator

◆ weightInd

int weightInd
private

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