The Quantum Exact Simulation Toolkit v4.2.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( "finalizeQuESTEnv", TEST_CATEGORY ) {
87
88 SECTION( LABEL_CORRECTNESS ) {
89
90 // cannot be meaningfully tested since calling
91 // mid-tests will break subsequent testing
92 SUCCEED( );
93 }
94
95 SECTION( LABEL_VALIDATION ) {
96
97 // cannot be validated since calling it once
98 // is always valid but would break subsequent tests
99 SUCCEED( );
100 }
101}
102
103
104TEST_CASE( "syncQuESTEnv", TEST_CATEGORY ) {
105
106 SECTION( LABEL_CORRECTNESS ) {
107
108 // always legal to call
109 REQUIRE_NOTHROW( syncQuESTEnv() );
110 }
111
112 SECTION( LABEL_VALIDATION ) {
113
114 // cannot test validation (that env is already
115 // created) since we cannot call before initQuESTEnv
116 SUCCEED( );
117 }
118}
119
120
121TEST_CASE( "isQuESTEnvInit", TEST_CATEGORY ) {
122
123 SECTION( LABEL_CORRECTNESS ) {
124
125 // cannot test for other outcome
126 REQUIRE( isQuESTEnvInit() == 1 );
127 }
128
129 SECTION( LABEL_VALIDATION ) {
130
131 // performs no validation
132 SUCCEED( );
133 }
134}
135
136
137TEST_CASE( "getQuESTEnv", TEST_CATEGORY ) {
138
139 SECTION( LABEL_CORRECTNESS ) {
140
141 QuESTEnv env = getQuESTEnv();
142
143 REQUIRE( (env.isMultithreaded == 0 || env.isMultithreaded == 1) );
144 REQUIRE( (env.isGpuAccelerated == 0 || env.isGpuAccelerated == 1) );
145 REQUIRE( (env.isDistributed == 0 || env.isDistributed == 1) );
146 REQUIRE( (env.isCuQuantumEnabled == 0 || env.isCuQuantumEnabled == 1) );
147 REQUIRE( (env.isGpuSharingEnabled == 0 || env.isGpuSharingEnabled == 1) );
148
149 REQUIRE( env.rank >= 0 );
150 REQUIRE( env.numNodes >= 0 );
151
152 if (!env.isDistributed) {
153 REQUIRE( env.rank == 0 );
154 REQUIRE( env.numNodes == 1 );
155 }
156
157 bool isNumNodesPow2 = ((env.numNodes & (env.numNodes - 1)) == 0);
158 REQUIRE( isNumNodesPow2 );
159 }
160
161 SECTION( LABEL_VALIDATION ) {
162
163 // performs no validation
164 SUCCEED( );
165 }
166}
167
168
169/** @} (end defgroup) */
170
171
172
173/**
174 * @todo
175 * UNTESTED FUNCTIONS
176 */
177
178void reportQuESTEnv();
void reportQuESTEnv()
void initCustomQuESTEnv(int useDistrib, int useGpuAccel, int useMultithread)
QuESTEnv getQuESTEnv()
int isQuESTEnvInit()
void syncQuESTEnv()
void initQuESTEnv()
TEST_CASE("initQuESTEnv", TEST_CATEGORY)