QMCPACK
NonLocalECPotential.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 // Peter W. Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #ifndef QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_H
19 #define QMCPLUSPLUS_NONLOCAL_ECPOTENTIAL_H
20 #include "Configuration.h"
24 #include "Particle/NeighborLists.h"
25 namespace qmcplusplus
26 {
27 class NonLocalECPComponent;
28 template<typename T>
29 struct NLPPJob;
30 
31 namespace testing
32 {
33 class TestNonLocalECPotential;
34 }
35 
36 /** @ingroup hamiltonian
37  * \brief Evaluate the semi local potentials
38  */
40 {
42 
44 
45 public:
46  NonLocalECPotential(ParticleSet& ions, ParticleSet& els, TrialWaveFunction& psi, bool computeForces, bool enable_DLA);
47  ~NonLocalECPotential() override;
48 
49  bool dependsOnWaveFunction() const override { return true; }
50  std::string getClassName() const override { return "NonLocalECPotential"; }
51  void resetTargetParticleSet(ParticleSet& P) override;
52 
53 #if !defined(REMOVE_TRACEMANAGER)
54  void contributeParticleQuantities() override;
55  void checkoutParticleQuantities(TraceManager& tm) override;
56  void deleteParticleQuantities() override;
57 #endif
58 
59  Return_t evaluate(ParticleSet& P) override;
63  const RefVectorWithLeader<ParticleSet>& p_list) const override;
64 
66 
69  const RefVectorWithLeader<ParticleSet>& p_list) const override;
70 
74  const std::vector<ListenerVector<Real>>& listeners,
75  const std::vector<ListenerVector<Real>>& listeners_ions) const override;
76 
80  const std::vector<ListenerVector<Real>>& listeners,
81  const std::vector<ListenerVector<Real>>& listeners_ions) const override;
82 
84  ParticleSet& ions,
85  TrialWaveFunction& psi,
86  ParticleSet::ParticlePos& hf_terms,
87  ParticleSet::ParticlePos& pulay_terms) override;
88 
90  ParticleSet& ions,
91  TrialWaveFunction& psi,
92  ParticleSet::ParticlePos& hf_terms,
93  ParticleSet::ParticlePos& pulay_terms) override;
94 
95  void evaluateOneBodyOpMatrix(ParticleSet& P, const TWFFastDerivWrapper& psi, std::vector<ValueMatrix>& B) override;
96 
98  ParticleSet& source,
99  const TWFFastDerivWrapper& psi,
100  const int iat,
101  std::vector<std::vector<ValueMatrix>>& Bforce) override;
102 
103 
104  /** set non local moves options
105  * @param cur the xml input
106  */
107  void setNonLocalMoves(xmlNodePtr cur) { UseTMove = nonLocalOps.put(cur); }
108 
109  void setNonLocalMoves(const std::string& non_local_move_option,
110  const double tau,
111  const double alpha,
112  const double gamma)
113  {
114  UseTMove = nonLocalOps.thingsThatShouldBeInMyConstructor(non_local_move_option, tau, alpha, gamma);
115  }
116  /** make non local moves with particle-by-particle moves
117  * @param P particle set
118  * @return the number of accepted moves
119  */
121 
123  const opt_variables_type& optvars,
124  const Vector<ValueType>& dlogpsi,
125  Vector<ValueType>& dhpsioverpsi) override;
126 
127  /** Do nothing */
128  bool put(xmlNodePtr cur) override { return true; }
129 
130  bool get(std::ostream& os) const override
131  {
132  os << "NonLocalECPotential: " << IonConfig.getName();
133  return true;
134  }
135 
136  /** initialize a shared resource and hand it to a collection
137  */
138  void createResource(ResourceCollection& collection) const override;
139 
140  /** acquire a shared resource from a collection
141  */
142  void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
143 
144  /** return a shared resource to a collection
145  */
146  void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<OperatorBase>& o_list) const override;
147 
148  std::unique_ptr<OperatorBase> makeClone(ParticleSet& qp, TrialWaveFunction& psi) override;
149 
150  void addComponent(int groupID, std::unique_ptr<NonLocalECPComponent>&& pp);
151 
152  /** set the internal RNG pointer as the given pointer
153  * @param rng input RNG pointer
154  */
156 
157  void addObservables(PropertySetType& plist, BufferType& collectables) override;
158 
159  void setObservables(PropertySetType& plist) override;
160 
161  void setParticlePropertyList(PropertySetType& plist, int offset) override;
162 
163  void registerObservables(std::vector<ObservableHelper>& h5list, hdf_archive& file) const override;
164 
165  /** Set the flag whether to compute forces or not.
166  * @param val The boolean value for computing forces
167  */
168  inline void setComputeForces(bool val) override { ComputeForces = val; }
169 
170 protected:
171  /** the actual implementation for batched walkers, used by mw_evaluate, mw_evaluateWithToperator
172  * mw_evaluatePerPaticleWithToperator
173  * @param o_list the list of NonLocalECPotential in a walker batch
174  * @param wf_list the list of TrialWaveFunction in a walker batch
175  * @param p_list the list of ParticleSet in a walker batch
176  * @param Tmove whether Txy for Tmove is updated
177  * @param listeners optional listeners which allow per particle and reduced to share impl
178  */
179  static void mw_evaluateImpl(const RefVectorWithLeader<OperatorBase>& o_list,
181  const RefVectorWithLeader<ParticleSet>& p_list,
182  bool Tmove,
183  std::optional<ListenerOption<Real>> listeners,
184  bool keepGrid = false);
185 
186  ///random number generator
188  ///the set of local-potentials (one for each ion)
189  std::vector<NonLocalECPComponent*> PP;
190  ///unique NonLocalECPComponent to remove
191  std::vector<std::unique_ptr<NonLocalECPComponent>> PPset;
192  ///reference to the center ion
194  ///target TrialWaveFunction
196  ///true if we should compute forces
198  ///true, determinant localization approximation(DLA) is enabled
199  bool use_DLA;
200 
201 private:
202  ///number of ions
203  int NumIons;
204  ///index of distance table for the ion-el pair
206  ///reference to the electrons
208  ///neighborlist of electrons
210  ///neighborlist of ions
212  ///use T-moves
213  int UseTMove;
214  ///ture if an electron is affected by other electrons moved by T-moves
215  std::vector<bool> elecTMAffected;
216  ///non local operator
218  ///Pulay force vector
220  // Tmove data
221  std::vector<NonLocalData> tmove_xy_;
222 #if !defined(REMOVE_TRACEMANAGER)
223  ///single particle trace samples
224 
227 #endif
228  ///NLPP job list of ion-electron pairs by spin group
229  std::vector<std::vector<NLPPJob<Real>>> nlpp_jobs;
230  /// mult walker shared resource
232 
233  /** the actual implementation, used by evaluate and evaluateWithToperator
234  * @param P particle set
235  * @param Tmove whether Txy for Tmove is updated
236  * @param keepGrid. If true, does not randomize the quadrature grid before evaluation.
237  */
238  void evaluateImpl(ParticleSet& P, bool Tmove, bool keepGrid = false);
239 
241  ParticleSet& ions,
242  TrialWaveFunction& psi,
243  ParticleSet::ParticlePos& hf_terms,
244  ParticleSet::ParticlePos& pulay_terms,
245  bool keepGrid = false);
246  /** compute the T move transition probability for a given electron
247  * member variable nonLocalOps.Txy is updated
248  * @param P particle set
249  * @param ref_elec reference electron id
250  */
251  void computeOneElectronTxy(ParticleSet& P, const int ref_elec);
252 
253  /** mark all the electrons affected by Tmoves and update ElecNeighborIons and IonNeighborElecs
254  * @param myTable electron ion distance table
255  * @param iel reference electron
256  * Note this function should be called before acceptMove for a Tmove
257  */
258  void markAffectedElecs(const DistanceTableAB& myTable, int iel);
259 
261 };
262 } // namespace qmcplusplus
263 #endif
void resetTargetParticleSet(ParticleSet &P) override
Reset the data with the target ParticleSet.
const std::string & getName() const
return the name
Return_t evaluateWithToperator(ParticleSet &P) override
Evaluate the local energy contribution of this component with Toperators updated if requested...
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
bool dependsOnWaveFunction() const override
return true if this operator depends on a wavefunction
QTBase::RealType RealType
Definition: Configuration.h:58
class to violate access control because evaluation of NonLocalECPotential uses RNG which we may not b...
std::vector< NonLocalData > tmove_xy_
void setObservables(PropertySetType &plist) override
Set the values evaluated by this object to plist Default implementation is to assign Value which is u...
void acquireResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
acquire a shared resource from a collection
ResourceHandle manages the temporary resource referenced from a collection.
void releaseResource(ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
return a shared resource to a collection
Declaration of OperatorBase.
std::string getClassName() const override
return class name
An object of this type is a listener expecting a callback to the report function with a vector of val...
Definition: Listener.hpp:38
int thingsThatShouldBeInMyConstructor(const std::string &non_local_move_option, const double tau, const double alpha, const double gamma)
replacement for put because wouldn&#39;t it be cool to know what the classes configuration actually is...
Declaration of NonLocalTOperator.
void evaluateOneBodyOpMatrixForceDeriv(ParticleSet &P, ParticleSet &source, const TWFFastDerivWrapper &psi, const int iat, std::vector< std::vector< ValueMatrix >> &Bforce) override
Evaluate "dB/dR" matrices for observable.
ParticleSet & IonConfig
reference to the center ion
class to handle hdf file
Definition: hdf_archive.h:51
std::vector< NonLocalECPComponent * > PP
the set of local-potentials (one for each ion)
int myTableIndex
index of distance table for the ion-el pair
NonLocalTOperator nonLocalOps
non local operator
bool ComputeForces
true if we should compute forces
Attaches a unit to a Vector for IO.
TWFFastDerivWrapper is a wrapper class for TrialWavefunction that provides separate and low level acc...
void registerObservables(std::vector< ObservableHelper > &h5list, hdf_archive &file) const override
add to observable descriptor for hdf5 The default implementation is to register a scalar for this->va...
ResourceHandle< NonLocalECPotentialMultiWalkerResource > mw_res_handle_
mult walker shared resource
Array< TraceReal, 1 > * Ve_sample
single particle trace samples
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
ParticleSet::Buffer_t BufferType
typedef for the serialized buffer
Definition: OperatorBase.h:75
void evaluateOneBodyOpMatrix(ParticleSet &P, const TWFFastDerivWrapper &psi, std::vector< ValueMatrix > &B) override
Evaluate "B" matrix for observable.
int makeNonLocalMovesPbyP(ParticleSet &P)
make non local moves with particle-by-particle moves
Return_t evaluateValueAndDerivatives(ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
void createResource(ResourceCollection &collection) const override
initialize a shared resource and hand it to a collection
static void mw_evaluateImpl(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, bool Tmove, std::optional< ListenerOption< Real >> listeners, bool keepGrid=false)
the actual implementation for batched walkers, used by mw_evaluate, mw_evaluateWithToperator mw_evalu...
ParticleSet & Peln
reference to the electrons
void computeOneElectronTxy(ParticleSet &P, const int ref_elec)
compute the T move transition probability for a given electron member variable nonLocalOps.Txy is updated
AB type of DistanceTable containing storage.
void mw_evaluate(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const override
Evaluate the contribution of this component of multiple walkers.
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
void addComponent(int groupID, std::unique_ptr< NonLocalECPComponent > &&pp)
int put(xmlNodePtr cur)
initialize the parameters
RandomBase< FullPrecRealType > * myRNG
random number generator
void checkoutParticleQuantities(TraceManager &tm) override
void evaluateImpl(ParticleSet &P, bool Tmove, bool keepGrid=false)
the actual implementation, used by evaluate and evaluateWithToperator
NeighborLists IonNeighborElecs
neighborlist of ions
void setNonLocalMoves(xmlNodePtr cur)
set non local moves options
NonLocalECPotential(ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool computeForces, bool enable_DLA)
constructor
An abstract class for Local Energy operators.
Definition: OperatorBase.h:59
bool use_DLA
true, determinant localization approximation(DLA) is enabled
Return_t evaluateWithIonDerivs(ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_terms, ParticleSet::ParticlePos &pulay_terms) override
Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase...
void setRandomGenerator(RandomBase< FullPrecRealType > *rng) override
set the internal RNG pointer as the given pointer
Evaluate the semi local potentials.
NeighborLists ElecNeighborIons
neighborlist of electrons
Class to represent a many-body trial wave function.
void addObservables(PropertySetType &plist, BufferType &collectables) override
named values to the property list Default implementaton uses addValue(plist_)
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
void markAffectedElecs(const DistanceTableAB &myTable, int iel)
mark all the electrons affected by Tmoves and update ElecNeighborIons and IonNeighborElecs ...
std::vector< std::vector< NLPPJob< Real > > > nlpp_jobs
NLPP job list of ion-electron pairs by spin group.
void mw_evaluateWithToperator(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const override
Evaluate the contribution of this component of multiple walkers.
std::vector< bool > elecTMAffected
ture if an electron is affected by other electrons moved by T-moves
Return_t evaluateWithIonDerivsDeterministic(ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_terms, ParticleSet::ParticlePos &pulay_terms) override
Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase...
Return_t evaluateDeterministic(ParticleSet &P) override
Evaluate the local energy contribution of this component, deterministically based on current state...
void setComputeForces(bool val) override
Set the flag whether to compute forces or not.
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) override
double B(double x, int k, int i, const std::vector< double > &t)
std::vector< std::unique_ptr< NonLocalECPComponent > > PPset
unique NonLocalECPComponent to remove
ParticleSet::ParticlePos PulayTerm
Pulay force vector.
void evalIonDerivsImpl(ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_terms, ParticleSet::ParticlePos &pulay_terms, bool keepGrid=false)
void mw_evaluatePerParticleWithToperator(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< Real >> &listeners, const std::vector< ListenerVector< Real >> &listeners_ions) const override
void setParticlePropertyList(PropertySetType &plist, int offset) override
Convenience container for common optional element to mw_eval.._impl.
Definition: Listener.hpp:76
TrialWaveFunction & Psi
target TrialWaveFunction
void setNonLocalMoves(const std::string &non_local_move_option, const double tau, const double alpha, const double gamma)
BareKineticEnergy::Return_t Return_t
void mw_evaluatePerParticle(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< Real >> &listeners, const std::vector< ListenerVector< Real >> &listeners_ions) const override
RecordNamedProperty< FullPrecRealType > PropertySetType
define PropertyList_t
Definition: Configuration.h:69
bool put(xmlNodePtr cur) override
Do nothing.