QMCPACK
OperatorEstBase Class Referenceabstract

An abstract class for gridded estimators. More...

+ Inheritance diagram for OperatorEstBase:
+ Collaboration diagram for OperatorEstBase:

Public Types

using QMCT = QMCTraits
 
using FullPrecRealType = QMCT::FullPrecRealType
 
using MCPWalker = Walker< QMCTraits, PtclOnLatticeTraits >
 
using Data = std::vector< QMCT::RealType >
 

Public Member Functions

 OperatorEstBase (DataLocality dl)
 constructor More...
 
 OperatorEstBase (const OperatorEstBase &oth)
 Shallow copy constructor! This alows us to keep the default copy constructors for derived classes which is quite useful to the spawnCrowdClone design. More...
 
virtual ~OperatorEstBase ()=default
 virtual destructor More...
 
virtual void accumulate (const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, const RefVector< QMCHamiltonian > &hams, RandomBase< FullPrecRealType > &rng)=0
 Accumulate whatever it is you are accumulating with respect to walkers. More...
 
virtual void collect (const RefVector< OperatorEstBase > &oebs)
 Reduce estimator result data from crowds to rank. More...
 
virtual void normalize (QMCT::RealType invToWgt)
 
virtual void startBlock (int steps)=0
 
std::vector< QMCT::RealType > & get_data ()
 
virtual void registerOperatorEstimator (hdf_archive &file)
 
virtual std::unique_ptr< OperatorEstBasespawnCrowdClone () const =0
 
void write (hdf_archive &file)
 Write to previously registered observable_helper hdf5 wrapper. More...
 
void zero ()
 zero data appropriately for the DataLocality More...
 
QMCT::FullPrecRealType get_walkers_weight () const
 Return the total walker weight for this block. More...
 
const std::string & get_my_name () const
 
virtual void registerListeners (QMCHamiltonian &ham_leader)
 Register 0-many listeners with a leading QMCHamiltonian instance i.e. More...
 
bool isListenerRequired ()
 
DataLocality get_data_locality () const
 

Protected Attributes

DataLocality data_locality_
 locality for accumulation of estimator data. More...
 
std::string my_name_
 name of this object – only used for debugging and h5 output More...
 
QMCT::FullPrecRealType walkers_weight_
 
std::vector< ObservableHelperh5desc_
 
Data data_
 
bool requires_listener_ = false
 

Detailed Description

An abstract class for gridded estimators.

Definition at line 39 of file OperatorEstBase.h.

Member Typedef Documentation

◆ Data

using Data = std::vector<QMCT::RealType>

Definition at line 46 of file OperatorEstBase.h.

◆ FullPrecRealType

Definition at line 43 of file OperatorEstBase.h.

◆ MCPWalker

Definition at line 44 of file OperatorEstBase.h.

◆ QMCT

using QMCT = QMCTraits

Definition at line 42 of file OperatorEstBase.h.

Constructor & Destructor Documentation

◆ OperatorEstBase() [1/2]

constructor

Definition at line 20 of file OperatorEstBase.cpp.

QMCT::FullPrecRealType walkers_weight_
DataLocality data_locality_
locality for accumulation of estimator data.

◆ OperatorEstBase() [2/2]

OperatorEstBase ( const OperatorEstBase oth)

Shallow copy constructor! This alows us to keep the default copy constructors for derived classes which is quite useful to the spawnCrowdClone design.

Data is likely to be quite large and since the OperatorEstBase design is that the children reduce to the parent it is infact undesirable for them to copy the data the parent has. Initialization of Data (i.e. call to resize) if any is the responsibility of the derived class.

Definition at line 22 of file OperatorEstBase.cpp.

23  : data_locality_(oth.data_locality_), my_name_(oth.my_name_), walkers_weight_(0)
24 {}
QMCT::FullPrecRealType walkers_weight_
std::string my_name_
name of this object – only used for debugging and h5 output
DataLocality data_locality_
locality for accumulation of estimator data.

◆ ~OperatorEstBase()

virtual ~OperatorEstBase ( )
virtualdefault

virtual destructor

Member Function Documentation

◆ accumulate()

virtual void accumulate ( const RefVector< MCPWalker > &  walkers,
const RefVector< ParticleSet > &  psets,
const RefVector< TrialWaveFunction > &  wfns,
const RefVector< QMCHamiltonian > &  hams,
RandomBase< FullPrecRealType > &  rng 
)
pure virtual

Accumulate whatever it is you are accumulating with respect to walkers.

This method is assumed to be called from the crowd context It provides parallelism with respect to computational effort of the estimator without causing a global sync. Depending on data locality the accumlation of the result may be different from the single thread write directly into the OperatorEstimator data.

Parameters
[in]walkers
[in,out]pset_targetcrowd scope target pset (should be returned to starting state after call)
[in]psetsper walker psets
[in]wnfsper walker TrialWaveFunction
[in,out]rngcrowd scope RandomGenerator

Implemented in MomentumDistribution, SpinDensityNew, SelfHealingOverlap, PerParticleHamiltonianLogger, and FakeOperatorEstimator.

◆ collect()

void collect ( const RefVector< OperatorEstBase > &  oebs)
virtual

Reduce estimator result data from crowds to rank.

This is assumed to be called from only from one thread per crowds->rank reduction. Implied is this is during a global sync or there is a guarantee that the crowd operator estimators accumulation data is not being written to.

There could be concurrent operations inside the scope of the collect call.

Reimplemented in MomentumDistribution, SpinDensityNew, SelfHealingOverlap, MagnetizationDensity, and PerParticleHamiltonianLogger.

Definition at line 26 of file OperatorEstBase.cpp.

References OperatorEstBase::data_, and OperatorEstBase::walkers_weight_.

Referenced by MagnetizationDensity::collect(), SelfHealingOverlap::collect(), SpinDensityNew::collect(), and MomentumDistribution::collect().

27 {
28  for (OperatorEstBase& crowd_oeb : type_erased_operator_estimators)
29  {
30  std::transform(data_.begin(), data_.end(), crowd_oeb.get_data().begin(), data_.begin(), std::plus<>{});
31  walkers_weight_ += crowd_oeb.walkers_weight_;
32  crowd_oeb.zero();
33  }
34 }
QMCT::FullPrecRealType walkers_weight_
OperatorEstBase(DataLocality dl)
constructor

◆ get_data()

◆ get_data_locality()

DataLocality get_data_locality ( ) const
inline

Definition at line 134 of file OperatorEstBase.h.

References OperatorEstBase::data_locality_.

Referenced by MomentumDistributionTests::testCopyConstructor().

134 { return data_locality_; }
DataLocality data_locality_
locality for accumulation of estimator data.

◆ get_my_name()

const std::string& get_my_name ( ) const
inline

Definition at line 121 of file OperatorEstBase.h.

References OperatorEstBase::my_name_.

121 { return my_name_; }
std::string my_name_
name of this object – only used for debugging and h5 output

◆ get_walkers_weight()

QMCT::FullPrecRealType get_walkers_weight ( ) const
inline

Return the total walker weight for this block.

Definition at line 119 of file OperatorEstBase.h.

References OperatorEstBase::walkers_weight_.

119 { return walkers_weight_; }
QMCT::FullPrecRealType walkers_weight_

◆ isListenerRequired()

bool isListenerRequired ( )
inline

Definition at line 132 of file OperatorEstBase.h.

References OperatorEstBase::requires_listener_.

◆ normalize()

void normalize ( QMCT::RealType  invToWgt)
virtual

Definition at line 36 of file OperatorEstBase.cpp.

References OperatorEstBase::data_.

37 {
38  for (QMCT::RealType& elem : data_)
39  elem *= invTotWgt;
40 }
QTBase::RealType RealType
Definition: Configuration.h:58

◆ registerListeners()

virtual void registerListeners ( QMCHamiltonian ham_leader)
inlinevirtual

Register 0-many listeners with a leading QMCHamiltonian instance i.e.

a QMCHamiltonian that has acquired the crowd scope QMCHamiltonianMultiWalkerResource. This must be called for each crowd scope estimator that listens to register listeners into the crowd scope QMCHamiltonianMultiWalkerResource.

Many estimators don't need per particle values so the default implementation is no op.

Reimplemented in PerParticleHamiltonianLogger.

Definition at line 130 of file OperatorEstBase.h.

130 {};

◆ registerOperatorEstimator()

virtual void registerOperatorEstimator ( hdf_archive file)
inlinevirtual

◆ spawnCrowdClone()

◆ startBlock()

◆ write()

void write ( hdf_archive file)

Write to previously registered observable_helper hdf5 wrapper.

if you haven't registered Operator Estimator this will do nothing.

Definition at line 42 of file OperatorEstBase.cpp.

References qmcplusplus::syclBLAS::copy_n(), OperatorEstBase::data_, OperatorEstBase::h5desc_, and hdf_archive::pop().

Referenced by OneBodyDensityMatricesTests< T >::testRegisterAndWrite().

43 {
44  if (h5desc_.empty())
45  return;
46  // We have to do this to deal with the legacy design that Observables using
47  // collectables in mixed precision were accumulated in float but always written
48  // to hdf5 in double.
49 #ifdef MIXED_PRECISION
50  std::vector<QMCT::FullPrecRealType> expanded_data(data_.size(), 0.0);
51  std::copy_n(data_.begin(), data_.size(), expanded_data.begin());
52  assert(!data_.empty());
53  // auto total = std::accumulate(data_->begin(), data_->end(), 0.0);
54  // std::cout << "data size: " << data_->size() << " : " << total << '\n';
55  for (auto& h5d : h5desc_)
56  h5d.write(expanded_data.data(), file);
57 #else
58  for (auto& h5d : h5desc_)
59  h5d.write(data_.data(), file);
60 #endif
61  file.pop();
62 }
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:540
std::vector< ObservableHelper > h5desc_

◆ zero()

void zero ( )

zero data appropriately for the DataLocality

Definition at line 64 of file OperatorEstBase.cpp.

References qmcplusplus::crowd, OperatorEstBase::data_, OperatorEstBase::data_locality_, qmcplusplus::rank, and OperatorEstBase::walkers_weight_.

65 {
67  std::fill(data_.begin(), data_.end(), 0.0);
68  else
69  data_.clear();
70  walkers_weight_ = 0;
71 }
QMCT::FullPrecRealType walkers_weight_
DataLocality data_locality_
locality for accumulation of estimator data.

Member Data Documentation

◆ data_

◆ data_locality_

DataLocality data_locality_
protected

locality for accumulation of estimator data.

This designates the memory scheme used for the estimator The default is: DataLocality::Crowd, each crowd and the rank level estimator have a full representation of the data Memory Savings Schemes: One: DataLocality::Rank, This estimator has the full representation of the data but its crowd spawn will have One per crowd: DataLocality::Queue This estimator accumulates queue of values to collect to the Rank estimator data DataLocality::? Another way to reduce memory use on thread/crowd local estimators.

Definition at line 148 of file OperatorEstBase.h.

Referenced by SpinDensityNew::accumulateToData(), MagnetizationDensity::collect(), SelfHealingOverlap::collect(), SpinDensityNew::collect(), MomentumDistribution::collect(), FakeOperatorEstimator::FakeOperatorEstimator(), OperatorEstBase::get_data_locality(), MagnetizationDensity::MagnetizationDensity(), MomentumDistribution::MomentumDistribution(), OneBodyDensityMatrices::OneBodyDensityMatrices(), PerParticleHamiltonianLogger::PerParticleHamiltonianLogger(), SelfHealingOverlap::SelfHealingOverlap(), PerParticleHamiltonianLogger::spawnCrowdClone(), SelfHealingOverlap::spawnCrowdClone(), MagnetizationDensity::spawnCrowdClone(), SpinDensityNew::spawnCrowdClone(), MomentumDistribution::spawnCrowdClone(), OneBodyDensityMatrices::spawnCrowdClone(), SpinDensityNew::SpinDensityNew(), SpinDensityNew::startBlock(), MagnetizationDensityTests::testCopyConstructor(), and OperatorEstBase::zero().

◆ h5desc_

◆ my_name_

◆ requires_listener_

bool requires_listener_ = false
protected

◆ walkers_weight_


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