The Quantum Exact Simulation Toolkit v4.3.0
Loading...
Searching...
No Matches
environment.cpp
1/** @file
2 * Unit tests of the environment module.
3 *
4 * @author Tyson Jones
5 *
6 * @defgroup unitenv Environment
7 * @ingroup unittests
8 */
9
10#include "quest.h"
11
12#include <catch2/catch_test_macros.hpp>
13#include <catch2/matchers/catch_matchers_string.hpp>
14
15#include "tests/utils/qvector.hpp"
16#include "tests/utils/qmatrix.hpp"
17#include "tests/utils/compare.hpp"
18#include "tests/utils/convert.hpp"
19#include "tests/utils/evolve.hpp"
20#include "tests/utils/linalg.hpp"
21#include "tests/utils/lists.hpp"
22#include "tests/utils/macros.hpp"
23#include "tests/utils/random.hpp"
24
25using Catch::Matchers::ContainsSubstring;
26
27
28
29/*
30 * UTILITIES
31 */
32
33#define TEST_CATEGORY \
34 LABEL_UNIT_TAG "[environment]"
35
36
37
38/**
39 * TESTS
40 *
41 * @ingroup unitenv
42 * @{
43 */
44
45
46TEST_CASE( "initQuESTEnv", TEST_CATEGORY ) {
47
48 SECTION( LABEL_CORRECTNESS ) {
49
50 // cannot be meaningfully tested since env already active
51 SUCCEED( );
52 }
53
54 SECTION( LABEL_VALIDATION ) {
55
56 REQUIRE_THROWS_WITH( initQuESTEnv(), ContainsSubstring( "already been initialised") );
57
58 // cannot automatically check other validations, such as:
59 // - has env been previously initialised then finalised?
60 // - is env distributed over power-of-2 nodes?
61 // - are environment-variables valid?
62 // - is max 1 MPI process bound to each GPU?
63 // - is GPU compatible with cuQuantum (if enabled)?
64 }
65}
66
67
68TEST_CASE( "initCustomQuESTEnv", TEST_CATEGORY ) {
69
70 SECTION( LABEL_CORRECTNESS ) {
71
72 // cannot be meaningfully tested since env already active
73 SUCCEED( );
74 }
75
76 SECTION( LABEL_VALIDATION ) {
77
78 REQUIRE_THROWS_WITH( initCustomQuESTEnv(0,0,0), ContainsSubstring( "already been initialised") );
79
80 // cannot check arguments since env-already-initialised
81 // validation is performed first
82 }
83}
84
85
86TEST_CASE( "initCustomMpiQuESTEnv", TEST_CATEGORY ) {
87
88 SECTION( LABEL_CORRECTNESS ) {
89
90 // cannot be meaningfully tested since env already active
91 SUCCEED( );
92 }
93
94 SECTION( LABEL_VALIDATION ) {
95
96 REQUIRE_THROWS_WITH( initCustomMpiQuESTEnv(0,0,0,0), ContainsSubstring( "already been initialised") );
97
98 // cannot check arguments since env-already-initialised
99 // validation is performed first
100 }
101}
102
103
104TEST_CASE( "finalizeQuESTEnv", TEST_CATEGORY ) {
105
106 SECTION( LABEL_CORRECTNESS ) {
107
108 // cannot be meaningfully tested since calling
109 // mid-tests will break subsequent testing
110 SUCCEED( );
111 }
112
113 SECTION( LABEL_VALIDATION ) {
114
115 // cannot be validated since calling it once
116 // is always valid but would break subsequent tests
117 SUCCEED( );
118 }
119}
120
121
122TEST_CASE( "syncQuESTEnv", TEST_CATEGORY ) {
123
124 SECTION( LABEL_CORRECTNESS ) {
125
126 // always legal to call
127 REQUIRE_NOTHROW( syncQuESTEnv() );
128 }
129
130 SECTION( LABEL_VALIDATION ) {
131
132 // cannot test validation (that env is already
133 // created) since we cannot call before initQuESTEnv
134 SUCCEED( );
135 }
136}
137
138
139TEST_CASE( "isQuESTEnvInit", TEST_CATEGORY ) {
140
141 SECTION( LABEL_CORRECTNESS ) {
142
143 // cannot test for other outcome
144 REQUIRE( isQuESTEnvInit() == 1 );
145 }
146
147 SECTION( LABEL_VALIDATION ) {
148
149 // performs no validation
150 SUCCEED( );
151 }
152}
153
154
155TEST_CASE( "getQuESTEnv", TEST_CATEGORY ) {
156
157 SECTION( LABEL_CORRECTNESS ) {
158
159 QuESTEnv env = getQuESTEnv();
160
161 REQUIRE( env.rank >= 0 );
162 REQUIRE( env.numNodes >= 0 );
163
164 if (!env.isDistributed) {
165 REQUIRE( env.rank == 0 );
166 REQUIRE( env.numNodes == 1 );
167 }
168
169 bool isNumNodesPow2 = ((env.numNodes & (env.numNodes - 1)) == 0);
170 REQUIRE( isNumNodesPow2 );
171 }
172
173 SECTION( LABEL_VALIDATION ) {
174
175 // performs no validation
176 SUCCEED( );
177 }
178}
179
180
181/** @} (end defgroup) */
182
183
184
185/**
186 * @todo
187 * UNTESTED FUNCTIONS
188 */
189
190void reportQuESTEnv();
void reportQuESTEnv()
void initCustomQuESTEnv(int useDistrib, int useGpuAccel, int useMultithread)
QuESTEnv getQuESTEnv()
int isQuESTEnvInit()
void syncQuESTEnv()
void initQuESTEnv()
void initCustomMpiQuESTEnv(int useDistrib, bool userOwnsMpi, int useGpuAccel, int useMultithread)
TEST_CASE("initQuESTEnv", TEST_CATEGORY)