QMCPACK
test_WalkerLogCollector.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: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Message/Communicate.h"
21 #include "Utilities/ProjectData.h"
22 
24 
25 
26 namespace qmcplusplus
27 {
28 
29 TEST_CASE("WalkerLogCollector::collect", "[estimators]")
30 {
31  app_log() << "\n\n=======================================================\n";
32  app_log() << "test WalkerLogCollector::collect\n";
33 
36 
37 
39  auto wavefunction_pool =
41  auto& pset = *(particle_pool.getParticleSet("e"));
42  // This is where the pset properties "properies" gain the different hamiltonian operator values.
44 
45  auto& twf = *(wavefunction_pool.getWaveFunction("wavefunction"));
46  auto& ham = *(hamiltonian_pool.getPrimary());
47 
48  // setup data structures for multiple walkers
49 
52  std::vector<ParticleSet> psets;
53 
54  int num_walkers = 4;
55  int num_electrons = particle_pool.getParticleSet("e")->getTotalNum();
56  int num_ions = particle_pool.getParticleSet("ion")->getTotalNum();
57 
58  for (int iw = 0; iw < num_walkers; ++iw)
59  {
60  psets.emplace_back(pset);
61  psets.back().randomizeFromSource(*particle_pool.getParticleSet("ion"));
62  twfs.emplace_back(twf.makeClone(psets.back()));
63  hams.emplace_back(hamiltonian_pool.getPrimary()->makeClone(psets.back(), *twfs.back()));
64  }
65 
67 
68  std::vector<MCPWalker> walkers(num_walkers, MCPWalker(pset.getTotalNum()));
69 
70  for (auto& walker : walkers)
71  {
72  walker.R = pset.R;
73  walker.spins = pset.spins;
74  walker.Properties = pset.Properties;
75  walker.registerData();
76  walker.DataSet.allocate();
77  }
78 
79  WalkerLogState state{true, 1, false};
80  WalkerLogCollector wlc(state);
81 
82  auto& bsi = wlc.walker_property_int_buffer;
83  auto& bsr = wlc.walker_property_real_buffer;
84  auto& bpr = wlc.walker_particle_real_buffer;
85 
86  CHECK(bsi.nrows() == 0);
87  CHECK(bsr.nrows() == 0);
88  CHECK(bpr.nrows() == 0);
89  CHECK(bsi.ncols() == 0);
90  CHECK(bsr.ncols() == 0);
91  CHECK(bpr.ncols() == 0);
92 
93 #ifndef QMC_COMPLEX
94  const size_t npcols = 56;
95 #else
96  const size_t npcols = 88;
97 #endif
98 
99  int step = 0;
100  wlc.collect(walkers[0], psets[0], *(twfs[0]), *(hams[0]), step);
101 
102  CHECK(bsi.nrows() == 1);
103  CHECK(bsr.nrows() == 1);
104  CHECK(bpr.nrows() == 1);
105  CHECK(bsi.ncols() == 4);
106  CHECK(bsr.ncols() == 13);
107  CHECK(bpr.ncols() == npcols);
108 
109  for (size_t iw = 1; iw < walkers.size(); ++iw)
110  wlc.collect(walkers[iw], psets[iw], *(twfs[iw]), *(hams[iw]), step);
111 
112  CHECK(bsi.nrows() == 4);
113  CHECK(bsr.nrows() == 4);
114  CHECK(bpr.nrows() == 4);
115  CHECK(bsi.ncols() == 4);
116  CHECK(bsr.ncols() == 13);
117  CHECK(bpr.ncols() == npcols);
118 
119  for (step = 1; step < 3; ++step)
120  for (size_t iw = 0; iw < walkers.size(); ++iw)
121  wlc.collect(walkers[iw], psets[iw], *(twfs[iw]), *(hams[iw]), step);
122 
123  CHECK(bsi.nrows() == 12);
124  CHECK(bsr.nrows() == 12);
125  CHECK(bpr.nrows() == 12);
126  CHECK(bsi.ncols() == 4);
127  CHECK(bsr.ncols() == 13);
128  CHECK(bpr.ncols() == npcols);
129 
130  app_log() << "\nend test WalkerLogCollector::collect\n";
131  app_log() << "=======================================================\n";
132 }
133 
134 
135 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
WalkerLogBuffer< WLog::Int > walker_property_int_buffer
buffer containing integer walker properties
std::ostream & app_log()
Definition: OutputManager.h:65
class ProjectData
Definition: ProjectData.h:36
static ParticleSetPool make_diamondC_1x1x1(Communicate *c)
const char num_walkers[]
Definition: HDFVersion.h:37
TEST_CASE("complex_helper", "[type_traits]")
static WaveFunctionPool make_diamondC_1x1x1(const RuntimeOptions &runtime_options, Communicate *comm, ParticleSetPool &particle_pool)
WalkerLogBuffer< WLog::Real > walker_property_real_buffer
buffer containing real-valued walker properties
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
Crowd-level resource for walker log collection.
std::vector< std::unique_ptr< T > > UPtrVector
const char walkers[]
Definition: HDFVersion.h:36
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
const RuntimeOptions & getRuntimeOptions() const noexcept
Wrapping information on parallelism.
Definition: Communicate.h:68
WalkerLogBuffer< WLog::Real > walker_particle_real_buffer
buffer containing per-particle walker data
void collect(const MCPWalker &walker, const ParticleSet &pset, const TrialWaveFunction &wfn, const QMCHamiltonian &ham, int step=-1)
collect all data for one walker into the data buffers
static HamiltonianPool make_hamWithEE(Communicate *comm, ParticleSetPool &particle_pool, WaveFunctionPool &wavefunction_pool)
Walker< QMCTraits, PtclOnLatticeTraits > MCPWalker
Definition: test_walker.cpp:31
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Helper struct holding data transferred from WalkerLogManager to WalkerLogCollector following input re...
A container class to represent a walker.
Definition: Walker.h:49
Declaration of QMCHamiltonian.