QMCPACK
test_walker.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 #include "catch.hpp"
14 
15 #include <cstring>
17 #include "Configuration.h"
23 
24 #include <stdio.h>
25 #include <string>
26 
27 using std::string;
28 
29 namespace qmcplusplus
30 {
33 
34 TEST_CASE("walker", "[particle]")
35 {
36  MCPWalker w(1);
37  REQUIRE(w.R.size() == 1);
38  w.R[0] = 1.0;
39 
40  CHECK(w.R[0][0] == Approx(1.0));
41 }
42 
43 /** Currently significant amounts of code assumes that the Walker by default
44  * has "Properties" ending with the LOCALPOTENTIAL element. This opens the door to off by 1
45  * when considering the default size.
46  */
47 TEST_CASE("walker assumptions", "[particle]")
48 {
50  MCPWalker w1(1);
51  REQUIRE(w1.Properties.cols() == WP::NUMPROPERTIES);
52 }
53 
54 TEST_CASE("walker HDF read and write", "[particle]")
55 {
57 
58  const size_t num_ptcls = 1;
59  MCPWalker w1(num_ptcls);
60  w1.R[0] = 1.0;
61 
62  MCPWalker w2(num_ptcls);
63  w2.R[0] = 0.5;
64 
65  // This method sets ownership to false so class does not attempt to
66  // free the walker elements.
67  WalkerConfigurations wc_list;
68  wc_list.createWalkers(2, num_ptcls);
69  wc_list[0]->R = w1.R;
70  wc_list[1]->R = w2.R;
71 
72  REQUIRE(wc_list.getActiveWalkers() == 2);
73 
74  std::vector<int> walker_offset(c->size() + 1);
75 
76  walker_offset[0] = 0;
77  int offset = 2;
78  for (int i = 0; i < c->size(); i++)
79  {
80  walker_offset[i + 1] = offset;
81  offset += 2;
82  }
83 
84  wc_list.setWalkerOffsets(walker_offset);
85 
86  c->setName("walker_test");
87  HDFWalkerOutput hout(num_ptcls, "this string apparently does nothing", c);
88  hout.dump(wc_list, 0);
89 
90  c->barrier();
91 
92  WalkerConfigurations wc_list2;
93 
94  HDFVersion version(0, 4);
95  HDFWalkerInput_0_4 hinp(wc_list2, num_ptcls, c, version);
96  bool okay = hinp.read_hdf5("walker_test.config.h5");
97  REQUIRE(okay);
98 
99  REQUIRE(wc_list2.getActiveWalkers() == 2);
100  for (int i = 0; i < 3; i++)
101  {
102  REQUIRE(wc_list2[0]->R[0][i] == w1.R[0][i]);
103  REQUIRE(wc_list2[1]->R[0][i] == w2.R[0][i]);
104  }
105 }
106 
107 TEST_CASE("walker buffer add, update, restore", "[particle]")
108 {
109  int num_particles = 4;
110 
112  auto createWalker = [num_particles](UPtr<MCPWalker>& walker_ptr) {
113  walker_ptr = std::make_unique<MCPWalker>(num_particles);
114  walker_ptr->registerData();
115  walker_ptr->DataSet.allocate();
116  };
117  std::for_each(walkers.begin(), walkers.end(), createWalker);
118 
119  walkers[0]->Properties(WP::LOGPSI) = 1.2;
120  walkers[0]->Properties(WP::SIGN) = 1.3;
121  walkers[0]->Properties(WP::UMBRELLAWEIGHT) = 1.4;
122  walkers[0]->Properties(WP::LOCALPOTENTIAL) = 1.6;
123  walkers[0]->updateBuffer();
124 
125  std::memcpy(walkers[1]->DataSet.data(), walkers[0]->DataSet.data(), walkers[0]->DataSet.size());
126  walkers[1]->copyFromBuffer();
127  CHECK(walkers[1]->Properties(WP::LOGPSI) == Approx(1.2));
128  CHECK(walkers[1]->Properties(WP::LOCALPOTENTIAL) == Approx(1.6));
129 }
130 
131 } // namespace qmcplusplus
bool dump(const WalkerConfigurations &w, int block)
dump configurations
PropertyContainer_t Properties
scalar properties of a walker
Definition: Walker.h:125
void barrier() const
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Declaration of a WalkerConfigurations.
size_t getActiveWalkers() const
return the number of active walkers
Writes a set of walker configurations to an HDF5 file.
A set of light weight walkers that are carried between driver sections and restart.
TEST_CASE("complex_helper", "[type_traits]")
void setWalkerOffsets(const std::vector< int > &o)
return the total number of active walkers among a MPI group
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
int size() const
return the number of tasks
Definition: Communicate.h:118
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))
void createWalkers(int numWalkers, size_t numPtcls)
create numWalkers Walkers
std::unique_ptr< T > UPtr
void setName(const std::string &aname)
Definition: Communicate.h:129
Indexes
an enum denoting index of physical properties
bool read_hdf5(const std::filesystem::path &h5name)
read walkers for small number of MPI tasks
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
A container class to represent a walker.
Definition: Walker.h:49
const char version[]
Definition: HDFVersion.h:30
ParticlePos R
The configuration vector (3N-dimensional vector to store the positions of all the particles for a sin...
Definition: Walker.h:114