From fade634cd1e73266d6e364ec59b44bc30d3c1a07 Mon Sep 17 00:00:00 2001 From: rcclay Date: Tue, 21 Dec 2021 14:33:27 -0700 Subject: [PATCH 01/20] Initial commit of TWFPrototype class --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 3 +- src/QMCWaveFunctions/TWFPrototype.cpp | 316 ++++++++++++++++++ src/QMCWaveFunctions/TWFPrototype.h | 99 ++++++ 3 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 src/QMCWaveFunctions/TWFPrototype.cpp create mode 100644 src/QMCWaveFunctions/TWFPrototype.h diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index f5b0726aa..8795a4a36 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -20,6 +20,7 @@ #include "QMCHamiltonians/tests/MinimalHamiltonianPool.h" #include "ParticleIO/XMLParticleIO.h" #include "Utilities/RandomGenerator.h" +#include "QMCWaveFunctions/TWFPrototype.h" namespace qmcplusplus { @@ -769,7 +770,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") REQUIRE(psi != nullptr); //end incantation -// TWFPrototype twf; + TWFPrototype twf; // psi->initialize_TWF_Prototype(elec, twf); SPOSet::ValueVector_t values; diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp new file mode 100644 index 000000000..68b550410 --- /dev/null +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -0,0 +1,316 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2021 QMCPACK developers. +// +// File developed by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories +// +// File created by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories +////////////////////////////////////////////////////////////////////////////////////// + +#include "QMCWaveFunctions/TWFPrototype.h" +#include "Numerics/DeterminantOperators.h" +#include +namespace qmcplusplus +{ +TWFPrototype::TWFPrototype() : initialized(false) { std::cout << "TWFPrototype Constructed\n"; } + +TWFPrototype::IndexType TWFPrototype::get_group_index(const IndexType gid) +{ + IndexType ndets = groups.size(); + for (IndexType i = 0; i < ndets; i++) + if (gid == groups[i]) + return i; + + return IndexType(-1); +} +void TWFPrototype::add_determinant(const ParticleSet& P, const IndexType gid, SPOSet* spo) +{ + if (std::find(groups.begin(), groups.end(), gid) == groups.end()) + { + groups.push_back(gid); + spos.push_back(spo); + IndexType first = P.first(gid); + IndexType last = P.last(gid); + IndexType norbs = spo->getOrbitalSetSize(); + num_orbs.push_back(norbs); + num_ptcls.push_back(last - first); + } + initialized = true; +} + +TWFPrototype::IndexType TWFPrototype::get_det_id(const IndexType species_id) +{ + IndexType detIndex = -1; + for (IndexType i = 0; i < groups.size(); i++) + { + if (species_id == groups[i]) + detIndex = i; + } + assert(detIndex != -1); + + return detIndex; +} + +void TWFPrototype::get_M(const ParticleSet& P, std::vector& mvec) +{ + IndexType ndets = spos.size(); + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; + for (IndexType i = 0; i < ndets; i++) + { + gid = groups[i]; + first = P.first(i); + last = P.last(i); + nptcls = last - first; + norbs = spos[i]->getOrbitalSetSize(); + mvec[i] = 0; + GradMatrix_t tmpgmat; + ValueMatrix_t tmplmat; + tmpgmat.resize(nptcls, norbs); + tmplmat.resize(nptcls, norbs); + spos[i]->evaluate_notranspose(P, first, last, mvec[i], tmpgmat, tmplmat); + } +} + +void TWFPrototype::get_egrad_elapl_M(const ParticleSet& P, + std::vector& mvec, + std::vector& gmat, + std::vector& lmat) +{ + IndexType ndets = mvec.size(); + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; + for (IndexType i = 0; i < ndets; i++) + { + gid = groups[i]; + first = P.first(i); + last = P.last(i); + nptcls = last - first; + norbs = spos[i]->getOrbitalSetSize(); + mvec[i] = 0; + gmat[i] = 0; + lmat[i] = 0; + spos[i]->evaluate_notranspose(P, first, last, mvec[i], gmat[i], lmat[i]); + } +} + +void TWFPrototype::get_igrad_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec) +{ + IndexType ndets = dmvec[0].size(); + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; + for (IndexType i = 0; i < ndets; i++) + { + gid = groups[i]; + first = P.first(i); + last = P.last(i); + nptcls = last - first; + norbs = spos[i]->getOrbitalSetSize(); + + GradMatrix_t grad_phi; + + grad_phi.resize(nptcls, norbs); + + spos[i]->evaluateGradSource(P, first, last, source, iat, grad_phi); + + for (IndexType idim = 0; idim < OHMMS_DIM; idim++) + for (IndexType iptcl = 0; iptcl < nptcls; iptcl++) + for (IndexType iorb = 0; iorb < norbs; iorb++) + { + dmvec[idim][i][iptcl][iorb] += grad_phi[iptcl][iorb][idim]; + } + } +} + +void TWFPrototype::get_igrad_igradelapl_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec, + std::vector>& dlmat) +{ + IndexType ndets = dmvec[0].size(); + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; + for (IndexType i = 0; i < ndets; i++) + { + gid = groups[i]; + first = P.first(i); + last = P.last(i); + nptcls = last - first; + norbs = spos[i]->getOrbitalSetSize(); + + GradMatrix_t grad_phi; + HessMatrix_t grad_grad_phi; + GradMatrix_t grad_lapl_phi; + + grad_phi.resize(nptcls, norbs); + grad_grad_phi.resize(nptcls, norbs); + grad_lapl_phi.resize(nptcls, norbs); + + spos[i]->evaluateGradSource(P, first, last, source, iat, grad_phi, grad_grad_phi, grad_lapl_phi); + + for (IndexType idim = 0; idim < OHMMS_DIM; idim++) + for (IndexType iptcl = 0; iptcl < nptcls; iptcl++) + for (IndexType iorb = 0; iorb < norbs; iorb++) + { + dmvec[idim][i][iptcl][iorb] += grad_phi[iptcl][iorb][idim]; + dlmat[idim][i][iptcl][iorb] += grad_lapl_phi[iptcl][iorb][idim]; + } + } +} + +TWFPrototype::ValueType TWFPrototype::compute_gs_derivative(const std::vector& Minv, + const std::vector& X, + const std::vector& dM, + const std::vector& dB) +{ + IndexType nspecies = num_species(); + ValueType dval = 0.0; + for (int id = 0; id < nspecies; id++) + { + int ptclnum = num_particles(id); + ValueType dval_id = 0.0; + for (int i = 0; i < ptclnum; i++) + for (int j = 0; j < ptclnum; j++) + { + //Tr[M^{-1} dB - X * dM ] + dval_id += Minv[id][i][j] * dB[id][j][i] - X[id][i][j] * dM[id][j][i]; + } + dval += dval_id; + } + return dval; +} + +void TWFPrototype::invert_M(const std::vector& M, std::vector& Minv) +{ + IndexType nspecies = num_species(); + for (IndexType id = 0; id < nspecies; id++) + { + assert(M[id].cols() == M[id].rows()); + Minv[id] = M[id]; + invert_matrix(Minv[id]); + } +} + +void TWFPrototype::build_X(const std::vector& Minv, + const std::vector& B, + std::vector& X) +{ + IndexType nspecies = num_species(); + + for (IndexType id = 0; id < nspecies; id++) + { + int ptclnum = num_particles(id); + ValueMatrix_t tmpmat; + X[id].resize(ptclnum, ptclnum); + tmpmat.resize(ptclnum, ptclnum); + //(B*A^-1) + for (int i = 0; i < ptclnum; i++) + for (int j = 0; j < ptclnum; j++) + for (int k = 0; k < ptclnum; k++) + { + tmpmat[i][j] += B[id][i][k] * Minv[id][k][j]; + } + //A^{-1}*B*A^{-1} + for (int i = 0; i < ptclnum; i++) + for (int j = 0; j < ptclnum; j++) + for (int k = 0; k < ptclnum; k++) + { + X[id][i][j] += Minv[id][i][k] * tmpmat[k][j]; + } + } +} + +void TWFPrototype::wipe_matrix(std::vector& A) +{ + IndexType nspecies = num_species(); + + for (IndexType id = 0; id < nspecies; id++) + { + A[id] = 0.0; + } +} + +TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, const std::vector& B) +{ + IndexType nspecies = num_species(); + ValueType val = 0.0; + //Now to compute the kinetic energy + for (IndexType id = 0; id < nspecies; id++) + { + int ptclnum = num_particles(id); + ValueType val_id = 0.0; + assert(A[id].cols() == B[id].rows() && A[id].rows() == B[id].cols()); + for (int i = 0; i < A[id].rows(); i++) + for (int j = 0; j < A[id].cols(); j++) + { + val_id += A[id][i][j] * B[id][j][i]; + } + val += val_id; + } + + return val; +} + +void TWFPrototype::get_gs_matrix(const std::vector& A, std::vector& Aslice) +{ + IndexType nspecies = num_species(); + Aslice.resize(nspecies); + for (IndexType id = 0; id < nspecies; id++) + { + IndexType ptclnum = num_particles(id); + Aslice[id].resize(ptclnum, ptclnum); + for (IndexType i = 0; i < ptclnum; i++) + for (IndexType j = 0; j < ptclnum; j++) + Aslice[id][i][j] = A[id][i][j]; + } +} + +TWFPrototype::IndexType TWFPrototype::get_igrad_row(const ParticleSet& P, + const ParticleSet& source, + IndexType iel, + IndexType iat_source, + std::vector& dval) +{ + return -1; +} + +TWFPrototype::IndexType TWFPrototype::get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val) +{ + IndexType gid = P.getGroupID(iel); + IndexType detIndex = get_det_id(gid); + + GradVector_t tempg; + ValueVector_t templ; + + IndexType norbs = spos[detIndex]->getOrbitalSetSize(); + + tempg.resize(norbs); + templ.resize(norbs); + + spos[detIndex]->evaluateVGL(P, iel, val, tempg, templ); + + return detIndex; +} + + +TWFPrototype::RealType TWFPrototype::evaluateLog(ParticleSet& P) { return 0; } + +} // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h new file mode 100644 index 000000000..9344bc4c3 --- /dev/null +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -0,0 +1,99 @@ +////////////////////////////////////////////////////////////////////////////////////// +// This file is distributed under the University of Illinois/NCSA Open Source License. +// See LICENSE file in top directory for details. +// +// Copyright (c) 2021 QMCPACK developers. +// +// File developed by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories +// +// File created by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories +////////////////////////////////////////////////////////////////////////////////////// + + +/**@file TWFPrototype.h + *@brief Declaration of TWFPrototype + */ +#ifndef QMCPLUSPLUS_TWFPROTOTYPE_H +#define QMCPLUSPLUS_TWFPROTOTYPE_H + +#include "QMCWaveFunctions/WaveFunctionComponent.h" +#include "QMCWaveFunctions/SPOSet.h" +#include "Configuration.h" +#include "Particle/ParticleSet.h" +namespace qmcplusplus +{ +class TWFPrototype +{ +public: + using ValueMatrix_t = SPOSet::ValueMatrix_t; + using GradMatrix_t = SPOSet::GradMatrix_t; + using HessMatrix_t = SPOSet::HessMatrix_t; + using IndexType = QMCTraits::IndexType; + using RealType = QMCTraits::RealType; + using ValueType = QMCTraits::ValueType; + + using ValueVector_t = SPOSet::ValueVector_t; + using GradVector_t = SPOSet::GradVector_t; + + TWFPrototype(); + void add_determinant(const ParticleSet& P, const IndexType groupid, SPOSet* spo); + inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; + + void get_M(const ParticleSet& P, std::vector& mmat); + IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); + IndexType get_igrad_row(const ParticleSet& P, + const ParticleSet& source, + IndexType iel, + IndexType iat_source, + std::vector& dval); + void get_egrad_elapl_M(const ParticleSet& P, + std::vector& mvec, + std::vector& gmat, + std::vector& lmat); + void get_igrad_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec); + void get_igrad_igradelapl_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec, + std::vector>& dlmat); + ValueType compute_gs_derivative(const std::vector& Minv, + const std::vector& X, + const std::vector& dM, + const std::vector& dB); + void invert_M(const std::vector& M, std::vector& Minv); + void get_gs_matrix(const std::vector& A, std::vector& Aslice); + void build_X(const std::vector& Minv, + const std::vector& B, + std::vector& X); + void wipe_matrix(std::vector& A); + ValueType trAB(const std::vector& A, const std::vector& B); + SPOSet* get_sposet(const IndexType sid) { return spos[sid]; }; + RealType evaluateLog(ParticleSet& P); + + //Whatever the group is labelled as in the particle set, sid corresponds to the group used to create determinant sid. + // so sid=4 returns the number of particles and orbitals used for det #4. Assuming a multispecies determinantal wfn like + // Prod_i Det(M_i). + inline IndexType num_orbitals(const IndexType sid) { return num_orbs[sid]; }; + inline IndexType num_particles(const IndexType sid) { return num_ptcls[sid]; }; + inline IndexType num_species() { return spos.size(); }; + IndexType get_det_id(const IndexType speciesid); + //This takes a particle set group index, and returns the "determinant" this refers to. + IndexType get_group_index(const IndexType gid); + bool initialized; + +private: + std::vector num_ptcls; + std::vector num_orbs; + std::vector spos; + std::vector groups; + std::vector psiM; + std::vector psiMinv; + std::vector J; +}; + +/**@}*/ +} // namespace qmcplusplus +#endif From c63e3d5c06d6b126ae6992e2429f4e97e37d583b Mon Sep 17 00:00:00 2001 From: rcclay Date: Tue, 4 Jan 2022 15:07:48 -0700 Subject: [PATCH 02/20] Add TWFPrototype to cmake --- src/QMCWaveFunctions/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/QMCWaveFunctions/CMakeLists.txt b/src/QMCWaveFunctions/CMakeLists.txt index 8bd64494e..79eb4b1b1 100644 --- a/src/QMCWaveFunctions/CMakeLists.txt +++ b/src/QMCWaveFunctions/CMakeLists.txt @@ -169,6 +169,7 @@ set(FERMION_SRCS SPOSetBuilderFactory.cpp TrialWaveFunction.cpp TWFdispatcher.cpp + TWFPrototype.cpp WaveFunctionFactory.cpp) if(ENABLE_CUDA) From 0ec1241659070df2dd38bfb66feef4d21b2b7f03 Mon Sep 17 00:00:00 2001 From: rcclay Date: Wed, 5 Jan 2022 14:02:26 -0700 Subject: [PATCH 03/20] Allow inititalization of wrapper for slater determinant wave functions --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 4 ++-- src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp | 7 +++++++ src/QMCWaveFunctions/Fermion/DiracDeterminant.h | 4 ++++ .../Fermion/DiracDeterminantBase.h | 4 ++++ src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 8 ++++++++ src/QMCWaveFunctions/Fermion/SlaterDet.h | 4 ++++ src/QMCWaveFunctions/TWFPrototype.h | 2 +- src/QMCWaveFunctions/TrialWaveFunction.cpp | 15 +++++++++++++++ src/QMCWaveFunctions/TrialWaveFunction.h | 6 ++++++ src/QMCWaveFunctions/WaveFunctionComponent.cpp | 7 +++++++ src/QMCWaveFunctions/WaveFunctionComponent.h | 7 ++++++- 11 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index 8795a4a36..e9081e46f 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -772,7 +772,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") TWFPrototype twf; -// psi->initialize_TWF_Prototype(elec, twf); + psi->initialize_TWF_Prototype(elec, twf); SPOSet::ValueVector_t values; SPOSet::GradVector_t dpsi; SPOSet::ValueVector_t d2psi; @@ -837,7 +837,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") X.push_back(upmat); X.push_back(dnmat); -// twf.get_M(elec, matlist); + twf.get_M(elec, matlist); OperatorBase* kinop = ham.getHamiltonian(KINETIC); diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 9d3d0ce75..7c3922a38 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -21,6 +21,7 @@ #include "CPU/SIMD/simd.hpp" #include "Numerics/DeterminantOperators.h" #include "Numerics/MatrixOperators.h" +#include "QMCWaveFunctions/TWFPrototype.h" namespace qmcplusplus { @@ -344,6 +345,12 @@ void DiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf updateEng.initializeInv(psiM); } +template +void DiracDeterminant::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +{ + twf.add_determinant(P, P.getGroupID(FirstIndex), Phi.get()); +} + /** return the ratio only for the iat-th partcle move * @param P current configuration * @param iat the particle thas is being moved diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index b5a2bb317..aee575452 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -76,6 +76,10 @@ public: void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override; + /** Finds the SPOSet associated with this determinant, and registers it with WFN wrapper + */ + void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) final; + /** return the ratio only for the iat-th partcle move * @param P current configuration * @param iat the particle thas is being moved diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h index 703e22b1a..baeb19024 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h @@ -85,6 +85,10 @@ public: inline void reportStatus(std::ostream& os) final {} + virtual void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) override + { + APP_ABORT("DiracDeterminantBase::register_TWF_Prototype must be overridden\n"); + } // expose CPU interfaces using WaveFunctionComponent::evaluateDerivatives; using WaveFunctionComponent::evaluateGL; diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index 8a2a1bc51..21d3d8bb3 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -253,4 +253,12 @@ std::unique_ptr SlaterDet::makeClone(ParticleSet& tqp) co return myclone; } +void SlaterDet::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +{ + for (int i = 0; i < Dets.size(); ++i) + { + Dets[i]->register_TWF_Prototype(P, twf); + } +} + } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index e72337dd4..566535958 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -18,6 +18,7 @@ #ifndef QMCPLUSPLUS_SLATERDETERMINANT_WITHBASE_H #define QMCPLUSPLUS_SLATERDETERMINANT_WITHBASE_H #include "QMCWaveFunctions/Fermion/DiracDeterminantBase.h" + #include namespace qmcplusplus @@ -28,6 +29,7 @@ namespace qmcplusplus // then change SlaterDet to SlaterDet // and SlaterDeterminantWithBackflow to SlaterDet // and remove all virtuals and inline them +class TWFPrototype; class SlaterDet : public WaveFunctionComponent { @@ -53,6 +55,8 @@ public: void reportStatus(std::ostream& os) override; + void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) override; + LogValueType evaluateLog(const ParticleSet& P, ParticleSet::ParticleGradient_t& G, ParticleSet::ParticleLaplacian_t& L) override; diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index 9344bc4c3..ca49e9db5 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -37,7 +37,7 @@ public: TWFPrototype(); void add_determinant(const ParticleSet& P, const IndexType groupid, SPOSet* spo); - inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; + //inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; void get_M(const ParticleSet& P, std::vector& mmat); IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index e498b9ace..9919420d4 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1248,5 +1248,20 @@ RefVector TrialWaveFunction::extractLRefList( return l_list; } +void TrialWaveFunction::initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +{ + for (int i = 0; i < Z.size(); ++i) + { + if (Z[i]->is_fermionic) + { + //OK, so this is a hack only for SlaterDeterminant objects. + //Needs a bit of logic and protection before this reaches production. + //SlaterDet* det = dynamic_cast(Z[i].get()); + //det->register_TWF_Prototype(P, twf); + } + else //Is Jastrow, so do nothing right now. + {} + } +} } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 71f1476d1..aa8eaff87 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -29,6 +29,7 @@ #include "Utilities/TimerManager.h" #include "type_traits/template_types.hpp" #include "Containers/MinimalContainers/RecordArray.hpp" +#include "QMCWaveFunctions/TWFPrototype.h" #ifdef QMC_CUDA #include "type_traits/CUDATypes.h" #endif @@ -168,6 +169,9 @@ public: */ void reportStatus(std::ostream& os); + /** Initialize a TWF wrapper for fast derivative evaluation + */ + void initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& twf); /** evalaute the log (internally gradients and laplacian) of the trial wavefunction. gold reference */ RealType evaluateLog(ParticleSet& P); @@ -517,6 +521,8 @@ private: ///a list of WaveFunctionComponents constituting many-body wave functions std::vector> Z; + /// For now, TrialWaveFunction will own the wrapper. + TWFPrototype twf_prototype; /// timers at TrialWaveFunction function call level TimerList_t TWF_timers_; /// timers at WaveFunctionComponent function call level diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index a9263db81..ca3dca08d 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -226,4 +226,11 @@ void WaveFunctionComponent::evaluateDerivRatios(VirtualParticleSet& VP, evaluateRatios(VP, ratios); } +void WaveFunctionComponent::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +{ + std::ostringstream o; + o << "WaveFunctionComponent::register_TWF_Prototype is not implemented by " << ClassName; + APP_ABORT(o.str()); +} + } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 3e9f0ae5f..11635aa25 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -50,7 +50,7 @@ struct NLjob class WaveFunctionComponent; struct DiffWaveFunctionComponent; class ResourceCollection; - +class TWFPrototype; /**@defgroup WaveFunctionComponent group * @brief Classes which constitute a many-body trial wave function * @@ -170,6 +170,11 @@ public: /** print the state, e.g., optimizables */ virtual void reportStatus(std::ostream& os) = 0; + /** Register the component with the TWFPrototype wrapper. Pure virtual, so will throw + * an error at compile time + */ + virtual void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf); + /** evaluate the value of the WaveFunctionComponent from scratch * \param[in] P active ParticleSet * \param[out] G Gradients, \f$\nabla\ln\Psi\f$ From 0e6a7ccb31c843e7d403792e2856a6e838331791 Mon Sep 17 00:00:00 2001 From: rcclay Date: Thu, 6 Jan 2022 11:50:43 -0700 Subject: [PATCH 04/20] Add documentation --- src/QMCWaveFunctions/TWFPrototype.h | 196 +++++++++++++++++---- src/QMCWaveFunctions/TrialWaveFunction.cpp | 1 + 2 files changed, 161 insertions(+), 36 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index ca49e9db5..1fc187bb1 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -22,6 +22,14 @@ #include "Particle/ParticleSet.h" namespace qmcplusplus { +/** + * TWFPrototype is a wrapper class for TrialWavefunction that provides separate and low level access to the Jastrow and + * SPOSet objects. This is so that observables can be recast in matrix form and their derivatives taken efficiently. + * Currently this is hard coded for ground state slater jastrow wave functions, but generalization to + * arbitrary occupations and multideterminants are straightforward and will come online as the code is tested and validated. + * + * Please see : J. Chem. Phys. 144, 194105 (2016) https://doi.org/10.1063/1.4948778 for implementation details and formalism. + */ class TWFPrototype { public: @@ -37,41 +45,7 @@ public: TWFPrototype(); void add_determinant(const ParticleSet& P, const IndexType groupid, SPOSet* spo); - //inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; - - void get_M(const ParticleSet& P, std::vector& mmat); - IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); - IndexType get_igrad_row(const ParticleSet& P, - const ParticleSet& source, - IndexType iel, - IndexType iat_source, - std::vector& dval); - void get_egrad_elapl_M(const ParticleSet& P, - std::vector& mvec, - std::vector& gmat, - std::vector& lmat); - void get_igrad_M(const ParticleSet& P, - const ParticleSet& source, - int iat, - std::vector>& dmvec); - void get_igrad_igradelapl_M(const ParticleSet& P, - const ParticleSet& source, - int iat, - std::vector>& dmvec, - std::vector>& dlmat); - ValueType compute_gs_derivative(const std::vector& Minv, - const std::vector& X, - const std::vector& dM, - const std::vector& dB); - void invert_M(const std::vector& M, std::vector& Minv); - void get_gs_matrix(const std::vector& A, std::vector& Aslice); - void build_X(const std::vector& Minv, - const std::vector& B, - std::vector& X); - void wipe_matrix(std::vector& A); - ValueType trAB(const std::vector& A, const std::vector& B); - SPOSet* get_sposet(const IndexType sid) { return spos[sid]; }; - RealType evaluateLog(ParticleSet& P); + inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; //Whatever the group is labelled as in the particle set, sid corresponds to the group used to create determinant sid. // so sid=4 returns the number of particles and orbitals used for det #4. Assuming a multispecies determinantal wfn like @@ -82,7 +56,155 @@ public: IndexType get_det_id(const IndexType speciesid); //This takes a particle set group index, and returns the "determinant" this refers to. IndexType get_group_index(const IndexType gid); - bool initialized; + SPOSet* get_sposet(const IndexType sid) { return spos[sid]; }; + + /** @brief Returns log(Psi). Should be consistent with QMCPACK unwrapped TrialWavefunction. + * + * @param P. Particle set. + * @return log(Psi). + */ + RealType evaluateLog(ParticleSet& P); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + //These are convenience functions/wrappers to SPOSet calls. Idea being that observables just need // + //to make calls to this object to build the auxiliary matrices required for fast derivative computation.// + //On the other hand, it wouldn't be unreasonable to make the observables do the SPOSet calls themselves.// + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** @brief Returns the non-rectangular slater matrices M_ij=phi_j(r_i) (N_particle x N_orbs) for each species group. + * + * @param P particle set. + * @param mmat Output vector of slater matrices. Each vector entry corresponds to a different particle group. + * @return Void + */ + void get_M(const ParticleSet& P, std::vector& mmat); + + /** @brief Returns value of all orbitals (relevant to given species/group) at a particular particle coordinate. + * + * @param P particle set. + * @param iel particle ID. + * @param val Vector of phi_i(r_iel) for all i=0,Norbs. + * @return Void + */ + IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); + + /** @brief Returns the ion derivative of all orbitals (relevant to given species/group) at a particular particle coordinate. + * + * @param P particle set. + * @param source ion particle set. + * @param iel particle ID. + * @param iat_source ion index w.r.t. which the ion derivative is taken + * @param dval Vector of d/dR_iat_source phi_i(r_iel) for all i=0,Norbs. First index is X derivative, second Y derivative, etc. + * @return Void + */ + IndexType get_igrad_row(const ParticleSet& P, + const ParticleSet& source, + IndexType iel, + IndexType iat_source, + std::vector& dval); + + /** @brief Returns value, gradient, and laplacian matrices for all orbitals and all particles, species by species. + * + * @param P particle set. + * @param mvec Slater matrix M_ij=phi_j(r_i) for each species group. + * @param gmat electron gradient of slater matrix [G_ij]_a = d/dr_a,i phi_j(r_i). a=x,y,z + * @param lmat electron laplacian of slater matrix [L_ij] = \nabla^2_i phi_j(r_i). + * @return Void + */ + void get_egrad_elapl_M(const ParticleSet& P, + std::vector& mvec, + std::vector& gmat, + std::vector& lmat); + + /** @brief Returns x,y,z components of ion gradient of slater matrices. + * + * @param P particle set. + * @param source ion particle set. + * @param iat ion ID w.r.t. which to take derivative. + * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. + * @return Void + */ + void get_igrad_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec); + + /** @brief Returns x,y,z components of ion gradient of slater matrices and their laplacians.. + * + * @param P particle set. + * @param source ion particle set. + * @param iat ion ID w.r.t. which to take derivative. + * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. + * @param dmvec Slater matrix d/dR_{iat,a} L_ij=d/dR_{iat,a} \nabla^2_i phi_j(r_i) for each species group. First index is a=x,y,z. + * @return Void + */ + void get_igrad_igradelapl_M(const ParticleSet& P, + const ParticleSet& source, + int iat, + std::vector>& dmvec, + std::vector>& dlmat); + + + /** @brief Takes sub matrices of full SPOSet quantities (evaluated on all particles and all orbitals), consistent with ground + * state occupations. + * + * @param A non-rectangular matrices of SPOSet derived quantities, evaluated on all orbitals and all particles. + * @param Aslice square matrices consistent with a ground state occupation. + * @return Void + */ + void get_gs_matrix(const std::vector& A, std::vector& Aslice); + + /** @brief Calculates derivative of observable via Tr[M^{-1} dB - X * dM ]. Consistent with ground state occupation. + * + * @param Minv. inverse of slater matrices for ground state occupations. + * @param X. X=M^-1 B M^-1. B observable matrix, and is consistent with ground state occupation. + * @param dM. Target derivative of M, and is consistent with ground state occupation. + * @param dB. Target derivative of B, and is consistent with ground state occupation. + * @return Void + */ + ValueType compute_gs_derivative(const std::vector& Minv, + const std::vector& X, + const std::vector& dM, + const std::vector& dB); + + ////////////////////////////////////////////////////////////////////////////////////////////// + //And now we just have some helper functions for doing useful math on our lists of matrices.// + ////////////////////////////////////////////////////////////////////////////////////////////// + + /** @brief Helper function that inverts all slater matrices in our species list. + * + * @param M. List of slater matrices for each species. These are square and consistent with some occupation. + * @param Minv. The species by species list of inverted matrices from M. + * @return Void. + */ + void invert_M(const std::vector& M, std::vector& Minv); + + /** @brief Helper function that inverts all slater matrices in our species list. + * + * @param Minv. List of slater matrix inverses M^-1 for a given occupation. + * @param B. Observable auxiliary matrix for a given occupation. + * @param X. M^-1*B*M^-1 is stored in this list of matrices. + * @return Void. + */ + void build_X(const std::vector& Minv, + const std::vector& B, + std::vector& X); + + /** @brief Goes through a list of matrices and zeros them out. Does this in place. + * + * @param A. The list of matrices to be zeroed out. After call, A is all zeros. + * @return Void. + */ + void wipe_matrix(std::vector& A); + /** @brief Returns Tr(A*B). Actually, we assume a block diagonal structure, so this is + * really Sum_i Tr(A_i*B_i), where i is the species index. + * + * @param A. Vector of matrices A. + * @param B. Vector of matrices B. + * @return Value of Sum_i Tr(A_i*B_i). + */ + ValueType trAB(const std::vector& A, const std::vector& B); + private: std::vector num_ptcls; @@ -92,6 +214,8 @@ private: std::vector psiM; std::vector psiMinv; std::vector J; + + bool initialized; }; /**@}*/ diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 9919420d4..f0562dcc3 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1258,6 +1258,7 @@ void TrialWaveFunction::initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& t //Needs a bit of logic and protection before this reaches production. //SlaterDet* det = dynamic_cast(Z[i].get()); //det->register_TWF_Prototype(P, twf); + Z[i]->register_TWF_Prototype(P,twf); } else //Is Jastrow, so do nothing right now. {} From 6a78bbb9354e7138236ecff3b62f9d2852406c20 Mon Sep 17 00:00:00 2001 From: rcclay Date: Thu, 6 Jan 2022 11:53:26 -0700 Subject: [PATCH 05/20] Clang format --- src/QMCWaveFunctions/TWFPrototype.h | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index 1fc187bb1..f30720a11 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -62,15 +62,15 @@ public: * * @param P. Particle set. * @return log(Psi). - */ + */ RealType evaluateLog(ParticleSet& P); ////////////////////////////////////////////////////////////////////////////////////////////////////////// //These are convenience functions/wrappers to SPOSet calls. Idea being that observables just need // - //to make calls to this object to build the auxiliary matrices required for fast derivative computation.// + //to make calls to this object to build the auxiliary matrices required for fast derivative computation.// //On the other hand, it wouldn't be unreasonable to make the observables do the SPOSet calls themselves.// ////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** @brief Returns the non-rectangular slater matrices M_ij=phi_j(r_i) (N_particle x N_orbs) for each species group. * * @param P particle set. @@ -85,7 +85,7 @@ public: * @param iel particle ID. * @param val Vector of phi_i(r_iel) for all i=0,Norbs. * @return Void - */ + */ IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); /** @brief Returns the ion derivative of all orbitals (relevant to given species/group) at a particular particle coordinate. @@ -96,13 +96,13 @@ public: * @param iat_source ion index w.r.t. which the ion derivative is taken * @param dval Vector of d/dR_iat_source phi_i(r_iel) for all i=0,Norbs. First index is X derivative, second Y derivative, etc. * @return Void - */ + */ IndexType get_igrad_row(const ParticleSet& P, const ParticleSet& source, IndexType iel, IndexType iat_source, std::vector& dval); - + /** @brief Returns value, gradient, and laplacian matrices for all orbitals and all particles, species by species. * * @param P particle set. @@ -110,7 +110,7 @@ public: * @param gmat electron gradient of slater matrix [G_ij]_a = d/dr_a,i phi_j(r_i). a=x,y,z * @param lmat electron laplacian of slater matrix [L_ij] = \nabla^2_i phi_j(r_i). * @return Void - */ + */ void get_egrad_elapl_M(const ParticleSet& P, std::vector& mvec, std::vector& gmat, @@ -123,7 +123,7 @@ public: * @param iat ion ID w.r.t. which to take derivative. * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. * @return Void - */ + */ void get_igrad_M(const ParticleSet& P, const ParticleSet& source, int iat, @@ -137,23 +137,23 @@ public: * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. * @param dmvec Slater matrix d/dR_{iat,a} L_ij=d/dR_{iat,a} \nabla^2_i phi_j(r_i) for each species group. First index is a=x,y,z. * @return Void - */ + */ void get_igrad_igradelapl_M(const ParticleSet& P, const ParticleSet& source, int iat, std::vector>& dmvec, std::vector>& dlmat); - + /** @brief Takes sub matrices of full SPOSet quantities (evaluated on all particles and all orbitals), consistent with ground * state occupations. * * @param A non-rectangular matrices of SPOSet derived quantities, evaluated on all orbitals and all particles. * @param Aslice square matrices consistent with a ground state occupation. * @return Void - */ + */ void get_gs_matrix(const std::vector& A, std::vector& Aslice); - + /** @brief Calculates derivative of observable via Tr[M^{-1} dB - X * dM ]. Consistent with ground state occupation. * * @param Minv. inverse of slater matrices for ground state occupations. @@ -161,7 +161,7 @@ public: * @param dM. Target derivative of M, and is consistent with ground state occupation. * @param dB. Target derivative of B, and is consistent with ground state occupation. * @return Void - */ + */ ValueType compute_gs_derivative(const std::vector& Minv, const std::vector& X, const std::vector& dM, @@ -176,7 +176,7 @@ public: * @param M. List of slater matrices for each species. These are square and consistent with some occupation. * @param Minv. The species by species list of inverted matrices from M. * @return Void. - */ + */ void invert_M(const std::vector& M, std::vector& Minv); /** @brief Helper function that inverts all slater matrices in our species list. @@ -185,7 +185,7 @@ public: * @param B. Observable auxiliary matrix for a given occupation. * @param X. M^-1*B*M^-1 is stored in this list of matrices. * @return Void. - */ + */ void build_X(const std::vector& Minv, const std::vector& B, std::vector& X); @@ -194,7 +194,7 @@ public: * * @param A. The list of matrices to be zeroed out. After call, A is all zeros. * @return Void. - */ + */ void wipe_matrix(std::vector& A); /** @brief Returns Tr(A*B). Actually, we assume a block diagonal structure, so this is * really Sum_i Tr(A_i*B_i), where i is the species index. @@ -204,7 +204,7 @@ public: * @return Value of Sum_i Tr(A_i*B_i). */ ValueType trAB(const std::vector& A, const std::vector& B); - + private: std::vector num_ptcls; @@ -214,7 +214,7 @@ private: std::vector psiM; std::vector psiMinv; std::vector J; - + bool initialized; }; From 00fa1bfc0fb2b697e0c65f69702237c805b2bb79 Mon Sep 17 00:00:00 2001 From: rcclay Date: Fri, 14 Jan 2022 09:05:27 -0700 Subject: [PATCH 06/20] rename add_determinant, add documentation --- .../Fermion/DiracDeterminant.cpp | 2 +- src/QMCWaveFunctions/TWFPrototype.cpp | 2 +- src/QMCWaveFunctions/TWFPrototype.h | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 7c3922a38..9baf954e7 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -348,7 +348,7 @@ void DiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf template void DiracDeterminant::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) { - twf.add_determinant(P, P.getGroupID(FirstIndex), Phi.get()); + twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); } /** return the ratio only for the iat-th partcle move diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index 68b550410..4684ceb5d 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -25,7 +25,7 @@ TWFPrototype::IndexType TWFPrototype::get_group_index(const IndexType gid) return IndexType(-1); } -void TWFPrototype::add_determinant(const ParticleSet& P, const IndexType gid, SPOSet* spo) +void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* spo) { if (std::find(groups.begin(), groups.end(), gid) == groups.end()) { diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index f30720a11..adef45a97 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -44,7 +44,22 @@ public: using GradVector_t = SPOSet::GradVector_t; TWFPrototype(); - void add_determinant(const ParticleSet& P, const IndexType groupid, SPOSet* spo); + + + /** @brief Add a particle group. + * + * Here, a "group" corresponds to a subset of particles which are antisymmetric with + * respect to eachother. TWFPrototype ensures that there is a binding between the groupid + * in ParticleSet and the SPOSet associated with that particle group. This function stores + * the ParticleSet groupid and SPOSet in a vector for lookup and communication with QMCPACK conventions, + * but is agnostic to the order of group registration or evaluation. + * + * @param[in] P. ParticleSet + * @param[in] groupid. ParticleSet groupid to which SPOSet corresponds. + * @param[in] spo. Pointer to SPOSet. + * @return void. + */ + void addGroup(const ParticleSet& P, const IndexType groupid, SPOSet* spo); inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; //Whatever the group is labelled as in the particle set, sid corresponds to the group used to create determinant sid. From 5c50ae933e86d028152901b1a2a90d7575dcb3ec Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 10:06:36 -0700 Subject: [PATCH 07/20] Change API names to comply with coding conventions. --- src/QMCWaveFunctions/TWFPrototype.cpp | 48 +++++++++++---------------- src/QMCWaveFunctions/TWFPrototype.h | 38 +++++++++++++++------ 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index 4684ceb5d..fe1eda77c 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -16,15 +16,18 @@ namespace qmcplusplus { TWFPrototype::TWFPrototype() : initialized(false) { std::cout << "TWFPrototype Constructed\n"; } -TWFPrototype::IndexType TWFPrototype::get_group_index(const IndexType gid) +TWFPrototype::IndexType TWFPrototype::getTWFGroupIndex(const IndexType gid) { - IndexType ndets = groups.size(); - for (IndexType i = 0; i < ndets; i++) + IndexType return_group_index(-1); + for (IndexType i = 0; i < groups.size(); i++) if (gid == groups[i]) - return i; + return_group_index=i; + + assert(return_group_index != -1); - return IndexType(-1); + return return_group_index; } + void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* spo) { if (std::find(groups.begin(), groups.end(), gid) == groups.end()) @@ -40,19 +43,6 @@ void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* s initialized = true; } -TWFPrototype::IndexType TWFPrototype::get_det_id(const IndexType species_id) -{ - IndexType detIndex = -1; - for (IndexType i = 0; i < groups.size(); i++) - { - if (species_id == groups[i]) - detIndex = i; - } - assert(detIndex != -1); - - return detIndex; -} - void TWFPrototype::get_M(const ParticleSet& P, std::vector& mvec) { IndexType ndets = spos.size(); @@ -181,11 +171,11 @@ TWFPrototype::ValueType TWFPrototype::compute_gs_derivative(const std::vector& dM, const std::vector& dB) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); ValueType dval = 0.0; for (int id = 0; id < nspecies; id++) { - int ptclnum = num_particles(id); + int ptclnum = numParticles(id); ValueType dval_id = 0.0; for (int i = 0; i < ptclnum; i++) for (int j = 0; j < ptclnum; j++) @@ -200,7 +190,7 @@ TWFPrototype::ValueType TWFPrototype::compute_gs_derivative(const std::vector& M, std::vector& Minv) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); for (IndexType id = 0; id < nspecies; id++) { assert(M[id].cols() == M[id].rows()); @@ -213,11 +203,11 @@ void TWFPrototype::build_X(const std::vector& Minv, const std::vector& B, std::vector& X) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); for (IndexType id = 0; id < nspecies; id++) { - int ptclnum = num_particles(id); + int ptclnum = numParticles(id); ValueMatrix_t tmpmat; X[id].resize(ptclnum, ptclnum); tmpmat.resize(ptclnum, ptclnum); @@ -240,7 +230,7 @@ void TWFPrototype::build_X(const std::vector& Minv, void TWFPrototype::wipe_matrix(std::vector& A) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); for (IndexType id = 0; id < nspecies; id++) { @@ -250,12 +240,12 @@ void TWFPrototype::wipe_matrix(std::vector& A) TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, const std::vector& B) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); ValueType val = 0.0; //Now to compute the kinetic energy for (IndexType id = 0; id < nspecies; id++) { - int ptclnum = num_particles(id); + int ptclnum = numParticles(id); ValueType val_id = 0.0; assert(A[id].cols() == B[id].rows() && A[id].rows() == B[id].cols()); for (int i = 0; i < A[id].rows(); i++) @@ -271,11 +261,11 @@ TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, void TWFPrototype::get_gs_matrix(const std::vector& A, std::vector& Aslice) { - IndexType nspecies = num_species(); + IndexType nspecies = numGroups(); Aslice.resize(nspecies); for (IndexType id = 0; id < nspecies; id++) { - IndexType ptclnum = num_particles(id); + IndexType ptclnum = numParticles(id); Aslice[id].resize(ptclnum, ptclnum); for (IndexType i = 0; i < ptclnum; i++) for (IndexType j = 0; j < ptclnum; j++) @@ -295,7 +285,7 @@ TWFPrototype::IndexType TWFPrototype::get_igrad_row(const ParticleSet& P, TWFPrototype::IndexType TWFPrototype::get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val) { IndexType gid = P.getGroupID(iel); - IndexType detIndex = get_det_id(gid); + IndexType detIndex = getTWFGroupIndex(gid); GradVector_t tempg; ValueVector_t templ; diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index adef45a97..5fc5a3ef7 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -62,16 +62,34 @@ public: void addGroup(const ParticleSet& P, const IndexType groupid, SPOSet* spo); inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; - //Whatever the group is labelled as in the particle set, sid corresponds to the group used to create determinant sid. - // so sid=4 returns the number of particles and orbitals used for det #4. Assuming a multispecies determinantal wfn like - // Prod_i Det(M_i). - inline IndexType num_orbitals(const IndexType sid) { return num_orbs[sid]; }; - inline IndexType num_particles(const IndexType sid) { return num_ptcls[sid]; }; - inline IndexType num_species() { return spos.size(); }; - IndexType get_det_id(const IndexType speciesid); - //This takes a particle set group index, and returns the "determinant" this refers to. - IndexType get_group_index(const IndexType gid); - SPOSet* get_sposet(const IndexType sid) { return spos[sid]; }; + /** @brief Takes particle set groupID and returns the TWF internal index for it. + * + * ParticleSet groups can be registered in whichever order. However, the internal indexing + * of TWFPrototype keeps track on a first-come, first serve basis. That is, if I register + * particle groups 3, 1, and 0 in that order, then the internal indexing goes like + * 0->3, 1->1, 2->0. Thus, this function looks up where in the internal indexing scheme + * ParticleSet gid is located. This is necessary, since the matrix list data structures follow + * the internal TWF indexing. + * + * @param[in] gid. ParticleSet group ID to look up. + * @return The corresponding internal groupID. + */ + IndexType getTWFGroupIndex(const IndexType gid); + + /** @ingroup Query functions + * @{ + * @brief These are query functions to the internal state of various groups and SPOSet info. + * All group indices will refer to the internal group indices. Convert from ParticleSet to + * TWF group first! + * + * Source of truth for orbital sizes will be the individual SPOSets. Particle group sizes + * will be ParticleSet in conjunction with groupID maps. + */ + inline IndexType numGroups() { return spos.size(); }; + SPOSet* getSPOSet(const IndexType sid) { return spos[sid]; }; + inline IndexType numOrbitals(const IndexType sid) { return spos[sid]->size(); }; + inline IndexType numParticles(const IndexType sid) { return num_ptcls[sid]; }; + /** @} */ /** @brief Returns log(Psi). Should be consistent with QMCPACK unwrapped TrialWavefunction. * From 7c5c94b3b9568873385501740bc9557426995d50 Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 10:29:52 -0700 Subject: [PATCH 08/20] Add [in,out] in documentation --- src/QMCWaveFunctions/TWFPrototype.h | 81 +++++++++++++++-------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index 5fc5a3ef7..49d047c4c 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -93,7 +93,7 @@ public: /** @brief Returns log(Psi). Should be consistent with QMCPACK unwrapped TrialWavefunction. * - * @param P. Particle set. + * @param[in] P. Particle set. * @return log(Psi). */ RealType evaluateLog(ParticleSet& P); @@ -106,28 +106,28 @@ public: /** @brief Returns the non-rectangular slater matrices M_ij=phi_j(r_i) (N_particle x N_orbs) for each species group. * - * @param P particle set. - * @param mmat Output vector of slater matrices. Each vector entry corresponds to a different particle group. + * @param[in] P particle set. + * @param[in,out] mmat Output vector of slater matrices. Each vector entry corresponds to a different particle group. * @return Void */ void get_M(const ParticleSet& P, std::vector& mmat); /** @brief Returns value of all orbitals (relevant to given species/group) at a particular particle coordinate. * - * @param P particle set. - * @param iel particle ID. - * @param val Vector of phi_i(r_iel) for all i=0,Norbs. + * @param[in] P particle set. + * @param[in]**** iel particle ID. + * @param[in,out] val Vector of phi_i(r_iel) for all i=0,Norbs. * @return Void */ IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); /** @brief Returns the ion derivative of all orbitals (relevant to given species/group) at a particular particle coordinate. * - * @param P particle set. - * @param source ion particle set. - * @param iel particle ID. - * @param iat_source ion index w.r.t. which the ion derivative is taken - * @param dval Vector of d/dR_iat_source phi_i(r_iel) for all i=0,Norbs. First index is X derivative, second Y derivative, etc. + * @param[in] P particle set. + * @param[in] source ion particle set. + * @param[in] iel particle ID. + * @param[in]m iat_source ion index w.r.t. which the ion derivative is taken + * @param[in,out] dval Vector of d/dR_iat_source phi_i(r_iel) for all i=0,Norbs. First index is X derivative, second Y derivative, etc. * @return Void */ IndexType get_igrad_row(const ParticleSet& P, @@ -138,10 +138,10 @@ public: /** @brief Returns value, gradient, and laplacian matrices for all orbitals and all particles, species by species. * - * @param P particle set. - * @param mvec Slater matrix M_ij=phi_j(r_i) for each species group. - * @param gmat electron gradient of slater matrix [G_ij]_a = d/dr_a,i phi_j(r_i). a=x,y,z - * @param lmat electron laplacian of slater matrix [L_ij] = \nabla^2_i phi_j(r_i). + * @param[in] P particle set. + * @param[in,out] mvec Slater matrix M_ij=phi_j(r_i) for each species group. + * @param[in,out] gmat electron gradient of slater matrix [G_ij]_a = d/dr_a,i phi_j(r_i). a=x,y,z + * @param[in,out] lmat electron laplacian of slater matrix [L_ij] = \nabla^2_i phi_j(r_i). * @return Void */ void get_egrad_elapl_M(const ParticleSet& P, @@ -151,10 +151,10 @@ public: /** @brief Returns x,y,z components of ion gradient of slater matrices. * - * @param P particle set. - * @param source ion particle set. - * @param iat ion ID w.r.t. which to take derivative. - * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. + * @param[in] P particle set. + * @param[in] source ion particle set. + * @param[in]*** iat ion ID w.r.t. which to take derivative. + * @param[in,out] dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. * @return Void */ void get_igrad_M(const ParticleSet& P, @@ -164,11 +164,13 @@ public: /** @brief Returns x,y,z components of ion gradient of slater matrices and their laplacians.. * - * @param P particle set. - * @param source ion particle set. - * @param iat ion ID w.r.t. which to take derivative. - * @param dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. - * @param dmvec Slater matrix d/dR_{iat,a} L_ij=d/dR_{iat,a} \nabla^2_i phi_j(r_i) for each species group. First index is a=x,y,z. + * @param[in] P particle set. + * @param[in] source ion particle set. + * @param[in] iat ion ID w.r.t. which to take derivative. + * @param[in,out] dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. + * First index is a=x,y,z. + * @param[in,out] dlmat Slater matrix d/dR_{iat,a} L_ij=d/dR_{iat,a} \nabla^2_i phi_j(r_i) for each species group. + * First index is a=x,y,z. * @return Void */ void get_igrad_igradelapl_M(const ParticleSet& P, @@ -181,19 +183,19 @@ public: /** @brief Takes sub matrices of full SPOSet quantities (evaluated on all particles and all orbitals), consistent with ground * state occupations. * - * @param A non-rectangular matrices of SPOSet derived quantities, evaluated on all orbitals and all particles. - * @param Aslice square matrices consistent with a ground state occupation. + * @param[in] A non-rectangular matrices of SPOSet derived quantities, evaluated on all orbitals and all particles. + * @param[in,out] Aslice square matrices consistent with a ground state occupation. * @return Void */ void get_gs_matrix(const std::vector& A, std::vector& Aslice); /** @brief Calculates derivative of observable via Tr[M^{-1} dB - X * dM ]. Consistent with ground state occupation. * - * @param Minv. inverse of slater matrices for ground state occupations. - * @param X. X=M^-1 B M^-1. B observable matrix, and is consistent with ground state occupation. - * @param dM. Target derivative of M, and is consistent with ground state occupation. - * @param dB. Target derivative of B, and is consistent with ground state occupation. - * @return Void + * @param[in] Minv. inverse of slater matrices for ground state occupations. + * @param[in] X. X=M^-1 B M^-1. B observable matrix, and is consistent with ground state occupation. + * @param[in] dM. Target derivative of M, and is consistent with ground state occupation. + * @param[in] dB. Target derivative of B, and is consistent with ground state occupation. + * @return Derivative of O psi/psi = Tr[M^{-1} dB - X * dM ] */ ValueType compute_gs_derivative(const std::vector& Minv, const std::vector& X, @@ -206,17 +208,17 @@ public: /** @brief Helper function that inverts all slater matrices in our species list. * - * @param M. List of slater matrices for each species. These are square and consistent with some occupation. - * @param Minv. The species by species list of inverted matrices from M. + * @param[in] M. List of slater matrices for each species. These are square and consistent with some occupation. + * @param[in,out] Minv. The species by species list of inverted matrices from M. * @return Void. */ void invert_M(const std::vector& M, std::vector& Minv); /** @brief Helper function that inverts all slater matrices in our species list. * - * @param Minv. List of slater matrix inverses M^-1 for a given occupation. - * @param B. Observable auxiliary matrix for a given occupation. - * @param X. M^-1*B*M^-1 is stored in this list of matrices. + * @param[in] Minv. List of slater matrix inverses M^-1 for a given occupation. + * @param[in] B. Observable auxiliary matrix for a given occupation. + * @param[in,out] X. M^-1*B*M^-1 is stored in this list of matrices. * @return Void. */ void build_X(const std::vector& Minv, @@ -225,15 +227,16 @@ public: /** @brief Goes through a list of matrices and zeros them out. Does this in place. * - * @param A. The list of matrices to be zeroed out. After call, A is all zeros. + * @param[in,out] A. The list of matrices to be zeroed out. After call, A is all zeros. * @return Void. */ void wipe_matrix(std::vector& A); + /** @brief Returns Tr(A*B). Actually, we assume a block diagonal structure, so this is * really Sum_i Tr(A_i*B_i), where i is the species index. * - * @param A. Vector of matrices A. - * @param B. Vector of matrices B. + * @param[in] A. Vector of matrices A. + * @param[in] B. Vector of matrices B. * @return Value of Sum_i Tr(A_i*B_i). */ ValueType trAB(const std::vector& A, const std::vector& B); From c1cee13f174b90a3f86977e9037397f26243cb46 Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 11:19:02 -0700 Subject: [PATCH 09/20] Change function names to conform with conventions --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 48 +++++++++---------- src/QMCWaveFunctions/TWFPrototype.cpp | 30 +++++------- src/QMCWaveFunctions/TWFPrototype.h | 40 +++++----------- 3 files changed, 48 insertions(+), 70 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index b0dd9dbde..e9b0a6159 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -837,7 +837,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") X.push_back(upmat); X.push_back(dnmat); - twf.get_M(elec, matlist); + twf.getM(elec, matlist); OperatorBase* kinop = ham.getHamiltonian(KINETIC); @@ -855,17 +855,17 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") minv.push_back(dnmat); -// twf.get_M(elec, matlist); +// twf.getM(elec, matlist); std::vector> dB_gs; std::vector> dM_gs; std::vector tmp_gs; -// twf.get_gs_matrix(B, B_gs); -// twf.get_gs_matrix(matlist, M_gs); -// twf.invert_M(M_gs, minv); -// twf.build_X(minv, B_gs, X); +// twf.getGSMatrix(B, B_gs); +// twf.getGSMatrix(matlist, M_gs); +// twf.invertMatrix(M_gs, minv); +// twf.buildX(minv, B_gs, X); for (int id = 0; id < matlist.size(); id++) { -// int ptclnum = twf.num_particles(id); +// int ptclnum = twf.numParticles(id); int ptclnum = (id==0 ? Nup : Ndn); //hard coded until twf interface comes online. ValueMatrix_t gs_m; gs_m.resize(ptclnum, ptclnum); @@ -891,18 +891,18 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") { for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.wipe_matrix(dB[idim]); -// twf.wipe_matrix(dM[idim]); +// twf.wipeMatrix(dB[idim]); +// twf.wipeMatrix(dM[idim]); } -// twf.get_igrad_M(elec, ions, ionid, dM); +// twf.getIonGradM(elec, ions, ionid, dM); // kinop->evaluateOneBodyOpMatrixForceDeriv(elec, ions, twf, ionid, dB); for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.get_gs_matrix(dB[idim], dB_gs[idim]); -// twf.get_gs_matrix(dM[idim], dM_gs[idim]); -// fkin_complex[ionid][idim] = twf.compute_gs_derivative(minv, X, dM_gs[idim], dB_gs[idim]); +// twf.getGSMatrix(dB[idim], dB_gs[idim]); +// twf.getGSMatrix(dM[idim], dM_gs[idim]); +// fkin_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); } convertToReal(fkin_complex[ionid], fkin[ionid]); } @@ -937,12 +937,12 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") app_log() << " Evaluated. Calling evaluteOneBodyOpMatrix\n"; -// twf.wipe_matrix(B); -// twf.wipe_matrix(B_gs); -// twf.wipe_matrix(X); +// twf.wipeMatrix(B); +// twf.wipeMatrix(B_gs); +// twf.wipeMatrix(X); // nlppop->evaluateOneBodyOpMatrix(elec, twf, B); -// twf.get_gs_matrix(B, B_gs); -// twf.build_X(minv, B_gs, X); +// twf.getGSMatrix(B, B_gs); +// twf.buildX(minv, B_gs, X); ValueType nlpp = 0.0; RealType nlpp_obs = 0.0; @@ -959,18 +959,18 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") { for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.wipe_matrix(dB[idim]); -// twf.wipe_matrix(dM[idim]); +// twf.wipeMatrix(dB[idim]); +// twf.wipeMatrix(dM[idim]); } -// twf.get_igrad_M(elec, ions, ionid, dM); +// twf.getIonGradM(elec, ions, ionid, dM); // nlppop->evaluateOneBodyOpMatrixForceDeriv(elec, ions, twf, ionid, dB); for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.get_gs_matrix(dB[idim], dB_gs[idim]); -// twf.get_gs_matrix(dM[idim], dM_gs[idim]); -// fnlpp_complex[ionid][idim] = twf.compute_gs_derivative(minv, X, dM_gs[idim], dB_gs[idim]); +// twf.getGSMatrix(dB[idim], dB_gs[idim]); +// twf.getGSMatrix(dM[idim], dM_gs[idim]); +// fnlpp_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); } convertToReal(fnlpp_complex[ionid], fnlpp[ionid]); } diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index fe1eda77c..c916ab1a4 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -43,7 +43,7 @@ void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* s initialized = true; } -void TWFPrototype::get_M(const ParticleSet& P, std::vector& mvec) +void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) { IndexType ndets = spos.size(); IndexType norbs = 0; @@ -67,7 +67,7 @@ void TWFPrototype::get_M(const ParticleSet& P, std::vector& mvec) } } -void TWFPrototype::get_egrad_elapl_M(const ParticleSet& P, +void TWFPrototype::getEGradELaplM(const ParticleSet& P, std::vector& mvec, std::vector& gmat, std::vector& lmat) @@ -92,9 +92,9 @@ void TWFPrototype::get_egrad_elapl_M(const ParticleSet& P, } } -void TWFPrototype::get_igrad_M(const ParticleSet& P, +void TWFPrototype::getIonGradM(const ParticleSet& P, const ParticleSet& source, - int iat, + const int iat, std::vector>& dmvec) { IndexType ndets = dmvec[0].size(); @@ -126,7 +126,7 @@ void TWFPrototype::get_igrad_M(const ParticleSet& P, } } -void TWFPrototype::get_igrad_igradelapl_M(const ParticleSet& P, +void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, const ParticleSet& source, int iat, std::vector>& dmvec, @@ -166,7 +166,7 @@ void TWFPrototype::get_igrad_igradelapl_M(const ParticleSet& P, } } -TWFPrototype::ValueType TWFPrototype::compute_gs_derivative(const std::vector& Minv, +TWFPrototype::ValueType TWFPrototype::computeGSDerivative(const std::vector& Minv, const std::vector& X, const std::vector& dM, const std::vector& dB) @@ -188,7 +188,7 @@ TWFPrototype::ValueType TWFPrototype::compute_gs_derivative(const std::vector& M, std::vector& Minv) +void TWFPrototype::invertMatrix(const std::vector& M, std::vector& Minv) { IndexType nspecies = numGroups(); for (IndexType id = 0; id < nspecies; id++) @@ -199,7 +199,7 @@ void TWFPrototype::invert_M(const std::vector& M, std::vector& Minv, +void TWFPrototype::buildX(const std::vector& Minv, const std::vector& B, std::vector& X) { @@ -228,7 +228,7 @@ void TWFPrototype::build_X(const std::vector& Minv, } } -void TWFPrototype::wipe_matrix(std::vector& A) +void TWFPrototype::wipeMatrix(std::vector& A) { IndexType nspecies = numGroups(); @@ -259,7 +259,7 @@ TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, return val; } -void TWFPrototype::get_gs_matrix(const std::vector& A, std::vector& Aslice) +void TWFPrototype::getGSMatrix(const std::vector& A, std::vector& Aslice) { IndexType nspecies = numGroups(); Aslice.resize(nspecies); @@ -273,16 +273,8 @@ void TWFPrototype::get_gs_matrix(const std::vector& A, std::vecto } } -TWFPrototype::IndexType TWFPrototype::get_igrad_row(const ParticleSet& P, - const ParticleSet& source, - IndexType iel, - IndexType iat_source, - std::vector& dval) -{ - return -1; -} -TWFPrototype::IndexType TWFPrototype::get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val) +TWFPrototype::IndexType TWFPrototype::getRowM(const ParticleSet& P, const IndexType iel, ValueVector_t& val) { IndexType gid = P.getGroupID(iel); IndexType detIndex = getTWFGroupIndex(gid); diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index 49d047c4c..d6445a716 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -60,7 +60,7 @@ public: * @return void. */ void addGroup(const ParticleSet& P, const IndexType groupid, SPOSet* spo); - inline void add_jastrow(WaveFunctionComponent* j) { J.push_back(j); }; + inline void addJastrow(WaveFunctionComponent* j) { J.push_back(j); }; /** @brief Takes particle set groupID and returns the TWF internal index for it. * @@ -110,31 +110,17 @@ public: * @param[in,out] mmat Output vector of slater matrices. Each vector entry corresponds to a different particle group. * @return Void */ - void get_M(const ParticleSet& P, std::vector& mmat); + void getM(const ParticleSet& P, std::vector& mmat); /** @brief Returns value of all orbitals (relevant to given species/group) at a particular particle coordinate. * * @param[in] P particle set. - * @param[in]**** iel particle ID. + * @param[in] iel particle ID. * @param[in,out] val Vector of phi_i(r_iel) for all i=0,Norbs. * @return Void */ - IndexType get_M_row(const ParticleSet& P, IndexType iel, ValueVector_t& val); + IndexType getRowM(const ParticleSet& P, const IndexType iel, ValueVector_t& val); - /** @brief Returns the ion derivative of all orbitals (relevant to given species/group) at a particular particle coordinate. - * - * @param[in] P particle set. - * @param[in] source ion particle set. - * @param[in] iel particle ID. - * @param[in]m iat_source ion index w.r.t. which the ion derivative is taken - * @param[in,out] dval Vector of d/dR_iat_source phi_i(r_iel) for all i=0,Norbs. First index is X derivative, second Y derivative, etc. - * @return Void - */ - IndexType get_igrad_row(const ParticleSet& P, - const ParticleSet& source, - IndexType iel, - IndexType iat_source, - std::vector& dval); /** @brief Returns value, gradient, and laplacian matrices for all orbitals and all particles, species by species. * @@ -144,7 +130,7 @@ public: * @param[in,out] lmat electron laplacian of slater matrix [L_ij] = \nabla^2_i phi_j(r_i). * @return Void */ - void get_egrad_elapl_M(const ParticleSet& P, + void getEGradELaplM(const ParticleSet& P, std::vector& mvec, std::vector& gmat, std::vector& lmat); @@ -157,9 +143,9 @@ public: * @param[in,out] dmvec Slater matrix d/dR_{iat,a} M_ij=d/dR_{iat,a} phi_j(r_i) for each species group. First index is a=x,y,z. * @return Void */ - void get_igrad_M(const ParticleSet& P, + void getIonGradM(const ParticleSet& P, const ParticleSet& source, - int iat, + const int iat, std::vector>& dmvec); /** @brief Returns x,y,z components of ion gradient of slater matrices and their laplacians.. @@ -173,7 +159,7 @@ public: * First index is a=x,y,z. * @return Void */ - void get_igrad_igradelapl_M(const ParticleSet& P, + void getIonGradIonGradELaplM(const ParticleSet& P, const ParticleSet& source, int iat, std::vector>& dmvec, @@ -187,7 +173,7 @@ public: * @param[in,out] Aslice square matrices consistent with a ground state occupation. * @return Void */ - void get_gs_matrix(const std::vector& A, std::vector& Aslice); + void getGSMatrix(const std::vector& A, std::vector& Aslice); /** @brief Calculates derivative of observable via Tr[M^{-1} dB - X * dM ]. Consistent with ground state occupation. * @@ -197,7 +183,7 @@ public: * @param[in] dB. Target derivative of B, and is consistent with ground state occupation. * @return Derivative of O psi/psi = Tr[M^{-1} dB - X * dM ] */ - ValueType compute_gs_derivative(const std::vector& Minv, + ValueType computeGSDerivative(const std::vector& Minv, const std::vector& X, const std::vector& dM, const std::vector& dB); @@ -212,7 +198,7 @@ public: * @param[in,out] Minv. The species by species list of inverted matrices from M. * @return Void. */ - void invert_M(const std::vector& M, std::vector& Minv); + void invertMatrix(const std::vector& M, std::vector& Minv); /** @brief Helper function that inverts all slater matrices in our species list. * @@ -221,7 +207,7 @@ public: * @param[in,out] X. M^-1*B*M^-1 is stored in this list of matrices. * @return Void. */ - void build_X(const std::vector& Minv, + void buildX(const std::vector& Minv, const std::vector& B, std::vector& X); @@ -230,7 +216,7 @@ public: * @param[in,out] A. The list of matrices to be zeroed out. After call, A is all zeros. * @return Void. */ - void wipe_matrix(std::vector& A); + void wipeMatrix(std::vector& A); /** @brief Returns Tr(A*B). Actually, we assume a block diagonal structure, so this is * really Sum_i Tr(A_i*B_i), where i is the species index. From 855550eabbe68afa3050c06d81a599af2e5c46ef Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 11:44:21 -0700 Subject: [PATCH 10/20] rename J to jastrow_list --- src/QMCWaveFunctions/TWFPrototype.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index d6445a716..320476fff 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -60,7 +60,7 @@ public: * @return void. */ void addGroup(const ParticleSet& P, const IndexType groupid, SPOSet* spo); - inline void addJastrow(WaveFunctionComponent* j) { J.push_back(j); }; + inline void addJastrow(WaveFunctionComponent* j) { jastrow_list.push_back(j); }; /** @brief Takes particle set groupID and returns the TWF internal index for it. * @@ -235,9 +235,8 @@ private: std::vector groups; std::vector psiM; std::vector psiMinv; - std::vector J; + std::vector jastrow_list; - bool initialized; }; /**@}*/ From d8ed4079f8732bddc3940b55f813667df68a6c4c Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 11:45:12 -0700 Subject: [PATCH 11/20] Update misleading WaveFunctionComponent documentation --- src/QMCWaveFunctions/WaveFunctionComponent.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 1d455ba2b..b055cd193 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -170,8 +170,7 @@ public: /** print the state, e.g., optimizables */ virtual void reportStatus(std::ostream& os) = 0; - /** Register the component with the TWFPrototype wrapper. Pure virtual, so will throw - * an error at compile time + /** Register the component with the TWFPrototype wrapper. */ virtual void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf); From cb164c853bc50d5b2226729d030a067e442696f2 Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 13:10:32 -0700 Subject: [PATCH 12/20] Rename private member variables. Eliminate internal particle array --- src/QMCWaveFunctions/TWFPrototype.cpp | 71 +++++++++++++-------------- src/QMCWaveFunctions/TWFPrototype.h | 26 ++++------ 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index c916ab1a4..8fc2d9b05 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -14,13 +14,12 @@ #include namespace qmcplusplus { -TWFPrototype::TWFPrototype() : initialized(false) { std::cout << "TWFPrototype Constructed\n"; } TWFPrototype::IndexType TWFPrototype::getTWFGroupIndex(const IndexType gid) { IndexType return_group_index(-1); - for (IndexType i = 0; i < groups.size(); i++) - if (gid == groups[i]) + for (IndexType i = 0; i < groups_.size(); i++) + if (gid == groups_[i]) return_group_index=i; assert(return_group_index != -1); @@ -30,22 +29,19 @@ TWFPrototype::IndexType TWFPrototype::getTWFGroupIndex(const IndexType gid) void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* spo) { - if (std::find(groups.begin(), groups.end(), gid) == groups.end()) + if (std::find(groups_.begin(), groups_.end(), gid) == groups_.end()) { - groups.push_back(gid); - spos.push_back(spo); + groups_.push_back(gid); + spos_.push_back(spo); IndexType first = P.first(gid); IndexType last = P.last(gid); IndexType norbs = spo->getOrbitalSetSize(); - num_orbs.push_back(norbs); - num_ptcls.push_back(last - first); } - initialized = true; } void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) { - IndexType ndets = spos.size(); + IndexType ndets = spos_.size(); IndexType norbs = 0; IndexType nptcls = 0; IndexType gid = 0; @@ -53,17 +49,17 @@ void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) IndexType last = 0; for (IndexType i = 0; i < ndets; i++) { - gid = groups[i]; + gid = groups_[i]; first = P.first(i); last = P.last(i); nptcls = last - first; - norbs = spos[i]->getOrbitalSetSize(); + norbs = spos_[i]->getOrbitalSetSize(); mvec[i] = 0; GradMatrix_t tmpgmat; ValueMatrix_t tmplmat; tmpgmat.resize(nptcls, norbs); tmplmat.resize(nptcls, norbs); - spos[i]->evaluate_notranspose(P, first, last, mvec[i], tmpgmat, tmplmat); + spos_[i]->evaluate_notranspose(P, first, last, mvec[i], tmpgmat, tmplmat); } } @@ -80,15 +76,15 @@ void TWFPrototype::getEGradELaplM(const ParticleSet& P, IndexType last = 0; for (IndexType i = 0; i < ndets; i++) { - gid = groups[i]; + gid = groups_[i]; first = P.first(i); last = P.last(i); nptcls = last - first; - norbs = spos[i]->getOrbitalSetSize(); + norbs = spos_[i]->getOrbitalSetSize(); mvec[i] = 0; gmat[i] = 0; lmat[i] = 0; - spos[i]->evaluate_notranspose(P, first, last, mvec[i], gmat[i], lmat[i]); + spos_[i]->evaluate_notranspose(P, first, last, mvec[i], gmat[i], lmat[i]); } } @@ -105,17 +101,17 @@ void TWFPrototype::getIonGradM(const ParticleSet& P, IndexType last = 0; for (IndexType i = 0; i < ndets; i++) { - gid = groups[i]; + gid = groups_[i]; first = P.first(i); last = P.last(i); nptcls = last - first; - norbs = spos[i]->getOrbitalSetSize(); + norbs = spos_[i]->getOrbitalSetSize(); GradMatrix_t grad_phi; grad_phi.resize(nptcls, norbs); - spos[i]->evaluateGradSource(P, first, last, source, iat, grad_phi); + spos_[i]->evaluateGradSource(P, first, last, source, iat, grad_phi); for (IndexType idim = 0; idim < OHMMS_DIM; idim++) for (IndexType iptcl = 0; iptcl < nptcls; iptcl++) @@ -140,11 +136,11 @@ void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, IndexType last = 0; for (IndexType i = 0; i < ndets; i++) { - gid = groups[i]; + gid = groups_[i]; first = P.first(i); last = P.last(i); nptcls = last - first; - norbs = spos[i]->getOrbitalSetSize(); + norbs = spos_[i]->getOrbitalSetSize(); GradMatrix_t grad_phi; HessMatrix_t grad_grad_phi; @@ -154,7 +150,7 @@ void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, grad_grad_phi.resize(nptcls, norbs); grad_lapl_phi.resize(nptcls, norbs); - spos[i]->evaluateGradSource(P, first, last, source, iat, grad_phi, grad_grad_phi, grad_lapl_phi); + spos_[i]->evaluateGradSource(P, first, last, source, iat, grad_phi, grad_grad_phi, grad_lapl_phi); for (IndexType idim = 0; idim < OHMMS_DIM; idim++) for (IndexType iptcl = 0; iptcl < nptcls; iptcl++) @@ -171,11 +167,11 @@ TWFPrototype::ValueType TWFPrototype::computeGSDerivative(const std::vector& dM, const std::vector& dB) { - IndexType nspecies = numGroups(); + IndexType nspecies = Minv.size(); ValueType dval = 0.0; for (int id = 0; id < nspecies; id++) { - int ptclnum = numParticles(id); + int ptclnum = Minv[id].rows(); ValueType dval_id = 0.0; for (int i = 0; i < ptclnum; i++) for (int j = 0; j < ptclnum; j++) @@ -190,7 +186,7 @@ TWFPrototype::ValueType TWFPrototype::computeGSDerivative(const std::vector& M, std::vector& Minv) { - IndexType nspecies = numGroups(); + IndexType nspecies = M.size(); for (IndexType id = 0; id < nspecies; id++) { assert(M[id].cols() == M[id].rows()); @@ -203,11 +199,12 @@ void TWFPrototype::buildX(const std::vector& Minv, const std::vector& B, std::vector& X) { - IndexType nspecies = numGroups(); + IndexType nspecies = Minv.size(); for (IndexType id = 0; id < nspecies; id++) { - int ptclnum = numParticles(id); + int ptclnum = Minv[id].rows(); + assert(Minv[id].rows()==Minv[id].cols()); ValueMatrix_t tmpmat; X[id].resize(ptclnum, ptclnum); tmpmat.resize(ptclnum, ptclnum); @@ -230,9 +227,8 @@ void TWFPrototype::buildX(const std::vector& Minv, void TWFPrototype::wipeMatrix(std::vector& A) { - IndexType nspecies = numGroups(); - for (IndexType id = 0; id < nspecies; id++) + for (IndexType id = 0; id < A.size(); id++) { A[id] = 0.0; } @@ -240,12 +236,13 @@ void TWFPrototype::wipeMatrix(std::vector& A) TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, const std::vector& B) { - IndexType nspecies = numGroups(); + IndexType nspecies = A.size(); + assert(A.size() == B.size()); ValueType val = 0.0; //Now to compute the kinetic energy for (IndexType id = 0; id < nspecies; id++) { - int ptclnum = numParticles(id); + int ptclnum = A[id].rows(); ValueType val_id = 0.0; assert(A[id].cols() == B[id].rows() && A[id].rows() == B[id].cols()); for (int i = 0; i < A[id].rows(); i++) @@ -261,11 +258,11 @@ TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, void TWFPrototype::getGSMatrix(const std::vector& A, std::vector& Aslice) { - IndexType nspecies = numGroups(); + IndexType nspecies = A.size(); Aslice.resize(nspecies); for (IndexType id = 0; id < nspecies; id++) { - IndexType ptclnum = numParticles(id); + IndexType ptclnum = A[id].rows(); Aslice[id].resize(ptclnum, ptclnum); for (IndexType i = 0; i < ptclnum; i++) for (IndexType j = 0; j < ptclnum; j++) @@ -277,19 +274,19 @@ void TWFPrototype::getGSMatrix(const std::vector& A, std::vector< TWFPrototype::IndexType TWFPrototype::getRowM(const ParticleSet& P, const IndexType iel, ValueVector_t& val) { IndexType gid = P.getGroupID(iel); - IndexType detIndex = getTWFGroupIndex(gid); + IndexType sid = getTWFGroupIndex(gid); GradVector_t tempg; ValueVector_t templ; - IndexType norbs = spos[detIndex]->getOrbitalSetSize(); + IndexType norbs = spos_[sid]->getOrbitalSetSize(); tempg.resize(norbs); templ.resize(norbs); - spos[detIndex]->evaluateVGL(P, iel, val, tempg, templ); + spos_[sid]->evaluateVGL(P, iel, val, tempg, templ); - return detIndex; + return sid; } diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index 320476fff..b64214fc5 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -10,9 +10,6 @@ ////////////////////////////////////////////////////////////////////////////////////// -/**@file TWFPrototype.h - *@brief Declaration of TWFPrototype - */ #ifndef QMCPLUSPLUS_TWFPROTOTYPE_H #define QMCPLUSPLUS_TWFPROTOTYPE_H @@ -43,8 +40,6 @@ public: using ValueVector_t = SPOSet::ValueVector_t; using GradVector_t = SPOSet::GradVector_t; - TWFPrototype(); - /** @brief Add a particle group. * @@ -60,7 +55,7 @@ public: * @return void. */ void addGroup(const ParticleSet& P, const IndexType groupid, SPOSet* spo); - inline void addJastrow(WaveFunctionComponent* j) { jastrow_list.push_back(j); }; + inline void addJastrow(WaveFunctionComponent* j) { jastrow_list_.push_back(j); }; /** @brief Takes particle set groupID and returns the TWF internal index for it. * @@ -85,10 +80,9 @@ public: * Source of truth for orbital sizes will be the individual SPOSets. Particle group sizes * will be ParticleSet in conjunction with groupID maps. */ - inline IndexType numGroups() { return spos.size(); }; - SPOSet* getSPOSet(const IndexType sid) { return spos[sid]; }; - inline IndexType numOrbitals(const IndexType sid) { return spos[sid]->size(); }; - inline IndexType numParticles(const IndexType sid) { return num_ptcls[sid]; }; + inline IndexType numGroups() { return spos_.size(); }; + SPOSet* getSPOSet(const IndexType sid) { return spos_[sid]; }; + inline IndexType numOrbitals(const IndexType sid) { return spos_[sid]->size(); }; /** @} */ /** @brief Returns log(Psi). Should be consistent with QMCPACK unwrapped TrialWavefunction. @@ -229,13 +223,11 @@ public: private: - std::vector num_ptcls; - std::vector num_orbs; - std::vector spos; - std::vector groups; - std::vector psiM; - std::vector psiMinv; - std::vector jastrow_list; + std::vector spos_; + std::vector groups_; + std::vector psi_M_; + std::vector psi_M_inv_; + std::vector jastrow_list_; }; From e5ff9421fc8ec120b89d0defe5253b1f46d9620f Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 13:26:10 -0700 Subject: [PATCH 13/20] Rename function to comply with coding conventions. --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminant.h | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h | 4 ++-- src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 4 ++-- src/QMCWaveFunctions/Fermion/SlaterDet.h | 2 +- src/QMCWaveFunctions/TrialWaveFunction.cpp | 6 +++--- src/QMCWaveFunctions/TrialWaveFunction.h | 2 +- src/QMCWaveFunctions/WaveFunctionComponent.cpp | 4 ++-- src/QMCWaveFunctions/WaveFunctionComponent.h | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index e9b0a6159..c4c67eec0 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -772,7 +772,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") TWFPrototype twf; - psi->initialize_TWF_Prototype(elec, twf); + psi->initializeTWFPrototype(elec, twf); SPOSet::ValueVector_t values; SPOSet::GradVector_t dpsi; SPOSet::ValueVector_t d2psi; diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 9baf954e7..f4d011e78 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -346,7 +346,7 @@ void DiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf } template -void DiracDeterminant::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +void DiracDeterminant::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) { twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index aee575452..626337e6d 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -78,7 +78,7 @@ public: /** Finds the SPOSet associated with this determinant, and registers it with WFN wrapper */ - void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) final; + void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) final; /** return the ratio only for the iat-th partcle move * @param P current configuration diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h index baeb19024..b666413b5 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h @@ -85,9 +85,9 @@ public: inline void reportStatus(std::ostream& os) final {} - virtual void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) override + virtual void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) override { - APP_ABORT("DiracDeterminantBase::register_TWF_Prototype must be overridden\n"); + APP_ABORT("DiracDeterminantBase::registerTWFPrototype must be overridden\n"); } // expose CPU interfaces using WaveFunctionComponent::evaluateDerivatives; diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index 21d3d8bb3..b9b5cb380 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -253,11 +253,11 @@ std::unique_ptr SlaterDet::makeClone(ParticleSet& tqp) co return myclone; } -void SlaterDet::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +void SlaterDet::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) { for (int i = 0; i < Dets.size(); ++i) { - Dets[i]->register_TWF_Prototype(P, twf); + Dets[i]->registerTWFPrototype(P, twf); } } diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index 566535958..4e07a9188 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -55,7 +55,7 @@ public: void reportStatus(std::ostream& os) override; - void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) override; + void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) override; LogValueType evaluateLog(const ParticleSet& P, ParticleSet::ParticleGradient_t& G, diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index ed8a7a367..985da6626 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1340,7 +1340,7 @@ RefVector TrialWaveFunction::extractLRefList( return l_list; } -void TrialWaveFunction::initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +void TrialWaveFunction::initializeTWFPrototype(ParticleSet& P, TWFPrototype& twf) { for (int i = 0; i < Z.size(); ++i) { @@ -1349,8 +1349,8 @@ void TrialWaveFunction::initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& t //OK, so this is a hack only for SlaterDeterminant objects. //Needs a bit of logic and protection before this reaches production. //SlaterDet* det = dynamic_cast(Z[i].get()); - //det->register_TWF_Prototype(P, twf); - Z[i]->register_TWF_Prototype(P,twf); + //det->registerTWFPrototype(P, twf); + Z[i]->registerTWFPrototype(P,twf); } else //Is Jastrow, so do nothing right now. {} diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 52b09a2f1..df49866e4 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -171,7 +171,7 @@ public: /** Initialize a TWF wrapper for fast derivative evaluation */ - void initialize_TWF_Prototype(ParticleSet& P, TWFPrototype& twf); + void initializeTWFPrototype(ParticleSet& P, TWFPrototype& twf); /** evalaute the log (internally gradients and laplacian) of the trial wavefunction. gold reference */ RealType evaluateLog(ParticleSet& P); diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index ca3dca08d..f37056060 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -226,10 +226,10 @@ void WaveFunctionComponent::evaluateDerivRatios(VirtualParticleSet& VP, evaluateRatios(VP, ratios); } -void WaveFunctionComponent::register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf) +void WaveFunctionComponent::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) { std::ostringstream o; - o << "WaveFunctionComponent::register_TWF_Prototype is not implemented by " << ClassName; + o << "WaveFunctionComponent::registerTWFPrototype is not implemented by " << ClassName; APP_ABORT(o.str()); } diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index b055cd193..12eb10e7a 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -172,7 +172,7 @@ public: /** Register the component with the TWFPrototype wrapper. */ - virtual void register_TWF_Prototype(ParticleSet& P, TWFPrototype& twf); + virtual void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf); /** evaluate the value of the WaveFunctionComponent from scratch * \param[in] P active ParticleSet From 19a59e9cb1676f3df0c31d3c497b12254e7c9a8c Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 15:23:22 -0700 Subject: [PATCH 14/20] Make functions and args const. Also add in missing implementation for DiracDeterminantBatched --- src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminant.h | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h | 2 +- src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp | 7 +++++++ src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h | 4 ++++ src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 2 +- src/QMCWaveFunctions/Fermion/SlaterDet.h | 2 +- src/QMCWaveFunctions/TrialWaveFunction.cpp | 2 +- src/QMCWaveFunctions/TrialWaveFunction.h | 2 +- src/QMCWaveFunctions/WaveFunctionComponent.cpp | 2 +- src/QMCWaveFunctions/WaveFunctionComponent.h | 2 +- 11 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index f4d011e78..523ef4f18 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -346,7 +346,7 @@ void DiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf } template -void DiracDeterminant::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) +void DiracDeterminant::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const { twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index 626337e6d..5f97d5b68 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -78,7 +78,7 @@ public: /** Finds the SPOSet associated with this determinant, and registers it with WFN wrapper */ - void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) final; + void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const final; /** return the ratio only for the iat-th partcle move * @param P current configuration diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h index b666413b5..ca07774a4 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h @@ -85,7 +85,7 @@ public: inline void reportStatus(std::ostream& os) final {} - virtual void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) override + virtual void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override { APP_ABORT("DiracDeterminantBase::registerTWFPrototype must be overridden\n"); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp index 48b2f6691..2ff5e6739 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp @@ -16,6 +16,7 @@ #include "CPU/BLAS.hpp" #include "OhmmsPETE/OhmmsMatrix.h" #include "Numerics/MatrixOperators.h" +#include "QMCWaveFunctions/TWFPrototype.h" #include "CPU/SIMD/simd.hpp" #include @@ -956,6 +957,12 @@ void DiracDeterminantBatched::evaluateDerivatives(ParticleSet& P, Phi->evaluateDerivatives(P, active, dlogpsi, dhpsioverpsi, FirstIndex, LastIndex); } +template +void DiracDeterminantBatched::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +{ + twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); +} + template std::unique_ptr DiracDeterminantBatched::makeCopy(std::shared_ptr&& spo) const { diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h index cd54383bf..64c8aa4f2 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h @@ -29,6 +29,9 @@ namespace qmcplusplus { +//forward declaration +class TWFPrototype; + template> class DiracDeterminantBatched : public DiracDeterminantBase { @@ -209,6 +212,7 @@ public: void releaseResource(ResourceCollection& collection, const RefVectorWithLeader& wfc_list) const override; + void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override; /** cloning function * @param tqp target particleset * @param spo spo set diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index b9b5cb380..ebaddecd5 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -253,7 +253,7 @@ std::unique_ptr SlaterDet::makeClone(ParticleSet& tqp) co return myclone; } -void SlaterDet::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) +void SlaterDet::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const { for (int i = 0; i < Dets.size(); ++i) { diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index 4e07a9188..5493f84a8 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -55,7 +55,7 @@ public: void reportStatus(std::ostream& os) override; - void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) override; + void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override; LogValueType evaluateLog(const ParticleSet& P, ParticleSet::ParticleGradient_t& G, diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 985da6626..04adc517e 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1340,7 +1340,7 @@ RefVector TrialWaveFunction::extractLRefList( return l_list; } -void TrialWaveFunction::initializeTWFPrototype(ParticleSet& P, TWFPrototype& twf) +void TrialWaveFunction::initializeTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const { for (int i = 0; i < Z.size(); ++i) { diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index df49866e4..9590bf7fa 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -171,7 +171,7 @@ public: /** Initialize a TWF wrapper for fast derivative evaluation */ - void initializeTWFPrototype(ParticleSet& P, TWFPrototype& twf); + void initializeTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const; /** evalaute the log (internally gradients and laplacian) of the trial wavefunction. gold reference */ RealType evaluateLog(ParticleSet& P); diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index f37056060..c39b25fb9 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -226,7 +226,7 @@ void WaveFunctionComponent::evaluateDerivRatios(VirtualParticleSet& VP, evaluateRatios(VP, ratios); } -void WaveFunctionComponent::registerTWFPrototype(ParticleSet& P, TWFPrototype& twf) +void WaveFunctionComponent::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const { std::ostringstream o; o << "WaveFunctionComponent::registerTWFPrototype is not implemented by " << ClassName; diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 12eb10e7a..c1975ccfc 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -172,7 +172,7 @@ public: /** Register the component with the TWFPrototype wrapper. */ - virtual void registerTWFPrototype(ParticleSet& P, TWFPrototype& twf); + virtual void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const; /** evaluate the value of the WaveFunctionComponent from scratch * \param[in] P active ParticleSet From ad691249857a0156849d40d0e3adc51dfb56db1c Mon Sep 17 00:00:00 2001 From: rcclay Date: Mon, 17 Jan 2022 15:25:10 -0700 Subject: [PATCH 15/20] Remove evaluateLog function --- src/QMCWaveFunctions/TWFPrototype.cpp | 2 -- src/QMCWaveFunctions/TWFPrototype.h | 7 ------- 2 files changed, 9 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index 8fc2d9b05..148b5db5f 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -290,6 +290,4 @@ TWFPrototype::IndexType TWFPrototype::getRowM(const ParticleSet& P, const IndexT } -TWFPrototype::RealType TWFPrototype::evaluateLog(ParticleSet& P) { return 0; } - } // namespace qmcplusplus diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFPrototype.h index b64214fc5..4a1f2d4ac 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFPrototype.h @@ -85,13 +85,6 @@ public: inline IndexType numOrbitals(const IndexType sid) { return spos_[sid]->size(); }; /** @} */ - /** @brief Returns log(Psi). Should be consistent with QMCPACK unwrapped TrialWavefunction. - * - * @param[in] P. Particle set. - * @return log(Psi). - */ - RealType evaluateLog(ParticleSet& P); - ////////////////////////////////////////////////////////////////////////////////////////////////////////// //These are convenience functions/wrappers to SPOSet calls. Idea being that observables just need // //to make calls to this object to build the auxiliary matrices required for fast derivative computation.// From 93957b9423c5d446259312474b3fe321acaf7038 Mon Sep 17 00:00:00 2001 From: rcclay Date: Tue, 18 Jan 2022 11:17:54 -0700 Subject: [PATCH 16/20] Uncomment TWFPrototype calls to increase coverage --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index c4c67eec0..2c61f2a6d 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -859,10 +859,10 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") std::vector> dB_gs; std::vector> dM_gs; std::vector tmp_gs; -// twf.getGSMatrix(B, B_gs); -// twf.getGSMatrix(matlist, M_gs); -// twf.invertMatrix(M_gs, minv); -// twf.buildX(minv, B_gs, X); + twf.getGSMatrix(B, B_gs); + twf.getGSMatrix(matlist, M_gs); + twf.invertMatrix(M_gs, minv); + twf.buildX(minv, B_gs, X); for (int id = 0; id < matlist.size(); id++) { // int ptclnum = twf.numParticles(id); @@ -891,18 +891,18 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") { for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.wipeMatrix(dB[idim]); -// twf.wipeMatrix(dM[idim]); + twf.wipeMatrix(dB[idim]); + twf.wipeMatrix(dM[idim]); } -// twf.getIonGradM(elec, ions, ionid, dM); + twf.getIonGradM(elec, ions, ionid, dM); // kinop->evaluateOneBodyOpMatrixForceDeriv(elec, ions, twf, ionid, dB); for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.getGSMatrix(dB[idim], dB_gs[idim]); -// twf.getGSMatrix(dM[idim], dM_gs[idim]); -// fkin_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); + twf.getGSMatrix(dB[idim], dB_gs[idim]); + twf.getGSMatrix(dM[idim], dM_gs[idim]); + fkin_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); } convertToReal(fkin_complex[ionid], fkin[ionid]); } @@ -910,7 +910,7 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") ValueType keval = 0.0; RealType keobs = 0.0; -// keval = twf.trAB(minv, B_gs); + keval = twf.trAB(minv, B_gs); convertToReal(keval, keobs); // CHECK(keobs == Approx(9.1821937928e+00)); #if defined(MIXED_PRECISION) From f178605c3384dd30d6929bbf24d239c89bd83367 Mon Sep 17 00:00:00 2001 From: rcclay Date: Tue, 18 Jan 2022 11:24:35 -0700 Subject: [PATCH 17/20] Move variable declarations inside loops --- src/QMCWaveFunctions/TWFPrototype.cpp | 56 +++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index 148b5db5f..ae04358c6 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -41,14 +41,14 @@ void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* s void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) { - IndexType ndets = spos_.size(); - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - for (IndexType i = 0; i < ndets; i++) + IndexType ngroups = spos_.size(); + for (IndexType i = 0; i < ngroups; i++) { + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; gid = groups_[i]; first = P.first(i); last = P.last(i); @@ -68,14 +68,14 @@ void TWFPrototype::getEGradELaplM(const ParticleSet& P, std::vector& gmat, std::vector& lmat) { - IndexType ndets = mvec.size(); - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - for (IndexType i = 0; i < ndets; i++) + IndexType ngroups = mvec.size(); + for (IndexType i = 0; i < ngroups; i++) { + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; gid = groups_[i]; first = P.first(i); last = P.last(i); @@ -93,14 +93,14 @@ void TWFPrototype::getIonGradM(const ParticleSet& P, const int iat, std::vector>& dmvec) { - IndexType ndets = dmvec[0].size(); - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - for (IndexType i = 0; i < ndets; i++) + IndexType ngroups = dmvec[0].size(); + for (IndexType i = 0; i < ngroups; i++) { + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; gid = groups_[i]; first = P.first(i); last = P.last(i); @@ -128,14 +128,14 @@ void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, std::vector>& dmvec, std::vector>& dlmat) { - IndexType ndets = dmvec[0].size(); - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - for (IndexType i = 0; i < ndets; i++) + IndexType ngroups = dmvec[0].size(); + for (IndexType i = 0; i < ngroups; i++) { + IndexType norbs = 0; + IndexType nptcls = 0; + IndexType gid = 0; + IndexType first = 0; + IndexType last = 0; gid = groups_[i]; first = P.first(i); last = P.last(i); From 89d0dda6818edfe955b0a3df9b087ea2391c15d9 Mon Sep 17 00:00:00 2001 From: rcclay Date: Tue, 18 Jan 2022 12:01:43 -0700 Subject: [PATCH 18/20] Change variable declarations and misc. cleanup --- src/QMCWaveFunctions/TWFPrototype.cpp | 67 ++++++++------------------- 1 file changed, 20 insertions(+), 47 deletions(-) diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFPrototype.cpp index ae04358c6..279c1fbec 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFPrototype.cpp @@ -33,9 +33,6 @@ void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* s { groups_.push_back(gid); spos_.push_back(spo); - IndexType first = P.first(gid); - IndexType last = P.last(gid); - IndexType norbs = spo->getOrbitalSetSize(); } } @@ -44,17 +41,11 @@ void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) IndexType ngroups = spos_.size(); for (IndexType i = 0; i < ngroups; i++) { - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - gid = groups_[i]; - first = P.first(i); - last = P.last(i); - nptcls = last - first; - norbs = spos_[i]->getOrbitalSetSize(); - mvec[i] = 0; + const IndexType gid = groups_[i]; + const IndexType first = P.first(i); + const IndexType last = P.last(i); + const IndexType nptcls = last - first; + const IndexType norbs = spos_[i]->getOrbitalSetSize(); GradMatrix_t tmpgmat; ValueMatrix_t tmplmat; tmpgmat.resize(nptcls, norbs); @@ -71,19 +62,11 @@ void TWFPrototype::getEGradELaplM(const ParticleSet& P, IndexType ngroups = mvec.size(); for (IndexType i = 0; i < ngroups; i++) { - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - gid = groups_[i]; - first = P.first(i); - last = P.last(i); - nptcls = last - first; - norbs = spos_[i]->getOrbitalSetSize(); - mvec[i] = 0; - gmat[i] = 0; - lmat[i] = 0; + const IndexType gid = groups_[i]; + const IndexType first = P.first(i); + const IndexType last = P.last(i); + const IndexType nptcls = last - first; + const IndexType norbs = spos_[i]->getOrbitalSetSize(); spos_[i]->evaluate_notranspose(P, first, last, mvec[i], gmat[i], lmat[i]); } } @@ -96,16 +79,11 @@ void TWFPrototype::getIonGradM(const ParticleSet& P, IndexType ngroups = dmvec[0].size(); for (IndexType i = 0; i < ngroups; i++) { - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - gid = groups_[i]; - first = P.first(i); - last = P.last(i); - nptcls = last - first; - norbs = spos_[i]->getOrbitalSetSize(); + const IndexType gid = groups_[i]; + const IndexType first = P.first(i); + const IndexType last = P.last(i); + const IndexType nptcls = last - first; + const IndexType norbs = spos_[i]->getOrbitalSetSize(); GradMatrix_t grad_phi; @@ -131,16 +109,11 @@ void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, IndexType ngroups = dmvec[0].size(); for (IndexType i = 0; i < ngroups; i++) { - IndexType norbs = 0; - IndexType nptcls = 0; - IndexType gid = 0; - IndexType first = 0; - IndexType last = 0; - gid = groups_[i]; - first = P.first(i); - last = P.last(i); - nptcls = last - first; - norbs = spos_[i]->getOrbitalSetSize(); + const IndexType gid = groups_[i]; + const IndexType first = P.first(i); + const IndexType last = P.last(i); + const IndexType nptcls = last - first; + const IndexType norbs = spos_[i]->getOrbitalSetSize(); GradMatrix_t grad_phi; HessMatrix_t grad_grad_phi; From ea9fc71d228fcc25bd86fccbf4907cd8b86cd8b4 Mon Sep 17 00:00:00 2001 From: rcclay Date: Wed, 19 Jan 2022 11:14:55 -0700 Subject: [PATCH 19/20] Rename TWFPrototype -> TWFFastDerivWrapper --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 6 ++-- src/QMCWaveFunctions/CMakeLists.txt | 2 +- .../Fermion/DiracDeterminant.cpp | 4 +-- .../Fermion/DiracDeterminant.h | 2 +- .../Fermion/DiracDeterminantBase.h | 4 +-- .../Fermion/DiracDeterminantBatched.cpp | 4 +-- .../Fermion/DiracDeterminantBatched.h | 4 +-- src/QMCWaveFunctions/Fermion/SlaterDet.cpp | 4 +-- src/QMCWaveFunctions/Fermion/SlaterDet.h | 4 +-- ...FPrototype.cpp => TWFFastDerivWrapper.cpp} | 28 +++++++++---------- .../{TWFPrototype.h => TWFFastDerivWrapper.h} | 12 ++++---- src/QMCWaveFunctions/TrialWaveFunction.cpp | 6 ++-- src/QMCWaveFunctions/TrialWaveFunction.h | 6 ++-- .../WaveFunctionComponent.cpp | 4 +-- src/QMCWaveFunctions/WaveFunctionComponent.h | 6 ++-- 15 files changed, 48 insertions(+), 48 deletions(-) rename src/QMCWaveFunctions/{TWFPrototype.cpp => TWFFastDerivWrapper.cpp} (85%) rename src/QMCWaveFunctions/{TWFPrototype.h => TWFFastDerivWrapper.h} (95%) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index 2c61f2a6d..057fb1838 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -20,7 +20,7 @@ #include "QMCHamiltonians/tests/MinimalHamiltonianPool.h" #include "ParticleIO/XMLParticleIO.h" #include "Utilities/RandomGenerator.h" -#include "QMCWaveFunctions/TWFPrototype.h" +#include "QMCWaveFunctions/TWFFastDerivWrapper.h" namespace qmcplusplus { @@ -770,9 +770,9 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") REQUIRE(psi != nullptr); //end incantation - TWFPrototype twf; + TWFFastDerivWrapper twf; - psi->initializeTWFPrototype(elec, twf); + psi->initializeTWFFastDerivWrapper(elec, twf); SPOSet::ValueVector_t values; SPOSet::GradVector_t dpsi; SPOSet::ValueVector_t d2psi; diff --git a/src/QMCWaveFunctions/CMakeLists.txt b/src/QMCWaveFunctions/CMakeLists.txt index 4d56f2af6..bb93070ca 100644 --- a/src/QMCWaveFunctions/CMakeLists.txt +++ b/src/QMCWaveFunctions/CMakeLists.txt @@ -169,7 +169,7 @@ set(FERMION_SRCS SPOSetBuilderFactory.cpp TrialWaveFunction.cpp TWFdispatcher.cpp - TWFPrototype.cpp + TWFFastDerivWrapper.cpp WaveFunctionFactory.cpp) if(ENABLE_CUDA) diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp index 523ef4f18..df3bc2135 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.cpp @@ -21,7 +21,7 @@ #include "CPU/SIMD/simd.hpp" #include "Numerics/DeterminantOperators.h" #include "Numerics/MatrixOperators.h" -#include "QMCWaveFunctions/TWFPrototype.h" +#include "QMCWaveFunctions/TWFFastDerivWrapper.h" namespace qmcplusplus { @@ -346,7 +346,7 @@ void DiracDeterminant::copyFromBuffer(ParticleSet& P, WFBufferType& buf } template -void DiracDeterminant::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +void DiracDeterminant::registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const { twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h index 5f97d5b68..98833a997 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminant.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminant.h @@ -78,7 +78,7 @@ public: /** Finds the SPOSet associated with this determinant, and registers it with WFN wrapper */ - void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const final; + void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const final; /** return the ratio only for the iat-th partcle move * @param P current configuration diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h index ca07774a4..d5940eca9 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBase.h @@ -85,9 +85,9 @@ public: inline void reportStatus(std::ostream& os) final {} - virtual void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override + virtual void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const override { - APP_ABORT("DiracDeterminantBase::registerTWFPrototype must be overridden\n"); + APP_ABORT("DiracDeterminantBase::registerTWFFastDerivWrapper must be overridden\n"); } // expose CPU interfaces using WaveFunctionComponent::evaluateDerivatives; diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp index 2ff5e6739..659e84145 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp @@ -16,7 +16,7 @@ #include "CPU/BLAS.hpp" #include "OhmmsPETE/OhmmsMatrix.h" #include "Numerics/MatrixOperators.h" -#include "QMCWaveFunctions/TWFPrototype.h" +#include "QMCWaveFunctions/TWFFastDerivWrapper.h" #include "CPU/SIMD/simd.hpp" #include @@ -958,7 +958,7 @@ void DiracDeterminantBatched::evaluateDerivatives(ParticleSet& P, } template -void DiracDeterminantBatched::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +void DiracDeterminantBatched::registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const { twf.addGroup(P, P.getGroupID(FirstIndex), Phi.get()); } diff --git a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h index 64c8aa4f2..bce47738e 100644 --- a/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h +++ b/src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.h @@ -30,7 +30,7 @@ namespace qmcplusplus { //forward declaration -class TWFPrototype; +class TWFFastDerivWrapper; template> class DiracDeterminantBatched : public DiracDeterminantBase @@ -212,7 +212,7 @@ public: void releaseResource(ResourceCollection& collection, const RefVectorWithLeader& wfc_list) const override; - void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override; + void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const override; /** cloning function * @param tqp target particleset * @param spo spo set diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp index ebaddecd5..e12be8c8b 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.cpp +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.cpp @@ -253,11 +253,11 @@ std::unique_ptr SlaterDet::makeClone(ParticleSet& tqp) co return myclone; } -void SlaterDet::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +void SlaterDet::registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const { for (int i = 0; i < Dets.size(); ++i) { - Dets[i]->registerTWFPrototype(P, twf); + Dets[i]->registerTWFFastDerivWrapper(P, twf); } } diff --git a/src/QMCWaveFunctions/Fermion/SlaterDet.h b/src/QMCWaveFunctions/Fermion/SlaterDet.h index 5493f84a8..6c2315e82 100644 --- a/src/QMCWaveFunctions/Fermion/SlaterDet.h +++ b/src/QMCWaveFunctions/Fermion/SlaterDet.h @@ -29,7 +29,7 @@ namespace qmcplusplus // then change SlaterDet to SlaterDet // and SlaterDeterminantWithBackflow to SlaterDet // and remove all virtuals and inline them -class TWFPrototype; +class TWFFastDerivWrapper; class SlaterDet : public WaveFunctionComponent { @@ -55,7 +55,7 @@ public: void reportStatus(std::ostream& os) override; - void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const override; + void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const override; LogValueType evaluateLog(const ParticleSet& P, ParticleSet::ParticleGradient_t& G, diff --git a/src/QMCWaveFunctions/TWFPrototype.cpp b/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp similarity index 85% rename from src/QMCWaveFunctions/TWFPrototype.cpp rename to src/QMCWaveFunctions/TWFFastDerivWrapper.cpp index 279c1fbec..3b45deba5 100644 --- a/src/QMCWaveFunctions/TWFPrototype.cpp +++ b/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp @@ -9,13 +9,13 @@ // File created by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories ////////////////////////////////////////////////////////////////////////////////////// -#include "QMCWaveFunctions/TWFPrototype.h" +#include "QMCWaveFunctions/TWFFastDerivWrapper.h" #include "Numerics/DeterminantOperators.h" #include namespace qmcplusplus { -TWFPrototype::IndexType TWFPrototype::getTWFGroupIndex(const IndexType gid) +TWFFastDerivWrapper::IndexType TWFFastDerivWrapper::getTWFGroupIndex(const IndexType gid) { IndexType return_group_index(-1); for (IndexType i = 0; i < groups_.size(); i++) @@ -27,7 +27,7 @@ TWFPrototype::IndexType TWFPrototype::getTWFGroupIndex(const IndexType gid) return return_group_index; } -void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* spo) +void TWFFastDerivWrapper::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* spo) { if (std::find(groups_.begin(), groups_.end(), gid) == groups_.end()) { @@ -36,7 +36,7 @@ void TWFPrototype::addGroup(const ParticleSet& P, const IndexType gid, SPOSet* s } } -void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) +void TWFFastDerivWrapper::getM(const ParticleSet& P, std::vector& mvec) { IndexType ngroups = spos_.size(); for (IndexType i = 0; i < ngroups; i++) @@ -54,7 +54,7 @@ void TWFPrototype::getM(const ParticleSet& P, std::vector& mvec) } } -void TWFPrototype::getEGradELaplM(const ParticleSet& P, +void TWFFastDerivWrapper::getEGradELaplM(const ParticleSet& P, std::vector& mvec, std::vector& gmat, std::vector& lmat) @@ -71,7 +71,7 @@ void TWFPrototype::getEGradELaplM(const ParticleSet& P, } } -void TWFPrototype::getIonGradM(const ParticleSet& P, +void TWFFastDerivWrapper::getIonGradM(const ParticleSet& P, const ParticleSet& source, const int iat, std::vector>& dmvec) @@ -100,7 +100,7 @@ void TWFPrototype::getIonGradM(const ParticleSet& P, } } -void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, +void TWFFastDerivWrapper::getIonGradIonGradELaplM(const ParticleSet& P, const ParticleSet& source, int iat, std::vector>& dmvec, @@ -135,7 +135,7 @@ void TWFPrototype::getIonGradIonGradELaplM(const ParticleSet& P, } } -TWFPrototype::ValueType TWFPrototype::computeGSDerivative(const std::vector& Minv, +TWFFastDerivWrapper::ValueType TWFFastDerivWrapper::computeGSDerivative(const std::vector& Minv, const std::vector& X, const std::vector& dM, const std::vector& dB) @@ -157,7 +157,7 @@ TWFPrototype::ValueType TWFPrototype::computeGSDerivative(const std::vector& M, std::vector& Minv) +void TWFFastDerivWrapper::invertMatrix(const std::vector& M, std::vector& Minv) { IndexType nspecies = M.size(); for (IndexType id = 0; id < nspecies; id++) @@ -168,7 +168,7 @@ void TWFPrototype::invertMatrix(const std::vector& M, std::vector } } -void TWFPrototype::buildX(const std::vector& Minv, +void TWFFastDerivWrapper::buildX(const std::vector& Minv, const std::vector& B, std::vector& X) { @@ -198,7 +198,7 @@ void TWFPrototype::buildX(const std::vector& Minv, } } -void TWFPrototype::wipeMatrix(std::vector& A) +void TWFFastDerivWrapper::wipeMatrix(std::vector& A) { for (IndexType id = 0; id < A.size(); id++) @@ -207,7 +207,7 @@ void TWFPrototype::wipeMatrix(std::vector& A) } } -TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, const std::vector& B) +TWFFastDerivWrapper::ValueType TWFFastDerivWrapper::trAB(const std::vector& A, const std::vector& B) { IndexType nspecies = A.size(); assert(A.size() == B.size()); @@ -229,7 +229,7 @@ TWFPrototype::ValueType TWFPrototype::trAB(const std::vector& A, return val; } -void TWFPrototype::getGSMatrix(const std::vector& A, std::vector& Aslice) +void TWFFastDerivWrapper::getGSMatrix(const std::vector& A, std::vector& Aslice) { IndexType nspecies = A.size(); Aslice.resize(nspecies); @@ -244,7 +244,7 @@ void TWFPrototype::getGSMatrix(const std::vector& A, std::vector< } -TWFPrototype::IndexType TWFPrototype::getRowM(const ParticleSet& P, const IndexType iel, ValueVector_t& val) +TWFFastDerivWrapper::IndexType TWFFastDerivWrapper::getRowM(const ParticleSet& P, const IndexType iel, ValueVector_t& val) { IndexType gid = P.getGroupID(iel); IndexType sid = getTWFGroupIndex(gid); diff --git a/src/QMCWaveFunctions/TWFPrototype.h b/src/QMCWaveFunctions/TWFFastDerivWrapper.h similarity index 95% rename from src/QMCWaveFunctions/TWFPrototype.h rename to src/QMCWaveFunctions/TWFFastDerivWrapper.h index 4a1f2d4ac..67954eae5 100644 --- a/src/QMCWaveFunctions/TWFPrototype.h +++ b/src/QMCWaveFunctions/TWFFastDerivWrapper.h @@ -10,8 +10,8 @@ ////////////////////////////////////////////////////////////////////////////////////// -#ifndef QMCPLUSPLUS_TWFPROTOTYPE_H -#define QMCPLUSPLUS_TWFPROTOTYPE_H +#ifndef QMCPLUSPLUS_TWFFASTDERIVWRAPPER_H +#define QMCPLUSPLUS_TWFFASTDERIVWRAPPER_H #include "QMCWaveFunctions/WaveFunctionComponent.h" #include "QMCWaveFunctions/SPOSet.h" @@ -20,14 +20,14 @@ namespace qmcplusplus { /** - * TWFPrototype is a wrapper class for TrialWavefunction that provides separate and low level access to the Jastrow and + * TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level access to the Jastrow and * SPOSet objects. This is so that observables can be recast in matrix form and their derivatives taken efficiently. * Currently this is hard coded for ground state slater jastrow wave functions, but generalization to * arbitrary occupations and multideterminants are straightforward and will come online as the code is tested and validated. * * Please see : J. Chem. Phys. 144, 194105 (2016) https://doi.org/10.1063/1.4948778 for implementation details and formalism. */ -class TWFPrototype +class TWFFastDerivWrapper { public: using ValueMatrix_t = SPOSet::ValueMatrix_t; @@ -44,7 +44,7 @@ public: /** @brief Add a particle group. * * Here, a "group" corresponds to a subset of particles which are antisymmetric with - * respect to eachother. TWFPrototype ensures that there is a binding between the groupid + * respect to eachother. TWFFastDerivWrapper ensures that there is a binding between the groupid * in ParticleSet and the SPOSet associated with that particle group. This function stores * the ParticleSet groupid and SPOSet in a vector for lookup and communication with QMCPACK conventions, * but is agnostic to the order of group registration or evaluation. @@ -60,7 +60,7 @@ public: /** @brief Takes particle set groupID and returns the TWF internal index for it. * * ParticleSet groups can be registered in whichever order. However, the internal indexing - * of TWFPrototype keeps track on a first-come, first serve basis. That is, if I register + * of TWFFastDerivWrapper keeps track on a first-come, first serve basis. That is, if I register * particle groups 3, 1, and 0 in that order, then the internal indexing goes like * 0->3, 1->1, 2->0. Thus, this function looks up where in the internal indexing scheme * ParticleSet gid is located. This is necessary, since the matrix list data structures follow diff --git a/src/QMCWaveFunctions/TrialWaveFunction.cpp b/src/QMCWaveFunctions/TrialWaveFunction.cpp index 04adc517e..c0cc3972d 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.cpp +++ b/src/QMCWaveFunctions/TrialWaveFunction.cpp @@ -1340,7 +1340,7 @@ RefVector TrialWaveFunction::extractLRefList( return l_list; } -void TrialWaveFunction::initializeTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +void TrialWaveFunction::initializeTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const { for (int i = 0; i < Z.size(); ++i) { @@ -1349,8 +1349,8 @@ void TrialWaveFunction::initializeTWFPrototype(const ParticleSet& P, TWFPrototyp //OK, so this is a hack only for SlaterDeterminant objects. //Needs a bit of logic and protection before this reaches production. //SlaterDet* det = dynamic_cast(Z[i].get()); - //det->registerTWFPrototype(P, twf); - Z[i]->registerTWFPrototype(P,twf); + //det->registerTWFFastDerivWrapper(P, twf); + Z[i]->registerTWFFastDerivWrapper(P,twf); } else //Is Jastrow, so do nothing right now. {} diff --git a/src/QMCWaveFunctions/TrialWaveFunction.h b/src/QMCWaveFunctions/TrialWaveFunction.h index 9590bf7fa..83a5a4a7b 100644 --- a/src/QMCWaveFunctions/TrialWaveFunction.h +++ b/src/QMCWaveFunctions/TrialWaveFunction.h @@ -29,7 +29,7 @@ #include "Utilities/TimerManager.h" #include "type_traits/template_types.hpp" #include "Containers/MinimalContainers/RecordArray.hpp" -#include "QMCWaveFunctions/TWFPrototype.h" +#include "QMCWaveFunctions/TWFFastDerivWrapper.h" #ifdef QMC_CUDA #include "type_traits/CUDATypes.h" #endif @@ -171,7 +171,7 @@ public: /** Initialize a TWF wrapper for fast derivative evaluation */ - void initializeTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const; + void initializeTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const; /** evalaute the log (internally gradients and laplacian) of the trial wavefunction. gold reference */ RealType evaluateLog(ParticleSet& P); @@ -544,7 +544,7 @@ private: std::vector> Z; /// For now, TrialWaveFunction will own the wrapper. - TWFPrototype twf_prototype; + TWFFastDerivWrapper twf_prototype; /// timers at TrialWaveFunction function call level TimerList_t TWF_timers_; /// timers at WaveFunctionComponent function call level diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.cpp b/src/QMCWaveFunctions/WaveFunctionComponent.cpp index c39b25fb9..1be1705ba 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.cpp +++ b/src/QMCWaveFunctions/WaveFunctionComponent.cpp @@ -226,10 +226,10 @@ void WaveFunctionComponent::evaluateDerivRatios(VirtualParticleSet& VP, evaluateRatios(VP, ratios); } -void WaveFunctionComponent::registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const +void WaveFunctionComponent::registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const { std::ostringstream o; - o << "WaveFunctionComponent::registerTWFPrototype is not implemented by " << ClassName; + o << "WaveFunctionComponent::registerTWFFastDerivWrapper is not implemented by " << ClassName; APP_ABORT(o.str()); } diff --git a/src/QMCWaveFunctions/WaveFunctionComponent.h b/src/QMCWaveFunctions/WaveFunctionComponent.h index 5e0d1611c..ae15f4a37 100644 --- a/src/QMCWaveFunctions/WaveFunctionComponent.h +++ b/src/QMCWaveFunctions/WaveFunctionComponent.h @@ -50,7 +50,7 @@ struct NLjob class WaveFunctionComponent; struct DiffWaveFunctionComponent; class ResourceCollection; -class TWFPrototype; +class TWFFastDerivWrapper; /**@defgroup WaveFunctionComponent group * @brief Classes which constitute a many-body trial wave function * @@ -170,9 +170,9 @@ public: /** print the state, e.g., optimizables */ virtual void reportStatus(std::ostream& os) = 0; - /** Register the component with the TWFPrototype wrapper. + /** Register the component with the TWFFastDerivWrapper wrapper. */ - virtual void registerTWFPrototype(const ParticleSet& P, TWFPrototype& twf) const; + virtual void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const; /** evaluate the value of the WaveFunctionComponent from scratch * \param[in] P active ParticleSet From 6d412c86be2c8b620a80cce7b98e15caa4741d6c Mon Sep 17 00:00:00 2001 From: rcclay Date: Wed, 19 Jan 2022 11:54:09 -0700 Subject: [PATCH 20/20] Fix function multiplicities and doc line --- src/QMCHamiltonians/tests/test_ion_derivs.cpp | 30 +++++++++---------- src/QMCWaveFunctions/TWFFastDerivWrapper.cpp | 6 ++-- src/QMCWaveFunctions/TWFFastDerivWrapper.h | 8 ++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/QMCHamiltonians/tests/test_ion_derivs.cpp b/src/QMCHamiltonians/tests/test_ion_derivs.cpp index 057fb1838..29848711b 100644 --- a/src/QMCHamiltonians/tests/test_ion_derivs.cpp +++ b/src/QMCHamiltonians/tests/test_ion_derivs.cpp @@ -859,9 +859,9 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") std::vector> dB_gs; std::vector> dM_gs; std::vector tmp_gs; - twf.getGSMatrix(B, B_gs); - twf.getGSMatrix(matlist, M_gs); - twf.invertMatrix(M_gs, minv); + twf.getGSMatrices(B, B_gs); + twf.getGSMatrices(matlist, M_gs); + twf.invertMatrices(M_gs, minv); twf.buildX(minv, B_gs, X); for (int id = 0; id < matlist.size(); id++) { @@ -891,8 +891,8 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") { for (int idim = 0; idim < OHMMS_DIM; idim++) { - twf.wipeMatrix(dB[idim]); - twf.wipeMatrix(dM[idim]); + twf.wipeMatrices(dB[idim]); + twf.wipeMatrices(dM[idim]); } twf.getIonGradM(elec, ions, ionid, dM); @@ -900,8 +900,8 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") for (int idim = 0; idim < OHMMS_DIM; idim++) { - twf.getGSMatrix(dB[idim], dB_gs[idim]); - twf.getGSMatrix(dM[idim], dM_gs[idim]); + twf.getGSMatrices(dB[idim], dB_gs[idim]); + twf.getGSMatrices(dM[idim], dM_gs[idim]); fkin_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); } convertToReal(fkin_complex[ionid], fkin[ionid]); @@ -937,11 +937,11 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") app_log() << " Evaluated. Calling evaluteOneBodyOpMatrix\n"; -// twf.wipeMatrix(B); -// twf.wipeMatrix(B_gs); -// twf.wipeMatrix(X); +// twf.wipeMatrices(B); +// twf.wipeMatrices(B_gs); +// twf.wipeMatrices(X); // nlppop->evaluateOneBodyOpMatrix(elec, twf, B); -// twf.getGSMatrix(B, B_gs); +// twf.getGSMatrices(B, B_gs); // twf.buildX(minv, B_gs, X); ValueType nlpp = 0.0; @@ -959,8 +959,8 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") { for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.wipeMatrix(dB[idim]); -// twf.wipeMatrix(dM[idim]); +// twf.wipeMatrices(dB[idim]); +// twf.wipeMatrices(dM[idim]); } // twf.getIonGradM(elec, ions, ionid, dM); @@ -968,8 +968,8 @@ TEST_CASE("Eloc_Derivatives:proto_sd_noj", "[hamiltonian]") for (int idim = 0; idim < OHMMS_DIM; idim++) { -// twf.getGSMatrix(dB[idim], dB_gs[idim]); -// twf.getGSMatrix(dM[idim], dM_gs[idim]); +// twf.getGSMatrices(dB[idim], dB_gs[idim]); +// twf.getGSMatrices(dM[idim], dM_gs[idim]); // fnlpp_complex[ionid][idim] = twf.computeGSDerivative(minv, X, dM_gs[idim], dB_gs[idim]); } convertToReal(fnlpp_complex[ionid], fnlpp[ionid]); diff --git a/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp b/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp index 3b45deba5..a26eb645c 100644 --- a/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp +++ b/src/QMCWaveFunctions/TWFFastDerivWrapper.cpp @@ -157,7 +157,7 @@ TWFFastDerivWrapper::ValueType TWFFastDerivWrapper::computeGSDerivative(const st return dval; } -void TWFFastDerivWrapper::invertMatrix(const std::vector& M, std::vector& Minv) +void TWFFastDerivWrapper::invertMatrices(const std::vector& M, std::vector& Minv) { IndexType nspecies = M.size(); for (IndexType id = 0; id < nspecies; id++) @@ -198,7 +198,7 @@ void TWFFastDerivWrapper::buildX(const std::vector& Minv, } } -void TWFFastDerivWrapper::wipeMatrix(std::vector& A) +void TWFFastDerivWrapper::wipeMatrices(std::vector& A) { for (IndexType id = 0; id < A.size(); id++) @@ -229,7 +229,7 @@ TWFFastDerivWrapper::ValueType TWFFastDerivWrapper::trAB(const std::vector& A, std::vector& Aslice) +void TWFFastDerivWrapper::getGSMatrices(const std::vector& A, std::vector& Aslice) { IndexType nspecies = A.size(); Aslice.resize(nspecies); diff --git a/src/QMCWaveFunctions/TWFFastDerivWrapper.h b/src/QMCWaveFunctions/TWFFastDerivWrapper.h index 67954eae5..f0ad56097 100644 --- a/src/QMCWaveFunctions/TWFFastDerivWrapper.h +++ b/src/QMCWaveFunctions/TWFFastDerivWrapper.h @@ -160,7 +160,7 @@ public: * @param[in,out] Aslice square matrices consistent with a ground state occupation. * @return Void */ - void getGSMatrix(const std::vector& A, std::vector& Aslice); + void getGSMatrices(const std::vector& A, std::vector& Aslice); /** @brief Calculates derivative of observable via Tr[M^{-1} dB - X * dM ]. Consistent with ground state occupation. * @@ -185,9 +185,9 @@ public: * @param[in,out] Minv. The species by species list of inverted matrices from M. * @return Void. */ - void invertMatrix(const std::vector& M, std::vector& Minv); + void invertMatrices(const std::vector& M, std::vector& Minv); - /** @brief Helper function that inverts all slater matrices in our species list. + /** @brief Build the auxiliary X=M^-1 B M^-1 matrix. * * @param[in] Minv. List of slater matrix inverses M^-1 for a given occupation. * @param[in] B. Observable auxiliary matrix for a given occupation. @@ -203,7 +203,7 @@ public: * @param[in,out] A. The list of matrices to be zeroed out. After call, A is all zeros. * @return Void. */ - void wipeMatrix(std::vector& A); + void wipeMatrices(std::vector& A); /** @brief Returns Tr(A*B). Actually, we assume a block diagonal structure, so this is * really Sum_i Tr(A_i*B_i), where i is the species index.