From 61638999b7695ffa6b793bebafbe131ec29f9d2a Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Wed, 18 Jan 2023 11:41:13 -0600 Subject: [PATCH 1/8] Add arguments to evaluateDerivRatios --- src/QMCHamiltonians/NonLocalECPotential.deriv.cpp | 2 +- src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp | 2 ++ src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h | 2 ++ src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h | 2 ++ src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h | 2 ++ src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp | 2 ++ src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h | 2 ++ src/QMCWaveFunctions/TrialWaveFunction.cpp | 4 +++- src/QMCWaveFunctions/TrialWaveFunction.h | 4 +++- src/QMCWaveFunctions/WaveFunctionComponent.cpp | 2 ++ src/QMCWaveFunctions/WaveFunctionComponent.h | 6 +++--- 11 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp b/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp index 1bd9559ced..3206e49e85 100644 --- a/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp +++ b/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp @@ -82,7 +82,7 @@ NonLocalECPComponent::RealType NonLocalECPComponent::evaluateValueAndDerivatives { // Compute ratios with VP VP->makeMoves(W, iel, deltaV, true, iat); - psi.evaluateDerivRatios(*VP, optvars, psiratio, dratio); + psi.evaluateDerivRatios(*VP, W, iel, optvars, psiratio, dratio); } else { diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp index a99dc72525..41ff996f4d 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp @@ -1016,6 +1016,8 @@ void MultiSlaterDetTableMethod::evaluateDerivativesMSD(const PsiValueType& multi } void MultiSlaterDetTableMethod::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h index b7a3fc7b82..266e30d605 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h @@ -189,6 +189,8 @@ class MultiSlaterDetTableMethod : public WaveFunctionComponent, public Optimizab Vector& dlogpsi) override; void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h index 0993bb7a26..dff6d4f08b 100644 --- a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h @@ -561,6 +561,8 @@ class J1OrbitalSoA : public WaveFunctionComponent /**@} */ void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override diff --git a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h index 3548c7ca0f..ac1c6b6bb2 100644 --- a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h @@ -948,6 +948,8 @@ class JeeIOrbitalSoA : public WaveFunctionComponent } void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override diff --git a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp index 29aff99e3b..5a6a9f6bd2 100644 --- a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp +++ b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp @@ -969,6 +969,8 @@ void TwoBodyJastrow::evaluateDerivativesWF(ParticleSet& P, template void TwoBodyJastrow::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h index 01301adcfa..940bc703ac 100644 --- a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h +++ b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h @@ -259,6 +259,8 @@ class TwoBodyJastrow : public WaveFunctionComponent void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& active, Vector& dlogpsi) override; void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 0fafb2263d..712739d601 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1037,6 +1037,8 @@ void TrialWaveFunction::mw_evaluateRatios(const RefVectorWithLeader& ratios, Matrix& dratio) @@ -1047,7 +1049,7 @@ void TrialWaveFunction::evaluateDerivRatios(const VirtualParticleSet& VP, for (int i = 0; i < Z.size(); ++i) { ScopedTimer z_timer(WFC_timers_[DERIVS_TIMER + TIMER_SKIP * i]); - Z[i]->evaluateDerivRatios(VP, optvars, t, dratio); + Z[i]->evaluateDerivRatios(VP, P, iel, optvars, t, dratio); for (int j = 0; j < ratios.size(); ++j) ratios[j] *= t[j]; } diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 78fbebf629..50b2f5b577 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -312,7 +312,9 @@ class TrialWaveFunction ComputeType ct = ComputeType::ALL); /** compute both ratios and deriatives of ratio with respect to the optimizables*/ - void evaluateDerivRatios(const VirtualParticleSet& P, + void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratio); diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index 0853e9916f..621a8a0784 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -248,6 +248,8 @@ void WaveFunctionComponent::mw_evaluateRatios(const RefVectorWithLeader& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 2cc34fe9e7..3c90df4c33 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -490,9 +490,7 @@ class WaveFunctionComponent : public QMCTraits * Note: this function differs from the evaluateDerivatives function in the way that it only computes * the derivative of the log of the wavefunction. */ - virtual void evaluateDerivativesWF(ParticleSet& P, - const opt_variables_type& optvars, - Vector& dlogpsi); + virtual void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& optvars, Vector& dlogpsi); /** Calculates the derivatives of \f$ \nabla \textnormal{log} \psi_f \f$ with respect to the optimizable parameters, and the dot product of this is then @@ -535,6 +533,8 @@ class WaveFunctionComponent : public QMCTraits * @param dratios Nq x Num_param matrix. \f$\partial_{\alpha}(\ln \Psi ({\bf R}^{\prime}) - \ln \Psi ({\bf R})) \f$ */ virtual void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios); From 02e73bf1ef56b7031d24e3c4ba6b962889098b7c Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Wed, 18 Jan 2023 22:43:37 -0600 Subject: [PATCH 2/8] Add parameter derivative functions Add evaluateDerivativesWF and evaluateDerivRatios to RotatedSPOs --- .../Fermion/DiracDeterminant.cpp | 22 +++ .../Fermion/DiracDeterminant.h | 11 ++ src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 10 ++ src/QMCWaveFunctions/Fermion/SlaterDet.h | 7 + src/QMCWaveFunctions/RotatedSPOs.cpp | 130 +++++++++++++++++- src/QMCWaveFunctions/RotatedSPOs.h | 17 +++ src/QMCWaveFunctions/SPOSet.cpp | 33 +++++ src/QMCWaveFunctions/SPOSet.h | 22 +++ 8 files changed, 249 insertions(+), 3 deletions(-) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 57da4f81e0..b94f300c80 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -456,6 +456,20 @@ void DiracDeterminant::mw_evaluateRatios(const RefVectorWithLeader +void DiracDeterminant::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) +{ + const int WorkingIndex = VP.refPtcl - FirstIndex; + assert(WorkingIndex >= 0); + std::copy_n(psiM[WorkingIndex], invRow.size(), invRow.data()); + Phi->evaluateDerivRatios(VP, P, iel, optvars, psiV, invRow, ratios, dratios, FirstIndex, LastIndex); +} + template void DiracDeterminant::evaluateRatiosAlltoOne(ParticleSet& P, std::vector& ratios) { @@ -673,6 +687,14 @@ void DiracDeterminant::evaluateDerivatives(ParticleSet& P, Phi->evaluateDerivatives(P, active, dlogpsi, dhpsioverpsi, FirstIndex, LastIndex); } +template +void DiracDeterminant::evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& active, + Vector& dlogpsi) +{ + Phi->evaluateDerivativesWF(P, active, dlogpsi, FirstIndex, LastIndex); +} + template std::unique_ptr DiracDeterminant::makeCopy(std::unique_ptr&& spo) const { diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index 981c3f05f8..5f88f20432 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -77,6 +77,10 @@ class DiracDeterminant : public DiracDeterminantBase Vector& dlogpsi, Vector& dhpsioverpsi) override; + void evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi) override; + void registerData(ParticleSet& P, WFBufferType& buf) override; void updateAfterSweep(const ParticleSet& P, ParticleSet::ParticleGradient& G, ParticleSet::ParticleLaplacian& L); @@ -109,6 +113,13 @@ class DiracDeterminant : public DiracDeterminantBase const RefVectorWithLeader& vp_list, std::vector>& ratios) const override; + void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) override; + PsiValueType ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override; PsiValueType ratioGradWithSpin(ParticleSet& P, int iat, GradType& grad_iat, ComplexType& spingrad) final; diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index f8907bc872..e41cd7fac7 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -88,6 +88,16 @@ void SlaterDet::evaluateRatiosAlltoOne(ParticleSet& P, std::vector& r Dets[i]->evaluateRatiosAlltoOne(P, ratios); } +void SlaterDet::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) +{ + return Dets[getDetID(VP.refPtcl)]->evaluateDerivRatios(VP, P, iel, optvars, ratios, dratios); +} + SlaterDet::LogValueType SlaterDet::evaluateLog(const ParticleSet& P, ParticleSet::ParticleGradient& G, ParticleSet::ParticleLaplacian& L) diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index 3bd2102e18..f7ccae05ec 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -109,6 +109,13 @@ class SlaterDet : public WaveFunctionComponent return Dets[getDetID(VP.refPtcl)]->evaluateRatios(VP, ratios); } + void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) override; + inline void mw_evaluateRatios(const RefVectorWithLeader& wfc_list, const RefVectorWithLeader& vp_list, std::vector>& ratios) const override diff --git a/src/QMCWaveFunctions/RotatedSPOs.cpp b/src/QMCWaveFunctions/RotatedSPOs.cpp index 45c576d378..1ea8a00bd2 100644 --- a/src/QMCWaveFunctions/RotatedSPOs.cpp +++ b/src/QMCWaveFunctions/RotatedSPOs.cpp @@ -306,6 +306,130 @@ void RotatedSPOs::log_antisym_matrix(ValueMatrix& mat) } } +void RotatedSPOs::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + ValueVector& psi, + const ValueVector& psiinv, + std::vector& ratios, + Matrix& dratios, + int FirstIndex, + int LastIndex) +{ + Phi->evaluateDetRatios(VP, psi, psiinv, ratios); + + const size_t nel = LastIndex - FirstIndex; + const size_t nmo = Phi->getOrbitalSetSize(); + + psiM_inv.resize(nel, nel); + psiM_all.resize(nel, nmo); + dpsiM_all.resize(nel, nmo); + d2psiM_all.resize(nel, nmo); + + psiM_inv = 0; + psiM_all = 0; + dpsiM_all = 0; + d2psiM_all = 0; + + Phi->evaluate_notranspose(P, FirstIndex, LastIndex, psiM_all, dpsiM_all, d2psiM_all); + + for (int i = 0; i < nel; i++) + for (int j = 0; j < nel; j++) + psiM_inv(i, j) = psiM_all(i, j); + + Invert(psiM_inv.data(), nel, nel); + + const ValueType* const A(psiM_all.data()); + const ValueType* const Ainv(psiM_inv.data()); + SPOSet::ValueMatrix T_orig; + T_orig.resize(nel, nmo); + + BLAS::gemm('N', 'N', nmo, nel, nel, ValueType(1.0), A, nmo, Ainv, nel, ValueType(0.0), T_orig.data(), nmo); + + SPOSet::ValueMatrix T; + T.resize(nel, nmo); + + ValueVector tmp_psi; + tmp_psi.resize(nmo); + + for (int iat = 0; iat < VP.getTotalNum(); iat++) + { + Phi->evaluateValue(VP, iat, tmp_psi); + + for (int j = 0; j < nmo; j++) + psiM_all(iel - FirstIndex, j) = tmp_psi[j]; + + for (int i = 0; i < nel; i++) + for (int j = 0; j < nel; j++) + psiM_inv(i, j) = psiM_all(i, j); + + Invert(psiM_inv.data(), nel, nel); + + const ValueType* const A(psiM_all.data()); + const ValueType* const Ainv(psiM_inv.data()); + + // The matrix A is rectangular. Ainv is the inverse of the square part of the matrix. + // The multiply of Ainv and the square part of A is just the identity. + // This multiply could be reduced to Ainv and the non-square part of A. + BLAS::gemm('N', 'N', nmo, nel, nel, ValueType(1.0), A, nmo, Ainv, nel, ValueType(0.0), T.data(), nmo); + + for (int i = 0; i < m_act_rot_inds.size(); i++) + { + int kk = myVars.where(i); + const int p = m_act_rot_inds.at(i).first; + const int q = m_act_rot_inds.at(i).second; + dratios(iat, kk) = T(p, q) - T_orig(p, q); // dratio size is (nknot, num_vars) + } + } +} + +void RotatedSPOs::evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi, + int FirstIndex, + int LastIndex) +{ + const size_t nel = LastIndex - FirstIndex; + const size_t nmo = Phi->getOrbitalSetSize(); + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART1 + + psiM_inv.resize(nel, nel); + psiM_all.resize(nel, nmo); + dpsiM_all.resize(nel, nmo); + d2psiM_all.resize(nel, nmo); + + psiM_inv = 0; + psiM_all = 0; + dpsiM_all = 0; + d2psiM_all = 0; + + Phi->evaluate_notranspose(P, FirstIndex, LastIndex, psiM_all, dpsiM_all, d2psiM_all); + + for (int i = 0; i < nel; i++) + for (int j = 0; j < nel; j++) + psiM_inv(i, j) = psiM_all(i, j); + + Invert(psiM_inv.data(), nel, nel); + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PART2 + const ValueType* const A(psiM_all.data()); + const ValueType* const Ainv(psiM_inv.data()); + SPOSet::ValueMatrix T; + T.resize(nel, nmo); + + BLAS::gemm('N', 'N', nmo, nel, nel, ValueType(1.0), A, nmo, Ainv, nel, ValueType(0.0), T.data(), nmo); + + for (int i = 0; i < m_act_rot_inds.size(); i++) + { + int kk = myVars.where(i); + const int p = m_act_rot_inds.at(i).first; + const int q = m_act_rot_inds.at(i).second; + dlogpsi[kk] = T(p, q); + } +} + void RotatedSPOs::evaluateDerivatives(ParticleSet& P, const opt_variables_type& optvars, Vector& dlogpsi, @@ -401,9 +525,9 @@ void RotatedSPOs::evaluateDerivatives(ParticleSet& P, for (int i = 0; i < m_act_rot_inds.size(); i++) { - int kk = myVars.where(i); - const int p = m_act_rot_inds.at(i).first; - const int q = m_act_rot_inds.at(i).second; + int kk = myVars.where(i); + const int p = m_act_rot_inds.at(i).first; + const int q = m_act_rot_inds.at(i).second; dlogpsi[kk] = T(p, q); dhpsioverpsi[kk] = ValueType(-0.5) * Y4(p, q); } diff --git a/src/QMCWaveFunctions/RotatedSPOs.h b/src/QMCWaveFunctions/RotatedSPOs.h index dd5d33f1c9..d6a7ce7307 100644 --- a/src/QMCWaveFunctions/RotatedSPOs.h +++ b/src/QMCWaveFunctions/RotatedSPOs.h @@ -104,6 +104,12 @@ class RotatedSPOs : public SPOSet, public OptimizableObject const int& FirstIndex, const int& LastIndex) override; + void evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi, + int FirstIndex, + int LastIndex) override; + void evaluateDerivatives(ParticleSet& P, const opt_variables_type& optvars, Vector& dlogpsi, @@ -247,6 +253,17 @@ class RotatedSPOs : public SPOSet, public OptimizableObject Phi->evaluateDetRatios(VP, psi, psiinv, ratios); } + void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + ValueVector& psi, + const ValueVector& psiinv, + std::vector& ratios, + Matrix& dratios, + int FirstIndex, + int LastIndex) override; + void evaluateVGH(const ParticleSet& P, int iat, ValueVector& psi, diff --git a/src/QMCWaveFunctions/SPOSet.cpp b/src/QMCWaveFunctions/SPOSet.cpp index 60b719ddd3..77af4243e7 100644 --- a/src/QMCWaveFunctions/SPOSet.cpp +++ b/src/QMCWaveFunctions/SPOSet.cpp @@ -264,6 +264,39 @@ void SPOSet::evaluateDerivatives(ParticleSet& P, "must be overloaded when the SPOSet is optimizable."); } +void SPOSet::evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi, + int FirstIndex, + int LastIndex) +{ + if (isOptimizable()) + throw std::logic_error("Bug!! " + getClassName() + + "::evaluateDerivativesWF " + "must be overloaded when the SPOSet is optimizable."); +} + +void SPOSet::evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + ValueVector& psi, + const ValueVector& psiinv, + std::vector& ratios, + Matrix& dratios, + int FirstIndex, + int LastIndex) +{ + // Match the fallback in WaveFunctionComponent that evaluates just the ratios + evaluateDetRatios(VP, psi, psiinv, ratios); + + if (isOptimizable()) + throw std::logic_error("Bug!! " + getClassName() + + "::evaluateDerivRatios " + "must be overloaded when the SPOSet is optimizable."); +} + + /** Evaluate the derivative of the optimized orbitals with respect to the parameters * this is used only for MSD, to be refined for better serving both single and multi SD */ diff --git a/src/QMCWaveFunctions/SPOSet.h b/src/QMCWaveFunctions/SPOSet.h index d6f9c39e69..fa999ee2df 100644 --- a/src/QMCWaveFunctions/SPOSet.h +++ b/src/QMCWaveFunctions/SPOSet.h @@ -125,6 +125,7 @@ class SPOSet : public QMCTraits /// apply rotation to all the orbitals virtual void applyRotation(const ValueMatrix& rot_mat, bool use_stored_copy = false); + /// Parameter derivatives of the wavefunction and the Laplacian of the wavefunction virtual void evaluateDerivatives(ParticleSet& P, const opt_variables_type& optvars, Vector& dlogpsi, @@ -132,6 +133,13 @@ class SPOSet : public QMCTraits const int& FirstIndex, const int& LastIndex); + /// Parameter derivatives of the wavefunction + virtual void evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi, + int FirstIndex, + int LastIndex); + /** Evaluate the derivative of the optimized orbitals with respect to the parameters * this is used only for MSD, to be refined for better serving both single and multi SD */ @@ -206,6 +214,20 @@ class SPOSet : public QMCTraits const ValueVector& psiinv, std::vector& ratios); + + /// Determinant ratios and parameter derivatives of the wavefunction for virtual moves + virtual void evaluateDerivRatios(const VirtualParticleSet& VP, + ParticleSet& P, + int iel, + const opt_variables_type& optvars, + ValueVector& psi, + const ValueVector& psiinv, + std::vector& ratios, + Matrix& dratios, + int FirstIndex, + int LastIndex); + + /** evaluate determinant ratios for virtual moves, e.g., sphere move for nonlocalPP, of multiple walkers * @param spo_list the list of SPOSet pointers in a walker batch * @param vp_list a list of virtual particle sets in a walker batch From c1968ed0ebc86d17cf01f483c7a716b2803bd79f Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Wed, 18 Jan 2023 22:50:42 -0600 Subject: [PATCH 3/8] Add and update tests --- .../tests/test_RotatedSPOs_NLPP.cpp | 57 ++++++++++++++++++- .../tests/test_multi_slater_determinant.cpp | 2 +- .../tests/test_polynomial_eeI_jastrow.cpp | 2 +- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp index b703d28f01..636f081c66 100644 --- a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp +++ b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp @@ -35,7 +35,7 @@ namespace qmcplusplus // Copied and extended from QMCWaveFunctions/tests/test_RotatedSPOs.cpp -TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") +void test_hcpBe_rotation(bool use_single_det, bool use_nlpp_batched) { using RealType = QMCTraits::RealType; @@ -104,7 +104,7 @@ TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") WaveFunctionPool wp(pp, c); REQUIRE(wp.empty() == true); - const char* wf_input = R"( + const char* wf_input_multi_det = R"( @@ -121,6 +121,30 @@ TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") )"; + const char* wf_input_single_det = R"( + + + + + + + + + + + + + + + + + + )"; + + const char* wf_input = wf_input_multi_det; + if (use_single_det) + wf_input = wf_input_single_det; + Libxml2Document doc; bool okay = doc.parseFromString(wf_input); REQUIRE(okay); @@ -134,13 +158,23 @@ TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") // Note the pbc="no" setting to turn off long-range summation. - const char* ham_input = R"( + const char* ham_input_nlpp_nonbatched = R"( )"; + const char* ham_input_nlpp_batched = R"( + + + + + )"; + + const char* ham_input = ham_input_nlpp_nonbatched; + if (use_nlpp_batched) + ham_input = ham_input_nlpp_batched; HamiltonianFactory hf("h0", elec, pp.getPool(), wp.getPool(), c); @@ -237,4 +271,21 @@ TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") CHECK(dhpsi_over_psi_list2[0][1] == Approx(dhpsioverpsi2[1])); } +TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") +{ + SECTION("nlpp non-batched") + { + bool use_single_det = GENERATE(true, false); + bool use_nlpp_batched = false; + test_hcpBe_rotation(use_single_det, use_nlpp_batched); + } + + SECTION("nlpp non-batched") + { + bool use_single_det = true; + bool use_nlpp_batched = true; + test_hcpBe_rotation(use_single_det, use_nlpp_batched); + } +} + } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp b/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp index e9748f79b3..83ed48870a 100644 --- a/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp +++ b/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp @@ -182,7 +182,7 @@ void test_LiH_msd(const std::string& spo_xml_string, std::fill(ratios2.begin(), ratios2.end(), 0); Matrix dratio(2, nparam); - twf.evaluateDerivRatios(VP, active, ratios2, dratio); + twf.evaluateDerivRatios(VP, elec_, 1, active, ratios2, dratio); CHECK(std::real(ratios2[0]) == Approx(-0.8544310407)); CHECK(std::real(ratios2[1]) == Approx(-1.0830708458)); diff --git a/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp b/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp index 5d68ee257b..b109c485a2 100644 --- a/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp +++ b/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp @@ -196,7 +196,7 @@ void test_J3_polynomial3D(const DynamicCoordinateKind kind_selected) std::fill(ratios2.begin(), ratios2.end(), 0); Matrix dratio(2, NumOptimizables); - j3->evaluateDerivRatios(VP, optvars, ratios2, dratio); + j3->evaluateDerivRatios(VP, elec_, 1, optvars, ratios2, dratio); REQUIRE(std::real(ratios2[0]) == Approx(1.0357541137)); REQUIRE(std::real(ratios2[1]) == Approx(1.0257141422)); From fb2e6a844861e631227d401d0d42f9d8e59bbacb Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Thu, 19 Jan 2023 10:23:58 -0600 Subject: [PATCH 4/8] Fix section name --- src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp index 636f081c66..983ae27f1a 100644 --- a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp +++ b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp @@ -280,7 +280,7 @@ TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") test_hcpBe_rotation(use_single_det, use_nlpp_batched); } - SECTION("nlpp non-batched") + SECTION("nlpp batched") { bool use_single_det = true; bool use_nlpp_batched = true; From a5737cb222299b11c7f205dfdbadab5fd40ce710 Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Thu, 19 Jan 2023 15:56:30 -0600 Subject: [PATCH 5/8] Fix test name --- src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp index 983ae27f1a..516b5bbf99 100644 --- a/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp +++ b/src/QMCHamiltonians/tests/test_RotatedSPOs_NLPP.cpp @@ -271,7 +271,7 @@ void test_hcpBe_rotation(bool use_single_det, bool use_nlpp_batched) CHECK(dhpsi_over_psi_list2[0][1] == Approx(dhpsioverpsi2[1])); } -TEST_CASE("RotatedSPOs SplineR2R hcpBe values multi det", "[wavefunction]") +TEST_CASE("RotatedSPOs SplineR2R hcpBe values", "[wavefunction]") { SECTION("nlpp non-batched") { From 5b244528a60ae80c37329e2f7ce79b9f1a232785 Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Sun, 22 Jan 2023 23:14:05 -0600 Subject: [PATCH 6/8] Use data stored in VirtualParticleSet Use the reference particle set and the reference particle index rather than adding them as function arguments. --- src/QMCHamiltonians/NonLocalECPotential.deriv.cpp | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp | 4 +--- src/QMCWaveFunctions/Fermion/DiracDeterminant.h | 2 -- src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp | 2 -- src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h | 2 -- src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 4 +--- src/QMCWaveFunctions/Fermion/SlaterDet.h | 2 -- src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h | 2 -- src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h | 2 -- src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp | 2 -- src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h | 2 -- src/QMCWaveFunctions/RotatedSPOs.cpp | 5 +++-- src/QMCWaveFunctions/RotatedSPOs.h | 2 -- src/QMCWaveFunctions/SPOSet.cpp | 2 -- src/QMCWaveFunctions/SPOSet.h | 2 -- src/QMCWaveFunctions/TrialWaveFunction.cpp | 4 +--- src/QMCWaveFunctions/TrialWaveFunction.h | 2 -- src/QMCWaveFunctions/WaveFunctionComponent.cpp | 2 -- src/QMCWaveFunctions/WaveFunctionComponent.h | 2 -- src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp | 2 +- src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp | 2 +- 21 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp b/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp index 3206e49e85..1bd9559ced 100644 --- a/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp +++ b/src/QMCHamiltonians/NonLocalECPotential.deriv.cpp @@ -82,7 +82,7 @@ NonLocalECPComponent::RealType NonLocalECPComponent::evaluateValueAndDerivatives { // Compute ratios with VP VP->makeMoves(W, iel, deltaV, true, iat); - psi.evaluateDerivRatios(*VP, W, iel, optvars, psiratio, dratio); + psi.evaluateDerivRatios(*VP, optvars, psiratio, dratio); } else { diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index b94f300c80..11ea9b4faa 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -458,8 +458,6 @@ void DiracDeterminant::mw_evaluateRatios(const RefVectorWithLeader void DiracDeterminant::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) @@ -467,7 +465,7 @@ void DiracDeterminant::evaluateDerivRatios(const VirtualParticleSet& VP const int WorkingIndex = VP.refPtcl - FirstIndex; assert(WorkingIndex >= 0); std::copy_n(psiM[WorkingIndex], invRow.size(), invRow.data()); - Phi->evaluateDerivRatios(VP, P, iel, optvars, psiV, invRow, ratios, dratios, FirstIndex, LastIndex); + Phi->evaluateDerivRatios(VP, optvars, psiV, invRow, ratios, dratios, FirstIndex, LastIndex); } template diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index 5f88f20432..6aed806654 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -114,8 +114,6 @@ class DiracDeterminant : public DiracDeterminantBase std::vector>& ratios) const override; void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp index 41ff996f4d..a99dc72525 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.cpp @@ -1016,8 +1016,6 @@ void MultiSlaterDetTableMethod::evaluateDerivativesMSD(const PsiValueType& multi } void MultiSlaterDetTableMethod::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h index 266e30d605..b7a3fc7b82 100644 --- a/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h +++ b/src/QMCWaveFunctions/Fermion/MultiSlaterDetTableMethod.h @@ -189,8 +189,6 @@ class MultiSlaterDetTableMethod : public WaveFunctionComponent, public Optimizab Vector& dlogpsi) override; void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index e41cd7fac7..8b20e48a2d 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -89,13 +89,11 @@ void SlaterDet::evaluateRatiosAlltoOne(ParticleSet& P, std::vector& r } void SlaterDet::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) { - return Dets[getDetID(VP.refPtcl)]->evaluateDerivRatios(VP, P, iel, optvars, ratios, dratios); + return Dets[getDetID(VP.refPtcl)]->evaluateDerivRatios(VP, optvars, ratios, dratios); } SlaterDet::LogValueType SlaterDet::evaluateLog(const ParticleSet& P, diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index f7ccae05ec..deffe209c4 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -110,8 +110,6 @@ class SlaterDet : public WaveFunctionComponent } void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h index dff6d4f08b..0993bb7a26 100644 --- a/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/J1OrbitalSoA.h @@ -561,8 +561,6 @@ class J1OrbitalSoA : public WaveFunctionComponent /**@} */ void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override diff --git a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h index ac1c6b6bb2..3548c7ca0f 100644 --- a/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h +++ b/src/QMCWaveFunctions/Jastrow/JeeIOrbitalSoA.h @@ -948,8 +948,6 @@ class JeeIOrbitalSoA : public WaveFunctionComponent } void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override diff --git a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp index 5a6a9f6bd2..29aff99e3b 100644 --- a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp +++ b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.cpp @@ -969,8 +969,6 @@ void TwoBodyJastrow::evaluateDerivativesWF(ParticleSet& P, template void TwoBodyJastrow::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h index 940bc703ac..01301adcfa 100644 --- a/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h +++ b/src/QMCWaveFunctions/Jastrow/TwoBodyJastrow.h @@ -259,8 +259,6 @@ class TwoBodyJastrow : public WaveFunctionComponent void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& active, Vector& dlogpsi) override; void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios) override; diff --git a/src/QMCWaveFunctions/RotatedSPOs.cpp b/src/QMCWaveFunctions/RotatedSPOs.cpp index 1ea8a00bd2..622ae16840 100644 --- a/src/QMCWaveFunctions/RotatedSPOs.cpp +++ b/src/QMCWaveFunctions/RotatedSPOs.cpp @@ -307,8 +307,6 @@ void RotatedSPOs::log_antisym_matrix(ValueMatrix& mat) } void RotatedSPOs::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, ValueVector& psi, const ValueVector& psiinv, @@ -332,6 +330,9 @@ void RotatedSPOs::evaluateDerivRatios(const VirtualParticleSet& VP, dpsiM_all = 0; d2psiM_all = 0; + const ParticleSet& P = VP.getRefPS(); + int iel = VP.refPtcl; + Phi->evaluate_notranspose(P, FirstIndex, LastIndex, psiM_all, dpsiM_all, d2psiM_all); for (int i = 0; i < nel; i++) diff --git a/src/QMCWaveFunctions/RotatedSPOs.h b/src/QMCWaveFunctions/RotatedSPOs.h index d6a7ce7307..410d0c8e46 100644 --- a/src/QMCWaveFunctions/RotatedSPOs.h +++ b/src/QMCWaveFunctions/RotatedSPOs.h @@ -254,8 +254,6 @@ class RotatedSPOs : public SPOSet, public OptimizableObject } void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, ValueVector& psi, const ValueVector& psiinv, diff --git a/src/QMCWaveFunctions/SPOSet.cpp b/src/QMCWaveFunctions/SPOSet.cpp index 77af4243e7..ca594799f4 100644 --- a/src/QMCWaveFunctions/SPOSet.cpp +++ b/src/QMCWaveFunctions/SPOSet.cpp @@ -277,8 +277,6 @@ void SPOSet::evaluateDerivativesWF(ParticleSet& P, } void SPOSet::evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, ValueVector& psi, const ValueVector& psiinv, diff --git a/src/QMCWaveFunctions/SPOSet.h b/src/QMCWaveFunctions/SPOSet.h index fa999ee2df..efa6476d8e 100644 --- a/src/QMCWaveFunctions/SPOSet.h +++ b/src/QMCWaveFunctions/SPOSet.h @@ -217,8 +217,6 @@ class SPOSet : public QMCTraits /// Determinant ratios and parameter derivatives of the wavefunction for virtual moves virtual void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, ValueVector& psi, const ValueVector& psiinv, diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 712739d601..0fafb2263d 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1037,8 +1037,6 @@ void TrialWaveFunction::mw_evaluateRatios(const RefVectorWithLeader& ratios, Matrix& dratio) @@ -1049,7 +1047,7 @@ void TrialWaveFunction::evaluateDerivRatios(const VirtualParticleSet& VP, for (int i = 0; i < Z.size(); ++i) { ScopedTimer z_timer(WFC_timers_[DERIVS_TIMER + TIMER_SKIP * i]); - Z[i]->evaluateDerivRatios(VP, P, iel, optvars, t, dratio); + Z[i]->evaluateDerivRatios(VP, optvars, t, dratio); for (int j = 0; j < ratios.size(); ++j) ratios[j] *= t[j]; } diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 50b2f5b577..a969a8df33 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -313,8 +313,6 @@ class TrialWaveFunction /** compute both ratios and deriatives of ratio with respect to the optimizables*/ void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratio); diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index 621a8a0784..0853e9916f 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -248,8 +248,6 @@ void WaveFunctionComponent::mw_evaluateRatios(const RefVectorWithLeader& ratios, Matrix& dratios) diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 3c90df4c33..3df3d82cc8 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -533,8 +533,6 @@ class WaveFunctionComponent : public QMCTraits * @param dratios Nq x Num_param matrix. \f$\partial_{\alpha}(\ln \Psi ({\bf R}^{\prime}) - \ln \Psi ({\bf R})) \f$ */ virtual void evaluateDerivRatios(const VirtualParticleSet& VP, - ParticleSet& P, - int iel, const opt_variables_type& optvars, std::vector& ratios, Matrix& dratios); diff --git a/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp b/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp index 83ed48870a..e9748f79b3 100644 --- a/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp +++ b/src/QMCWaveFunctions/tests/test_multi_slater_determinant.cpp @@ -182,7 +182,7 @@ void test_LiH_msd(const std::string& spo_xml_string, std::fill(ratios2.begin(), ratios2.end(), 0); Matrix dratio(2, nparam); - twf.evaluateDerivRatios(VP, elec_, 1, active, ratios2, dratio); + twf.evaluateDerivRatios(VP, active, ratios2, dratio); CHECK(std::real(ratios2[0]) == Approx(-0.8544310407)); CHECK(std::real(ratios2[1]) == Approx(-1.0830708458)); diff --git a/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp b/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp index b109c485a2..5d68ee257b 100644 --- a/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp +++ b/src/QMCWaveFunctions/tests/test_polynomial_eeI_jastrow.cpp @@ -196,7 +196,7 @@ void test_J3_polynomial3D(const DynamicCoordinateKind kind_selected) std::fill(ratios2.begin(), ratios2.end(), 0); Matrix dratio(2, NumOptimizables); - j3->evaluateDerivRatios(VP, elec_, 1, optvars, ratios2, dratio); + j3->evaluateDerivRatios(VP, optvars, ratios2, dratio); REQUIRE(std::real(ratios2[0]) == Approx(1.0357541137)); REQUIRE(std::real(ratios2[1]) == Approx(1.0257141422)); From edb11bcde57afc382c1386b9fbf4f63077f43800 Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Mon, 23 Jan 2023 12:00:15 -0600 Subject: [PATCH 7/8] Enable NLPP parameter derivatives in batched code Add evaluateDerivativesWF to DiracDeterminantBatched --- src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp | 8 ++++++++ src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp index cbb0e09f50..b1c608c929 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp @@ -1108,6 +1108,14 @@ void DiracDeterminantBatched::evaluateDerivatives(ParticleSet& P, Phi->evaluateDerivatives(P, active, dlogpsi, dhpsioverpsi, FirstIndex, LastIndex); } +template +void DiracDeterminantBatched::evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& active, + Vector& dlogpsi) +{ + Phi->evaluateDerivativesWF(P, active, dlogpsi, FirstIndex, LastIndex); +} + template void DiracDeterminantBatched::registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h index bc2ec90039..a770a82565 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h @@ -103,6 +103,10 @@ class DiracDeterminantBatched : public DiracDeterminantBase Vector& dlogpsi, Vector& dhpsioverpsi) override; + void evaluateDerivativesWF(ParticleSet& P, + const opt_variables_type& optvars, + Vector& dlogpsi) override; + void registerData(ParticleSet& P, WFBufferType& buf) override; LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override; From e24eb3a777194670ed5d1edb3856c1590df7d141 Mon Sep 17 00:00:00 2001 From: Mark Dewing Date: Mon, 23 Jan 2023 12:52:54 -0600 Subject: [PATCH 8/8] Enable Hamiltonian NLPP derivatives in batched code Add evaluateDerivRatios to DiracDeterminantBatched --- .../Fermion/DiracDeterminantBatched.cpp | 17 ++++++++++++++--- .../Fermion/DiracDeterminantBatched.h | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp index b1c608c929..73f845a1b3 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp @@ -815,6 +815,18 @@ void DiracDeterminantBatched::mw_evaluateRatios( } } +template +void DiracDeterminantBatched::evaluateDerivRatios(const VirtualParticleSet& VP, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) +{ + const int WorkingIndex = VP.refPtcl - FirstIndex; + assert(WorkingIndex >= 0); + std::copy_n(det_engine_.get_psiMinv()[WorkingIndex], d2psiV.size(), d2psiV.data()); + Phi->evaluateDerivRatios(VP, optvars, psiV_host_view, d2psiV_host_view, ratios, dratios, FirstIndex, LastIndex); +} + template void DiracDeterminantBatched::evaluateRatiosAlltoOne(ParticleSet& P, std::vector& ratios) { @@ -827,7 +839,6 @@ void DiracDeterminantBatched::evaluateRatiosAlltoOne(ParticleSet& P, ratios[FirstIndex + i] = simd::dot(psiMinv[i], psiV.data(), NumOrbitals); } - template void DiracDeterminantBatched::resizeScratchObjectsForIonDerivs() { @@ -1110,8 +1121,8 @@ void DiracDeterminantBatched::evaluateDerivatives(ParticleSet& P, template void DiracDeterminantBatched::evaluateDerivativesWF(ParticleSet& P, - const opt_variables_type& active, - Vector& dlogpsi) + const opt_variables_type& active, + Vector& dlogpsi) { Phi->evaluateDerivativesWF(P, active, dlogpsi, FirstIndex, LastIndex); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h index a770a82565..703b4a2d61 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h @@ -132,6 +132,11 @@ class DiracDeterminantBatched : public DiracDeterminantBase const RefVectorWithLeader& vp_list, std::vector>& ratios) const override; + void evaluateDerivRatios(const VirtualParticleSet& VP, + const opt_variables_type& optvars, + std::vector& ratios, + Matrix& dratios) override; + PsiValue ratioGrad(ParticleSet& P, int iat, Grad& grad_iat) override; void mw_ratioGrad(const RefVectorWithLeader& wfc_list,