The Quantum Exact Simulation Toolkit v4.3.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 ()
 
quregCache createCustomCachedQuregs (int numQubits, bool isDensityMatrix)
 
void destroyCachedFullStateDiagMatrs ()
 
void destroyCachedQuregs ()
 
void destroyCustomCachedQuregs (quregCache &cache)
 
quregCache getAltCachedDensmatrs ()
 
quregCache getAltCachedStatevecs ()
 
Qureg getArbitraryCachedDensmatr ()
 
Qureg getArbitraryCachedStatevec ()
 
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 198 of file cache.cpp.

198 {
199
200 // must not be called twice
201 DEMAND( matrices.empty() );
202
203 // only add supported-deployment matrices to the cache
204 for (auto [label, mpi, gpu, omp] : getSupportedDeployments())
205 matrices[label] = createCustomFullStateDiagMatr(getNumCachedQubits(), mpi, gpu, omp);
206}
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 int numQubits = getNumCachedQubits();
114 statevecs1 = createCustomCachedQuregs(numQubits, false);
115 statevecs2 = createCustomCachedQuregs(numQubits, false);
116 densmatrs1 = createCustomCachedQuregs(numQubits, true);
117 densmatrs2 = createCustomCachedQuregs(numQubits, true);
118}

◆ createCustomCachedQuregs()

quregCache createCustomCachedQuregs ( int numQubits,
bool isDensityMatrix )

Definition at line 94 of file cache.cpp.

94 {
95
96 quregCache out;
97
98 // only add supported-deployment quregs to the cache
99 for (auto [label, mpi, gpu, omp] : getSupportedDeployments())
100 out[label] = createCustomQureg(numQubits, isDensityMatrix, mpi, gpu, omp);
101
102 return out;
103}
Qureg createCustomQureg(int numQubits, int isDensMatr, int useDistrib, int useGpuAccel, int useMultithread)
Definition qureg.cpp:283

◆ destroyCachedFullStateDiagMatrs()

void destroyCachedFullStateDiagMatrs ( )

Definition at line 208 of file cache.cpp.

208 {
209
210 // must not be called twice
211 DEMAND( !matrices.empty() );
212
213 for (auto& [label, matrix]: matrices)
215
216 matrices.clear();
217}
void destroyFullStateDiagMatr(FullStateDiagMatr matrix)
Definition matrices.cpp:400

◆ destroyCachedQuregs()

void destroyCachedQuregs ( )

Definition at line 125 of file cache.cpp.

125 {
126
127 // must not be called twice nor pre-creation
128 DEMAND( ! statevecs1.empty() );
129 DEMAND( ! statevecs2.empty() );
130 DEMAND( ! densmatrs1.empty() );
131 DEMAND( ! densmatrs2.empty() );
132
133 std::vector<quregCache> caches = {
134 statevecs1, statevecs2,
135 densmatrs1, densmatrs2};
136
137 for (auto& cache : caches)
138 destroyCustomCachedQuregs(cache);
139
140 statevecs1.clear();
141 statevecs2.clear();
142 densmatrs1.clear();
143 densmatrs2.clear();
144}

◆ destroyCustomCachedQuregs()

void destroyCustomCachedQuregs ( quregCache & cache)

Definition at line 120 of file cache.cpp.

120 {
121 for (auto& [label, qureg]: cache)
122 destroyQureg(qureg);
123}
void destroyQureg(Qureg qureg)
Definition qureg.cpp:340

◆ getAltCachedDensmatrs()

quregCache getAltCachedDensmatrs ( )

Definition at line 168 of file cache.cpp.

168 {
169
170 // must not be called pre-creation nor post-destruction
171 DEMAND( !densmatrs2.empty() );
172
173 return densmatrs2;
174}

◆ getAltCachedStatevecs()

quregCache getAltCachedStatevecs ( )

Definition at line 161 of file cache.cpp.

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

◆ getArbitraryCachedDensmatr()

Qureg getArbitraryCachedDensmatr ( )

Definition at line 184 of file cache.cpp.

184 {
185
186 // must not be called pre-creation nor post-destruction
187 DEMAND( !densmatrs1.empty() );
188
189 return densmatrs1.begin()->second;
190}

◆ getArbitraryCachedStatevec()

Qureg getArbitraryCachedStatevec ( )

Definition at line 176 of file cache.cpp.

176 {
177
178 // must not be called pre-creation nor post-destruction
179 DEMAND( !statevecs1.empty() );
180
181 return statevecs1.begin()->second;
182}

◆ getCachedDensmatrs()

quregCache getCachedDensmatrs ( )

Definition at line 153 of file cache.cpp.

153 {
154
155 // must not be called pre-creation nor post-destruction
156 DEMAND( !densmatrs1.empty() );
157
158 return densmatrs1;
159}

◆ getCachedFullStateDiagMatrs()

matrixCache getCachedFullStateDiagMatrs ( )

Definition at line 219 of file cache.cpp.

219 {
220
221 // must not be called pre-creation nor post-destruction
222 DEMAND( !matrices.empty() );
223
224 return matrices;
225}

◆ getCachedStatevecs()

quregCache getCachedStatevecs ( )

Definition at line 146 of file cache.cpp.

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

◆ 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 236 of file cache.cpp.

236 {
237 return getZeroMatrix(getPow2(getNumCachedQubits()));
238}
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18

◆ getRefStatevec()

qvector getRefStatevec ( )

Definition at line 233 of file cache.cpp.

233 {
234 return getZeroVector(getPow2(getNumCachedQubits()));
235}

◆ 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()