QMCPACK
test_QMCDriverNew.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) 2019 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 
18 #include "Message/Communicate.h"
24 #include "Concurrency/Info.hpp"
26 
27 namespace qmcplusplus
28 {
29 TEST_CASE("QMCDriverNew tiny case", "[drivers]")
30 {
31  using namespace testing;
36 
39  REQUIRE(okay);
40  xmlNodePtr node = doc.getRoot();
41  QMCDriverInput qmcdriver_input;
42  qmcdriver_input.readXML(node);
44  auto wavefunction_pool =
46 
48  WalkerConfigurations walker_confs;
49  QMCDriverNewTestWrapper qmcdriver(test_project, std::move(qmcdriver_input), walker_confs,
50  MCPopulation(comm->size(), comm->rank(), particle_pool.getParticleSet("e"),
51  wavefunction_pool.getPrimary(), hamiltonian_pool.getPrimary()),
52  comm);
53 
54  // setStatus must be called before process
55  std::string root_name{"Test"};
56  //For later sections this appears to contain important state.
57  std::string prev_config_file{""};
58 
59  qmcdriver.setStatus(root_name, prev_config_file, false);
60  // We want to express out expectations of the QMCDriver state machine so we catch
61  // changes to it over time.
63 
64  REQUIRE(qmcdriver.getBranchEngine() == nullptr);
65  qmcdriver.process(node);
66  REQUIRE(qmcdriver.get_num_living_walkers() == 1);
67 
68  // What else should we expect after process
69 }
70 
71 #ifdef _OPENMP
72 TEST_CASE("QMCDriverNew more crowds than threads", "[drivers]")
73 {
74  using namespace testing;
75 
76  Concurrency::OverrideMaxCapacity<> override(8);
80 
83  REQUIRE(okay);
84  xmlNodePtr node = doc.getRoot();
85  QMCDriverInput qmcdriver_input;
86  qmcdriver_input.readXML(node);
88  auto wavefunction_pool =
90 
92 
93  int num_crowds = 9;
94 
95  // test is a no op except for openmp, max threads is >> than num cores
96  // in other concurrency models.
97  if (Concurrency::maxCapacity<>() != 8)
98  throw std::runtime_error("Insufficient threads available to match test input");
99 
100  QMCDriverInput qmcdriver_copy(qmcdriver_input);
101  WalkerConfigurations walker_confs;
102  QMCDriverNewTestWrapper qmc_batched(test_project, std::move(qmcdriver_copy), walker_confs,
103  MCPopulation(comm->size(), comm->rank(), particle_pool.getParticleSet("e"),
104  wavefunction_pool.getPrimary(), hamiltonian_pool.getPrimary()),
105  comm);
106  QMCDriverNewTestWrapper::TestNumCrowdsVsNumThreads<ParallelExecutor<>> testNumCrowds;
107  testNumCrowds(9);
108  testNumCrowds(8);
109 }
110 
111 TEST_CASE("QMCDriverNew walker counts", "[drivers]")
112 {
113  using namespace testing;
114  Concurrency::OverrideMaxCapacity<> override(8);
115  ProjectData test_project("test", ProjectData::DriverVersion::BATCH);
118 
121  REQUIRE(okay);
122  xmlNodePtr node = doc.getRoot();
123  QMCDriverInput qmcdriver_input;
124  qmcdriver_input.readXML(node);
126  auto wavefunction_pool =
128 
130 
131  int num_crowds = 8;
132 
133  if (Concurrency::maxCapacity<>() < 8)
134  num_crowds = Concurrency::maxCapacity<>();
135 
136  if (num_crowds < 8)
137  throw std::runtime_error("Insufficient threads available to match test input");
138 
139  QMCDriverInput qmcdriver_copy(qmcdriver_input);
140  WalkerConfigurations walker_confs;
141  QMCDriverNewTestWrapper qmc_batched(test_project, std::move(qmcdriver_copy), walker_confs,
142  MCPopulation(comm->size(), comm->rank(), particle_pool.getParticleSet("e"),
143  wavefunction_pool.getPrimary(), hamiltonian_pool.getPrimary()),
144  comm);
145 
146  qmc_batched.testAdjustGlobalWalkerCount();
147 }
148 #endif
149 
150 TEST_CASE("QMCDriverNew test driver operations", "[drivers]")
151 {
152  using namespace testing;
157 
160  REQUIRE(okay);
161  xmlNodePtr node = doc.getRoot();
162 
163  QMCDriverInput qmcdriver_input;
164  qmcdriver_input.readXML(node);
166  auto wavefunction_pool =
168 
170  WalkerConfigurations walker_confs;
171  QMCDriverNewTestWrapper qmcdriver(test_project, std::move(qmcdriver_input), walker_confs,
172  MCPopulation(comm->size(), comm->rank(), particle_pool.getParticleSet("e"),
173  wavefunction_pool.getPrimary(), hamiltonian_pool.getPrimary()),
174  comm);
175 
176 
177  auto tau = 1.0;
178  auto invmass = 0.2;
179  auto spin_mass = 0.5;
180  {
181  TauParams<QMCTraits::RealType, CoordsType::POS> taus(tau, invmass, spin_mass);
182  constexpr auto mct = CoordsType::POS;
183  auto mc_coords = MCCoords<mct>(3);
184  QMCTraits::PosType p1({0.1, 0.2, 0.3});
185  QMCTraits::PosType p2({0.4, 0.5, 0.6});
186  QMCTraits::PosType p3({0.7, 0.8, 0.9});
187  mc_coords.positions = {p1, p2, p3};
188 
189  auto deltas = mc_coords;
190  QMCDriverNew::scaleBySqrtTau(taus, deltas);
191  mc_coords += deltas;
192  CHECK(Approx(mc_coords.positions[0][0]) == 0.14472135955);
193  CHECK(Approx(mc_coords.positions[0][1]) == 0.28944271910);
194  CHECK(Approx(mc_coords.positions[0][2]) == 0.43416407865);
195  CHECK(Approx(mc_coords.positions[1][0]) == 0.57888543820);
196  CHECK(Approx(mc_coords.positions[1][1]) == 0.72360679775);
197  CHECK(Approx(mc_coords.positions[1][2]) == 0.86832815730);
198  CHECK(Approx(mc_coords.positions[2][0]) == 1.01304951685);
199  CHECK(Approx(mc_coords.positions[2][1]) == 1.15777087640);
200  CHECK(Approx(mc_coords.positions[2][2]) == 1.30249223595);
201 
202  std::vector<QMCTraits::RealType> loggf(3), loggb(3);
203 
204  qmcdriver.computeLogGreensFunction(deltas, taus, loggf);
205  CHECK(Approx(loggf[0]) == -0.07);
206  CHECK(Approx(loggf[1]) == -0.385);
207  CHECK(Approx(loggf[2]) == -0.97);
208 
209  qmcdriver.computeLogGreensFunction(mc_coords, taus, loggb);
210  CHECK(Approx(loggb[0]) == -0.733049516850);
211  CHECK(Approx(loggb[1]) == -4.031772342675);
212  CHECK(Approx(loggb[2]) == -10.15797187635);
213  }
214 
215  {
216  TauParams<QMCTraits::RealType, CoordsType::POS_SPIN> taus(tau, invmass, spin_mass);
217  constexpr auto mct = CoordsType::POS_SPIN;
218  auto mc_coords = MCCoords<mct>(3);
219  QMCTraits::PosType p1({-0.1, -0.2, -0.3});
220  QMCTraits::PosType p2({-0.4, -0.5, -0.6});
221  QMCTraits::PosType p3({-0.7, -0.8, -0.9});
222  mc_coords.positions = {p1, p2, p3};
223  mc_coords.spins = {0.1, 0.2, 0.3};
224 
225  auto deltas = mc_coords;
226  QMCDriverNew::scaleBySqrtTau(taus, deltas);
227  mc_coords += deltas;
228  CHECK(Approx(mc_coords.positions[0][0]) == -0.14472135955);
229  CHECK(Approx(mc_coords.positions[0][1]) == -0.28944271910);
230  CHECK(Approx(mc_coords.positions[0][2]) == -0.43416407865);
231  CHECK(Approx(mc_coords.positions[1][0]) == -0.57888543820);
232  CHECK(Approx(mc_coords.positions[1][1]) == -0.72360679775);
233  CHECK(Approx(mc_coords.positions[1][2]) == -0.86832815730);
234  CHECK(Approx(mc_coords.positions[2][0]) == -1.01304951685);
235  CHECK(Approx(mc_coords.positions[2][1]) == -1.15777087640);
236  CHECK(Approx(mc_coords.positions[2][2]) == -1.30249223595);
237 
238  CHECK(Approx(mc_coords.spins[0]) == 0.163245553203);
239  CHECK(Approx(mc_coords.spins[1]) == 0.326491106407);
240  CHECK(Approx(mc_coords.spins[2]) == 0.489736659610);
241 
242  std::vector<QMCTraits::RealType> loggf(3), loggb(3);
243 
244  qmcdriver.computeLogGreensFunction(deltas, taus, loggf);
245  CHECK(Approx(loggf[0]) == -0.075);
246  CHECK(Approx(loggf[1]) == -0.405);
247  CHECK(Approx(loggf[2]) == -1.015);
248 
249  qmcdriver.computeLogGreensFunction(mc_coords, taus, loggb);
250  CHECK(Approx(loggb[0]) == -0.766360905151);
251  CHECK(Approx(loggb[1]) == -4.165017895878);
252  CHECK(Approx(loggb[2]) == -10.457774371057);
253  }
254 
255  {
257  qmcdriver.testMeasureImbalance();
259  }
260 
261  qmcdriver.testDetermineStepsPerBlock();
262 }
263 } // namespace qmcplusplus
class that handles xmlDoc
Definition: Libxml2Doc.h:76
void pause()
Pause the summary and log streams.
Abstraction of information on executor environments.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
int rank() const
return the rank
Definition: Communicate.h:116
if(!okay) throw std xmlNodePtr node
constexpr int valid_vmc_input_vmc_tiny_index
Declaration of QMCDriverNew.
class ProjectData
Definition: ProjectData.h:36
static ParticleSetPool make_diamondC_1x1x1(Communicate *c)
A set of light weight walkers that are carried between driver sections and restart.
TEST_CASE("complex_helper", "[type_traits]")
static WaveFunctionPool make_diamondC_1x1x1(const RuntimeOptions &runtime_options, Communicate *comm, ParticleSetPool &particle_pool)
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
static void scaleBySqrtTau(const TauParams< RT, CT > &taus, MCCoords< CT > &coords)
Definition: QMCDriverNew.h:257
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
Object to encapsulate appropriate tau derived parameters for a particular CoordsType specialization...
Definition: TauParams.hpp:25
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
int size() const
return the number of tasks
Definition: Communicate.h:118
const RuntimeOptions & getRuntimeOptions() const noexcept
OutputManagerClass outputManager(Verbosity::HIGH)
Wrapping information on parallelism.
Definition: Communicate.h:68
void resume()
Resume the summary and log streams.
REQUIRE(std::filesystem::exists(filename))
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
constexpr std::array< const char *, 4 > valid_vmc_input_sections
A service class to override active avaiable threads upon construction.
static void computeLogGreensFunction(const MCCoords< CT > &coords, const TauParams< RT, CT > &taus, std::vector< QMCTraits::RealType > &log_gb)
calculates Green Function from displacements stored in MCCoords [param, out] log_g ...
Definition: QMCDriverNew.h:270
void process(xmlNodePtr node) override
QMCDriverNew driver second (3rd, 4th...) stage of constructing a valid driver.
void setStatus(const std::string &aname, const std::string &h5name, bool append) override
Set the status of the QMCDriver.
IndexType get_num_living_walkers() const
Definition: QMCDriverNew.h:220
static HamiltonianPool make_hamWithEE(Communicate *comm, ParticleSetPool &particle_pool, WaveFunctionPool &wavefunction_pool)
virtual std::unique_ptr< BranchEngineType > getBranchEngine()
constexpr int valid_dmc_input_dmc_batch_index
void readXML(xmlNodePtr cur)
Reads qmc section xml node parameters.
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
utility functions for executors
avoids many repeated xml heredoc sections
Input representation for Driver base class runtime parameters.