QMCPACK
SpinorSet.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) 2022 QMCPACK developers
6 //
7 // File developed by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories
8 // Cody A. Melton, cmelton@sandia.gov, Sandia National Laboratories
9 //
10 // File created by: Raymond Clay III, rclay@sandia.gov, Sandia National Laboratories
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 #ifndef QMCPLUSPLUS_SPINORSET_H
14 #define QMCPLUSPLUS_SPINORSET_H
15 
17 #include <ResourceHandle.h>
18 
19 namespace qmcplusplus
20 {
21 /** Class for Melton & Mitas style Spinors.
22  *
23  */
24 class SpinorSet : public SPOSet
25 {
26 public:
27  /** constructor */
28  SpinorSet(const std::string& my_name);
29  ~SpinorSet() override;
30 
31  std::string getClassName() const override { return "SpinorSet"; }
32  bool isOptimizable() const override { return spo_up->isOptimizable() || spo_dn->isOptimizable(); }
33  bool isOMPoffload() const override { return spo_up->isOMPoffload() || spo_dn->isOMPoffload(); }
34  bool hasIonDerivs() const override { return spo_up->hasIonDerivs() || spo_dn->hasIonDerivs(); }
35  bool isRotationSupported() const override { return spo_up->isRotationSupported() && spo_dn->isRotationSupported(); }
36 
37  void storeParamsBeforeRotation() override;
38 
39  void applyRotation(const ValueMatrix& rot_mat, bool use_stored_copy) override;
40 
41  //This class is initialized by separately building the up and down channels of the spinor set and
42  //then registering them.
43  void set_spos(std::unique_ptr<SPOSet>&& up, std::unique_ptr<SPOSet>&& dn);
44 
45  /** set the OrbitalSetSize
46  * @param norbs number of single-particle orbitals
47  */
48  void setOrbitalSetSize(int norbs) override;
49 
50  /** evaluate the values of this spinor set
51  * @param P current ParticleSet
52  * @param iat active particle
53  * @param psi values of the SPO
54  */
55  void evaluateValue(const ParticleSet& P, int iat, ValueVector& psi) override;
56 
58  ValueVector& psi,
59  const std::pair<ValueVector, ValueVector>& spinor_multipler,
60  const ValueVector& invrow,
61  std::vector<ValueType>& ratios) override;
62 
63  /** evaluate the values, gradients and laplacians of this single-particle orbital set
64  * @param P current ParticleSet
65  * @param iat active particle
66  * @param psi values of the SPO
67  * @param dpsi gradients of the SPO
68  * @param d2psi laplacians of the SPO
69  */
70  void evaluateVGL(const ParticleSet& P, int iat, ValueVector& psi, GradVector& dpsi, ValueVector& d2psi) override;
71 
72  /** evaluate the values, gradients and laplacians of this single-particle orbital set
73  * @param P current ParticleSet
74  * @param iat active particle
75  * @param psi values of the SPO
76  * @param dpsi gradients of the SPO
77  * @param d2psi laplacians of the SPO
78  * @param dspin spin gradient of the SPO
79  */
80  void evaluateVGL_spin(const ParticleSet& P,
81  int iat,
82  ValueVector& psi,
83  GradVector& dpsi,
84  ValueVector& d2psi,
85  ValueVector& dspin) override;
86 
87  /** evaluate the values, gradients and laplacians and spin gradient of this single-particle orbital sets of multiple walkers
88  * @param spo_list the list of SPOSet pointers in a walker batch
89  * @param P_list the list of ParticleSet pointers in a walker batch
90  * @param iat active particle
91  * @param psi_v_list the list of value vector pointers in a walker batch
92  * @param dpsi_v_list the list of gradient vector pointers in a walker batch
93  * @param d2psi_v_list the list of laplacian vector pointers in a walker batch
94  * @param mw_dspin dual matrix of spin gradients. nw x num_orbitals
95  */
98  int iat,
99  const RefVector<ValueVector>& psi_v_list,
100  const RefVector<GradVector>& dpsi_v_list,
101  const RefVector<ValueVector>& d2psi_v_list,
102  OffloadMatrix<ComplexType>& mw_dspin) const override;
103 
104 
105  /** evaluate the values, gradients and laplacians of this single-particle orbital sets and determinant ratio
106  * and grads of multiple walkers. Device data of phi_vgl_v must be up-to-date upon return.
107  * Includes spin gradients
108  * @param spo_list the list of SPOSet pointers in a walker batch
109  * @param P_list the list of ParticleSet pointers in a walker batch
110  * @param iat active particle
111  * @param phi_vgl_v orbital values, gradients and laplacians of all the walkers
112  * @param ratios, ratios of all walkers
113  * @param grads, spatial gradients of all walkers
114  * @param spingrads, spin gradients of all walkers
115  */
117  const RefVectorWithLeader<ParticleSet>& P_list,
118  int iat,
119  const std::vector<const ValueType*>& invRow_ptr_list,
120  OffloadMWVGLArray& phi_vgl_v,
121  std::vector<ValueType>& ratios,
122  std::vector<GradType>& grads,
123  std::vector<ValueType>& spingrads) const override;
124 
125  /** evaluate the values, gradients and laplacians of this single-particle orbital for [first,last) particles
126  * @param P current ParticleSet
127  * @param first starting index of the particles
128  * @param last ending index of the particles
129  * @param logdet determinant matrix to be inverted
130  * @param dlogdet gradients
131  * @param d2logdet laplacians
132  *
133  */
134  void evaluate_notranspose(const ParticleSet& P,
135  int first,
136  int last,
137  ValueMatrix& logdet,
138  GradMatrix& dlogdet,
139  ValueMatrix& d2logdet) override;
140 
142  const RefVectorWithLeader<ParticleSet>& P_list,
143  int first,
144  int last,
145  const RefVector<ValueMatrix>& logdet_list,
146  const RefVector<GradMatrix>& dlogdet_list,
147  const RefVector<ValueMatrix>& d2logdet_list) const override;
148 
150  int first,
151  int last,
152  ValueMatrix& logdet,
153  GradMatrix& dlogdet,
154  ValueMatrix& d2logdet,
155  ValueMatrix& dspinlogdet) override;
156  /** Evaluate the values, spin gradients, and spin laplacians of single particle spinors corresponding to electron iat.
157  * @param P current particle set.
158  * @param iat electron index.
159  * @param spinor values.
160  * @param spin gradient values. d/ds phi(r,s).
161  *
162  */
163  void evaluate_spin(const ParticleSet& P, int iat, ValueVector& psi, ValueVector& dpsi) override;
164 
165  /** evaluate the gradients of this single-particle orbital
166  * for [first,last) target particles with respect to the given source particle
167  * @param P current ParticleSet
168  * @param first starting index of the particles
169  * @param last ending index of the particles
170  * @param iat_src source particle index
171  * @param gradphi gradients
172  *
173  */
174  virtual void evaluateGradSource(const ParticleSet& P,
175  int first,
176  int last,
177  const ParticleSet& source,
178  int iat_src,
179  GradMatrix& gradphi) override;
180 
181  std::unique_ptr<SPOSet> makeClone() const override;
182 
183  void createResource(ResourceCollection& collection) const override;
184 
185  void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const override;
186 
187  void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<SPOSet>& spo_list) const override;
188 
189  /// check if the multi walker resource is owned. For testing only.
190  bool isResourceOwned() const { return bool(mw_res_handle_); }
191 
192 private:
195 
196  std::pair<RefVectorWithLeader<SPOSet>, RefVectorWithLeader<SPOSet>> extractSpinComponentRefList(
197  const RefVectorWithLeader<SPOSet>& spo_list) const;
198 
199  //Sposet for the up and down channels of our spinors.
200  std::unique_ptr<SPOSet> spo_up;
201  std::unique_ptr<SPOSet> spo_dn;
202 
203  //temporary arrays for holding the values of the up and down channels respectively.
206 
207  //temporary arrays for holding the gradients of the up and down channels respectively.
210 
211  //temporary arrays for holding the laplacians of the up and down channels respectively.
214 
215  //Same as above, but these are the full matrices containing all spinor/particle combinations.
218 
221 
224 };
225 
226 } // namespace qmcplusplus
227 #endif
std::pair< RefVectorWithLeader< SPOSet >, RefVectorWithLeader< SPOSet > > extractSpinComponentRefList(const RefVectorWithLeader< SPOSet > &spo_list) const
Definition: SpinorSet.cpp:607
base class for Single-particle orbital sets
Definition: SPOSet.h:46
std::unique_ptr< SPOSet > makeClone() const override
make a clone of itself every derived class must implement this to have threading working correctly...
Definition: SpinorSet.cpp:569
Class for Melton & Mitas style Spinors.
Definition: SpinorSet.h:24
void evaluateVGL_spin(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi, ValueVector &dspin) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
Definition: SpinorSet.cpp:153
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to collection
Definition: SpinorSet.cpp:578
ValueVector psi_work_up
Definition: SpinorSet.h:204
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void evaluate_spin(const ParticleSet &P, int iat, ValueVector &psi, ValueVector &dpsi) override
Evaluate the values, spin gradients, and spin laplacians of single particle spinors corresponding to ...
Definition: SpinorSet.cpp:516
void storeParamsBeforeRotation() override
store parameters before getting destroyed by rotation.
Definition: SpinorSet.cpp:34
ValueMatrix logpsi_work_up
Definition: SpinorSet.h:216
ResourceHandle< SpinorSetMultiWalkerResource > mw_res_handle_
Definition: SpinorSet.h:193
void setOrbitalSetSize(int norbs) override
set the OrbitalSetSize
Definition: SpinorSet.cpp:61
void mw_evaluateVGLandDetRatioGradsWithSpin(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, std::vector< ValueType > &spingrads) const override
evaluate the values, gradients and laplacians of this single-particle orbital sets and determinant ra...
Definition: SpinorSet.cpp:258
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const override
return a shared resource to collection
Definition: SpinorSet.cpp:596
ValueVector d2psi_work_down
Definition: SpinorSet.h:213
ResourceHandle manages the temporary resource referenced from a collection.
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
std::unique_ptr< SPOSet > spo_up
Definition: SpinorSet.h:200
GradVector dpsi_work_up
Definition: SpinorSet.h:208
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
void evaluate_notranspose(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet) override
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
Definition: SpinorSet.cpp:337
ValueVector d2psi_work_up
Definition: SpinorSet.h:212
void mw_evaluate_notranspose(const RefVectorWithLeader< SPOSet > &spo_list, const RefVectorWithLeader< ParticleSet > &P_list, int first, int last, const RefVector< ValueMatrix > &logdet_list, const RefVector< GradMatrix > &dlogdet_list, const RefVector< ValueMatrix > &d2logdet_list) const override
Definition: SpinorSet.cpp:382
OrbitalSetTraits< ValueType >::ValueVector ValueVector
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
Definition: SpinorSet.cpp:119
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) override
evaluate the values of this spinor set
Definition: SpinorSet.cpp:64
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< SPOSet > &spo_list) const override
acquire a shared resource from collection
Definition: SpinorSet.cpp:585
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
ValueMatrix d2logpsi_work_up
Definition: SpinorSet.h:222
GradMatrix dlogpsi_work_down
Definition: SpinorSet.h:220
bool isOptimizable() const override
Query if this SPOSet is optimizable.
Definition: SpinorSet.h:32
void applyRotation(const ValueMatrix &rot_mat, bool use_stored_copy) override
apply rotation to all the orbitals
Definition: SpinorSet.cpp:40
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
SpinorSet(const std::string &my_name)
constructor
Definition: SpinorSet.cpp:31
std::string getClassName() const override
return class name
Definition: SpinorSet.h:31
std::unique_ptr< SPOSet > spo_dn
Definition: SpinorSet.h:201
ValueMatrix logpsi_work_down
Definition: SpinorSet.h:217
bool isOMPoffload() const override
Query if this SPOSet uses OpenMP offload.
Definition: SpinorSet.h:33
GradMatrix dlogpsi_work_up
Definition: SpinorSet.h:219
std::vector< std::reference_wrapper< T > > RefVector
virtual void evaluateGradSource(const ParticleSet &P, int first, int last, const ParticleSet &source, int iat_src, GradMatrix &gradphi) override
evaluate the gradients of this single-particle orbital for [first,last) target particles with respect...
Definition: SpinorSet.cpp:542
void mw_evaluateVGLWithSpin(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, OffloadMatrix< ComplexType > &mw_dspin) const override
evaluate the values, gradients and laplacians and spin gradient of this single-particle orbital sets ...
Definition: SpinorSet.cpp:194
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
bool hasIonDerivs() const override
Query if this SPOSet has an explicit ion dependence.
Definition: SpinorSet.h:34
GradVector dpsi_work_down
Definition: SpinorSet.h:209
void evaluateDetSpinorRatios(const VirtualParticleSet &VP, ValueVector &psi, const std::pair< ValueVector, ValueVector > &spinor_multipler, const ValueVector &invrow, std::vector< ValueType > &ratios) override
evaluate determinant ratios for virtual moves, specifically for Spinor SPOSets
Definition: SpinorSet.cpp:89
void set_spos(std::unique_ptr< SPOSet > &&up, std::unique_ptr< SPOSet > &&dn)
Definition: SpinorSet.cpp:46
ValueVector psi_work_down
Definition: SpinorSet.h:205
bool isRotationSupported() const override
return true if this SPOSet can be wrappered by RotatedSPO
Definition: SpinorSet.h:35
void evaluate_notranspose_spin(const ParticleSet &P, int first, int last, ValueMatrix &logdet, GradMatrix &dlogdet, ValueMatrix &d2logdet, ValueMatrix &dspinlogdet) override
evaluate the values, gradients and laplacians of this single-particle orbital for [first...
Definition: SpinorSet.cpp:468
ValueMatrix d2logpsi_work_down
Definition: SpinorSet.h:223
bool isResourceOwned() const
check if the multi walker resource is owned. For testing only.
Definition: SpinorSet.h:190