QMCPACK
LCAOrbitalSet.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by:
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_SOA_LINEARCOMIBINATIONORBITALSET_TEMP_H
14 #define QMCPLUSPLUS_SOA_LINEARCOMIBINATIONORBITALSET_TEMP_H
15 
16 #include <memory>
19 
22 
23 namespace qmcplusplus
24 {
25 /** class to handle linear combinations of basis orbitals used to evaluate the Dirac determinants.
26  *
27  * SoA verson of LCOrtbitalSet
28  * Localized basis set is always real
29  */
30 struct LCAOrbitalSet : public SPOSet
31 {
32 public:
38 
39  ///pointer to the basis set
40  std::unique_ptr<basis_type> myBasisSet;
41  /// pointer to matrix containing the coefficients
42  std::shared_ptr<OffloadValueMatrix> C;
43 
44  /** constructor
45  * @param my_name name of the SPOSet object
46  * @param bs pointer to the BasisSet
47  * @param norb number of orbitals
48  * @param identity if true, the MO coefficients matrix is identity
49  */
50  LCAOrbitalSet(const std::string& my_name,
51  std::unique_ptr<basis_type>&& bs,
52  size_t norbs,
53  bool identity,
54  bool use_offload);
55 
56  LCAOrbitalSet(const LCAOrbitalSet& in);
57 
58  bool isOMPoffload() const override { return useOMPoffload_; }
59 
60  std::string getClassName() const final { return "LCAOrbitalSet"; }
61 
62  bool isRotationSupported() const final { return true; }
63 
64  bool hasIonDerivs() const final { return true; }
65 
66  std::unique_ptr<SPOSet> makeClone() const final;
67 
68  void storeParamsBeforeRotation() final { C_copy = std::make_shared<OffloadValueMatrix>(*C); }
69 
70  void applyRotation(const ValueMatrix& rot_mat, bool use_stored_copy) final;
71 
72  /** set the OrbitalSetSize and Identity=false and initialize internal storages
73  */
74  void setOrbitalSetSize(int norbs) final;
75 
76  /** return the size of the basis set
77  */
78  int getBasisSetSize() const { return (myBasisSet == nullptr) ? 0 : myBasisSet->getBasisSetSize(); }
79 
80  bool isIdentity() const { return Identity; };
81 
82  /** check consistency between Identity and C
83  *
84  */
85  void checkObject() const final;
86 
87  /** update C on device
88  */
89  void finalizeConstruction() override;
90 
91  void evaluateValue(const ParticleSet& P, int iat, ValueVector& psi) final;
92 
93  void evaluateVGL(const ParticleSet& P, int iat, ValueVector& psi, GradVector& dpsi, ValueVector& d2psi) final;
94 
95  void mw_evaluateValue(const RefVectorWithLeader<SPOSet>& spo_list,
96  const RefVectorWithLeader<ParticleSet>& P_list,
97  int iat,
98  const RefVector<ValueVector>& psi_v_list) const final;
99 
100  void mw_evaluateVGL(const RefVectorWithLeader<SPOSet>& spo_list,
101  const RefVectorWithLeader<ParticleSet>& P_list,
102  int iat,
103  const RefVector<ValueVector>& psi_v_list,
104  const RefVector<GradVector>& dpsi_v_list,
105  const RefVector<ValueVector>& d2psi_v_list) const final;
106 
107  void mw_evaluateDetRatios(const RefVectorWithLeader<SPOSet>& spo_list,
108  const RefVectorWithLeader<const VirtualParticleSet>& vp_list,
109  const RefVector<ValueVector>& psi_list,
110  const std::vector<const ValueType*>& invRow_ptr_list,
111  std::vector<std::vector<ValueType>>& ratios_list) const final;
112 
113  void evaluateDetRatios(const VirtualParticleSet& VP,
114  ValueVector& psi,
115  const ValueVector& psiinv,
116  std::vector<ValueType>& ratios) final;
117 
119  const RefVectorWithLeader<ParticleSet>& P_list,
120  int iat,
121  const std::vector<const ValueType*>& invRow_ptr_list,
122  OffloadMWVGLArray& phi_vgl_v,
123  std::vector<ValueType>& ratios,
124  std::vector<GradType>& grads) const final;
125 
126  void evaluateVGH(const ParticleSet& P, int iat, ValueVector& psi, GradVector& dpsi, HessVector& grad_grad_psi) final;
127 
128  void evaluateVGHGH(const ParticleSet& P,
129  int iat,
130  ValueVector& psi,
131  GradVector& dpsi,
132  HessVector& grad_grad_psi,
133  GGGVector& grad_grad_grad_psi) final;
134 
135  void evaluate_notranspose(const ParticleSet& P,
136  int first,
137  int last,
138  ValueMatrix& logdet,
139  GradMatrix& dlogdet,
140  ValueMatrix& d2logdet) final;
141 
142  void evaluate_notranspose(const ParticleSet& P,
143  int first,
144  int last,
145  ValueMatrix& logdet,
146  GradMatrix& dlogdet,
147  HessMatrix& grad_grad_logdet) final;
148 
149  void evaluate_notranspose(const ParticleSet& P,
150  int first,
151  int last,
152  ValueMatrix& logdet,
153  GradMatrix& dlogdet,
154  HessMatrix& grad_grad_logdet,
155  GGGMatrix& grad_grad_grad_logdet) final;
156 
157  //NOTE: The data types get complicated here, so here's an overview of the
158  // data types associated with ionic derivatives, and how to get their data.
159  //
160  //NOTE: These data structures hold the data for one particular ion, and so the ID is implicit.
161  // It's up to the user to keep track of which ion these derivatives refer to.
162  //
163  // 1.) GradMatrix grad_phi: Holds the ionic derivatives of each SPO for each electron.
164  // Example: grad_phi[iel][iorb][idim]. iel -- electron index.
165  // iorb -- orbital index.
166  // idim -- cartesian index of ionic derivative.
167  // X=0, Y=1, Z=2.
168  //
169  // 2.) HessMatrix grad_grad_phi: Holds the ionic derivatives of the electron gradient components
170  // for each SPO and each electron.
171  // Example: grad_grad_phi[iel][iorb](idim,edim) iel -- electron index.
172  // iorb -- orbital index.
173  // idim -- ionic derivative's cartesian index.
174  // X=0, Y=1, Z=2
175  // edim -- electron derivative's cartesian index.
176  // x=0, y=1, z=2.
177  //
178  // 3.) GradMatrix grad_lapl_phi: Holds the ionic derivatives of the electron laplacian for each SPO and each electron.
179  // Example: grad_lapl_phi[iel][iorb][idim]. iel -- electron index.
180  // iorb -- orbital index.
181  // idim -- cartesian index of ionic derivative.
182  // X=0, Y=1, Z=2.
183 
184  /**
185  * \brief Calculate ion derivatives of SPO's.
186  *
187  * @param P Electron particle set.
188  * @param first index of first electron
189  * @@param last index of last electron
190  * @param source Ion particle set.
191  * @param iat_src Index of ion.
192  * @param gradphi Container storing ion gradients for all particles and all orbitals.
193  */
194  void evaluateGradSource(const ParticleSet& P,
195  int first,
196  int last,
197  const ParticleSet& source,
198  int iat_src,
199  GradMatrix& grad_phi) final;
200 
201  /**
202  * \brief Calculate ion derivatives of SPO's, their gradients, and their laplacians.
203  *
204  * @param P Electron particle set.
205  * @param first index of first electron.
206  * @@param last index of last electron
207  * @param source Ion particle set.
208  * @param iat_src Index of ion.
209  * @param grad_phi Container storing ion gradients for all particles and all orbitals.
210  * @param grad_grad_phi Container storing ion gradients of electron gradients for all particles and all orbitals.
211  * @param grad_lapl_phi Container storing ion gradients of SPO laplacians for all particles and all orbitals.
212  */
213  void evaluateGradSource(const ParticleSet& P,
214  int first,
215  int last,
216  const ParticleSet& source,
217  int iat_src,
218  GradMatrix& grad_phi,
219  HessMatrix& grad_grad_phi,
220  GradMatrix& grad_lapl_phi) final;
221 
222  void evaluateGradSourceRow(const ParticleSet& P,
223  int iel,
224  const ParticleSet& source,
225  int iat_src,
226  GradVector& grad_phi) final;
227 
228  void createResource(ResourceCollection& collection) const final;
229  void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const final;
230  void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const final;
231 
232 protected:
233  ///number of Single-particle orbitals
235  /// a copy of the original C before orbital rotation is applied;
237  ///true if C is an identity matrix
238  const bool Identity;
239  /// whether offload is on or off at runtime.
240  const bool useOMPoffload_;
241 
242  ///Temp(BasisSetSize) : Row index=V,Gx,Gy,Gz,L
244  ///Tempv(OrbitalSetSize) Tempv=C*Temp
246 
247  ///These are temporary VectorSoAContainers to hold value, gradient, and hessian for
248  ///all basis or SPO functions evaluated at a given point.
249  ///Nbasis x [1(value)+3(gradient)+6(hessian)]
251  ///Norbitals x [1(value)+3(gradient)+6(hessian)]
253 
254  ///These are temporary VectorSoAContainers to hold value, gradient, hessian, and
255  /// gradient hessian for all basis or SPO functions evaluated at a given point.
256  ///Nbasis x [1(value)+3(gradient)+6(hessian)+10(grad_hessian)]
258  ///Nbasis x [1(value)+3(gradient)+6(hessian)+10(grad_hessian)]
260 
261 private:
262  ///helper functions to handle Identity
263  void evaluate_vgl_impl(const vgl_type& temp, ValueVector& psi, GradVector& dpsi, ValueVector& d2psi) const;
264 
265  void evaluate_vgl_impl(const vgl_type& temp,
266  int i,
267  ValueMatrix& logdet,
268  GradMatrix& dlogdet,
269  ValueMatrix& d2logdet) const;
270  ///These two functions unpack the data in vgh_type temp object into wavefunction friendly data structures.
271 
272 
273  ///This unpacks temp into vectors psi, dpsi, and d2psi.
274  void evaluate_vgh_impl(const vgh_type& temp, ValueVector& psi, GradVector& dpsi, HessVector& d2psi) const;
275 
276  ///Unpacks temp into the ith row (or electron index) of logdet, dlogdet, dhlogdet.
277  void evaluate_vgh_impl(const vgh_type& temp,
278  int i,
279  ValueMatrix& logdet,
280  GradMatrix& dlogdet,
281  HessMatrix& dhlogdet) const;
282  ///Unpacks data in vghgh_type temp object into wavefunction friendly data structures for value, gradient, hessian
283  ///and gradient hessian.
284  void evaluate_vghgh_impl(const vghgh_type& temp,
285  ValueVector& psi,
286  GradVector& dpsi,
287  HessVector& d2psi,
288  GGGVector& dghpsi) const;
289 
290  void evaluate_vghgh_impl(const vghgh_type& temp,
291  int i,
292  ValueMatrix& logdet,
293  GradMatrix& dlogdet,
294  HessMatrix& dhlogdet,
295  GGGMatrix& dghlogdet) const;
296 
297 
298  ///Unpacks data in vgl object and calculates/places ionic gradient result into dlogdet.
299  void evaluate_ionderiv_v_impl(const vgl_type& temp, int i, GradMatrix& dlogdet) const;
300 
301  ///Unpacks data in vgl object and calculates/places ionic gradient of value,
302  /// electron gradient, and electron laplacian result into dlogdet, dglogdet, and dllogdet respectively.
303  void evaluate_ionderiv_vgl_impl(const vghgh_type& temp,
304  int i,
305  GradMatrix& dlogdet,
306  HessMatrix& dglogdet,
307  GradMatrix& dllogdet) const;
308 
309  ///Unpacks data in vgl object and calculates/places ionic gradient of a single row (phi_j(r)) into dlogdet.
310  void evaluate_ionderiv_v_row_impl(const vgl_type& temp, GradVector& dlogdet) const;
311 
312  void mw_evaluateVGLImplGEMM(const RefVectorWithLeader<SPOSet>& spo_list,
313  const RefVectorWithLeader<ParticleSet>& P_list,
314  int iat,
315  OffloadMWVGLArray& phi_vgl_v) const;
316 
317  /// packed walker GEMM implementation
319  const RefVectorWithLeader<ParticleSet>& P_list,
320  int iat,
321  OffloadMWVArray& phi_v) const;
322 
323  /// packed walker GEMM implementation with multi virtual particle sets
325  const RefVectorWithLeader<const VirtualParticleSet>& vp_list,
326  OffloadMWVArray& phi_v) const;
327 
328  /// helper function for extracting a list of basis sets from a list of LCAOrbitalSet
330 
333  /// timer for basis set
335  /// timer for MO
337 };
338 } // namespace qmcplusplus
339 #endif
base class for Single-particle orbital sets
Definition: SPOSet.h:46
OrbitalSetTraits< ValueType >::HessVector HessVector
Definition: SPOSet.h:53
OffloadMatrix< ValueType > OffloadValueMatrix
Definition: LCAOrbitalSet.h:37
void mw_evaluateVGL(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, const RefVector< ValueVector > &psi_v_list, const RefVector< GradVector > &dpsi_v_list, const RefVector< ValueVector > &d2psi_v_list) const final
evaluate the values, gradients and laplacians of this single-particle orbital sets of multiple walker...
bool hasIonDerivs() const final
Query if this SPOSet has an explicit ion dependence.
Definition: LCAOrbitalSet.h:64
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int getBasisSetSize() const
return the size of the basis set
Definition: LCAOrbitalSet.h:78
std::string getClassName() const final
return class name
Definition: LCAOrbitalSet.h:60
void evaluateGradSourceRow(const ParticleSet &P, int iel, const ParticleSet &source, int iat_src, GradVector &grad_phi) final
Returns a row of d/dR_iat phi_j(r) evaluated at position r.
std::unique_ptr< SPOSet > makeClone() const final
make a clone of itself every derived class must implement this to have threading working correctly...
ResourceHandle manages the temporary resource referenced from a collection.
void evaluate_ionderiv_v_row_impl(const vgl_type &temp, GradVector &dlogdet) const
Unpacks data in vgl object and calculates/places ionic gradient of a single row (phi_j(r)) into dlogd...
const bool Identity
true if C is an identity matrix
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
NewTimer & mo_timer_
timer for MO
std::unique_ptr< basis_type > myBasisSet
pointer to the basis set
Definition: LCAOrbitalSet.h:40
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
LatticeGaussianProduct::GradType GradType
std::shared_ptr< OffloadValueMatrix > C_copy
a copy of the original C before orbital rotation is applied;
SoA adaptor class for Vector<TinyVector<T,D> >
bool isRotationSupported() const final
return true if this SPOSet can be wrappered by RotatedSPO
Definition: LCAOrbitalSet.h:62
void applyRotation(const ValueMatrix &rot_mat, bool use_stored_copy) final
apply rotation to all the orbitals
Timer accumulates time and call counts.
Definition: NewTimer.h:135
void evaluateGradSource(const ParticleSet &P, int first, int last, const ParticleSet &source, int iat_src, GradMatrix &grad_phi) final
Calculate ion derivatives of SPO&#39;s.
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) final
evaluate the values, gradients and laplacians of this single-particle orbital set ...
void evaluate_vghgh_impl(const vghgh_type &temp, ValueVector &psi, GradVector &dpsi, HessVector &d2psi, GGGVector &dghpsi) const
Unpacks data in vghgh_type temp object into wavefunction friendly data structures for value...
LCAOrbitalSet(const std::string &my_name, std::unique_ptr< basis_type > &&bs, size_t norbs, bool identity, bool use_offload)
constructor
OrbitalSetTraits< ValueType >::ValueVector ValueVector
void mw_evaluateVGLImplGEMM(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, OffloadMWVGLArray &phi_vgl_v) const
QMCTraits::IndexType IndexType
Definition: FSUtilities.h:11
vgh_type Temph
These are temporary VectorSoAContainers to hold value, gradient, and hessian for all basis or SPO fun...
void evaluateVGH(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, HessVector &grad_grad_psi) final
evaluate the values, gradients and hessians of this single-particle orbital set
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
Array< ValueType, 3, OffloadPinnedAllocator< ValueType > > OffloadMWVGLArray
Definition: SPOSet.h:58
void finalizeConstruction() override
update C on device
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) final
evaluate the values of this single-particle orbital set
const IndexType BasisSetSize
number of Single-particle orbitals
VectorSoaContainer< T, 10 > vgh_type
Definition: BasisSetBase.h:136
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
std::shared_ptr< OffloadValueMatrix > C
pointer to matrix containing the coefficients
Definition: LCAOrbitalSet.h:42
vgl_type Tempv
Tempv(OrbitalSetSize) Tempv=C*Temp.
RefVectorWithLeader< basis_type > extractBasisRefList(const RefVectorWithLeader< SPOSet > &spo_list) const
helper function for extracting a list of basis sets from a list of LCAOrbitalSet
void mw_evaluateValue(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, const RefVector< ValueVector > &psi_v_list) const final
evaluate the values this single-particle orbital sets of multiple walkers
void evaluate_vgh_impl(const vgh_type &temp, ValueVector &psi, GradVector &dpsi, HessVector &d2psi) const
These two functions unpack the data in vgh_type temp object into wavefunction friendly data structure...
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const final
acquire a shared resource from collection
void mw_evaluateValueVPsImplGEMM(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, OffloadMWVArray &phi_v) const
packed walker GEMM implementation with multi virtual particle sets
void checkObject() const final
check consistency between Identity and C
vghgh_type Tempghv
Nbasis x [1(value)+3(gradient)+6(hessian)+10(grad_hessian)].
void evaluateDetRatios(const VirtualParticleSet &VP, ValueVector &psi, const ValueVector &psiinv, std::vector< ValueType > &ratios) final
evaluate determinant ratios for virtual moves, e.g., sphere move for nonlocalPP
Define determinant operators.
std::vector< std::reference_wrapper< T > > RefVector
vgh_type Temphv
Norbitals x [1(value)+3(gradient)+6(hessian)].
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const final
return a shared resource to collection
ResourceHandle< LCAOMultiWalkerMem > mw_mem_handle_
OrbitalSetTraits< ValueType >::GradHessVector GGGVector
Definition: SPOSet.h:55
void evaluate_ionderiv_v_impl(const vgl_type &temp, int i, GradMatrix &dlogdet) const
Unpacks data in vgl object and calculates/places ionic gradient result into dlogdet.
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
void createResource(ResourceCollection &collection) const final
initialize a shared resource and hand it to collection
const bool useOMPoffload_
whether offload is on or off at runtime.
void mw_evaluateVGLandDetRatioGrads(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, const std::vector< const ValueType *> &invRow_ptr_list, OffloadMWVGLArray &phi_vgl_v, std::vector< ValueType > &ratios, std::vector< GradType > &grads) const final
evaluate the values, gradients and laplacians of this single-particle orbital sets and determinant ra...
VectorSoaContainer< T, 20 > vghgh_type
Definition: BasisSetBase.h:137
void evaluate_ionderiv_vgl_impl(const vghgh_type &temp, int i, GradMatrix &dlogdet, HessMatrix &dglogdet, GradMatrix &dllogdet) const
Unpacks data in vgl object and calculates/places ionic gradient of value, electron gradient...
void storeParamsBeforeRotation() final
store parameters before getting destroyed by rotation.
Definition: LCAOrbitalSet.h:68
void evaluate_vgl_impl(const vgl_type &temp, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) const
helper functions to handle Identity
LatticeGaussianProduct::ValueType ValueType
vghgh_type Tempgh
These are temporary VectorSoAContainers to hold value, gradient, hessian, and gradient hessian for al...
vgl_type Temp
Temp(BasisSetSize) : Row index=V,Gx,Gy,Gz,L.
class to handle linear combinations of basis orbitals used to evaluate the Dirac determinants.
Definition: LCAOrbitalSet.h:30
void setOrbitalSetSize(int norbs) final
set the OrbitalSetSize and Identity=false and initialize internal storages
VectorSoaContainer< T, OHMMS_DIM+2 > vgl_type
Definition: BasisSetBase.h:135
void evaluate_notranspose(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet) final
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
OrbitalSetTraits< ValueType >::GradHessMatrix GGGMatrix
Definition: SPOSet.h:56
NewTimer & basis_timer_
timer for basis set
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
bool isOMPoffload() const override
Query if this SPOSet uses OpenMP offload.
Definition: LCAOrbitalSet.h:58
void mw_evaluateValueImplGEMM(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, OffloadMWVArray &phi_v) const
packed walker GEMM implementation
void mw_evaluateDetRatios(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, const RefVector< ValueVector > &psi_list, const std::vector< const ValueType *> &invRow_ptr_list, std::vector< std::vector< ValueType >> &ratios_list) const final
evaluate determinant ratios for virtual moves, e.g., sphere move for nonlocalPP, of multiple walkers ...
void evaluateVGHGH(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, HessVector &grad_grad_psi, GGGVector &grad_grad_grad_psi) final
evaluate the values, gradients, hessians, and grad hessians of this single-particle orbital set ...
OrbitalSetTraits< ValueType >::HessMatrix HessMatrix
Definition: SPOSet.h:54
Declaration of a base class of BasisSet.
Base for real basis set.
Definition: BasisSetBase.h:132