QMCPACK
DMCUpdateAll.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 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #include "DMCUpdateAll.h"
20 
21 namespace qmcplusplus
22 {
24 
25 /// Constructor.
27  TrialWaveFunction& psi,
28  QMCHamiltonian& h,
30  : QMCUpdateBase(w, psi, h, rg)
31 {
32  UpdatePbyP = false;
33 }
34 
35 /// destructor
37 
38 /** advance all the walkers with killnode==no
39  * @param nat number of particles to move
40  *
41  * When killnode==no, any move resulting in node-crossing is treated
42  * as a normal rejection.
43  */
44 void DMCUpdateAllWithRejection::advanceWalker(Walker_t& thisWalker, bool recompute)
45 {
46  W.loadWalker(thisWalker, false);
47  //create a 3N-Dimensional Gaussian with variance=1
49  //RealType nodecorr = setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
51  //save old local energy
52  RealType eold = thisWalker.Properties(WP::LOCALENERGY);
53  RealType enew = eold;
54  bool accepted = false;
55  RealType rr_accepted = 0.0;
56  RealType rr_proposed = 0.0;
57  RealType logpsi;
58 
60  {
61  //evaluate the new wave function
62  logpsi = Psi.evaluateLog(W);
63  //fixed node
65  {
66  RealType logGf = -0.5 * Dot(deltaR, deltaR);
68  deltaR = thisWalker.R - W.R - drift;
69  RealType logGb = logBackwardGF(deltaR);
70  //RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);
71  RealType prob = std::min(std::exp(logGb - logGf + 2.0 * (logpsi - thisWalker.Properties(WP::LOGPSI))), 1.0);
72  //calculate rr_proposed here
73  deltaR = W.R - thisWalker.R;
74  rr_proposed = Dot(deltaR, deltaR);
75  if (RandomGen() <= prob)
76  {
77  accepted = true;
78  rr_accepted = rr_proposed;
79  }
80  }
81  }
82 
83  // recompute Psi if the move is rejected
84  if (!accepted)
85  {
86  W.loadWalker(thisWalker, false);
87  W.update();
88  logpsi = Psi.evaluateLog(W);
89  }
90 
91  // evaluate Hamiltonian
92  enew = H.evaluateWithToperator(W);
93  H.auxHevaluate(W, thisWalker);
94  H.saveProperty(thisWalker.getPropertyBase());
95 
96  // operate on thisWalker.
97  if (accepted)
98  {
99  W.saveWalker(thisWalker);
100  thisWalker.resetProperty(logpsi, Psi.getPhase(), enew, rr_accepted, rr_proposed, nodecorr);
101  }
102  else
103  {
104  thisWalker.Age++;
105  thisWalker.Properties(WP::R2ACCEPTED) = 0.0;
106  thisWalker.Properties(WP::R2PROPOSED) = rr_proposed;
107  }
108 
109  const int NonLocalMoveAcceptedTemp = H.makeNonLocalMoves(W);
110  if (NonLocalMoveAcceptedTemp > 0)
111  {
112  W.saveWalker(thisWalker);
113  thisWalker.resetProperty(Psi.getLogPsi(), Psi.getPhase(), enew);
114  // debugging lines
115  //logpsi = Psi.getLogPsi();
116  //W.update(true);
117  //RealType logpsi2 = Psi.evaluateLog(W);
118  //if(logpsi!=logpsi2) std::cout << " logpsi " << logpsi << " logpsi2 " << logpsi2
119  // << " diff " << logpsi2-logpsi << std::endl;
120 
121  NonLocalMoveAccepted += NonLocalMoveAcceptedTemp;
122  }
123 
124  thisWalker.Weight *= branchEngine->branchWeight(enew, eold);
125  //branchEngine->accumulate(eold,1);
126  if (accepted)
127  ++nAccept;
128  else
129  ++nReject;
130 
131  setMultiplicity(thisWalker);
132 }
133 
134 /*
135  * DMCUpdateAllWithKill member functions
136  */
137 /// Constructor.
139  TrialWaveFunction& psi,
140  QMCHamiltonian& h,
142  : QMCUpdateBase(w, psi, h, rg)
143 {
144  UpdatePbyP = false;
145 }
146 
147 /// destructor
149 
150 /** advance all the walkers with killnode==yes
151  */
152 void DMCUpdateAllWithKill::advanceWalker(Walker_t& thisWalker, bool recompute)
153 {
154  W.loadWalker(thisWalker, false);
155  //RealType nodecorr = setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
157  //create a 3N-Dimensional Gaussian with variance=1
159  //if(!W.makeMoveAllParticlesWithDrift(thisWalker,drift,deltaR, m_sqrttau))
161  {
162  H.rejectedMove(W, thisWalker);
163  return;
164  }
165  //save old local energy
166  RealType eold = thisWalker.Properties(WP::LOCALENERGY);
167  RealType enew = eold;
168  RealType logpsi(Psi.evaluateLog(W));
169  bool accepted = false;
170  RealType rr_accepted = 0.0;
171  nodecorr = 0.0;
173  {
174  thisWalker.Age++;
175  thisWalker.willDie();
176  }
177  else
178  {
179  enew = H.evaluate(W);
180  RealType logGf = -0.5 * Dot(deltaR, deltaR);
181  //nodecorr = setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
183  deltaR = thisWalker.R - W.R - drift;
184  RealType logGb = logBackwardGF(deltaR);
185  //RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);
186  RealType prob = std::min(std::exp(logGb - logGf + 2.0 * (logpsi - thisWalker.Properties(WP::LOGPSI))), 1.0);
187  //calculate rr_proposed here
188  deltaR = W.R - thisWalker.R;
189  RealType rr_proposed = Dot(deltaR, deltaR);
190  if (RandomGen() > prob)
191  {
192  enew = eold;
193  thisWalker.Age++;
194  thisWalker.Properties(WP::R2ACCEPTED) = 0.0;
195  thisWalker.Properties(WP::R2PROPOSED) = rr_proposed;
196  H.rejectedMove(W, thisWalker);
197  }
198  else
199  {
200  thisWalker.Age = 0;
201  accepted = true;
202  W.saveWalker(thisWalker);
203  rr_accepted = rr_proposed;
204  thisWalker.resetProperty(logpsi, Psi.getPhase(), enew, rr_accepted, rr_proposed, nodecorr);
205  H.auxHevaluate(W, thisWalker);
206  H.saveProperty(thisWalker.getPropertyBase());
207  }
208  // std::cout <<logpsi<<" "<<Psi.getPhase()<<" "<<enew<<" "<<rr_accepted<<" "<<rr_proposed<<" "<<nodecorr<< std::endl;
209  thisWalker.Weight *= branchEngine->branchWeight(enew, eold);
210  }
211  if (accepted)
212  ++nAccept;
213  else
214  ++nReject;
215 
216  setMultiplicity(thisWalker);
217 }
218 } // namespace qmcplusplus
RealType evaluateLog(ParticleSet &P)
evalaute the log (internally gradients and laplacian) of the trial wavefunction.
const BranchEngineType * branchEngine
branch engine, stateless reference to the one in QMCDriver
ParticleSet::ParticlePos drift
temporary storage for drift
PropertyContainer_t Properties
scalar properties of a walker
Definition: Walker.h:125
Base class for update methods for each step.
Definition: QMCUpdateBase.h:41
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
TrialWaveFunction & Psi
trial function
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
bool phaseChanged(RealType psi0) const
Collection of Local Energy Operators.
void willDie()
marked to die
Definition: Walker.h:336
DMCUpdateAllWithKill(MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, RandomBase< FullPrecRealType > &rg)
Constructor.
void update(bool skipSK=false)
update the internal data
ParticleSet::ParticlePos deltaR
temporary storage for random displacement
int Age
Age of this walker age is incremented when a walker is not moved after a sweep.
Definition: Walker.h:100
T Dot(const ParticleAttrib< TinyVector< T, D >> &pa, const ParticleAttrib< TinyVector< T, D >> &pb)
T min(T a, T b)
T setScaledDriftPbyPandNodeCorr(T tau, const ParticleAttrib< TinyVector< T1, D >> &qf, ParticleAttrib< TinyVector< T, D >> &drift)
scale drift
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
FullPrecRealType evaluateWithToperator(ParticleSet &P)
evaluate Local energy with Toperators updated.
RealType branchWeight(FullPrecRealType enew, FullPrecRealType eold) const
return the bare branch weight with a filtering using an energy window
DMCUpdateAllWithRejection(MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, RandomBase< FullPrecRealType > &rg)
Constructor.
std::vector< RealType > SqrtTauOverMass
sqrt(tau/Mass) per particle
~DMCUpdateAllWithKill() override
destructor
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
RealType logBackwardGF(const ParticleSet::ParticlePos &displ)
ParticlePos R
Position.
Definition: ParticleSet.h:79
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
~DMCUpdateAllWithRejection() override
destructor
MCWalkerConfiguration & W
walker ensemble
std::vector< RealType > MassInvP
1/Mass per particle
void loadWalker(Walker_t &awalker, bool pbyp)
load a Walker_t to the current ParticleSet
void auxHevaluate(ParticleSet &P)
void rejectedMove(ParticleSet &P, Walker_t &ThisWalker)
Looks like a hack see DMCBatched.cpp and DMC.cpp weight is used like temporary flag from DMC...
void advanceWalker(Walker_t &thisWalker, bool recompute) override
advance all the walkers with killnode==no
Class to represent a many-body trial wave function.
RandomBase< FullPrecRealType > & RandomGen
random number generator
void advanceWalker(Walker_t &thisWalker, bool recompute) override
advance all the walkers with killnode==yes
Indexes
an enum denoting index of physical properties
FullPrecRealType evaluate(ParticleSet &P)
evaluate Local Energy
FullPrecRealType Weight
Weight of the walker.
Definition: Walker.h:102
bool makeMoveAllParticlesWithDrift(const Walker_t &awalker, const ParticlePos &drift, const ParticlePos &deltaR, RealType dt)
move all the particles including the drift
int makeNonLocalMoves(ParticleSet &P)
make non local moves
IndexType nAccept
counter for number of moves accepted
Definition: QMCUpdateBase.h:63
IndexType nReject
counter for number of moves rejected
Definition: QMCUpdateBase.h:65
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
void setMultiplicity(WalkerIter_t it, WalkerIter_t it_end)
set the multiplicity of the walkers to branch
A container class to represent a walker.
Definition: Walker.h:49
QMCHamiltonian & H
Hamiltonian.
void resetProperty(FullPrecRealType logpsi, FullPrecRealType sigN, FullPrecRealType ene)
reset the property of a walker
Definition: Walker.h:296
IndexType NonLocalMoveAccepted
Total numer of non-local moves accepted.
Definition: QMCUpdateBase.h:71
ParticlePos R
The configuration vector (3N-dimensional vector to store the positions of all the particles for a sin...
Definition: Walker.h:114
bool UpdatePbyP
update particle-by-particle
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)