QMCPACK
test_EstimatorManagerInput.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) 2024 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
13 #include "EstimatorManagerInput.h"
17 #include "ValidSpinDensityInput.h"
18 
19 namespace qmcplusplus
20 {
21 
22 namespace testing
23 {
25 {
26 public:
27  /** @ingroup testing "private" methods of estimator class
28  * useful for this new implementation
29  * @{
30  */
31  /// Actually from valid xml.
32  template<class T>
34  {
36  }
37  /** @} */
38 };
39 
40 } // namespace testing
41 
42 TEST_CASE("EstimatorManagerInput::testInserts", "[estimators]")
43 {
44  using namespace testing;
47 
48  {
51  bool okay = doc.parseFromString(input::xml[input::VANILLA]);
52  REQUIRE(okay);
53  xmlNodePtr node = doc.getRoot();
55  }
56  {
58  using spin_input = testing::ValidSpinDensityInput;
59  bool okay = doc.parseFromString(spin_input::xml[spin_input::GRID]);
60  REQUIRE(okay);
61  xmlNodePtr node = doc.getRoot();
63  }
64 }
65 
66 TEST_CASE("EstimatorManagerInput::readXML", "[estimators]")
67 {
68  using namespace testing;
71 
72  CHECK(emi.get_estimator_inputs().size() == 2);
73  CHECK(emi.get_scalar_estimator_inputs().size() == 5);
74 
75  // CHECK EMI throws if unparsable estimators are in input.
77  std::string bad_estimator = R"XML(
78 <estimator type="NeutrinoDensity" name="bad_estimator"/>
79 )XML";
80  bool okay = doc.parseFromString(bad_estimator);
81  REQUIRE(okay);
82  xmlNodePtr node = doc.getRoot();
83  int max_node_recurse = 1;
84  estimators_doc.addChild(xmlCopyNode(node, max_node_recurse));
86 }
87 
88 template<class INPUT>
90 {
91 public:
93 
94 private:
95  const INPUT input_;
96 };
97 
98 TEST_CASE("EstimatorManagerInput::moveFromEstimatorInputs", "[estimators]")
99 {
100  using namespace testing;
103 
104  {
107  bool okay = doc.parseFromString(input::xml[input::VANILLA]);
108  REQUIRE(okay);
109  xmlNodePtr node = doc.getRoot();
111  }
112  {
114  using spin_input = testing::ValidSpinDensityInput;
115  bool okay = doc.parseFromString(spin_input::xml[spin_input::GRID]);
116  REQUIRE(okay);
117  xmlNodePtr node = doc.getRoot();
119  }
121  std::move(std::get<SpinDensityInput>(emi.get_estimator_inputs().back())));
122  emi.get_estimator_inputs().pop_back();
124  std::move(std::get<OneBodyDensityMatricesInput>(emi.get_estimator_inputs().back())));
125  emi.get_estimator_inputs().pop_back();
126 }
127 
128 TEST_CASE("EstimatorManagerInput::moveConstructor", "[estimators]")
129 {
130  using namespace testing;
133 
134  CHECK(emi.get_estimator_inputs().size() == 2);
135  CHECK(emi.get_scalar_estimator_inputs().size() == 5);
136 
137  EstimatorManagerInput emi_moved_to(std::move(emi));
138 
139  CHECK(emi_moved_to.get_estimator_inputs().size() == 2);
140  CHECK(emi_moved_to.get_scalar_estimator_inputs().size() == 5);
141 }
142 
143 TEST_CASE("EstimatorManagerInput::MergeConstructor", "[estimators]")
144 {
145  using namespace testing;
148  EstimatorManagerInput emi_global(global_estimators_doc.getRoot());
150  EstimatorManagerInput emi_merged{emi_global, emi_local};
151 
152  CHECK(emi_merged.get_estimator_inputs().size() == 2);
153  CHECK(emi_merged.get_scalar_estimator_inputs().size() == 6);
154 }
155 
156 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
ScalarEstimatorInputs & get_scalar_estimator_inputs()
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
declares the list supported estimator input types and declares the input type for EstimatorManagerNew...
if(!okay) throw std xmlNodePtr node
Libxml2Document createEstimatorManagerNewInputXML()
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
EstimatorManagerInput emi(estimators_doc.getRoot())
Libxml2Document createEstimatorManagerNewGlobalInputXML()
static constexpr std::array< std::string_view, 3 > xml
Native representation for DensityMatrices1B Estimator&#39;s inputs.
REQUIRE(std::filesystem::exists(filename))
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
This a subclass for runtime errors that will occur on all ranks.
OneBodyDensityMatricesInput obdmi(node)
Native representation for Spin Density Estimators inputs.
Libxml2Document estimators_doc
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
Input type for EstimatorManagerNew Parses Estimators level of input and and delegates child estimator...
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void addChild(xmlNodePtr newnode)
Definition: Libxml2Doc.cpp:111
void testAppendFromXML(EstimatorManagerInput &emi, xmlNodePtr node)
"" useful for this new implementation