QMCPACK
test_EstimatorManagerCrowd.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 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"
28 #include "Utilities/ProjectData.h"
29 
30 namespace qmcplusplus
31 {
32 TEST_CASE("EstimatorManagerCrowd::EstimatorManagerCrowd", "[estimators]")
33 {
36 
37  using namespace testing;
40 
41 
43  auto wavefunction_pool =
45  auto& pset = *(particle_pool.getParticleSet("e"));
47  auto& twf = *(wavefunction_pool.getWaveFunction("wavefunction"));
48  auto& ham = *(hamiltonian_pool.getPrimary());
49 
50  EstimatorManagerNew emn(comm, std::move(emi), ham, pset, twf);
51 
52  CHECK(emn.getNumEstimators() == 2);
54 
56 }
57 
58 TEST_CASE("EstimatorManagerCrowd PerParticleHamiltonianLogger integration", "[estimators]")
59 {
62 
63  using namespace testing;
66 
67 
69  auto wavefunction_pool =
71  auto& pset = *(particle_pool.getParticleSet("e"));
72  // This is where the pset properties "properies" gain the different hamiltonian operator values.
74 
75  auto& twf = *(wavefunction_pool.getWaveFunction("wavefunction"));
76  auto& ham = *(hamiltonian_pool.getPrimary());
77 
79 
81  emi.append(std::move(pphli));
82 
83  EstimatorManagerNew emn(comm, std::move(emi), ham, pset, twf);
84 
85  CHECK(emn.getNumEstimators() == 3);
87 
88  // We repeat a bunch of test_QMCHamiltonian here to get things set up.
89 
92  std::vector<ParticleSet> psets;
93 
94  int num_walkers = 4;
95  int num_electrons = particle_pool.getParticleSet("e")->getTotalNum();
96  int num_ions = particle_pool.getParticleSet("ion")->getTotalNum();
97 
98  for (int iw = 0; iw < num_walkers; ++iw)
99  {
100  psets.emplace_back(pset);
101  psets.back().randomizeFromSource(*particle_pool.getParticleSet("ion"));
102  twfs.emplace_back(twf.makeClone(psets.back()));
103  hams.emplace_back(hamiltonian_pool.getPrimary()->makeClone(psets.back(), *twfs.back()));
104  }
105 
107 
109 
110  std::vector<MCPWalker> walkers(num_walkers, MCPWalker(pset.getTotalNum()));
111 
112  for (auto& walker : walkers)
113  {
114  walker.R = pset.R;
115  walker.spins = pset.spins;
116  walker.Properties = pset.Properties;
117  walker.registerData();
118  walker.DataSet.allocate();
119  }
120 
121  auto walker_refs = makeRefVector<MCPWalker>(walkers);
122  RefVectorWithLeader<MCPWalker> walker_list{walker_refs[0], walker_refs};
123 
124  auto p_refs = makeRefVector<ParticleSet>(psets);
125  RefVectorWithLeader<ParticleSet> p_list{p_refs[0], p_refs};
126 
127  ResourceCollection pset_res("test_pset_res");
128  p_list.getLeader().createResource(pset_res);
129  ResourceCollectionTeamLock<ParticleSet> pset_lock(pset_res, p_list);
130 
131  auto twf_refs = convertUPtrToRefVector(twfs);
132  RefVectorWithLeader<TrialWaveFunction> twf_list{twf_refs[0], twf_refs};
133 
134  ResourceCollection wfc_res("test_wfc_res");
135  twf_list.getLeader().createResource(wfc_res);
136  ResourceCollectionTeamLock<TrialWaveFunction> mw_wfc_lock(wfc_res, twf_list);
137 
138  auto ham_refs = convertUPtrToRefVector(hams);
139  RefVectorWithLeader<QMCHamiltonian> ham_list(ham_refs[0], ham_refs);
140 
141  ResourceCollection ham_res("test_ham_res");
142  ham_list.getLeader().createResource(ham_res);
143  ResourceCollectionTeamLock<QMCHamiltonian> mw_ham_lock(ham_res, ham_list);
144 
145  emc.registerListeners(ham_list);
146 
147  // Setup RNG
149 
150  // Without this QMCHamiltonian::mw_evaluate segfaults
151  // Because the CoulombPBCAA hamiltonian component has PtclRhoK (StructFact) that is invalid.
152  ParticleSet::mw_update(p_list);
153 
154  QMCHamiltonian::mw_evaluate(ham_list, twf_list, p_list);
155 
156  auto savePropertiesIntoWalker = [](QMCHamiltonian& ham, MCPWalker& walker) {
157  ham.saveProperty(walker.getPropertyBase());
158  };
159  for (int iw = 0; iw < num_walkers; ++iw)
160  savePropertiesIntoWalker(*(hams[iw]), walkers[iw]);
161 
162  emc.accumulate(walker_refs, p_refs, twf_refs, ham_refs, rng);
163 }
164 
165 
166 } // namespace qmcplusplus
void informOperatorsOfListener()
Some Hamiltonian components need to be informed that they are in a per particle reporting situation s...
class that handles xmlDoc
Definition: Libxml2Doc.h:76
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Libxml2Document createEstimatorManagerNewInputXML()
Class to manage a set of ScalarEstimators As a manager, this class handles the aggregation of data fr...
class ProjectData
Definition: ProjectData.h:36
static ParticleSetPool make_diamondC_1x1x1(Communicate *c)
void saveProperty(IT first)
save the values of Hamiltonian elements to the Properties
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)
Libxml2Document createEstimatorManagerNewVMCInputXML()
xmlNodePtr getRoot()
Definition: Libxml2Doc.h:88
Collection of Local Energy Operators.
ProjectData test_project("test", ProjectData::DriverVersion::BATCH)
std::vector< std::unique_ptr< T > > UPtrVector
const char walkers[]
Definition: HDFVersion.h:36
EstimatorManagerInput emi(estimators_doc.getRoot())
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
static RefVector< T > convertUPtrToRefVector(const UPtrVector< T > &ptr_list)
convert a vector of std::unique_ptrs<T> to a refvector<T>
const RuntimeOptions & getRuntimeOptions() const noexcept
static std::vector< QMCHamiltonian::FullPrecRealType > mw_evaluate(const RefVectorWithLeader< QMCHamiltonian > &ham_list, const RefVectorWithLeader< TrialWaveFunction > &wf_list, const RefVectorWithLeader< ParticleSet > &p_list)
batched version of evaluate for LocalEnergy
void append(const EstimatorInput &ei)
typed appending of already parsed inputs.
Wrapping information on parallelism.
Definition: Communicate.h:68
Compilation units that construct QMCDriverInput need visibility to the actual input classes types in ...
Thread local estimator container/accumulator.
static HamiltonianPool make_hamWithEE(Communicate *comm, ParticleSetPool &particle_pool, WaveFunctionPool &wavefunction_pool)
Libxml2Document estimators_doc
Walker< QMCTraits, PtclOnLatticeTraits > MCPWalker
Definition: test_walker.cpp:31
Input type for EstimatorManagerNew Parses Estimators level of input and and delegates child estimator...
static void mw_update(const RefVectorWithLeader< ParticleSet > &p_list, bool skipSK=false)
batched version of update
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
handles acquire/release resource by the consumer (RefVectorWithLeader type).
void registerListeners(const RefVectorWithLeader< QMCHamiltonian > &ham_list)
This registers the crowd lever estimators that require listeners into the QMCHamiltonianMultiWalkerRe...
A container class to represent a walker.
Definition: Walker.h:49
EstimatorManagerNew emn(comm, std::move(emi), ham, pset, twf)
Declaration of QMCHamiltonian.
void accumulate(const RefVector< MCPWalker > &walkers, const RefVector< ParticleSet > &psets, const RefVector< TrialWaveFunction > &wfns, const RefVector< QMCHamiltonian > &hams, RandomBase< FullPrecRealType > &rng)
Accumulate over all scalar estimators and operator estimators over all walkers in crowd...