QMCPACK
test_manager_mpi.cpp
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: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
13 #include "Message/Communicate.h"
14 
19 
20 namespace qmcplusplus
21 {
22 namespace testing
23 {
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 }
62 
63 } // namespace testing
64 
65 TEST_CASE("EstimatorManagerNew::makeBlockAverages()", "[estimators]")
66 {
68  int num_ranks = c->size();
71 
74 
75  // right now only rank() == 0 gets the actual averages
76  if (c->rank() == 0)
77  {
78  double correct_value = (5.0 * num_ranks + 3.0) / (4 * (num_ranks - 1) + 5);
79  CHECK(embt.em.get_AverageCache()[0] == Approx(correct_value));
80  correct_value = (8.0 * num_ranks + 3.0) / (4 * (num_ranks - 1) + 5);
81  CHECK(embt.em.get_AverageCache()[1] == Approx(correct_value));
82  correct_value = (11.0 * num_ranks + 3.0) / (4 * (num_ranks - 1) + 5);
83  CHECK(embt.em.get_AverageCache()[2] == Approx(correct_value));
84  correct_value = (14.0 * num_ranks + 3.0) / (4 * (num_ranks - 1) + 5);
85  CHECK(embt.em.get_AverageCache()[3] == Approx(correct_value));
86  }
87 }
88 
89 TEST_CASE("EstimatorManagerNew::reduceOperatorestimators()", "[estimators]")
90 {
92  int num_ranks = c->size();
93  QMCHamiltonian ham;
94  testing::EstimatorManagerNewTest embt(ham, c, num_ranks);
95 
97  std::vector<QMCTraits::RealType> good_data = embt.generateGoodOperatorData(num_ranks);
98 
99  // Normalization is done by reduceOperatorEstimators based on the the total weight of the
100  // estimators for that block.
102 
103  if (c->rank() == 0)
104  {
105  auto& test_data = embt.get_operator_data();
106 
108  for (size_t i = 0; i < test_data.size(); ++i)
109  {
110  QMCTraits::RealType norm_good_data = good_data[i] * norm;
111  if (norm_good_data != test_data[i])
112  {
113  FAIL_CHECK("norm_good_data " << norm_good_data << " != test_data " << test_data[i] << " at index " << i);
114  break;
115  }
116  }
117  }
118 }
119 
120 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
void fakeSomeOperatorEstimatorSamples(int rank)
Quickly add scalar samples using FakeOperatorEstimator mock estimator.
void makeBlockAverages(unsigned long accept, unsigned long reject)
collect data and write
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int rank() const
return the rank
Definition: Communicate.h:116
QTBase::RealType RealType
Definition: Configuration.h:58
Declaration of OutputManager class.
TEST_CASE("complex_helper", "[type_traits]")
Collection of Local Energy Operators.
int weightInd
index for the block weight PropertyCache(weightInd)
std::vector< QMCTraits::RealType > good_data
Testing class breaking EstimatorManagerNew encapsultation.
void fakeMainScalarSamples()
Quickly add main scalar samples using FakeEstimator mock estimator.
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
int size() const
return the number of tasks
Definition: Communicate.h:118
Wrapping information on parallelism.
Definition: Communicate.h:68
int acceptRatioInd
index for the accept counter PropertyCache(acceptInd)
double norm(const zVec &c)
Definition: VectorOps.h:118
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
testing::EstimatorManagerNewTest embt(ham, c, 1)
void collectMainEstimators(const RefVector< ScalarEstimatorBase > &scalar_estimators)
At end of block collect the main scalar estimators for the entire rank.
std::vector< QMCT::RealType > & get_operator_data()
std::vector< std::reference_wrapper< T > > RefVector
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Communicate * my_comm_
communicator to handle communication
RecordNamedProperty< RealType > BlockProperties
manager of property data
std::vector< QMCT::RealType > generateGoodOperatorData(int num_ranks)
for mpi test (it&#39;s trivial for 1 rank)
Declaration of QMCHamiltonian.