QMCPACK
test_manager.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) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewin@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Message/Communicate.h"
16 #include "OhmmsData/Libxml2Doc.h"
23 
24 #include <stdio.h>
25 #include <sstream>
26 
27 namespace qmcplusplus
28 {
29 TEST_CASE("EstimatorManagerBase", "[estimators]")
30 {
32 
34 
35  REQUIRE(em.size() == 0);
36 
37  // Must create on heap since the EstimatorManager destructor deletes all estimators
38  auto fake_est_uptr = std::make_unique<FakeEstimator>();
39  auto fake_est = fake_est_uptr.get();
40 
41  em.add(std::move(fake_est_uptr), "fake");
42 
43  ScalarEstimatorBase* est2 = em.getEstimator("fake");
44  FakeEstimator* fake_est2 = dynamic_cast<FakeEstimator*>(est2);
45  REQUIRE(fake_est2 != NULL);
46  REQUIRE(fake_est2 == fake_est);
47 
48  // Check the copy constructor
49  EstimatorManagerBase em2(em);
50  REQUIRE(em.size() == 1);
51 
52  em.start(2, true);
53 
54  em.stop();
55  // compute averages over threads
56  //em.stop();
57  em.reset();
58 }
59 
60 TEST_CASE("Estimator adhoc addVector operator", "[estimators]")
61 {
62  int num_scalars = 3;
63  std::vector<double> vec_a{1.0, 2.0, 3.0};
64  std::vector<double> vec_b{2.0, 3.0, 4.0};
65  std::vector<std::vector<double>> est{vec_a, vec_b};
66  auto addVectors = [](const auto& vec_a, const auto& vec_b) {
67  std::vector<ScalarEstimatorBase::RealType> result_vector(vec_a.size(), 0.0);
68  for (int i = 0; i < vec_a.size(); ++i)
69  result_vector[i] = vec_a[i] + vec_b[i];
70  return result_vector;
71  };
72 
73  std::vector<double> reduced_scalars(num_scalars);
74  reduced_scalars = std::accumulate(est.begin(), est.end(), std::vector<double>(num_scalars, 0.0), addVectors);
75  std::vector<double> correct{3.0, 5.0, 7.0};
76  REQUIRE(reduced_scalars == correct);
77 }
78 
79 } // namespace qmcplusplus
int add(std::unique_ptr< EstimatorType > newestimator, const std::string &aname)
add an Estimator
EstimatorType * getEstimator(const std::string &a)
return a pointer to the estimator aname
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
int size() const
return the number of ScalarEstimators
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))
Manager class of scalar estimators.
Class to manage a set of ScalarEstimators.
Abstract class for an estimator of a scalar operator.
void start(int blocks, bool record=true)
start a run
Declaration of a MCWalkerConfiguration.
Declaration of QMCHamiltonian.