QMCPACK
test_local_energy_est.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) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewin@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "Message/Communicate.h"
16 #include "OhmmsData/Libxml2Doc.h"
22 #include "io/hdf/hdf_archive.h"
23 
24 #include <stdio.h>
25 #include <sstream>
26 
27 namespace qmcplusplus
28 {
30 
31 TEST_CASE("LocalEnergyOnly", "[estimators]")
32 {
34 
35  const SimulationCell simulation_cell;
36  MCWalkerConfiguration W(simulation_cell);
37  W.setName("electrons");
38  W.create({1});
39  W.createWalkers(1);
40 
41  (*W.begin())->Properties(WP::LOCALENERGY) = 1.1;
42 
43  le_est.accumulate(W, W.begin(), W.end(), 1.0);
44 
45  CHECK(le_est.getName() == "LocalEnergyOnlyEstimator");
46  CHECK(le_est.scalars[0].mean() == Approx(1.1));
47 }
48 
49 TEST_CASE("LocalEnergy", "[estimators]")
50 {
52  LocalEnergyEstimator le_est(H, false);
53 
54  CHECK(le_est.getName() == "LocalEnergyEstimator");
55 
56  std::unique_ptr<LocalEnergyEstimator> le_est2{le_est.clone()};
57  REQUIRE(le_est2 != nullptr);
58  REQUIRE(le_est2.get() != &le_est);
59 
60  const SimulationCell simulation_cell;
61  MCWalkerConfiguration W(simulation_cell);
62  W.setName("electrons");
63  W.create({1});
64  W.createWalkers(1);
65 
66  (*W.begin())->Properties(WP::LOCALENERGY) = 1.1;
67  (*W.begin())->Properties(WP::LOCALPOTENTIAL) = 1.2;
68 
69  le_est.accumulate(W, W.begin(), W.end(), 1.0);
70 
71  // from enum in LocalEnergyEstimator
72  // 0 - ENERGY_INDEX
73  // 1 - ENERGY2_INDEX
74  // 2 - POTENTIAL_INDEX
75  CHECK(le_est.scalars[0].mean() == Approx(1.1));
76  REQUIRE(le_est.scalars[1].mean() == le_est.scalars[0].mean2());
77  CHECK(le_est.scalars[2].mean() == Approx(1.2));
78 }
79 
80 TEST_CASE("LocalEnergy with hdf5", "[estimators]")
81 {
83  LocalEnergyEstimator le_est(H, true);
84 
85  const SimulationCell simulation_cell;
86  MCWalkerConfiguration W(simulation_cell);
87  W.setName("electrons");
88  W.create({1});
89  W.createWalkers(1);
90 
91  (*W.begin())->Properties(WP::LOCALENERGY) = 1.1;
92  (*W.begin())->Properties(WP::LOCALPOTENTIAL) = 1.2;
93 
94  std::vector<ObservableHelper> h5desc;
95 
96  std::filesystem::path filename("tmp_obs.h5");
97  hdf_archive h_file;
98  h_file.create(filename);
99  le_est.registerObservables(h5desc, h_file);
100  h_file.close();
101  REQUIRE(std::filesystem::exists(filename));
102  // Check contents?
103  REQUIRE(std::filesystem::remove(filename));
104 
106  le_est.add2Record(record);
107  // Not sure how to test this - for now make sure it doesn't crash
108 }
109 
110 } // namespace qmcplusplus
void setName(const std::string &aname)
Definition: ParticleSet.h:237
A set of walkers that are to be advanced by Metropolis Monte Carlo.
void registerObservables(std::vector< ObservableHelper > &h5dec, hdf_archive &file) override
add descriptors of observables to utilize hdf5
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Estimator for local energy only.
void accumulate(const MCWalkerConfiguration &W, WalkerIterator first, WalkerIterator last, RealType wgt) override
a virtual function to accumulate observables or collectables
std::string getName() const override
TEST_CASE("complex_helper", "[type_traits]")
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
Collection of Local Energy Operators.
class to handle hdf file
Definition: hdf_archive.h:51
Class to accumulate the local energy and components.
std::vector< accumulator_type > scalars
scalars to be measured
void accumulate(const Walker_t &awalker, RealType wgt)
accumulation per walker
LocalEnergyEstimator * clone() override
clone the object
WalkerProperties::Indexes WP
Definition: ParticleSet.cpp:34
REQUIRE(std::filesystem::exists(filename))
void create(const std::vector< int > &agroup)
create grouped particles
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
void add2Record(RecordListType &record) override
add the local energy, variance and all the Hamiltonian components to the scalar record container ...
Indexes
an enum denoting index of physical properties
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void createWalkers(int numWalkers)
create numWalkers Walkers
iterator end()
return the last iterator, [begin(), end())
Declaration of a MCWalkerConfiguration.
Declaration of QMCHamiltonian.
iterator begin()
return the first iterator