QMCPACK
test_QMCDriverFactory.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 
13 #include "catch.hpp"
14 
15 #include <iostream>
16 #include <stdio.h>
17 #include <string>
18 #include <sstream>
20 #include "Message/Communicate.h"
21 #include "OhmmsData/Libxml2Doc.h"
28 #include "ProjectData.h"
29 #include "Message/Communicate.h"
30 #include "QMCDrivers/VMC/VMC.h"
31 #include "QMCDrivers/DMC/DMC.h"
35 
36 namespace qmcplusplus
37 {
38 namespace testing
39 {
41 {
42 public:
43  QMCDriverPools(const RuntimeOptions& runtime_options, Communicate* comm)
44  : particle(MinimalParticlePool::make_diamondC_1x1x1(comm)),
45  wavefunction(MinimalWaveFunctionPool::make_diamondC_1x1x1(runtime_options, comm, particle)),
47  {}
51 };
52 
53 auto createDriver(const RuntimeOptions& runtime_options,
55  QMCDriverFactory& driver_factory,
56  xmlNodePtr node,
58 {
59  QMCDriverPools dr_pools(runtime_options, comm);
60  std::string target("e");
61  MCWalkerConfiguration* qmc_system = dr_pools.particle.getWalkerSet(target);
62  return driver_factory.createQMCDriver(node, das, std::nullopt, *qmc_system, dr_pools.particle, dr_pools.wavefunction,
63  dr_pools.hamiltonian, comm);
64 }
65 
66 } // namespace testing
67 
68 TEST_CASE("QMCDriverFactory create VMC Driver", "[qmcapp]")
69 {
70  using namespace testing;
73 
75  QMCDriverFactory driver_factory(test_project);
76 
79  REQUIRE(okay);
80  xmlNodePtr node = doc.getRoot();
83 
84  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
85 
86  REQUIRE(qmc_driver != nullptr);
87  REQUIRE_THROWS(dynamic_cast<VMCBatched&>(*qmc_driver));
88  REQUIRE_NOTHROW(dynamic_cast<VMC&>(*qmc_driver));
89  CHECK(qmc_driver->getEngineName() == "VMC");
90 }
91 
92 TEST_CASE("QMCDriverFactory create VMCBatched driver", "[qmcapp]")
93 {
96  using namespace testing;
97 
98  SECTION("driver version behavior")
99  {
101  QMCDriverFactory driver_factory(test_project);
102 
105  REQUIRE(okay);
106  xmlNodePtr node = doc.getRoot();
109 
110  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
111  REQUIRE(qmc_driver != nullptr);
112  REQUIRE_NOTHROW(dynamic_cast<VMCBatched&>(*qmc_driver));
113  REQUIRE_THROWS(dynamic_cast<VMC&>(*qmc_driver));
114  CHECK(qmc_driver->getEngineName() == "VMCBatched");
115  }
116  SECTION("Deprecated _batch behavior")
117  {
118  using namespace testing;
120  QMCDriverFactory driver_factory(test_project);
121 
124  REQUIRE(okay);
125  xmlNodePtr node = doc.getRoot();
128 
129  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
130 
131  REQUIRE(qmc_driver != nullptr);
132  REQUIRE_NOTHROW(dynamic_cast<VMCBatched&>(*qmc_driver));
133  REQUIRE_THROWS(dynamic_cast<VMC&>(*qmc_driver));
134  CHECK(qmc_driver->getEngineName() == "VMCBatched");
135  }
136 }
137 
138 TEST_CASE("QMCDriverFactory create DMC driver", "[qmcapp]")
139 {
140  using namespace testing;
141  Communicate* comm;
143 
145  QMCDriverFactory driver_factory(test_project);
146 
149  REQUIRE(okay);
150  xmlNodePtr node = doc.getRoot();
153 
154  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
155 
156  REQUIRE(qmc_driver != nullptr);
157  REQUIRE_THROWS(dynamic_cast<DMCBatched&>(*qmc_driver));
158  REQUIRE_NOTHROW(dynamic_cast<DMC&>(*qmc_driver));
159  CHECK(qmc_driver->getEngineName() == "DMC");
160 }
161 
162 TEST_CASE("QMCDriverFactory create DMCBatched driver", "[qmcapp]")
163 {
164  using namespace testing;
165  Communicate* comm;
167 
168  SECTION("driver version behavior")
169  {
171  QMCDriverFactory driver_factory(test_project);
172 
175  REQUIRE(okay);
176  xmlNodePtr node = doc.getRoot();
179 
180  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
181  REQUIRE(qmc_driver != nullptr);
182  REQUIRE_NOTHROW(dynamic_cast<DMCBatched&>(*qmc_driver));
183  REQUIRE_THROWS(dynamic_cast<DMC&>(*qmc_driver));
184  CHECK(qmc_driver->getEngineName() == "DMCBatched");
185  }
186  SECTION("Deprecated _batch behavior")
187  {
189  QMCDriverFactory driver_factory(test_project);
190 
193  REQUIRE(okay);
194  xmlNodePtr node = doc.getRoot();
197 
198  auto qmc_driver = testing::createDriver(test_project.getRuntimeOptions(), comm, driver_factory, node, das);
199 
200  REQUIRE(qmc_driver != nullptr);
201  REQUIRE_NOTHROW(dynamic_cast<DMCBatched&>(*qmc_driver));
202  REQUIRE_THROWS(dynamic_cast<DMC&>(*qmc_driver));
203  CHECK(qmc_driver->getEngineName() == "DMCBatched");
204  }
205 }
206 
207 } // namespace qmcplusplus
DMC type: dmc, dmc-ptcl.
MCWalkerConfiguration * getWalkerSet(const std::string &pname)
get a named MCWalkerConfiguration
class that handles xmlDoc
Definition: Libxml2Doc.h:76
constexpr int valid_vmc_input_vmc_index
TEST_CASE("ListenerVector", "[hamiltonian]")
A set of walkers that are to be advanced by Metropolis Monte Carlo.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
if(!okay) throw std xmlNodePtr node
DriverAssemblyState readSection(xmlNodePtr cur) const
default constructor
class ProjectData
Definition: ProjectData.h:36
TEST_CASE("complex_helper", "[type_traits]")
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
This should be the minimal ParticleSetPool for integration tests.
constexpr int valid_vmc_input_vmc_batch_index
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
const RuntimeOptions & getRuntimeOptions() const noexcept
constexpr int valid_dmc_input_dmc_index
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
std::unique_ptr< QMCDriverInterface > createQMCDriver(xmlNodePtr cur, DriverAssemblyState &das, const std::optional< EstimatorManagerInput > &emi, MCWalkerConfiguration &qmc_system, ParticleSetPool &particle_pool, WaveFunctionPool &wave_function_pool, HamiltonianPool &hamiltonian_pool, Communicate *comm) const
create a new QMCDriver
Manage a collection of ParticleSet objects.
constexpr std::array< const char *, 4 > valid_vmc_input_sections
constexpr int valid_vmc_batch_input_vmc_batch_index
constexpr int valid_dmc_input_dmc_batch_index
bool parseFromString(const std::string_view data)
Definition: Libxml2Doc.cpp:204
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
constexpr std::array< const char *, 3 > valid_dmc_input_sections
constexpr int valid_dmc_batch_input_dmc_batch_index
VMC type: vmc, vmc-ptcl, vmc-multiple, vmc-ptcl-multiple.
QMCDriverPools(const RuntimeOptions &runtime_options, Communicate *comm)
Declare a global Random Number Generator.
auto createDriver(const RuntimeOptions &runtime_options, Communicate *comm, QMCDriverFactory &driver_factory, xmlNodePtr node, QMCDriverFactory::DriverAssemblyState &das)
Define OpenMP-able DMC Driver.
avoids many repeated xml heredoc sections
Manage a collection of TrialWaveFunction objects.
Manage a collection of QMCHamiltonian objects.