QMCPACK
CSEnergyEstimator Struct Reference
+ Inheritance diagram for CSEnergyEstimator:
+ Collaboration diagram for CSEnergyEstimator:

Public Types

enum  { ENERGY_INDEX, ENERGY_SQ_INDEX, WEIGHT_INDEX, LE_INDEX }
 
- 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 Member Functions

 CSEnergyEstimator (const QMCHamiltonian &h, int hcopy=1)
 constructor More...
 
 CSEnergyEstimator (CSLocalEnergyInput &&input, const QMCHamiltonian &h)
 
std::string getName () const override
 
RealType getUmbrellaWeight (int ipsi)
 
void accumulate (const Walker_t &awalker, RealType wgt)
 
void accumulate (const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
 
void accumulate (const RefVector< MCPWalker > &walkers) override
 a virtual function to accumulate observables or collectables More...
 
void add2Record (RecordNamedProperty< RealType > &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 &gid) override
 add descriptors of observables to utilize hdf5 More...
 
CSEnergyEstimatorclone () override
 clone the object More...
 
const std::string & getSubTypeStr () const override
 String representation of the derived type of the ScalarEstimator. More...
 
void evaluateDiff ()
 
bool isMainEstimator () const override
 Is this estimator a main estimator i.e. the estimator required for a particular 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 accumulate (const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt)=0
 a virtual function to accumulate observables or collectables More...
 
virtual void add2Record (RecordNamedProperty< RealType > &record)=0
 add the content of the scalar estimator to the record More...
 

Public Attributes

int NumCopies
 number of correlated systems More...
 
int FirstHamiltonian
 index of the starting Hamiltonian component More...
 
int LastHamiltonian
 index of the ending Hamiltonian component More...
 
std::vector< RealTypeuweights
 save umbrella weights More...
 
Matrix< RealTypetmp_data
 temporary dat More...
 
std::vector< std::string > h_components
 name of hamiltonian components More...
 
const CSLocalEnergyInput input_
 
- 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

Definition at line 28 of file CSEnergyEstimator.h.

Member Enumeration Documentation

◆ anonymous enum

Constructor & Destructor Documentation

◆ CSEnergyEstimator() [1/2]

CSEnergyEstimator ( const QMCHamiltonian h,
int  hcopy = 1 
)

constructor

Parameters
hQMCHamiltonian to define the components
hcopynumber of copies of QMCHamiltonians

Definition at line 32 of file CSEnergyEstimator.cpp.

References CSEnergyEstimator::FirstHamiltonian, QMCHamiltonian::getObservableName(), CSEnergyEstimator::h_components, CSEnergyEstimator::LastHamiltonian, CSEnergyEstimator::NumCopies, ScalarEstimatorBase::scalars, ScalarEstimatorBase::scalars_saved, QMCHamiltonian::sizeOfObservables(), and QMCHamiltonian::startIndex().

Referenced by CSEnergyEstimator::clone().

33 {
34  int NumObservables = h.sizeOfObservables();
35 
36  NumCopies = hcopy;
37  FirstHamiltonian = h.startIndex();
38  LastHamiltonian = FirstHamiltonian + NumObservables;
39 
40  //add names
41  h_components.push_back("LocEne");
42  h_components.push_back("LocPot");
43  for (int i = 0; i < NumObservables; ++i)
44  h_components.push_back(h.getObservableName(i));
45 
46  scalars.resize(NumCopies + h_components.size() * (NumCopies + NumCopies * (NumCopies - 1) / 2));
47  scalars_saved.resize(scalars.size());
48 }
int NumCopies
number of correlated systems
std::vector< accumulator_type > scalars
scalars to be measured
int FirstHamiltonian
index of the starting Hamiltonian component
std::vector< accumulator_type > scalars_saved
scalars saved
int LastHamiltonian
index of the ending Hamiltonian component
std::vector< std::string > h_components
name of hamiltonian components

◆ CSEnergyEstimator() [2/2]

CSEnergyEstimator ( CSLocalEnergyInput &&  input,
const QMCHamiltonian h 
)

Definition at line 50 of file CSEnergyEstimator.cpp.

References CSEnergyEstimator::FirstHamiltonian, CSLocalEnergyInput::get_n_psi(), QMCHamiltonian::getObservableName(), CSEnergyEstimator::h_components, CSEnergyEstimator::input_, CSEnergyEstimator::LastHamiltonian, CSEnergyEstimator::NumCopies, ScalarEstimatorBase::scalars, ScalarEstimatorBase::scalars_saved, QMCHamiltonian::sizeOfObservables(), and QMCHamiltonian::startIndex().

50  : input_(input)
51 {
52  int NumObservables = h.sizeOfObservables();
53 
55  FirstHamiltonian = h.startIndex();
56  LastHamiltonian = FirstHamiltonian + NumObservables;
57 
58  //add names
59  h_components.push_back("LocEne");
60  h_components.push_back("LocPot");
61  for (int i = 0; i < NumObservables; ++i)
62  h_components.push_back(h.getObservableName(i));
63 
64  scalars.resize(NumCopies + h_components.size() * (NumCopies + NumCopies * (NumCopies - 1) / 2));
65  scalars_saved.resize(scalars.size());
66 }
int NumCopies
number of correlated systems
std::vector< accumulator_type > scalars
scalars to be measured
int FirstHamiltonian
index of the starting Hamiltonian component
std::vector< accumulator_type > scalars_saved
scalars saved
testing::ValidSpinDensityInput input
int LastHamiltonian
index of the ending Hamiltonian component
const CSLocalEnergyInput input_
std::vector< std::string > h_components
name of hamiltonian components

Member Function Documentation

◆ accumulate() [1/3]

void accumulate ( const Walker_t awalker,
RealType  wgt 
)

Definition at line 126 of file CSEnergyEstimator.cpp.

References Matrix< T, Alloc >::cols(), copy(), Matrix< T, Alloc >::data(), CSEnergyEstimator::FirstHamiltonian, Walker< t_traits, p_traits >::getPropertyBase(), CSEnergyEstimator::LastHamiltonian, mean(), CSEnergyEstimator::NumCopies, ScalarEstimatorBase::scalars, CSEnergyEstimator::tmp_data, and CSEnergyEstimator::uweights.

Referenced by CSEnergyEstimator::accumulate().

127 {
129  std::vector<double> weightaverage(NumCopies);
130  //first copy data to tmp_dat to calculate differences
131  for (int i = 0; i < NumCopies; i++)
132  {
133  const RealType* restrict prop = awalker.getPropertyBase(i);
134  RealType* restrict prop_saved = tmp_data[i];
135  uweights[i] = prop[WP::UMBRELLAWEIGHT];
136  *prop_saved++ = prop[WP::LOCALENERGY];
137  *prop_saved++ = prop[WP::LOCALPOTENTIAL];
138  std::copy(prop + FirstHamiltonian, prop + LastHamiltonian, prop_saved);
139  }
140 
141  int ii = 0;
142  const RealType* hptr = tmp_data.data();
143  for (int i = 0; i < NumCopies; i++)
144  {
145  RealType uw = uweights[i];
146  for (int k = 0; k < tmp_data.cols(); ++k)
147  scalars[ii++](*hptr++, uw);
148  }
149 
150  for (int i = 0; i < NumCopies; i++)
151  {
152  scalars[ii++](uweights[i], 1.0);
153  }
154 
155  int ii_i(0); //index of observable ii for copy i
156  int ii_j(0); //index of observable ii for copy j
157  for (int i = 0; i < NumCopies; i++)
158  {
159  for (int j = i + 1; j < NumCopies; j++)
160  {
161  for (int k = 0; k < tmp_data.cols(); ++k)
162  {
163  ii_i = i * tmp_data.cols() + k;
164  ii_j = j * tmp_data.cols() + k;
165 
166  //reset is used here because we do no accumulating. Just overwrite.
167  scalars[ii++].reset(scalars[ii_i].mean() - scalars[ii_j].mean(), 1.0);
168  }
169  }
170  }
171 }
int NumCopies
number of correlated systems
std::vector< RealType > uweights
save umbrella weights
Indexes
an enum denoting index of physical properties
std::vector< accumulator_type > scalars
scalars to be measured
size_type cols() const
Definition: OhmmsMatrix.h:78
int FirstHamiltonian
index of the starting Hamiltonian component
Matrix< RealType > tmp_data
temporary dat
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
int LastHamiltonian
index of the ending Hamiltonian component
ACC::value_type mean(const ACC &ac)
Definition: accumulators.h:147
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
QMCTraits::RealType RealType

◆ accumulate() [2/3]

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

Definition at line 70 of file CSEnergyEstimator.h.

References CSEnergyEstimator::accumulate().

74  {
75  //accumulate the number of times accumulation has occurred.
76  //d_wgt+=last-first;
77  for (; first != last; ++first)
78  accumulate(**first, wgt);
79  }
void accumulate(const Walker_t &awalker, RealType wgt)

◆ accumulate() [3/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 81 of file CSEnergyEstimator.h.

References CSEnergyEstimator::accumulate(), qmcplusplus::walker, and qmcplusplus::hdf::walkers.

82  {
83  for (MCPWalker& walker : walkers)
84  accumulate(walker, 1.0);
85  }
void accumulate(const Walker_t &awalker, RealType wgt)
const char walkers[]
Definition: HDFVersion.h:36
Walker< QMCTraits, PtclOnLatticeTraits > MCPWalker

◆ add2Record()

void add2Record ( RecordNamedProperty< RealType > &  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 74 of file CSEnergyEstimator.cpp.

References RecordNamedProperty< T >::add(), ScalarEstimatorBase::clear(), ScalarEstimatorBase::FirstIndex, CSEnergyEstimator::h_components, ScalarEstimatorBase::LastIndex, CSEnergyEstimator::NumCopies, Matrix< T, Alloc >::resize(), RecordNamedProperty< T >::size(), CSEnergyEstimator::tmp_data, and CSEnergyEstimator::uweights.

75 {
76  std::array<char, 80> aname;
77  FirstIndex = record.size();
78 
79  for (int i = 0; i < NumCopies; ++i)
80  {
81  for (int k = 0; k < h_components.size(); ++k)
82  {
83  int length = std::snprintf(aname.data(), aname.size(), "%s_%i", h_components[k].c_str(), i);
84  if (length < 0)
85  throw std::runtime_error("Error generating record name");
86  record.add(std::string(aname.data(), length));
87  }
88  }
89 
90  for (int i = 0; i < NumCopies; ++i)
91  {
92  int length = std::snprintf(aname.data(), aname.size(), "wpsi_%i", i);
93  if (length < 0)
94  throw std::runtime_error("Error generating record name");
95  record.add(std::string(aname.data(), length));
96  }
97 
98  for (int i = 0; i < NumCopies; i++)
99  {
100  for (int j = i + 1; j < NumCopies; j++)
101  {
102  for (int k = 0; k < h_components.size(); ++k)
103  {
104  int length = std::snprintf(aname.data(), aname.size(), "d%s_%d_%d", h_components[k].c_str(), i, j);
105  if (length < 0)
106  throw std::runtime_error("Error generating record name");
107  record.add(std::string(aname.data(), length));
108  }
109  }
110  }
111 
112 
113  LastIndex = record.size();
115  uweights.resize(NumCopies);
116  clear();
117 
118  //msg.add(d_data.begin(),d_data.end());
119 }
int NumCopies
number of correlated systems
std::vector< RealType > uweights
save umbrella weights
Matrix< RealType > tmp_data
temporary dat
int LastIndex
last index within an record of the first element handled by an object
int FirstIndex
first index within an record of the first element handled by an object
void clear()
clear the scalars to collect
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
std::vector< std::string > h_components
name of hamiltonian components
int add(const std::string &aname)

◆ clone()

CSEnergyEstimator * clone ( )
overridevirtual

clone the object

Implements ScalarEstimatorBase.

Definition at line 69 of file CSEnergyEstimator.cpp.

References CSEnergyEstimator::CSEnergyEstimator().

69 { return new CSEnergyEstimator(*this); }
CSEnergyEstimator(const QMCHamiltonian &h, int hcopy=1)
constructor

◆ evaluateDiff()

void evaluateDiff ( )

◆ getName()

std::string getName ( ) const
inlineoverridevirtual

Implements ScalarEstimatorBase.

Definition at line 60 of file CSEnergyEstimator.h.

60 { return "CSEnergyEstimator"; }

◆ getSubTypeStr()

const std::string& getSubTypeStr ( ) const
inlineoverridevirtual

String representation of the derived type of the ScalarEstimator.

Implements ScalarEstimatorBase.

Definition at line 93 of file CSEnergyEstimator.h.

References CSLocalEnergyInput::get_type(), and CSEnergyEstimator::input_.

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

◆ getUmbrellaWeight()

RealType getUmbrellaWeight ( int  ipsi)
inline

Definition at line 62 of file CSEnergyEstimator.h.

References CSEnergyEstimator::LE_INDEX, ScalarEstimatorBase::scalars_saved, and CSEnergyEstimator::WEIGHT_INDEX.

63  {
64  return scalars_saved[ipsi * LE_INDEX + WEIGHT_INDEX].result();
65  //return d_data[ipsi*LE_INDEX+WEIGHT_INDEX];
66  }
std::vector< accumulator_type > scalars_saved
scalars saved

◆ isMainEstimator()

bool isMainEstimator ( ) const
inlineoverridevirtual

Is this estimator a main estimator i.e. the estimator required for a particular driver.

Reimplemented from ScalarEstimatorBase.

Definition at line 96 of file CSEnergyEstimator.h.

96 { return true; }

◆ registerObservables()

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

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 121 of file CSEnergyEstimator.cpp.

122 {
123  //NEED TO IMPLEMENT for hdf5
124 }

Member Data Documentation

◆ FirstHamiltonian

int FirstHamiltonian

index of the starting Hamiltonian component

Definition at line 42 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::accumulate(), and CSEnergyEstimator::CSEnergyEstimator().

◆ h_components

std::vector<std::string> h_components

name of hamiltonian components

Definition at line 50 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::add2Record(), and CSEnergyEstimator::CSEnergyEstimator().

◆ input_

◆ LastHamiltonian

int LastHamiltonian

index of the ending Hamiltonian component

Definition at line 44 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::accumulate(), and CSEnergyEstimator::CSEnergyEstimator().

◆ NumCopies

int NumCopies

number of correlated systems

Definition at line 40 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::accumulate(), CSEnergyEstimator::add2Record(), and CSEnergyEstimator::CSEnergyEstimator().

◆ tmp_data

Matrix<RealType> tmp_data

temporary dat

Definition at line 48 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::accumulate(), and CSEnergyEstimator::add2Record().

◆ uweights

std::vector<RealType> uweights

save umbrella weights

Definition at line 46 of file CSEnergyEstimator.h.

Referenced by CSEnergyEstimator::accumulate(), and CSEnergyEstimator::add2Record().


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