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) 2020 QMCPACK developers. 6 // 7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab 8 // 9 // File refactored from: Refactored from test_manager.cpp 10 ////////////////////////////////////////////////////////////////////////////////////// 11 12 13 #include "catch.hpp" 14 15 #include "Message/Communicate.h" 16 #include "OhmmsData/Libxml2Doc.h" 17 #include "QMCHamiltonians/QMCHamiltonian.h" 18 #include "Estimators/EstimatorManagerNew.h" 19 #include "Estimators/ScalarEstimatorBase.h" 20 #include "Estimators/tests/EstimatorManagerNewTest.h" 21 22 #include <stdio.h> 23 #include <sstream> 24 25 namespace qmcplusplus 26 { 27 28 TEST_CASE("EstimatorManagerNew", "[estimators]") 29 { 30 Communicate* c = OHMMS::Controller; 31 32 testing::EstimatorManagerNewTest embt(c, 1); 33 34 REQUIRE(embt.em.size() == 0); 35 36 REQUIRE(embt.testAddGetEstimator()); 37 } 38 39 TEST_CASE("EstimatorManagerNew::collectScalarEstimators", "[estimators]") 40 { 41 Communicate* c = OHMMS::Controller; 42 43 testing::EstimatorManagerNewTest embt(c, 1); 44 // by design we have done no averaging here 45 // the division by total weight happens only when a block is over and the 46 // accumulated data has been reduced down. So here there should just be simple sums. 47 48 embt.fakeSomeScalarSamples(); 49 embt.collectScalarEstimators(); 50 double correct_value = 5.0; 51 REQUIRE(embt.em.get_AverageCache()[0] == Approx(correct_value)); 52 correct_value = 8.0; 53 REQUIRE(embt.em.get_AverageCache()[1] == Approx(correct_value)); 54 correct_value = 11.0; 55 REQUIRE(embt.em.get_AverageCache()[2] == Approx(correct_value)); 56 correct_value = 14.0; 57 REQUIRE(embt.em.get_AverageCache()[3] == Approx(correct_value)); 58 59 } 60 61 62 TEST_CASE("EstimatorManagerNew::collectOperatorEstimators", "[estimators]") 63 { 64 Communicate* c = OHMMS::Controller; 65 66 testing::EstimatorManagerNewTest embt(c, 1); 67 // by design we have done no averaging here 68 // the division by total weight happens only when a block is over and the 69 // accumulated data has been reduced down. So here there should just be simple sums. 70 71 } 72 73 74 TEST_CASE("EstimatorManagerNew adhoc addVector operator", "[estimators]") 75 { 76 int num_scalars = 3; 77 std::vector<double> vec_a{1.0, 2.0, 3.0}; 78 std::vector<double> vec_b{2.0, 3.0, 4.0}; 79 std::vector<std::vector<double>> est{vec_a, vec_b}; __anona0baf17f0102(const auto& vec_a, const auto& vec_b) 80 auto addVectors = [](const auto& vec_a, const auto& vec_b) { 81 std::vector<ScalarEstimatorBase::RealType> result_vector(vec_a.size(), 0.0); 82 for (int i = 0; i < vec_a.size(); ++i) 83 result_vector[i] = vec_a[i] + vec_b[i]; 84 return result_vector; 85 }; 86 87 std::vector<double> reduced_scalars(num_scalars); 88 reduced_scalars = std::accumulate(est.begin(), est.end(), std::vector<double>(num_scalars, 0.0), addVectors); 89 std::vector<double> correct{3.0, 5.0, 7.0}; 90 REQUIRE(reduced_scalars == correct); 91 } 92 93 } // namespace qmcplusplus 94