QMCPACK
SelfHealingOverlap.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 //
9 //////////////////////////////////////////////////////////////////////////////////////
10 
11 #include "SelfHealingOverlap.h"
12 #include "TrialWaveFunction.h"
14 
15 #include <iostream>
16 #include <numeric>
17 
18 
19 namespace qmcplusplus
20 {
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 }
37 
38 
40 {
41  data_locality_ = dl;
42 }
43 
44 std::unique_ptr<OperatorEstBase> SelfHealingOverlap::spawnCrowdClone() const
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 }
61 
63 
64 /** Gets called every step and writes to thread local data.
65  *
66  */
68  const RefVector<ParticleSet>& psets,
69  const RefVector<TrialWaveFunction>& wfns,
70  const RefVector<QMCHamiltonian>& hams,
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
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 }
116 
117 
118 void SelfHealingOverlap::collect(const RefVector<OperatorEstBase>& type_erased_operator_estimators)
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 }
129 
130 
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 }
141 
142 
143 } // namespace qmcplusplus
const std::vector< ValueType > & getLinearExpansionCoefs() const
SelfHealingOverlapInputSection input_section_
Class that collects MSD coefficient values via the Self-Healing overlap.
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
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
std::vector< ObservableHelper > h5desc_
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
class to handle hdf file
Definition: hdf_archive.h:51
const char walkers[]
Definition: HDFVersion.h:36
void collect(const RefVector< OperatorEstBase > &operator_estimators) override
this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverl...
DataLocality data_locality_
locality for accumulation of estimator data.
std::unique_ptr< OperatorEstBase > spawnCrowdClone() const override
standard interface
SelfHealingOverlap(SelfHealingOverlapInput &&inp, const TrialWaveFunction &wfn, DataLocality dl=DataLocality::crowd)
Constructor for SelfHealingOverlapInput.
RefVector< MultiSlaterDetTableMethod > findMSD() const
find MSD WFCs if exist
std::complex< QTFull::RealType > LogValue
An abstract class for a component of a many-body trial wave function.
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
QMCT::FullPrecRealType walkers_weight_
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void calcIndividualDetRatios(Vector< ValueType > &ratios)
Compute ratios of the individual Slater determinants and the total MSD value.
Native representation for Self-Healing Overlap Estimator inputs.
const SelfHealingOverlapInput input_
An abstract class for gridded estimators.
std::vector< std::unique_ptr< WaveFunctionComponent > > const & getOrbitals()
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
Declaration of a TrialWaveFunction.
std::vector< std::reference_wrapper< T > > RefVector
Class to represent a many-body trial wave function.
DataLocality
data locality with respect to walker buffer
Definition: DataLocality.h:19
void startBlock(int steps) override
This allows us to allocate the necessary data for the DataLocality::queue.
void registerOperatorEstimator(hdf_archive &file) override
this allows the EstimatorManagerNew to reduce without needing to know the details of SelfHealingOverl...
A container class to represent a walker.
Definition: Walker.h:49
An AntiSymmetric WaveFunctionComponent composed of a linear combination of SlaterDeterminants.
virtual void collect(const RefVector< OperatorEstBase > &oebs)
Reduce estimator result data from crowds to rank.