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

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

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

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

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

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

◆ getQuregAmp()

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

Definition at line 487 of file qureg.cpp.

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

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

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

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

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