QMCPACK
SelfHealingOverlapLegacy.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) 2024 QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
14 #include "TrialWaveFunction.h"
16 #include "OhmmsData/AttributeSet.h"
17 
18 namespace qmcplusplus
19 {
21  : psi_ref(wfn)
22 {
23  name_ = "SelfHealingOverlap";
24  update_mode_.set(COLLECTABLE, 1);
25 
26  auto msd_refvec = wfn.findMSD();
27  if (msd_refvec.size() != 1)
28  throw std::runtime_error(
29  "SelfHealingOverlap requires one and only one multi slater determinant component in the trial wavefunction.");
30 
31  const MultiSlaterDetTableMethod& msd = msd_refvec[0];
32 
33  ncoef = msd.getLinearExpansionCoefs().size();
34 }
35 
36 
37 std::unique_ptr<OperatorBase> SelfHealingOverlapLegacy::makeClone(ParticleSet& P, TrialWaveFunction& psi)
38 {
39  return std::make_unique<SelfHealingOverlapLegacy>(psi);
40 }
41 
42 
43 bool SelfHealingOverlapLegacy::put(xmlNodePtr cur)
44 {
45  OhmmsAttributeSet attrib;
46  attrib.add(name_, "name");
47  attrib.put(cur);
48  return true;
49 }
50 
51 
52 
54 {
55  my_index_ = collectables.current();
56  std::vector<RealType> tmp(ncoef);
57  collectables.add(tmp.begin(), tmp.end());
58 }
59 
60 
61 void SelfHealingOverlapLegacy::registerCollectables(std::vector<ObservableHelper>& h5desc, hdf_archive& file) const
62 {
63  std::vector<int> ng(1);
64  ng[0] = ncoef;
65  h5desc.push_back({{"sh_coeff"}});
66  auto& h5o = h5desc.back();
67  h5o.set_dimensions(ng, my_index_);
68 }
69 
70 
72 {
73  RealType weight = t_walker_->Weight;
74  int offset = my_index_;
75  auto& wcs = psi_ref.getOrbitals();
76 
77  // separate jastrow and fermi wavefunction components
78  std::vector<WaveFunctionComponent*> wcs_jastrow;
79  std::vector<WaveFunctionComponent*> wcs_fermi;
80  for (auto& wc : wcs)
81  if (wc->isFermionic())
82  wcs_fermi.push_back(wc.get());
83  else
84  wcs_jastrow.push_back(wc.get());
85  auto msd_refvec = psi_ref.findMSD();
86  MultiSlaterDetTableMethod& msd = msd_refvec[0];
87 
88  // fermionic must have only one component, and must be multideterminant
89  assert(wcs_fermi.size() == 1);
90  WaveFunctionComponent& wf = *wcs_fermi[0];
91  if (!wf.isMultiDet())
92  throw std::runtime_error("SelfHealingOverlap estimator requires use of multideterminant wavefunction");
93 
94  // collect parameter derivatives: (dpsi/dc_i)/psi
96 
97  // collect jastrow prefactor
99  for (auto& wc : wcs_jastrow)
100  Jval += wc->get_log_value();
101  auto Jprefactor = std::real(std::exp(-2. * Jval));
102 
103  // accumulate data
104  assert(det_ratios.size() == ncoef);
105  for (int ic = 0; ic < det_ratios.size(); ++ic)
106  P.Collectables[offset+ic] += weight * Jprefactor * real(det_ratios[ic]); // only real supported for now
107 
108  return 0.0;
109 }
110 
111 
112 } // namespace qmcplusplus
const std::vector< ValueType > & getLinearExpansionCoefs() const
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
bool put(xmlNodePtr cur) override
Read the input parameter.
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
int my_index_
starting index of this object
Definition: OperatorBase.h:535
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
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
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
Vectorized record engine for scalar properties.
RefVector< MultiSlaterDetTableMethod > findMSD() const
find MSD WFCs if exist
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
std::complex< QTFull::RealType > LogValue
An abstract class for a component of a many-body trial wave function.
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void add(T &x)
Definition: PooledData.h:88
void calcIndividualDetRatios(Vector< ValueType > &ratios)
Compute ratios of the individual Slater determinants and the total MSD value.
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
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)
size_type current() const
Definition: PooledData.h:51
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
Buffer_t Collectables
observables in addition to those registered in Properties/PropertyList
Definition: ParticleSet.h:126
Declaration of a TrialWaveFunction.
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
Class to represent a many-body trial wave function.
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
void addObservables(PropertySetType &plist, BufferType &olist) override
named values to the property list Default implementaton uses addValue(plist_)
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
std::bitset< 8 > update_mode_
set the current update mode
Definition: OperatorBase.h:521
An AntiSymmetric WaveFunctionComponent composed of a linear combination of SlaterDeterminants.