-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathconfig.cpp
More file actions
76 lines (55 loc) · 1.64 KB
/
Copy pathconfig.cpp
File metadata and controls
76 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/** @file
* Testing utilities for loading environment variables
* which configure the unit tests, independent of QuEST's
* internal environment variable facilities
*
* @author Tyson Jones
*/
#include <string>
#include <cstdlib>
#include <stdexcept>
using std::string;
/*
* PRIVATE
*/
string getEnvVarValue(string name) {
// unspecified var returns empty string
const char* ptr = std::getenv(name.c_str());
return (ptr == nullptr)? "" : std::string(ptr);
}
int getIntEnvVarValueOrDefault(string name, int defaultValue) {
string strValue = getEnvVarValue(name);
int intValue = defaultValue;
// overwrite default only when passed variable is interpretable
try {
intValue = std::stoi(strValue);
}
catch (const std::out_of_range&) { }
catch (const std::invalid_argument&) { }
return intValue;
}
/*
* PUBLIC
*
* which each call std::getenv only once
*/
int getNumQubitsInUnitTestedQuregs() {
static int value = getIntEnvVarValueOrDefault("TEST_NUM_QUBITS_IN_QUREG", 6);
return value;
}
int getMaxNumTestedQubitPermutations() {
static int value = getIntEnvVarValueOrDefault("TEST_MAX_NUM_QUBIT_PERMUTATIONS", 0);
return value;
}
int getMaxNumTestedSuperoperatorTargets() {
static int value = getIntEnvVarValueOrDefault("TEST_MAX_NUM_SUPEROP_TARGETS", 4);
return value;
}
int getNumTestedMixedDeploymentRepetitions() {
static int value = getIntEnvVarValueOrDefault("TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS", 10);
return value;
}
bool getWhetherToTestAllDeployments() {
static bool value = getIntEnvVarValueOrDefault("TEST_ALL_DEPLOYMENTS", 1);
return value;
}