The Quantum Exact Simulation Toolkit v4.0.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 180 of file cache.cpp.

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

◆ createCachedQuregs()

void createCachedQuregs ( )

Definition at line 108 of file cache.cpp.

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

◆ destroyCachedFullStateDiagMatrs()

void destroyCachedFullStateDiagMatrs ( )

Definition at line 190 of file cache.cpp.

190 {
191
192 // must not be called twice
193 DEMAND( !matrices.empty() );
194
195 for (auto& [label, matrix]: matrices)
197
198 matrices.clear();
199}
void destroyFullStateDiagMatr(FullStateDiagMatr matrix)
Definition matrices.cpp:404

◆ destroyCachedQuregs()

void destroyCachedQuregs ( )

Definition at line 122 of file cache.cpp.

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

◆ getAltCachedDensmatrs()

quregCache getAltCachedDensmatrs ( )

Definition at line 166 of file cache.cpp.

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

◆ getAltCachedStatevecs()

quregCache getAltCachedStatevecs ( )

Definition at line 159 of file cache.cpp.

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

◆ getCachedDensmatrs()

quregCache getCachedDensmatrs ( )

Definition at line 151 of file cache.cpp.

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

◆ getCachedFullStateDiagMatrs()

matrixCache getCachedFullStateDiagMatrs ( )

Definition at line 201 of file cache.cpp.

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

◆ getCachedStatevecs()

quregCache getCachedStatevecs ( )

Definition at line 144 of file cache.cpp.

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

◆ getNumCachedQubits()

int getNumCachedQubits ( )

Definition at line 50 of file cache.cpp.

50 {
51 return NUM_QUBITS_IN_CACHE;
52}

◆ getRefDensmatr()

qmatrix getRefDensmatr ( )

Definition at line 218 of file cache.cpp.

218 {
219 return getZeroMatrix(getPow2(NUM_QUBITS_IN_CACHE));
220}
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18

◆ getRefStatevec()

qvector getRefStatevec ( )

Definition at line 215 of file cache.cpp.

215 {
216 return getZeroVector(getPow2(NUM_QUBITS_IN_CACHE));
217}

◆ getSupportedDeployments()

deployInfo getSupportedDeployments ( )

Definition at line 60 of file cache.cpp.

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