QMCPACK
EstimatorManagerNewTest Class Reference

Testing class breaking EstimatorManagerNew encapsultation. More...

+ Collaboration diagram for EstimatorManagerNewTest:

Public Types

using QMCT = QMCTraits
 

Public Member Functions

 EstimatorManagerNewTest (const QMCHamiltonian &ham, Communicate *comm, int ranks)
 
void fakeMainScalarSamples ()
 Quickly add main scalar samples using FakeEstimator mock estimator. More...
 
void fakeScalarSamplesAndCollect ()
 Quickly add scalar samples using FakeEstimator mock estimator. More...
 
void fakeSomeOperatorEstimatorSamples (int rank)
 Quickly add scalar samples using FakeOperatorEstimator mock estimator. More...
 
void collectMainEstimators ()
 call private EMB method and collect EMBTs estimators_ as main_estimators More...
 
void collectScalarEstimators ()
 call private EMB method and colelct EMBTs estimators_ More...
 
void collectOperatorEstimators ()
 reduce the OperatorEstimators onto the EstimatorManagerNew copy. More...
 
std::vector< QMCT::RealTypegenerateGoodOperatorData (int num_ranks)
 for mpi test (it's trivial for 1 rank) More...
 
bool testReplaceMainEstimator ()
 test replacing the main estimator More...
 
bool testMakeBlockAverages ()
 
void testReduceOperatorEstimators ()
 
std::vector< QMCT::RealType > & get_operator_data ()
 

Public Attributes

EstimatorManagerNew em
 

Private Attributes

Communicatecomm_
 
std::vector< FakeEstimatorestimators_
 
std::vector< RefVector< ScalarEstimatorBase > > scalar_estimators_
 

Detailed Description

Testing class breaking EstimatorManagerNew encapsultation.

Wraps EstimatorManagerNew

Definition at line 30 of file EstimatorManagerNewTest.h.

Member Typedef Documentation

◆ QMCT

using QMCT = QMCTraits

Definition at line 33 of file EstimatorManagerNewTest.h.

Constructor & Destructor Documentation

◆ EstimatorManagerNewTest()

EstimatorManagerNewTest ( const QMCHamiltonian ham,
Communicate comm,
int  ranks 
)

Definition at line 24 of file EstimatorManagerNewTest.cpp.

References qmcplusplus::app_log(), EstimatorManagerNewTest::comm_, qmcplusplus::num_ranks, and Communicate::size().

25  : em(ham, comm), comm_(comm)
26 {
27  int num_ranks = comm_->size();
28  if (num_ranks != ranks)
29  throw std::runtime_error("Bad Rank Count, test expects different number of ranks.");
30 
31  app_log() << "running on " << num_ranks << '\n';
32 }
std::ostream & app_log()
Definition: OutputManager.h:65
int size() const
return the number of tasks
Definition: Communicate.h:118

Member Function Documentation

◆ collectMainEstimators()

void collectMainEstimators ( )

call private EMB method and collect EMBTs estimators_ as main_estimators

Definition at line 147 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNew::collectMainEstimators(), EstimatorManagerNewTest::em, and EstimatorManagerNewTest::estimators_.

Referenced by qmcplusplus::TEST_CASE().

148 {
149  auto crowd_main_estimators = makeRefVector<ScalarEstimatorBase>(estimators_);
150  em.collectMainEstimators(crowd_main_estimators);
151 }
void collectMainEstimators(const RefVector< ScalarEstimatorBase > &scalar_estimators)
At end of block collect the main scalar estimators for the entire rank.

◆ collectOperatorEstimators()

void collectOperatorEstimators ( )

reduce the OperatorEstimators onto the EstimatorManagerNew copy.

◆ collectScalarEstimators()

void collectScalarEstimators ( )

call private EMB method and colelct EMBTs estimators_

◆ fakeMainScalarSamples()

void fakeMainScalarSamples ( )

Quickly add main scalar samples using FakeEstimator mock estimator.

Definition at line 52 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNewTest::em, EstimatorManagerNewTest::estimators_, EstimatorManagerNew::get_AverageCache(), ScalarEstimatorBase::scalars, and ScalarEstimatorBase::scalars_saved.

Referenced by qmcplusplus::TEST_CASE().

53 {
54  estimators_.clear();
55  FakeEstimator fake_estimator;
56  fake_estimator.scalars.resize(4);
57  fake_estimator.scalars_saved.resize(4);
58  fake_estimator.scalars[0](1.0);
59  fake_estimator.scalars[1](2.0);
60  fake_estimator.scalars[2](3.0);
61  fake_estimator.scalars[3](4.0);
62 
63  //three estimators
64  estimators_.push_back(fake_estimator);
65  estimators_.push_back(fake_estimator);
66  estimators_.push_back(fake_estimator);
67 
68  estimators_[2].scalars[0](2.0);
69  estimators_[2].scalars[1](2.0);
70  estimators_[2].scalars[2](2.0);
71  estimators_[2].scalars[3](2.0);
72 
73  em.get_AverageCache().resize(4);
74 }

◆ fakeScalarSamplesAndCollect()

void fakeScalarSamplesAndCollect ( )

Quickly add scalar samples using FakeEstimator mock estimator.

Definition at line 76 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNew::addScalarEstimator(), EstimatorManagerNew::collectScalarEstimators(), EstimatorManagerNewTest::em, EstimatorManagerNewTest::estimators_, EstimatorManagerNew::get_AverageCache(), EstimatorManagerNewTest::scalar_estimators_, ScalarEstimatorBase::scalars, and ScalarEstimatorBase::scalars_saved.

Referenced by qmcplusplus::TEST_CASE().

77 {
78  estimators_.clear();
79  FakeEstimator fake_estimator;
80  fake_estimator.scalars.resize(4);
81  fake_estimator.scalars_saved.resize(4);
82  fake_estimator.scalars[0](1.0);
83  fake_estimator.scalars[1](2.0);
84  fake_estimator.scalars[2](3.0);
85  fake_estimator.scalars[3](4.0);
86 
87  //three estimators
88  estimators_.push_back(fake_estimator);
89  estimators_.push_back(fake_estimator);
90  estimators_.push_back(fake_estimator);
91 
92  estimators_[2].scalars[0](2.0);
93  estimators_[2].scalars[1](2.0);
94  estimators_[2].scalars[2](2.0);
95  estimators_[2].scalars[3](2.0);
96 
97  std::vector<FakeEstimator> estimators2;
98  estimators2.push_back(fake_estimator);
99  estimators2.push_back(fake_estimator);
100  estimators2.push_back(fake_estimator);
101 
102  std::vector<FakeEstimator> estimators3;
103  estimators3.push_back(fake_estimator);
104  estimators3.push_back(fake_estimator);
105  estimators3.push_back(fake_estimator);
106 
107  em.addScalarEstimator(std::make_unique<FakeEstimator>());
108  em.addScalarEstimator(std::make_unique<FakeEstimator>());
109  em.addScalarEstimator(std::make_unique<FakeEstimator>());
110 
111  scalar_estimators_.push_back(makeRefVector<ScalarEstimatorBase>(estimators_));
112  scalar_estimators_.push_back(makeRefVector<ScalarEstimatorBase>(estimators2));
113  scalar_estimators_.push_back(makeRefVector<ScalarEstimatorBase>(estimators3));
114 
115  em.get_AverageCache().resize(4);
116 
118 }
int addScalarEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
add an Estimator
void collectScalarEstimators(const std::vector< RefVector< ScalarEstimatorBase >> &scalar_ests)
Deals with possible free form scalar estimators.
std::vector< RefVector< ScalarEstimatorBase > > scalar_estimators_

◆ fakeSomeOperatorEstimatorSamples()

void fakeSomeOperatorEstimatorSamples ( int  rank)

Quickly add scalar samples using FakeOperatorEstimator mock estimator.

Definition at line 120 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNewTest::comm_, qmcplusplus::crowd, EstimatorManagerNewTest::em, OperatorEstBase::get_data(), EstimatorManagerNew::operator_ests_, qmcplusplus::rank, FakeOperatorEstimator::set_walker_weights(), and Communicate::size().

121 {
122  em.operator_ests_.emplace_back(new FakeOperatorEstimator(comm_->size(), DataLocality::crowd));
123  FakeOperatorEstimator& foe = dynamic_cast<FakeOperatorEstimator&>(*(em.operator_ests_.back()));
124  std::vector<QMCT::RealType>& data = foe.get_data();
125  for (int id = 0; id < data.size(); ++id)
126  {
127  if (id > rank)
128  data[id] += rank + 1;
129  }
130  foe.set_walker_weights(1);
131 }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.
int size() const
return the number of tasks
Definition: Communicate.h:118

◆ generateGoodOperatorData()

std::vector< QMCTraits::RealType > generateGoodOperatorData ( int  num_ranks)

for mpi test (it's trivial for 1 rank)

only used by test_manager_mpi.cpp so implemented there.

Definition at line 133 of file EstimatorManagerNewTest.cpp.

References qmcplusplus::num_ranks.

134 {
135  std::vector<QMCT::RealType> data(num_ranks * 10, 0.0);
136  for (int ir = 0; ir < num_ranks; ++ir)
137  {
138  for (int id = 0; id < data.size(); ++id)
139  {
140  if (id > ir)
141  data[id] += ir + 1;
142  }
143  }
144  return data;
145 }

◆ get_operator_data()

std::vector<QMCT::RealType>& get_operator_data ( )
inline

Definition at line 59 of file EstimatorManagerNewTest.h.

References EstimatorManagerNewTest::em, and EstimatorManagerNew::operator_ests_.

59 { return em.operator_ests_[0]->get_data(); }
std::vector< std::unique_ptr< OperatorEstBase > > operator_ests_
OperatorEst Observables.

◆ testMakeBlockAverages()

bool testMakeBlockAverages ( )

Definition at line 24 of file test_manager_mpi.cpp.

References EstimatorManagerNew::acceptRatioInd, RecordNamedProperty< T >::add(), EstimatorManagerNew::BlockProperties, EstimatorManagerNew::collectMainEstimators(), EstimatorManagerNew::cpuInd, EstimatorManagerNewTest::em, EstimatorManagerNewTest::estimators_, EstimatorManagerNew::makeBlockAverages(), EstimatorManagerNew::my_comm_, EstimatorManagerNew::PropertyCache, Communicate::rank(), Vector< T, Alloc >::resize(), RecordNamedProperty< T >::size(), and EstimatorManagerNew::weightInd.

25 {
26  if (em.my_comm_->rank() == 1)
27  {
28  estimators_[1].scalars[0](3.0);
29  estimators_[1].scalars[1](3.0);
30  estimators_[1].scalars[2](3.0);
31  estimators_[1].scalars[3](3.0);
32  }
33 
34  // manipulation of state to arrive at to be tested state.
35  // - From EstimatorManagerBase::reset
36  em.weightInd = em.BlockProperties.add("BlockWeight");
37  em.cpuInd = em.BlockProperties.add("BlockCPU");
38  em.acceptRatioInd = em.BlockProperties.add("AcceptRatio");
39 
40  // - From EstimatorManagerBase::start
42 
43  // - From EstimatorManagerBase::stopBlocknew
44  // three estimators
45  // - 2 with 1 sample 1
46  // - 1 with 2
47  double block_weight = 0;
48  std::for_each(estimators_.begin(), estimators_.end(),
49  [&block_weight](auto& est) { block_weight += est.scalars[0].count(); });
50  em.PropertyCache[em.weightInd] = block_weight;
51  em.PropertyCache[em.cpuInd] = 1.0;
52 
53  //RefVector<ScalarEstimatorBase> est_list = makeRefVector<ScalarEstimatorBase>(estimators_);
54  RefVector<ScalarEstimatorBase> est_lists(makeRefVector<ScalarEstimatorBase>(estimators_));
55  em.collectMainEstimators(est_lists);
56 
57  unsigned long accepts = 4;
58  unsigned long rejects = 1;
59  em.makeBlockAverages(accepts, rejects);
60  return true;
61 }
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
void makeBlockAverages(unsigned long accept, unsigned long reject)
collect data and write
int rank() const
return the rank
Definition: Communicate.h:116
int weightInd
index for the block weight PropertyCache(weightInd)
int acceptRatioInd
index for the accept counter PropertyCache(acceptInd)
int add(const std::string &aname)
int cpuInd
index for the block cpu PropertyCache(cpuInd)
Vector< RealType > PropertyCache
cached block averages of properties, e.g. BlockCPU
void collectMainEstimators(const RefVector< ScalarEstimatorBase > &scalar_estimators)
At end of block collect the main scalar estimators for the entire rank.
Communicate * my_comm_
communicator to handle communication
RecordNamedProperty< RealType > BlockProperties
manager of property data

◆ testReduceOperatorEstimators()

void testReduceOperatorEstimators ( )

Definition at line 153 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNewTest::em, and EstimatorManagerNew::reduceOperatorEstimators().

void reduceOperatorEstimators()
do the rank wise reduction of the OperatorEstimators

◆ testReplaceMainEstimator()

bool testReplaceMainEstimator ( )

test replacing the main estimator

Definition at line 34 of file EstimatorManagerNewTest.cpp.

References EstimatorManagerNew::addMainEstimator(), qmcplusplus::CHECK(), EstimatorManagerNewTest::em, and EstimatorManagerNew::main_estimator_.

Referenced by qmcplusplus::TEST_CASE().

35 {
36  // Must create on heap since the EstimatorManager destructor deletes all estimators
37  auto fake_est_uptr = std::make_unique<FakeEstimator>();
38  FakeEstimator* fake_est = fake_est_uptr.get();
39 
40  em.addMainEstimator(std::move(fake_est_uptr));
41 
42  CHECK(em.main_estimator_->getSubTypeStr() == "fake");
43 
44  auto fake_est2 = std::make_unique<FakeEstimator>();
45  fake_est2->type_ = "Fake2";
46 
47  em.addMainEstimator(std::move(fake_est2));
48 
49  return em.main_estimator_->getSubTypeStr() == "Fake2";
50 }
void addMainEstimator(std::unique_ptr< ScalarEstimatorBase > &&estimator)
UPtr< ScalarEstimatorBase > main_estimator_
main estimator i.e. some version of a local energy estimator.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))

Member Data Documentation

◆ comm_

◆ em

◆ estimators_

◆ scalar_estimators_

std::vector<RefVector<ScalarEstimatorBase> > scalar_estimators_
private

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