The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
Constructors

Functions for creating variable-size matrices. More...

Functions

CompMatr createCompMatr (int numQubits)
 
FullStateDiagMatr createCustomFullStateDiagMatr (int numQubits, int useDistrib, int useGpuAccel, int useMultithread)
 
DiagMatr createDiagMatr (int numQubits)
 
FullStateDiagMatr createFullStateDiagMatr (int numQubits)
 
FullStateDiagMatr createFullStateDiagMatrFromPauliStrSum (PauliStrSum in)
 
CompMatr createInlineCompMatr (int numQb, std::vector< std::vector< qcomp > > elems)
 
DiagMatr createInlineDiagMatr (int numQb, std::vector< qcomp > elems)
 

Detailed Description

Functions for creating variable-size matrices.

Function Documentation

◆ createCompMatr()

CompMatr createCompMatr ( int numQubits)
Note
Documentation for this function or struct is under construction!

Definition at line 211 of file matrices.cpp.

211 {
212 validate_envIsInit(__func__);
213 validate_newCompMatrParams(numQubits, __func__);
214
215 // validation ensures these never overflow
216 qindex numRows = powerOf2(numQubits);
217 qindex numElems = numRows * numRows;
218
219 qcomp* cpuMem = cpu_allocArray(numElems); // nullptr if failed
220 qcomp* gpuMem = nullptr;
221 if (getQuESTEnv().isGpuAccelerated)
222 gpuMem = gpu_allocArray(numElems); // nullptr if failed
223
224 // initialise all CompMatr fields inline because most are const
225 CompMatr out = {
226 .numQubits = numQubits,
227 .numRows = numRows,
228
229 // allocate flags in the heap so that struct copies are mutable
230 .isApproxUnitary = util_allocEpsilonSensitiveHeapFlag(), // nullptr if failed
231 .isApproxHermitian = util_allocEpsilonSensitiveHeapFlag(),
232
233 .wasGpuSynced = cpu_allocHeapFlag(), // nullptr if failed
234
235 .cpuElems = cpu_allocAndInitMatrixWrapper(cpuMem, numRows), // nullptr if failed
236 .cpuElemsFlat = cpuMem,
237 .gpuElemsFlat = gpuMem
238 };
239
240 validateMatrixAllocs(out, __func__);
241 setInitialHeapFlags(out);
242 return out;
243}
QuESTEnv getQuESTEnv()

Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().

◆ createCustomFullStateDiagMatr()

FullStateDiagMatr createCustomFullStateDiagMatr ( int numQubits,
int useDistrib,
int useGpuAccel,
int useMultithread )
Note
Documentation for this function or struct is under construction!

Definition at line 322 of file matrices.cpp.

322 {
323
324 return validateAndCreateCustomFullStateDiagMatr(numQubits, useDistrib, useGpuAccel, useMultithread, __func__);
325}

Referenced by TEST_CASE().

◆ createDiagMatr()

DiagMatr createDiagMatr ( int numQubits)
Note
Documentation for this function or struct is under construction!

Definition at line 246 of file matrices.cpp.

246 {
247 validate_envIsInit(__func__);
248 validate_newDiagMatrParams(numQubits, __func__);
249
250 // validation ensures this never overflows
251 qindex numElems = powerOf2(numQubits);
252
253 // initialise all CompMatr fields inline because most are const
254 DiagMatr out = {
255 .numQubits = numQubits,
256 .numElems = numElems,
257
258 // allocate flags in the heap so that struct copies are mutable
259 .isApproxUnitary = util_allocEpsilonSensitiveHeapFlag(), // nullptr if failed
260 .isApproxHermitian = util_allocEpsilonSensitiveHeapFlag(),
261 .isApproxNonZero = util_allocEpsilonSensitiveHeapFlag(),
262 .isStrictlyNonNegative = cpu_allocHeapFlag(), // nullptr if failed
263 .wasGpuSynced = cpu_allocHeapFlag(),
264
265 // 1D CPU memory
266 .cpuElems = cpu_allocArray(numElems), // nullptr if failed
267
268 // 1D GPU memory
269 .gpuElems = (getQuESTEnv().isGpuAccelerated)? gpu_allocArray(numElems) : nullptr // nullptr if failed or not needed
270 };
271
272 validateMatrixAllocs(out, __func__);
273 setInitialHeapFlags(out);
274 return out;
275}

Referenced by TEST_CASE(), and TEST_CASE().

◆ createFullStateDiagMatr()

FullStateDiagMatr createFullStateDiagMatr ( int numQubits)
Note
Documentation for this function or struct is under construction!

Definition at line 327 of file matrices.cpp.

327 {
328
329 return validateAndCreateCustomFullStateDiagMatr(numQubits, modeflag::USE_AUTO, modeflag::USE_AUTO, modeflag::USE_AUTO, __func__);
330}

Referenced by createFullStateDiagMatrFromPauliStrSum(), and TEST_CASE().

◆ createFullStateDiagMatrFromPauliStrSum()

FullStateDiagMatr createFullStateDiagMatrFromPauliStrSum ( PauliStrSum in)
Note
Documentation for this function or struct is under construction!
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!

Definition at line 658 of file matrices.cpp.

658 {
659 validate_pauliStrSumFields(in, __func__);
660
661 // ensure createFullStateDiagMatr() below succeeds (so if not, that thrower name is correct)
662 int numQubits = 1 + paulis_getIndOfLefmostNonIdentityPauli(in);
663 validate_newFullStateDiagMatrParams(numQubits, modeflag::USE_AUTO, modeflag::USE_AUTO, modeflag::USE_AUTO, __func__);
664
665 // permit 'in' to be non-Hermitian since it does not determine 'out' unitarity
666
668 localiser_fullstatediagmatr_setElemsToPauliStrSum(out, in);
669 markMatrixAsSynced(out);
670 return out;
671}
FullStateDiagMatr createFullStateDiagMatr(int numQubits)
Definition matrices.cpp:327

◆ createInlineCompMatr()

CompMatr createInlineCompMatr ( int numQb,
std::vector< std::vector< qcomp > > elems )
Note
Documentation for this function or struct is under construction!

◆ createInlineDiagMatr()

DiagMatr createInlineDiagMatr ( int numQb,
std::vector< qcomp > elems )
Note
Documentation for this function or struct is under construction!