QMCPACK
CSVMCUpdatePbyP.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14 
15 
16 #include "CSVMCUpdatePbyP.h"
19 #include "Particle/HDFWalkerIO.h"
22 //#include "Estimators/MultipleEnergyEstimator.h"
24 
25 namespace qmcplusplus
26 {
28 
29 /// Constructor.
31  std::vector<TrialWaveFunction*>& psi,
32  std::vector<QMCHamiltonian*>& h,
34  : CSUpdateBase(w, psi, h, rg)
35 {}
36 
38 
39 void CSVMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute)
40 {
41  W.loadWalker(thisWalker, true);
42 
43  //First step, we initialize all Psis, and read up the value of logpsi
44  //from the last run.
45  for (int ipsi = 0; ipsi < nPsi; ipsi++)
46  {
47  Psi1[ipsi]->copyFromBuffer(W, thisWalker.DataSet);
48  logpsi[ipsi] = thisWalker.Properties(ipsi, WP::LOGPSI);
49  }
50 
51  //Now we compute sumratio and more importantly, ratioij.
53  for (int iter = 0; iter < nSubSteps; ++iter)
54  {
56  bool stucked = true;
57  for (int ig = 0; ig < W.groups(); ++ig) //loop over species
58  {
59  RealType sqrttau = std::sqrt(Tau * MassInvS[ig]);
60  for (int iat = W.first(ig); iat < W.last(ig); ++iat)
61  {
62  PosType dr = sqrttau * deltaR[iat];
63  //The move proposal for particle iat.
64  if (W.makeMoveAndCheck(iat, dr))
65  {
66  for (int ipsi = 0; ipsi < nPsi; ipsi++)
67  ratio[ipsi] = std::norm(Psi1[ipsi]->calcRatio(W, iat));
68  //Compute the ratio and acceptance probability.
69  RealType prob = 0;
70  for (int ipsi = 0; ipsi < nPsi; ipsi++)
71  prob += ratio[ipsi] / sumratio[ipsi];
72 
73  bool is_accepted = false;
74  if (RandomGen() < prob)
75  {
76  is_accepted = true;
77  stucked = false;
78  ++nAccept;
79  for (int ipsi = 0; ipsi < nPsi; ipsi++)
80  Psi1[ipsi]->acceptMove(W, iat, true);
81 
82  //Now we update ratioIJ.
85  }
86  else
87  {
88  ++nReject;
89  for (int ipsi = 0; ipsi < nPsi; ipsi++)
90  Psi1[ipsi]->rejectMove(iat);
91  }
92 
93  W.accept_rejectMove(iat, is_accepted);
94  }
95  else //reject illegal moves
96  ++nReject;
97  } //iat
98  } //ig for the species
99  if (stucked)
100  {
101  ++nAllRejected;
102  }
103  for (int ipsi = 0; ipsi < nPsi; ipsi++)
104  Psi1[ipsi]->completeUpdates();
105  }
106 
107  W.donePbyP();
108 
109  for (int ipsi = 0; ipsi < nPsi; ipsi++)
110  {
111  //now recompute logpsi, gradients, and laplacians of the new R. Save them.
112  logpsi[ipsi] = Psi1[ipsi]->updateBuffer(W, thisWalker.DataSet, recompute);
113  W.saveWalker(thisWalker);
114  //Save G and L for this wavefunction in the working G1, L1 arrays.
115  *G1[ipsi] = thisWalker.G;
116  *L1[ipsi] = thisWalker.L;
117  //Set G and L for this wavefunction.
118  Psi1[ipsi]->G = W.G;
119  Psi1[ipsi]->L = W.L;
120  }
121 
123  for (int ipsi = 0; ipsi < nPsi; ipsi++)
124  {
125  invsumratio[ipsi] = sumratio[ipsi];
126  cumNorm[ipsi] += 1.0 / invsumratio[ipsi];
127  }
128 
129  for (int ipsi = 0; ipsi < nPsi; ipsi++)
130  {
131  //Now reload the G and L associated with ipsi into the walker and particle set.
132  //This is required for correct calculation of kinetic energy.
133  thisWalker.G = *G1[ipsi];
134  thisWalker.L = *L1[ipsi];
135  W.L = thisWalker.L;
136  W.G = thisWalker.G;
137  thisWalker.Properties(ipsi, WP::LOCALENERGY) = H1[ipsi]->evaluate(W);
138  thisWalker.Properties(ipsi, WP::LOGPSI) = logpsi[ipsi];
139  thisWalker.Properties(ipsi, WP::SIGN) = Psi1[ipsi]->getPhase();
140  thisWalker.Properties(ipsi, WP::UMBRELLAWEIGHT) = 1.0 / sumratio[ipsi];
141  //Use Multiplicity as a temporary container for sumratio.
142  thisWalker.Multiplicity = sumratio[0];
143  H1[ipsi]->auxHevaluate(W, thisWalker);
144  H1[ipsi]->saveProperty(thisWalker.getPropertyBase(ipsi));
145  }
146 }
147 
148 
149 /// UpdatePbyP With Drift Fast.
151  std::vector<TrialWaveFunction*>& psi,
152  std::vector<QMCHamiltonian*>& h,
154  : CSUpdateBase(w, psi, h, rg){APP_ABORT("CSVMCUpdatePbyPWithDriftFast currently not working. Please eliminate \
155  drift option, or choose all electron moves instead.")}
156 
158 {}
159 
160 void CSVMCUpdatePbyPWithDriftFast::advanceWalker(Walker_t& thisWalker, bool recompute) {}
161 
162 
163 } // namespace qmcplusplus
std::vector< RealType > sumratio
Definition: CSUpdateBase.h:40
PropertyContainer_t Properties
scalar properties of a walker
Definition: Walker.h:125
std::vector< RealType > cumNorm
Definition: CSUpdateBase.h:45
WFBuffer_t DataSet
buffer for the data for particle-by-particle update
Definition: Walker.h:135
A set of walkers that are to be advanced by Metropolis Monte Carlo.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
void computeSumRatio(const std::vector< RealType > &logpsi, const std::vector< RealType > &avgNorm, std::vector< RealType > &sumratio)
void updateRatioMatrix(const std::vector< RealType > &ratio_pbyp, Matrix< RealType > &ratioij)
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
ParticleSet::ParticlePos deltaR
temporary storage for random displacement
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
std::vector< TrialWaveFunction * > Psi1
a list of TrialWaveFunctions for multiple method
Definition: CSUpdateBase.h:57
int groups() const
return the number of groups
Definition: ParticleSet.h:511
std::vector< RealType > logpsi
Definition: CSUpdateBase.h:39
double norm(const zVec &c)
Definition: VectorOps.h:118
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
std::vector< RealType > invsumratio
Definition: CSUpdateBase.h:41
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
void saveWalker(Walker_t &awalker)
save this to awalker
RealType Tau
timestep
Definition: QMCUpdateBase.h:73
void accept_rejectMove(Index_t iat, bool accepted, bool forward_mode=true)
accept or reject a proposed move Two operation modes: The using and updating distance tables via Part...
std::vector< ParticleSet::ParticleGradient * > G1
Definition: CSUpdateBase.h:59
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
Matrix< RealType > RatioIJ
Definition: CSUpdateBase.h:51
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
MCWalkerConfiguration & W
walker ensemble
void advanceWalker(Walker_t &thisWalker, bool recompute) override
move a walker
void loadWalker(Walker_t &awalker, bool pbyp)
load a Walker_t to the current ParticleSet
int nSubSteps
number of steps per measurement
Definition: QMCUpdateBase.h:56
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
RandomBase< FullPrecRealType > & RandomGen
random number generator
Indexes
an enum denoting index of physical properties
std::vector< RealType > ratio
Definition: CSUpdateBase.h:47
std::vector< RealType > avgNorm
Definition: CSUpdateBase.h:42
bool makeMoveAndCheck(Index_t iat, const SingleParticlePos &displ)
move the iat-th particle to active_pos_
std::vector< ParticleSet::ParticleLaplacian * > L1
Definition: CSUpdateBase.h:60
IndexType nAccept
counter for number of moves accepted
Definition: QMCUpdateBase.h:63
IndexType nReject
counter for number of moves rejected
Definition: QMCUpdateBase.h:65
CSVMCUpdatePbyPWithDriftFast(MCWalkerConfiguration &w, std::vector< TrialWaveFunction *> &psi, std::vector< QMCHamiltonian *> &h, RandomBase< FullPrecRealType > &rg)
Constructor.
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
FullPrecRealType Multiplicity
Number of copies for branching When Multiplicity = 0, this walker will be destroyed.
Definition: Walker.h:106
CSVMCUpdatePbyP(MCWalkerConfiguration &w, std::vector< TrialWaveFunction *> &psi, std::vector< QMCHamiltonian *> &h, RandomBase< FullPrecRealType > &rg)
Constructor.
std::vector< RealType > MassInvS
1/Mass per species
Declaration of a MCWalkerConfiguration.
A container class to represent a walker.
Definition: Walker.h:49
std::vector< QMCHamiltonian * > H1
a list of QMCHamiltonians for multiple method
Definition: CSUpdateBase.h:55
void donePbyP(bool skipSK=false)
update structure factor and unmark active_ptcl_
ParticleLaplacian L
^2_i d for the i-th particle
Definition: Walker.h:122
IndexType nAllRejected
Total number of the steps when all the particle moves are rejected.
Definition: QMCUpdateBase.h:67
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)