QMCPACK
DiracDeterminant.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Bryan Clark, bclark@Princeton.edu, Princeton University
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory
13 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
14 //
15 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
16 //////////////////////////////////////////////////////////////////////////////////////
17 
18 
19 /**@file DiracDeterminant.h
20  * @brief Declaration of DiracDeterminant with a S(ingle)P(article)O(rbital)Set
21  */
22 #ifndef QMCPLUSPLUS_DIRACDETERMINANT_H
23 #define QMCPLUSPLUS_DIRACDETERMINANT_H
24 
27 #if defined(ENABLE_CUDA)
29 #endif
30 #if defined(ENABLE_SYCL)
32 #endif
33 
34 namespace qmcplusplus
35 {
36 template<typename DU_TYPE = DelayedUpdate<QMCTraits::ValueType, QMCTraits::QTFull::ValueType>>
38 {
39 protected:
40  const int ndelay_;
41 
42  ///reset the size: with the number of particles and number of orbtials
43  void resize(int nel, int morb);
44 
45 public:
52 
55 
56  /** constructor
57  *@param spos the single-particle orbital set
58  *@param first index of the first particle
59  *@param last index of last particle
60  *@param ndelay delayed update rank
61  */
62  DiracDeterminant(std::unique_ptr<SPOSet>&& spos,
63  int first,
64  int last,
65  int ndelay = 1,
66  DetMatInvertor matrix_inverter_kind = DetMatInvertor::ACCEL);
67 
68  // copy constructor and assign operator disabled
69  DiracDeterminant(const DiracDeterminant& s) = delete;
70  DiracDeterminant& operator=(const DiracDeterminant& s) = delete;
71 
72  std::string getClassName() const override { return "DiracDeterminant"; }
73 
75  const opt_variables_type& active,
76  Vector<ValueType>& dlogpsi,
77  Vector<ValueType>& dhpsioverpsi) override;
78 
79  void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& optvars, Vector<ValueType>& dlogpsi) override;
80 
81  void registerData(ParticleSet& P, WFBufferType& buf) override;
82 
84 
85  LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override;
86 
87  void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override;
88 
89  /** Finds the SPOSet associated with this determinant, and registers it with WFN wrapper
90  */
92 
93  /** return the ratio only for the iat-th partcle move
94  * @param P current configuration
95  * @param iat the particle thas is being moved
96  */
97  PsiValue ratio(ParticleSet& P, int iat) override;
98 
99  //Ye: TODO, good performance needs batched SPO evaluation.
100  //void mw_calcRatio(const std::vector<WaveFunctionComponent*>& wfc_list,
101  // const std::vector<ParticleSet*>& p_list,
102  // int iat,
103  // std::vector<PsiValue>& ratios) override;
104 
105  /** compute multiple ratios for a particle move
106  */
107  void evaluateRatios(const VirtualParticleSet& VP, std::vector<ValueType>& ratios) override;
108 
109  void evaluateSpinorRatios(const VirtualParticleSet& VP, const std::pair<ValueVector, ValueVector>& spinor_multipler, std::vector<ValueType>& ratios) override;
110 
113  std::vector<std::vector<ValueType>>& ratios) const override;
114 
116  const opt_variables_type& optvars,
117  std::vector<ValueType>& ratios,
118  Matrix<ValueType>& dratios) override;
119 
120  PsiValue ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override;
121 
122  PsiValue ratioGradWithSpin(ParticleSet& P, int iat, GradType& grad_iat, ComplexType& spingrad) final;
123 
125  const RefVectorWithLeader<ParticleSet>& p_list,
126  int iat,
127  std::vector<PsiValue>& ratios,
128  std::vector<GradType>& grad_new) const override;
129 
130  GradType evalGrad(ParticleSet& P, int iat) override;
131 
132  GradType evalGradWithSpin(ParticleSet& P, int iat, ComplexType& spingrad) final;
133 
134  GradType evalGradSource(ParticleSet& P, ParticleSet& source, int iat) override;
135 
137  ParticleSet& source,
138  int iat,
141 
142  /** move was accepted, update the real container
143  */
144  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override;
145 
147  const RefVectorWithLeader<ParticleSet>& p_list,
148  int iat,
149  const std::vector<bool>& isAccepted,
150  bool safe_to_delay = false) const override
151  {
152  for (int iw = 0; iw < wfc_list.size(); iw++)
153  if (isAccepted[iw])
154  wfc_list[iw].acceptMove(p_list[iw], iat, safe_to_delay);
155  else
156  wfc_list[iw].restore(iat);
157  }
158 
159  void completeUpdates() override;
160 
162  {
163  for (int iw = 0; iw < wfc_list.size(); iw++)
164  wfc_list[iw].completeUpdates();
165  }
166 
167  /** move was rejected. copy the real container to the temporary to move on
168  */
169  void restore(int iat) override;
170 
171  ///evaluate log of a determinant for a particle set
174  ParticleSet::ParticleLaplacian& L) override;
175 
176  //Ye: TODO, good performance needs batched SPO evaluation.
177  //void mw_evaluateLog(const std::vector<WaveFunctionComponent*>& wfc_list,
178  // const std::vector<ParticleSet*>& p_list,
179  // const std::vector<ParticleSet::ParticleGradient*>& G_list,
180  // const std::vector<ParticleSet::ParticleLaplacian*>& L_list) override;
181 
182  void recompute(const ParticleSet& P) override;
183 
187  bool fromscratch) override;
188 
189  void evaluateHessian(ParticleSet& P, HessVector& grad_grad_psi) override;
190 
191  void createResource(ResourceCollection& collection) const override;
192  void acquireResource(ResourceCollection& collection,
193  const RefVectorWithLeader<WaveFunctionComponent>& wf_list) const override;
194  void releaseResource(ResourceCollection& collection,
195  const RefVectorWithLeader<WaveFunctionComponent>& wf_list) const override;
196 
197  /** cloning function
198  * @param tqp target particleset
199  * @param spo spo set
200  *
201  * This interface is exposed only to SlaterDet and its derived classes
202  * can overwrite to clone itself correctly.
203  */
204  std::unique_ptr<DiracDeterminantBase> makeCopy(std::unique_ptr<SPOSet>&& spo) const override;
205 
206  void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios) override;
207 
208 #ifndef NDEBUG
209  /// return for testing
210  ValueMatrix& getPsiMinv() override { return psiM; }
211 #else
212  ValueMatrix& getPsiMinv() { return psiM; }
213 #endif
214 
215  /// psiM(j,i) \f$= \psi_j({\bf r}_i)\f$
217 
218  /// inverse transpose of psiM(j,i) \f$= \psi_j({\bf r}_i)\f$
220 
221  /// temporary container for testing
223 
224  /// dpsiM(i,j) \f$= \nabla_i \psi_j({\bf r}_i)\f$
226 
227  /// d2psiM(i,j) \f$= \nabla_i^2 \psi_j({\bf r}_i)\f$
229 
230  /// Used for force computations
233 
237 
238  /// value of single-particle orbital for particle-by-particle update
243 
244  /// delayed update engine
245  DU_TYPE updateEng;
246 
247  /// the row of up-to-date inverse matrix
249 
250  /** row id correspond to the up-to-date invRow. [0 norb), invRow is ready; -1, invRow is not valid.
251  * This id is set after calling getInvRow indicating invRow has been prepared for the invRow_id row
252  * ratioGrad checks if invRow_id is consistent. If not, invRow needs to be recomputed.
253  * acceptMove and completeUpdates mark invRow invalid by setting invRow_id to -1
254  */
256 
260 
261 private:
262  /// slow but doesn't consume device memory
264 
265  /// selected scheme for inversion
267 
268  /// invert psiM or its copies
269  void invertPsiM(const ValueMatrix& logdetT, ValueMatrix& invMat);
270 
271  /// Resize all temporary arrays required for force computation.
273 
274  /// internal function computing ratio and gradients after computing the SPOs, used by ratioGrad.
275  PsiValue ratioGrad_compute(int iat, GradType& grad_iat);
276 };
277 
278 extern template class DiracDeterminant<>;
279 #if defined(ENABLE_CUDA)
281 #endif
282 #if defined(ENABLE_SYCL)
284 #endif
285 
286 } // namespace qmcplusplus
287 #endif
OrbitalSetTraits< ValueType >::HessVector HessVector
Definition: SPOSet.h:53
Declaration of DiracDeterminantBase with a S(ingle)P(article)O(rbital)Set.
void mw_evaluateRatios(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, std::vector< std::vector< ValueType >> &ratios) const override
evaluate ratios to evaluate the non-local PP multiple walkers
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wf_list) const override
acquire a shared resource from a collection
void recompute(const ParticleSet &P) override
recompute the value of the WaveFunctionComponents which require critical accuracy.
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::string getClassName() const override
return class name
void resizeScratchObjectsForIonDerivs()
Resize all temporary arrays required for force computation.
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
move was accepted, update the real container
void evaluateSpinorRatios(const VirtualParticleSet &VP, const std::pair< ValueVector, ValueVector > &spinor_multipler, std::vector< ValueType > &ratios) override
Used by SOECPComponent for faster SOC evaluation.
void resize(int nel, int morb)
reset the size: with the number of particles and number of orbtials
RealType ValueType
Definition: QMCTypes.h:42
DetMatInvertor
determinant matrix inverter select
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
LogValue evaluateGL(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, bool fromscratch) override
compute gradients and laplacian of the TWF with respect to each particle.
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi) override
Compute the derivatives of the log of the wavefunction with respect to optimizable parameters...
GradType evalGradWithSpin(ParticleSet &P, int iat, ComplexType &spingrad) final
return the current spin gradient for the iat-th particle Default implementation assumes that WaveFunc...
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
LatticeGaussianProduct::GradType GradType
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
ValueMatrix d2psiM
d2psiM(i,j)
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate log of a determinant for a particle set
ValueVector psiV
value of single-particle orbital for particle-by-particle update
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
void mw_ratioGrad(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, std::vector< GradType > &grad_new) const override
compute the ratio of the new to old WaveFunctionComponent value and the new gradient of multiple walk...
Attaches a unit to a Vector for IO.
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
void mw_accept_rejectMove(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< bool > &isAccepted, bool safe_to_delay=false) const override
moves of the iat-th particle on some walkers in a batch is accepted.
SPOSet::ValueMatrix ValueMatrix
DiracDeterminant(std::unique_ptr< SPOSet > &&spos, int first, int last, int ndelay=1, DetMatInvertor matrix_inverter_kind=DetMatInvertor::ACCEL)
constructor
int invRow_id
row id correspond to the up-to-date invRow.
OrbitalSetTraits< ValueType >::GradMatrix GradMatrix
Definition: SPOSet.h:52
GradMatrix dpsiM
dpsiM(i,j)
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
const DetMatInvertor matrix_inverter_kind_
selected scheme for inversion
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios) override
evaluate the ratios of one virtual move with respect to all the particles
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
void completeUpdates() override
complete all the delayed or asynchronous operations before leaving the p-by-p move region...
void evaluateDerivRatios(const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratios) override
evaluate ratios to evaluate the non-local PP
void updateAfterSweep(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L)
void restore(int iat) override
move was rejected.
void evaluateRatios(const VirtualParticleSet &VP, std::vector< ValueType > &ratios) override
compute multiple ratios for a particle move
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wf_list) const override
return a shared resource to a collection
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
PsiValue ratioGrad_compute(int iat, GradType &grad_iat)
internal function computing ratio and gradients after computing the SPOs, used by ratioGrad...
DU_TYPE updateEng
delayed update engine
GradMatrix grad_source_psiM
Used for force computations.
ValueMatrix psiM
inverse transpose of psiM(j,i)
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
PsiValue ratioGradWithSpin(ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad) final
evaluate the ratio of the new to old WaveFunctionComponent value and the new spin gradient Default im...
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
ValueMatrix & getPsiMinv() override
return for testing
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimi...
OrbitalSetTraits< ValueType >::GradVector GradVector
Definition: SPOSet.h:51
void registerTWFFastDerivWrapper(const ParticleSet &P, TWFFastDerivWrapper &twf) const final
Finds the SPOSet associated with this determinant, and registers it with WFN wrapper.
ValueMatrix psiMinv
temporary container for testing
SPOSet::ValueVector ValueVector
QMCTraits::ComplexType ComplexType
DiracMatrix< QMCTraits::QTFull::ValueType > host_inverter_
slow but doesn&#39;t consume device memory
void invertPsiM(const ValueMatrix &logdetT, ValueMatrix &invMat)
invert psiM or its copies
LatticeGaussianProduct::ValueType ValueType
ValueMatrix psiM_temp
psiM(j,i)
std::complex< double > LogValue
QMCTraits::QTFull::ValueType mValueType
PsiValue ratio(ParticleSet &P, int iat) override
return the ratio only for the iat-th partcle move
void mw_completeUpdates(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const override
complete all the delayed or asynchronous operations for all the walkers in a batch before leaving the...
ValueVector invRow
the row of up-to-date inverse matrix
std::unique_ptr< DiracDeterminantBase > makeCopy(std::unique_ptr< SPOSet > &&spo) const override
cloning function
GradType evalGradSource(ParticleSet &P, ParticleSet &source, int iat) override
return the logarithmic gradient for the iat-th particle of the source particleset ...
void evaluateHessian(ParticleSet &P, HessVector &grad_grad_psi) override
OrbitalSetTraits< ValueType >::HessMatrix HessMatrix
Definition: SPOSet.h:54
DiracDeterminant & operator=(const DiracDeterminant &s)=delete