Skip to content

Commit

Permalink
Rename SPOSetT and connect the rest.
Browse files Browse the repository at this point in the history
  • Loading branch information
ye-luo committed Nov 9, 2023
1 parent d6b8a9e commit 198909f
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 286 deletions.
3 changes: 1 addition & 2 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ struct QMCTraits
{
enum
{
DIM = OHMMS_DIM,
DIM_VGL = OHMMS_DIM + 2 // Value(1) + Gradients(OHMMS_DIM) + Laplacian(1)
DIM = OHMMS_DIM
};
using QTBase = QMCTypes<OHMMS_PRECISION, DIM>;
using QTFull = QMCTypes<OHMMS_PRECISION_FULL, DIM>;
Expand Down
2 changes: 1 addition & 1 deletion src/QMCWaveFunctions/BsplineFactory/SplineR2R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void SplineR2R<ST>::applyRotation(const ValueMatrix& rot_mat, bool use_stored_co
for (IndexType j = 0; j < OrbitalSetSize; j++)
{
const auto cur_elem = Nsplines * i + j;
FullPrecValueType newval{0.};
QTFull::ValueType newval{0.};
for (IndexType k = 0; k < OrbitalSetSize; k++)
{
const auto index = i * Nsplines + k;
Expand Down
6 changes: 3 additions & 3 deletions src/QMCWaveFunctions/Fermion/DiracDeterminantBatched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void DiracDeterminantBatched<DET_ENGINE>::mw_ratioGrad(const RefVectorWithLeader

auto psiMinv_row_dev_ptr_list = DET_ENGINE::mw_getInvRow(engine_list, WorkingIndex, !Phi->isOMPoffload());

phi_vgl_v.resize(DIM_VGL, wfc_list.size(), NumOrbitals);
phi_vgl_v.resize(SPOSet::DIM_VGL, wfc_list.size(), NumOrbitals);
ratios_local.resize(wfc_list.size());
grad_new_local.resize(wfc_list.size());

Expand Down Expand Up @@ -391,7 +391,7 @@ void DiracDeterminantBatched<DET_ENGINE>::mw_ratioGradWithSpin(

auto psiMinv_row_dev_ptr_list = DET_ENGINE::mw_getInvRow(engine_list, WorkingIndex, !Phi->isOMPoffload());

phi_vgl_v.resize(DIM_VGL, wfc_list.size(), NumOrbitals);
phi_vgl_v.resize(SPOSet::DIM_VGL, wfc_list.size(), NumOrbitals);
ratios_local.resize(wfc_list.size());
grad_new_local.resize(wfc_list.size());
spingrad_new_local.resize(wfc_list.size());
Expand Down Expand Up @@ -784,7 +784,7 @@ void DiracDeterminantBatched<DET_ENGINE>::mw_calcRatio(const RefVectorWithLeader

auto psiMinv_row_dev_ptr_list = DET_ENGINE::mw_getInvRow(engine_list, WorkingIndex, !Phi->isOMPoffload());

phi_vgl_v.resize(DIM_VGL, wfc_list.size(), NumOrbitals);
phi_vgl_v.resize(SPOSet::DIM_VGL, wfc_list.size(), NumOrbitals);
ratios_local.resize(wfc_list.size());
grad_new_local.resize(wfc_list.size());

Expand Down
5 changes: 4 additions & 1 deletion src/QMCWaveFunctions/Fermion/SlaterDetBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class BackflowTransformation;
class DiracDeterminantBase;
class MultiSlaterDetTableMethod;
struct CSFData;
class SPOSet;

template<typename VALUE>
class SPOSetT;
using SPOSet = SPOSetT<QMCTraits::QTBase::ValueType>;
class SPOSetBuilder;
class SPOSetBuilderFactory;
struct ci_configuration;
Expand Down
440 changes: 220 additions & 220 deletions src/QMCWaveFunctions/SPOSet.cpp

Large diffs are not rendered by default.

131 changes: 74 additions & 57 deletions src/QMCWaveFunctions/SPOSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ namespace qmcplusplus
{
class ResourceCollection;

template<typename Value>
class SPOSet;
template<typename VALUE>
class SPOSetT;
namespace testing
{
template<typename Value>
opt_variables_type& getMyVars(SPOSet<Value>& spo);
template<typename VALUE>
opt_variables_type& getMyVars(SPOSetT<VALUE>& spo);
}


Expand All @@ -46,36 +46,47 @@ opt_variables_type& getMyVars(SPOSet<Value>& spo);
* SPOSet stands for S(ingle)P(article)O(rbital)Set which contains
* a number of single-particle orbitals with capabilities of evaluating \f$ \psi_j({\bf r}_i)\f$
*/
template<typename Value>
class SPOSet
template<typename VALUE>
class SPOSetT
{
public:
using Grad = typename OrbitalSetTraits<Value>::GradType;
using Complex = std::complex<typename OrbitalSetTraits<Value>::RealType>;
enum
{
DIM = OHMMS_DIM,
DIM_VGL = OHMMS_DIM + 2 // Value(1) + Gradients(OHMMS_DIM) + Laplacian(1)
};
using PosType = QMCTraits::QTBase::PosType;
using IndexType = QMCTraits::IndexType;
using ValueVector = typename OrbitalSetTraits<Value>::ValueVector;
using ValueMatrix = typename OrbitalSetTraits<Value>::ValueMatrix;
using GradVector = typename OrbitalSetTraits<Value>::GradVector;
using GradMatrix = typename OrbitalSetTraits<Value>::GradMatrix;
using HessVector = typename OrbitalSetTraits<Value>::HessVector;
using HessMatrix = typename OrbitalSetTraits<Value>::HessMatrix;
using GGGVector = typename OrbitalSetTraits<Value>::GradHessVector;
using GGGMatrix = typename OrbitalSetTraits<Value>::GradHessMatrix;
using SPOMap = std::map<std::string, const std::unique_ptr<const SPOSet>>;
using RealType = typename OrbitalSetTraits<VALUE>::RealType;
using Complex = std::complex<RealType>;
using ComplexType = Complex;
using Value = VALUE;
using ValueType = Value;
using Grad = typename OrbitalSetTraits<VALUE>::GradType;
using GradType = Grad;
using ValueVector = typename OrbitalSetTraits<VALUE>::ValueVector;
using ValueMatrix = typename OrbitalSetTraits<VALUE>::ValueMatrix;
using GradVector = typename OrbitalSetTraits<VALUE>::GradVector;
using GradMatrix = typename OrbitalSetTraits<VALUE>::GradMatrix;
using HessVector = typename OrbitalSetTraits<VALUE>::HessVector;
using HessMatrix = typename OrbitalSetTraits<VALUE>::HessMatrix;
using GGGVector = typename OrbitalSetTraits<VALUE>::GradHessVector;
using GGGMatrix = typename OrbitalSetTraits<VALUE>::GradHessMatrix;
using SPOMap = std::map<std::string, const std::unique_ptr<const SPOSetT>>;
using OffloadMWVGLArray = Array<Value, 3, OffloadPinnedAllocator<Value>>; // [VGL, walker, Orbs]
using OffloadMWVArray = Array<Value, 2, OffloadPinnedAllocator<Value>>; // [walker, Orbs]
template<typename DT>
using OffloadMatrix = Matrix<DT, OffloadPinnedAllocator<DT>>;
using QTFull = QMCTraits::QTFull;

/** constructor */
SPOSet(const std::string& my_name);
SPOSetT(const std::string& my_name);

/** destructor
*
* Derived class destructor needs to pay extra attention to freeing memory shared among clones of SPOSet.
*/
virtual ~SPOSet() = default;
virtual ~SPOSetT() = default;

/** return the size of the orbital set
* Ye: this needs to be replaced by getOrbitalSetSize();
Expand Down Expand Up @@ -143,40 +154,41 @@ class SPOSet
/** Evaluate the derivative of the optimized orbitals with respect to the parameters
* this is used only for MSD, to be refined for better serving both single and multi SD
*/
virtual void evaluateDerivatives(ParticleSet& P,
const opt_variables_type& optvars,
Vector<Value>& dlogpsi,
Vector<Value>& dhpsioverpsi,
const Value& psiCurrent, //FIXME, why is this full precision as in evaluateDerivativesWF
const std::vector<Value>& Coeff,
const std::vector<size_t>& C2node_up,
const std::vector<size_t>& C2node_dn,
const ValueVector& detValues_up,
const ValueVector& detValues_dn,
const GradMatrix& grads_up,
const GradMatrix& grads_dn,
const ValueMatrix& lapls_up,
const ValueMatrix& lapls_dn,
const ValueMatrix& M_up,
const ValueMatrix& M_dn,
const ValueMatrix& Minv_up,
const ValueMatrix& Minv_dn,
const GradMatrix& B_grad,
const ValueMatrix& B_lapl,
const std::vector<int>& detData_up,
const size_t N1,
const size_t N2,
const size_t NP1,
const size_t NP2,
const std::vector<std::vector<int>>& lookup_tbl);
virtual void evaluateDerivatives(
ParticleSet& P,
const opt_variables_type& optvars,
Vector<Value>& dlogpsi,
Vector<Value>& dhpsioverpsi,
const Value& psiCurrent, //FIXME, why is this full precision as in evaluateDerivativesWF
const std::vector<Value>& Coeff,
const std::vector<size_t>& C2node_up,
const std::vector<size_t>& C2node_dn,
const ValueVector& detValues_up,
const ValueVector& detValues_dn,
const GradMatrix& grads_up,
const GradMatrix& grads_dn,
const ValueMatrix& lapls_up,
const ValueMatrix& lapls_dn,
const ValueMatrix& M_up,
const ValueMatrix& M_dn,
const ValueMatrix& Minv_up,
const ValueMatrix& Minv_dn,
const GradMatrix& B_grad,
const ValueMatrix& B_lapl,
const std::vector<int>& detData_up,
const size_t N1,
const size_t N2,
const size_t NP1,
const size_t NP2,
const std::vector<std::vector<int>>& lookup_tbl);

/** Evaluate the derivative of the optimized orbitals with respect to the parameters
* this is used only for MSD, to be refined for better serving both single and multi SD
*/
virtual void evaluateDerivativesWF(ParticleSet& P,
const opt_variables_type& optvars,
Vector<Value>& dlogpsi,
const QMCTraits::QTFull::ValueType& psiCurrent, //FIXME it is still a compile time type
const QTFull::ValueType& psiCurrent, //FIXME it is still a compile time type
const std::vector<Value>& Coeff,
const std::vector<size_t>& C2node_up,
const std::vector<size_t>& C2node_dn,
Expand Down Expand Up @@ -233,7 +245,7 @@ class SPOSet
* @param invRow_ptr_list a list of pointers to the rows of inverse slater matrix corresponding to the particles moved virtually
* @param ratios_list a list of returning determinant ratios
*/
virtual void mw_evaluateDetRatios(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateDetRatios(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<const VirtualParticleSet>& vp_list,
const RefVector<ValueVector>& psi_list,
const std::vector<const Value*>& invRow_ptr_list,
Expand Down Expand Up @@ -269,7 +281,7 @@ class SPOSet
* @param iat active particle
* @param psi_v_list the list of value vector pointers in a walker batch
*/
virtual void mw_evaluateValue(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateValue(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
const RefVector<ValueVector>& psi_v_list) const;
Expand All @@ -282,7 +294,7 @@ class SPOSet
* @param dpsi_v_list the list of gradient vector pointers in a walker batch
* @param d2psi_v_list the list of laplacian vector pointers in a walker batch
*/
virtual void mw_evaluateVGL(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateVGL(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
const RefVector<ValueVector>& psi_v_list,
Expand All @@ -299,7 +311,7 @@ class SPOSet
* @param mw_dspin is a dual matrix of spin gradients [nw][norb]
* Note that the device side of mw_dspin is up to date
*/
virtual void mw_evaluateVGLWithSpin(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateVGLWithSpin(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
const RefVector<ValueVector>& psi_v_list,
Expand All @@ -315,7 +327,7 @@ class SPOSet
* @param phi_vgl_v orbital values, gradients and laplacians of all the walkers
* @param psi_ratio_grads_v determinant ratio and grads of all the walkers
*/
virtual void mw_evaluateVGLandDetRatioGrads(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateVGLandDetRatioGrads(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
const std::vector<const Value*>& invRow_ptr_list,
Expand All @@ -334,7 +346,7 @@ class SPOSet
* @param grads, spatial gradients of all walkers
* @param spingrads, spin gradients of all walkers
*/
virtual void mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluateVGLandDetRatioGradsWithSpin(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
const std::vector<const Value*>& invRow_ptr_list,
Expand Down Expand Up @@ -422,7 +434,7 @@ class SPOSet
ValueMatrix& d2logdet,
ValueMatrix& dspinlogdet);

virtual void mw_evaluate_notranspose(const RefVectorWithLeader<SPOSet>& spo_list,
virtual void mw_evaluate_notranspose(const RefVectorWithLeader<SPOSetT>& spo_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int first,
int last,
Expand Down Expand Up @@ -524,16 +536,16 @@ class SPOSet

/** acquire a shared resource from collection
*/
virtual void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const {}
virtual void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSetT>& spo_list) const {}

/** return a shared resource to collection
*/
virtual void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const {}
virtual void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSetT>& spo_list) const {}

/** make a clone of itself
* every derived class must implement this to have threading working correctly.
*/
[[noreturn]] virtual std::unique_ptr<SPOSet<Value>> makeClone() const;
[[noreturn]] virtual std::unique_ptr<SPOSetT<VALUE>> makeClone() const;

/** Used only by cusp correction in AOS LCAO.
* Ye: the SoA LCAO moves all this responsibility to the builder.
Expand Down Expand Up @@ -562,8 +574,13 @@ class SPOSet
/// Optimizable variables
opt_variables_type myVars;

friend opt_variables_type& testing::getMyVars<Value>(SPOSet<Value>& spo);
friend opt_variables_type& testing::getMyVars<VALUE>(SPOSetT<VALUE>& spo);
};

extern template class SPOSetT<QMCTraits::QTBase::RealType>;
extern template class SPOSetT<QMCTraits::QTBase::ComplexType>;

using SPOSet = SPOSetT<QMCTraits::QTBase::ValueType>;
using SPOSetPtr = SPOSet*;
} // namespace qmcplusplus
#endif
3 changes: 2 additions & 1 deletion src/QMCWaveFunctions/tests/test_RotatedSPOs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ TEST_CASE("RotatedSPOs construct delta matrix", "[wavefunction]")

namespace testing
{
opt_variables_type& getMyVars(SPOSet& rot) { return rot.myVars; }
template<typename Value>
opt_variables_type& getMyVars(SPOSetT<Value>& rot) { return rot.myVars; }
opt_variables_type& getMyVarsFull(RotatedSPOs& rot) { return rot.myVarsFull; }
std::vector<std::vector<QMCTraits::RealType>>& getHistoryParams(RotatedSPOs& rot) { return rot.history_params_; }
} // namespace testing
Expand Down
2 changes: 1 addition & 1 deletion src/QMCWaveFunctions/tests/test_einset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ TEST_CASE("Einspline SPO from HDF diamond_2x1x1 5 electrons", "[wavefunction]")
std::vector<const SPOSet::ValueType*> inv_row_ptr(nw, inv_row.device_data());

SPOSet::OffloadMWVGLArray phi_vgl_v;
phi_vgl_v.resize(QMCTraits::DIM_VGL, nw, 5);
phi_vgl_v.resize(SPOSet::DIM_VGL, nw, 5);
spo->mw_evaluateVGLandDetRatioGrads(spo_list, p_list, 0, inv_row_ptr, phi_vgl_v, ratio_v, grads_v);
#if !defined(QMC_COMPLEX)
CHECK(std::real(ratio_v[0]) == Approx(0.2365307168));
Expand Down

0 comments on commit 198909f

Please sign in to comment.