QMCPACK
VMCUpdatePbyP.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 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #include "VMCUpdatePbyP.h"
19 #include "Concurrency/OpenMP.h"
20 #if !defined(REMOVE_TRACEMANAGER)
22 #else
23 using TraceManager = int;
24 #endif
25 
26 
27 namespace qmcplusplus
28 {
29 /// Constructor
31  TrialWaveFunction& psi,
32  QMCHamiltonian& h,
34  : QMCUpdateBase(w, psi, h, rg),
35  buffer_timer_(createGlobalTimer("VMCUpdatePbyP::Buffer", timer_level_medium)),
36  movepbyp_timer_(createGlobalTimer("VMCUpdatePbyP::MovePbyP", timer_level_medium)),
37  hamiltonian_timer_(createGlobalTimer("VMCUpdatePbyP::Hamiltonian", timer_level_medium)),
38  collectables_timer_(createGlobalTimer("VMCUpdatePbyP::Collectables", timer_level_medium))
39 {}
40 
42 
43 void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute)
44 {
46  W.loadWalker(thisWalker, true);
47  Walker_t::WFBuffer_t& w_buffer(thisWalker.DataSet);
48  Psi.copyFromBuffer(W, w_buffer);
50 
51  // start PbyP moves
53  bool moved = false;
54  constexpr RealType mhalf(-0.5);
55  for (int iter = 0; iter < nSubSteps; ++iter)
56  {
57  //create a 3N-Dimensional Gaussian with variance=1
59  moved = false;
60  for (int ig = 0; ig < W.groups(); ++ig) //loop over species
61  {
62  RealType tauovermass = Tau * MassInvS[ig];
63  RealType oneover2tau = 0.5 / (tauovermass);
64  RealType sqrttau = std::sqrt(tauovermass);
65  Psi.prepareGroup(W, ig);
66  for (int iat = W.first(ig); iat < W.last(ig); ++iat)
67  {
68  PosType dr;
69  if (UseDrift)
70  {
71  GradType grad_now = Psi.evalGrad(W, iat);
72  DriftModifier->getDrift(tauovermass, grad_now, dr);
73  dr += sqrttau * deltaR[iat];
74  }
75  else
76  dr = sqrttau * deltaR[iat];
77 
78  if (!W.makeMoveAndCheck(iat, dr))
79  {
80  ++nReject;
81  W.accept_rejectMove(iat, false);
82  continue;
83  }
84 
85  RealType prob(0);
86  if (UseDrift)
87  {
88  GradType grad_new;
89  prob = std::norm(Psi.calcRatioGrad(W, iat, grad_new));
90  DriftModifier->getDrift(tauovermass, grad_new, dr);
91  dr = W.R[iat] - W.getActivePos() - dr;
92  RealType logGb = -oneover2tau * dot(dr, dr);
93  RealType logGf = mhalf * dot(deltaR[iat], deltaR[iat]);
94  prob *= std::exp(logGb - logGf);
95  }
96  else
97  prob = std::norm(Psi.calcRatio(W, iat));
98 
99  bool is_accepted = false;
100  if (prob >= std::numeric_limits<RealType>::epsilon() && RandomGen() < prob)
101  {
102  is_accepted = true;
103  moved = true;
104  ++nAccept;
105  Psi.acceptMove(W, iat, true);
106  }
107  else
108  {
109  ++nReject;
110  Psi.rejectMove(iat);
111  }
112  W.accept_rejectMove(iat, is_accepted);
113  }
114  }
116  }
117  W.donePbyP();
120  RealType logpsi = Psi.updateBuffer(W, w_buffer, recompute);
122  checkLogAndGL(W, Psi, "checkGL_after_moves");
123  W.saveWalker(thisWalker);
125  // end PbyP moves
127  FullPrecRealType eloc = H.evaluate(W);
128  thisWalker.resetProperty(logpsi, Psi.getPhase(), eloc);
131  H.auxHevaluate(W, thisWalker);
132  H.saveProperty(thisWalker.getPropertyBase());
134 #if !defined(REMOVE_TRACEMANAGER)
136 #endif
137  if(wlog_collector)
138  wlog_collector->collect(thisWalker,W,Psi,H);
139  if (!moved)
140  ++nAllRejected;
141 }
142 
143 } // namespace qmcplusplus
TraceManager * Traces
traces
WalkerLogCollector * wlog_collector
Base class for update methods for each step.
Definition: QMCUpdateBase.h:41
void rejectMove(int iat)
restore to the original state
ValueType calcRatio(ParticleSet &P, int iat, ComputeType ct=ComputeType::ALL)
compute psi(R_new) / psi(R_current) ratio It returns a complex value if the wavefunction is complex...
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.
void copyFromBuffer(ParticleSet &P, WFBufferType &buf)
copy all the wavefunction components from buffer.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
TrialWaveFunction & Psi
trial function
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false)
update the state with the new data
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
Collection of Local Energy Operators.
void buffer_sample(int current_step)
int first(int igroup) const
return the first index of a group i
Definition: ParticleSet.h:514
int current_step
current MC step
Definition: ParticleSet.h:134
ParticleSet::ParticlePos deltaR
temporary storage for random displacement
RealType updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false)
update all the wavefunction components in buffer.
DriverDebugChecks debug_checks_
determine additional checks for debugging purpose
Definition: QMCUpdateBase.h:58
VMCUpdatePbyP(MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, RandomBase< FullPrecRealType > &rg)
Constructor.
int groups() const
return the number of groups
Definition: ParticleSet.h:511
const PosType & getActivePos() const
Definition: ParticleSet.h:261
double norm(const zVec &c)
Definition: VectorOps.h:118
void saveWalker(Walker_t &awalker)
save this to awalker
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
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...
ParticlePos R
Position.
Definition: ParticleSet.h:79
int last(int igroup) const
return the last index of a group i
Definition: ParticleSet.h:517
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
MCWalkerConfiguration & W
walker ensemble
static void checkLogAndGL(ParticleSet &pset, TrialWaveFunction &twf, const std::string_view location)
check logpsi and grad and lap against values computed from scratch
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
void collect(const MCPWalker &walker, const ParticleSet &pset, const TrialWaveFunction &wfn, const QMCHamiltonian &ham, int step=-1)
collect all data for one walker into the data buffers
void auxHevaluate(ParticleSet &P)
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)
Class to represent a many-body trial wave function.
RandomBase< FullPrecRealType > & RandomGen
random number generator
GradType evalGrad(ParticleSet &P, int iat)
FullPrecRealType evaluate(ParticleSet &P)
evaluate Local Energy
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
bool makeMoveAndCheck(Index_t iat, const SingleParticlePos &displ)
move the iat-th particle to active_pos_
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
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
virtual void getDrift(RealType tau, const GradType &qf, PosType &drift) const =0
evaluate a drift with a real force
void prepareGroup(ParticleSet &P, int ig)
Prepare internal data for updating WFC correspond to a particle group Particle groups usually corresp...
std::vector< RealType > MassInvS
1/Mass per species
A container class to represent a walker.
Definition: Walker.h:49
QMCHamiltonian & H
Hamiltonian.
ValueType calcRatioGrad(ParticleSet &P, int iat, GradType &grad_iat)
compute psi(R_new) / psi(R_current) ratio and ln(psi(R_new)) gradients It returns a complex value if...
void donePbyP(bool skipSK=false)
update structure factor and unmark active_ptcl_
void resetProperty(FullPrecRealType logpsi, FullPrecRealType sigN, FullPrecRealType ene)
reset the property of a walker
Definition: Walker.h:296
void completeUpdates()
complete all the delayed or asynchronous operations before leaving the p-by-p move region...
IndexType nAllRejected
Total number of the steps when all the particle moves are rejected.
Definition: QMCUpdateBase.h:67
const DriftModifierBase * DriftModifier
drift modifer, stateless reference to the one in QMCDriver
void makeGaussRandomWithEngine(ParticleAttrib< TinyVector< T, D >> &a, RG &rng)