The Quantum Exact Simulation Toolkit v4.2.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 501 of file qureg.cpp.

501 {
502 validate_quregFields(qureg, __func__);
503 validate_quregIsDensityMatrix(qureg, __func__);
504 validate_basisStateRowCol(qureg, row, column, __func__);
505
506 qindex ind = util_getGlobalFlatIndex(qureg, row, column);
507 qcomp amp = localiser_statevec_getAmp(qureg, ind);
508 return amp;
509}

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 461 of file qureg.cpp.

461 {
462 validate_quregFields(qureg, __func__);
463 validate_quregIsDensityMatrix(qureg, __func__);
464 validate_basisStateRowCols(qureg, startRow, startCol, numRows, numCols, __func__);
465
466 localiser_densmatr_getAmps(outAmps, qureg, startRow, startCol, numRows, numCols);
467}

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++.
See also
getDensityQuregAmps()

Definition at line 535 of file qureg.cpp.

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

◆ getQuregAmp()

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

Definition at line 488 of file qureg.cpp.

488 {
489 validate_quregFields(qureg, __func__);
490 validate_quregIsStateVector(qureg, __func__);
491 validate_basisStateIndex(qureg, index, __func__);
492
493 return localiser_statevec_getAmp(qureg, index);
494}

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 452 of file qureg.cpp.

452 {
453 validate_quregFields(qureg, __func__);
454 validate_quregIsStateVector(qureg, __func__);
455 validate_basisStateIndices(qureg, startInd, numAmps, __func__);
456
457 localiser_statevec_getAmps(outAmps, qureg, startInd, numAmps);
458}

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++.
See also
getQuregAmps()

Definition at line 522 of file qureg.cpp.

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