QMCPACK
RMCLocalEnergyEstimator Class Reference

Class to accumulate the local energy and components. More...

+ Inheritance diagram for RMCLocalEnergyEstimator:
+ Collaboration diagram for RMCLocalEnergyEstimator:

Public Member Functions

 RMCLocalEnergyEstimator (QMCHamiltonian &ham, int nobs=2)
 constructor More...
 
 RMCLocalEnergyEstimator (RMCLocalEnergyInput &&input, const QMCHamiltonian &ham)
 Construct from LocalEnergyInput and const reference to hamiltonian. More...
 
void accumulate (const Walker_t &awalker, RealType wgt)
 accumulation per walker More...
 
void accumulate (const RefVector< MCPWalker > &walkers) override
 a virtual function to accumulate observables or collectables More...
 
void accumulate (const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
 a virtual function to accumulate observables or collectables More...
 
std::string getName () const override
 
void add2Record (RecordListType &record) override
 add the local energy, variance and all the Hamiltonian components to the scalar record container More...
 
void registerObservables (std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
 add descriptors of observables to utilize hdf5 More...
 
RMCLocalEnergyEstimatorclone () override
 clone the object More...
 
const std::string & getSubTypeStr () const override
 String representation of the derived type of the ScalarEstimator. More...
 
bool isMainEstimator () const override
 RMCLocalEnergyEstimator is the main estimator type for RMC driver. More...
 
- Public Member Functions inherited from ScalarEstimatorBase
 ScalarEstimatorBase ()
 
virtual ~ScalarEstimatorBase ()
 
RealType average (int i=0) const
 return average of the More...
 
RealType variance (int i=0) const
 return a variance More...
 
std::pair< RealType, RealTypeoperator[] (int i) const
 retrun mean and variance More...
 
virtual int size () const
 return the size of scalars it manages More...
 
void clear ()
 clear the scalars to collect More...
 
template<typename IT >
void takeBlockAverage (IT first)
 take block average and write to a common container More...
 
template<typename IT >
void takeBlockAverage (IT first, IT first_sq)
 take block average and write to common containers for values and squared values More...
 
template<typename IT >
void addAccumulated (IT first)
 add the block accumulated scalars More...
 
virtual void add2Record (RecordNamedProperty< RealType > &record)=0
 add the content of the scalar estimator to the record More...
 

Private Types

using WP = WalkerProperties::Indexes
 

Private Member Functions

void resizeBasedOnHamiltonian (const QMCHamiltonian &ham)
 

Private Attributes

int FirstHamiltonian
 
int SizeOfHamiltonians
 
const QMCHamiltonianrefH
 
int NObs
 
int RMCSpecificTerms = 8
 
const RMCLocalEnergyInput input_
 

Additional Inherited Members

- Public Types inherited from ScalarEstimatorBase
using RealType = QMCTraits::FullPrecRealType
 
using accumulator_type = accumulator_set< RealType >
 
using Walker_t = MCWalkerConfiguration::Walker_t
 
using MCPWalker = Walker< QMCTraits, PtclOnLatticeTraits >
 
using WalkerIterator = MCWalkerConfiguration::const_iterator
 
using RecordListType = RecordNamedProperty< RealType >
 
- Public Attributes inherited from ScalarEstimatorBase
int FirstIndex
 first index within an record of the first element handled by an object More...
 
int LastIndex
 last index within an record of the first element handled by an object More...
 
std::vector< accumulator_typescalars
 scalars to be measured More...
 
std::vector< accumulator_typescalars_saved
 scalars saved More...
 

Detailed Description

Class to accumulate the local energy and components.

Use Walker::Properties to accumulate Hamiltonian-related quantities.

Definition at line 28 of file RMCLocalEnergyEstimator.h.

Member Typedef Documentation

◆ WP

using WP = WalkerProperties::Indexes
private

Definition at line 30 of file RMCLocalEnergyEstimator.h.

Constructor & Destructor Documentation

◆ RMCLocalEnergyEstimator() [1/2]

RMCLocalEnergyEstimator ( QMCHamiltonian ham,
int  nobs = 2 
)

constructor

Parameters
hQMCHamiltonian to define the components

Definition at line 19 of file RMCLocalEnergyEstimator.cpp.

References qmcplusplus::ham, and RMCLocalEnergyEstimator::resizeBasedOnHamiltonian().

Referenced by RMCLocalEnergyEstimator::clone().

◆ RMCLocalEnergyEstimator() [2/2]

Construct from LocalEnergyInput and const reference to hamiltonian.

Parameters
[in]RMCLocalEnergyEstimatorInputcontains input parameters for RMCLocalEnergyEstimator
[in]istaken as a local reference and used to size scalars data and to get obs output names

Definition at line 24 of file RMCLocalEnergyEstimator.cpp.

References qmcplusplus::ham, and RMCLocalEnergyEstimator::resizeBasedOnHamiltonian().

24  : refH(ham), NObs(input.get_n_obs()), input_(input)
25 {
27 }
void resizeBasedOnHamiltonian(const QMCHamiltonian &ham)
testing::ValidSpinDensityInput input

Member Function Documentation

◆ accumulate() [1/3]

void accumulate ( const Walker_t awalker,
RealType  wgt 
)
inline

accumulation per walker

Parameters
awalkercurrent walker
wgtweight

Weight of observables should take into account the walkers weight. For Pure DMC. In branching DMC set weights to 1.

Definition at line 56 of file RMCLocalEnergyEstimator.h.

56 {}

◆ accumulate() [2/3]

void accumulate ( const RefVector< MCPWalker > &  )
inlineoverridevirtual

a virtual function to accumulate observables or collectables

Parameters
global_walkers_walkers per ranks or walkers total?
RefVectorof MCPWalkers
wgtweight or maybe norm

Implements ScalarEstimatorBase.

Definition at line 58 of file RMCLocalEnergyEstimator.h.

59  {
60  throw std::runtime_error("RMC not supported by Unified Driver interfaces");
61  }

◆ accumulate() [3/3]

void accumulate ( const MCWalkerConfiguration W,
WalkerIterator  first,
WalkerIterator  last,
RealType  wgt 
)
inlineoverridevirtual

a virtual function to accumulate observables or collectables

Parameters
Wconst MCWalkerConfiguration
firstconst_iterator for the first walker
lastconst_iterator for the last walker
wgtweight

Pass W along with the iterators so that the properties of W can be utilized.

Implements ScalarEstimatorBase.

Definition at line 62 of file RMCLocalEnergyEstimator.h.

References RMCLocalEnergyEstimator::FirstHamiltonian, Reptile::getCenter(), Reptile::getHead(), Walker< t_traits, p_traits >::getPropertyBase(), Reptile::getTail(), MCWalkerConfiguration::reptile, RMCLocalEnergyEstimator::RMCSpecificTerms, ScalarEstimatorBase::scalars, and RMCLocalEnergyEstimator::SizeOfHamiltonians.

66  {
67  //WalkerIterator tail=first+W.activeBead+W.direction;
68  //WalkerIterator head=first+W.activeBead;
69  //if(tail>=last)
70  // tail-=last-first;
71  //else if(tail<first)
72  // tail+=last-first;
73  Walker_t& head = W.reptile->getHead();
74  Walker_t& tail = W.reptile->getTail();
75  Walker_t& center = W.reptile->getCenter();
76  // mixed estimator stuff
77  const RealType* restrict ePtr = head.getPropertyBase();
78  const RealType* restrict lPtr = tail.getPropertyBase();
79  const RealType* restrict cPtr = center.getPropertyBase();
80  // RealType wwght= head.Weight;
81  RealType wwght = 0.5;
82  //app_log()<<"~~~~~For head: Energy:"<<ePtr[LOCALENERGY]<< std::endl;
83  scalars[0](0.5 * (ePtr[WP::LOCALENERGY] + lPtr[WP::LOCALENERGY]), wwght);
84  scalars[1](0.5 * (ePtr[WP::LOCALENERGY] * ePtr[WP::LOCALENERGY] + lPtr[WP::LOCALENERGY] * lPtr[WP::LOCALENERGY]),
85  wwght);
86  scalars[2](cPtr[WP::LOCALENERGY], wwght);
87  scalars[3](cPtr[WP::LOCALENERGY] * cPtr[WP::LOCALENERGY], wwght);
88  scalars[4](ePtr[WP::LOCALENERGY] * lPtr[WP::LOCALENERGY], wwght);
89  scalars[5](0.5 * (ePtr[WP::LOCALPOTENTIAL] + lPtr[WP::LOCALPOTENTIAL]), wwght);
90  scalars[6](cPtr[WP::LOCALPOTENTIAL], wwght);
91 
92  for (int target = RMCSpecificTerms, source = FirstHamiltonian; source < FirstHamiltonian + SizeOfHamiltonians;
93  ++target, ++source)
94  {
95  wwght = 0.5;
96  scalars[target](lPtr[source], wwght);
97  scalars[target](ePtr[source], wwght);
98  }
99  for (int target = RMCSpecificTerms + SizeOfHamiltonians, source = FirstHamiltonian;
100  source < FirstHamiltonian + SizeOfHamiltonians; ++target, ++source)
101  {
102  wwght = 1;
103  scalars[target](cPtr[source], wwght);
104  }
105  // scalars[target](lPtr[source],wwght);
106  // int stride(0);
107  // int bds(last-first);
108  // if(bds%2>0)//odd
109  // {
110  // int odd=(bds+1)/2;
111  // stride=odd/NObs;
112  // }
113  // else
114  // {
115  // int odd=bds/2;
116  // stride=odd/NObs;
117  // }
118  //
119  // int indx(4+SizeOfHamiltonians);
120  // for(int j=0; j < NObs; j++)
121  // {
122  // tail+= -W.direction*stride;
123  // head+= W.direction*stride;
124  // if(tail>=last)
125  // tail-=last-first;
126  // else if(tail<first)
127  // tail+=last-first;
128  // if(head>=last)
129  // head-=last-first;
130  // else if(head<first)
131  // head+=last-first;
132  // const RealType* lPtr = tail.getPropertyBase();
133  // const RealType* ePtr = head.getPropertyBase();
134  // for(int target=0, source=FirstHamiltonian; target<SizeOfHamiltonians; ++target, ++source, indx++)
135  // {
136  // scalars[indx](lPtr[source]);
137  // scalars[indx](ePtr[source]);
138  // }
139  // }
140  // int maxage(0);
141  // while(first!=last)
142  // {
143  // maxage= std::max(maxage,(*first)->Age);
144  // first++;
145  // }
146  // scalars[3](maxage);
147  // for(; first != last; ++first) std::accumulate(**first,wgt);*/
148  }
std::vector< accumulator_type > scalars
scalars to be measured
QMCTraits::RealType RealType
FullPrecRealType * getPropertyBase()
Definition: Walker.h:277
MCWalkerConfiguration::Walker_t Walker_t

◆ add2Record()

void add2Record ( RecordListType record)
override

add the local energy, variance and all the Hamiltonian components to the scalar record container

Parameters
recordstorage of scalar records (name,value)

Definition at line 42 of file RMCLocalEnergyEstimator.cpp.

References RecordNamedProperty< T >::add(), ScalarEstimatorBase::clear(), ScalarEstimatorBase::FirstIndex, QMCHamiltonian::getObservableName(), ScalarEstimatorBase::LastIndex, RMCLocalEnergyEstimator::refH, RecordNamedProperty< T >::size(), and RMCLocalEnergyEstimator::SizeOfHamiltonians.

43 {
44  FirstIndex = record.size();
45  record.add("LocalEnergy");
46  record.add("LocalEnergy_sq");
47  record.add("LocalEnergy_p");
48  record.add("LocalEnergy_sq_p");
49  record.add("LocalEnergy_sq_cross");
50  record.add("LocalPotential");
51  record.add("LocalPotential_pure");
52 
53  record.add("OldestBead");
54  //for(int j=0; j <= NObs; j++)
55  for (int i = 0; i < SizeOfHamiltonians; i++)
56  {
57  std::ostringstream ss;
58  ss << refH.getObservableName(i) << "_m";
59  record.add(ss.str());
60  }
61  for (int i = 0; i < SizeOfHamiltonians; i++)
62  {
63  std::ostringstream ss;
64  ss << refH.getObservableName(i) << "_p";
65  // app_log()<<"Registering observable "<<ss.str()<< std::endl;
66  record.add(ss.str());
67  }
68  LastIndex = record.size();
69  clear();
70 }
std::string getObservableName(int i) const
return the name of the i-th observable
int FirstIndex
first index within an record of the first element handled by an object
void clear()
clear the scalars to collect
int LastIndex
last index within an record of the first element handled by an object

◆ clone()

RMCLocalEnergyEstimator * clone ( )
overridevirtual

clone the object

Implements ScalarEstimatorBase.

Definition at line 37 of file RMCLocalEnergyEstimator.cpp.

References RMCLocalEnergyEstimator::RMCLocalEnergyEstimator().

37 { return new RMCLocalEnergyEstimator(*this); }
RMCLocalEnergyEstimator(QMCHamiltonian &ham, int nobs=2)
constructor

◆ getName()

std::string getName ( ) const
inlineoverridevirtual

Implements ScalarEstimatorBase.

Definition at line 150 of file RMCLocalEnergyEstimator.h.

150 { return "RMCLocalEnergyEstimator"; }

◆ getSubTypeStr()

const std::string& getSubTypeStr ( ) const
inlineoverridevirtual

String representation of the derived type of the ScalarEstimator.

Implements ScalarEstimatorBase.

Definition at line 155 of file RMCLocalEnergyEstimator.h.

References RMCLocalEnergyInput::get_type(), and RMCLocalEnergyEstimator::input_.

155 { return input_.get_type(); }
const std::string & get_type() const

◆ isMainEstimator()

bool isMainEstimator ( ) const
inlineoverridevirtual

RMCLocalEnergyEstimator is the main estimator type for RMC driver.

Reimplemented from ScalarEstimatorBase.

Definition at line 157 of file RMCLocalEnergyEstimator.h.

157 { return true; }

◆ registerObservables()

void registerObservables ( std::vector< ObservableHelper > &  h5dec,
hdf_archive file 
)
inlineoverridevirtual

add descriptors of observables to utilize hdf5

Parameters
h5descdescriptor of a data stored in a h5 group
filefile to which each statistical data will be stored

Implements ScalarEstimatorBase.

Definition at line 153 of file RMCLocalEnergyEstimator.h.

153 {}

◆ resizeBasedOnHamiltonian()

void resizeBasedOnHamiltonian ( const QMCHamiltonian ham)
private

Definition at line 29 of file RMCLocalEnergyEstimator.cpp.

References RMCLocalEnergyEstimator::FirstHamiltonian, qmcplusplus::ham, RMCLocalEnergyEstimator::RMCSpecificTerms, ScalarEstimatorBase::scalars, ScalarEstimatorBase::scalars_saved, RMCLocalEnergyEstimator::SizeOfHamiltonians, QMCHamiltonian::sizeOfObservables(), and QMCHamiltonian::startIndex().

Referenced by RMCLocalEnergyEstimator::RMCLocalEnergyEstimator().

30 {
35 }
int startIndex() const
retrun the starting index
std::vector< accumulator_type > scalars
scalars to be measured
int sizeOfObservables() const
return the size of observables
std::vector< accumulator_type > scalars_saved
scalars saved

Member Data Documentation

◆ FirstHamiltonian

int FirstHamiltonian
private

◆ input_

const RMCLocalEnergyInput input_
private

Definition at line 38 of file RMCLocalEnergyEstimator.h.

Referenced by RMCLocalEnergyEstimator::getSubTypeStr().

◆ NObs

int NObs
private

Definition at line 34 of file RMCLocalEnergyEstimator.h.

◆ refH

const QMCHamiltonian& refH
private

Definition at line 33 of file RMCLocalEnergyEstimator.h.

Referenced by RMCLocalEnergyEstimator::add2Record().

◆ RMCSpecificTerms

int RMCSpecificTerms = 8
private

◆ SizeOfHamiltonians


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