QMCPACK
test_trace_manager.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) 2018 Jeongnim Kim and 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 "Message/Communicate.h"
17 #include "OhmmsData/Libxml2Doc.h"
18 // Hack to convert aborts into test failures.
19 // Works because all abort calls are in the .h file.
20 #undef APP_ABORT
21 #define APP_ABORT(msg) FAIL(msg)
23 
24 
25 #include <stdio.h>
26 #include <sstream>
27 
28 namespace qmcplusplus
29 {
30 // See QMCHamiltonian.cpp::initialize_traces for the usage sequence
31 
32 TEST_CASE("TraceManager", "[estimators]")
33 {
35 
36  TraceManager tm(c);
37 
38  tm.put(NULL, true, "test");
39 
40  TraceRequest req1;
41  req1.contribute_scalar("scalar1", true);
42  req1.streaming_scalar("scalar1");
43 
44  tm.request.incorporate(req1);
45 
47 
48  auto int_sample = std::unique_ptr<Array<TraceInt, 1>>{tm.checkout_int<1>("scalar1")};
49  (*int_sample)(0) = 2;
50 
51  tm.update_status();
52 }
53 
54 // Moved here from TraceManager.cpp, check_trace_build
55 TEST_CASE("TraceManager check_trace_build", "[estimators]")
56 {
57  std::string domain = "domain";
58  std::string name = "name";
59  std::string name1 = "name_1";
60  std::string name2 = "name_2";
61  std::string name3 = "name_3";
62  std::string name4 = "name_4";
63  int index = 0;
64  int dim = 3;
65  std::string label = "label";
66  Vector<int> vi;
67  Vector<double> vr;
69  // Shape checking code requires size > 0
70  TinyVector<int, 4> shape1 = {1, 0, 0, 0};
71  TinyVector<int, 4> shape2 = {1, 1, 0, 0};
72  TinyVector<int, 4> shape3 = {1, 1, 1, 0};
73  TinyVector<int, 4> shape4 = {1, 1, 1, 1};
74  const SimulationCell simulation_cell;
75  ParticleSet P(simulation_cell);
76  P.create({1}); // zero-sized particle set not handled well by TraceManager
77  TraceSample<int> tsi(domain, name, index, dim, vi);
78  TraceSample<double> tsr(domain, name, index, dim, vr);
79  TraceSample<std::complex<double>> tsc(domain, name, index, dim, vc);
80  TraceSamples<int> tssi;
83  TraceBuffer<int> tbi;
85 
86  auto ai1 = std::unique_ptr<Array<int, 1>>{tssi.checkout_array<1>(domain, name1, shape1)};
87  ai1.reset(tssi.checkout_array<1>(P, name, shape1));
88  auto ai2 = std::unique_ptr<Array<int, 2>>{tssi.checkout_array<2>(domain, name2, shape2)};
89  ai2.reset(tssi.checkout_array<2>(P, name2, shape2));
90  auto ai3 = std::unique_ptr<Array<int, 3>>{tssi.checkout_array<3>(domain, name3, shape3)};
91  ai3.reset(tssi.checkout_array<3>(P, name3, shape3));
92  auto ai4 = std::unique_ptr<Array<int, 4>>{tssi.checkout_array<4>(domain, name4, shape4)};
93  ai4.reset(tssi.checkout_array<4>(P, name4, shape4));
94 
95  auto ar1 = std::unique_ptr<Array<TraceReal, 1>>{tssr.checkout_array<1>(domain, name1, shape1)};
96  ar1.reset(tssr.checkout_array<1>(P, name1, shape1));
97  auto ar2 = std::unique_ptr<Array<TraceReal, 2>>{tssr.checkout_array<2>(domain, name2, shape2)};
98  ar2.reset(tssr.checkout_array<2>(P, name2, shape2));
99  auto ar3 = std::unique_ptr<Array<TraceReal, 3>>{tssr.checkout_array<3>(domain, name3, shape3)};
100  ar3.reset(tssr.checkout_array<3>(P, name3, shape3));
101  auto ar4 = std::unique_ptr<Array<TraceReal, 4>>{tssr.checkout_array<4>(domain, name4, shape4)};
102  ar4.reset(tssr.checkout_array<4>(P, name4, shape4));
103 
104  auto ac1 = std::unique_ptr<Array<TraceComp, 1>>{tssc.checkout_array<1>(domain, name1, shape1)};
105  ac1.reset(tssc.checkout_array<1>(P, name1, shape1));
106  auto ac2 = std::unique_ptr<Array<TraceComp, 2>>{tssc.checkout_array<2>(domain, name2, shape2)};
107  ac2.reset(tssc.checkout_array<2>(P, name2, shape2));
108  auto ac3 = std::unique_ptr<Array<TraceComp, 3>>{tssc.checkout_array<3>(domain, name3, shape3)};
109  ac3.reset(tssc.checkout_array<3>(P, name3, shape3));
110  auto ac4 = std::unique_ptr<Array<TraceComp, 4>>{tssc.checkout_array<4>(domain, name4, shape4)};
111  ac4.reset(tssc.checkout_array<4>(P, name4, shape4));
112 
113  TraceManager tm;
114  auto al1 = std::unique_ptr<Array<long, 1>>{tm.checkout_int<1>(name1)};
115  al1.reset(tm.checkout_int<1>(domain, name1, 10));
116  al1.reset(tm.checkout_int<1>(name1, P));
117  auto al2 = std::unique_ptr<Array<long, 2>>{tm.checkout_int<2>(name2, 5, 6)};
118  al2.reset(tm.checkout_int<2>(domain, name2, 10, 11));
119  al2.reset(tm.checkout_int<2>(name2, P, 11));
120  auto al3 = std::unique_ptr<Array<long, 3>>{tm.checkout_int<3>(name3, 5, 6, 7)};
121  al3.reset(tm.checkout_int<3>(domain, name3, 10, 11, 12));
122  al3.reset(tm.checkout_int<3>(name3, P, 11, 12));
123  auto al4 = std::unique_ptr<Array<long, 4>>{tm.checkout_int<4>(name4, 5, 6, 7, 8)};
124  al4.reset(tm.checkout_int<4>(domain, name4, 10, 11, 12, 13));
125  al4.reset(tm.checkout_int<4>(name4, P, 11, 12, 13));
126  ar1.reset(tm.checkout_real<1>(name1));
127  ar1.reset(tm.checkout_real<1>(domain, name1, 10));
128  ar1.reset(tm.checkout_real<1>(name1, P));
129  ar2.reset(tm.checkout_real<2>(name2, 5, 6));
130  ar2.reset(tm.checkout_real<2>(domain, name2, 10, 11));
131  ar2.reset(tm.checkout_real<2>(name2, P, 11));
132  ar3.reset(tm.checkout_real<3>(name3, 5, 6, 7));
133  ar3.reset(tm.checkout_real<3>(domain, name3, 10, 11, 12));
134  ar3.reset(tm.checkout_real<3>(name3, P, 11, 12));
135  ar4.reset(tm.checkout_real<4>(name4, 5, 6, 7, 8));
136  ar4.reset(tm.checkout_real<4>(domain, name4, 10, 11, 12, 13));
137  ar4.reset(tm.checkout_real<4>(name4, P, 11, 12, 13));
138 
139  ac1.reset(tm.checkout_complex<1>(name1));
140  ac1.reset(tm.checkout_complex<1>(domain, name1, 10));
141  ac1.reset(tm.checkout_complex<1>(name1, P));
142  ac2.reset(tm.checkout_complex<2>(name2, 5, 6));
143  ac2.reset(tm.checkout_complex<2>(domain, name2, 10, 11));
144  ac2.reset(tm.checkout_complex<2>(name2, P, 11));
145  ac3.reset(tm.checkout_complex<3>(name3, 5, 6, 7));
146  ac3.reset(tm.checkout_complex<3>(domain, name3, 10, 11, 12));
147  ac3.reset(tm.checkout_complex<3>(name3, P, 11, 12));
148  ac4.reset(tm.checkout_complex<4>(name4, 5, 6, 7, 8));
149  ac4.reset(tm.checkout_complex<4>(domain, name4, 10, 11, 12, 13));
150  ac4.reset(tm.checkout_complex<4>(name4, P, 11, 12, 13));
151 }
152 
153 } // namespace qmcplusplus
void put(xmlNodePtr cur, bool allow_traces, std::string series_root)
Array< TraceComp, D > * checkout_complex(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
bool streaming_scalar(const std::string &name)
Definition: TraceManager.h:242
Array< TraceInt, D > * checkout_int(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
Wrapping information on parallelism.
Definition: Communicate.h:68
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
void contribute_scalar(const std::string &name, bool default_quantity=false)
Definition: TraceManager.h:189
void incorporate(TraceRequest &other)
Definition: TraceManager.h:282
Array< TraceReal, D > * checkout_real(const std::string &name, int n1=1, int n2=0, int n3=0, int n4=0)
void create(const std::vector< int > &agroup)
create grouped particles
Array< T, D > * checkout_array(const std::string &domain, const std::string &name, TinyVector< int, DMAX > shape)
Definition: TraceManager.h:784