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