QMCPACK
SOVMCUpdatePbyP.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Cody A. Melton, cmelton@sandia.gov, Sandia National Laboratories
8 //
9 // File created by: Cody A. Melton, cmelton@sandia.gov, Sandia National Laboratories
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "SOVMCUpdatePbyP.h"
15 #include "Concurrency/OpenMP.h"
16 #if !defined(REMOVE_TRACEMANAGER)
18 #else
19 using TraceManager = int;
20 #endif
21 
22 
23 namespace qmcplusplus
24 {
25 /// Constructor
27  TrialWaveFunction& psi,
28  QMCHamiltonian& h,
30  : QMCUpdateBase(w, psi, h, rg),
31  buffer_timer_(createGlobalTimer("SOVMCUpdatePbyP::Buffer", timer_level_medium)),
32  movepbyp_timer_(createGlobalTimer("SOVMCUpdatePbyP::MovePbyP", timer_level_medium)),
33  hamiltonian_timer_(createGlobalTimer("SOVMCUpdatePbyP::Hamiltonian", timer_level_medium)),
34  collectables_timer_(createGlobalTimer("SOVMCUpdatePbyP::Collectables", timer_level_medium))
35 {}
36 
38 
39 void SOVMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute)
40 {
42  W.loadWalker(thisWalker, true);
43  Walker_t::WFBuffer_t& w_buffer(thisWalker.DataSet);
44  Psi.copyFromBuffer(W, w_buffer);
46 
47  // start PbyP moves
49  bool moved = false;
50  constexpr RealType mhalf(-0.5);
51  for (int iter = 0; iter < nSubSteps; ++iter)
52  {
53  //create a 3N-Dimensional Gaussian with variance=1
56  moved = false;
57  for (int ig = 0; ig < W.groups(); ++ig) //loop over species
58  {
59  RealType tauovermass = Tau * MassInvS[ig];
60  RealType oneover2tau = 0.5 / (tauovermass);
61  RealType sqrttau = std::sqrt(tauovermass);
62  Psi.prepareGroup(W, ig);
63  for (int iat = W.first(ig); iat < W.last(ig); ++iat)
64  {
65  PosType dr;
67  if (UseDrift)
68  {
69  ComplexType spingrad_now;
70  GradType grad_now = Psi.evalGradWithSpin(W, iat, spingrad_now);
71  DriftModifier->getDrift(tauovermass, grad_now, dr);
72  DriftModifier->getDrift(tauovermass / spinMass, spingrad_now, ds);
73  dr += sqrttau * deltaR[iat];
74  ds += std::sqrt(tauovermass / spinMass) * deltaS[iat];
75  }
76  else
77  {
78  dr = sqrttau * deltaR[iat];
79  ds = std::sqrt(tauovermass / spinMass) * deltaS[iat];
80  }
81  if (!W.makeMoveAndCheckWithSpin(iat, dr, ds))
82  {
83  ++nReject;
84  W.accept_rejectMove(iat, false);
85  continue;
86  }
87  RealType prob(0);
88  if (UseDrift)
89  {
90  GradType grad_new;
91  ComplexType spingrad_new;
92  prob = std::norm(Psi.calcRatioGradWithSpin(W, iat, grad_new, spingrad_new));
93  DriftModifier->getDrift(tauovermass, grad_new, dr);
94  dr = W.R[iat] - W.getActivePos() - dr;
95  RealType logGb = -oneover2tau * dot(dr, dr);
96  RealType logGf = mhalf * dot(deltaR[iat], deltaR[iat]);
97 
98  DriftModifier->getDrift(tauovermass / spinMass, spingrad_new, ds);
99  ds = W.spins[iat] - W.getActiveSpinVal() - ds;
100  logGb += -spinMass * oneover2tau * ds * ds;
101  logGf += mhalf * deltaS[iat] * deltaS[iat];
102 
103  prob *= std::exp(logGb - logGf);
104  }
105  else
106  {
107  prob = std::norm(Psi.calcRatio(W, iat));
108  }
109 
110  bool is_accepted = false;
111  if (prob >= std::numeric_limits<RealType>::epsilon() && RandomGen() < prob)
112  {
113  is_accepted = true;
114  moved = true;
115  ++nAccept;
116  Psi.acceptMove(W, iat, true);
117  }
118  else
119  {
120  ++nReject;
121  Psi.rejectMove(iat);
122  }
123  W.accept_rejectMove(iat, is_accepted);
124  }
125  }
127  }
128  W.donePbyP();
131  RealType logpsi = Psi.updateBuffer(W, w_buffer, recompute);
133  checkLogAndGL(W, Psi, "checkGL_after_moves");
134  W.saveWalker(thisWalker);
136  // end PbyP moves
138  FullPrecRealType eloc = H.evaluate(W);
139  thisWalker.resetProperty(logpsi, Psi.getPhase(), eloc);
142  H.auxHevaluate(W, thisWalker);
143  H.saveProperty(thisWalker.getPropertyBase());
145 #if !defined(REMOVE_TRACEMANAGER)
147 #endif
148  if (!moved)
149  ++nAllRejected;
150 }
151 
152 } // namespace qmcplusplus
TraceManager * Traces
traces
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
Scalar_t getActiveSpinVal() const
Definition: ParticleSet.h:262
ParticleScalar spins
internal spin variables for dynamical spin calculations
Definition: ParticleSet.h:81
QTBase::RealType RealType
Definition: Configuration.h:58
TrialWaveFunction & Psi
trial function
RealType spinMass
spin mass
Definition: QMCUpdateBase.h:75
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false)
update the state with the new data
ParticleSet::ParticleScalar deltaS
temporart storage for spin displacement
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
SOVMCUpdatePbyP(MCWalkerConfiguration &w, TrialWaveFunction &psi, QMCHamiltonian &h, RandomBase< FullPrecRealType > &rg)
Constructor.
Collection of Local Energy Operators.
void buffer_sample(int current_step)
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
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
int groups() const
return the number of groups
Definition: ParticleSet.h:511
const PosType & getActivePos() const
Definition: ParticleSet.h:261
GradType evalGradWithSpin(ParticleSet &P, int iat, ComplexType &spingrad)
compute d/ds ln(psi) spin gradient at current particle position for iat electron
double norm(const zVec &c)
Definition: VectorOps.h:118
bool makeMoveAndCheckWithSpin(Index_t iat, const SingleParticlePos &displ, const Scalar_t &sdispl)
makeMoveAndCheck, but now includes an update to the spin variable
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 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
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)
ValueType calcRatioGradWithSpin(ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad_iat)
compute psi(R_new) / psi(R_current) ratio and d/ds ln(psi(R_new)) spin gradient It returns a complex ...
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.
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)