diff --git a/src/QMCDrivers/CorrelatedSampling/CSVMCUpdatePbyP.cpp b/src/QMCDrivers/CorrelatedSampling/CSVMCUpdatePbyP.cpp index 906bea4a18..3e46903efb 100644 --- a/src/QMCDrivers/CorrelatedSampling/CSVMCUpdatePbyP.cpp +++ b/src/QMCDrivers/CorrelatedSampling/CSVMCUpdatePbyP.cpp @@ -73,7 +73,7 @@ void CSVMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) stucked = false; ++nAccept; for (int ipsi = 0; ipsi < nPsi; ipsi++) - Psi1[ipsi]->acceptMove(W, iat); + Psi1[ipsi]->acceptMove(W, iat, true); W.acceptMove(iat, true); //Now we update ratioIJ. diff --git a/src/QMCDrivers/DMC/DMCBatched.cpp b/src/QMCDrivers/DMC/DMCBatched.cpp index 7cadb65ae8..250ec6f9a9 100644 --- a/src/QMCDrivers/DMC/DMCBatched.cpp +++ b/src/QMCDrivers/DMC/DMCBatched.cpp @@ -263,7 +263,7 @@ void DMCBatched::advanceWalkers(const StateForThread& sft, } } - TrialWaveFunction::flex_acceptMove(twf_accept_list, elec_accept_list, iat); + TrialWaveFunction::flex_acceptMove(twf_accept_list, elec_accept_list, iat, true); TrialWaveFunction::flex_rejectMove(twf_reject_list, iat); ParticleSet::flex_acceptMove(elec_accept_list, iat, true); diff --git a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp index 378537a2be..c653189d99 100644 --- a/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp +++ b/src/QMCDrivers/DMC/DMCUpdatePbyPFast.cpp @@ -108,7 +108,7 @@ void DMCUpdatePbyPWithRejectionFast::advanceWalker(Walker_t& thisWalker, bool re if (RandomGen() < prob) { ++nAcceptTemp; - Psi.acceptMove(W, iat); + Psi.acceptMove(W, iat, true); W.acceptMove(iat, true); rr_accepted += rr; gf_acc *= prob; //accumulate the ratio diff --git a/src/QMCDrivers/RMC/RMCUpdatePbyP.cpp b/src/QMCDrivers/RMC/RMCUpdatePbyP.cpp index accecd1e6e..4f26971c1e 100644 --- a/src/QMCDrivers/RMC/RMCUpdatePbyP.cpp +++ b/src/QMCDrivers/RMC/RMCUpdatePbyP.cpp @@ -179,7 +179,7 @@ void RMCUpdatePbyPWithDrift::advanceWalkersVMC() if (RandomGen() < prob) { ++nAcceptTemp; - Psi.acceptMove(W, iat); + Psi.acceptMove(W, iat, true); W.acceptMove(iat, true); rr_accepted += rr; gf_acc *= prob; //accumulate the ratio @@ -310,7 +310,7 @@ void RMCUpdatePbyPWithDrift::advanceWalkersRMC() if (RandomGen() < prob) { ++nAcceptTemp; - Psi.acceptMove(W, iat); + Psi.acceptMove(W, iat, true); W.acceptMove(iat, true); rr_accepted += rr; gf_acc *= prob; //accumulate the ratio diff --git a/src/QMCDrivers/VMC/SOVMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/SOVMCUpdatePbyP.cpp index 97a9fa8818..04fd977deb 100644 --- a/src/QMCDrivers/VMC/SOVMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/SOVMCUpdatePbyP.cpp @@ -111,7 +111,7 @@ void SOVMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) { moved = true; ++nAccept; - Psi.acceptMove(W, iat); + Psi.acceptMove(W, iat, true); W.acceptMove(iat, true); } else diff --git a/src/QMCDrivers/VMC/VMCBatched.cpp b/src/QMCDrivers/VMC/VMCBatched.cpp index 095a1b8447..b71cae8193 100644 --- a/src/QMCDrivers/VMC/VMCBatched.cpp +++ b/src/QMCDrivers/VMC/VMCBatched.cpp @@ -190,7 +190,7 @@ void VMCBatched::advanceWalkers(const StateForThread& sft, elec_reject_list.push_back(crowd.get_walker_elecs()[i_accept]); } - TrialWaveFunction::flex_acceptMove(twf_accept_list, elec_accept_list, iat); + TrialWaveFunction::flex_acceptMove(twf_accept_list, elec_accept_list, iat, true); TrialWaveFunction::flex_rejectMove(twf_reject_list, iat); ParticleSet::flex_acceptMove(elec_accept_list, iat, true); diff --git a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp index f39e1d7bdc..d9bbfb1c66 100644 --- a/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp +++ b/src/QMCDrivers/VMC/VMCUpdatePbyP.cpp @@ -95,7 +95,7 @@ void VMCUpdatePbyP::advanceWalker(Walker_t& thisWalker, bool recompute) { moved = true; ++nAccept; - Psi.acceptMove(W, iat); + Psi.acceptMove(W, iat, true); W.acceptMove(iat, true); } else diff --git a/src/QMCHamiltonians/NonLocalECPotential.cpp b/src/QMCHamiltonians/NonLocalECPotential.cpp index 9683a7d800..f12d72fa75 100644 --- a/src/QMCHamiltonians/NonLocalECPotential.cpp +++ b/src/QMCHamiltonians/NonLocalECPotential.cpp @@ -351,7 +351,7 @@ int NonLocalECPotential::makeNonLocalMovesPbyP(ParticleSet& P) { GradType grad_iat; Psi.calcRatioGrad(P, iat, grad_iat); - Psi.acceptMove(P, iat); + Psi.acceptMove(P, iat, true); P.acceptMove(iat); NonLocalMoveAccepted++; } @@ -371,7 +371,7 @@ int NonLocalECPotential::makeNonLocalMovesPbyP(ParticleSet& P) if (P.makeMoveAndCheck(iat, oneTMove->Delta)) { Psi.calcRatioGrad(P, iat, grad_iat); - Psi.acceptMove(P, iat); + Psi.acceptMove(P, iat, true); P.acceptMove(iat); NonLocalMoveAccepted++; } @@ -401,7 +401,7 @@ int NonLocalECPotential::makeNonLocalMovesPbyP(ParticleSet& P) if (P.makeMoveAndCheck(iat, oneTMove->Delta)) { Psi.calcRatioGrad(P, iat, grad_iat); - Psi.acceptMove(P, iat); + Psi.acceptMove(P, iat, true); // mark all affected electrons markAffectedElecs(P.getDistTable(myTableIndex), iat); P.acceptMove(iat); diff --git a/src/QMCWaveFunctions/AGPDeterminant.cpp b/src/QMCWaveFunctions/AGPDeterminant.cpp index 15add95998..af6bffa35d 100644 --- a/src/QMCWaveFunctions/AGPDeterminant.cpp +++ b/src/QMCWaveFunctions/AGPDeterminant.cpp @@ -354,7 +354,7 @@ void AGPDeterminant::ratioDown(ParticleSet& P, int iat) /** move was accepted, update the real container */ -void AGPDeterminant::acceptMove(ParticleSet& P, int iat) +void AGPDeterminant::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { LogValue += convertValueToLog(curRatio); //CurrentDet *= curRatio; diff --git a/src/QMCWaveFunctions/AGPDeterminant.h b/src/QMCWaveFunctions/AGPDeterminant.h index bfcb6f8d02..1f97924038 100644 --- a/src/QMCWaveFunctions/AGPDeterminant.h +++ b/src/QMCWaveFunctions/AGPDeterminant.h @@ -74,7 +74,7 @@ class AGPDeterminant : public WaveFunctionComponent /** move was accepted, update the real container */ - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); /** move was rejected. copy the real container to the temporary to move on */ diff --git a/src/QMCWaveFunctions/ConstantOrbital.h b/src/QMCWaveFunctions/ConstantOrbital.h index e8a3a8c042..d0b603b983 100644 --- a/src/QMCWaveFunctions/ConstantOrbital.h +++ b/src/QMCWaveFunctions/ConstantOrbital.h @@ -39,7 +39,7 @@ class ConstantOrbital : public WaveFunctionComponent return 0.0; } - virtual void acceptMove(ParticleSet& P, int iat) override {} + virtual void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override {} virtual void restore(int iat) override {} diff --git a/src/QMCWaveFunctions/ExampleHeComponent.h b/src/QMCWaveFunctions/ExampleHeComponent.h index 0a72118c65..cee185a695 100644 --- a/src/QMCWaveFunctions/ExampleHeComponent.h +++ b/src/QMCWaveFunctions/ExampleHeComponent.h @@ -48,7 +48,7 @@ class ExampleHeComponent : public WaveFunctionComponent ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) override; - void acceptMove(ParticleSet& P, int iat) override {} + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override {} void restore(int iat) override {} diff --git a/src/QMCWaveFunctions/FDLRWfn.cpp b/src/QMCWaveFunctions/FDLRWfn.cpp index 001f6e5787..a8fbf04786 100644 --- a/src/QMCWaveFunctions/FDLRWfn.cpp +++ b/src/QMCWaveFunctions/FDLRWfn.cpp @@ -662,10 +662,10 @@ FDLRWfn::PsiValueType FDLRWfn::ratio(ParticleSet& P, int iat) /// \param[in] iat the id number of the moved particle /// /////////////////////////////////////////////////////////////////////////////////////////////// -void FDLRWfn::acceptMove(ParticleSet& P, int iat) +void FDLRWfn::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { - m_wfn_xpd->acceptMove(P, iat); - m_wfn_xmd->acceptMove(P, iat); + m_wfn_xpd->acceptMove(P, iat, safe_to_delay); + m_wfn_xmd->acceptMove(P, iat, safe_to_delay); LogValue += convertValueToLog(curRatio); diff --git a/src/QMCWaveFunctions/FDLRWfn.h b/src/QMCWaveFunctions/FDLRWfn.h index ec12b0433b..fe2e054fb6 100644 --- a/src/QMCWaveFunctions/FDLRWfn.h +++ b/src/QMCWaveFunctions/FDLRWfn.h @@ -200,7 +200,7 @@ class FDLRWfn : public WaveFunctionComponent PsiValueType ratio(ParticleSet& P, int iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); void restore(int iat); diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 5a70bf13db..bced0b4aaa 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -223,12 +223,14 @@ void DiracDeterminant::mw_ratioGrad(const std::vector -void DiracDeterminant::acceptMove(ParticleSet& P, int iat) +void DiracDeterminant::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { const int WorkingIndex = iat - FirstIndex; LogValue += convertValueToLog(curRatio); UpdateTimer.start(); updateEng.acceptRow(psiM, WorkingIndex, psiV); + if (!safe_to_delay) + updateEng.updateInvMat(psiM); // invRow becomes invalid after accepting a move invRow_id = -1; if (UpdateMode == ORB_PBYP_PARTIAL) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index bf898da378..7083b07be1 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -122,14 +122,14 @@ class DiracDeterminant : public DiracDeterminantBase /** move was accepted, update the real container */ - void acceptMove(ParticleSet& P, int iat) override; + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override; void mw_acceptMove(const std::vector& WFC_list, const std::vector& P_list, - int iat) override + int iat, bool safe_to_delay = false) override { for (int iw = 0; iw < WFC_list.size(); iw++) - WFC_list[iw]->acceptMove(*P_list[iw], iat); + WFC_list[iw]->acceptMove(*P_list[iw], iat, safe_to_delay); } void completeUpdates() override; diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantCUDA.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantCUDA.h index e9ce417844..bff5f04c25 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantCUDA.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantCUDA.h @@ -157,7 +157,7 @@ class DiracDeterminantCUDA : public DiracDeterminantBase APP_ABORT("Calling DiracDeterminantCUDA::evaluateLog is illegal!"); } - void acceptMove(ParticleSet& P, int iat) { APP_ABORT("Calling DiracDeterminantCUDA::acceptMove is illegal!"); } + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { APP_ABORT("Calling DiracDeterminantCUDA::acceptMove is illegal!"); } void restore(int iat) { APP_ABORT("Calling DiracDeterminantCUDA::restore is illegal!"); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.cpp index 3b3daf0857..b1aa8a5364 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.cpp @@ -567,7 +567,7 @@ DiracDeterminantWithBackflow::LogValueType DiracDeterminantWithBackflow::evaluat /** move was accepted, update the real container */ -void DiracDeterminantWithBackflow::acceptMove(ParticleSet& P, int iat) +void DiracDeterminantWithBackflow::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { LogValue += convertValueToLog(curRatio); UpdateTimer.start(); diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.h index 4e4137dd5f..426dc8cf8e 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantWithBackflow.h @@ -123,7 +123,7 @@ class DiracDeterminantWithBackflow : public DiracDeterminantBase /** move was accepted, update the real container */ - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); /** move was rejected. copy the real container to the temporary to move on */ diff --git a/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.cpp index a1eab14910..68bb6b5844 100644 --- a/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.cpp @@ -255,7 +255,7 @@ void MultiDiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf) /** move was accepted, update the real container */ -void MultiDiracDeterminant::acceptMove(ParticleSet& P, int iat) +void MultiDiracDeterminant::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { WorkingIndex = iat - FirstIndex; switch (UpdateMode) diff --git a/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.h b/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.h index 612f47ed23..11aca2df67 100644 --- a/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/MultiDiracDeterminant.h @@ -155,7 +155,7 @@ class MultiDiracDeterminant : public WaveFunctionComponent /** move was accepted, update the real container */ - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); /** move was rejected. copy the real container to the temporary to move on */ diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.cpp b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.cpp index 1a8a678366..4bf7eabab0 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.cpp @@ -393,7 +393,7 @@ WaveFunctionComponent::PsiValueType MultiSlaterDeterminant::ratio(ParticleSet& P } } -void MultiSlaterDeterminant::acceptMove(ParticleSet& P, int iat) +void MultiSlaterDeterminant::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { // this should depend on the type of update, ratio / ratioGrad // for now is incorrect fot ratio(P,iat,dG,dL) updates diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.h b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.h index f73efa7050..737eaa7a90 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminant.h @@ -95,7 +95,7 @@ class MultiSlaterDeterminant : public WaveFunctionComponent virtual GradType evalGrad(ParticleSet& P, int iat); virtual PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat); virtual PsiValueType ratio(ParticleSet& P, int iat); - virtual void acceptMove(ParticleSet& P, int iat); + virtual void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); virtual void restore(int iat); virtual void registerData(ParticleSet& P, WFBufferType& buf); diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.cpp b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.cpp index 85d5521e92..400ca22bb1 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.cpp @@ -377,7 +377,7 @@ WaveFunctionComponent::PsiValueType MultiSlaterDeterminantFast::ratio(ParticleSe return curRatio; } -void MultiSlaterDeterminantFast::acceptMove(ParticleSet& P, int iat) +void MultiSlaterDeterminantFast::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { // this should depend on the type of update, ratio / ratioGrad // for now is incorrect fot ratio(P,iat,dG,dL) updates @@ -390,7 +390,7 @@ void MultiSlaterDeterminantFast::acceptMove(ParticleSet& P, int iat) psiCurrent *= curRatio; curRatio = 1.0; - Dets[iat >= nels_up]->acceptMove(P, iat); + Dets[iat >= nels_up]->acceptMove(P, iat, safe_to_delay); //Dets[DetID[iat]]->acceptMove(P,iat); AccRejTimer.stop(); diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.h b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.h index 566e93a5d5..e094e4bc0c 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.h +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantFast.h @@ -118,7 +118,7 @@ class MultiSlaterDeterminantFast : public WaveFunctionComponent APP_ABORT(" Need to implement MultiSlaterDeterminantFast::evaluateRatiosAlltoOne. \n"); } - void acceptMove(ParticleSet& P, int iat) override; + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override; void restore(int iat) override; void registerData(ParticleSet& P, WFBufferType& buf) override; diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.cpp b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.cpp index 2a927c672c..70d96c3d84 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.cpp @@ -355,7 +355,7 @@ WaveFunctionComponent::PsiValueType MultiSlaterDeterminantWithBackflow::ratio(Pa } } -void MultiSlaterDeterminantWithBackflow::acceptMove(ParticleSet& P, int iat) +void MultiSlaterDeterminantWithBackflow::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { // this should depend on the type of update, ratio / ratioGrad // for now is incorrect fot ratio(P,iat,dG,dL) updates diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.h b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.h index b866acf993..f7ee2d069d 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.h +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDeterminantWithBackflow.h @@ -65,7 +65,7 @@ class MultiSlaterDeterminantWithBackflow : public MultiSlaterDeterminant GradType evalGrad(ParticleSet& P, int iat); PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat); PsiValueType ratio(ParticleSet& P, int iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); void restore(int iat); void registerData(ParticleSet& P, WFBufferType& buf); diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index 48e4f4e874..e82ad8095b 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -162,9 +162,9 @@ class SlaterDet : public WaveFunctionComponent Dets[det_id]->mw_restore(extract_Det_list(WFC_list, det_id), iat); } - virtual inline void acceptMove(ParticleSet& P, int iat) override + virtual inline void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override { - Dets[getDetID(iat)]->acceptMove(P, iat); + Dets[getDetID(iat)]->acceptMove(P, iat, safe_to_delay); LogValue = 0.0; for (int i = 0; i < Dets.size(); ++i) @@ -173,7 +173,7 @@ class SlaterDet : public WaveFunctionComponent virtual void mw_acceptMove(const std::vector& WFC_list, const std::vector& P_list, - int iat) override + int iat, bool safe_to_delay = false) override { constexpr RealType czero(0); @@ -185,7 +185,7 @@ class SlaterDet : public WaveFunctionComponent const std::vector Det_list(extract_Det_list(WFC_list, i)); if (i == getDetID(iat)) - Dets[i]->mw_acceptMove(Det_list, P_list, iat); + Dets[i]->mw_acceptMove(Det_list, P_list, iat, safe_to_delay); for (int iw = 0; iw < WFC_list.size(); iw++) WFC_list[iw]->LogValue += Det_list[iw]->LogValue; diff --git a/src/QMCWaveFunctions/Fermion/SlaterDetWithBackflow.h b/src/QMCWaveFunctions/Fermion/SlaterDetWithBackflow.h index cbd5189cbb..03c3c75f16 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDetWithBackflow.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDetWithBackflow.h @@ -119,7 +119,7 @@ class SlaterDetWithBackflow : public SlaterDet return GradType(); } - inline void acceptMove(ParticleSet& P, int iat) + inline void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { BFTrans->acceptMove(P, iat); for (int i = 0; i < Dets.size(); i++) diff --git a/src/QMCWaveFunctions/Jastrow/CountingJastrow.h b/src/QMCWaveFunctions/Jastrow/CountingJastrow.h index 4158dfe281..830e548ccc 100644 --- a/src/QMCWaveFunctions/Jastrow/CountingJastrow.h +++ b/src/QMCWaveFunctions/Jastrow/CountingJastrow.h @@ -380,7 +380,7 @@ class CountingJastrow : public WaveFunctionComponent return std::exp(static_cast(Jval_t - Jval)); } - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { C->acceptMove(P, iat); // update values for C, FC to those at proposed position diff --git a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h index 403519dd22..d85e36f8a9 100644 --- a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h @@ -315,7 +315,7 @@ struct J1OrbitalSoA : public WaveFunctionComponent inline void restore(int iat) {} /** Accpted move. Update Vat[iat],Grad[iat] and Lap[iat] */ - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { if (UpdateMode == ORB_PBYP_RATIO) { diff --git a/src/QMCWaveFunctions/Jastrow/J2OrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/J2OrbitalSoA.h index e3ae72e6b0..83d1170f81 100644 --- a/src/QMCWaveFunctions/Jastrow/J2OrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/J2OrbitalSoA.h @@ -262,7 +262,7 @@ class J2OrbitalSoA : public WaveFunctionComponent PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); inline void restore(int iat) {} /** compute G and L after the sweep @@ -548,7 +548,7 @@ typename J2OrbitalSoA::PsiValueType J2OrbitalSoA::ratioGrad(ParticleSet& } template -void J2OrbitalSoA::acceptMove(ParticleSet& P, int iat) +void J2OrbitalSoA::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { // get the old u, du, d2u const auto& d_table = P.getDistTable(my_table_ID_); diff --git a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h index 4afec1838d..0655886016 100644 --- a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h @@ -480,7 +480,7 @@ class JeeIOrbitalSoA : public WaveFunctionComponent inline void restore(int iat) {} - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { const DistanceTableData& eI_table = P.getDistTable(ei_Table_ID_); const DistanceTableData& ee_table = P.getDistTable(ee_Table_ID_); diff --git a/src/QMCWaveFunctions/Jastrow/OneBodyJastrowOrbital.h b/src/QMCWaveFunctions/Jastrow/OneBodyJastrowOrbital.h index ce56de897e..ae54fe847f 100644 --- a/src/QMCWaveFunctions/Jastrow/OneBodyJastrowOrbital.h +++ b/src/QMCWaveFunctions/Jastrow/OneBodyJastrowOrbital.h @@ -386,7 +386,7 @@ class OneBodyJastrowOrbital : public WaveFunctionComponent inline void restore(int iat) {} - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { LogValue += U[iat] - curVal; U[iat] = curVal; diff --git a/src/QMCWaveFunctions/Jastrow/OneBodySpinJastrowOrbital.h b/src/QMCWaveFunctions/Jastrow/OneBodySpinJastrowOrbital.h index f94e979fd3..000a2d7e2f 100644 --- a/src/QMCWaveFunctions/Jastrow/OneBodySpinJastrowOrbital.h +++ b/src/QMCWaveFunctions/Jastrow/OneBodySpinJastrowOrbital.h @@ -384,7 +384,7 @@ class OneBodySpinJastrowOrbital : public WaveFunctionComponent inline void restore(int iat) {} - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { U[iat] = curVal; dU[iat] = curGrad; diff --git a/src/QMCWaveFunctions/Jastrow/RPAJastrow.cpp b/src/QMCWaveFunctions/Jastrow/RPAJastrow.cpp index f6e98f6962..26dd01f431 100644 --- a/src/QMCWaveFunctions/Jastrow/RPAJastrow.cpp +++ b/src/QMCWaveFunctions/Jastrow/RPAJastrow.cpp @@ -280,10 +280,10 @@ RPAJastrow::PsiValueType RPAJastrow::ratioGrad(ParticleSet& P, int iat, GradType } -void RPAJastrow::acceptMove(ParticleSet& P, int iat) +void RPAJastrow::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { for (int i = 0; i < Psi.size(); i++) - Psi[i]->acceptMove(P, iat); + Psi[i]->acceptMove(P, iat, safe_to_delay); } void RPAJastrow::restore(int iat) diff --git a/src/QMCWaveFunctions/Jastrow/RPAJastrow.h b/src/QMCWaveFunctions/Jastrow/RPAJastrow.h index 669e012a66..85189075c7 100644 --- a/src/QMCWaveFunctions/Jastrow/RPAJastrow.h +++ b/src/QMCWaveFunctions/Jastrow/RPAJastrow.h @@ -80,7 +80,7 @@ struct RPAJastrow : public WaveFunctionComponent GradType evalGrad(ParticleSet& P, int iat); PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); void restore(int iat); diff --git a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrowOrbital.h b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrowOrbital.h index 7d59236b25..ed35d6320d 100644 --- a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrowOrbital.h +++ b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrowOrbital.h @@ -375,7 +375,7 @@ class TwoBodyJastrowOrbital : public WaveFunctionComponent inline void restore(int iat) {} - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { DiffValSum += DiffVal; for (int jat = 0, ij = iat * N, ji = iat; jat < N; jat++, ij++, ji += N) diff --git a/src/QMCWaveFunctions/Jastrow/eeI_JastrowOrbital.h b/src/QMCWaveFunctions/Jastrow/eeI_JastrowOrbital.h index 8550435f25..db0ec6fc79 100644 --- a/src/QMCWaveFunctions/Jastrow/eeI_JastrowOrbital.h +++ b/src/QMCWaveFunctions/Jastrow/eeI_JastrowOrbital.h @@ -874,7 +874,7 @@ class eeI_JastrowOrbital : public WaveFunctionComponent inline void restore(int iat) {} - void acceptMove(ParticleSet& P, int iat) + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) { const auto& eI_table = P.getDistTable(ei_table_index_); // std::cerr << "acceptMove called.\n"; diff --git a/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.cpp b/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.cpp index 4e10d94cbe..e086a80165 100644 --- a/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.cpp +++ b/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.cpp @@ -628,7 +628,7 @@ void kSpaceJastrow::restore(int iat) //if(NeedToRestore) Rhok -= delta_eikr; } -void kSpaceJastrow::acceptMove(ParticleSet& P, int iat) +void kSpaceJastrow::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { for (int i = 0; i < TwoBody_e2iGr_new.size(); i++) TwoBody_rhoG[i] += Delta_e2iGr(iat, i); diff --git a/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.h b/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.h index e9387dabe4..81c3ed8757 100644 --- a/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.h +++ b/src/QMCWaveFunctions/Jastrow/kSpaceJastrow.h @@ -171,7 +171,7 @@ class kSpaceJastrow : public WaveFunctionComponent PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat); void restore(int iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); // Allocate per-walker data in the PooledData buffer void registerData(ParticleSet& P, WFBufferType& buf); diff --git a/src/QMCWaveFunctions/LatticeGaussianProduct.cpp b/src/QMCWaveFunctions/LatticeGaussianProduct.cpp index 5a6ae71c78..1dd4070264 100644 --- a/src/QMCWaveFunctions/LatticeGaussianProduct.cpp +++ b/src/QMCWaveFunctions/LatticeGaussianProduct.cpp @@ -164,7 +164,7 @@ PsiValueType LatticeGaussianProduct::ratioGrad(ParticleSet& P, int iat, GradType void LatticeGaussianProduct::restore(int iat) {} -void LatticeGaussianProduct::acceptMove(ParticleSet& P, int iat) +void LatticeGaussianProduct::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { U[iat] = curVal; dU[iat] = curGrad; diff --git a/src/QMCWaveFunctions/LatticeGaussianProduct.h b/src/QMCWaveFunctions/LatticeGaussianProduct.h index 86aefe82cd..fe50feb3f2 100644 --- a/src/QMCWaveFunctions/LatticeGaussianProduct.h +++ b/src/QMCWaveFunctions/LatticeGaussianProduct.h @@ -68,7 +68,7 @@ struct LatticeGaussianProduct : public WaveFunctionComponent PsiValueType ratio(ParticleSet& P, int iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); void restore(int iat); diff --git a/src/QMCWaveFunctions/LinearOrbital.h b/src/QMCWaveFunctions/LinearOrbital.h index 493b071abe..5e35d81ed6 100644 --- a/src/QMCWaveFunctions/LinearOrbital.h +++ b/src/QMCWaveFunctions/LinearOrbital.h @@ -58,7 +58,7 @@ class LinearOrbital : public WaveFunctionComponent return LogValue; } - virtual void acceptMove(ParticleSet& P, int iat) {} + virtual void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) {} virtual void restore(int iat) {} diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 11fb7e7a7c..1a3de67ba8 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -583,12 +583,12 @@ void TrialWaveFunction::flex_rejectMove(const RefVector& wf_l * The proposed move of the iath particle is accepted. * All the temporary data should be incorporated so that the next move is valid. */ -void TrialWaveFunction::acceptMove(ParticleSet& P, int iat) +void TrialWaveFunction::acceptMove(ParticleSet& P, int iat, bool safe_to_delay) { for (int i = 0, ii = ACCEPT_TIMER; i < Z.size(); i++, ii += TIMER_SKIP) { myTimers[ii]->start(); - Z[i]->acceptMove(P, iat); + Z[i]->acceptMove(P, iat, safe_to_delay); myTimers[ii]->stop(); } PhaseValue += PhaseDiff; @@ -600,7 +600,7 @@ void TrialWaveFunction::acceptMove(ParticleSet& P, int iat) void TrialWaveFunction::flex_acceptMove(const RefVector& wf_list, const RefVector& p_list, - int iat) + int iat, bool safe_to_delay) { if (wf_list.size() > 1) { @@ -618,7 +618,7 @@ void TrialWaveFunction::flex_acceptMove(const RefVector& wf_l ScopedTimer localtimer(wf_list[0].get().get_timers()[ii]); const auto wfc_list(extractWFCRefList(wf_list, i)); wavefunction_components[i]->mw_acceptMove(convert_ref_to_ptr_list(wfc_list), convert_ref_to_ptr_list(p_list), - iat); + iat, safe_to_delay); for (int iw = 0; iw < wf_list.size(); iw++) { wf_list[iw].get().LogValue += std::real(wfc_list[iw].get().LogValue); @@ -627,7 +627,7 @@ void TrialWaveFunction::flex_acceptMove(const RefVector& wf_l } } else if (wf_list.size() == 1) - wf_list[0].get().acceptMove(p_list[0], iat); + wf_list[0].get().acceptMove(p_list[0], iat, safe_to_delay); } void TrialWaveFunction::completeUpdates() diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 0ffd3bcf3a..50488d12a5 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -259,11 +259,11 @@ class TrialWaveFunction : public MPIObjectBase /* flexible batched version of rejectMove */ static void flex_rejectMove(const RefVector& wf_list, int iat); - void acceptMove(ParticleSet& P, int iat); + void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false); /* flexible batched version of acceptMove */ static void flex_acceptMove(const RefVector& wf_list, const RefVector& p_list, - int iat); + int iat, bool safe_to_delay = false); void completeUpdates(); /* flexible batched version of completeUpdates. */ void flex_completeUpdates(const std::vector& WF_list) const; diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index e969a30cc5..17f33c0a73 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -363,22 +363,24 @@ struct WaveFunctionComponent : public QMCTraits /** a move for iat-th particle is accepted. Update the current content. * @param P target ParticleSet * @param iat index of the particle whose new position was proposed + * @param safe_to_delay if true, delayed accept is safe. */ - virtual void acceptMove(ParticleSet& P, int iat) = 0; + virtual void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) = 0; /** moves of the iat-th particle on some walkers in a batch is accepted. Update the current content. * Note that all the lists only include accepted walkers. * @param WFC_list the list of WaveFunctionComponent pointers of the same component in a walker batch * @param P_list the list of ParticleSet pointers in a walker batch * @param iat particle index + * @param safe_to_delay if true, delayed accept is safe. */ virtual void mw_acceptMove(const std::vector& WFC_list, const std::vector& P_list, - int iat) + int iat, bool safe_to_delay = false) { #pragma omp parallel for for (int iw = 0; iw < WFC_list.size(); iw++) - WFC_list[iw]->acceptMove(*P_list[iw], iat); + WFC_list[iw]->acceptMove(*P_list[iw], iat, safe_to_delay); } /** complete all the delayed updates, must be called after each substep or step during pbyp move diff --git a/src/QMCWaveFunctions/tests/test_dirac_det.cpp b/src/QMCWaveFunctions/tests/test_dirac_det.cpp index 1964371d5b..e8c6222af2 100644 --- a/src/QMCWaveFunctions/tests/test_dirac_det.cpp +++ b/src/QMCWaveFunctions/tests/test_dirac_det.cpp @@ -247,7 +247,6 @@ TEST_CASE("DiracDeterminant_first", "[wavefunction][fermion]") REQUIRE(det_ratio1 == ValueApprox(det_ratio)); ddb.acceptMove(elec, 0); - ddb.completeUpdates(); b(0, 0) = 3.455170657; b(0, 1) = -1.35124809; @@ -345,7 +344,6 @@ TEST_CASE("DiracDeterminant_second", "[wavefunction][fermion]") ddb.acceptMove(elec, 0); - PsiValueType det_ratio2 = ddb.ratioGrad(elec, 1, grad); LogValueType det_update2; simd::transpose(a_update2.data(), a_update2.rows(), a_update2.cols(), scratchT.data(), scratchT.rows(), @@ -377,7 +375,6 @@ TEST_CASE("DiracDeterminant_second", "[wavefunction][fermion]") //check_value(det_ratio3, det_ratio3_val); ddb.acceptMove(elec, 2); - ddb.completeUpdates(); simd::transpose(orig_a.data(), orig_a.rows(), orig_a.cols(), scratchT.data(), scratchT.rows(), scratchT.cols()); dm.invert_transpose(scratchT, orig_a, det_update3); @@ -474,10 +471,12 @@ TEST_CASE("DiracDeterminant_delayed_update", "[wavefunction][fermion]") REQUIRE(det_ratio1 == ValueApprox(det_ratio)); // update of Ainv in ddc is delayed - ddc.acceptMove(elec, 0); + ddc.acceptMove(elec, 0, true); // force update Ainv in ddc using SM-1 code path ddc.completeUpdates(); + check_matrix(a_update1, ddc.psiM); + grad = ddc.evalGrad(elec, 1); PsiValueType det_ratio2 = ddc.ratioGrad(elec, 1, grad); simd::transpose(a_update2.data(), a_update2.rows(), a_update2.cols(), scratchT.data(), scratchT.rows(), @@ -495,7 +494,7 @@ TEST_CASE("DiracDeterminant_delayed_update", "[wavefunction][fermion]") REQUIRE(det_ratio2 == ValueApprox(det_ratio2_val)); // update of Ainv in ddc is delayed - ddc.acceptMove(elec, 1); + ddc.acceptMove(elec, 1, true); grad = ddc.evalGrad(elec, 2); PsiValueType det_ratio3 = ddc.ratioGrad(elec, 2, grad); @@ -514,7 +513,7 @@ TEST_CASE("DiracDeterminant_delayed_update", "[wavefunction][fermion]") //check_value(det_ratio3, det_ratio3_val); // maximal delay reached and Ainv is updated fully - ddc.acceptMove(elec, 2); + ddc.acceptMove(elec, 2, true); ddc.completeUpdates(); // fresh invert orig_a