QMCPACK
MultiDiracDeterminant.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: Bryan Clark, bclark@Princeton.edu, Princeton University
8 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Bryan Clark, bclark@Princeton.edu, Princeton University
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 /**@file DiracDeterminant.h
18  * @brief Declaration of DiracDeterminant with a S(ingle)P(article)O(rbital)Set
19  */
20 #ifndef QMCPLUSPLUS_MULTIDIRACDETERMINANT_H
21 #define QMCPLUSPLUS_MULTIDIRACDETERMINANT_H
26 #include "Message/Communicate.h"
28 #include "ResourceCollection.h"
29 //#include "CPU/BLAS.hpp"
30 
31 namespace qmcplusplus
32 {
34 {
35 public:
41 
42  // Optimizable parameter
44 
45  template<typename DT>
47  template<typename DT>
49  template<typename DT>
51  template<typename DT>
53 
56 
58  {
59  MultiDiracDetMultiWalkerResource() : Resource("MultiDiracDeterminant") {}
61 
62  std::unique_ptr<Resource> makeClone() const override
63  {
64  return std::make_unique<MultiDiracDetMultiWalkerResource>(*this);
65  }
66 
67  void resizeConstants(size_t nw)
68  {
69  if (nw > czero_vec.size())
70  {
71  czero_vec.resize(nw);
72  cone_vec.resize(nw);
73  cminus_one_vec.resize(nw);
74  std::fill_n(czero_vec.data(), nw, 0);
75  std::fill_n(cone_vec.data(), nw, 1);
76  std::fill_n(cminus_one_vec.data(), nw, -1);
77  czero_vec.updateTo();
78  cone_vec.updateTo();
79  cminus_one_vec.updateTo();
80  }
81  else
82  {
83  czero_vec.resize(nw);
84  cone_vec.resize(nw);
85  cminus_one_vec.resize(nw);
86  }
87  }
88 
92 
98 
105 
106  // pointer lists used by mw_buildTableMatrix_calculateRatios_impl
111 
114 
117  };
118 
119  //lookup table mapping the unique determinants to their element position in C2_node vector
120  std::vector<std::vector<int>> lookup_tbl;
121 
122  /** constructor
123  *@param spos the single-particle orbital set
124  *@param first index of the first particle
125  */
126  MultiDiracDeterminant(std::unique_ptr<SPOSet>&& spos, bool spinor, int first, int nel);
127 
128  ///default destructor
129  ~MultiDiracDeterminant() override;
130 
131  /**copy constructor
132  * @param s existing DiracDeterminant
133  *
134  * This constructor makes a shallow copy of Phi.
135  * Other data members are allocated properly.
136  */
138 
140 
141  /** return a clone of Phi
142  */
143  std::unique_ptr<SPOSet> clonePhi() const;
144 
145  SPOSetPtr getPhi() { return Phi.get(); };
146 
147  std::string getClassName() const override { return "MultiDiracDeterminant"; }
148 
149  bool isFermionic() const final { return true; }
150  inline bool isOptimizable() const final { return Phi->isOptimizable(); }
151 
153  {
154  Phi->extractOptimizableObjectRefs(opt_obj_refs);
155  }
156 
157  inline void checkOutVariables(const opt_variables_type& active) override
158  {
159  if (Phi->isOptimizable())
160  Phi->checkOutVariables(active);
161  }
162 
163  /// create optimizable orbital rotation parameters
164  void buildOptVariables(std::vector<size_t>& C2node);
165  ///helper function to buildOptVariables
166  int build_occ_vec(const OffloadVector<int>& data, const size_t nel, const size_t nmo, std::vector<int>& occ_vec);
167 
169  const opt_variables_type& optvars,
170  Vector<ValueType>& dlogpsi,
171  Vector<ValueType>& dhpsioverpsi) override
172  {}
173 
175  const opt_variables_type& optvars,
176  Vector<ValueType>& dlogpsi,
177  Vector<ValueType>& dhpsioverpsi,
178  const MultiDiracDeterminant& pseudo_dn,
179  const ValueType& psiCurrent,
180  const std::vector<ValueType>& Coeff,
181  const std::vector<size_t>& C2node_up,
182  const std::vector<size_t>& C2node_dn);
183 
185  const opt_variables_type& optvars,
186  Vector<ValueType>& dlogpsi,
187  const MultiDiracDeterminant& pseudo_dn,
188  const PsiValue& psiCurrent,
189  const std::vector<ValueType>& Coeff,
190  const std::vector<size_t>& C2node_up,
191  const std::vector<size_t>& C2node_dn);
192 
193 
194  void registerData(ParticleSet& P, WFBufferType& buf) override;
195 
196  LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override;
197 
198  void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override;
199 
200  /** move was accepted, update the real container
201  */
202  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override;
203 
204  /** move was rejected. copy the real container to the temporary to move on
205  */
206  void restore(int iat) override;
207 
209  const RefVectorWithLeader<ParticleSet>& p_list,
210  int iat,
211  const std::vector<bool>& isAccepted);
212 
213  void createResource(ResourceCollection& collection) const override;
214  void acquireResource(ResourceCollection& collection,
215  const RefVectorWithLeader<MultiDiracDeterminant>& wfc_list) const;
216  void releaseResource(ResourceCollection& collection,
217  const RefVectorWithLeader<MultiDiracDeterminant>& wfc_list) const;
218 
219  std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const override;
220 
221  /****************************************************************************
222  * These functions should not be called.
223  ***************************************************************************/
224 
225  PsiValue ratio(ParticleSet& P, int iat) override
226  {
227  APP_ABORT(" MultiDiracDeterminant: This should not be called. \n");
228  return PsiValue();
229  }
230 
231  GradType evalGrad(ParticleSet& P, int iat) override
232  {
233  APP_ABORT(" MultiDiracDeterminant: This should not be called. \n");
234  return GradType();
235  }
236 
237  PsiValue ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override
238  {
239  APP_ABORT(" MultiDiracDeterminant: This should not be called. \n");
240  return PsiValue();
241  }
242 
245  ParticleSet::ParticleLaplacian& L) override
246  {
247  APP_ABORT(" MultiDiracDeterminant: This should not be called. \n");
248  return 0.0;
249  }
250 
252  {
253  APP_ABORT(" MultiDiracDeterminant: This should not be called. \n");
254  return ValueType();
255  }
256 
257 
258  /****************************************************************************
259  * END END END
260  ***************************************************************************/
261 
262  /** create necessary structures related to unique determinants
263  * sort configlist_unsorted by excitation level abd store the results in ciConfigList (class member)
264  * ciConfigList shouldn't change during a simulation after it is sorted here
265  *
266  * @param ref_det_id id of the reference determinant before sorting
267  * @param configlist_unsorted config list to be loaded.
268  * @param C2nodes_unsorted mapping from overall det index to unique det (configlist_unsorted) index
269  * @param C2nodes_sorted mapping from overall det index to unique det (ciConfigList) index
270  */
271  void createDetData(const int ref_det_id,
272  const std::vector<ci_configuration2>& configlist_unsorted,
273  const std::vector<size_t>& C2nodes_unsorted,
274  std::vector<size_t>& C2nodes_sorted);
275 
276  /** evaluate the value of all the unique determinants with one electron moved. Used by the table method
277  *@param P particle set which provides the positions
278  *@param iat the index of the moved electron
279  *@param refPtcl if given, the id of the reference particle in virtual moves
280  */
281  void evaluateDetsForPtclMove(const ParticleSet& P, int iat, int refPtcl = -1);
282  /// multi walker version of evaluateDetsForPtclMove
284  const RefVectorWithLeader<ParticleSet>& P_list,
285  int iat);
286 
287  /// evaluate the value and gradients of all the unique determinants with one electron moved. Used by the table method
288  void evaluateDetsAndGradsForPtclMove(const ParticleSet& P, int iat);
289  /// multi walker version of mw_evaluateDetsAndGradsForPtclMove
291  const RefVectorWithLeader<ParticleSet>& P_list,
292  int iat,
293  UnpinnedOffloadMatrix<ValueType>& mw_grads);
294  /// evaluate the value and gradients of all the unique determinants with one electron moved. Used by the table method. Includes Spin Gradient data
296 
297 
298  /// evaluate the gradients of all the unique determinants with one electron moved. Used by the table method
299  void evaluateGrads(ParticleSet& P, int iat);
300  /// multi walker version of mw_evaluateGrads
302  const RefVectorWithLeader<ParticleSet>& P_list,
303  int iat,
304  UnpinnedOffloadMatrix<ValueType>& mw_grads);
305  /// evaluate the gradients of all the unique determinants with one electron moved. Used by the table method. Includes Spin Gradient data
306  void evaluateGradsWithSpin(ParticleSet& P, int iat);
307 
308  // full evaluation of all the structures from scratch, used in evaluateLog for example
309  void evaluateForWalkerMove(const ParticleSet& P, bool fromScratch = true);
310  // full evaluation of all the structures from scratch, used in evaluateLog for example. Includes spin gradients for spin moves
311  void evaluateForWalkerMoveWithSpin(const ParticleSet& P, bool fromScratch = true);
312 
313  // accessors
314  inline int getNumDets() const { return ciConfigList->size(); }
315  inline int getNumPtcls() const { return NumPtcls; }
316  inline int getFirstIndex() const { return FirstIndex; }
317 
320  const Matrix<GradType>& getGrads() const { return grads; }
321  const Matrix<GradType>& getNewGrads() const { return new_grads; }
322  const Matrix<ValueType>& getLapls() const { return lapls; }
323  const Matrix<ValueType>& getNewLapls() const { return new_lapls; }
324  const Matrix<ValueType>& getSpinGrads() const { return spingrads; }
326 
327  PsiValue getRefDetRatio() const { return static_cast<PsiValue>(curRatio); }
329 
330 private:
331  void mw_InverseUpdateByColumn(MultiDiracDetMultiWalkerResource& mw_res,
332  const int working_index,
333  const OffloadVector<ValueType>& curRatio_list,
334  const OffloadVector<ValueType*>& psiV_deviceptr_list,
335  const OffloadVector<ValueType*>& psiMinv_deviceptr_list,
336  const size_t psiMinv_rows) const;
337 
338  /** update ratios with respect to the reference deteriminant for a given excitation level
339  * @param ext_level excitation level
340  * @param det_offset offset of the determinant id
341  * @param data_offset offset of the "data" structure
342  * @param sign of determinants
343  * @param table_matrix_list list of table_matrix
344  *
345  * this is a general implementation. Support abitrary excitation level
346  */
347  void mw_updateRatios_generic(const int ext_level,
348  const size_t det_offset,
349  const size_t data_offset,
350  SmallMatrixDetCalculator<ValueType>& det_calculator,
351  const OffloadVector<int>& data,
353  const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
354  const RefVector<OffloadVector<ValueType>>& ratios_list) const;
355 
356  /** update ratios of the reference deteriminant
357  * @param det0_list list of reference det value
358  */
359  void mw_updateRatios_det0(const OffloadVector<ValueType>& det0_list,
360  const OffloadVector<ValueType*>& ratios_deviceptr_list) const;
361 
362  /** update ratios with respect to the reference deteriminant for a given excitation level
363  * @param det_offset offset of the determinant id
364  * @param data_offset offset of the "data" structure
365  * @param sign of determinants
366  * @param table_matrix_list list of table_matrix
367  *
368  * this is intended to be customized based on EXT_LEVEL
369  */
370  template<unsigned EXT_LEVEL>
371  void mw_updateRatios(const size_t det_offset,
372  const size_t data_offset,
373  const OffloadVector<int>& data,
375  const OffloadVector<ValueType*>& table_matrix_deviceptr_list,
376  const size_t num_table_matrix_cols,
377  const OffloadVector<ValueType*>& ratios_deviceptr_list) const;
378 
379  /** Function to calculate the ratio of the excited determinant to the reference determinant in CustomizedMatrixDet following the paper by Clark et al. JCP 135(24), 244105
380  *@param nw Number of walkers in the batch
381  *@param ref ID of the reference determinant
382  *@param det0_list takes lists of ValueType(1) for the value or RatioGrad/curRatio for the gradients
383  *@param psiinv_list
384  *@param psi_list
385  *@param data (Shared by all determinants)
386  *@param pairs is the number of unique determinants (std::pair[Nb_unique_alpha][Nb_unique_beta]) (Shared by all determinants)
387  *@param sign (Shared by all determinants)
388  *@param table_matrix_list stores all the dot products between 2 determinants (I,J)
389  *@param ratio_list returned computed ratios
390  */
391  void mw_buildTableMatrix_calculateRatios_impl(MultiDiracDetMultiWalkerResource& mw_res,
392  int ref,
393  const OffloadVector<ValueType>& det0_list,
394  const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
395  const RefVector<OffloadMatrix<ValueType>>& psi_list,
396  const OffloadVector<int>& data,
397  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
399  const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
400  const RefVector<OffloadVector<ValueType>>& ratios_list);
401 
402  /** Function to calculate the ratio of the excited determinant to the reference determinant in CustomizedMatrixDet following the paper by Clark et al. JCP 135(24), 244105
403  *@param ref ID of the reference determinant
404  *@param det0 take ValueType(1) for the value or RatioGrad/curRatio for the gradients
405  *@param ratios returned computed ratios
406  *@param psiinv
407  *@param psi
408  *@param table_matrix stores all the dot products between 2 determinants (I,J)
409  *@param data (Shared by all determinants)
410  *@param pairs is the number of unique determinants (std::pair[Nb_unique_alpha][Nb_unique_beta]) (Shared by all determinants)
411  *@param sign (Shared by all determinants)
412  */
414  ValueType det0,
415  ValueType* restrict ratios,
416  const OffloadMatrix<ValueType>& psiinv,
417  const OffloadMatrix<ValueType>& psi,
418  OffloadMatrix<ValueType>& table_matrix,
419  const OffloadVector<int>& data,
420  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
422 
423  /** compute the ratio of the excited determinants to the reference determinant
424  * @param ratios the output.
425  */
427  const OffloadMatrix<ValueType>& psiinv,
428  const OffloadMatrix<ValueType>& psi,
429  const OffloadVector<int>& data,
430  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
432  OffloadMatrix<ValueType>& table_matrix,
433  OffloadVector<ValueType>& ratios);
434 
435  void mw_buildTableMatrix_calculateRatios(MultiDiracDetMultiWalkerResource& mw_res,
436  int ref,
437  const OffloadVector<ValueType>& det0_list,
438  const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
439  const RefVector<OffloadMatrix<ValueType>>& psi_list,
440  const OffloadVector<int>& data,
441  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
443  const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
444  const RefVector<OffloadVector<ValueType>>& ratios_list);
445 
446  /** Function to calculate the ratio of the gradients of the excited determinant to the reference determinant in CustomizedMatrixDet following the paper by Clark et al. JCP 135(24), 244105
447  *@param ref ID of the reference determinant
448  *@param psiinv
449  *@param psi
450  *@param data (Shared by all determinants)
451  *@param pairs is the number of unique determinants (std::pair[Nb_unique_alpha][Nb_unique_beta]) (Shared by all determinants)
452  *@param sign (Shared by all determinants)
453  *@param det0_grad gradient value taking RatioGrad/curRatio
454  *@param table_matrix stores all the dot products between 2 determinants (I,J)
455  *@param dx dimension (OHMMS_DIM)
456  *@param iat atom ID
457  *@param grads returned computed gradients
458  */
460  const OffloadMatrix<ValueType>& psiinv,
461  const OffloadMatrix<ValueType>& psi,
462  const OffloadVector<int>& data,
463  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
465  const ValueType& det0_grad,
466  OffloadMatrix<ValueType>& table_matrix,
467  int dx,
468  int iat,
470 
471  /** Function to calculate the ratio of the gradients of the excited determinant to the reference determinant in CustomizedMatrixDet following the paper by Clark et al. JCP 135(24), 244105
472  *@param nw Number of walkers in the batch
473  *@param ref ID of the reference determinant
474  *@param iat atom ID
475  *@param dx dimension (OHMMS_DIM)
476  *@param getNumDets Number of determinants
477  *@param psiinv_list
478  *@param psi_list
479  *@param data (Shared by all determinants)
480  *@param pairs is the number of unique determinants (std::pair[Nb_unique_alpha][Nb_unique_beta]) (Shared by all determinants)
481  *@param sign (Shared by all determinants)
482  *@param WorkSpace_list list refering to det.WorkSpace
483  *@param table_matrix_list stores all the dot products between 2 determinants (I,J)
484  *@param ratios_list returned computed list of gradients
485  */
486  void mw_buildTableMatrix_calculateGradRatios(MultiDiracDetMultiWalkerResource& mw_res,
487  int ref,
488  int iat,
489  int dx,
490  int getNumDets,
491  const OffloadVector<ValueType>& det0_grad_list,
492  const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
493  const RefVector<OffloadMatrix<ValueType>>& psi_list,
494  const OffloadVector<int>& data,
495  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
497  const RefVector<OffloadVector<ValueType>>& WorkSpace_list,
498  const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
499  UnpinnedOffloadMatrix<ValueType>& mw_grads);
500 
502  int ref,
503  const OffloadMatrix<ValueType>& psiinv,
504  const OffloadMatrix<ValueType>& psi,
505  const OffloadVector<int>& data,
506  const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
508  OffloadMatrix<ValueType>& table_matrix,
509  int iat,
510  Matrix<ValueType>& ratios);
511 
512  ///reset the size: with the number of particles
513  void resize();
514 
515  ///a set of single-particle orbitals used to fill in the values of the matrix
516  const std::unique_ptr<SPOSet> Phi;
517  ///number of single-particle orbitals which belong to this Dirac determinant
518  const int NumOrbitals;
519  ///index of the first particle with respect to the particle set
520  const int FirstIndex;
521  ///number of particles which belong to this Dirac determinant
522  const int NumPtcls;
523  ///index of the last particle with respect to the particle set
524  const int LastIndex;
525  ///use shared_ptr
526  std::shared_ptr<std::vector<ci_configuration2>> ciConfigList;
527  /// all the unique determinants are sorted, the id of the reference det id is always 0
528  static constexpr int ReferenceDeterminant = 0;
529  /// reference determinant occupation
530  std::shared_ptr<OffloadVector<size_t>> refdet_occup;
531  // flag to determine if spin arrays need to be resized and used. Set by ParticleSet::is_spinor_ in SlaterDetBuilder
532  const bool is_spinor_;
533 
534  /// psiM(i,j) \f$= \psi_j({\bf r}_i)\f$
535  /// TpsiM(i,j) \f$= psiM(j,i) \f$
537  /// inverse Dirac determinant matrix of the reference det
539  /// dpsiM(i,j) \f$= \nabla_i \psi_j({\bf r}_i)\f$
541  // temporaty storage
543  /// d2psiM(i,j) \f$= \nabla_i^2 \psi_j({\bf r}_i)\f$
545  /* dspin_psiM(i,j) \f$= \partial_{s_i} \psi_j({\bf r}_i,s_i)\f$ where \f$s_i\f$s is the spin variable
546  * This is only resized if a spinor calculation is used
547  */
549 
550  /// value of single-particle orbital for particle-by-particle update
551  //ValueVector psiV, psiV_temp;
556  //spin derivative of single-particle orbitals. Only resized if a spinor calculation
558 
560 
563 
568 
569  /// determinant ratios with respect to the reference determinant
571  /// new determinant ratios with respect to the updated reference determinant upon a proposed move
573  /// new value of the reference determinant over the old value upon a proposed move
575  /// log value of the reference determinant
577  /// store determinant grads (old and new)
579  /// store determinant lapls (old and new)
581  // additional storage for spin derivatives. Only resized if the calculation uses spinors
583 
584 
585  /* mmorales:
586  * i decided to stored the excitation information of all determinants in the following
587  * compact form: (all these integers are found consecutively in the array)
588  * For each determinant:
589  * -n : number of excitations
590  * -i1,i2,...,in : occupied orbital to be replaced (these must be numbers from 0:Nptcl-1)
591  * -a1,a2,...,an : excited states that replace the orbitals (these can be anything)
592  */
593  std::shared_ptr<OffloadVector<int>> detData;
594  std::shared_ptr<VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>> uniquePairs;
595  std::shared_ptr<OffloadVector<RealType>> DetSigns;
596  /** number of unique determinants at each excitation level (relative to reference)
597  * {1, n_singles, n_doubles, n_triples, ...}
598  */
599  std::shared_ptr<std::vector<int>> ndets_per_excitation_level_;
601 
602  /// for matrices with leading dimensions <= MaxSmallDet, compute determinant with direct expansion.
603  static constexpr size_t MaxSmallDet = 5;
604 
606 };
607 
608 
609 } // namespace qmcplusplus
610 #endif
base class for Single-particle orbital sets
Definition: SPOSet.h:46
~MultiDiracDeterminant() override
default destructor
std::shared_ptr< OffloadVector< size_t > > refdet_occup
reference determinant occupation
Matrix< ValueType > lapls
store determinant lapls (old and new)
WaveFunctionComponent::PsiValue PsiValue
Definition: SlaterDet.cpp:25
std::shared_ptr< std::vector< ci_configuration2 > > ciConfigList
use shared_ptr
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::GradType GradType
Definition: Configuration.h:62
std::shared_ptr< OffloadVector< int > > detData
MultiDiracDeterminant & operator=(const MultiDiracDeterminant &s)=delete
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
const int NumPtcls
number of particles which belong to this Dirac determinant
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
const std::unique_ptr< SPOSet > Phi
a set of single-particle orbitals used to fill in the values of the matrix
OffloadMatrix< GradType > dpsiM
dpsiM(i,j)
LogValue log_value_ref_det_
log value of the reference determinant
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21
ResourceHandle manages the temporary resource referenced from a collection.
OffloadMatrix< ValueType > psiMinv_temp
OrbitalSetTraits< ValueType >::ValueMatrix ValueMatrix
Definition: SPOSet.h:50
Matrix< GradType > grads
store determinant grads (old and new)
LatticeGaussianProduct::GradType GradType
std::shared_ptr< std::vector< int > > ndets_per_excitation_level_
number of unique determinants at each excitation level (relative to reference) {1, n_singles, n_doubles, n_triples, ...}
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
SoA adaptor class for Vector<TinyVector<T,D> >
Timer accumulates time and call counts.
Definition: NewTimer.h:135
void mw_buildTableMatrix_calculateGradRatios(MultiDiracDetMultiWalkerResource &mw_res, int ref, int iat, int dx, int getNumDets, const OffloadVector< ValueType > &det0_grad_list, const RefVector< OffloadMatrix< ValueType >> &psiinv_list, const RefVector< OffloadMatrix< ValueType >> &psi_list, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, const RefVector< OffloadVector< ValueType >> &WorkSpace_list, const RefVector< OffloadMatrix< ValueType >> &table_matrix_list, UnpinnedOffloadMatrix< ValueType > &mw_grads)
Function to calculate the ratio of the gradients of the excited determinant to the reference determin...
void evaluateGradsWithSpin(ParticleSet &P, int iat)
evaluate the gradients of all the unique determinants with one electron moved. Used by the table meth...
Attaches a unit to a Vector for IO.
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
static constexpr size_t MaxSmallDet
for matrices with leading dimensions <= MaxSmallDet, compute determinant with direct expansion...
void evaluateForWalkerMoveWithSpin(const ParticleSet &P, bool fromScratch=true)
const OffloadVector< ValueType > & getNewRatiosToRefDet() const
void createDetData(const int ref_det_id, const std::vector< ci_configuration2 > &configlist_unsorted, const std::vector< size_t > &C2nodes_unsorted, std::vector< size_t > &C2nodes_sorted)
create necessary structures related to unique determinants sort configlist_unsorted by excitation lev...
static void mw_accept_rejectMove(const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< bool > &isAccepted)
static constexpr int ReferenceDeterminant
all the unique determinants are sorted, the id of the reference det id is always 0 ...
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) final
extract underlying OptimizableObject references
ValueType evaluate(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L)
std::complex< QTFull::RealType > LogValue
const Matrix< ValueType > & getNewSpinGrads() const
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
void buildOptVariables(std::vector< size_t > &C2node)
create optimizable orbital rotation parameters
void mw_updateRatios_generic(const int ext_level, const size_t det_offset, const size_t data_offset, SmallMatrixDetCalculator< ValueType > &det_calculator, const OffloadVector< int > &data, const OffloadVector< RealType > &sign, const RefVector< OffloadMatrix< ValueType >> &table_matrix_list, const RefVector< OffloadVector< ValueType >> &ratios_list) const
update ratios with respect to the reference deteriminant for a given excitation level ...
An abstract class for a component of a many-body trial wave function.
void evaluateDetsAndGradsForPtclMoveWithSpin(const ParticleSet &P, int iat)
evaluate the value and gradients of all the unique determinants with one electron moved...
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
static void mw_evaluateGrads(const RefVectorWithLeader< MultiDiracDeterminant > &det_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, UnpinnedOffloadMatrix< ValueType > &mw_grads)
multi walker version of mw_evaluateGrads
void buildTableMatrix_calculateRatiosValueMatrixOneParticle(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, OffloadMatrix< ValueType > &table_matrix, int iat, Matrix< ValueType > &ratios)
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list) const
OffloadVector< ValueType > ratios_to_ref_
determinant ratios with respect to the reference determinant
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< MultiDiracDeterminant > &wfc_list) const
OffloadVector< ValueType > psiV
value of single-particle orbital for particle-by-particle update
void buildTableMatrix_calculateRatios_impl(int ref, ValueType det0, ValueType *restrict ratios, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, OffloadMatrix< ValueType > &table_matrix, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign)
Function to calculate the ratio of the excited determinant to the reference determinant in Customized...
QTBase::ValueType ValueType
Definition: Configuration.h:60
void mw_updateRatios_det0(const OffloadVector< ValueType > &det0_list, const OffloadVector< ValueType *> &ratios_deviceptr_list) const
update ratios of the reference deteriminant
std::shared_ptr< OffloadVector< RealType > > DetSigns
OffloadMatrix< ValueType > psiMinv
inverse Dirac determinant matrix of the reference det
static void mw_evaluateDetsForPtclMove(const RefVectorWithLeader< MultiDiracDeterminant > &det_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat)
multi walker version of evaluateDetsForPtclMove
OrbitalSetTraits< ValueType >::ValueVector ValueVector
Definition: SPOSet.h:49
const Matrix< GradType > & getGrads() const
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
int build_occ_vec(const OffloadVector< int > &data, const size_t nel, const size_t nmo, std::vector< int > &occ_vec)
helper function to buildOptVariables
std::shared_ptr< VectorSoaContainer< int, 2, OffloadPinnedAllocator< int > > > uniquePairs
ValueType curRatio
new value of the reference determinant over the old value upon a proposed move
OffloadVector< ValueType > WorkSpace
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
bool isFermionic() const final
true, if this component is fermionic
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
move was accepted, update the real container
const Matrix< ValueType > & getNewLapls() const
void mw_buildTableMatrix_calculateRatios_impl(MultiDiracDetMultiWalkerResource &mw_res, int ref, const OffloadVector< ValueType > &det0_list, const RefVector< OffloadMatrix< ValueType >> &psiinv_list, const RefVector< OffloadMatrix< ValueType >> &psi_list, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, const RefVector< OffloadMatrix< ValueType >> &table_matrix_list, const RefVector< OffloadVector< ValueType >> &ratios_list)
Function to calculate the ratio of the excited determinant to the reference determinant in Customized...
OMPallocator is an allocator with fused device and dualspace allocator functionality.
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
double sign(double x)
Definition: Standard.h:73
OffloadMatrix< ValueType > d2psiM
d2psiM(i,j)
bool isOptimizable() const final
if true, this contains optimizable components
OffloadMatrix< ValueType > table_matrix
SmallMatrixDetCalculator< ValueType > det_calculator_
OffloadVector< ValueType > psiV_temp
std::unique_ptr< SPOSet > clonePhi() const
return a clone of Phi
Define determinant operators.
std::vector< std::reference_wrapper< T > > RefVector
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, const MultiDiracDeterminant &pseudo_dn, const PsiValue &psiCurrent, const std::vector< ValueType > &Coeff, const std::vector< size_t > &C2node_up, const std::vector< size_t > &C2node_dn)
const Matrix< ValueType > & getSpinGrads() const
const int NumOrbitals
number of single-particle orbitals which belong to this Dirac determinant
void mw_buildTableMatrix_calculateRatios(MultiDiracDetMultiWalkerResource &mw_res, int ref, const OffloadVector< ValueType > &det0_list, const RefVector< OffloadMatrix< ValueType >> &psiinv_list, const RefVector< OffloadMatrix< ValueType >> &psi_list, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, const RefVector< OffloadMatrix< ValueType >> &table_matrix_list, const RefVector< OffloadVector< ValueType >> &ratios_list)
MultiDiracDeterminant(std::unique_ptr< SPOSet > &&spos, bool spinor, int first, int nel)
constructor
void evaluateDetsForPtclMove(const ParticleSet &P, int iat, int refPtcl=-1)
evaluate the value of all the unique determinants with one electron moved.
OffloadMatrix< ValueType > psiM
psiM(i,j) TpsiM(i,j)
OffloadVector< ValueType > new_ratios_to_ref_
new determinant ratios with respect to the updated reference determinant upon a proposed move ...
ResourceHandle< MultiDiracDetMultiWalkerResource > mw_res_handle_
void restore(int iat) override
move was rejected.
void evaluateDetsAndGradsForPtclMove(const ParticleSet &P, int iat)
evaluate the value and gradients of all the unique determinants with one electron moved...
const Matrix< ValueType > & getLapls() const
void evaluateForWalkerMove(const ParticleSet &P, bool fromScratch=true)
void mw_InverseUpdateByColumn(MultiDiracDetMultiWalkerResource &mw_res, const int working_index, const OffloadVector< ValueType > &curRatio_list, const OffloadVector< ValueType *> &psiV_deviceptr_list, const OffloadVector< ValueType *> &psiMinv_deviceptr_list, const size_t psiMinv_rows) const
LatticeGaussianProduct::ValueType ValueType
void resize()
reset the size: with the number of particles
void buildTableMatrix_calculateRatios(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, OffloadMatrix< ValueType > &table_matrix, OffloadVector< ValueType > &ratios)
compute the ratio of the excited determinants to the reference determinant
const int FirstIndex
index of the first particle with respect to the particle set
Declaration of WaveFunctionComponent.
std::complex< double > LogValue
const int LastIndex
index of the last particle with respect to the particle set
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
static void mw_evaluateDetsAndGradsForPtclMove(const RefVectorWithLeader< MultiDiracDeterminant > &det_list, const RefVectorWithLeader< ParticleSet > &P_list, int iat, UnpinnedOffloadMatrix< ValueType > &mw_grads)
multi walker version of mw_evaluateDetsAndGradsForPtclMove
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
std::vector< std::vector< int > > lookup_tbl
const Matrix< GradType > & getNewGrads() const
std::string getClassName() const override
return class name
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
void mw_updateRatios(const size_t det_offset, const size_t data_offset, const OffloadVector< int > &data, const OffloadVector< RealType > &sign, const OffloadVector< ValueType *> &table_matrix_deviceptr_list, const size_t num_table_matrix_cols, const OffloadVector< ValueType *> &ratios_deviceptr_list) const
update ratios with respect to the reference deteriminant for a given excitation level ...
const OffloadVector< ValueType > & getRatiosToRefDet() const
void evaluateGrads(ParticleSet &P, int iat)
evaluate the gradients of all the unique determinants with one electron moved. Used by the table meth...
MultiDiracDetMultiWalkerResource(const MultiDiracDetMultiWalkerResource &)
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
void buildTableMatrix_calculateGradRatios(int ref, const OffloadMatrix< ValueType > &psiinv, const OffloadMatrix< ValueType > &psi, const OffloadVector< int > &data, const VectorSoaContainer< int, 2, OffloadPinnedAllocator< int >> &pairs, const OffloadVector< RealType > &sign, const ValueType &det0_grad, OffloadMatrix< ValueType > &table_matrix, int dx, int iat, Matrix< GradType > &grads)
Function to calculate the ratio of the gradients of the excited determinant to the reference determin...