QMCPACK
test_sample_stack.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: Mark Dewing, mdewing@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 
16 #include "Particle/MCSample.h"
17 #include "Particle/SampleStack.h"
18 
19 #include <stdio.h>
20 #include <string>
21 
22 using std::string;
23 
24 namespace qmcplusplus
25 {
26 TEST_CASE("SampleStack", "[particle]")
27 {
28  SampleStack samples;
29 
30  const int total_num = 2; // number of particles
31 
32  // reserve storage
33  int nranks = 2;
34  samples.setMaxSamples(8, nranks);
35  REQUIRE(samples.getMaxSamples() == 8);
36  REQUIRE(samples.getNumSamples() == 0);
37  REQUIRE(samples.getGlobalNumSamples() == 16);
38 
39  // increase storage
40  samples.setMaxSamples(10);
41  REQUIRE(samples.getMaxSamples() == 10);
42  REQUIRE(samples.getNumSamples() == 0);
43 
44  using Walker_t = ParticleSet::Walker_t;
45  using WalkerList_t = std::vector<std::unique_ptr<Walker_t>>;
46 
47  WalkerList_t walker_list;
48 
49  // Add size one list
50  walker_list.push_back(std::make_unique<Walker_t>(total_num));
51  walker_list[0]->R[0][0] = 1.1;
52  for (auto& wi : walker_list)
53  {
54  samples.appendSample(MCSample(*wi));
55  }
56  REQUIRE(samples.getNumSamples() == 1);
57 
58  Walker_t w1;
59  samples.getSample(0).convertToWalker(w1);
60  CHECK(w1.R[0][0] == Approx(1.1));
61 
62  // Should test that more members of the Walker are saved correctly
63 
64  samples.resetSampleCount();
65  REQUIRE(samples.getNumSamples() == 0);
66 
67  // clear storage
68  samples.clearEnsemble();
69  REQUIRE(samples.getNumSamples() == 0);
70 }
71 
72 
73 } // namespace qmcplusplus
Walker< QMCTraits, PtclOnLatticeTraits > Walker_t
walker type
Definition: ParticleSet.h:59
Stores particle configurations for later use in DMC and wavefunction optimization.
Stores particle configurations for later use in DMC and wavefunction optimization.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
size_t getMaxSamples() const
Definition: SampleStack.h:34
void resetSampleCount()
Set the sample count to zero but preserve the storage.
Definition: SampleStack.cpp:57
TEST_CASE("complex_helper", "[type_traits]")
size_t getNumSamples() const
Definition: SampleStack.h:41
void clearEnsemble()
clear the ensemble
Definition: SampleStack.cpp:51
store minimum Walker data
Definition: MCSample.h:28
REQUIRE(std::filesystem::exists(filename))
const MCSample & getSample(size_t i) const
Definition: SampleStack.cpp:31
void setMaxSamples(size_t n, size_t number_of_ranks=1)
set the number of max samples per rank.
Definition: SampleStack.cpp:23
void convertToWalker(Walker_t &w) const
Definition: MCSample.h:61
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
void appendSample(MCSample &&sample)
Definition: SampleStack.cpp:33
size_t getGlobalNumSamples() const
Global number of samples is number of samples per rank * number of ranks.
Definition: SampleStack.h:45