QMCPACK
SelfHealingOverlap Class Reference

Class that collects MSD coefficient values via the Self-Healing overlap. More...

+ Inheritance diagram for SelfHealingOverlap:
+ Collaboration diagram for SelfHealingOverlap:

Public Types

using LatticeType = PtclOnLatticeTraits::ParticleLayout
 
using RealType = QMCTraits::RealType
 
using ComplexType = QMCTraits::ComplexType
 
using ValueType = QMCTraits::ValueType
 
using PosType = QMCTraits::PosType
 
- Public Types inherited from OperatorEstBase
using QMCT = QMCTraits
 
using FullPrecRealType = QMCT::FullPrecRealType
 
using MCPWalker = Walker< QMCTraits, PtclOnLatticeTraits >
 
using Data = std::vector< QMCT::RealType >
 

Public Member Functions

 SelfHealingOverlap (SelfHealingOverlapInput &&inp, const TrialWaveFunction &wfn, DataLocality dl=DataLocality::crowd)
 Constructor for SelfHealingOverlapInput. More...
 
 SelfHealingOverlap (const SelfHealingOverlap &sh, DataLocality dl)
 Constructor used when spawing crowd clones needs to be public so std::make_unique can call it. More...
 
void startBlock (int steps) override
 This allows us to allocate the necessary data for the DataLocality::queue. More...
 
std::unique_ptr< OperatorEstBasespawnCrowdClone () const override
 standard interface More...
 
void accumulate (const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, const RefVector< QMCHamiltonian > &hams, RandomBase< FullPrecRealType > &rng) override
 accumulate 1 or more walkers of SelfHealingOverlap samples More...
 
void collect (const RefVector< OperatorEstBase > &operator_estimators) override
 this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverlap's data. More...
 
void registerOperatorEstimator (hdf_archive &file) override
 this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverlap's data. More...
 
- Public Member Functions inherited from OperatorEstBase
 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 normalize (QMCT::RealType invToWgt)
 
std::vector< QMCT::RealType > & get_data ()
 
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
 

Public Attributes

const SelfHealingOverlapInput input_
 
Vector< ValueTypedet_ratios
 
More...
 

Private Member Functions

 SelfHealingOverlap (const SelfHealingOverlap &md)=default
 

Additional Inherited Members

- Protected Attributes inherited from OperatorEstBase
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

Class that collects MSD coefficient values via the Self-Healing overlap.

Definition at line 27 of file SelfHealingOverlap.h.

Member Typedef Documentation

◆ ComplexType

Definition at line 32 of file SelfHealingOverlap.h.

◆ LatticeType

◆ PosType

Definition at line 34 of file SelfHealingOverlap.h.

◆ RealType

Definition at line 31 of file SelfHealingOverlap.h.

◆ ValueType

Definition at line 33 of file SelfHealingOverlap.h.

Constructor & Destructor Documentation

◆ SelfHealingOverlap() [1/3]

Constructor for SelfHealingOverlapInput.

Definition at line 21 of file SelfHealingOverlap.cpp.

References OperatorEstBase::data_, TrialWaveFunction::findMSD(), MultiSlaterDetTableMethod::getLinearExpansionCoefs(), SelfHealingOverlap::input_, and SelfHealingOverlapInput::input_section_.

22  : OperatorEstBase(dl), input_(std::move(inp_))
23 {
24  //my_name_ = input_.get_name();
25 
26  auto& inp = this->input_.input_section_;
27 
28  auto msd_refvec = wfn.findMSD();
29  if (msd_refvec.size() != 1)
30  throw std::runtime_error(
31  "SelfHealingOverlap requires one and only one multi slater determinant component in the trial wavefunction.");
32 
33  const MultiSlaterDetTableMethod& msd = msd_refvec[0];
34  const size_t data_size = msd.getLinearExpansionCoefs().size();
35  data_.resize(data_size, 0.0);
36 }
SelfHealingOverlapInputSection input_section_
OperatorEstBase(DataLocality dl)
constructor
const SelfHealingOverlapInput input_

◆ SelfHealingOverlap() [2/3]

Constructor used when spawing crowd clones needs to be public so std::make_unique can call it.

Do not use directly unless you've really thought it through.

Definition at line 39 of file SelfHealingOverlap.cpp.

References OperatorEstBase::data_locality_.

39  : SelfHealingOverlap(sh)
40 {
41  data_locality_ = dl;
42 }
DataLocality data_locality_
locality for accumulation of estimator data.
SelfHealingOverlap(SelfHealingOverlapInput &&inp, const TrialWaveFunction &wfn, DataLocality dl=DataLocality::crowd)
Constructor for SelfHealingOverlapInput.

◆ SelfHealingOverlap() [3/3]

SelfHealingOverlap ( const SelfHealingOverlap md)
privatedefault

Member Function Documentation

◆ accumulate()

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

accumulate 1 or more walkers of SelfHealingOverlap samples

Gets called every step and writes to thread local data.

Implements OperatorEstBase.

Definition at line 67 of file SelfHealingOverlap.cpp.

References MultiSlaterDetTableMethod::calcIndividualDetRatios(), OperatorEstBase::data_, SelfHealingOverlap::det_ratios, qmcplusplus::exp(), TrialWaveFunction::findMSD(), TrialWaveFunction::getOrbitals(), qmcplusplus::pset, qmcplusplus::real(), Vector< T, Alloc >::size(), qmcplusplus::walker, qmcplusplus::hdf::walkers, and OperatorEstBase::walkers_weight_.

72 {
73  for (int iw = 0; iw < walkers.size(); ++iw)
74  {
75  MCPWalker& walker = walkers[iw];
76  ParticleSet& pset = psets[iw];
77  TrialWaveFunction& psi = wfns[iw];
78  RealType weight = walker.Weight;
79  auto& wcs = psi.getOrbitals();
80 
81  // separate jastrow and fermi wavefunction components
82  std::vector<WaveFunctionComponent*> wcs_jastrow;
83  std::vector<WaveFunctionComponent*> wcs_fermi;
84  for (auto& wc : wcs)
85  if (wc->isFermionic())
86  wcs_fermi.push_back(wc.get());
87  else
88  wcs_jastrow.push_back(wc.get());
89 
90  // fermionic must have only one component, and must be multideterminant
91  assert(wcs_fermi.size() == 1);
92  WaveFunctionComponent& wf = *wcs_fermi[0];
93  if (!wf.isMultiDet())
94  throw std::runtime_error("SelfHealingOverlap estimator requires use of multideterminant wavefunction");
95  auto msd_refvec = psi.findMSD();
96  MultiSlaterDetTableMethod& msd = msd_refvec[0];
97 
98  // collect parameter derivatives: (dpsi/dc_i)/psi
99  msd.calcIndividualDetRatios(det_ratios);
100 
101  // collect jastrow prefactor
103  for (auto& wc : wcs_jastrow)
104  Jval += wc->get_log_value();
105  auto Jprefactor = std::real(std::exp(-2. * Jval));
106 
107  // accumulate weight (required by all estimators, otherwise inf results)
108  walkers_weight_ += weight;
109 
110  // accumulate data
111  assert(det_ratios.size() == data_.size());
112  for (int ic = 0; ic < det_ratios.size(); ++ic)
113  data_[ic] += weight * Jprefactor * real(det_ratios[ic]); // only real supported for now
114  }
115 }
QMCTraits::RealType real
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
const char walkers[]
Definition: HDFVersion.h:36
std::complex< QTFull::RealType > LogValue
QMCT::FullPrecRealType walkers_weight_
size_type size() const
return the current size
Definition: OhmmsVector.h:162
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
QMCTraits::RealType RealType
Walker< QMCTraits, PtclOnLatticeTraits > MCPWalker

◆ collect()

void collect ( const RefVector< OperatorEstBase > &  operator_estimators)
overridevirtual

this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverlap's data.

can use base class default until crowd level SelfHealingOverlap estimators don't have a copy of the density grid.

Reimplemented from OperatorEstBase.

Definition at line 118 of file SelfHealingOverlap.cpp.

References OperatorEstBase::collect(), qmcplusplus::crowd, and OperatorEstBase::data_locality_.

119 {
121  {
122  OperatorEstBase::collect(type_erased_operator_estimators);
123  }
124  else
125  {
126  throw std::runtime_error("You cannot call collect on a SelfHealingOverlap with this DataLocality");
127  }
128 }
DataLocality data_locality_
locality for accumulation of estimator data.
virtual void collect(const RefVector< OperatorEstBase > &oebs)
Reduce estimator result data from crowds to rank.

◆ registerOperatorEstimator()

void registerOperatorEstimator ( hdf_archive file)
overridevirtual

this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverlap's data.

can use base class default until crowd level SelfHealingOverlap estimators don't have a copy of the density grid. this gets us into the hdf5 file

Just parroting for now don't fully understand. , needs to be unraveled and simplified the hdf5 output is another big state big coupling design.

Reimplemented from OperatorEstBase.

Definition at line 131 of file SelfHealingOverlap.cpp.

References OperatorEstBase::data_, and OperatorEstBase::h5desc_.

132 {
133  using namespace std::string_literals;
134  ////descriptor for the data, 1-D data
135  std::vector<int> ng(1);
136  ng[0] = data_.size();
137  h5desc_.push_back({{"sh_coeff"}});
138  auto& h5o = h5desc_.back();
139  h5o.set_dimensions(ng, 0); // JTK: doesn't seem right
140 }
std::vector< ObservableHelper > h5desc_

◆ spawnCrowdClone()

std::unique_ptr< OperatorEstBase > spawnCrowdClone ( ) const
overridevirtual

standard interface

Implements OperatorEstBase.

Definition at line 44 of file SelfHealingOverlap.cpp.

References OperatorEstBase::data_, OperatorEstBase::data_locality_, qmcplusplus::queue, and qmcplusplus::rank.

45 {
46  std::size_t data_size = data_.size();
47  auto spawn_data_locality = data_locality_;
48 
50  {
51  // This is just a stub until a memory saving optimization is deemed necessary
52  spawn_data_locality = DataLocality::queue;
53  data_size = 0;
54  throw std::runtime_error("There is no memory savings implementation for SelfHealingOverlap");
55  }
56 
57  auto spawn = std::make_unique<SelfHealingOverlap>(*this, spawn_data_locality);
58  spawn->get_data().resize(data_size);
59  return spawn;
60 }
DataLocality data_locality_
locality for accumulation of estimator data.

◆ startBlock()

void startBlock ( int  steps)
overridevirtual

This allows us to allocate the necessary data for the DataLocality::queue.

Implements OperatorEstBase.

Definition at line 62 of file SelfHealingOverlap.cpp.

62 {}

Member Data Documentation

◆ det_ratios

Vector<ValueType> det_ratios


Definition at line 41 of file SelfHealingOverlap.h.

Referenced by SelfHealingOverlap::accumulate().

◆ input_

Definition at line 37 of file SelfHealingOverlap.h.

Referenced by SelfHealingOverlap::SelfHealingOverlap().


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