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

Functions for obtaining amplitudes from statevectors or density matrices. More...

Functions

qcomp getDensityQuregAmp (Qureg qureg, qindex row, qindex column)
 
void getDensityQuregAmps (qcomp **outAmps, Qureg qureg, qindex startRow, qindex startCol, qindex numRows, qindex numCols)
 
std::vector< std::vector< qcomp > > getDensityQuregAmps (Qureg qureg, qindex startRow, qindex startCol, qindex numRows, qindex numCols)
 
qcomp getQuregAmp (Qureg qureg, qindex index)
 
void getQuregAmps (qcomp *outAmps, Qureg qureg, qindex startInd, qindex numAmps)
 
std::vector< qcomp > getQuregAmps (Qureg qureg, qindex startInd, qindex numAmps)
 

Detailed Description

Functions for obtaining amplitudes from statevectors or density matrices.

Function Documentation

◆ getDensityQuregAmp()

qcomp getDensityQuregAmp ( Qureg qureg,
qindex row,
qindex column )
Note
Documentation for this function or struct is under construction!

Definition at line 497 of file qureg.cpp.

497 {
498 validate_quregFields(qureg, __func__);
499 validate_quregIsDensityMatrix(qureg, __func__);
500 validate_basisStateRowCol(qureg, row, column, __func__);
501
502 qindex ind = util_getGlobalFlatIndex(qureg, row, column);
503 qcomp amp = localiser_statevec_getAmp(qureg, ind);
504 return amp;
505}

Referenced by TEST_CASE().

◆ getDensityQuregAmps() [1/2]

void getDensityQuregAmps ( qcomp ** outAmps,
Qureg qureg,
qindex startRow,
qindex startCol,
qindex numRows,
qindex numCols )
Note
Documentation for this function or struct is under construction!

Definition at line 457 of file qureg.cpp.

457 {
458 validate_quregFields(qureg, __func__);
459 validate_quregIsDensityMatrix(qureg, __func__);
460 validate_basisStateRowCols(qureg, startRow, startCol, numRows, numCols, __func__);
461
462 localiser_densmatr_getAmps(outAmps, qureg, startRow, startCol, numRows, numCols);
463}

Referenced by getDensityQuregAmps(), and TEST_CASE().

◆ getDensityQuregAmps() [2/2]

std::vector< std::vector< qcomp > > getDensityQuregAmps ( Qureg qureg,
qindex startRow,
qindex startCol,
qindex numRows,
qindex numCols )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 531 of file qureg.cpp.

531 {
532
533 // allocate the output matrix, and validate successful
534 vector<vector<qcomp>> out;
535 qindex numElems = numRows * numCols; // never overflows (else Qureg alloc would fail)
536 auto callback1 = [&]() { validate_tempAllocSucceeded(false, numElems, sizeof(qcomp), __func__); };
537 util_tryAllocMatrix(out, numRows, numCols, callback1);
538
539 // we must pass nested pointers to core C function, requiring another temp array, also validated
540 vector<qcomp*> ptrs;
541 auto callback2 = [&]() { validate_tempAllocSucceeded(false, numRows, sizeof(qcomp*), __func__); };
542 util_tryAllocVector(ptrs, numRows, callback2);
543
544 // embed out pointers
545 for (qindex i=0; i<numRows; i++)
546 ptrs[i] = out[i].data();
547
548 // modify out through its ptrs
549 getDensityQuregAmps(ptrs.data(), qureg, startRow, startCol, numRows, numCols);
550 return out;
551}
void getDensityQuregAmps(qcomp **outAmps, Qureg qureg, qindex startRow, qindex startCol, qindex numRows, qindex numCols)
Definition qureg.cpp:457

◆ getQuregAmp()

qcomp getQuregAmp ( Qureg qureg,
qindex index )
Note
Documentation for this function or struct is under construction!

Definition at line 484 of file qureg.cpp.

484 {
485 validate_quregFields(qureg, __func__);
486 validate_quregIsStateVector(qureg, __func__);
487 validate_basisStateIndex(qureg, index, __func__);
488
489 return localiser_statevec_getAmp(qureg, index);
490}

Referenced by TEST_CASE().

◆ getQuregAmps() [1/2]

void getQuregAmps ( qcomp * outAmps,
Qureg qureg,
qindex startInd,
qindex numAmps )
Note
Documentation for this function or struct is under construction!

Definition at line 448 of file qureg.cpp.

448 {
449 validate_quregFields(qureg, __func__);
450 validate_quregIsStateVector(qureg, __func__);
451 validate_basisStateIndices(qureg, startInd, numAmps, __func__);
452
453 localiser_statevec_getAmps(outAmps, qureg, startInd, numAmps);
454}

Referenced by getQuregAmps(), and TEST_CASE().

◆ getQuregAmps() [2/2]

std::vector< qcomp > getQuregAmps ( Qureg qureg,
qindex startInd,
qindex numAmps )
Warning
This function has not yet been unit tested and may contain bugs. Please use with caution!
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
Note
Documentation for this function or struct is under construction!
Remarks
This function is only available in C++.

Definition at line 518 of file qureg.cpp.

518 {
519
520 // allocate the output vector, and validate successful
521 vector<qcomp> out;
522 auto callback = [&]() { validate_tempAllocSucceeded(false, numAmps, sizeof(qcomp), __func__); };
523 util_tryAllocVector(out, numAmps, callback);
524
525 // performs main validation
526 getQuregAmps(out.data(), qureg, startInd, numAmps);
527 return out;
528}
void getQuregAmps(qcomp *outAmps, Qureg qureg, qindex startInd, qindex numAmps)
Definition qureg.cpp:448