QMCPACK
SOECPotential Class Reference
+ Inheritance diagram for SOECPotential:
+ Collaboration diagram for SOECPotential:

Classes

struct  SOECPotentialMultiWalkerResource
 

Public Member Functions

 SOECPotential (ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool use_exact_spin)
 constructor More...
 
 ~SOECPotential () override
 
bool dependsOnWaveFunction () const override
 return true if this operator depends on a wavefunction More...
 
std::string getClassName () const override
 return class name More...
 
void resetTargetParticleSet (ParticleSet &P) override
 Reset the data with the target ParticleSet. More...
 
Return_t evaluate (ParticleSet &P) override
 Evaluate the local energy contribution of this component. More...
 
Return_t evaluateDeterministic (ParticleSet &P) override
 Evaluate the local energy contribution of this component, deterministically based on current state. More...
 
Return_t evaluateValueAndDerivatives (ParticleSet &P, const opt_variables_type &optvars, const Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
 Evaluate value and derivatives wrt the optimizables. More...
 
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. More...
 
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
 
bool put (xmlNodePtr cur) override
 Read the input parameter. More...
 
bool get (std::ostream &os) const override
 write about the class More...
 
std::unique_ptr< OperatorBasemakeClone (ParticleSet &qp, TrialWaveFunction &psi) final
 
void addComponent (int groupID, std::unique_ptr< SOECPComponent > &&pp)
 
void setRandomGenerator (RandomBase< FullPrecRealType > *rng) override
 Set the Random Generator object TODO: add docs. More...
 
void createResource (ResourceCollection &collection) const override
 Initialize a shared resource and hand it to a collection. More...
 
void acquireResource (ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
 Acquire a shared resource from a collection. More...
 
void releaseResource (ResourceCollection &collection, const RefVectorWithLeader< OperatorBase > &o_list) const override
 Return a shared resource to a collection. More...
 
- Public Member Functions inherited from OperatorBase
 OperatorBase ()
 Construct a new Operator Base object Default and unique empty constructor. More...
 
virtual ~OperatorBase ()=default
 
std::bitset< 8 > & getUpdateMode () noexcept
 get update_mode_ reference More...
 
Return_t getValue () const noexcept
 get a copy of value_ More...
 
std::string getName () const noexcept
 getter a copy of my_name_, rvalue small string optimization More...
 
void setName (const std::string name) noexcept
 Set my_name member, uses small string optimization (pass by value) More...
 
TraceRequestgetRequest () noexcept
 Get request_ member. More...
 
virtual void addObservables (PropertySetType &plist, BufferType &collectables)
 named values to the property list Default implementaton uses addValue(plist_) More...
 
virtual void registerObservables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
 add to observable descriptor for hdf5 The default implementation is to register a scalar for this->value_ More...
 
virtual void registerCollectables (std::vector< ObservableHelper > &h5desc, hdf_archive &file) const
 
virtual void setObservables (PropertySetType &plist)
 Set the values evaluated by this object to plist Default implementation is to assign Value which is updated by evaluate function using my_index_. More...
 
virtual void setParticlePropertyList (PropertySetType &plist, int offset)
 
virtual void setHistories (Walker_t &ThisWalker)
 
virtual void mw_evaluatePerParticle (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual void mw_evaluateWithParameterDerivatives (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< ParticleSet > &p_list, const opt_variables_type &optvars, const RecordArray< ValueType > &dlogpsi, RecordArray< ValueType > &dhpsioverpsi) const
 TODO: add docs. More...
 
virtual Return_t rejectedMove (ParticleSet &P)
 TODO: add docs. More...
 
virtual Return_t evaluateWithToperator (ParticleSet &P)
 Evaluate the local energy contribution of this component with Toperators updated if requested. More...
 
virtual void mw_evaluateWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list) const
 Evaluate the contribution of this component of multiple walkers. More...
 
virtual void mw_evaluatePerParticleWithToperator (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, const std::vector< ListenerVector< RealType >> &listeners, const std::vector< ListenerVector< RealType >> &listeners_ions) const
 Evaluate the contribution of this component of multiple walkers per particle and report to registerd listeners from objects in Estimators. More...
 
virtual Return_t evaluateWithIonDerivs (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual Return_t evaluateWithIonDerivsDeterministic (ParticleSet &P, ParticleSet &ions, TrialWaveFunction &psi, ParticleSet::ParticlePos &hf_term, ParticleSet::ParticlePos &pulay_term)
 Evaluate contribution to local energy and derivatives w.r.t ionic coordinates from OperatorBase. More...
 
virtual void evaluateOneBodyOpMatrix (ParticleSet &P, const TWFFastDerivWrapper &psi, std::vector< ValueMatrix > &B)
 Evaluate "B" matrix for observable. More...
 
virtual void evaluateOneBodyOpMatrixForceDeriv (ParticleSet &P, ParticleSet &source, const TWFFastDerivWrapper &psi, const int iat, std::vector< std::vector< ValueMatrix >> &Bforce)
 Evaluate "dB/dR" matrices for observable. More...
 
virtual void updateSource (ParticleSet &s)
 Update data associated with a particleset. More...
 
virtual Return_t getEnsembleAverage ()
 Return an average value by collective operation. More...
 
virtual void add2Hamiltonian (ParticleSet &qp, TrialWaveFunction &psi, QMCHamiltonian &targetH)
 TODO: add docs. More...
 
virtual void getRequiredTraces (TraceManager &tm)
 TODO: add docs. More...
 
virtual void informOfPerParticleListener ()
 
bool isClassical () const noexcept
 
bool isQuantum () const noexcept
 
bool isClassicalClassical () const noexcept
 
bool isQuantumClassical () const noexcept
 
bool isQuantumQuantum () const noexcept
 
bool getMode (const int i) const noexcept
 Return the mode i. More...
 
bool isNonLocal () const noexcept
 TODO: add docs. More...
 
bool hasListener () const noexcept
 
void contributeTraceQuantities ()
 Make trace quantities available. More...
 
void checkoutTraceQuantities (TraceManager &tm)
 Checkout trace arrays Derived classes must guard individual checkouts using request info. More...
 
void collectScalarTraces ()
 Collect scalar trace data. More...
 
void deleteTraceQuantities ()
 delete trace arrays More...
 

Static Protected Member Functions

static void mw_evaluateImpl (const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::optional< ListenerOption< Real >> listeners, bool keep_grid=false)
 

Protected Attributes

RandomBase< FullPrecRealType > * my_rng_
 
std::vector< SOECPComponent * > pp_
 
std::vector< std::unique_ptr< SOECPComponent > > ppset_
 
ParticleSetion_config_
 
TrialWaveFunctionpsi_
 
- Protected Attributes inherited from OperatorBase
std::bitset< 8 > update_mode_
 set the current update mode More...
 
Return_t value_
 current value More...
 
std::string name_
 name of this object More...
 
TraceRequest request_
 whether traces are being collected More...
 
int my_index_
 starting index of this object More...
 
Return_t new_value_
 a new value for a proposed move More...
 
Walker_tt_walker_
 reference to the current walker More...
 
bool streaming_particles_
 
bool have_required_traces_
 

Private Types

using Real = QMCTraits::RealType
 

Private Member Functions

void evaluateImpl (ParticleSet &elec, bool keep_grid=false)
 

Private Attributes

int num_ions_
 number of ions More...
 
int my_table_index_
 index of distance table for ion-el pair More...
 
ParticleSetpeln_
 reference to the electrons More...
 
NeighborLists elec_neighbor_ions_
 neighborlist of electrons More...
 
NeighborLists ion_neighbor_elecs_
 neighborlist of ions More...
 
std::vector< std::vector< NLPPJob< RealType > > > sopp_jobs_
 
ResourceHandle< SOECPotentialMultiWalkerResourcemw_res_handle_
 
const bool use_exact_spin_
 

Friends

class testing::TestSOECPotential
 

Additional Inherited Members

- Public Types inherited from OperatorBase
enum  EnergyDomains { KINETIC = 0, POTENTIAL, NO_ENERGY_DOMAIN }
 enum to denote energy domain of operators More...
 
enum  QuantumDomains {
  NO_QUANTUM_DOMAIN = 0, CLASSICAL, QUANTUM, CLASSICAL_CLASSICAL,
  QUANTUM_CLASSICAL, QUANTUM_QUANTUM
}
 
enum  {
  PRIMARY = 0, OPTIMIZABLE = 1, RATIOUPDATE = 2, PHYSICAL = 3,
  COLLECTABLE = 4, NONLOCAL = 5
}
 enum for update_mode More...
 
using Return_t = FullPrecRealType
 type of return value of evaluate More...
 
using ValueMatrix = SPOSet::ValueMatrix
 For fast derivative evaluation. More...
 
using GradMatrix = SPOSet::GradMatrix
 
using BufferType = ParticleSet::Buffer_t
 typedef for the serialized buffer More...
 
using Walker_t = ParticleSet::Walker_t
 typedef for the walker More...
 
using ParticleScalar = ParticleSet::Scalar_t
 typedef for the ParticleScalar More...
 
using SPOMap = SPOSet::SPOMap
 typedef for SPOMap More...
 
- Public Types inherited from QMCTraits
enum  { DIM = OHMMS_DIM, DIM_VGL = OHMMS_DIM + 2 }
 
using QTBase = QMCTypes< OHMMS_PRECISION, DIM >
 
using QTFull = QMCTypes< OHMMS_PRECISION_FULL, DIM >
 
using RealType = QTBase::RealType
 
using ComplexType = QTBase::ComplexType
 
using ValueType = QTBase::ValueType
 
using PosType = QTBase::PosType
 
using GradType = QTBase::GradType
 
using TensorType = QTBase::TensorType
 
using IndexType = OHMMS_INDEXTYPE
 define other types More...
 
using FullPrecRealType = QTFull::RealType
 
using FullPrecValueType = QTFull::ValueType
 
using PropertySetType = RecordNamedProperty< FullPrecRealType >
 define PropertyList_t More...
 
using PtclGrpIndexes = std::vector< std::pair< int, int > >
 
- Protected Member Functions inherited from OperatorBase
virtual void contributeScalarQuantities ()
 
virtual void checkoutScalarQuantities (TraceManager &tm)
 
virtual void collectScalarQuantities ()
 
virtual void deleteScalarQuantities ()
 
virtual void contributeParticleQuantities ()
 
virtual void checkoutParticleQuantities (TraceManager &tm)
 
virtual void deleteParticleQuantities ()
 
virtual void setComputeForces (bool compute)
 
void setEnergyDomain (EnergyDomains edomain)
 Set the Energy Domain. More...
 
void setQuantumDomain (QuantumDomains qdomain)
 set quantum domain More...
 
void oneBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for one-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P)
 set quantum domain for two-body operator More...
 
void twoBodyQuantumDomain (const ParticleSet &P1, const ParticleSet &P2)
 set quantum domain for two-body operator More...
 
void addValue (PropertySetType &plist)
 named values to the property list More...
 

Detailed Description

Definition at line 28 of file SOECPotential.h.

Member Typedef Documentation

◆ Real

using Real = QMCTraits::RealType
private

Definition at line 31 of file SOECPotential.h.

Constructor & Destructor Documentation

◆ SOECPotential()

SOECPotential ( ParticleSet ions,
ParticleSet els,
TrialWaveFunction psi,
bool  use_exact_spin 
)

constructor

Parameters
ionicpositions
elselectronic poitions
psiTrial wave function

Definition at line 44 of file SOECPotential.cpp.

References ParticleSet::addTable(), ParticleSet::getSpeciesSet(), SpeciesSet::getTotalNum(), ParticleSet::getTotalNum(), ParticleSet::groups(), ParticleSet::groupsize(), SOECPotential::ion_config_, SOECPotential::my_table_index_, SOECPotential::num_ions_, OperatorBase::POTENTIAL, SOECPotential::pp_, SOECPotential::ppset_, OperatorBase::setEnergyDomain(), SOECPotential::sopp_jobs_, and OperatorBase::twoBodyQuantumDomain().

45  : my_rng_(nullptr),
46  ion_config_(ions),
47  psi_(psi),
48  peln_(els),
50  ion_neighbor_elecs_(ions),
51  use_exact_spin_(use_exact_spin)
52 {
54  twoBodyQuantumDomain(ions, els);
55  my_table_index_ = els.addTable(ions);
56  num_ions_ = ions.getTotalNum();
57  pp_.resize(num_ions_, nullptr);
59  sopp_jobs_.resize(els.groups());
60  for (size_t ig = 0; ig < els.groups(); ig++)
61  sopp_jobs_[ig].reserve(2 * els.groupsize(ig));
62 }
void twoBodyQuantumDomain(const ParticleSet &P)
set quantum domain for two-body operator
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85
std::vector< std::vector< NLPPJob< RealType > > > sopp_jobs_
NeighborLists ion_neighbor_elecs_
neighborlist of ions
int my_table_index_
index of distance table for ion-el pair
Definition: SOECPotential.h:98
std::vector< SOECPComponent * > pp_
Definition: SOECPotential.h:84
int getTotalNum() const
return the number of species
Definition: SpeciesSet.h:55
NeighborLists elec_neighbor_ions_
neighborlist of electrons
void setEnergyDomain(EnergyDomains edomain)
Set the Energy Domain.
int num_ions_
number of ions
Definition: SOECPotential.h:96
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
ParticleSet & peln_
reference to the electrons
TrialWaveFunction & psi_
Definition: SOECPotential.h:87
RandomBase< FullPrecRealType > * my_rng_
Definition: SOECPotential.h:83

◆ ~SOECPotential()

~SOECPotential ( )
overridedefault

Member Function Documentation

◆ acquireResource()

void acquireResource ( ResourceCollection collection,
const RefVectorWithLeader< OperatorBase > &  o_list 
) const
overridevirtual

Acquire a shared resource from a collection.

Parameters
collection
o_list

Reimplemented from OperatorBase.

Definition at line 331 of file SOECPotential.cpp.

References RefVectorWithLeader< T >::getCastedLeader(), ResourceCollection::lendResource(), and SOECPotential::mw_res_handle_.

333 {
334  auto& O_leader = o_list.getCastedLeader<SOECPotential>();
335  O_leader.mw_res_handle_ = collection.lendResource<SOECPotentialMultiWalkerResource>();
336 }
SOECPotential(ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool use_exact_spin)
constructor

◆ addComponent()

void addComponent ( int  groupID,
std::unique_ptr< SOECPComponent > &&  pp 
)

Definition at line 311 of file SOECPotential.cpp.

References ParticleSet::GroupID, SOECPotential::ion_config_, SOECPotential::pp_, and SOECPotential::ppset_.

Referenced by qmcplusplus::doSOECPotentialTest().

312 {
313  for (int iat = 0; iat < pp_.size(); iat++)
314  if (ion_config_.GroupID[iat] == groupID)
315  pp_[iat] = ppot.get();
316  ppset_[groupID] = std::move(ppot);
317 }
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85
ParticleIndex GroupID
Species ID.
Definition: ParticleSet.h:77
std::vector< SOECPComponent * > pp_
Definition: SOECPotential.h:84

◆ createResource()

void createResource ( ResourceCollection collection) const
overridevirtual

Initialize a shared resource and hand it to a collection.

Parameters
collection

Reimplemented from OperatorBase.

Definition at line 319 of file SOECPotential.cpp.

References ResourceCollection::addResource(), and SOECPotential::ppset_.

Referenced by qmcplusplus::doSOECPotentialTest().

320 {
321  auto new_res = std::make_unique<SOECPotentialMultiWalkerResource>();
322  for (int ig = 0; ig < ppset_.size(); ig++)
323  if (ppset_[ig]->getVP())
324  {
325  ppset_[ig]->getVP()->createResource(new_res->collection);
326  break;
327  }
328  auto resource_index = collection.addResource(std::move(new_res));
329 }
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85

◆ dependsOnWaveFunction()

bool dependsOnWaveFunction ( ) const
inlineoverridevirtual

return true if this operator depends on a wavefunction

Reimplemented from OperatorBase.

Definition at line 37 of file SOECPotential.h.

37 { return true; }

◆ evaluate()

SOECPotential::Return_t evaluate ( ParticleSet P)
overridevirtual

Evaluate the local energy contribution of this component.

Parameters
Pinput configuration containing N particles
Returns
the value of the Hamiltonian component

Implements OperatorBase.

Definition at line 68 of file SOECPotential.cpp.

References SOECPotential::evaluateImpl(), and OperatorBase::value_.

69 {
70  evaluateImpl(P, false);
71  return value_;
72 }
void evaluateImpl(ParticleSet &elec, bool keep_grid=false)
Return_t value_
current value
Definition: OperatorBase.h:524

◆ evaluateDeterministic()

SOECPotential::Return_t evaluateDeterministic ( ParticleSet P)
overridevirtual

Evaluate the local energy contribution of this component, deterministically based on current state.

The correct behavior of this routine requires estimators with non-deterministic components in their evaluate() function to override this function.

Parameters
Pinput configuration containing N particles
Returns
the value of the Hamiltonian component

Reimplemented from OperatorBase.

Definition at line 74 of file SOECPotential.cpp.

References SOECPotential::evaluateImpl(), and OperatorBase::value_.

75 {
76  evaluateImpl(P, true);
77  return value_;
78 }
void evaluateImpl(ParticleSet &elec, bool keep_grid=false)
Return_t value_
current value
Definition: OperatorBase.h:524

◆ evaluateImpl()

void evaluateImpl ( ParticleSet elec,
bool  keep_grid = false 
)
private

Definition at line 80 of file SOECPotential.cpp.

References SOECPotential::elec_neighbor_ions_, qmcplusplus::generateRandomRotationMatrix(), ParticleSet::getDistTableAB(), NeighborLists::getNeighborList(), ParticleSet::getTotalNum(), SOECPotential::ion_neighbor_elecs_, SOECPotential::my_rng_, SOECPotential::my_table_index_, SOECPotential::num_ions_, SOECPotential::pp_, SOECPotential::ppset_, SOECPotential::psi_, SOECPotential::use_exact_spin_, and OperatorBase::value_.

Referenced by TestSOECPotential::evalFast(), SOECPotential::evaluate(), and SOECPotential::evaluateDeterministic().

81 {
82  value_ = 0.0;
83  if (!keep_grid)
84  for (int ipp = 0; ipp < ppset_.size(); ipp++)
85  if (ppset_[ipp])
86  ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*my_rng_));
87 
88  const auto& ble = P.getDistTableAB(my_table_index_);
89  for (int iat = 0; iat < num_ions_; iat++)
91  for (int jel = 0; jel < P.getTotalNum(); jel++)
93 
94  for (int jel = 0; jel < P.getTotalNum(); jel++)
95  {
96  const auto& dist = ble.getDistRow(jel);
97  const auto& displ = ble.getDisplRow(jel);
98  std::vector<int>& NeighborIons = elec_neighbor_ions_.getNeighborList(jel);
99  for (int iat = 0; iat < num_ions_; iat++)
100  if (pp_[iat] != nullptr && dist[iat] < pp_[iat]->getRmax())
101  {
102  RealType pairpot = 0;
103  if (use_exact_spin_)
104  pairpot = pp_[iat]->evaluateOneExactSpinIntegration(P, iat, psi_, jel, dist[iat], -displ[iat]);
105  else
106  pairpot = pp_[iat]->evaluateOne(P, iat, psi_, jel, dist[iat], -displ[iat]);
107  value_ += pairpot;
108  NeighborIons.push_back(iat);
109  ion_neighbor_elecs_.getNeighborList(iat).push_back(jel);
110  }
111  }
112 }
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85
NeighborLists ion_neighbor_elecs_
neighborlist of ions
int my_table_index_
index of distance table for ion-el pair
Definition: SOECPotential.h:98
std::vector< SOECPComponent * > pp_
Definition: SOECPotential.h:84
NeighborLists elec_neighbor_ions_
neighborlist of electrons
int num_ions_
number of ions
Definition: SOECPotential.h:96
QMCTraits::TensorType generateRandomRotationMatrix(RandomBase< QMCTraits::FullPrecRealType > &rng)
Create a random 3D rotation matrix using a random generator.
QMCTraits::RealType RealType
Return_t value_
current value
Definition: OperatorBase.h:524
TrialWaveFunction & psi_
Definition: SOECPotential.h:87
std::vector< int > & getNeighborList(int source)
get the neighbor list of the source particle
Definition: NeighborLists.h:32
RandomBase< FullPrecRealType > * my_rng_
Definition: SOECPotential.h:83

◆ evaluateValueAndDerivatives()

SOECPotential::Return_t evaluateValueAndDerivatives ( ParticleSet P,
const opt_variables_type optvars,
const Vector< ValueType > &  dlogpsi,
Vector< ValueType > &  dhpsioverpsi 
)
overridevirtual

Evaluate value and derivatives wrt the optimizables.

Default uses evaluate.

Parameters
P
optvars
dlogpsi
dhpsioverpsi
Returns
Return_t

Reimplemented from OperatorBase.

Definition at line 114 of file SOECPotential.cpp.

References qmcplusplus::generateRandomRotationMatrix(), DistanceTableAB::getDistRow(), ParticleSet::getDistTableAB(), ParticleSet::getTotalNum(), SOECPotential::my_rng_, SOECPotential::my_table_index_, SOECPotential::num_ions_, SOECPotential::pp_, SOECPotential::ppset_, SOECPotential::psi_, and OperatorBase::value_.

118 {
119  value_ = 0.0;
120  for (int ipp = 0; ipp < ppset_.size(); ipp++)
121  if (ppset_[ipp])
122  ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*my_rng_));
123 
124  const auto& ble = P.getDistTableAB(my_table_index_);
125  for (int jel = 0; jel < P.getTotalNum(); jel++)
126  {
127  const auto& dist = ble.getDistRow(jel);
128  const auto& displ = ble.getDisplRow(jel);
129  for (int iat = 0; iat < num_ions_; iat++)
130  if (pp_[iat] != nullptr && dist[iat] < pp_[iat]->getRmax())
131  value_ += pp_[iat]->evaluateValueAndDerivatives(P, iat, psi_, jel, dist[iat], -displ[iat], optvars, dlogpsi,
132  dhpsioverpsi);
133  }
134  return value_;
135 }
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85
int my_table_index_
index of distance table for ion-el pair
Definition: SOECPotential.h:98
std::vector< SOECPComponent * > pp_
Definition: SOECPotential.h:84
int num_ions_
number of ions
Definition: SOECPotential.h:96
QMCTraits::TensorType generateRandomRotationMatrix(RandomBase< QMCTraits::FullPrecRealType > &rng)
Create a random 3D rotation matrix using a random generator.
Return_t value_
current value
Definition: OperatorBase.h:524
TrialWaveFunction & psi_
Definition: SOECPotential.h:87
RandomBase< FullPrecRealType > * my_rng_
Definition: SOECPotential.h:83

◆ get()

bool get ( std::ostream &  os) const
inlineoverridevirtual

write about the class

Implements OperatorBase.

Definition at line 61 of file SOECPotential.h.

References OhmmsElementBase::getName(), and SOECPotential::ion_config_.

62  {
63  os << "SOECPotential: " << ion_config_.getName();
64  return true;
65  }
const std::string & getName() const
return the name

◆ getClassName()

std::string getClassName ( ) const
inlineoverridevirtual

return class name

Implements OperatorBase.

Definition at line 38 of file SOECPotential.h.

38 { return "SOECPotential"; }

◆ makeClone()

std::unique_ptr< OperatorBase > makeClone ( ParticleSet qp,
TrialWaveFunction psi 
)
finalvirtual

Implements OperatorBase.

Definition at line 302 of file SOECPotential.cpp.

References SOECPotential::ion_config_, SOECPotential::ppset_, and SOECPotential::use_exact_spin_.

Referenced by qmcplusplus::doSOECPotentialTest().

303 {
304  std::unique_ptr<SOECPotential> myclone = std::make_unique<SOECPotential>(ion_config_, qp, psi, use_exact_spin_);
305  for (int ig = 0; ig < ppset_.size(); ++ig)
306  if (ppset_[ig])
307  myclone->addComponent(ig, std::unique_ptr<SOECPComponent>(ppset_[ig]->makeClone(qp)));
308  return myclone;
309 }
std::vector< std::unique_ptr< SOECPComponent > > ppset_
Definition: SOECPotential.h:85
std::unique_ptr< OperatorBase > makeClone(ParticleSet &qp, TrialWaveFunction &psi) final

◆ mw_evaluate()

void mw_evaluate ( const RefVectorWithLeader< OperatorBase > &  o_list,
const RefVectorWithLeader< TrialWaveFunction > &  wf_list,
const RefVectorWithLeader< ParticleSet > &  p_list 
) const
overridevirtual

Evaluate the contribution of this component of multiple walkers.

Take o_list and p_list update evaluation result variables in o_list? really should reduce vector of local_energies. matching the ordering and size of o list the this can be call for 1 or more QMCHamiltonians

Parameters
o_list
wf_list
p_list

Temporary raw omp pragma for simple thread parallelism ignoring the driver level concurrency

TODO: replace this with a proper abstraction. It should adequately describe the behavior and strictly limit the activation of this level concurrency to when it is intended. It is unlikely to belong in this function.

This implicitly depends on openmp work division logic. Essentially adhoc runtime crowds over which we have given up control of thread/global scope. How many walkers per thread? How to handle their data movement if any of these hamiltonians should be accelerated? We can neither reason about or describe it in C++

As I understand it it should only be required for as long as the AMD openmp offload compliler is incapable of running multiple threads. They should/must fix their compiler before delivery of frontier and it should be removed at that point at latest

If you want 16 threads of 1 walker that should be 16 crowds of 1 not one crowd of 16 with openmp thrown in at hamiltonian level. If this must be different from the other crowd batching. Make this a reasoned about and controlled level of concurency blocking at the driver level.

This is only thread safe only if each walker has a complete set of anything involved in an Operator.evaluate.

Reimplemented from OperatorBase.

Definition at line 137 of file SOECPotential.cpp.

References SOECPotential::mw_evaluateImpl().

140 {
141  mw_evaluateImpl(o_list, wf_list, p_list, std::nullopt);
142 }
static void mw_evaluateImpl(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::optional< ListenerOption< Real >> listeners, bool keep_grid=false)

◆ mw_evaluateImpl()

void mw_evaluateImpl ( const RefVectorWithLeader< OperatorBase > &  o_list,
const RefVectorWithLeader< TrialWaveFunction > &  wf_list,
const RefVectorWithLeader< ParticleSet > &  p_list,
std::optional< ListenerOption< Real >>  listeners,
bool  keep_grid = false 
)
staticprotected

Definition at line 154 of file SOECPotential.cpp.

References qmcplusplus::generateRandomRotationMatrix(), RefVectorWithLeader< T >::getCastedElement(), RefVectorWithLeader< T >::getCastedLeader(), RefVectorWithLeader< T >::getLeader(), SOECPComponent::mw_evaluateOne(), TrialWaveFunction::mw_prepareGroup(), SOECPotential::psi_, ListenerVector< T >::report, and SOECPotential::sopp_jobs_.

Referenced by SOECPotential::mw_evaluate(), TestSOECPotential::mw_evaluateImpl(), and SOECPotential::mw_evaluatePerParticle().

159 {
160  auto& O_leader = o_list.getCastedLeader<SOECPotential>();
161  ParticleSet& pset_leader = p_list.getLeader();
162  const size_t nw = o_list.size();
163 
164  for (size_t iw = 0; iw < nw; iw++)
165  {
166  auto& O = o_list.getCastedElement<SOECPotential>(iw);
167  const ParticleSet& P(p_list[iw]);
168 
169  if (!keep_grid)
170  for (size_t ipp = 0; ipp < O.ppset_.size(); ipp++)
171  if (O.ppset_[ipp])
172  O.ppset_[ipp]->rotateQuadratureGrid(generateRandomRotationMatrix(*O.my_rng_));
173 
174  //loop over all the ions
175  const auto& ble = P.getDistTableAB(O.my_table_index_);
176  //clear elec and ion neighbor lists
177  for (size_t iat = 0; iat < O.num_ions_; iat++)
178  O.ion_neighbor_elecs_.getNeighborList(iat).clear();
179  for (size_t jel = 0; jel < P.getTotalNum(); jel++)
180  O.elec_neighbor_ions_.getNeighborList(jel).clear();
181 
182  for (size_t ig = 0; ig < P.groups(); ig++) // loop over species
183  {
184  auto& joblist = O.sopp_jobs_[ig];
185  joblist.clear();
186 
187  for (size_t jel = P.first(ig); jel < P.last(ig); jel++)
188  {
189  const auto& dist = ble.getDistRow(jel);
190  const auto& displ = ble.getDisplRow(jel);
191  std::vector<int>& NeighborIons = O.elec_neighbor_ions_.getNeighborList(jel);
192  for (size_t iat = 0; iat < O.num_ions_; iat++)
193  if (O.pp_[iat] != nullptr && dist[iat] < O.pp_[iat]->getRmax())
194  {
195  NeighborIons.push_back(iat);
196  O.ion_neighbor_elecs_.getNeighborList(iat).push_back(jel);
197  joblist.emplace_back(iat, jel, dist[iat], -displ[iat]);
198  }
199  }
200  }
201  O.value_ = 0.0;
202  }
203 
204  if (listeners)
205  {
206  auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
207  auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
208  ve_samples.resize(nw, pset_leader.getTotalNum());
209  vi_samples.resize(nw, O_leader.ion_config_.getTotalNum());
210  }
211 
212  auto pp_component = std::find_if(O_leader.ppset_.begin(), O_leader.ppset_.end(), [](auto& ptr) { return bool(ptr); });
213  assert(pp_component != std::end(O_leader.ppset_));
214 
215  RefVector<SOECPotential> soecp_potential_list;
216  RefVectorWithLeader<SOECPComponent> soecp_component_list(**pp_component);
217  RefVectorWithLeader<ParticleSet> pset_list(pset_leader);
218  RefVectorWithLeader<TrialWaveFunction> psi_list(O_leader.psi_);
219  assert(&O_leader.psi_ == &wf_list.getLeader());
220  for (size_t iw = 0; iw < nw; iw++)
221  assert(&o_list.getCastedElement<SOECPotential>(iw).psi_ == &wf_list[iw]);
222 
223  RefVector<const NLPPJob<RealType>> batch_list;
224  std::vector<RealType> pairpots(nw);
225 
226  soecp_potential_list.reserve(nw);
227  soecp_component_list.reserve(nw);
228  pset_list.reserve(nw);
229  psi_list.reserve(nw);
230  batch_list.reserve(nw);
231 
232  for (size_t ig = 0; ig < pset_leader.groups(); ig++)
233  {
234  TrialWaveFunction::mw_prepareGroup(wf_list, p_list, ig);
235 
236  size_t max_num_jobs = 0;
237  for (size_t iw = 0; iw < nw; iw++)
238  {
239  const auto& O = o_list.getCastedElement<SOECPotential>(iw);
240  max_num_jobs = std::max(max_num_jobs, O.sopp_jobs_[ig].size());
241  }
242 
243  for (size_t jobid = 0; jobid < max_num_jobs; jobid++)
244  {
245  soecp_potential_list.clear();
246  soecp_component_list.clear();
247  pset_list.clear();
248  psi_list.clear();
249  batch_list.clear();
250  for (size_t iw = 0; iw < nw; iw++)
251  {
252  auto& O = o_list.getCastedElement<SOECPotential>(iw);
253  if (jobid < O.sopp_jobs_[ig].size())
254  {
255  const auto& job = O.sopp_jobs_[ig][jobid];
256  soecp_potential_list.push_back(O);
257  soecp_component_list.push_back(*O.pp_[job.ion_id]);
258  pset_list.push_back(p_list[iw]);
259  psi_list.push_back(wf_list[iw]);
260  batch_list.push_back(job);
261  }
262  }
263 
264  SOECPComponent::mw_evaluateOne(soecp_component_list, pset_list, psi_list, batch_list, pairpots,
265  O_leader.mw_res_handle_.getResource().collection);
266 
267  for (size_t j = 0; j < soecp_potential_list.size(); j++)
268  {
269  soecp_potential_list[j].get().value_ += pairpots[j];
270 
271  if (listeners)
272  {
273  auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
274  auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
275  int iw = j;
276  ve_samples(iw, batch_list[j].get().electron_id) += pairpots[j];
277  vi_samples(iw, batch_list[j].get().ion_id) += pairpots[j];
278  }
279  }
280  }
281  }
282 
283  if (listeners)
284  {
285  auto& ve_samples = O_leader.mw_res_handle_.getResource().ve_samples;
286  auto& vi_samples = O_leader.mw_res_handle_.getResource().vi_samples;
287  int num_electrons = pset_leader.getTotalNum();
288  for (int iw = 0; iw < nw; iw++)
289  {
290  Vector<Real> ve_sample(ve_samples.begin(iw), num_electrons);
291  Vector<Real> vi_sample(vi_samples.begin(iw), O_leader.num_ions_);
292  for (const ListenerVector<Real>& listener : listeners->electron_values)
293  listener.report(iw, O_leader.getName(), ve_sample);
294  for (const ListenerVector<Real>& listener : listeners->ion_values)
295  listener.report(iw, O_leader.getName(), vi_sample);
296  }
297  ve_samples = 0.0;
298  vi_samples = 0.0;
299  }
300 }
static void mw_prepareGroup(const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, int ig)
batched version of prepareGroup
QMCTraits::TensorType generateRandomRotationMatrix(RandomBase< QMCTraits::FullPrecRealType > &rng)
Create a random 3D rotation matrix using a random generator.
SOECPotential(ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool use_exact_spin)
constructor
static void mw_evaluateOne(const RefVectorWithLeader< SOECPComponent > &soecp_component_list, const RefVectorWithLeader< ParticleSet > &p_list, const RefVectorWithLeader< TrialWaveFunction > &psi_list, const RefVector< const NLPPJob< RealType >> &joblist, std::vector< RealType > &pairpots, ResourceCollection &collection)

◆ mw_evaluatePerParticle()

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

Definition at line 144 of file SOECPotential.cpp.

References SOECPotential::mw_evaluateImpl().

149 {
150  std::optional<ListenerOption<Real>> l_opt(std::in_place, listeners, listeners_ions);
151  mw_evaluateImpl(o_list, wf_list, p_list, l_opt);
152 }
static void mw_evaluateImpl(const RefVectorWithLeader< OperatorBase > &o_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list, std::optional< ListenerOption< Real >> listeners, bool keep_grid=false)

◆ put()

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

Read the input parameter.

Parameters
curxml node for a OperatorBase object

Implements OperatorBase.

Definition at line 59 of file SOECPotential.h.

59 { return true; }

◆ releaseResource()

void releaseResource ( ResourceCollection collection,
const RefVectorWithLeader< OperatorBase > &  o_list 
) const
overridevirtual

Return a shared resource to a collection.

Parameters
collection
o_list

Reimplemented from OperatorBase.

Definition at line 338 of file SOECPotential.cpp.

References RefVectorWithLeader< T >::getCastedLeader(), and ResourceCollection::takebackResource().

340 {
341  auto& O_leader = o_list.getCastedLeader<SOECPotential>();
342  collection.takebackResource(O_leader.mw_res_handle_);
343 }
SOECPotential(ParticleSet &ions, ParticleSet &els, TrialWaveFunction &psi, bool use_exact_spin)
constructor

◆ resetTargetParticleSet()

void resetTargetParticleSet ( ParticleSet P)
overridevirtual

Reset the data with the target ParticleSet.

Parameters
Pnew target ParticleSet

Implements OperatorBase.

Definition at line 66 of file SOECPotential.cpp.

66 {}

◆ setRandomGenerator()

void setRandomGenerator ( RandomBase< FullPrecRealType > *  rng)
inlineoverridevirtual

Set the Random Generator object TODO: add docs.

Parameters
rng

Reimplemented from OperatorBase.

Definition at line 71 of file SOECPotential.h.

References SOECPotential::my_rng_.

Referenced by qmcplusplus::doSOECPotentialTest().

71 { my_rng_ = rng; }
RandomBase< FullPrecRealType > * my_rng_
Definition: SOECPotential.h:83

Friends And Related Function Documentation

◆ testing::TestSOECPotential

friend class testing::TestSOECPotential
friend

Definition at line 116 of file SOECPotential.h.

Member Data Documentation

◆ elec_neighbor_ions_

NeighborLists elec_neighbor_ions_
private

neighborlist of electrons

Definition at line 102 of file SOECPotential.h.

Referenced by SOECPotential::evaluateImpl().

◆ ion_config_

◆ ion_neighbor_elecs_

NeighborLists ion_neighbor_elecs_
private

neighborlist of ions

Definition at line 104 of file SOECPotential.h.

Referenced by SOECPotential::evaluateImpl().

◆ mw_res_handle_

Definition at line 108 of file SOECPotential.h.

Referenced by SOECPotential::acquireResource().

◆ my_rng_

◆ my_table_index_

int my_table_index_
private

index of distance table for ion-el pair

Definition at line 98 of file SOECPotential.h.

Referenced by SOECPotential::evaluateImpl(), SOECPotential::evaluateValueAndDerivatives(), and SOECPotential::SOECPotential().

◆ num_ions_

int num_ions_
private

◆ peln_

ParticleSet& peln_
private

reference to the electrons

Definition at line 100 of file SOECPotential.h.

◆ pp_

◆ ppset_

◆ psi_

◆ sopp_jobs_

std::vector<std::vector<NLPPJob<RealType> > > sopp_jobs_
private

◆ use_exact_spin_

const bool use_exact_spin_
private

Definition at line 111 of file SOECPotential.h.

Referenced by SOECPotential::evaluateImpl(), and SOECPotential::makeClone().


The documentation for this class was generated from the following files: