The Quantum Exact Simulation Toolkit v4.2.0
Loading...
Searching...
No Matches

Testing utilities which create Quregs across all available hardware deployments. More...

Typedefs

using deployInfo = std::vector<std::tuple<std::string,int,int,int>>
 
using matrixCache = std::unordered_map<std::string,FullStateDiagMatr>
 
using quregCache = std::unordered_map<std::string,Qureg>
 

Functions

void createCachedFullStateDiagMatrs ()
 
void createCachedQuregs ()
 
void destroyCachedFullStateDiagMatrs ()
 
void destroyCachedQuregs ()
 
quregCache getAltCachedDensmatrs ()
 
quregCache getAltCachedStatevecs ()
 
quregCache getCachedDensmatrs ()
 
matrixCache getCachedFullStateDiagMatrs ()
 
quregCache getCachedStatevecs ()
 
int getNumCachedQubits ()
 
qmatrix getRefDensmatr ()
 
qvector getRefStatevec ()
 
deployInfo getSupportedDeployments ()
 

Detailed Description

Testing utilities which create Quregs across all available hardware deployments.

Typedef Documentation

◆ deployInfo

using deployInfo = std::vector<std::tuple<std::string,int,int,int>>

Definition at line 27 of file cache.hpp.

◆ matrixCache

using matrixCache = std::unordered_map<std::string,FullStateDiagMatr>

Definition at line 26 of file cache.hpp.

◆ quregCache

using quregCache = std::unordered_map<std::string,Qureg>

Definition at line 25 of file cache.hpp.

Function Documentation

◆ createCachedFullStateDiagMatrs()

void createCachedFullStateDiagMatrs ( )

Definition at line 177 of file cache.cpp.

177 {
178
179 // must not be called twice
180 DEMAND( matrices.empty() );
181
182 // only add supported-deployment matrices to the cache
183 for (auto [label, mpi, gpu, omp] : getSupportedDeployments())
184 matrices[label] = createCustomFullStateDiagMatr(getNumCachedQubits(), mpi, gpu, omp);
185}
FullStateDiagMatr createCustomFullStateDiagMatr(int numQubits, int useDistrib, int useGpuAccel, int useMultithread)
Definition matrices.cpp:318

◆ createCachedQuregs()

void createCachedQuregs ( )

Definition at line 105 of file cache.cpp.

105 {
106
107 // must not be called twice nor pre-creation
108 DEMAND( statevecs1.empty() );
109 DEMAND( statevecs2.empty() );
110 DEMAND( densmatrs1.empty() );
111 DEMAND( densmatrs2.empty() );
112
113 statevecs1 = createCachedStatevecsOrDensmatrs(false);
114 statevecs2 = createCachedStatevecsOrDensmatrs(false);
115 densmatrs1 = createCachedStatevecsOrDensmatrs(true);
116 densmatrs2 = createCachedStatevecsOrDensmatrs(true);
117}

◆ destroyCachedFullStateDiagMatrs()

void destroyCachedFullStateDiagMatrs ( )

Definition at line 187 of file cache.cpp.

187 {
188
189 // must not be called twice
190 DEMAND( !matrices.empty() );
191
192 for (auto& [label, matrix]: matrices)
194
195 matrices.clear();
196}
void destroyFullStateDiagMatr(FullStateDiagMatr matrix)
Definition matrices.cpp:400

◆ destroyCachedQuregs()

void destroyCachedQuregs ( )

Definition at line 119 of file cache.cpp.

119 {
120
121 // must not be called twice nor pre-creation
122 DEMAND( ! statevecs1.empty() );
123 DEMAND( ! statevecs2.empty() );
124 DEMAND( ! densmatrs1.empty() );
125 DEMAND( ! densmatrs2.empty() );
126
127 auto caches = {
128 statevecs1, statevecs2,
129 densmatrs1, densmatrs2};
130
131 for (auto& cache : caches)
132 for (auto& [label, qureg]: cache)
133 destroyQureg(qureg);
134
135 statevecs1.clear();
136 statevecs2.clear();
137 densmatrs1.clear();
138 densmatrs2.clear();
139}
void destroyQureg(Qureg qureg)
Definition qureg.cpp:334

◆ getAltCachedDensmatrs()

quregCache getAltCachedDensmatrs ( )

Definition at line 163 of file cache.cpp.

163 {
164
165 // must not be called pre-creation nor post-destruction
166 DEMAND( !densmatrs2.empty() );
167
168 return densmatrs2;
169}

◆ getAltCachedStatevecs()

quregCache getAltCachedStatevecs ( )

Definition at line 156 of file cache.cpp.

156 {
157
158 // must not be called pre-creation nor post-destruction
159 DEMAND( !statevecs2.empty() );
160
161 return statevecs2;
162}

◆ getCachedDensmatrs()

quregCache getCachedDensmatrs ( )

Definition at line 148 of file cache.cpp.

148 {
149
150 // must not be called pre-creation nor post-destruction
151 DEMAND( !densmatrs1.empty() );
152
153 return densmatrs1;
154}

◆ getCachedFullStateDiagMatrs()

matrixCache getCachedFullStateDiagMatrs ( )

Definition at line 198 of file cache.cpp.

198 {
199
200 // must not be called pre-creation nor post-destruction
201 DEMAND( !matrices.empty() );
202
203 return matrices;
204}

◆ getCachedStatevecs()

quregCache getCachedStatevecs ( )

Definition at line 141 of file cache.cpp.

141 {
142
143 // must not be called pre-creation nor post-destruction
144 DEMAND( !statevecs1.empty() );
145
146 return statevecs1;
147}

◆ getNumCachedQubits()

int getNumCachedQubits ( )

Definition at line 40 of file cache.cpp.

40 {
41
42 // we are merely aliasing the below env-var fetching function
43 // to minimise a diff since pre-runtime controlling the tested
44 // Qureg sizes is experimental and not fully designed (we may
45 // eventually wish to specify different sizes for statevectors
46 // vs density matrices, or control integration test Qureg sizes
47 // also through environment variables, etc)
48 return getNumQubitsInUnitTestedQuregs();
49}

◆ getRefDensmatr()

qmatrix getRefDensmatr ( )

Definition at line 215 of file cache.cpp.

215 {
216 return getZeroMatrix(getPow2(getNumCachedQubits()));
217}
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18

◆ getRefStatevec()

qvector getRefStatevec ( )

Definition at line 212 of file cache.cpp.

212 {
213 return getZeroVector(getPow2(getNumCachedQubits()));
214}

◆ getSupportedDeployments()

deployInfo getSupportedDeployments ( )

Definition at line 57 of file cache.cpp.

57 {
58
59 deployInfo out;
60
61 // determine which Qureg deployments are supported
62 QuESTEnv env = getQuESTEnv();
63 bool omp = env.isMultithreaded;
64 bool mpi = env.isDistributed;
65 bool gpu = env.isGpuAccelerated;
66
67 // return only the "most-accelerated" deployment, unless all are desired
68 bool one = ! getWhetherToTestAllDeployments();
69
70 // add only those supported to the output list, in order of preference.
71 // flag order is (MPI, GPU, OMP), matching createCustomQureg
72 if (gpu && omp && mpi) { out.push_back({"GPU + OMP + MPI", 1, 1, 1}); if (one) return out; }
73 if (gpu && mpi) { out.push_back({"GPU + MPI", 1, 1, 0}); if (one) return out; }
74 if (gpu && omp) { out.push_back({"GPU + OMP", 0, 1, 1}); if (one) return out; }
75 if (gpu) { out.push_back({"GPU", 0, 1, 0}); if (one) return out; }
76 if (mpi && omp) { out.push_back({"CPU + OMP + MPI", 1, 0, 1}); if (one) return out; }
77 if (mpi) { out.push_back({"CPU + MPI", 1, 0, 0}); if (one) return out; }
78 if (omp) { out.push_back({"CPU + OMP", 0, 0, 1}); if (one) return out; }
79 if (true) { out.push_back({"CPU", 0, 0, 0}); if (one) return out; }
80
81 // always contains CPU obviously, but this makes it explicit
82 DEMAND( !out.empty() );
83
84 // return all supported deployments
85 return out;
86}
QuESTEnv getQuESTEnv()