QMCPACK
TrialWaveFunction.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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
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 TrialWaveFunction.h
20  *@brief Declaration of a TrialWaveFunction
21  */
22 #ifndef QMCPLUSPLUS_TRIALWAVEFUNCTION_H
23 #define QMCPLUSPLUS_TRIALWAVEFUNCTION_H
24 
25 #include "Message/MPIObjectBase.h"
28 #include "Utilities/TimerManager.h"
32 #include "TWFGrads.hpp"
34 
35 /**@defgroup MBWfs Many-body wave function group
36  * @brief Classes to handle many-body trial wave functions
37  */
38 
39 namespace qmcplusplus
40 {
41 class MultiSlaterDetTableMethod;
42 
43 /** @ingroup MBWfs
44  * @brief Class to represent a many-body trial wave function
45  *
46  *A many-body trial wave function is represented by
47  *\f$\Psi({\bf R}) = \prod_i \psi_i({\bf R})\f$,
48  *where each function \f$\psi_i({\bf R})\f$ is an WaveFunctionComponent
49  (see WaveFunctionComponent).
50  *A Composite Pattern is used to handle \f$\prod\f$ operations.
51  *Each WaveFunctionComponent should provide proper evaluate functions
52  *for the value, gradient and laplacian values.
53  *
54  * mw_ prefix is a function name signature indicating it is for handling
55  * a batch of TrialWaveFunction objects in a lock-step fashion. These functions
56  * are defined statically because they should not have access to a
57  * concrete TWF object except through the passed RefVectorWithLeader<TWF>&.
58  * It dispatches to mw_ functions of WaveFunctionComponent
59  */
61 {
62 public:
63  // derived types from WaveFunctionComponent
66 
67 #ifndef NDEBUG
69 #endif
70 
80 
82 
83  /// enum type for computing partial WaveFunctionComponents
84  enum class ComputeType
85  {
86  ALL,
87  FERMIONIC,
89  };
90 
91  ///differential gradients
93  ///differential laplacians
95 
96  TrialWaveFunction(const RuntimeOptions& runtime_options, const std::string_view aname = "psi0", bool tasking = false);
97 
98  // delete copy constructor
99  TrialWaveFunction(const TrialWaveFunction&) = delete;
100  // deleteFassign operator
102 
104 
105  inline int size() const { return Z.size(); }
106  inline RealType getPhase() const { return PhaseValue; }
107 
108  inline void setPhase(RealType PhaseValue_new) { PhaseValue = PhaseValue_new; }
109  void getLogs(std::vector<RealType>& lvals);
110  void getPhases(std::vector<RealType>& pvals);
111 
112  inline RealType getPhaseDiff() const { return PhaseDiff; }
113  inline void resetPhaseDiff() { PhaseDiff = 0.0; }
114  inline RealType getLogPsi() const { return log_real_; }
115  inline void setLogPsi(RealType LogPsi_new) { log_real_ = LogPsi_new; }
116 
117  /** add a WaveFunctionComponent
118  * @param aterm a WaveFunctionComponent pointer
119  */
120  void addComponent(std::unique_ptr<WaveFunctionComponent>&& aterm);
121 
122  ///read from xmlNode
123  bool put(xmlNodePtr cur);
124 
125  // Wavefunction Parameter Optimization
126  //
127  // The wavefunction consists of a set of components (derived from WaveFunctionComponent).
128  // Each of these components may or may not have variational parameters.
129  // In order to perform optimization:
130  // 1. Parameters are collected into a single list.
131  // 2. Optimization algorithm computes new values for those parameters.
132  // 3. Changed parameters are propagated back to each of the components.
133  //
134  // The collection of variables is of type VariableSet (opt_variables_type is a typedef).
135  // The variables local to each component are stored in WaveFunctionComponent::myVars, which
136  // is set to the local parameters when the component is set up.
137  // The call to checkInVariables collects all the local parameters into a global list (step 1).
138  // The resetIndex function on VariableSet then computes indices for this global list.
139  // The call to checkOutVariables sets up the mapping from global index to local index in each component's 'myVars'.
140  // Finally, the call to resetParameters progates the new values (step 3).
141  // The call to checkOutVariables is a prerequisite for resetParameters to set the local values successfully.
142 
143  /** extract underlying OptimizableObject references
144  * @param opt_obj_refs aggregated list of optimizable object references
145  */
147 
148  /** Check in an optimizable parameter
149  * @param o aggregated list of optimizable variables
150  *
151  * Gather all the optimizable parameters from wavefunction components into a single list
152  */
154 
155  /** Check out optimizable variables
156  * Assign index mappings from global list (o) to local values in each component
157  */
158  void checkOutVariables(const opt_variables_type& o);
159 
160  /** Set values of parameters in each component from the global list
161  */
162  void resetParameters(const opt_variables_type& active);
163 
164 
165  /** print out state of the trial wavefunction
166  */
167  void reportStatus(std::ostream& os);
168 
169  /** Initialize a TWF wrapper for fast derivative evaluation
170  */
172  /** evalaute the log (internally gradients and laplacian) of the trial wavefunction. gold reference */
174 
175  /** batched version of evaluateLog. gold reference */
176  static void mw_evaluateLog(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
177  const RefVectorWithLeader<ParticleSet>& p_list);
178 
179  /** recompute the value of the orbitals which require critical accuracy */
180  void recompute(const ParticleSet& P);
181 
182  /** batched version of recompute*/
183  static void mw_recompute(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
184  const RefVectorWithLeader<ParticleSet>& p_list,
185  const std::vector<bool>& recompute);
186 
187  /** evaluate the log value of a many-body wave function
188  * @param P input configuration containing N particles
189  * @param recomputeall recompute all orbitals from scratch
190  * @return the value of \f$ \log( \Pi_i \Psi_i) \f$ many-body wave function
191  *
192  * @if recompute == true
193  * all orbitals have "evaluateLog" called on them, including the non-optimized ones.
194  * @else
195  * default value. call evaluateLog only on optimizable orbitals. OK if nonlocal pp's aren't used.
196  *
197  * To save time, logpsi, G, and L are only computed for orbitals that change over the course of the optimization.
198  * It is assumed that the fixed components are stored elsewhere. See evaluateDeltaLog(P,logpsi_fixed_r,logpsi_opt,fixedG,fixedL)
199  * defined below. Nonlocal pseudopotential evaluation requires temporary information like matrix inverses, so while
200  * the logpsi, G, and L don't change, evaluateLog is called anyways to compute these auxiliary quantities from scratch.
201  * logpsi, G, and L associated with these non-optimizable orbitals are discarded explicitly and with dummy variables.
202  */
203 
205 
206  /** evaluate the sum of log value of optimizable many-body wavefunctions
207  * @param P input configuration containing N particles
208  * @param logpsi_fixed log(std::abs(psi)) of the invariant orbitals
209  * @param logpsi_opt log(std::abs(psi)) of the variable orbitals
210  * @param fixedG gradients of log(psi) of the fixed wave functions
211  * @param fixedL laplacians of log(psi) of the fixed wave functions
212  *
213  * This function is introduced for optimization only.
214  * fixedG and fixedL save the terms coming from the wave functions
215  * that are invariant during optimizations.
216  * It is expected that evaluateDeltaLog(P,false) is called later
217  * and the external object adds the varying G and L and the fixed terms.
218  */
220  RealType& logpsi_fixed,
221  RealType& logpsi_opt,
224 
225  /** evaluate the sum of log value of optimizable many-body wavefunctions
226  * @param wf_list vector of wavefunctions
227  * @param p_list vector of input particle configurations
228  * @param logpsi_fixed_list vector of log(std::abs(psi)) of the invariant orbitals
229  * @param logpsi_opt_list vector of log(std::abs(psi)) of the variable orbitals
230  * @param fixedG_list vector of gradients of log(psi) of the fixed wave functions
231  * @param fixedL_list vector of laplacians of log(psi) of the fixed wave functions
232  *
233  * For wavefunction optimization, it can speed evaluation to split the log value,
234  * the gradient, and the laplacian computed from wavefunction components with optimizable
235  * parameters from components that do not. This function computes the log value of
236  * both parts, and the gradient and laplacian of the fixed components.
237  * During correlated sampling steps only the components with optimizable
238  * parameters need to have the gradient and laplacian re-evaluated.
239  *
240  * Parameters fixedG_list and fixedL_list save the terms coming from the components
241  * that do not have optimizable parameters.
242  * It is expected that mw_evaluateDeltaLog(P,false) is called later
243  * and the external object adds the varying G and L and the fixed terms.
244  */
246  const RefVectorWithLeader<ParticleSet>& p_list,
247  std::vector<RealType>& logpsi_fixed_list,
248  std::vector<RealType>& logpsi_opt_list,
251 
252  /** evaluate the log value for optimizable parts of a many-body wave function
253  * @param wf_list vector of wavefunctions
254  * @param p_list vector of input particle configurations
255  * @param logpsi_list vector of log(std::abs(psi)) of the variable orbitals
256  * @param dummyG_list vector of gradients of log(psi) of the fixed wave functions.
257  * @param dummyL_list vector of laplacians of log(psi) of the fixed wave functions
258  *
259  * The dummyG_list and dummyL_list are only referenced if recompute is true.
260  * If recompute is false, the storage of these lists are needed, but the values can be discarded.
261  *
262  * @if recompute == true
263  * all orbitals have "evaluateLog" called on them, including the non-optimized ones.
264  * @else
265  * default value. call evaluateLog only on optimizable orbitals. OK if nonlocal pp's aren't used.
266  *
267  * To save time, logpsi, G, and L are only computed for orbitals that change over the course of the optimization.
268  * It is assumed that the fixed components are stored elsewhere. See mw_evaluateDeltaLogSetup defined above.
269  * Nonlocal pseudopotential evaluation requires temporary information like matrix inverses, so while
270  * the logpsi, G, and L don't change, evaluateLog is called anyways to compute these auxiliary quantities from scratch.
271  * logpsi, G, and L associated with these non-optimizable orbitals are discarded explicitly and with dummy variables.
272  */
273 
274 
276  const RefVectorWithLeader<ParticleSet>& p_list,
277  std::vector<RealType>& logpsi_list,
280  bool recompute = false);
281 
282 
283  /** compute psi(R_new) / psi(R_current) ratio
284  * It returns a complex value if the wavefunction is complex.
285  * @param P the active ParticleSet
286  * @param iat the index of a particle moved to the new position.
287  * @param ct select ComputeType
288  * @return ratio value
289  */
291 
292  /** batched version of calcRatio */
293  static void mw_calcRatio(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
294  const RefVectorWithLeader<ParticleSet>& p_list,
295  int iat,
296  std::vector<PsiValue>& ratios,
298 
299  /** compulte multiple ratios to handle non-local moves and other virtual moves
300  */
301  void evaluateRatios(const VirtualParticleSet& VP, std::vector<ValueType>& ratios, ComputeType ct = ComputeType::ALL);
302 
303  /** Used by SOECPComponent to do faster SOC evaluation
304  */
305  void evaluateSpinorRatios(const VirtualParticleSet& VP, const std::pair<ValueVector, ValueVector>& spinor_multiplier, std::vector<ValueType>& ratios) const;
306 
307  /** batched version of evaluateRatios
308  * Note: unlike other mw_ static functions, *this is the batch leader instead of wf_list[0].
309  */
312  const RefVector<std::vector<ValueType>>& ratios_list,
314 
315  /** compute both ratios and deriatives of ratio with respect to the optimizables*/
317  const opt_variables_type& optvars,
318  std::vector<ValueType>& ratios,
319  Matrix<ValueType>& dratio);
320 
322 
323  /** Returns the logarithmic gradient of the trial wave function
324  * with respect to the iat^th atom of the source ParticleSet. */
325  GradType evalGradSource(ParticleSet& P, ParticleSet& source, int iat);
326  /** Returns the logarithmic gradient of the w.r.t. the iat^th atom
327  * of the source ParticleSet of the sum of laplacians w.r.t. the
328  * electrons (target ParticleSet) of the trial wave function. */
330  ParticleSet& source,
331  int iat,
334 
335  /** compute psi(R_new) / psi(R_current) ratio and \nabla ln(psi(R_new)) gradients
336  * It returns a complex value if the wavefunction is complex.
337  * @param P the active ParticleSet
338  * @param iat the index of a particle moved to the new position.
339  * @param grad_iat gradients. The consumer must verify if ratio is non-zero.
340  * @return ratio value. The caller must reject zero ratio moves.
341  */
342  ValueType calcRatioGrad(ParticleSet& P, int iat, GradType& grad_iat);
343 
344  /** compute psi(R_new) / psi(R_current) ratio and d/ds ln(psi(R_new)) spin gradient
345  * It returns a complex value if the wavefunction is complex.
346  * @param P the active ParticleSet
347  * @param iat the index of a particle moved to the new position.
348  * @param grad_iat real space gradient for iat. The consumer must verify if ratio is non-zero.
349  * @param spingrad_iat spin gradient for iat. The consumer must verify if ratio is non-zero.
350  * @return ratio value. The caller must reject zero ratio moves.
351  */
352  ValueType calcRatioGradWithSpin(ParticleSet& P, int iat, GradType& grad_iat, ComplexType& spingrad_iat);
353 
354  /** batched version of ratioGrad
355  *
356  * all vector sizes must match
357  * implements switch between normal and WithSpin version
358  */
359  template<CoordsType CT>
360  static void mw_calcRatioGrad(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
361  const RefVectorWithLeader<ParticleSet>& p_list,
362  int iat,
363  std::vector<PsiValue>& ratios,
364  TWFGrads<CT>& grads);
365 
366  /** Prepare internal data for updating WFC correspond to a particle group
367  * Particle groups usually correspond to determinants of different spins.
368  * This call can be used to handle precomputation for PbyP moves.
369  * @param P quantum particle set
370  * @param ig particle group index
371  */
372  void prepareGroup(ParticleSet& P, int ig);
373  /** batched version of prepareGroup
374  *
375  * all vector sizes must match
376  */
377  static void mw_prepareGroup(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
378  const RefVectorWithLeader<ParticleSet>& p_list,
379  int ig);
380 
381  GradType evalGrad(ParticleSet& P, int iat);
382 
383  /** compute d/ds ln(psi) spin gradient at current particle position for iat electron
384  *
385  * @param P active particle set.
386  * @param iat index of the particle moved to the new position.
387  * @param spingrad spingrad value. Zeroed out first, then filled with d/ds ln(psi).
388  * @return \nabla ln(psi) (complex)
389  *
390  */
391  GradType evalGradWithSpin(ParticleSet& P, int iat, ComplexType& spingrad);
392 
393  /** batched version of evalGrad
394  *
395  * This is static because it should have no direct access
396  * to any TWF.
397  * implements switch between normal and WithSpin version
398  */
399  template<CoordsType CT>
400  static void mw_evalGrad(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
401  const RefVectorWithLeader<ParticleSet>& p_list,
402  int iat,
403  TWFGrads<CT>& grads);
404 
405  void rejectMove(int iat);
406 
407  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false);
408  /* batched version of acceptMove */
410  const RefVectorWithLeader<ParticleSet>& p_list,
411  int iat,
412  const std::vector<bool>& isAccepted,
413  bool safe_to_delay = false);
414 
415  /** complete all the delayed or asynchronous operations before leaving the p-by-p move region.
416  * See WaveFunctionComponent::completeUpdates for more detail */
417  void completeUpdates();
418  /* batched version of completeUpdates. */
420 
421  /** compute gradients and laplacian of the TWF with respect to each particle.
422  * See WaveFunctionComponent::evaluateGL for more detail */
423  LogValue evaluateGL(ParticleSet& P, bool fromscratch);
424  /* batched version of evaluateGL.
425  */
426  static void mw_evaluateGL(const RefVectorWithLeader<TrialWaveFunction>& wf_list,
427  const RefVectorWithLeader<ParticleSet>& p_list,
428  bool fromscratch);
429 
430  /** register all the wavefunction components in buffer.
431  * See WaveFunctionComponent::registerData for more detail */
432  void registerData(ParticleSet& P, WFBufferType& buf);
433 
434  /** update all the wavefunction components in buffer.
435  * See WaveFunctionComponent::updateBuffer for more detail */
436  RealType updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false);
437 
438  /** copy all the wavefunction components from buffer.
439  * See WaveFunctionComponent::updateBuffer for more detail */
440  void copyFromBuffer(ParticleSet& P, WFBufferType& buf);
441 
442  /// initialize a shared resource and hand it to a collection
443  void createResource(ResourceCollection& collection) const;
444  /** acquire external resource
445  * Note: use RAII ResourceCollectionLock whenever possible
446  */
447  static void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<TrialWaveFunction>& wf_list);
448  /** release external resource
449  * Note: use RAII ResourceCollectionLock whenever possible
450  */
451  static void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<TrialWaveFunction>& wf_list);
452 
453  RealType KECorrection() const;
454 
456  const opt_variables_type& optvars,
457  Vector<ValueType>& dlogpsi,
458  Vector<ValueType>& dhpsioverpsi);
459 
461  const RefVectorWithLeader<ParticleSet>& p_list,
462  const opt_variables_type& optvars,
463  RecordArray<ValueType>& dlogpsi,
464  RecordArray<ValueType>& dhpsioverpsi);
465 
466  void evaluateDerivativesWF(ParticleSet& P, const opt_variables_type& optvars, Vector<ValueType>& dlogpsi);
467 
468  void evaluateGradDerivatives(const ParticleSet::ParticleGradient& G_in, std::vector<ValueType>& dgradlogpsi);
469 
470  /** evaluate the hessian w.r.t. electronic coordinates of particle iat **/
471  // void evaluateHessian(ParticleSet & P, int iat, HessType& grad_grad_psi);
472  /** evaluate the hessian hessian w.r.t. electronic coordinates of particle iat **/
473  void evaluateHessian(ParticleSet& P, HessVector& all_grad_grad_psi);
474 
475  std::unique_ptr<TrialWaveFunction> makeClone(ParticleSet& tqp) const;
476 
477  std::vector<std::unique_ptr<WaveFunctionComponent>> const& getOrbitals() { return Z; }
478 
479  void evaluateRatiosAlltoOne(ParticleSet& P, std::vector<ValueType>& ratios);
480 
481  void setTwist(const std::vector<RealType>& t) { myTwist = t; }
482  void setTwist(std::vector<RealType>&& t) { myTwist = std::move(t); }
483  const std::vector<RealType>& twist() const { return myTwist; }
484 
485  inline void setMassTerm(ParticleSet& P)
486  {
487  OneOverM = 1.0 / P.Mass[0];
488  //SpeciesSet tspecies(P.getSpeciesSet());
489  //int massind=tspecies.addAttribute("mass");
490  //RealType mass = tspecies(massind,0);
491  //OneOverM = 1.0/mass;
492  }
493 
495 
496  const std::string& getName() const { return myName; }
497 
498  bool use_tasking() const { return use_tasking_; }
499 
500  void storeXMLNode(xmlNodePtr node) { myNode_ = xmlCopyNode(node, 1); }
501 
502  xmlNodePtr getNode() const { return myNode_; }
503 
504  /// store an SPOSet map
505  void storeSPOMap(SPOMap&& spomap) { *spomap_ = std::move(spomap); }
506 
507  /// look up SPOSet named 'name', if not found, throw exception.
508  const SPOSet& getSPOSet(const std::string& name) const;
509 
510  /// spomap_ reference accessor
511  const SPOMap& getSPOMap() const { return *spomap_; }
512 
513  /// find MSD WFCs if exist
515 
516 private:
517  static void debugOnlyCheckBuffer(WFBufferType& buffer);
518 
519  /// @brief top-level runtime options from project data information > WaveFunctionPool
521 
522  /** XML input node for a many-body wavefunction. Copied from the original one.
523  * WFOpt driver needs to look it up and make its own copies.
524  * YL: updating parameters in an XML file is extremely messy. Better to make WFOpt using h5 only.
525  */
526  xmlNodePtr myNode_;
527 
528  /// Owned SPOSets. Once a TWF is fully built, SPOSet lookup should be done via TWF.
529  const std::shared_ptr<SPOMap> spomap_;
530 
531  ///getName is in the way
532  const std::string myName;
533 
534  ///starting index of the buffer
535  size_t BufferCursor;
536 
537  ///starting index of the scalar buffer
539 
540  ///sign of the trial wave function
542 
543  ///diff of the phase of the trial wave function during ratio calls
545 
546  ///real part of trial wave function log
548 
549  ///One over mass of target particleset, needed for Local Energy Derivatives
551 
552  /// if true, using internal tasking implementation
553  const bool use_tasking_;
554 
555  ///a list of WaveFunctionComponents constituting many-body wave functions
556  std::vector<std::unique_ptr<WaveFunctionComponent>> Z;
557 
558  /// For now, TrialWaveFunction will own the wrapper.
560  /// timers at TrialWaveFunction function call level
562  /// timers at WaveFunctionComponent function call level
563  std::vector<std::reference_wrapper<NewTimer>> WFC_timers_;
564  std::vector<RealType> myTwist;
565 
566  /** @{
567  * @brief helper function for extracting a list of WaveFunctionComponent from a list of TrialWaveFunction
568  */
569  static std::vector<WaveFunctionComponent*> extractWFCPtrList(const UPtrVector<TrialWaveFunction>& wf_list, int id);
570 
573  int id);
574  /** }@ */
575 
576  // helper function for extrating a list of gradients from a list of TrialWaveFunction
579 
580  // helper function for extracting a list of laplacian from a list of TrialWaveFunction
583 };
584 /**@}*/
585 } // namespace qmcplusplus
586 #endif
const std::vector< RealType > & twist() const
base class for Single-particle orbital sets
Definition: SPOSet.h:46
size_t BufferCursor_scalar
starting index of the scalar buffer
RealType evaluateLog(ParticleSet &P)
evalaute the log (internally gradients and laplacian) of the trial wavefunction.
WaveFunctionComponent::PsiValue PsiValue
WaveFunctionComponent::RealType RealType
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
TrialWaveFunction & operator=(const TrialWaveFunction &)=delete
void rejectMove(int iat)
restore to the original state
void evaluateSpinorRatios(const VirtualParticleSet &VP, const std::pair< ValueVector, ValueVector > &spinor_multiplier, std::vector< ValueType > &ratios) const
Used by SOECPComponent to do faster SOC evaluation.
ValueType calcRatio(ParticleSet &P, int iat, ComputeType ct=ComputeType::ALL)
compute psi(R_new) / psi(R_current) ratio It returns a complex value if the wavefunction is complex...
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios)
OrbitalSetTraits< ValueType >::ValueVector ValueVector
void copyFromBuffer(ParticleSet &P, WFBufferType &buf)
copy all the wavefunction components from buffer.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::GradType GradType
Definition: Configuration.h:62
void getLogs(std::vector< RealType > &lvals)
timer_manager class.
void createResource(ResourceCollection &collection) const
initialize a shared resource and hand it to a collection
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi)
evaluate derivatives of KE wrt optimizable varibles
QTBase::RealType RealType
Definition: Configuration.h:58
if(!okay) throw std xmlNodePtr node
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false)
update the state with the new data
void evaluateHessian(ParticleSet &P, HessVector &all_grad_grad_psi)
evaluate the hessian w.r.t.
void setMassTerm(ParticleSet &P)
static void mw_prepareGroup(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int ig)
batched version of prepareGroup
void evaluateDerivativesWF(ParticleSet &P, const opt_variables_type &optvars, Vector< ValueType > &dlogpsi)
static void mw_calcRatioGrad(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, TWFGrads< CT > &grads)
batched version of ratioGrad
void resetParameters(const opt_variables_type &active)
Set values of parameters in each component from the global list.
RealType PhaseDiff
diff of the phase of the trial wave function during ratio calls
A ParticleSet that handles virtual moves of a selected particle of a given physical ParticleSet Virtu...
WaveFunctionComponent::LogValue LogValue
const bool use_tasking_
if true, using internal tasking implementation
const SPOSet & getSPOSet(const std::string &name) const
look up SPOSet named &#39;name&#39;, if not found, throw exception.
TrialWaveFunction(const RuntimeOptions &runtime_options, const std::string_view aname="psi0", bool tasking=false)
ParticleAttrib< QTFull::ValueType > ParticleLaplacian
Definition: Configuration.h:96
LatticeGaussianProduct::GradType GradType
void printGL(ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L, std::string tag="GL")
ParticleSet::ParticleLaplacian L
differential laplacians
QTBase::ComplexType ComplexType
Definition: Configuration.h:59
const std::string & getName() const
std::vector< std::unique_ptr< T > > UPtrVector
declaration of MPIObjectBase
WaveFunctionComponent::ValueType ValueType
Attaches a unit to a Vector for IO.
static RefVectorWithLeader< WaveFunctionComponent > extractWFCRefList(const RefVectorWithLeader< TrialWaveFunction > &wf_list, int id)
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
static RefVector< ParticleSet::ParticleGradient > extractGRefList(const RefVectorWithLeader< TrialWaveFunction > &wf_list)
}@
static void mw_accept_rejectMove(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, const std::vector< bool > &isAccepted, bool safe_to_delay=false)
RealType updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false)
update all the wavefunction components in buffer.
OrbitalSetTraits< ValueType >::HessType HessType
A proxy class to the quantum ParticleSet.
std::unique_ptr< TrialWaveFunction > makeClone(ParticleSet &tqp) const
RefVector< MultiSlaterDetTableMethod > findMSD() const
find MSD WFCs if exist
WaveFunctionComponent::HessType HessType
void recompute(const ParticleSet &P)
recompute the value of the orbitals which require critical accuracy
void setLogPsi(RealType LogPsi_new)
std::complex< QTFull::RealType > LogValue
TWFFastDerivWrapper twf_prototype
For now, TrialWaveFunction will own the wrapper.
void evaluateDeltaLogSetup(ParticleSet &P, RealType &logpsi_fixed, RealType &logpsi_opt, ParticleSet::ParticleGradient &fixedG, ParticleSet::ParticleLaplacian &fixedL)
evaluate the sum of log value of optimizable many-body wavefunctions
UniqueOptObjRefs extractOptimizableObjectRefs()
extract underlying OptimizableObject references
ParticleSet::ParticleGradient G
differential gradients
RealType PhaseValue
sign of the trial wave function
static void mw_evaluateGL(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, bool fromscratch)
WaveFunctionComponent::ComplexType ComplexType
LogValue evaluateGL(ParticleSet &P, bool fromscratch)
compute gradients and laplacian of the TWF with respect to each particle.
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
std::vector< std::unique_ptr< WaveFunctionComponent > > Z
a list of WaveFunctionComponents constituting many-body wave functions
WaveFunctionComponent::WFBufferType WFBufferType
void setTwist(const std::vector< RealType > &t)
GradType evalGradWithSpin(ParticleSet &P, int iat, ComplexType &spingrad)
compute d/ds ln(psi) spin gradient at current particle position for iat electron
QTBase::ValueType ValueType
Definition: Configuration.h:60
void storeSPOMap(SPOMap &&spomap)
store an SPOSet map
void evaluateGradDerivatives(const ParticleSet::ParticleGradient &G_in, std::vector< ValueType > &dgradlogpsi)
WaveFunctionComponent::FullPrecRealType FullPrecRealType
static void mw_evaluateParameterDerivatives(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const opt_variables_type &optvars, RecordArray< ValueType > &dlogpsi, RecordArray< ValueType > &dhpsioverpsi)
static void mw_calcRatio(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, std::vector< PsiValue > &ratios, ComputeType ct=ComputeType::ALL)
batched version of calcRatio
const std::shared_ptr< SPOMap > spomap_
Owned SPOSets. Once a TWF is fully built, SPOSet lookup should be done via TWF.
RealType log_real_
real part of trial wave function log
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
GradType evalGradSource(ParticleSet &P, ParticleSet &source, int iat)
Returns the logarithmic gradient of the trial wave function with respect to the iat^th atom of the so...
static void mw_evaluateDeltaLog(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::vector< RealType > &logpsi_list, RefVector< ParticleSet::ParticleGradient > &dummyG_list, RefVector< ParticleSet::ParticleLaplacian > &dummyL_list, bool recompute=false)
evaluate the log value for optimizable parts of a many-body wave function
void registerData(ParticleSet &P, WFBufferType &buf)
register all the wavefunction components in buffer.
std::vector< std::unique_ptr< WaveFunctionComponent > > const & getOrbitals()
const SPOMap & getSPOMap() const
spomap_ reference accessor
ComputeType
enum type for computing partial WaveFunctionComponents
xmlNodePtr myNode_
XML input node for a many-body wavefunction.
void checkOutVariables(const opt_variables_type &o)
Check out optimizable variables Assign index mappings from global list (o) to local values in each co...
static void mw_evalGrad(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int iat, TWFGrads< CT > &grads)
batched version of evalGrad
static void mw_evaluateDeltaLogSetup(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::vector< RealType > &logpsi_fixed_list, std::vector< RealType > &logpsi_opt_list, RefVector< ParticleSet::ParticleGradient > &fixedG_list, RefVector< ParticleSet::ParticleLaplacian > &fixedL_list)
evaluate the sum of log value of optimizable many-body wavefunctions
static void debugOnlyCheckBuffer(WFBufferType &buffer)
static void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< TrialWaveFunction > &wf_list)
acquire external resource Note: use RAII ResourceCollectionLock whenever possible ...
static std::vector< WaveFunctionComponent * > extractWFCPtrList(const UPtrVector< TrialWaveFunction > &wf_list, int id)
helper function for extracting a list of WaveFunctionComponent from a list of TrialWaveFunction ...
WaveFunctionComponent::ValueVector ValueVector
void getPhases(std::vector< RealType > &pvals)
std::vector< RealType > myTwist
static void mw_completeUpdates(const RefVectorWithLeader< TrialWaveFunction > &wf_list)
WaveFunctionComponent::HessVector HessVector
TimerList_t TWF_timers_
timers at TrialWaveFunction function call level
std::vector< std::reference_wrapper< T > > RefVector
static void mw_recompute(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< bool > &recompute)
batched version of recompute
void reportStatus(std::ostream &os)
print out state of the trial wavefunction
RealType evaluateDeltaLog(ParticleSet &P, bool recompute=false)
evaluate the log value of a many-body wave function
Class to represent a many-body trial wave function.
static RefVector< ParticleSet::ParticleLaplacian > extractLRefList(const RefVectorWithLeader< TrialWaveFunction > &wf_list)
ParticleScalar Mass
mass of each particle
Definition: ParticleSet.h:87
GradType evalGrad(ParticleSet &P, int iat)
std::map< std::string, const std::unique_ptr< const SPOSet > > SPOMap
Definition: SPOSet.h:57
RealType OneOverM
One over mass of target particleset, needed for Local Energy Derivatives.
bool put(xmlNodePtr cur)
read from xmlNode
void storeXMLNode(xmlNodePtr node)
QMCTraits::ComplexType ComplexType
OrbitalSetTraits< ValueType >::HessVector HessVector
LatticeGaussianProduct::ValueType ValueType
ParticleAttrib< QTFull::GradType > ParticleGradient
Definition: Configuration.h:95
ValueType calcRatioGradWithSpin(ParticleSet &P, int iat, GradType &grad_iat, ComplexType &spingrad_iat)
compute psi(R_new) / psi(R_current) ratio and d/ds ln(psi(R_new)) spin gradient It returns a complex ...
const RuntimeOptions & runtime_options_
top-level runtime options from project data information > WaveFunctionPool
void evaluateDerivRatios(const VirtualParticleSet &VP, const opt_variables_type &optvars, std::vector< ValueType > &ratios, Matrix< ValueType > &dratio)
compute both ratios and deriatives of ratio with respect to the optimizables
QTFull::RealType FullPrecRealType
Definition: Configuration.h:66
size_t BufferCursor
starting index of the buffer
Declaration of WaveFunctionComponent.
std::complex< double > LogValue
static void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< TrialWaveFunction > &wf_list)
release external resource Note: use RAII ResourceCollectionLock whenever possible ...
void prepareGroup(ParticleSet &P, int ig)
Prepare internal data for updating WFC correspond to a particle group Particle groups usually corresp...
const std::string myName
getName is in the way
std::vector< std::reference_wrapper< NewTimer > > WFC_timers_
timers at WaveFunctionComponent function call level
void setTwist(std::vector< RealType > &&t)
void setPhase(RealType PhaseValue_new)
ValueType calcRatioGrad(ParticleSet &P, int iat, GradType &grad_iat)
compute psi(R_new) / psi(R_current) ratio and ln(psi(R_new)) gradients It returns a complex value if...
static void mw_evaluateRatios(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< const VirtualParticleSet > &Vp_list, const RefVector< std::vector< ValueType >> &ratios_list, ComputeType ct=ComputeType::ALL)
batched version of evaluateRatios Note: unlike other mw_ static functions, *this is the batch leader ...
void evaluateRatios(const VirtualParticleSet &VP, std::vector< ValueType > &ratios, ComputeType ct=ComputeType::ALL)
compulte multiple ratios to handle non-local moves and other virtual moves
void completeUpdates()
complete all the delayed or asynchronous operations before leaving the p-by-p move region...
void addComponent(std::unique_ptr< WaveFunctionComponent > &&aterm)
add a WaveFunctionComponent
static void mw_evaluateLog(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list)
batched version of evaluateLog.
void checkInVariables(opt_variables_type &o)
Check in an optimizable parameter.
void initializeTWFFastDerivWrapper(const ParticleSet &P, TWFFastDerivWrapper &twf) const
Initialize a TWF wrapper for fast derivative evaluation.