QMCPACK
DiracDeterminantBase.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: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 /**@file DiracDeterminantBase.h
14  * @brief Declaration of DiracDeterminantBase with a S(ingle)P(article)O(rbital)Set
15  */
16 #ifndef QMCPLUSPLUS_DIRACDETERMINANT_BASE_H
17 #define QMCPLUSPLUS_DIRACDETERMINANT_BASE_H
18 
21 #include "Utilities/TimerManager.h"
22 #include "CPU/math.hpp"
23 
24 namespace qmcplusplus
25 {
26 /// determinant matrix inverter select
27 enum class DetMatInvertor
28 {
29  HOST,
30  ACCEL,
31 };
32 
34 {
35 public:
36  /** constructor
37  *@param spos the single-particle orbital set.
38  *@param first index of the first particle
39  *@param last index of last particle
40  */
41  DiracDeterminantBase(const std::string& class_name, std::unique_ptr<SPOSet>&& spos, int first, int last)
42  : UpdateTimer(createGlobalTimer(class_name + "::update", timer_level_fine)),
43  RatioTimer(createGlobalTimer(class_name + "::ratio", timer_level_fine)),
44  InverseTimer(createGlobalTimer(class_name + "::inverse", timer_level_fine)),
45  BufferTimer(createGlobalTimer(class_name + "::buffer", timer_level_fine)),
46  SPOVTimer(createGlobalTimer(class_name + "::spoval", timer_level_fine)),
47  SPOVGLTimer(createGlobalTimer(class_name + "::spovgl", timer_level_fine)),
48  Phi(std::move(spos)),
49  FirstIndex(first),
50  LastIndex(last),
51  NumOrbitals(last - first),
52  NumPtcls(last - first)
53  {}
54 
55  ///default destructor
56  ~DiracDeterminantBase() override {}
57 
58  // copy constructor and assign operator disabled
61 
62  // get the SPO pointer
63  inline SPOSetPtr getPhi() const { return Phi.get(); }
64 
65  // get FirstIndex, Last Index
66  inline int getFirstIndex() const { return FirstIndex; }
67  inline int getLastIndex() const { return LastIndex; }
68 
69 #ifndef NDEBUG
70  virtual ValueMatrix& getPsiMinv() { return dummy_vmt; }
71 #endif
72 
73  bool isFermionic() const final { return true; }
74  inline bool isOptimizable() const final { return Phi->isOptimizable(); }
75 
77  {
78  Phi->extractOptimizableObjectRefs(opt_obj_refs);
79  }
80 
81  inline void checkOutVariables(const opt_variables_type& active) final
82  {
83  if (Phi->isOptimizable())
84  Phi->checkOutVariables(active);
85  }
86 
87  virtual void registerTWFFastDerivWrapper(const ParticleSet& P, TWFFastDerivWrapper& twf) const override
88  {
89  throw std::runtime_error("DiracDeterminantBase::registerTWFFastDerivWrapper must be overridden\n");
90  }
91 
93  const opt_variables_type& optvars,
94  Vector<ValueType>& dlogpsi) override
95  {
96  // assume no orbital optimization. If implemented, override this function
97  }
98 
99  // expose CPU interfaces
106 
110 
114 
126 
133 
134  // used by DiracDeterminantWithBackflow
136  const opt_variables_type& active,
137  int offset,
138  Matrix<RealType>& dlogpsi,
139  Array<GradType, 3>& dG,
140  Matrix<RealType>& dL)
141  {
142  APP_ABORT(" Illegal action. Cannot use DiracDeterminantBase::evaluateDerivatives");
143  }
144 
145  // final keyword is intended to disable makeClone being further inherited.
146  std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const final
147  {
148  APP_ABORT(" Illegal action. Cannot use DiracDeterminantBase::makeClone");
149  return std::unique_ptr<DiracDeterminantBase>();
150  }
151 
152  PsiValue ratioGradWithSpin(ParticleSet& P, int iat, GradType& grad_iat, ComplexType& spingrad) override
153  {
154  APP_ABORT(" DiracDeterminantBase::ratioGradWithSpin(): Implementation required\n");
155  return 0.0;
156  }
157  GradType evalGradWithSpin(ParticleSet& P, int iat, ComplexType& spingrad) override
158  {
159  APP_ABORT(" DiracDeterminantBase::evalGradWithSpin(): Implementation required\n");
160  return GradType();
161  }
162  /** cloning function
163  * @param tqp target particleset
164  * @param spo spo set
165  *
166  * This interface is exposed only to SlaterDet and its derived classes
167  * can overwrite to clone itself correctly.
168  */
169  virtual std::unique_ptr<DiracDeterminantBase> makeCopy(std::unique_ptr<SPOSet>&& spo) const = 0;
170 
171 protected:
172  /// Timers
174  /// a set of single-particle orbitals used to fill in the values of the matrix
175  const std::unique_ptr<SPOSet> Phi;
176  ///index of the first particle with respect to the particle set
177  const int FirstIndex;
178  ///index of the last particle with respect to the particle set
179  const int LastIndex;
180  ///number of single-particle orbitals which belong to this Dirac determinant
181  const int NumOrbitals;
182  ///number of particles which belong to this Dirac determinant
183  const int NumPtcls;
184 
185 #ifndef NDEBUG
186  // This is for debugging and testing in debug mode
187  // psiMinv is not a base class data member or public in most implementations
188  // it is frequently Dual and its consistency not guaranteed.
190 #endif
191 
192  static bool checkG(const GradType& g)
193  {
194 #if !defined(NDEBUG)
195  auto g_mag = std::abs(dot(g, g));
196  if (qmcplusplus::isnan(g_mag))
197  throw std::runtime_error("gradient of NaN");
198  if (qmcplusplus::isinf(g_mag))
199  throw std::runtime_error("gradient of inf");
200  if (g_mag < std::abs(std::numeric_limits<RealType>::epsilon()))
201  {
202  std::cerr << "evalGrad gradient is " << g[0] << ' ' << g[1] << ' ' << g[2] << '\n';
203  throw std::runtime_error("gradient of zero");
204  }
205 #endif
206  return true;
207  }
208 };
209 
210 } // namespace qmcplusplus
211 #endif
base class for Single-particle orbital sets
Definition: SPOSet.h:46
virtual void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
return a shared resource to a collection
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
virtual LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L)=0
evaluate the value of the WaveFunctionComponent from scratch
virtual LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false)=0
For particle-by-particle move.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::GradType GradType
Definition: Configuration.h:62
timer_manager class.
virtual void recompute(const ParticleSet &P)
recompute the value of the WaveFunctionComponents which require critical accuracy.
virtual void evaluateHessian(ParticleSet &P, HessVector &grad_grad_psi_all)
virtual void registerTWFFastDerivWrapper(const ParticleSet &P, TWFFastDerivWrapper &twf) const override
Register the component with the TWFFastDerivWrapper wrapper.
virtual GradType evalGradSource(ParticleSet &P, ParticleSet &source, int iat)
return the logarithmic gradient for the iat-th particle of the source particleset ...
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
virtual LogValue evaluateGL(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, bool fromscratch)
compute gradients and laplacian of the TWF with respect to each particle.
DetMatInvertor
determinant matrix inverter select
virtual std::unique_ptr< DiracDeterminantBase > makeCopy(std::unique_ptr< SPOSet > &&spo) const =0
cloning function
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
Timer accumulates time and call counts.
Definition: NewTimer.h:135
bool isFermionic() const final
true, if this component is fermionic
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
virtual void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
acquire a shared resource from a collection
const int FirstIndex
index of the first particle with respect to the particle set
void mw_evalGrad(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const int iat, TWFGrads< CT > &grads_now) const
compute the current gradients for the iat-th particle of multiple walkers
virtual void mw_evaluateGL(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list, bool fromscratch) const
evaluate gradients and laplacian of the same type WaveFunctionComponent of multiple walkers ...
static bool checkG(const GradType &g)
An abstract class for a component of a many-body trial wave function.
virtual void evaluateDerivatives(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi)=0
Compute the derivatives of both the log of the wavefunction and kinetic energy with respect to optimi...
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
GradType evalGradWithSpin(ParticleSet &P, int iat, ComplexType &spingrad) override
return the current spin gradient for the iat-th particle Default implementation assumes that WaveFunc...
const std::unique_ptr< SPOSet > Phi
a set of single-particle orbitals used to fill in the values of the matrix
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const final
make clone
virtual void registerData(ParticleSet &P, WFBufferType &buf)=0
For particle-by-particle move.
PsiValue ratioGradWithSpin(ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new spin gradient Default im...
void checkOutVariables(const opt_variables_type &active) final
check out variational optimizable variables
virtual void mw_completeUpdates(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list) const
complete all the delayed or asynchronous operations for all the walkers in a batch before leaving the...
NewTimer & createGlobalTimer(const std::string &myname, timer_levels mylevel)
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
const int LastIndex
index of the last particle with respect to the particle set
virtual void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
virtual GradType evalGrad(ParticleSet &P, int iat)
return the current gradient for the iat-th particle
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
virtual void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, int offset, Matrix< RealType > &dlogpsi, Array< GradType, 3 > &dG, Matrix< RealType > &dL)
virtual void evaluateSpinorRatios(const VirtualParticleSet &VP, const std::pair< ValueVector, ValueVector > &spinor_multiplier, std::vector< ValueType > &ratios)
Used by SOECPComponent for faster SOC evaluation.
virtual PsiValue ratio(ParticleSet &P, int iat)=0
evaluate the ratio of the new to old WaveFunctionComponent value
virtual void evaluateRatios(const VirtualParticleSet &VP, std::vector< ValueType > &ratios)
evaluate ratios to evaluate the non-local PP
const int NumOrbitals
number of single-particle orbitals which belong to this Dirac determinant
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) final
extract underlying OptimizableObject references
virtual 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
moves of the iat-th particle on some walkers in a batch is accepted.
DiracDeterminantBase(const std::string &class_name, std::unique_ptr< SPOSet > &&spos, int first, int last)
constructor
virtual void mw_evaluateLog(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVector< ParticleSet::ParticleGradient > &G_list, const RefVector< ParticleSet::ParticleLaplacian > &L_list) const
evaluate from scratch the same type WaveFunctionComponent of multiple walkers
~DiracDeterminantBase() override
default destructor
void mw_ratioGrad(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, TWFGrads< CT > &grad_new) const
virtual void mw_evaluateRatios(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< const VirtualParticleSet > &vp_list, std::vector< std::vector< ValueType >> &ratios) const
evaluate ratios to evaluate the non-local PP multiple walkers
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
virtual 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...
virtual PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat)
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
virtual void copyFromBuffer(ParticleSet &P, WFBufferType &buf)=0
For particle-by-particle move.
virtual void completeUpdates()
complete all the delayed or asynchronous operations before leaving the p-by-p move region...
Declaration of WaveFunctionComponent.
virtual void mw_calcRatio(const RefVectorWithLeader< WaveFunctionComponent > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios) const
compute the ratio of the new to old WaveFunctionComponent value of multiple walkers ...
const int NumPtcls
number of particles which belong to this Dirac determinant
virtual void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios)
evaluate the ratios of one virtual move with respect to all the particles
virtual void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false)=0
a move for iat-th particle is accepted.
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25
virtual void restore(int iat)=0
If a move for iat-th particle is rejected, restore to the content.
bool isOptimizable() const final
if true, this contains optimizable components
bool isinf(float a)
return true if the value is Inf.
Definition: math.cpp:24
DiracDeterminantBase & operator=(const DiracDeterminantBase &s)=delete
bool isnan(float a)
return true if the value is NaN.
Definition: math.cpp:18