QMCPACK
SlaterDet.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
12 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #include "SlaterDet.h"
19 #include "Message/Communicate.h"
20 
21 namespace qmcplusplus
22 {
23 
24 // for return types
26 
28  std::vector<std::unique_ptr<Determinant_t>> dets,
29  const std::string& class_name)
30  : Dets(std::move(dets))
31 {
32  assert(Dets.size() == targetPtcl.groups());
33 
34  Last.resize(targetPtcl.groups());
35  for (int i = 0; i < Last.size(); ++i)
36  Last[i] = targetPtcl.last(i) - 1;
37 }
38 
39 ///destructor
40 SlaterDet::~SlaterDet() = default;
41 
43 {
44  return std::any_of(Dets.begin(), Dets.end(), [](const auto& det) { return det->isOptimizable(); });
45 }
46 
48 {
49  for (int i = 0; i < Dets.size(); i++)
50  Dets[i]->extractOptimizableObjectRefs(opt_obj_refs);
51 }
52 
54 {
55  myVars.clear();
56  if (isOptimizable())
57  for (int i = 0; i < Dets.size(); i++)
58  {
59  Dets[i]->checkOutVariables(active);
61  }
62  myVars.getIndex(active);
63 }
64 
66 {
67  return Dets[getDetID(iat)]->ratioGrad(P, iat, grad_iat);
68 }
69 
71 {
72  return Dets[getDetID(iat)]->ratioGradWithSpin(P, iat, grad_iat, spingrad_iat);
73 }
74 
77  int iat,
78  std::vector<PsiValue>& ratios,
79  std::vector<GradType>& grad_now) const
80 {
81  const int det_id = getDetID(iat);
82  Dets[det_id]->mw_ratioGrad(extract_DetRef_list(wfc_list, det_id), p_list, iat, ratios, grad_now);
83 }
84 
87  int iat,
88  std::vector<PsiValue>& ratios,
89  std::vector<GradType>& grad_now,
90  std::vector<ComplexType>& spingrad_now) const
91 {
92  const int det_id = getDetID(iat);
93  Dets[det_id]->mw_ratioGradWithSpin(extract_DetRef_list(wfc_list, det_id), p_list, iat, ratios, grad_now,
94  spingrad_now);
95 }
96 
97 
100  int iat,
101  std::vector<GradType>& grad_now,
102  std::vector<ComplexType>& spingrad_now) const
103 {
104  const int det_id = getDetID(iat);
105  Dets[det_id]->mw_evalGradWithSpin(extract_DetRef_list(wfc_list, det_id), p_list, iat, grad_now, spingrad_now);
106 }
107 
108 void SlaterDet::evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios)
109 {
110  for (int i = 0; i < Dets.size(); ++i)
111  Dets[i]->evaluateRatiosAlltoOne(P, ratios);
112 }
113 
115  const opt_variables_type& optvars,
116  std::vector<ValueType>& ratios,
117  Matrix<ValueType>& dratios)
118 {
119  return Dets[getDetID(VP.refPtcl)]->evaluateDerivRatios(VP, optvars, ratios, dratios);
120 }
121 
125 {
126  log_value_ = 0.0;
127  for (int i = 0; i < Dets.size(); ++i)
128  log_value_ += Dets[i]->evaluateLog(P, G, L);
129  return log_value_;
130 }
131 
133  const RefVectorWithLeader<ParticleSet>& p_list,
135  const RefVector<ParticleSet::ParticleLaplacian>& L_list) const
136 {
137  constexpr LogValue czero(0);
138 
139  for (int iw = 0; iw < wfc_list.size(); iw++)
140  wfc_list.getCastedElement<SlaterDet>(iw).log_value_ = czero;
141 
142  for (int i = 0; i < Dets.size(); ++i)
143  {
144  const auto Det_list(extract_DetRef_list(wfc_list, i));
145  Dets[i]->mw_evaluateLog(Det_list, p_list, G_list, L_list);
146  for (int iw = 0; iw < wfc_list.size(); iw++)
147  wfc_list.getCastedElement<SlaterDet>(iw).log_value_ += Det_list[iw].get_log_value();
148  }
149 }
150 
154  bool from_scratch)
155 {
156  log_value_ = 0.0;
157  for (int i = 0; i < Dets.size(); ++i)
158  log_value_ += Dets[i]->evaluateGL(P, G, L, from_scratch);
159  return log_value_;
160 }
161 
163  const RefVectorWithLeader<ParticleSet>& p_list,
166  bool fromscratch) const
167 {
168  constexpr LogValue czero(0);
169 
170  for (int iw = 0; iw < wfc_list.size(); iw++)
171  wfc_list.getCastedElement<SlaterDet>(iw).log_value_ = czero;
172 
173  for (int i = 0; i < Dets.size(); ++i)
174  {
175  const auto Det_list(extract_DetRef_list(wfc_list, i));
176  Dets[i]->mw_evaluateGL(Det_list, p_list, G_list, L_list, fromscratch);
177  for (int iw = 0; iw < wfc_list.size(); iw++)
178  wfc_list.getCastedElement<SlaterDet>(iw).log_value_ += Det_list[iw].get_log_value();
179  }
180 }
181 
183 {
184  for (int i = 0; i < Dets.size(); ++i)
185  Dets[i]->recompute(P);
186 }
187 
189  const RefVectorWithLeader<ParticleSet>& p_list,
190  const std::vector<bool>& recompute) const
191 {
192  for (int i = 0; i < Dets.size(); ++i)
193  {
194  const auto Det_list(extract_DetRef_list(wfc_list, i));
195  Dets[i]->mw_recompute(Det_list, p_list, recompute);
196  }
197 }
198 
200 {
201  grad_grad_psi.resize(P.getTotalNum());
202  HessVector tmp;
203  tmp.resize(P.getTotalNum());
204  for (int i = 0; i < Dets.size(); ++i)
205  {
206  tmp = 0;
207  Dets[i]->evaluateHessian(P, tmp);
208  // app_log()<<"squee ----- "<<i<< std::endl;
209  // app_log()<<"grad_grad_psi = "<<grad_grad_psi<< std::endl;
210  // app_log()<<"tmp = "<<tmp<< std::endl<< std::endl;
211  grad_grad_psi += tmp;
212  }
213 }
214 
216 {
217  for (int i = 0; i < Dets.size(); ++i)
218  Dets[i]->createResource(collection);
219 }
220 
222  const RefVectorWithLeader<WaveFunctionComponent>& wfc_list) const
223 {
224  for (int i = 0; i < Dets.size(); ++i)
225  {
226  const auto det_list(extract_DetRef_list(wfc_list, i));
227  Dets[i]->acquireResource(collection, det_list);
228  }
229 }
230 
232  const RefVectorWithLeader<WaveFunctionComponent>& wfc_list) const
233 {
234  for (int i = 0; i < Dets.size(); ++i)
235  {
236  const auto det_list(extract_DetRef_list(wfc_list, i));
237  Dets[i]->releaseResource(collection, det_list);
238  }
239 }
240 
242 {
243  DEBUG_PSIBUFFER(" SlaterDet::registerData ", buf.current());
244  for (int i = 0; i < Dets.size(); ++i)
245  Dets[i]->registerData(P, buf);
246  DEBUG_PSIBUFFER(" SlaterDet::registerData ", buf.current());
247 }
248 
250 {
251  DEBUG_PSIBUFFER(" SlaterDet::updateBuffer ", buf.current());
252  log_value_ = 0.0;
253  for (int i = 0; i < Dets.size(); ++i)
254  log_value_ += Dets[i]->updateBuffer(P, buf, fromscratch);
255  DEBUG_PSIBUFFER(" SlaterDet::updateBuffer ", buf.current());
256  return log_value_;
257 }
258 
260 {
261  DEBUG_PSIBUFFER(" SlaterDet::copyFromBuffer ", buf.current());
262  for (int i = 0; i < Dets.size(); i++)
263  Dets[i]->copyFromBuffer(P, buf);
264  DEBUG_PSIBUFFER(" SlaterDet::copyFromBuffer ", buf.current());
265 }
266 
267 std::unique_ptr<WaveFunctionComponent> SlaterDet::makeClone(ParticleSet& tqp) const
268 {
269  std::vector<std::unique_ptr<Determinant_t>> dets;
270  for (const auto& det : Dets)
271  dets.emplace_back(det->makeCopy(det->getPhi()->makeClone()));
272  auto myclone = std::make_unique<SlaterDet>(tqp, std::move(dets));
273  assert(myclone->isOptimizable() == isOptimizable());
274  return myclone;
275 }
276 
278 {
279  for (int i = 0; i < Dets.size(); ++i)
280  {
281  Dets[i]->registerTWFFastDerivWrapper(P, twf);
282  }
283 }
284 
285 } // namespace qmcplusplus
void evaluateHessian(ParticleSet &P, HessVector &grad_grad_psi) override
Definition: SlaterDet.cpp:199
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
Definition: SlaterDet.cpp:53
LogValue evaluateGL(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, bool fromscratch) override
compute gradients and laplacian of the TWF with respect to each particle.
Definition: SlaterDet.cpp:151
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
void evaluateDerivRatios(const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratios) override
evaluate ratios to evaluate the non-local PP
Definition: SlaterDet.cpp:114
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
Definition: SlaterDet.cpp:267
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) override
extract underlying OptimizableObject references
Definition: SlaterDet.cpp:47
size_t getTotalNum() const
Definition: ParticleSet.h:493
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: SlaterDet.cpp:241
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
void mw_ratioGradWithSpin(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, std::vector< GradType > &grad_now, std::vector< ComplexType > &spingrad_now) const override
compute the ratio of the new to old WaveFunctionComponent value and the new gradient/spingradient of ...
Definition: SlaterDet.cpp:85
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
int getDetID(const int iat) const
Definition: SlaterDet.h:298
int refPtcl
Reference particle.
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
const std::vector< std::unique_ptr< Determinant_t > > Dets
container for the DiracDeterminants
Definition: SlaterDet.h:33
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
Definition: SlaterDet.cpp:215
Attaches a unit to a Vector for IO.
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
void mw_evaluateLog(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list) const override
evaluate from scratch the same type WaveFunctionComponent of multiple walkers
Definition: SlaterDet.cpp:132
opt_variables_type myVars
list of variables this WaveFunctionComponent handles
std::complex< QTFull::RealType > LogValue
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
evaluate the ratios of one virtual move with respect to all the particles
Definition: SlaterDet.cpp:108
int groups() const
return the number of groups
Definition: ParticleSet.h:511
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
Definition: SlaterDet.cpp:249
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const override
return a shared resource to a collection
Definition: SlaterDet.cpp:231
PsiValue ratioGradWithSpin(ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new spin gradient Default im...
Definition: SlaterDet.cpp:70
RefVectorWithLeader< WaveFunctionComponent > extract_DetRef_list(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, int det_id) const
Definition: SlaterDet.h:307
void recompute(const ParticleSet &P) override
recompute the value of the WaveFunctionComponents which require critical accuracy.
Definition: SlaterDet.cpp:182
void registerTWFFastDerivWrapper(const ParticleSet &P, TWFFastDerivWrapper &twf) const override
Register the component with the TWFFastDerivWrapper wrapper.
Definition: SlaterDet.cpp:277
void mw_ratioGrad(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, std::vector< GradType > &grad_now) const override
compute the ratio of the new to old WaveFunctionComponent value and the new gradient of multiple walk...
Definition: SlaterDet.cpp:75
CASTTYPE & getCastedElement(size_t i) const
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
Definition: SlaterDet.cpp:65
bool isOptimizable() const override
if true, this contains optimizable components
Definition: SlaterDet.cpp:42
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const override
acquire a shared resource from a collection
Definition: SlaterDet.cpp:221
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
#define DEBUG_PSIBUFFER(who, msg)
Definition: Configuration.h:40
void clear()
clear the variable set
Definition: VariableSet.cpp:28
~SlaterDet() override
destructor
size_type current() const
Definition: PooledMemory.h:76
std::vector< std::reference_wrapper< T > > RefVector
std::vector< int > Last
the last particle of each group
Definition: SlaterDet.h:319
void mw_evalGradWithSpin(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< GradType > &grad_now, std::vector< ComplexType > &spingrad_now) const override
compute the current gradients and spin gradients for the iat-th particle of multiple walkers ...
Definition: SlaterDet.cpp:98
OrbitalSetTraits< ValueType >::HessVector HessVector
void mw_recompute(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< bool > &recompute) const override
Definition: SlaterDet.cpp:188
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
Definition: VariableSet.cpp:37
void mw_evaluateGL(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list, bool fromscratch) const override
evaluate gradients and laplacian of the same type WaveFunctionComponent of multiple walkers ...
Definition: SlaterDet.cpp:162
SlaterDet(ParticleSet &targetPtcl, std::vector< std::unique_ptr< Determinant_t >> dets, const std::string &class_name="SlaterDet")
constructor
Definition: SlaterDet.cpp:27
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
Definition: SlaterDet.cpp:122
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Definition: SlaterDet.cpp:259
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter