QMCPACK
SlaterDetWithBackflow.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: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "SlaterDetWithBackflow.h"
17 #include "Message/Communicate.h"
18 
19 namespace qmcplusplus
20 {
21 
23  std::vector<std::unique_ptr<Determinant_t>> dets,
24  std::unique_ptr<BackflowTransformation> BF)
25  : Dets(std::move(dets)), BFTrans(std::move(BF))
26 {
27  assert(BFTrans);
28  assert(Dets.size() == targetPtcl.groups());
29 }
30 
31 ///destructor
33 
35 {
36  return BFTrans->isOptimizable() ||
37  std::any_of(Dets.begin(), Dets.end(), [](const auto& det) { return det->isOptimizable(); });
38 }
39 
41 {
42  opt_obj_refs.push_back(*BFTrans);
43  for (int i = 0; i < Dets.size(); i++)
44  Dets[i]->extractOptimizableObjectRefs(opt_obj_refs);
45 }
46 
47 void SlaterDetWithBackflow::evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios)
48 {
49  for (int i = 0; i < Dets.size(); ++i)
50  Dets[i]->evaluateRatiosAlltoOne(P, ratios);
51 }
52 
56 {
57  BFTrans->evaluate(P);
58  log_value_ = 0.0;
59  for (int i = 0; i < Dets.size(); ++i)
60  log_value_ += Dets[i]->evaluateLog(P, G, L);
61  return log_value_;
62 }
63 
65 {
66  BFTrans->registerData(P, buf);
67  for (int i = 0; i < Dets.size(); ++i)
68  Dets[i]->registerData(P, buf);
69 }
70 
72 {
73  BFTrans->updateBuffer(P, buf, fromscratch);
74  log_value_ = 0.0;
75  for (int i = 0; i < Dets.size(); ++i)
76  log_value_ += Dets[i]->updateBuffer(P, buf, fromscratch);
77  return log_value_;
78 }
79 
81 {
82  BFTrans->copyFromBuffer(P, buf);
83  for (int i = 0; i < Dets.size(); i++)
84  Dets[i]->copyFromBuffer(P, buf);
85 }
86 
87 std::unique_ptr<WaveFunctionComponent> SlaterDetWithBackflow::makeClone(ParticleSet& tqp) const
88 {
89  auto bf = BFTrans->makeClone(tqp);
90  std::vector<std::unique_ptr<Determinant_t>> dets;
91  for (const auto& det : Dets)
92  dets.push_back(det->makeCopyWithBF(det->getPhi()->makeClone(), *bf));
93  auto myclone = std::make_unique<SlaterDetWithBackflow>(tqp, std::move(dets), std::move(bf));
94  assert(myclone->isOptimizable() == isOptimizable());
95  return myclone;
96 }
97 
99 {
100  // testing derivatives of G and L
101  app_log() << "testing derivatives of G and L \n";
102  opt_variables_type wfVars, wfvar_prime;
103  UniqueOptObjRefs opt_obj_refs;
104  extractOptimizableObjectRefs(opt_obj_refs);
105  for (OptimizableObject& obj : opt_obj_refs)
106  obj.checkInVariablesExclusive(wfVars);
107  checkOutVariables(wfVars);
108  int Nvars = wfVars.size();
109  wfvar_prime = wfVars;
110  wfVars.print(std::cout);
111  std::vector<RealType> dlogpsi;
112  std::vector<RealType> dhpsi;
113  dlogpsi.resize(Nvars);
114  dhpsi.resize(Nvars);
117  G0.resize(P.getTotalNum());
118  G1.resize(P.getTotalNum());
119  G2.resize(P.getTotalNum());
120  L0.resize(P.getTotalNum());
121  L1.resize(P.getTotalNum());
122  L2.resize(P.getTotalNum());
123  LogValue psi1 = 1.0;
124  LogValue psi2 = 1.0;
125  RealType dh = 0.00001;
126  for (int k = 0; k < Dets.size(); k++)
127  {
128  DiracDeterminantWithBackflow* Dets_ = dynamic_cast<DiracDeterminantWithBackflow*>(Dets[k].get());
129  Dets_->testGGG(P);
130  for (int i = 0; i < Nvars; i++)
131  {
132  Dets_->testDerivFjj(P, i);
133  Dets_->testDerivLi(P, i);
134  }
135  }
136  app_log() << "Nvars: " << Nvars << std::endl;
137  for (int i = 0; i < Nvars; i++)
138  {
139  for (int j = 0; j < Nvars; j++)
140  wfvar_prime[j] = wfVars[j];
141  for (OptimizableObject& obj : opt_obj_refs)
142  obj.checkInVariablesExclusive(wfvar_prime);
143  BFTrans->evaluateDerivatives(P);
144  G0 = 0.0;
145  G1 = 0.0;
146  G2 = 0.0;
147  L0 = 0.0;
148  L1 = 0.0;
149  L2 = 0.0;
150  for (int k = 0; k < Dets.size(); k++)
151  {
152  DiracDeterminantWithBackflow* Dets_ = dynamic_cast<DiracDeterminantWithBackflow*>(Dets[k].get());
153  Dets_->evaluateDerivatives(P, wfVars, dlogpsi, dhpsi, &G0, &L0, i);
154  }
155 
156  for (int j = 0; j < Nvars; j++)
157  wfvar_prime[j] = wfVars[j];
158  wfvar_prime[i] = wfVars[i] + dh;
159  for (OptimizableObject& obj : opt_obj_refs)
160  obj.checkInVariablesExclusive(wfvar_prime);
161  BFTrans->evaluate(P);
162  for (int k = 0; k < Dets.size(); k++)
163  psi1 += Dets[k]->evaluateLog(P, G1, L1);
164 
165  for (int j = 0; j < Nvars; j++)
166  wfvar_prime[j] = wfVars[j];
167  wfvar_prime[i] = wfVars[i] - dh;
168  for (OptimizableObject& obj : opt_obj_refs)
169  obj.checkInVariablesExclusive(wfvar_prime);
170  BFTrans->evaluate(P);
171  for (int k = 0; k < Dets.size(); k++)
172  psi2 += Dets[k]->evaluateLog(P, G2, L2);
173 
175  for (int q = 0; q < P.getTotalNum(); q++)
176  tmp += (L1[q] - L2[q]) / (2.0 * dh);
177  app_log() << i << "\n"
178  << "Ldiff : " << L0[0] << " " << tmp << " " << L0[0] - tmp << std::endl;
179  for (int k = 0; k < P.getTotalNum(); k++)
180  {
181  app_log() << G0[k] << std::endl
182  << (G1[k] - G2[k]) / (2.0 * dh) << std::endl
183  << "Gdiff: " << G0[k] - (G1[k] - G2[k]) / (2.0 * dh) << std::endl
184  << std::endl;
185  }
186  }
187  for (OptimizableObject& obj : opt_obj_refs)
188  obj.checkInVariablesExclusive(wfVars);
189  APP_ABORT("Testing bF derivs \n");
190 }
191 
192 
194  const opt_variables_type& optvars,
195  Vector<ValueType>& dlogpsi,
196  Vector<ValueType>& dhpsioverpsi)
197 {
198  //testDerivGL(P);
199  if (BFTrans->isOptimizable())
200  {
201  // build QP,Amat,Bmat_full,Xmat,Cmat,Ymat
202  BFTrans->evaluateDerivatives(P);
203  for (int i = 0; i < Dets.size(); i++)
204  Dets[i]->evaluateDerivatives(P, optvars, dlogpsi, dhpsioverpsi);
205  }
206 }
207 
208 
209 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimi...
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) override
extract underlying OptimizableObject references
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Tensor< T, D >::Type_t det(const Tensor< T, D > &a)
Definition: TensorOps.h:838
QTBase::RealType RealType
Definition: Configuration.h:58
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimi...
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
~SlaterDetWithBackflow() override
destructor
Attaches a unit to a Vector for IO.
QTFull::ValueType SingleParticleValue
Definition: Configuration.h:97
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
evaluate the ratios of one virtual move with respect to all the particles
std::complex< QTFull::RealType > LogValue
int groups() const
return the number of groups
Definition: ParticleSet.h:511
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
const std::unique_ptr< BackflowTransformation > BFTrans
backflow transformation
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
SlaterDetWithBackflow(ParticleSet &targetPtcl, std::vector< std::unique_ptr< Determinant_t >> dets, std::unique_ptr< BackflowTransformation > BF)
constructor
bool isOptimizable() const override
if true, this contains optimizable components
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
size_type size() const
return the size
Definition: VariableSet.h:88
class to handle determinants with backflow
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
void push_back(OptimizableObject &obj)
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
const std::vector< std::unique_ptr< Determinant_t > > Dets
container for the DiracDeterminants