Unit tests of the QuEST API, using Catch2 in C++14.
More...
|
| TEST_CASE ("applyDiagonalOp", "[operators]") |
|
| TEST_CASE ("applyMatrix2", "[operators]") |
|
| TEST_CASE ("applyMatrix4", "[operators]") |
|
| TEST_CASE ("applyMatrixN", "[operators]") |
|
| TEST_CASE ("applyMultiControlledMatrixN", "[operators]") |
|
| TEST_CASE ("applyPauliHamil", "[operators]") |
|
| TEST_CASE ("applyPauliSum", "[operators]") |
|
| TEST_CASE ("applyTrotterCircuit", "[operators]") |
|
| TEST_CASE ("calcDensityInnerProduct", "[calculations]") |
|
| TEST_CASE ("calcExpecDiagonalOp", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliHamil", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliProd", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliSum", "[calculations]") |
|
| TEST_CASE ("calcFidelity", "[calculations]") |
|
| TEST_CASE ("calcHilbertSchmidtDistance", "[calculations]") |
|
| TEST_CASE ("calcInnerProduct", "[calculations]") |
|
| TEST_CASE ("calcProbOfOutcome", "[calculations]") |
|
| TEST_CASE ("calcPurity", "[calculations]") |
|
| TEST_CASE ("calcTotalProb", "[calculations]") |
|
| TEST_CASE ("cloneQureg", "[state_initialisations]") |
|
| TEST_CASE ("collapseToOutcome", "[gates]") |
|
| TEST_CASE ("compactUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledCompactUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledMultiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledNot", "[unitaries]") |
|
| TEST_CASE ("controlledPauliY", "[unitaries]") |
|
| TEST_CASE ("controlledPhaseFlip", "[unitaries]") |
|
| TEST_CASE ("controlledPhaseShift", "[unitaries]") |
|
| TEST_CASE ("controlledRotateAroundAxis", "[unitaries]") |
|
| TEST_CASE ("controlledRotateX", "[unitaries]") |
|
| TEST_CASE ("controlledRotateY", "[unitaries]") |
|
| TEST_CASE ("controlledRotateZ", "[unitaries]") |
|
| TEST_CASE ("controlledTwoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledUnitary", "[unitaries]") |
|
| TEST_CASE ("createCloneQureg", "[data_structures]") |
|
| TEST_CASE ("createComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("createDensityQureg", "[data_structures]") |
|
| TEST_CASE ("createDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("createPauliHamil", "[data_structures]") |
|
| TEST_CASE ("createPauliHamilFromFile", "[data_structures]") |
|
| TEST_CASE ("createQuESTEnv", "[data_structures]") |
|
| TEST_CASE ("createQureg", "[data_structures]") |
|
| TEST_CASE ("destroyComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("destroyDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("destroyPauliHamil", "[data_structures]") |
|
| TEST_CASE ("destroyQuESTEnv", "[data_structures]") |
|
| TEST_CASE ("destroyQureg", "[data_structures]") |
|
| TEST_CASE ("fromComplex", "[data_structures]") |
|
| TEST_CASE ("getAmp", "[calculations]") |
|
| TEST_CASE ("getDensityAmp", "[calculations]") |
|
| TEST_CASE ("getImagAmp", "[calculations]") |
|
| TEST_CASE ("getNumAmps", "[calculations]") |
|
| TEST_CASE ("getNumQubits", "[calculations]") |
|
| TEST_CASE ("getProbAmp", "[calculations]") |
|
| TEST_CASE ("getRealAmp", "[calculations]") |
|
| TEST_CASE ("getStaticComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("hadamard", "[unitaries]") |
|
| TEST_CASE ("initBlankState", "[state_initialisations]") |
|
| TEST_CASE ("initClassicalState", "[state_initialisations]") |
|
| TEST_CASE ("initComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("initDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("initPauliHamil", "[data_structures]") |
|
| TEST_CASE ("initPlusState", "[state_initialisations]") |
|
| TEST_CASE ("initPureState", "[state_initialisations]") |
|
| TEST_CASE ("initStateFromAmps", "[state_initialisations]") |
|
| TEST_CASE ("initZeroState", "[state_initialisations]") |
|
| TEST_CASE ("measure", "[gates]") |
|
| TEST_CASE ("measureWithStats", "[gates]") |
|
| TEST_CASE ("mixDamping", "[decoherence]") |
|
| TEST_CASE ("mixDensityMatrix", "[decoherence]") |
|
| TEST_CASE ("mixDephasing", "[decoherence]") |
|
| TEST_CASE ("mixDepolarising", "[decoherence]") |
|
| TEST_CASE ("mixKrausMap", "[decoherence]") |
|
| TEST_CASE ("mixMultiQubitKrausMap", "[decoherence]") |
|
| TEST_CASE ("mixPauli", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitDephasing", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitDepolarising", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitKrausMap", "[decoherence]") |
|
| TEST_CASE ("multiControlledMultiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiControlledPhaseFlip", "[unitaries]") |
|
| TEST_CASE ("multiControlledPhaseShift", "[unitaries]") |
|
| TEST_CASE ("multiControlledTwoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiControlledUnitary", "[unitaries]") |
|
| TEST_CASE ("multiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiRotatePauli", "[unitaries]") |
|
| TEST_CASE ("multiRotateZ", "[unitaries]") |
|
| TEST_CASE ("multiStateControlledUnitary", "[unitaries]") |
|
| TEST_CASE ("pauliX", "[unitaries]") |
|
| TEST_CASE ("pauliY", "[unitaries]") |
|
| TEST_CASE ("pauliZ", "[unitaries]") |
|
| TEST_CASE ("phaseShift", "[unitaries]") |
|
| TEST_CASE ("rotateAroundAxis", "[unitaries]") |
|
| TEST_CASE ("rotateX", "[unitaries]") |
|
| TEST_CASE ("rotateY", "[unitaries]") |
|
| TEST_CASE ("rotateZ", "[unitaries]") |
|
| TEST_CASE ("setAmps", "[state_initialisations]") |
|
| TEST_CASE ("setDiagonalOpElems", "[data_structures]") |
|
| TEST_CASE ("setWeightedQureg", "[state_initialisations]") |
|
| TEST_CASE ("sGate", "[unitaries]") |
|
| TEST_CASE ("sqrtSwapGate", "[unitaries]") |
|
| TEST_CASE ("swapGate", "[unitaries]") |
|
| TEST_CASE ("syncDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("tGate", "[unitaries]") |
|
| TEST_CASE ("toComplex", "[data_structures]") |
|
| TEST_CASE ("twoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("unitary", "[unitaries]") |
|
Unit tests of the QuEST API, using Catch2 in C++14.
◆ TEST_CASE() [1/106]
TEST_CASE |
( |
"applyDiagonalOp" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyDiagonalOp
- Author
- Tyson Jones
Definition at line 32 of file test_operators.cpp.
36 SECTION(
"correctness" ) {
39 GENERATE( range(0,10) );
49 SECTION(
"state-vector" ) {
55 SECTION(
"density-matrix" ) {
59 REQUIRE(
areEqual(quregMatr, ref, 100*REAL_EPS) );
64 SECTION(
"input validation" ) {
66 SECTION(
"mismatching size" ) {
70 REQUIRE_THROWS_WITH(
applyDiagonalOp(quregVec, op), Contains(
"equal number of qubits"));
71 REQUIRE_THROWS_WITH(
applyDiagonalOp(quregMatr, op), Contains(
"equal number of qubits"));
References applyDiagonalOp(), areEqual(), CLEANUP_TEST, createDiagonalOp(), destroyDiagonalOp(), getRandomReal(), DiagonalOp::imag, NUM_QUBITS, DiagonalOp::numElemsPerChunk, PREPARE_TEST, QUEST_ENV, DiagonalOp::real, syncDiagonalOp(), and toQMatrix().
◆ TEST_CASE() [2/106]
TEST_CASE |
( |
"applyMatrix2" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrix2
- Author
- Tyson Jones
Definition at line 85 of file test_operators.cpp.
93 SECTION(
"correctness" ) {
100 int targs[] = {target};
103 SECTION(
"state-vector" ) {
108 REQUIRE(
areEqual(quregVec, refVec) );
110 SECTION(
"density-matrix" ) {
115 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
118 SECTION(
"input validation" ) {
120 SECTION(
"qubit indices" ) {
123 REQUIRE_THROWS_WITH(
applyMatrix2(quregVec, target, matr), Contains(
"Invalid target") );
References applyMatrix2(), applyReferenceMatrix(), areEqual(), CLEANUP_TEST, getRandomQMatrix(), NUM_QUBITS, PREPARE_TEST, and toComplexMatrix2().
◆ TEST_CASE() [3/106]
TEST_CASE |
( |
"applyMatrix4" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrix4
- Author
- Tyson Jones
Definition at line 135 of file test_operators.cpp.
140 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
146 SECTION(
"correctness" ) {
149 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
154 int targs[] = {targ1, targ2};
157 SECTION(
"state-vector" ) {
161 REQUIRE(
areEqual(quregVec, refVec) );
163 SECTION(
"density-matrix" ) {
167 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
170 SECTION(
"input validation" ) {
172 SECTION(
"qubit indices" ) {
176 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, targ1, targ2, matr), Contains(
"Invalid target") );
177 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, targ2, targ1, matr), Contains(
"Invalid target") );
179 SECTION(
"repetition of targets" ) {
182 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, qb, qb, matr), Contains(
"target") && Contains(
"unique") );
184 SECTION(
"matrix fits in node" ) {
187 quregVec.numAmpsPerChunk = 1;
188 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, 0, 1, matr), Contains(
"targets too many qubits"));
References applyMatrix4(), applyReferenceMatrix(), areEqual(), CLEANUP_TEST, getRandomQMatrix(), NUM_QUBITS, PREPARE_TEST, and toComplexMatrix4().
◆ TEST_CASE() [4/106]
TEST_CASE |
( |
"applyMatrixN" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrixN
- Author
- Tyson Jones
Definition at line 200 of file test_operators.cpp.
205 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
207 SECTION(
"correctness" ) {
210 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
222 SECTION(
"state-vector" ) {
226 REQUIRE(
areEqual(quregVec, refVec) );
228 SECTION(
"density-matrix" ) {
232 REQUIRE(
areEqual(quregMatr, refMatr, 100*REAL_EPS) );
236 SECTION(
"input validation" ) {
238 SECTION(
"number of targets" ) {
241 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
245 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"Invalid number of target"));
248 SECTION(
"repetition in targets" ) {
251 int targs[] = {1,2,2};
254 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
257 SECTION(
"qubit indices" ) {
260 int targs[] = {1,2,3};
264 targs[GENERATE_COPY( range(0,numTargs) )] = inv;
265 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"Invalid target") );
269 SECTION(
"matrix creation" ) {
272 int targs[] = {1,2,3};
282 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"created") );
284 SECTION(
"matrix dimensions" ) {
286 int targs[2] = {1,2};
289 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, 2, matr), Contains(
"matrix size"));
292 SECTION(
"matrix fits in node" ) {
295 quregVec.numAmpsPerChunk = 1;
298 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, qb, 2, matr), Contains(
"targets too many qubits"));
References applyMatrixN(), applyReferenceMatrix(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomQMatrix(), ComplexMatrixN::imag, NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [5/106]
TEST_CASE |
( |
"applyMultiControlledMatrixN" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMultiControlledMatrixN
- Author
- Tyson Jones
Definition at line 311 of file test_operators.cpp.
316 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
320 SECTION(
"correctness" ) {
323 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
325 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
329 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
336 SECTION(
"state-vector" ) {
340 REQUIRE(
areEqual(quregVec, refVec) );
342 SECTION(
"density-matrix" ) {
346 REQUIRE(
areEqual(quregMatr, refMatr, 100*REAL_EPS) );
350 SECTION(
"input validation" ) {
352 SECTION(
"number of targets" ) {
356 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
362 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 1, targs, numTargs, matr), Contains(
"Invalid number of target"));
365 SECTION(
"repetition in targets" ) {
369 int targs[] = {1,2,2};
373 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 1, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
376 SECTION(
"number of controls" ) {
384 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, numCtrls, targs, 1, matr), Contains(
"Invalid number of control"));
387 SECTION(
"repetition in controls" ) {
389 int ctrls[] = {0,1,1};
397 SECTION(
"control and target collision" ) {
399 int ctrls[] = {0,1,2};
400 int targs[] = {3,1,4};
404 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 3, targs, 3, matr), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
407 SECTION(
"qubit indices" ) {
418 qb1[GENERATE_COPY(range(0,numQb))] = inv;
424 SECTION(
"matrix creation" ) {
427 int targs[3] = {1,2,3};
439 SECTION(
"matrix dimensions" ) {
442 int targs[2] = {1,2};
449 SECTION(
"matrix fits in node" ) {
452 quregVec.numAmpsPerChunk = 1;
454 int targs[2] = {1,2};
References applyMultiControlledMatrixN(), applyReferenceMatrix(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomQMatrix(), ComplexMatrixN::imag, NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [6/106]
TEST_CASE |
( |
"applyPauliHamil" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPauliHamil
- Author
- Tyson Jones
Definition at line 471 of file test_operators.cpp.
481 SECTION(
"correctness" ) {
486 GENERATE( range(0,10) );
488 int numTerms = GENERATE( 1, 2, 10, 15 );
493 SECTION(
"state-vector" ) {
502 REQUIRE(
areEqual(vecOut, refHamil * vecRef) );
504 SECTION(
"density-matrix" ) {
513 REQUIRE(
areEqual(matOut, refHamil * matRef, 1E2*REAL_EPS) );
518 SECTION(
"input validation" ) {
520 SECTION(
"pauli codes" ) {
527 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, vecOut), Contains(
"Invalid Pauli code") );
531 SECTION(
"qureg dimensions" ) {
536 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, badVec), Contains(
"Dimensions of the qubit registers don't match") );
541 SECTION(
"qureg types" ) {
545 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, matOut), Contains(
"Registers must both be state-vectors or both be density matrices") );
549 SECTION(
"matching hamiltonian qubits" ) {
553 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, vecOut), Contains(
"same number of qubits") );
554 REQUIRE_THROWS_WITH(
applyPauliHamil(matIn, hamil, matOut), Contains(
"same number of qubits") );
References applyPauliHamil(), areEqual(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), initDebugState(), NUM_QUBITS, PauliHamil::pauliCodes, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [7/106]
TEST_CASE |
( |
"applyPauliSum" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPauliSum
- Author
- Tyson Jones
Definition at line 571 of file test_operators.cpp.
581 SECTION(
"correctness" ) {
588 GENERATE( range(0,10) );
590 int numTerms = GENERATE( 1, 2, 10, 15);
594 qreal coeffs[numTerms];
599 SECTION(
"state-vector" ) {
608 REQUIRE(
areEqual(vecOut, pauliSum * vecRef) );
610 SECTION(
"density-matrix" ) {
619 REQUIRE(
areEqual(matOut, pauliSum * matRef, 1E2*REAL_EPS) );
622 SECTION(
"input validation" ) {
624 SECTION(
"number of terms" ) {
626 int numTerms = GENERATE( -1, 0 );
627 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, NULL, NULL, numTerms, vecOut), Contains(
"Invalid number of terms") );
629 SECTION(
"pauli codes" ) {
635 for (
int i=0; i<numPaulis; i++)
639 paulis[GENERATE_COPY( range(0,numPaulis) )] = (
pauliOpType) GENERATE( -1, 4 );
640 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, numTerms, vecOut), Contains(
"Invalid Pauli code") );
642 SECTION(
"qureg dimensions" ) {
646 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, 1, badVec), Contains(
"Dimensions of the qubit registers don't match") );
649 SECTION(
"qureg types" ) {
652 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, 1, matOut), Contains(
"Registers must both be state-vectors or both be density matrices") );
References applyPauliSum(), areEqual(), createDensityQureg(), createQureg(), destroyQureg(), initDebugState(), NUM_QUBITS, PAULI_I, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [8/106]
TEST_CASE |
( |
"applyTrotterCircuit" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyTrotterCircuit
- Author
- Tyson Jones
Definition at line 667 of file test_operators.cpp.
677 SECTION(
"correctness" ) {
679 SECTION(
"one term" ) {
687 int targs[] = {0, 1, 2};
690 for (
int i=0; i<numTargs; i++)
697 int reps = GENERATE( range(1,5) );
702 SECTION(
"state-vector" ) {
704 int order = GENERATE( 1, 2, 4 );
708 REQUIRE(
areEqual(vec, vecRef, 10*REAL_EPS) );
710 SECTION(
"density-matrix" ) {
712 int order = GENERATE( 1, 2 );
716 REQUIRE(
areEqual(mat, matRef, 1E2*REAL_EPS) );
721 SECTION(
"commuting terms" ) {
727 int targs[] = {0, 1, 2};
743 SECTION(
"state-vector" ) {
745 int reps = GENERATE( range(1,5) );
746 int order = GENERATE( 1, 2, 4 );
751 REQUIRE(
areEqual(vec, vecRef, 10*REAL_EPS) );
753 SECTION(
"density-matrix" ) {
755 int reps = GENERATE( range(1,5) );
756 int order = GENERATE( 1, 2 );
761 REQUIRE(
areEqual(mat, matRef, 1E2*REAL_EPS) );
766 SECTION(
"general" ) {
784 qreal coeffs[] = {M_PI * sqrt(2.0), M_PI, M_PI};
795 qreal fidNorm = 728359.8336;
797 SECTION(
"absolute" ) {
805 REQUIRE( fid == Approx(1).epsilon(1E-8) );
807 SECTION(
"repetitions scaling" ) {
810 int order = GENERATE( 2, 4, 6 );
813 int reps[] = {1, 5, 10};
816 for (
int i=0; i<3; i++) {
821 REQUIRE( fid >= prevFid );
825 SECTION(
"order scaling" ) {
828 int reps = GENERATE( 5, 10 );
831 int orders[] = {1, 2, 4, 6};
834 for (
int i=0; i<4; i++) {
839 REQUIRE( fid >= prevFid );
847 SECTION(
"input validation" ) {
849 SECTION(
"repetitions" ) {
852 int reps = GENERATE( -1, 0 );
854 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, reps), Contains(
"repetitions must be >=1") );
861 int order = GENERATE( -1, 0, 3, 5, 7 );
863 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, order, 1), Contains(
"order must be 1, or an even number") );
867 SECTION(
"pauli codes" ) {
874 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, 1), Contains(
"Invalid Pauli code") );
878 SECTION(
"matching hamiltonian qubits" ) {
882 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, 1), Contains(
"same number of qubits") );
883 REQUIRE_THROWS_WITH(
applyTrotterCircuit(mat, hamil, 1, 1, 1), Contains(
"same number of qubits") );
References applyTrotterCircuit(), areEqual(), calcFidelity(), createCloneQureg(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), getRandomReal(), initDebugState(), initPauliHamil(), multiRotatePauli(), NUM_QUBITS, PauliHamil::numSumTerms, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PauliHamil::pauliCodes, qreal, QUEST_ENV, and PauliHamil::termCoeffs.
◆ TEST_CASE() [9/106]
TEST_CASE |
( |
"calcDensityInnerProduct" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcDensityInnerProduct
- Author
- Tyson Jones
Definition at line 15 of file test_calculations.cpp.
20 SECTION(
"correctness" ) {
23 GENERATE( range(0,10) );
25 SECTION(
"density-matrix" ) {
39 for (
size_t i=0; i<r1.size(); i++)
40 prod += conj(r1[i]) * r2[i];
41 qreal densProd = pow(abs(prod),2);
54 for (
size_t i=0; i<ref1.size(); i++)
55 for (
size_t j=0; j<ref1.size(); j++)
56 refProd += conj(ref1[i][j]) * ref2[i][j];
57 REQUIRE( imag(refProd) == Approx(0).margin(REAL_EPS) );
64 SECTION(
"unnormalised" ) {
74 for (
size_t i=0; i<ref1.size(); i++)
75 for (
size_t j=0; j<ref1.size(); j++)
76 refProd += conj(ref1[i][j]) * ref2[i][j];
82 SECTION(
"input validation" ) {
84 SECTION(
"dimensions" ) {
90 SECTION(
"state-vectors" ) {
References calcDensityInnerProduct(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), NUM_QUBITS, qcomp, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [10/106]
TEST_CASE |
( |
"calcExpecDiagonalOp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecDiagonalOp
- Author
- Tyson Jones
Definition at line 111 of file test_calculations.cpp.
120 SECTION(
"correctness" ) {
123 GENERATE( range(0,10) );
133 SECTION(
"state-vector" ) {
139 for (
size_t i=0; i<vecRef.size(); i++)
140 prod += conj(vecRef[i]) * sumRef[i];
143 REQUIRE( res.
real == Approx(real(prod)).margin(REAL_EPS) );
144 REQUIRE( res.
imag == Approx(imag(prod)).margin(REAL_EPS) );
146 SECTION(
"density-matrix" ) {
151 for (
size_t i=0; i<matRef.size(); i++)
155 REQUIRE( res.
real == Approx(real(tr)).margin(100*REAL_EPS) );
156 REQUIRE( res.
imag == Approx(imag(tr)).margin(100*REAL_EPS) );
161 SECTION(
"input validation" ) {
163 SECTION(
"mismatching size" ) {
References calcExpecDiagonalOp(), createDensityQureg(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), getRandomReal(), Complex::imag, DiagonalOp::imag, initDebugState(), NUM_QUBITS, DiagonalOp::numElemsPerChunk, qcomp, QUEST_ENV, Complex::real, DiagonalOp::real, syncDiagonalOp(), toQMatrix(), and toQVector().
◆ TEST_CASE() [11/106]
TEST_CASE |
( |
"calcExpecPauliHamil" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliHamil
- Author
- Tyson Jones
Definition at line 183 of file test_calculations.cpp.
195 SECTION(
"correctness" ) {
200 GENERATE( range(0,10) );
202 int numTerms = GENERATE( 1, 2, 10, 15 );
207 SECTION(
"state-vector" ) {
211 QVector sumRef = refHamil * vecRef;
213 for (
size_t i=0; i<vecRef.size(); i++)
214 prod += conj(vecRef[i]) * sumRef[i];
215 REQUIRE( imag(prod) == Approx(0).margin(10*REAL_EPS) );
218 REQUIRE( res == Approx(real(prod)).margin(10*REAL_EPS) );
220 SECTION(
"density-matrix" ) {
223 matRef = refHamil * matRef;
225 for (
size_t i=0; i<matRef.size(); i++)
226 tr += real(matRef[i][i]);
230 REQUIRE( res == Approx(tr).margin(1E2*REAL_EPS) );
235 SECTION(
"validation" ) {
237 SECTION(
"pauli codes" ) {
244 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vecWork), Contains(
"Invalid Pauli code") );
248 SECTION(
"workspace type" ) {
253 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, mat), Contains(
"Registers must both be state-vectors or both be density matrices") );
254 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, vec), Contains(
"Registers must both be state-vectors or both be density matrices") );
258 SECTION(
"workspace dimensions" ) {
264 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
268 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
273 SECTION(
"matching hamiltonian qubits" ) {
278 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vecWork), Contains(
"same number of qubits") );
279 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, matWork), Contains(
"same number of qubits") );
References calcExpecPauliHamil(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), initDebugState(), NUM_QUBITS, PauliHamil::pauliCodes, qcomp, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [12/106]
TEST_CASE |
( |
"calcExpecPauliProd" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliProd
- Author
- Tyson Jones
Definition at line 296 of file test_calculations.cpp.
308 SECTION(
"correctness" ) {
310 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
318 GENERATE( range(0,10) );
320 for (
int i=0; i<numTargs; i++)
329 for (
int i=0; i<numTargs; i++) {
331 if (paulis[i] ==
PAULI_I) fac = iMatr;
332 if (paulis[i] ==
PAULI_X) fac = xMatr;
333 if (paulis[i] ==
PAULI_Y) fac = yMatr;
334 if (paulis[i] ==
PAULI_Z) fac = zMatr;
338 SECTION(
"state-vector" ) {
345 for (
size_t i=0; i<vecRef.size(); i++)
346 prod += conj(vecRef[i]) * prodRef[i];
347 REQUIRE( imag(prod) == Approx(0).margin(REAL_EPS) );
350 REQUIRE( res == Approx(real(prod)).margin(REAL_EPS) );
352 SECTION(
"density-matrix" ) {
358 matRef = fullOp * matRef;
362 for (
size_t i=0; i<matRef.size(); i++)
363 tr += real(matRef[i][i]);
367 REQUIRE( res == Approx(tr).margin(10*REAL_EPS) );
370 SECTION(
"validation" ) {
372 SECTION(
"number of targets" ) {
374 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
375 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, NULL, NULL, numTargs, vecWork), Contains(
"Invalid number of target") );
377 SECTION(
"target indices" ) {
380 int targs[3] = {0, 1, 2};
383 targs[GENERATE( range(0,3) )] = GENERATE( -1,
NUM_QUBITS );
384 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"Invalid target qubit") );
386 SECTION(
"repetition in targets" ) {
389 int targs[3] = {0, 1, 1};
390 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"target qubits must be unique") );
392 SECTION(
"pauli codes" ) {
395 int targs[3] = {0, 1, 2};
399 codes[GENERATE( range(0,3) )] = (
pauliOpType) GENERATE( -1, 4 );
400 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vecWork), Contains(
"Invalid Pauli code") );
402 SECTION(
"workspace type" ) {
408 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, matWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
409 REQUIRE_THROWS_WITH(
calcExpecPauliProd(mat, targs, codes, numTargs, vecWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
411 SECTION(
"workspace dimensions" ) {
418 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
422 REQUIRE_THROWS_WITH(
calcExpecPauliProd(mat, targs, codes, numTargs, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
References applyReferenceOp(), calcExpecPauliProd(), createDensityQureg(), createQureg(), destroyQureg(), getFullOperatorMatrix(), getKroneckerProduct(), getRandomInt(), initDebugState(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, qcomp, qreal, QUEST_ENV, sublists(), toQMatrix(), and toQVector().
◆ TEST_CASE() [13/106]
TEST_CASE |
( |
"calcExpecPauliSum" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliSum
- Author
- Tyson Jones
Definition at line 438 of file test_calculations.cpp.
450 SECTION(
"correctness" ) {
452 int numSumTerms = GENERATE( 1, 2, 10, 15 );
457 GENERATE( range(0,10) );
460 qreal coeffs[numSumTerms];
466 SECTION(
"state-vector" ) {
470 QVector sumRef = pauliSum * vecRef;
472 for (
size_t i=0; i<vecRef.size(); i++)
473 prod += conj(vecRef[i]) * sumRef[i];
474 REQUIRE( imag(prod) == Approx(0).margin(10*REAL_EPS) );
477 REQUIRE( res == Approx(real(prod)).margin(10*REAL_EPS) );
479 SECTION(
"density-matrix" ) {
482 matRef = pauliSum * matRef;
484 for (
size_t i=0; i<matRef.size(); i++)
485 tr += real(matRef[i][i]);
489 REQUIRE( res == Approx(tr).margin(1E2*REAL_EPS) );
492 SECTION(
"validation" ) {
494 SECTION(
"number of sum terms" ) {
496 int numSumTerms = GENERATE( -1, 0 );
497 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, NULL, NULL, numSumTerms, vecWork), Contains(
"Invalid number of terms in the Pauli sum") );
499 SECTION(
"pauli codes" ) {
503 qreal coeffs[numSumTerms];
510 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vecWork), Contains(
"Invalid Pauli code") );
512 SECTION(
"workspace type" ) {
516 qreal coeffs[1] = {0};
521 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, mat), Contains(
"Registers must both be state-vectors or both be density matrices") );
522 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, vec), Contains(
"Registers must both be state-vectors or both be density matrices") );
524 SECTION(
"workspace dimensions" ) {
528 qreal coeffs[1] = {0};
534 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
538 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
References calcExpecPauliSum(), createDensityQureg(), createQureg(), destroyQureg(), initDebugState(), NUM_QUBITS, PAULI_I, qcomp, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [14/106]
TEST_CASE |
( |
"calcFidelity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcFidelity
- Author
- Tyson Jones
Definition at line 554 of file test_calculations.cpp.
560 SECTION(
"correctness" ) {
563 GENERATE( range(0,10) );
565 SECTION(
"state-vector" ) {
569 SECTION(
"normalised" ) {
582 for (
size_t i=0; i<vecRef.size(); i++)
583 dotProd += conj(vecRef[i]) * pureRef[i];
584 qreal refFid = pow(abs(dotProd), 2);
588 SECTION(
"unnormalised" ) {
598 for (
size_t i=0; i<vecRef.size(); i++)
599 nv += pow(abs(vecRef[i]), 2);
605 for (
size_t i=0; i<vecRef.size(); i++)
606 dotProd += conj(vecRef[i]) * pureRef[i];
607 qreal refFid = pow(abs(dotProd), 2);
612 SECTION(
"density-matrix" ) {
633 for (
size_t i=0; i<r1.size(); i++)
634 dotProd += conj(r1[i]) * pureRef[i];
635 qreal refFid = pow(abs(dotProd), 2);
649 QVector rhs = matRef * pureRef;
651 for (
size_t i=0; i<rhs.size(); i++)
652 dotProd += conj(pureRef[i]) * rhs[i];
654 REQUIRE( imag(dotProd) == Approx(0).margin(REAL_EPS) );
655 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
657 SECTION(
"unnormalised" ) {
666 QVector rhs = matRef * pureRef;
668 for (
size_t i=0; i<rhs.size(); i++)
669 dotProd += conj(pureRef[i]) * rhs[i];
671 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
675 SECTION(
"input validation" ) {
677 SECTION(
"dimensions" ) {
681 REQUIRE_THROWS_WITH(
calcFidelity(vec2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
686 REQUIRE_THROWS_WITH(
calcFidelity(mat2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
689 SECTION(
"density-matrices" ) {
692 REQUIRE_THROWS_WITH(
calcFidelity(mat,mat), Contains(
"Second argument must be a state-vector") );
References calcFidelity(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomQVector(), getRandomStateVector(), NUM_QUBITS, Qureg::numQubitsRepresented, qcomp, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [15/106]
TEST_CASE |
( |
"calcHilbertSchmidtDistance" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcHilbertSchmidtDistance
- Author
- Tyson Jones
Definition at line 706 of file test_calculations.cpp.
711 SECTION(
"correctness" ) {
714 GENERATE( range(0,10) );
716 SECTION(
"density-matrix" ) {
730 for (
size_t i=0; i<m1.size(); i++)
731 for (
size_t j=0; j<m1.size(); j++)
732 tr += pow(abs(m1[i][j] - m2[i][j]), 2);
735 REQUIRE( res == Approx(sqrt(tr)) );
738 SECTION(
"normalised" ) {
747 for (
size_t i=0; i<ref1.size(); i++)
748 for (
size_t j=0; j<ref1.size(); j++)
749 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
752 REQUIRE( res == Approx(sqrt(tr)) );
754 SECTION(
"unnormalised" ) {
764 for (
size_t i=0; i<ref1.size(); i++)
765 for (
size_t j=0; j<ref1.size(); j++)
766 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
769 REQUIRE( res == Approx(sqrt(tr)) );
773 SECTION(
"input validation") {
775 SECTION(
"dimensions" ) {
781 SECTION(
"state-vector" ) {
References calcHilbertSchmidtDistance(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [16/106]
TEST_CASE |
( |
"calcInnerProduct" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcInnerProduct
- Author
- Tyson Jones
Definition at line 802 of file test_calculations.cpp.
807 SECTION(
"correctness" ) {
810 GENERATE( range(0,10) );
812 SECTION(
"state-vector" ) {
814 SECTION(
"normalised" ) {
820 for (
size_t i=0; i<r1.size(); i++)
821 prod += conj(r1[i]) * r2[i];
827 REQUIRE( res.
real == Approx(real(prod)) );
828 REQUIRE( res.
imag == Approx(imag(prod)) );
830 SECTION(
"unnormalised" ) {
836 for (
size_t i=0; i<r1.size(); i++)
837 prod += conj(r1[i]) * r2[i];
843 REQUIRE( res.
real == Approx(real(prod)) );
844 REQUIRE( res.
imag == Approx(imag(prod)) );
848 SECTION(
"input validation" ) {
850 SECTION(
"dimensions" ) {
853 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,vec3), Contains(
"Dimensions") && Contains(
"don't match") );
856 SECTION(
"density-matrix" ) {
860 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,mat), Contains(
"valid only for state-vectors") );
861 REQUIRE_THROWS_WITH(
calcInnerProduct(mat,vec1), Contains(
"valid only for state-vectors") );
862 REQUIRE_THROWS_WITH(
calcInnerProduct(mat,mat), Contains(
"valid only for state-vectors") );
References calcInnerProduct(), createDensityQureg(), createQureg(), destroyQureg(), getRandomQVector(), getRandomStateVector(), Complex::imag, NUM_QUBITS, qcomp, QUEST_ENV, Complex::real, and toQureg().
◆ TEST_CASE() [17/106]
TEST_CASE |
( |
"calcProbOfOutcome" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcProbOfOutcome
- Author
- Tyson Jones
Definition at line 877 of file test_calculations.cpp.
882 SECTION(
"correctness" ) {
885 int outcome = GENERATE( 0, 1 );
887 SECTION(
"state-vector" ) {
889 SECTION(
"normalised" ) {
896 for (
size_t ind=0; ind<ref.size(); ind++) {
897 int bit = (ind >> target) & 1;
899 prob += pow(abs(ref[ind]), 2);
904 SECTION(
"unnormalised" ) {
912 for (
size_t ind=0; ind<ref.size(); ind++) {
913 int bit = (ind >> target) & 1;
915 prob += pow(abs(ref[ind]), 2);
923 SECTION(
"density-matrix" ) {
933 for (
size_t ind=0; ind<ref.size(); ind++) {
934 int bit = (ind >> target) & 1;
936 prob += pow(abs(ref[ind]), 2);
948 for (
size_t ind=0; ind<ref.size(); ind++) {
949 int bit = (ind >> target) & 1;
953 REQUIRE( imag(tr) == Approx(0).margin(REAL_EPS) );
957 SECTION(
"unnormalised" ) {
965 for (
size_t ind=0; ind<ref.size(); ind++) {
966 int bit = (ind >> target) & 1;
968 tr += real(ref[ind][ind]);
977 SECTION(
"validation" ) {
979 SECTION(
"qubit indices" ) {
982 REQUIRE_THROWS_WITH(
calcProbOfOutcome(vec, target, 0), Contains(
"Invalid target qubit") );
984 SECTION(
"outcome value" ) {
986 int outcome = GENERATE( -1, 2 );
987 REQUIRE_THROWS_WITH(
calcProbOfOutcome(vec, 0, outcome), Contains(
"Invalid measurement outcome") );
References calcProbOfOutcome(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomQVector(), getRandomStateVector(), NUM_QUBITS, qcomp, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [18/106]
TEST_CASE |
( |
"calcPurity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcPurity
- Author
- Tyson Jones
Definition at line 1000 of file test_calculations.cpp.
1004 SECTION(
"correctness" ) {
1007 GENERATE( range(1,10) );
1009 SECTION(
"density-matrix" ) {
1024 SECTION(
"mixed" ) {
1030 REQUIRE( purity < 1 );
1036 for (
size_t i=0; i<prod.size(); i++)
1037 tr += real(prod[i][i]);
1038 REQUIRE( purity == Approx(tr) );
1040 SECTION(
"unnormalised" ) {
1045 for (
size_t i=0; i<ref.size(); i++)
1046 for (
size_t j=0; j<ref.size(); j++)
1047 tot += pow(abs(ref[i][j]), 2);
1054 SECTION(
"input validation" ) {
1056 SECTION(
"state-vector" ) {
1059 REQUIRE_THROWS_WITH(
calcPurity(vec), Contains(
"valid only for density matrices") );
References calcPurity(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), initZeroState(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [19/106]
TEST_CASE |
( |
"calcTotalProb" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcTotalProb
- Author
- Tyson Jones
Definition at line 1072 of file test_calculations.cpp.
1077 SECTION(
"correctness" ) {
1079 SECTION(
"state-vector" ) {
1097 for (
size_t i=0; i<ref.size(); i++)
1098 refProb += pow(abs(ref[i]), 2);
1101 SECTION(
"density-matrix" ) {
1119 for (
size_t i=0; i<ref.size(); i++)
1120 refProb += real(ref[i][i]);
1124 SECTION(
"input validation" ) {
References calcTotalProb(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), initBlankState(), initDebugState(), initPlusState(), NUM_QUBITS, qreal, QUEST_ENV, toQMatrix(), toQureg(), and toQVector().
◆ TEST_CASE() [20/106]
TEST_CASE |
( |
"cloneQureg" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- cloneQureg
- Author
- Tyson Jones
Definition at line 15 of file test_state_initialisations.cpp.
20 SECTION(
"correctness" ) {
22 SECTION(
"state-vector" ) {
41 SECTION(
"density-matrix" ) {
61 SECTION(
"input validation" ) {
63 SECTION(
"qureg type" ) {
65 REQUIRE_THROWS_WITH(
cloneQureg(mat1, vec1), Contains(
"both be state-vectors") && Contains(
"density matrices") );
66 REQUIRE_THROWS_WITH(
cloneQureg(vec1, mat1), Contains(
"both be state-vectors") && Contains(
"density matrices") );
68 SECTION(
"qureg dimensions" ) {
73 REQUIRE_THROWS_WITH(
cloneQureg(vec1, vec3), Contains(
"Dimensions") && Contains(
"don't match") );
74 REQUIRE_THROWS_WITH(
cloneQureg(mat1, mat3), Contains(
"Dimensions") && Contains(
"don't match") );
References areEqual(), cloneQureg(), createDensityQureg(), createQureg(), destroyQureg(), initBlankState(), initDebugState(), NUM_QUBITS, Qureg::numQubitsRepresented, QUEST_ENV, toQMatrix(), and toQVector().
◆ TEST_CASE() [21/106]
TEST_CASE |
( |
"collapseToOutcome" |
, |
|
|
"" |
[gates] |
|
) |
| |
- See also
- collapseToOutcome
- Author
- Tyson Jones
Definition at line 15 of file test_gates.cpp.
20 SECTION(
"correctness" ) {
23 int outcome = GENERATE( 0, 1 );
26 GENERATE( range(0,10) );
28 SECTION(
"state-vector" ) {
36 for (
size_t ind=0; ind<vecRef.size(); ind++) {
37 int bit = (ind >> qubit) & 1;
39 prob += pow(abs(vecRef[ind]), 2);
43 for (
size_t ind=0; ind<vecRef.size(); ind++) {
44 int bit = (ind >> qubit) & 1;
46 vecRef[ind] /= sqrt(prob);
52 REQUIRE( res == Approx(prob) );
55 SECTION(
"density-matrix" ) {
63 for (
size_t ind=0; ind<matRef.size(); ind++) {
64 int bit = (ind >> qubit) & 1;
66 tr += matRef[ind][ind];
68 REQUIRE( imag(tr) == Approx(0).margin(REAL_EPS) );
69 qreal prob = real(tr);
72 for (
size_t r=0; r<matRef.size(); r++) {
73 for (
size_t c=0; c<matRef.size(); c++) {
74 int ketBit = (c >> qubit) & 1;
75 int braBit = (r >> qubit) & 1;
77 if (ketBit == outcome && braBit == outcome)
85 REQUIRE( res == Approx(prob) );
89 SECTION(
"input validation" ) {
91 SECTION(
"qubit index" ) {
95 REQUIRE_THROWS_WITH(
collapseToOutcome(mat, qubit, outcome), Contains(
"Invalid target qubit") );
97 SECTION(
"outcome value" ) {
100 int outcome = GENERATE( -1, 2 );
101 REQUIRE_THROWS_WITH(
collapseToOutcome(mat, qubit, outcome), Contains(
"Invalid measurement outcome") );
103 SECTION(
"outcome probability" ) {
106 REQUIRE_THROWS_WITH(
collapseToOutcome(vec, 0, 1), Contains(
"Can't collapse to state with zero probability") );
108 REQUIRE_THROWS_WITH(
collapseToOutcome(vec, 0, 0), Contains(
"Can't collapse to state with zero probability") );
References areEqual(), collapseToOutcome(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), initClassicalState(), initZeroState(), NUM_QUBITS, qcomp, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [22/106]
TEST_CASE |
( |
"compactUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- compactUnitary
- Author
- Tyson Jones
Definition at line 46 of file test_unitaries.cpp.
56 SECTION(
"correctness" ) {
60 SECTION(
"state-vector" ) {
64 REQUIRE(
areEqual(quregVec, refVec) );
66 SECTION(
"density-matrix" ) {
70 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
73 SECTION(
"input validation" ) {
75 SECTION(
"qubit indices" ) {
78 REQUIRE_THROWS_WITH(
compactUnitary(quregVec, target, alpha, beta), Contains(
"Invalid target") );
80 SECTION(
"unitarity" ) {
83 alpha = {.
real=1, .imag=2};
84 beta = {.
real=3, .imag=4};
85 REQUIRE_THROWS_WITH(
compactUnitary(quregVec, 0, alpha, beta), Contains(
"unitary") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, compactUnitary(), expI(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, qcomp, Complex::real, toComplex, and toQMatrix().
◆ TEST_CASE() [23/106]
TEST_CASE |
( |
"controlledCompactUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledCompactUnitary
- Author
- Tyson Jones
Definition at line 97 of file test_unitaries.cpp.
107 SECTION(
"correctness" ) {
110 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
112 SECTION(
"state-vector" ) {
116 REQUIRE(
areEqual(quregVec, refVec) );
118 SECTION(
"density-matrix" ) {
122 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
125 SECTION(
"input validation" ) {
127 SECTION(
"control and target collision" ) {
130 REQUIRE_THROWS_WITH(
controlledCompactUnitary(quregVec, qb, qb, alpha, beta), Contains(
"Control") && Contains(
"target") );
132 SECTION(
"qubit indices" ) {
138 SECTION(
"unitarity" ) {
141 alpha = {.
real=1, .imag=2};
142 beta = {.
real=3, .imag=4};
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledCompactUnitary(), expI(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, qcomp, Complex::real, toComplex, and toQMatrix().
◆ TEST_CASE() [24/106]
TEST_CASE |
( |
"controlledMultiQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledMultiQubitUnitary
- Author
- Tyson Jones
Definition at line 155 of file test_unitaries.cpp.
160 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
164 SECTION(
"correctness" ) {
168 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
176 SECTION(
"state-vector" ) {
180 REQUIRE(
areEqual(quregVec, refVec) );
182 SECTION(
"density-matrix" ) {
186 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
190 SECTION(
"input validation" ) {
192 SECTION(
"number of targets" ) {
196 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
202 SECTION(
"repetition in targets" ) {
206 int targs[] = {1,2,2};
209 REQUIRE_THROWS_WITH(
controlledMultiQubitUnitary(quregVec, ctrl, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
212 SECTION(
"control and target collision" ) {
215 int targs[] = {0,1,2};
216 int ctrl = targs[GENERATE_COPY( range(0,numTargs) )];
219 REQUIRE_THROWS_WITH(
controlledMultiQubitUnitary(quregVec, ctrl, targs, numTargs, matr), Contains(
"Control") && Contains(
"target"));
222 SECTION(
"qubit indices" ) {
226 int targs[] = {1,2,3};
234 targs[GENERATE_COPY( range(0,numTargs) )] = inv;
239 SECTION(
"unitarity" ) {
242 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
246 for (
int i=0; i<numTargs; i++)
252 SECTION(
"unitary creation" ) {
255 int targs[] = {1,2,3};
267 SECTION(
"unitary dimensions" ) {
270 int targs[2] = {1,2};
276 SECTION(
"unitary fits in node" ) {
279 quregVec.numAmpsPerChunk = 1;
References applyReferenceOp(), areEqual(), calcLog2(), CLEANUP_TEST, controlledMultiQubitUnitary(), createComplexMatrixN(), destroyComplexMatrixN(), getRandomUnitary(), ComplexMatrixN::imag, NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [25/106]
TEST_CASE |
( |
"controlledNot" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledNot
- Author
- Tyson Jones
Definition at line 295 of file test_unitaries.cpp.
300 SECTION(
"correctness" ) {
303 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
305 SECTION(
"state-vector" ) {
309 REQUIRE(
areEqual(quregVec, refVec) );
311 SECTION(
"density-matrix" ) {
315 REQUIRE(
areEqual(quregMatr, refMatr) );
318 SECTION(
"input validation" ) {
320 SECTION(
"control and target collision" ) {
323 REQUIRE_THROWS_WITH(
controlledNot(quregVec, qb, qb), Contains(
"Control") && Contains(
"target") );
325 SECTION(
"qubit indices" ) {
328 REQUIRE_THROWS_WITH(
controlledNot(quregVec, qb, 0), Contains(
"Invalid control") );
329 REQUIRE_THROWS_WITH(
controlledNot(quregVec, 0, qb), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledNot(), NUM_QUBITS, and PREPARE_TEST.
◆ TEST_CASE() [26/106]
TEST_CASE |
( |
"controlledPauliY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledPauliY
- Author
- Tyson Jones
Definition at line 341 of file test_unitaries.cpp.
346 SECTION(
"correctness" ) {
349 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
351 SECTION(
"state-vector" ) {
355 REQUIRE(
areEqual(quregVec, refVec) );
357 SECTION(
"density-matrix" ) {
361 REQUIRE(
areEqual(quregMatr, refMatr) );
364 SECTION(
"input validation" ) {
366 SECTION(
"control and target collision" ) {
369 REQUIRE_THROWS_WITH(
controlledPauliY(quregVec, qb, qb), Contains(
"Control") && Contains(
"target") );
371 SECTION(
"qubit indices" ) {
374 REQUIRE_THROWS_WITH(
controlledPauliY(quregVec, qb, 0), Contains(
"Invalid control") );
375 REQUIRE_THROWS_WITH(
controlledPauliY(quregVec, 0, qb), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledPauliY(), NUM_QUBITS, and PREPARE_TEST.
◆ TEST_CASE() [27/106]
TEST_CASE |
( |
"controlledPhaseFlip" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledPhaseFlip
- Author
- Tyson Jones
Definition at line 387 of file test_unitaries.cpp.
392 SECTION(
"correctness" ) {
395 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
397 SECTION(
"state-vector" ) {
401 REQUIRE(
areEqual(quregVec, refVec) );
403 SECTION(
"density-matrix" ) {
407 REQUIRE(
areEqual(quregMatr, refMatr) );
410 SECTION(
"input validation" ) {
412 SECTION(
"control and target collision" ) {
415 REQUIRE_THROWS_WITH(
controlledPhaseFlip(quregVec, qb, qb), Contains(
"Control") && Contains(
"target") );
417 SECTION(
"qubit indices" ) {
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledPhaseFlip(), NUM_QUBITS, and PREPARE_TEST.
◆ TEST_CASE() [28/106]
TEST_CASE |
( |
"controlledPhaseShift" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledPhaseShift
- Author
- Tyson Jones
Definition at line 433 of file test_unitaries.cpp.
439 SECTION(
"correctness" ) {
442 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
444 SECTION(
"state-vector" ) {
448 REQUIRE(
areEqual(quregVec, refVec) );
450 SECTION(
"density-matrix" ) {
454 REQUIRE(
areEqual(quregMatr, refMatr) );
457 SECTION(
"input validation" ) {
459 SECTION(
"control and target collision" ) {
462 REQUIRE_THROWS_WITH(
controlledPhaseShift(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
464 SECTION(
"qubit indices" ) {
467 REQUIRE_THROWS_WITH(
controlledPhaseShift(quregVec, qb, 0, param), Contains(
"Invalid control") );
468 REQUIRE_THROWS_WITH(
controlledPhaseShift(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledPhaseShift(), expI(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [29/106]
TEST_CASE |
( |
"controlledRotateAroundAxis" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateAroundAxis
- Author
- Tyson Jones
Definition at line 480 of file test_unitaries.cpp.
490 qreal c = cos(param/2);
491 qreal s = sin(param/2);
492 qreal m = sqrt(vec.
x*vec.
x + vec.
y*vec.
y + vec.
z*vec.
z);
493 QMatrix op{{c - 1i*vec.
z*s/m, -(vec.
y + 1i*vec.
x)*s/m},
494 {(vec.
y - 1i*vec.
x)*s/m, c + 1i*vec.
z*s/m}};
496 SECTION(
"correctness" ) {
499 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
501 SECTION(
"state-vector" ) {
505 REQUIRE(
areEqual(quregVec, refVec) );
507 SECTION(
"density-matrix" ) {
511 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
514 SECTION(
"input validation" ) {
516 SECTION(
"control and target collision" ) {
521 SECTION(
"qubit indices" ) {
527 SECTION(
"zero rotation axis" ) {
529 vec = {.
x=0, .y=0, .z=0};
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateAroundAxis(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, qreal, Vector::x, Vector::y, and Vector::z.
◆ TEST_CASE() [30/106]
TEST_CASE |
( |
"controlledRotateX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateX
- Author
- Tyson Jones
Definition at line 542 of file test_unitaries.cpp.
546 QMatrix op{{cos(param/2), -1i*sin(param/2)}, {-1i*sin(param/2), cos(param/2)}};
548 SECTION(
"correctness" ) {
551 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
553 SECTION(
"state-vector" ) {
557 REQUIRE(
areEqual(quregVec, refVec) );
559 SECTION(
"density-matrix" ) {
563 REQUIRE(
areEqual(quregMatr, refMatr) );
566 SECTION(
"input validation" ) {
568 SECTION(
"control and target collision" ) {
571 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
573 SECTION(
"qubit indices" ) {
576 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, qb, 0, param), Contains(
"Invalid control") );
577 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateX(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [31/106]
TEST_CASE |
( |
"controlledRotateY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateY
- Author
- Tyson Jones
Definition at line 589 of file test_unitaries.cpp.
593 QMatrix op{{cos(param/2), -sin(param/2)},{sin(param/2), cos(param/2)}};
595 SECTION(
"correctness" ) {
598 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
600 SECTION(
"state-vector" ) {
604 REQUIRE(
areEqual(quregVec, refVec) );
606 SECTION(
"density-matrix" ) {
610 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
613 SECTION(
"input validation" ) {
615 SECTION(
"control and target collision" ) {
618 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
620 SECTION(
"qubit indices" ) {
623 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, qb, 0, param), Contains(
"Invalid control") );
624 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateY(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [32/106]
TEST_CASE |
( |
"controlledRotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateZ
- Author
- Tyson Jones
Definition at line 636 of file test_unitaries.cpp.
642 SECTION(
"correctness" ) {
645 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
647 SECTION(
"state-vector" ) {
651 REQUIRE(
areEqual(quregVec, refVec) );
653 SECTION(
"density-matrix" ) {
657 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
660 SECTION(
"input validation" ) {
662 SECTION(
"control and target collision" ) {
665 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
667 SECTION(
"qubit indices" ) {
670 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, qb, 0, param), Contains(
"Invalid control") );
671 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateZ(), expI(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [33/106]
TEST_CASE |
( |
"controlledTwoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledTwoQubitUnitary
- Author
- Tyson Jones
Definition at line 683 of file test_unitaries.cpp.
688 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
694 SECTION(
"correctness" ) {
697 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
698 int control = GENERATE_COPY( filter([=](
int c){
return c!=targ1 && c!=targ2; }, range(0,
NUM_QUBITS)) );
700 SECTION(
"state-vector" ) {
704 REQUIRE(
areEqual(quregVec, refVec) );
706 SECTION(
"density-matrix" ) {
710 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
713 SECTION(
"input validation" ) {
715 SECTION(
"repetition of targets" ) {
718 REQUIRE_THROWS_WITH(
controlledTwoQubitUnitary(quregVec, ctrl, targ, targ, matr), Contains(
"target") && Contains(
"unique") );
720 SECTION(
"control and target collision" ) {
724 int ctrl = GENERATE( 1,2 );
725 REQUIRE_THROWS_WITH(
controlledTwoQubitUnitary(quregVec, ctrl, targ1, targ2, matr), Contains(
"Control") && Contains(
"target") );
727 SECTION(
"qubit indices" ) {
739 SECTION(
"unitarity" ) {
744 SECTION(
"unitary fits in node" ) {
747 quregVec.numAmpsPerChunk = 1;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledTwoQubitUnitary(), getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix4::real, and toComplexMatrix4().
◆ TEST_CASE() [34/106]
TEST_CASE |
( |
"controlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledUnitary
- Author
- Tyson Jones
Definition at line 760 of file test_unitaries.cpp.
766 SECTION(
"correctness" ) {
769 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
771 SECTION(
"state-vector" ) {
775 REQUIRE(
areEqual(quregVec, refVec) );
777 SECTION(
"density-matrix" ) {
781 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
784 SECTION(
"input validation" ) {
786 SECTION(
"control and target collision" ) {
789 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, qb, qb, matr), Contains(
"Control") && Contains(
"target") );
791 SECTION(
"qubit indices" ) {
794 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, qb, 0, matr), Contains(
"Invalid control") );
795 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, 0, qb, matr), Contains(
"Invalid target") );
797 SECTION(
"unitarity" ) {
800 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, 0, 1, matr), Contains(
"unitary") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledUnitary(), getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, and toComplexMatrix2().
◆ TEST_CASE() [35/106]
TEST_CASE |
( |
"createCloneQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createCloneQureg
- Author
- Tyson Jones
Definition at line 57 of file test_data_structures.cpp.
59 SECTION(
"state-vector" ) {
77 SECTION(
"density-matrix" ) {
References areEqual(), createCloneQureg(), createDensityQureg(), createQureg(), destroyQureg(), Qureg::isDensityMatrix, NUM_QUBITS, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, Qureg::numQubitsInStateVec, Qureg::numQubitsRepresented, and QUEST_ENV.
◆ TEST_CASE() [36/106]
TEST_CASE |
( |
"createComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [37/106]
TEST_CASE |
( |
"createDensityQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createDensityQureg
- Author
- Tyson Jones
Definition at line 131 of file test_data_structures.cpp.
138 SECTION(
"correctness" ) {
141 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
151 SECTION(
"input validation") {
153 SECTION(
"number of qubits" ) {
155 int numQb = GENERATE( -1, 0 );
158 SECTION(
"number of amplitudes" ) {
164 int maxQb = (int)
calcLog2(SIZE_MAX) / 2;
165 REQUIRE_THROWS_WITH(
createDensityQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
170 int minQb = GENERATE_COPY( range(3,maxQb) );
171 env.
numRanks = (int) pow(2, 2*minQb);
172 int numQb = GENERATE_COPY( range(1,minQb) );
175 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), createDensityQureg(), destroyQureg(), getZeroMatrix(), QuESTEnv::numRanks, and QUEST_ENV.
◆ TEST_CASE() [38/106]
TEST_CASE |
( |
"createDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createDiagonalOp
- Author
- Tyson Jones
Definition at line 190 of file test_data_structures.cpp.
197 SECTION(
"correctness" ) {
200 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
208 REQUIRE( op.
real != NULL );
209 REQUIRE( op.
imag != NULL );
218 SECTION(
"input validation" ) {
220 SECTION(
"number of qubits" ) {
222 int numQb = GENERATE( -1, 0 );
225 SECTION(
"number of amplitudes" ) {
231 int maxQb = (int)
calcLog2(SIZE_MAX);
232 REQUIRE_THROWS_WITH(
createDiagonalOp(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
235 int minQb = GENERATE_COPY( range(2,maxQb) );
237 int numQb = GENERATE_COPY( range(1,minQb) );
238 REQUIRE_THROWS_WITH(
createDiagonalOp(numQb, env), Contains(
"Too few qubits") );
240 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), DiagonalOp::chunkId, createDiagonalOp(), destroyDiagonalOp(), DiagonalOp::imag, DiagonalOp::numChunks, DiagonalOp::numElemsPerChunk, DiagonalOp::numQubits, QuESTEnv::numRanks, QUEST_ENV, QuESTEnv::rank, DiagonalOp::real, and toQVector().
◆ TEST_CASE() [39/106]
TEST_CASE |
( |
"createPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createPauliHamil
- Author
- Tyson Jones
Definition at line 255 of file test_data_structures.cpp.
257 SECTION(
"correctness" ) {
259 int numQb = GENERATE( range(1,5) );
260 int numTerms = GENERATE( range(1,5) );
268 int numPaulis = numQb * numTerms;
269 for (
int i=0; i<numPaulis; i++) {
274 for (
int j=0; j<numTerms; j++) {
281 SECTION(
"input validation") {
283 SECTION(
"number of qubits" ) {
285 int numQb = GENERATE( -1, 0 );
286 REQUIRE_THROWS_WITH(
createPauliHamil(numQb, 1), Contains(
"The number of qubits and terms in the PauliHamil must be strictly positive.") );
288 SECTION(
"number of terms" ) {
290 int numTerms = GENERATE( -1, 0 );
291 REQUIRE_THROWS_WITH(
createPauliHamil(1, numTerms), Contains(
"The number of qubits and terms in the PauliHamil must be strictly positive.") );
References createPauliHamil(), destroyPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PAULI_I, PauliHamil::pauliCodes, and PauliHamil::termCoeffs.
◆ TEST_CASE() [40/106]
TEST_CASE |
( |
"createPauliHamilFromFile" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createPauliHamilFromFile
- Author
- Tyson Jones
Definition at line 302 of file test_data_structures.cpp.
305 char fn[] =
"temp_test_output_file.txt";
307 SECTION(
"correctness" ) {
309 SECTION(
"general" ) {
312 int numQb = GENERATE( range(1,6) );
313 int numTerms = GENERATE( range(1,6) );
314 int numPaulis = numQb*numTerms;
317 qreal coeffs[numTerms];
322 FILE* file = fopen(fn,
"w");
324 for (
int n=0; n<numTerms; n++) {
325 fprintf(file,
"%.20f ", coeffs[n]);
326 for (
int q=0; q<numQb; q++)
327 fprintf(file,
"%d ", (
int) paulis[i++]);
342 for (
int n=0; n<numTerms; n++) {
344 for (
int q=0; q<numQb; q++) {
352 SECTION(
"edge cases" ) {
354 SECTION(
"no trailing newline or space" ) {
356 FILE* file = fopen(fn,
"w");
357 fprintf(file,
".1 1 0 1");
365 SECTION(
"trailing newlines" ) {
367 FILE* file = fopen(fn,
"w");
368 fprintf(file,
".1 1 0 1\n\n\n");
376 SECTION(
"trailing spaces" ) {
378 FILE* file = fopen(fn,
"w");
379 fprintf(file,
".1 1 0 1 ");
389 SECTION(
"input validation") {
391 SECTION(
"number of qubits" ) {
393 FILE* file = fopen(fn,
"w");
394 fprintf(file,
".1 ");
396 REQUIRE_THROWS_WITH(
createPauliHamilFromFile(fn), Contains(
"The number of qubits") && Contains(
"strictly positive"));
398 SECTION(
"coefficient type" ) {
400 FILE* file = fopen(fn,
"w");
401 fprintf(file,
"notanumber 1 2 3");
405 SECTION(
"pauli code" ) {
408 FILE* file = fopen(fn,
"w");
409 fprintf(file,
".1 1 2 4");
414 file = fopen(fn,
"w");
415 fprintf(file,
".1 1 2 notanumber");
References createPauliHamilFromFile(), destroyPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PauliHamil::pauliCodes, qreal, setRandomPauliSum(), and PauliHamil::termCoeffs.
◆ TEST_CASE() [41/106]
TEST_CASE |
( |
"createQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [42/106]
TEST_CASE |
( |
"createQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createQureg
- Author
- Tyson Jones
Definition at line 443 of file test_data_structures.cpp.
450 SECTION(
"correctness" ) {
453 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
463 SECTION(
"input validation") {
465 SECTION(
"number of qubits" ) {
467 int numQb = GENERATE( -1, 0 );
470 SECTION(
"number of amplitudes" ) {
476 int maxQb = (int)
calcLog2(SIZE_MAX);
477 REQUIRE_THROWS_WITH(
createQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
480 int minQb = GENERATE_COPY( range(2,maxQb) );
482 int numQb = GENERATE_COPY( range(1,minQb) );
483 REQUIRE_THROWS_WITH(
createQureg(numQb, env), Contains(
"Too few qubits") );
485 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), createQureg(), destroyQureg(), QuESTEnv::numRanks, and QUEST_ENV.
◆ TEST_CASE() [43/106]
TEST_CASE |
( |
"destroyComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [44/106]
TEST_CASE |
( |
"destroyDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [45/106]
TEST_CASE |
( |
"destroyPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [46/106]
TEST_CASE |
( |
"destroyQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [47/106]
TEST_CASE |
( |
"destroyQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [48/106]
TEST_CASE |
( |
"fromComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [49/106]
TEST_CASE |
( |
"getAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getAmp
- Author
- Tyson Jones
Definition at line 1139 of file test_calculations.cpp.
1143 SECTION(
"correctness" ) {
1145 SECTION(
"state-vector" ) {
1150 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1155 SECTION(
"input validation" ) {
1157 SECTION(
"state index" ) {
1160 REQUIRE_THROWS_WITH(
getAmp(vec,ind), Contains(
"Invalid amplitude index") );
1162 SECTION(
"density-matrix" ) {
1165 REQUIRE_THROWS_WITH(
getAmp(mat,0), Contains(
"valid only for state-vectors") );
References createDensityQureg(), createQureg(), destroyQureg(), fromComplex, getAmp(), initDebugState(), NUM_QUBITS, QUEST_ENV, and toQVector().
◆ TEST_CASE() [50/106]
TEST_CASE |
( |
"getDensityAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getDensityAmp
- Author
- Tyson Jones
Definition at line 1178 of file test_calculations.cpp.
1182 SECTION(
"correctness" ) {
1184 SECTION(
"density-matrix" ) {
1189 int row = GENERATE( range(0,1<<
NUM_QUBITS) );
1190 int col = GENERATE( range(0,1<<
NUM_QUBITS) );
1196 SECTION(
"input validation" ) {
1198 SECTION(
"state index" ) {
1201 REQUIRE_THROWS_WITH(
getDensityAmp(mat,ind,0), Contains(
"Invalid amplitude index") );
1202 REQUIRE_THROWS_WITH(
getDensityAmp(mat,0,ind), Contains(
"Invalid amplitude index") );
1205 SECTION(
"state-vector" ) {
1208 REQUIRE_THROWS_WITH(
getDensityAmp(vec,0,0), Contains(
"valid only for density matrices") );
References createDensityQureg(), createQureg(), destroyQureg(), fromComplex, getDensityAmp(), initDebugState(), NUM_QUBITS, QUEST_ENV, and toQMatrix().
◆ TEST_CASE() [51/106]
TEST_CASE |
( |
"getImagAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getImagAmp
- Author
- Tyson Jones
Definition at line 1221 of file test_calculations.cpp.
1225 SECTION(
"correctness" ) {
1227 SECTION(
"state-vector" ) {
1232 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1233 REQUIRE(
getImagAmp(vec,ind) == imag(ref[ind]) );
1236 SECTION(
"input validation" ) {
1238 SECTION(
"state index" ) {
1241 REQUIRE_THROWS_WITH(
getImagAmp(vec,ind), Contains(
"Invalid amplitude index") );
1243 SECTION(
"density-matrix" ) {
1246 REQUIRE_THROWS_WITH(
getImagAmp(mat,0), Contains(
"valid only for state-vectors") );
References createDensityQureg(), createQureg(), destroyQureg(), getImagAmp(), initDebugState(), NUM_QUBITS, QUEST_ENV, and toQVector().
◆ TEST_CASE() [52/106]
TEST_CASE |
( |
"getNumAmps" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [53/106]
TEST_CASE |
( |
"getNumQubits" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [54/106]
TEST_CASE |
( |
"getProbAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getProbAmp
- Author
- Tyson Jones
Definition at line 1322 of file test_calculations.cpp.
1326 SECTION(
"correctness" ) {
1328 SECTION(
"state-vector" ) {
1333 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1334 qreal refCalc = pow(abs(ref[ind]), 2);
1335 REQUIRE(
getProbAmp(vec,ind) == Approx(refCalc) );
1338 SECTION(
"input validation" ) {
1340 SECTION(
"state index" ) {
1343 REQUIRE_THROWS_WITH(
getProbAmp(vec,ind), Contains(
"Invalid amplitude index") );
1345 SECTION(
"density-matrix" ) {
1348 REQUIRE_THROWS_WITH(
getProbAmp(mat,0), Contains(
"valid only for state-vectors") );
References createDensityQureg(), createQureg(), destroyQureg(), getProbAmp(), initDebugState(), NUM_QUBITS, qreal, QUEST_ENV, and toQVector().
◆ TEST_CASE() [55/106]
TEST_CASE |
( |
"getRealAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getRealAmp
- Author
- Tyson Jones
Definition at line 1361 of file test_calculations.cpp.
1365 SECTION(
"correctness" ) {
1367 SECTION(
"state-vector" ) {
1372 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1373 REQUIRE(
getRealAmp(vec,ind) == real(ref[ind]) );
1376 SECTION(
"input validation" ) {
1378 SECTION(
"state index" ) {
1381 REQUIRE_THROWS_WITH(
getRealAmp(vec,ind), Contains(
"Invalid amplitude index") );
1383 SECTION(
"density-matrix" ) {
1386 REQUIRE_THROWS_WITH(
getRealAmp(mat,0), Contains(
"valid only for state-vectors") );
References createDensityQureg(), createQureg(), destroyQureg(), getRealAmp(), initDebugState(), NUM_QUBITS, QUEST_ENV, and toQVector().
◆ TEST_CASE() [56/106]
TEST_CASE |
( |
"getStaticComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [57/106]
TEST_CASE |
( |
"hadamard" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- hadamard
- Author
- Tyson Jones
Definition at line 812 of file test_unitaries.cpp.
818 SECTION(
"correctness" ) {
822 SECTION(
"state-vector ") {
826 REQUIRE(
areEqual(quregVec, refVec) );
828 SECTION(
"density-matrix" ) {
832 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
835 SECTION(
"input validation" ) {
837 SECTION(
"qubit indices" ) {
840 REQUIRE_THROWS_WITH(
hadamard(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, hadamard(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [58/106]
TEST_CASE |
( |
"initBlankState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [59/106]
TEST_CASE |
( |
"initClassicalState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [60/106]
TEST_CASE |
( |
"initComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [61/106]
TEST_CASE |
( |
"initDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- initDiagonalOp
- Author
- Tyson Jones
Definition at line 601 of file test_data_structures.cpp.
608 SECTION(
"correctness" ) {
611 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
614 long long int len = (1LL << numQb);
618 for (n=0; n<len; n++) {
619 reals[n] = (
qreal) n;
620 imags[n] = (
qreal) -2*n;
642 REQUIRE(
areEqual(prodRef, result) );
References applyDiagonalOp(), areEqual(), calcLog2(), copyStateFromGPU(), copyStateToGPU(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), initDiagonalOp(), Qureg::numAmpsPerChunk, QuESTEnv::numRanks, qreal, QUEST_ENV, Qureg::stateVec, toQMatrix(), and toQVector().
◆ TEST_CASE() [62/106]
TEST_CASE |
( |
"initPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- initPauliHamil
- Author
- Tyson Jones
Definition at line 655 of file test_data_structures.cpp.
657 SECTION(
"correctness" ) {
661 qreal coeffs[] = {-5, 5};
668 for (
int t=0; t<2; t++) {
670 for (
int q=0; q<3; q++) {
672 REQUIRE( codes[ind] == hamil.
pauliCodes[ind] );
678 SECTION(
"input validation" ) {
680 SECTION(
"parameters" ) {
689 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"number of qubits") && Contains(
"strictly positive") );
693 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"terms") && Contains(
"strictly positive") );
695 SECTION(
"Pauli codes" ) {
699 int numCodes = numQb * numTerms;
700 qreal coeffs[numTerms];
704 for (
int i=0; i<numCodes; i++)
706 codes[GENERATE_COPY( range(0,numCodes) )] = (
pauliOpType) GENERATE( -1, 4 );
709 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"Invalid Pauli code") );
References createPauliHamil(), destroyPauliHamil(), initPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PauliHamil::pauliCodes, qreal, and PauliHamil::termCoeffs.
◆ TEST_CASE() [63/106]
TEST_CASE |
( |
"initPlusState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [64/106]
TEST_CASE |
( |
"initPureState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- initPureState
- Author
- Tyson Jones
Definition at line 211 of file test_state_initialisations.cpp.
216 SECTION(
"correctness" ) {
218 SECTION(
"state-vector" ) {
239 SECTION(
"density-matrix" ) {
251 for (
size_t i=0; i<matRef.size(); i++)
252 for (
size_t j=0; j<matRef.size(); j++)
253 matRef[i][j] = copy1[i] * conj(copy1[j]);
260 SECTION(
"input validation" ) {
262 SECTION(
"qureg types" ) {
265 REQUIRE_THROWS_WITH(
initPureState(vec1, mat1), Contains(
"Second argument must be a state-vector") );
266 REQUIRE_THROWS_WITH(
initPureState(mat1, mat1), Contains(
"Second argument must be a state-vector") );
268 SECTION(
"qureg dimensions" ) {
271 REQUIRE_THROWS_WITH(
initPureState(vec1, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
272 REQUIRE_THROWS_WITH(
initPureState(mat1, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getZeroMatrix(), initBlankState(), initDebugState(), initPureState(), NUM_QUBITS, QUEST_ENV, and toQVector().
◆ TEST_CASE() [65/106]
TEST_CASE |
( |
"initStateFromAmps" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- initStateFromAmps
- Author
- Tyson Jones
Definition at line 286 of file test_state_initialisations.cpp.
290 SECTION(
"correctness" ) {
292 SECTION(
"state-vector" ) {
301 vecRef[i] = (ampsRe[i]) + 1i*(ampsIm[i]);
309 SECTION(
"input validation" ) {
311 SECTION(
"density-matrix" ) {
314 REQUIRE_THROWS_WITH(
initStateFromAmps(mat, NULL, NULL), Contains(
"valid only for state-vectors") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), initBlankState(), initStateFromAmps(), NUM_QUBITS, Qureg::numAmpsTotal, qreal, and QUEST_ENV.
◆ TEST_CASE() [66/106]
TEST_CASE |
( |
"initZeroState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- initZeroState
- Author
- Tyson Jones
Definition at line 327 of file test_state_initialisations.cpp.
332 SECTION(
"correctness" ) {
334 SECTION(
"state-vector" ) {
343 SECTION(
"density-matrix" ) {
353 SECTION(
"input validation" ) {
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getZeroMatrix(), initBlankState(), initZeroState(), NUM_QUBITS, Qureg::numAmpsTotal, Qureg::numQubitsRepresented, and QUEST_ENV.
◆ TEST_CASE() [67/106]
TEST_CASE |
( |
"measure" |
, |
|
|
"" |
[gates] |
|
) |
| |
- See also
- measure
- Author
- Tyson Jones
Definition at line 121 of file test_gates.cpp.
126 SECTION(
"correctness" ) {
131 GENERATE( range(0,10) );
133 SECTION(
"state-vector" ) {
138 int outcome =
measure(vec, qubit);
139 REQUIRE( (outcome == 0 || outcome == 1) );
143 for (
size_t ind=0; ind<vecRef.size(); ind++) {
144 int bit = (ind >> qubit) & 1;
146 prob += pow(abs(vecRef[ind]), 2);
149 REQUIRE( prob > REAL_EPS );
152 for (
size_t ind=0; ind<vecRef.size(); ind++) {
153 int bit = (ind >> qubit) & 1;
155 vecRef[ind] /= sqrt(prob);
161 SECTION(
"density-matrix" ) {
166 int outcome =
measure(mat, qubit);
167 REQUIRE( (outcome == 0 || outcome == 1) );
171 for (
size_t ind=0; ind<matRef.size(); ind++) {
172 int bit = (ind >> qubit) & 1;
174 prob += real(matRef[ind][ind]);
177 REQUIRE( prob > REAL_EPS );
180 for (
size_t r=0; r<matRef.size(); r++) {
181 for (
size_t c=0; c<matRef.size(); c++) {
182 int ketBit = (c >> qubit) & 1;
183 int braBit = (r >> qubit) & 1;
185 if (ketBit == outcome && braBit == outcome)
186 matRef[r][c] /= prob;
195 SECTION(
"input validation" ) {
197 SECTION(
"qubit index" ) {
200 REQUIRE_THROWS_WITH(
measure(vec, qubit), Contains(
"Invalid target qubit") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), measure(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [68/106]
TEST_CASE |
( |
"measureWithStats" |
, |
|
|
"" |
[gates] |
|
) |
| |
- See also
- measureWithStats
- Author
- Tyson Jones
Definition at line 213 of file test_gates.cpp.
218 SECTION(
"correctness" ) {
223 GENERATE( range(0,10) );
225 SECTION(
"state-vector" ) {
232 REQUIRE( (outcome == 0 || outcome == 1) );
236 for (
size_t ind=0; ind<vecRef.size(); ind++) {
237 int bit = (ind >> qubit) & 1;
239 prob += pow(abs(vecRef[ind]), 2);
242 REQUIRE( prob == Approx(res) );
245 for (
size_t ind=0; ind<vecRef.size(); ind++) {
246 int bit = (ind >> qubit) & 1;
248 vecRef[ind] /= sqrt(prob);
254 SECTION(
"density-matrix" ) {
261 REQUIRE( (outcome == 0 || outcome == 1) );
265 for (
size_t ind=0; ind<matRef.size(); ind++) {
266 int bit = (ind >> qubit) & 1;
268 prob += real(matRef[ind][ind]);
271 REQUIRE( prob == Approx(res) );
274 for (
size_t r=0; r<matRef.size(); r++) {
275 for (
size_t c=0; c<matRef.size(); c++) {
276 int ketBit = (c >> qubit) & 1;
277 int braBit = (r >> qubit) & 1;
279 if (ketBit == outcome && braBit == outcome)
280 matRef[r][c] /= prob;
289 SECTION(
"input validation" ) {
291 SECTION(
"qubit index" ) {
295 REQUIRE_THROWS_WITH(
measureWithStats(vec, qubit, &res), Contains(
"Invalid target qubit") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), measureWithStats(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [69/106]
TEST_CASE |
( |
"mixDamping" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixDamping
- Author
- Tyson Jones
Definition at line 23 of file test_decoherence.cpp.
27 SECTION(
"correctness" ) {
34 QMatrix kraus0{{1,0},{0,sqrt(1-prob)}};
37 QMatrix kraus1{{0,sqrt(prob)},{0,0}};
44 SECTION(
"validation ") {
46 SECTION(
"qubit index" ) {
49 REQUIRE_THROWS_WITH(
mixDamping(qureg, target, 0), Contains(
"Invalid target") );
52 SECTION(
"probability" ) {
54 REQUIRE_THROWS_WITH(
mixDamping(qureg, 0, -.1), Contains(
"Probabilities") );
55 REQUIRE_THROWS_WITH(
mixDamping(qureg, 0, 1.1), Contains(
"Probabilities") );
57 SECTION(
"density-matrix" ) {
60 REQUIRE_THROWS_WITH(
mixDamping(vec, 0, 0), Contains(
"density matrices") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomReal(), mixDamping(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [70/106]
TEST_CASE |
( |
"mixDensityMatrix" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixDensityMatrix
- Author
- Tyson Jones
Definition at line 73 of file test_decoherence.cpp.
82 SECTION(
"correctness" ) {
85 qreal prob = GENERATE( 0., 1., take(10, random(0.,1.)) );
89 ref1 = (1-prob)*ref1 + (prob)*ref2;
95 SECTION(
"input validation" ) {
97 SECTION(
"probabilities") {
99 qreal prob = GENERATE( -0.1, 1.1 );
100 REQUIRE_THROWS_WITH(
mixDensityMatrix(qureg1, prob, qureg2), Contains(
"Probabilities") );
102 SECTION(
"density matrices" ) {
106 REQUIRE_THROWS_WITH(
mixDensityMatrix(qureg1, 0, state1), Contains(
"density matrices") );
107 REQUIRE_THROWS_WITH(
mixDensityMatrix(state1, 0, qureg1), Contains(
"density matrices") );
111 REQUIRE_THROWS_WITH(
mixDensityMatrix(state1, 0, state2), Contains(
"density matrices") );
116 SECTION(
"matching dimensions" ) {
119 REQUIRE_THROWS_WITH(
mixDensityMatrix(qureg1, 0, qureg3), Contains(
"Dimensions") );
120 REQUIRE_THROWS_WITH(
mixDensityMatrix(qureg3, 0, qureg1), Contains(
"Dimensions") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), initDebugState(), mixDensityMatrix(), NUM_QUBITS, Qureg::numQubitsRepresented, qreal, QUEST_ENV, and toQMatrix().
◆ TEST_CASE() [71/106]
TEST_CASE |
( |
"mixDephasing" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixDephasing
- Author
- Tyson Jones
Definition at line 134 of file test_decoherence.cpp.
138 SECTION(
"correctness " ) {
147 ref = ((1 - prob) * ref) + (prob * phaseRef);
151 SECTION(
"validation ") {
153 SECTION(
"qubit index" ) {
156 REQUIRE_THROWS_WITH(
mixDephasing(qureg, target, 0), Contains(
"Invalid target") );
159 SECTION(
"probability" ) {
161 REQUIRE_THROWS_WITH(
mixDephasing(qureg, 0, -.1), Contains(
"Probabilities") );
162 REQUIRE_THROWS_WITH(
mixDephasing(qureg, 0, .6), Contains(
"probability") && Contains(
"cannot exceed 1/2") );
164 SECTION(
"density-matrix" ) {
167 REQUIRE_THROWS_WITH(
mixDephasing(vec, 0, 0), Contains(
"density matrices") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomReal(), mixDephasing(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [72/106]
TEST_CASE |
( |
"mixDepolarising" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixDepolarising
- Author
- Tyson Jones
Definition at line 180 of file test_decoherence.cpp.
184 SECTION(
"correctness " ) {
196 ref = ((1 - prob) * ref) + ((prob/3.) * ( xRef + yRef + zRef));
200 SECTION(
"validation ") {
202 SECTION(
"qubit index" ) {
205 REQUIRE_THROWS_WITH(
mixDepolarising(qureg, target, 0), Contains(
"Invalid target") );
208 SECTION(
"probability" ) {
210 REQUIRE_THROWS_WITH(
mixDepolarising(qureg, 0, -.1), Contains(
"Probabilities") );
211 REQUIRE_THROWS_WITH(
mixDepolarising(qureg, 0, .76), Contains(
"probability") && Contains(
"cannot exceed 3/4") );
213 SECTION(
"density-matrix" ) {
216 REQUIRE_THROWS_WITH(
mixDepolarising(vec, 0, 0), Contains(
"density matrices") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomReal(), mixDepolarising(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [73/106]
TEST_CASE |
( |
"mixKrausMap" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixKrausMap
- Author
- Tyson Jones
Definition at line 520 of file test_decoherence.cpp.
524 SECTION(
"correctness" ) {
527 int numOps = GENERATE( range(1,5) );
531 for (
int i=0; i<numOps; i++)
537 for (
int i=0; i<numOps; i++) {
542 for (
int i=0; i<numOps; i++)
545 REQUIRE(
areEqual(qureg, ref, 10*REAL_EPS) );
547 SECTION(
"input validation" ) {
549 SECTION(
"number of operators" ) {
551 int numOps = GENERATE( 0, 5 );
552 REQUIRE_THROWS_WITH(
mixKrausMap(qureg, 0, NULL, numOps), Contains(
"operators") );
554 SECTION(
"trace preserving" ) {
557 int numOps = GENERATE( range(1,5) );
560 for (
int i=0; i<numOps; i++)
564 ops[GENERATE_REF( range(0,numOps) )].
real[0][0] = 0;
565 REQUIRE_THROWS_WITH(
mixKrausMap(qureg, 0, ops, numOps), Contains(
"trace preserving") );
568 SECTION(
"qubit index" ) {
571 REQUIRE_THROWS_WITH(
mixKrausMap(qureg, target, NULL, 1), Contains(
"Invalid target qubit") );
573 SECTION(
"density-matrix" ) {
576 REQUIRE_THROWS_WITH(
mixKrausMap(vec, 0, NULL, 1), Contains(
"density matrices") );
579 SECTION(
"operators fit in node" ) {
581 qureg.numAmpsPerChunk = 3;
582 REQUIRE_THROWS_WITH(
mixKrausMap(qureg, 0, NULL, 1), Contains(
"targets too many qubits") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomKrausMap(), getZeroMatrix(), mixKrausMap(), NUM_QUBITS, PREPARE_TEST, QUEST_ENV, ComplexMatrix2::real, and toComplexMatrix2().
◆ TEST_CASE() [74/106]
TEST_CASE |
( |
"mixMultiQubitKrausMap" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixMultiQubitKrausMap
- Author
- Tyson Jones
Definition at line 229 of file test_decoherence.cpp.
235 int maxNumTargs =
calcLog2(qureg.numAmpsPerChunk) / 2;
237 SECTION(
"correctness" ) {
243 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
250 int maxNumOps = (2*numTargs)*(2*numTargs);
251 int numOps = GENERATE_COPY( 1, maxNumOps, take(2,random(1,maxNumOps)) );
258 for (
int i=0; i<numOps; i++) {
267 for (
int i=0; i<numOps; i++) {
272 for (
int i=0; i<numOps; i++)
275 REQUIRE(
areEqual(qureg, ref, 1E2*REAL_EPS) );
278 for (
int i=0; i<numOps; i++)
281 SECTION(
"input validation" ) {
283 SECTION(
"repetition of target" ) {
292 int copyInd = GENERATE_COPY( filter([=](
int i){
return i!=badInd; }, range(0,
NUM_QUBITS)) );
293 targs[badInd] = targs[copyInd];
297 SECTION(
"qubit indices" ) {
309 SECTION(
"number of operators" ) {
311 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
312 int maxNumOps = (2*numTargs)*(2*numTargs);
313 int numOps = GENERATE_REF( -1, 0, maxNumOps + 1 );
317 for (
int i=0; i<numTargs; i++)
319 REQUIRE_THROWS_WITH(
mixMultiQubitKrausMap(qureg, targs, numTargs, NULL, numOps), Contains(
"operators may be specified") );
321 SECTION(
"initialisation of operators" ) {
330 int numOps = (2*numTargs)*(2*numTargs);
334 for (
int i=0; i<numOps; i++)
335 ops[i].numQubits = numTargs;
338 ops[GENERATE_COPY( range(0,numTargs) )].
real = NULL;
342 for (
int i=0; i<numTargs; i++)
345 REQUIRE_THROWS_WITH(
mixMultiQubitKrausMap(qureg, targs, numTargs, ops, numOps), Contains(
"ComplexMatrixN") && Contains(
"created") );
347 SECTION(
"dimension of operators" ) {
351 int numOps = (2*numTargs)*(2*numTargs);
353 for (
int i=0; i<numOps; i++)
357 int badInd = GENERATE_COPY( range(0,numTargs) );
363 for (
int i=0; i<numTargs; i++)
366 REQUIRE_THROWS_WITH(
mixMultiQubitKrausMap(qureg, targs, numTargs, ops, numOps), Contains(
"same number of qubits") );
368 for (
int i=0; i<numOps; i++)
371 SECTION(
"trace preserving" ) {
373 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
374 int maxNumOps = (2*numTargs) * (2*numTargs);
375 int numOps = GENERATE_COPY( 1, 2, maxNumOps );
380 for (
int i=0; i<numOps; i++) {
386 ops[GENERATE_REF( range(0,numOps) )].
real[0][0] = 0;
390 for (
int i=0; i<numTargs; i++)
393 REQUIRE_THROWS_WITH(
mixMultiQubitKrausMap(qureg, targs, numTargs, ops, numOps), Contains(
"trace preserving") );
395 for (
int i=0; i<numOps; i++)
398 SECTION(
"density-matrix" ) {
411 SECTION(
"operator fits in node" ) {
424 ops[0].real[i][i] = 1;
427 qureg.numAmpsPerChunk = minAmps - 1;
References applyReferenceOp(), areEqual(), calcLog2(), createComplexMatrixN(), createQureg(), destroyComplexMatrixN(), destroyQureg(), getRandomKrausMap(), getZeroMatrix(), mixMultiQubitKrausMap(), NUM_QUBITS, PREPARE_TEST, QUEST_ENV, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [75/106]
TEST_CASE |
( |
"mixPauli" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixPauli
- Author
- Tyson Jones
Definition at line 442 of file test_decoherence.cpp.
446 SECTION(
"correctness" ) {
454 qreal max1 = (max0 - probs[0])/2.;
456 qreal max2 = (max1 - probs[1])/2.;
460 int inds[3] = {0,1,2};
461 std::shuffle(inds,inds+3, std::default_random_engine(1E5 * target));
462 qreal probX = probs[inds[0]];
463 qreal probY = probs[inds[1]];
464 qreal probZ = probs[inds[2]];
466 mixPauli(qureg, target, probX, probY, probZ);
474 ref = ((1 - probX - probY - probZ) * ref) +
475 (probX * xRef) + (probY * yRef) + (probZ * zRef);
479 SECTION(
"input validation" ) {
481 SECTION(
"qubit index" ) {
484 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, 0, 0, 0), Contains(
"Invalid target") );
487 SECTION(
"probability" ) {
492 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, -.1, 0, 0), Contains(
"Probabilities") );
493 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, 0, -.1, 0), Contains(
"Probabilities") );
494 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, 0, 0, -.1), Contains(
"Probabilities") );
497 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, .6, 0, 0), Contains(
"cannot exceed the probability") );
498 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, 0, .6, 0), Contains(
"cannot exceed the probability") );
499 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, 0, 0, .6), Contains(
"cannot exceed the probability") );
502 REQUIRE_THROWS_WITH(
mixPauli(qureg, target, .3, .3, .3), Contains(
"cannot exceed the probability") );
504 SECTION(
"density-matrix" ) {
507 REQUIRE_THROWS_WITH(
mixPauli(vec, 0, 0, 0, 0), Contains(
"density matrices") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomReal(), mixPauli(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [76/106]
TEST_CASE |
( |
"mixTwoQubitDephasing" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixTwoQubitDephasing
- Author
- Tyson Jones
Definition at line 594 of file test_decoherence.cpp.
598 SECTION(
"correctness" ) {
601 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
615 ref = ((1 - prob) * ref) + (prob/3.) * (z1Ref + z2Ref + z1z2Ref);
619 SECTION(
"input validation" ) {
621 SECTION(
"qubit indices" ) {
627 SECTION(
"target collision" ) {
630 REQUIRE_THROWS_WITH(
mixTwoQubitDephasing(qureg, targ, targ, 0), Contains(
"target") && Contains(
"unique") );
632 SECTION(
"probability" ) {
635 REQUIRE_THROWS_WITH(
mixTwoQubitDephasing(qureg, 0, 1, 3/4. + .01), Contains(
"probability") && Contains(
"cannot exceed 3/4") );
637 SECTION(
"density-matrix" ) {
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomReal(), mixTwoQubitDephasing(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [77/106]
TEST_CASE |
( |
"mixTwoQubitDepolarising" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixTwoQubitDepolarising
- Author
- Tyson Jones
Definition at line 653 of file test_decoherence.cpp.
657 SECTION(
"correctness" ) {
660 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
672 int targs[2] = {targ1, targ2};
674 ref = (1 - (16/15.)*prob) * ref;
675 for (
int i=0; i<4; i++) {
676 for (
int j=0; j<4; j++) {
680 ref += (prob/15.) * term;
684 REQUIRE(
areEqual(qureg, ref, 1E4*REAL_EPS) );
686 SECTION(
"input validation" ) {
688 SECTION(
"qubit indices" ) {
694 SECTION(
"target collision" ) {
697 REQUIRE_THROWS_WITH(
mixTwoQubitDepolarising(qureg, targ, targ, 0), Contains(
"target") && Contains(
"unique") );
699 SECTION(
"probability" ) {
702 REQUIRE_THROWS_WITH(
mixTwoQubitDepolarising(qureg, 0, 1, 15/16. + .01), Contains(
"probability") && Contains(
"cannot exceed 15/16") );
704 SECTION(
"density-matrix" ) {
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getKroneckerProduct(), getRandomReal(), mixTwoQubitDepolarising(), NUM_QUBITS, PREPARE_TEST, qreal, and QUEST_ENV.
◆ TEST_CASE() [78/106]
TEST_CASE |
( |
"mixTwoQubitKrausMap" |
, |
|
|
"" |
[decoherence] |
|
) |
| |
- See also
- mixTwoQubitKrausMap
- Author
- Tyson Jones
Definition at line 720 of file test_decoherence.cpp.
724 SECTION(
"correctness" ) {
727 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
728 int numOps = GENERATE( range(1,17) );
732 for (
int i=0; i<numOps; i++)
737 int targs[2] = {targ1, targ2};
739 for (
int i=0; i<numOps; i++) {
744 for (
int i=0; i<numOps; i++)
747 REQUIRE(
areEqual(qureg, ref, 10*REAL_EPS) );
749 SECTION(
"input validation" ) {
751 SECTION(
"number of operators" ) {
753 int numOps = GENERATE( 0, 17 );
754 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, 0,1, NULL, numOps), Contains(
"operators") );
756 SECTION(
"trace preserving" ) {
759 int numOps = GENERATE( range(1,16) );
762 for (
int i=0; i<numOps; i++)
766 ops[GENERATE_REF( range(0,numOps) )].
real[0][0] = 0;
767 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, 0,1, ops, numOps), Contains(
"trace preserving") );
769 SECTION(
"target collision" ) {
772 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, target, target, NULL, 1), Contains(
"target qubits") && Contains(
"unique") );
774 SECTION(
"qubit index" ) {
777 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, 0,target, NULL, 1), Contains(
"Invalid target qubit") );
778 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, target,0, NULL, 1), Contains(
"Invalid target qubit") );
780 SECTION(
"density-matrix" ) {
783 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(vec, 0,1, NULL, 1), Contains(
"density matrices") );
786 SECTION(
"operators fit in node" ) {
788 qureg.numAmpsPerChunk = 15;
789 REQUIRE_THROWS_WITH(
mixTwoQubitKrausMap(qureg, 0,1, NULL, 1), Contains(
"targets too many qubits") );
References applyReferenceOp(), areEqual(), createQureg(), destroyQureg(), getRandomKrausMap(), getZeroMatrix(), mixTwoQubitKrausMap(), NUM_QUBITS, PREPARE_TEST, QUEST_ENV, ComplexMatrix4::real, and toComplexMatrix4().
◆ TEST_CASE() [79/106]
TEST_CASE |
( |
"multiControlledMultiQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledMultiQubitUnitary
- Author
- Tyson Jones
Definition at line 852 of file test_unitaries.cpp.
857 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
861 SECTION(
"correctness" ) {
864 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
866 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
870 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
877 SECTION(
"state-vector" ) {
881 REQUIRE(
areEqual(quregVec, refVec) );
883 SECTION(
"density-matrix" ) {
887 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
891 SECTION(
"input validation" ) {
893 SECTION(
"number of targets" ) {
897 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
906 SECTION(
"repetition in targets" ) {
910 int targs[] = {1,2,2};
917 SECTION(
"number of controls" ) {
928 SECTION(
"repetition in controls" ) {
930 int ctrls[] = {0,1,1};
938 SECTION(
"control and target collision" ) {
940 int ctrls[] = {0,1,2};
941 int targs[] = {3,1,4};
945 REQUIRE_THROWS_WITH(
multiControlledMultiQubitUnitary(quregVec, ctrls, 3, targs, 3, matr), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
948 SECTION(
"qubit indices" ) {
959 qb1[GENERATE_COPY(range(0,numQb))] = inv;
965 SECTION(
"unitarity" ) {
968 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
970 for (
int i=0; i<numTargs; i++)
977 SECTION(
"unitary creation" ) {
980 int targs[3] = {1,2,3};
992 SECTION(
"unitary dimensions" ) {
995 int targs[2] = {1,2};
1002 SECTION(
"unitary fits in node" ) {
1005 quregVec.numAmpsPerChunk = 1;
1007 int targs[2] = {1,2};
References applyReferenceOp(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomUnitary(), ComplexMatrixN::imag, multiControlledMultiQubitUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [80/106]
TEST_CASE |
( |
"multiControlledPhaseFlip" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledPhaseFlip
- Author
- Tyson Jones
Definition at line 1024 of file test_unitaries.cpp.
1031 SECTION(
"correctness" ) {
1034 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1037 SECTION(
"state-vector" ) {
1041 REQUIRE(
areEqual(quregVec, refVec) );
1043 SECTION(
"density-matrix" ) {
1047 REQUIRE(
areEqual(quregMatr, refMatr) );
1050 SECTION(
"input validation" ) {
1052 SECTION(
"number of controls" ) {
1054 int numCtrls = GENERATE( -1, 0,
NUM_QUBITS+1 );
1058 SECTION(
"repetition of controls" ) {
1061 int ctrls[] = {0,1,1};
1064 SECTION(
"qubit indices" ) {
1067 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
References applyReferenceOp(), areEqual(), CLEANUP_TEST, multiControlledPhaseFlip(), NUM_QUBITS, PREPARE_TEST, and sublists().
◆ TEST_CASE() [81/106]
TEST_CASE |
( |
"multiControlledPhaseShift" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledPhaseShift
- Author
- Tyson Jones
Definition at line 1080 of file test_unitaries.cpp.
1086 SECTION(
"correctness" ) {
1089 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1092 SECTION(
"state-vector" ) {
1096 REQUIRE(
areEqual(quregVec, refVec) );
1098 SECTION(
"density-matrix" ) {
1102 REQUIRE(
areEqual(quregMatr, refMatr) );
1105 SECTION(
"input validation" ) {
1107 SECTION(
"number of controls" ) {
1109 int numCtrls = GENERATE( -1, 0,
NUM_QUBITS+1 );
1111 REQUIRE_THROWS_WITH(
multiControlledPhaseShift(quregVec, ctrls, numCtrls, param), Contains(
"Invalid number of qubits"));
1113 SECTION(
"repetition of controls" ) {
1116 int ctrls[] = {0,1,1};
1119 SECTION(
"qubit indices" ) {
1122 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), multiControlledPhaseShift(), NUM_QUBITS, PREPARE_TEST, qreal, and sublists().
◆ TEST_CASE() [82/106]
TEST_CASE |
( |
"multiControlledTwoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledTwoQubitUnitary
- Author
- Tyson Jones
Definition at line 1135 of file test_unitaries.cpp.
1140 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
1146 SECTION(
"correctness" ) {
1150 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
1151 int targs[] = {targ1, targ2};
1152 int numCtrls = GENERATE( range(1,
NUM_QUBITS-1) );
1155 SECTION(
"state-vector" ) {
1159 REQUIRE(
areEqual(quregVec, refVec) );
1161 SECTION(
"density-matrix" ) {
1165 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1168 SECTION(
"input validation" ) {
1170 SECTION(
"number of controls" ) {
1177 SECTION(
"repetition of controls" ) {
1180 int ctrls[] = {0,1,1};
1185 SECTION(
"repetition of targets" ) {
1188 int ctrls[] = {0,1,2};
1193 SECTION(
"control and target collision" ) {
1196 int ctrls[] = {0,1,2};
1198 int targ2 = ctrls[GENERATE_COPY( range(0,numCtrls) )];
1201 SECTION(
"qubit indices" ) {
1207 int ctrls[] = { 2, 3, 4 };
1213 ctrls[numCtrls-1] = inv;
1216 SECTION(
"unitarity " ) {
1219 matr.
real[0][0] = 0;
1222 SECTION(
"unitary fits in node" ) {
1225 quregVec.numAmpsPerChunk = 1;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), multiControlledTwoQubitUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix4::real, sublists(), and toComplexMatrix4().
◆ TEST_CASE() [83/106]
TEST_CASE |
( |
"multiControlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledUnitary
- Author
- Tyson Jones
Definition at line 1239 of file test_unitaries.cpp.
1247 SECTION(
"correctness" ) {
1249 int target = GENERATE( range(0,
NUM_QUBITS) );
1250 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1253 SECTION(
"state-vector" ) {
1257 REQUIRE(
areEqual(quregVec, refVec) );
1259 SECTION(
"density-matrix" ) {
1263 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1266 SECTION(
"input validation" ) {
1268 SECTION(
"number of controls" ) {
1272 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, numCtrls, 0, matr), Contains(
"Invalid number of control"));
1274 SECTION(
"repetition of controls" ) {
1276 int ctrls[] = {0,1,1};
1277 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, 2, matr), Contains(
"control") && Contains(
"unique"));
1279 SECTION(
"control and target collision" ) {
1281 int ctrls[] = {0,1,2};
1282 int targ = ctrls[GENERATE( range(0,3) )];
1283 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, targ, matr), Contains(
"Control") && Contains(
"target") );
1285 SECTION(
"qubit indices" ) {
1287 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
1292 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, targ, matr), Contains(
"Invalid target") );
1294 SECTION(
"unitarity" ) {
1296 matr.
real[0][0] = 0;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), multiControlledUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, sublists(), and toComplexMatrix2().
◆ TEST_CASE() [84/106]
TEST_CASE |
( |
"multiQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiQubitUnitary
- Author
- Tyson Jones
Definition at line 1310 of file test_unitaries.cpp.
1315 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
1317 SECTION(
"correctness" ) {
1320 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
1328 SECTION(
"state-vector" ) {
1332 REQUIRE(
areEqual(quregVec, refVec) );
1334 SECTION(
"density-matrix" ) {
1338 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1342 SECTION(
"input validation" ) {
1344 SECTION(
"number of targets" ) {
1347 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1351 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"Invalid number of target"));
1354 SECTION(
"repetition in targets" ) {
1357 int targs[] = {1,2,2};
1360 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
1363 SECTION(
"qubit indices" ) {
1366 int targs[] = {1,2,3};
1370 targs[GENERATE_COPY( range(0,numTargs) )] = inv;
1371 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"Invalid target") );
1375 SECTION(
"unitarity" ) {
1377 int numTargs = GENERATE_COPY( range(1,maxNumTargs) );
1378 int targs[numTargs];
1379 for (
int i=0; i<numTargs; i++)
1384 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"unitary") );
1387 SECTION(
"unitary creation" ) {
1390 int targs[] = {1,2,3};
1400 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"created") );
1402 SECTION(
"unitary dimensions" ) {
1404 int targs[2] = {1,2};
1407 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, 2, matr), Contains(
"matrix size"));
1410 SECTION(
"unitary fits in node" ) {
1413 quregVec.numAmpsPerChunk = 1;
1416 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, qb, 2, matr), Contains(
"targets too many qubits"));
References applyReferenceOp(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomUnitary(), ComplexMatrixN::imag, multiQubitUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [85/106]
TEST_CASE |
( |
"multiRotatePauli" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiRotatePauli
- Author
- Tyson Jones
Definition at line 1429 of file test_unitaries.cpp.
1434 SECTION(
"correctness" ) {
1436 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
1444 GENERATE( range(0,10) );
1446 for (
int i=0; i<numTargs; i++)
1450 int refTargs[numTargs];
1451 int numRefTargs = 0;
1454 QMatrix yMatr{{0,-1i},{1i,0}};
1459 for (
int i=0; i<numTargs; i++) {
1461 if (paulis[i] ==
PAULI_I)
continue;
1462 if (paulis[i] ==
PAULI_X) fac = xMatr;
1463 if (paulis[i] ==
PAULI_Y) fac = yMatr;
1464 if (paulis[i] ==
PAULI_Z) fac = zMatr;
1468 refTargs[numRefTargs++] = targs[i];
1473 if (numRefTargs > 0)
1476 SECTION(
"state-vector" ) {
1479 if (numRefTargs > 0)
1481 REQUIRE(
areEqual(quregVec, refVec) );
1483 SECTION(
"density-matrix" ) {
1486 if (numRefTargs > 0)
1488 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1491 SECTION(
"input validation" ) {
1493 SECTION(
"number of targets" ) {
1495 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1498 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid number of target"));
1501 SECTION(
"repetition of targets" ) {
1504 int targs[3] = {0, 1, 1};
1506 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"target") && Contains(
"unique"));
1508 SECTION(
"qubit indices" ) {
1511 int targs[3] = {0, 1, 2};
1512 targs[GENERATE_COPY(range(0,numTargs))] = GENERATE( -1,
NUM_QUBITS );
1514 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid target"));
1516 SECTION(
"pauli codes" ) {
1518 int targs[3] = {0, 1, 2};
1520 paulis[GENERATE_COPY(range(0,numTargs))] = (
pauliOpType) GENERATE( -1, 4 );
1521 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid Pauli code"));
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfPauliMatrix(), getKroneckerProduct(), getRandomInt(), getRandomReal(), multiRotatePauli(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PREPARE_TEST, qreal, and sublists().
◆ TEST_CASE() [86/106]
TEST_CASE |
( |
"multiRotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiRotateZ
- Author
- Tyson Jones
Definition at line 1533 of file test_unitaries.cpp.
1538 SECTION(
"correctness" ) {
1540 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
1546 for (
int t=0; t<numTargs-1; t++)
1550 QMatrix expArg = (-1i * param / 2.) *
1561 SECTION(
"state-vector" ) {
1565 REQUIRE(
areEqual(quregVec, refVec) );
1568 SECTION(
"density-matrix" ) {
1572 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
1575 SECTION(
"input validation" ) {
1577 SECTION(
"number of targets" ) {
1579 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1581 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"Invalid number of target"));
1584 SECTION(
"repetition of targets" ) {
1587 int targs[3] = {0, 1, 1};
1588 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"target") && Contains(
"unique"));
1590 SECTION(
"qubit indices" ) {
1593 int targs[3] = {0, 1, 2};
1594 targs[GENERATE_COPY(range(0,numTargs))] = GENERATE( -1,
NUM_QUBITS );
1595 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"Invalid target"));
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfDiagonalMatrix(), getFullOperatorMatrix(), getKroneckerProduct(), getRandomReal(), multiRotateZ(), NUM_QUBITS, PREPARE_TEST, qreal, and sublists().
◆ TEST_CASE() [87/106]
TEST_CASE |
( |
"multiStateControlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiStateControlledUnitary
- Author
- Tyson Jones
Definition at line 1607 of file test_unitaries.cpp.
1618 SECTION(
"correctness" ) {
1620 int target = GENERATE( range(0,
NUM_QUBITS) );
1621 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1623 int* ctrlState = GENERATE_COPY(
bitsets(numCtrls) );
1625 SECTION(
"state-vector" ) {
1630 for (
int i=0; i<numCtrls; i++)
1631 if (ctrlState[i] == 0)
1634 for (
int i=0; i<numCtrls; i++)
1635 if (ctrlState[i] == 0)
1638 REQUIRE(
areEqual(quregVec, refVec) );
1640 SECTION(
"density-matrix" ) {
1645 for (
int i=0; i<numCtrls; i++)
1646 if (ctrlState[i] == 0)
1649 for (
int i=0; i<numCtrls; i++)
1650 if (ctrlState[i] == 0)
1653 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1656 SECTION(
"input validation" ) {
1658 SECTION(
"number of controls" ) {
1663 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, numCtrls, 0, matr), Contains(
"Invalid number of control"));
1665 SECTION(
"repetition of controls" ) {
1667 int ctrls[] = {0,1,1};
1668 int ctrlState[] = {0, 1, 0};
1669 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, 3, 2, matr), Contains(
"control") && Contains(
"unique"));
1671 SECTION(
"control and target collision" ) {
1673 int ctrls[] = {0,1,2};
1674 int ctrlState[] = {0, 1, 0};
1675 int targ = ctrls[GENERATE( range(0,3) )];
1676 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, 3, targ, matr), Contains(
"Control") && Contains(
"target") );
1678 SECTION(
"qubit indices" ) {
1680 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
1681 int ctrlState[] = {0, 1, 0};
1688 SECTION(
"unitarity" ) {
1690 matr.
real[0][0] = 0;
1692 int ctrlState[1] = {0};
1695 SECTION(
"control state bits" ) {
1698 int ctrls[] = {0, 1, 2};
1699 int ctrlState[] = {0, 0, 0};
1703 ctrlState[2] = GENERATE(-1, 2);
References applyReferenceOp(), areEqual(), bitsets(), CLEANUP_TEST, getRandomUnitary(), multiStateControlledUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, sublists(), and toComplexMatrix2().
◆ TEST_CASE() [88/106]
TEST_CASE |
( |
"pauliX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliX
- Author
- Tyson Jones
Definition at line 1716 of file test_unitaries.cpp.
1721 SECTION(
"correctness" ) {
1723 int target = GENERATE( range(0,
NUM_QUBITS) );
1725 SECTION(
"state-vector" ) {
1727 pauliX(quregVec, target);
1729 REQUIRE(
areEqual(quregVec, refVec) );
1731 SECTION(
"density-matrix correctness" ) {
1733 pauliX(quregMatr, target);
1735 REQUIRE(
areEqual(quregMatr, refMatr) );
1738 SECTION(
"input validation" ) {
1740 SECTION(
"qubit indices" ) {
1743 REQUIRE_THROWS_WITH(
pauliX(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliX(), and PREPARE_TEST.
◆ TEST_CASE() [89/106]
TEST_CASE |
( |
"pauliY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliY
- Author
- Tyson Jones
Definition at line 1755 of file test_unitaries.cpp.
1760 SECTION(
"correctness" ) {
1762 int target = GENERATE( range(0,
NUM_QUBITS) );
1764 SECTION(
"state-vector" ) {
1766 pauliY(quregVec, target);
1768 REQUIRE(
areEqual(quregVec, refVec) );
1770 SECTION(
"density-matrix correctness" ) {
1772 pauliY(quregMatr, target);
1774 REQUIRE(
areEqual(quregMatr, refMatr) );
1777 SECTION(
"input validation" ) {
1779 SECTION(
"qubit indices" ) {
1782 REQUIRE_THROWS_WITH(
pauliY(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliY(), and PREPARE_TEST.
◆ TEST_CASE() [90/106]
TEST_CASE |
( |
"pauliZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliZ
- Author
- Tyson Jones
Definition at line 1794 of file test_unitaries.cpp.
1799 SECTION(
"correctness" ) {
1801 int target = GENERATE( range(0,
NUM_QUBITS) );
1803 SECTION(
"state-vector" ) {
1805 pauliZ(quregVec, target);
1807 REQUIRE(
areEqual(quregVec, refVec) );
1809 SECTION(
"density-matrix correctness" ) {
1811 pauliZ(quregMatr, target);
1813 REQUIRE(
areEqual(quregMatr, refMatr) );
1816 SECTION(
"input validation" ) {
1818 SECTION(
"qubit indices" ) {
1821 REQUIRE_THROWS_WITH(
pauliZ(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliZ(), and PREPARE_TEST.
◆ TEST_CASE() [91/106]
TEST_CASE |
( |
"phaseShift" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- phaseShift
- Author
- Tyson Jones
Definition at line 1833 of file test_unitaries.cpp.
1839 SECTION(
"correctness" ) {
1841 int target = GENERATE( range(0,
NUM_QUBITS) );
1843 SECTION(
"state-vector ") {
1847 REQUIRE(
areEqual(quregVec, refVec) );
1849 SECTION(
"density-matrix" ) {
1853 REQUIRE(
areEqual(quregMatr, refMatr) );
1856 SECTION(
"input validation" ) {
1858 SECTION(
"qubit indices" ) {
1861 REQUIRE_THROWS_WITH(
phaseShift(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), NUM_QUBITS, phaseShift(), PREPARE_TEST, and qreal.
◆ TEST_CASE() [92/106]
TEST_CASE |
( |
"rotateAroundAxis" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateAroundAxis
- Author
- Tyson Jones
Definition at line 1873 of file test_unitaries.cpp.
1883 qreal c = cos(param/2);
1884 qreal s = sin(param/2);
1885 qreal m = sqrt(vec.
x*vec.
x + vec.
y*vec.
y + vec.
z*vec.
z);
1886 QMatrix op{{c - 1i*vec.
z*s/m, -(vec.
y + 1i*vec.
x)*s/m},
1887 {(vec.
y - 1i*vec.
x)*s/m, c + 1i*vec.
z*s/m}};
1889 SECTION(
"correctness" ) {
1891 int target = GENERATE( range(0,
NUM_QUBITS) );
1893 SECTION(
"state-vector ") {
1897 REQUIRE(
areEqual(quregVec, refVec) );
1899 SECTION(
"density-matrix" ) {
1903 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1906 SECTION(
"input validation" ) {
1908 SECTION(
"qubit indices" ) {
1911 REQUIRE_THROWS_WITH(
rotateAroundAxis(quregVec, target, param, vec), Contains(
"Invalid target") );
1913 SECTION(
"zero rotation axis" ) {
1916 vec = {.
x=0, .y=0, .z=0};
1917 REQUIRE_THROWS_WITH(
rotateAroundAxis(quregVec, target, param, vec), Contains(
"Invalid axis") && Contains(
"zero") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), NUM_QUBITS, PREPARE_TEST, qreal, rotateAroundAxis(), Vector::x, Vector::y, and Vector::z.
◆ TEST_CASE() [93/106]
TEST_CASE |
( |
"rotateX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateX
- Author
- Tyson Jones
Definition at line 1929 of file test_unitaries.cpp.
1933 QMatrix op{{cos(param/2), -1i*sin(param/2)}, {-1i*sin(param/2), cos(param/2)}};
1935 SECTION(
"correctness" ) {
1937 int target = GENERATE( range(0,
NUM_QUBITS) );
1939 SECTION(
"state-vector ") {
1941 rotateX(quregVec, target, param);
1943 REQUIRE(
areEqual(quregVec, refVec) );
1945 SECTION(
"density-matrix" ) {
1947 rotateX(quregMatr, target, param);
1949 REQUIRE(
areEqual(quregMatr, refMatr) );
1952 SECTION(
"input validation" ) {
1954 SECTION(
"qubit indices" ) {
1957 REQUIRE_THROWS_WITH(
rotateX(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), NUM_QUBITS, PREPARE_TEST, qreal, and rotateX().
◆ TEST_CASE() [94/106]
TEST_CASE |
( |
"rotateY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateY
- Author
- Tyson Jones
Definition at line 1969 of file test_unitaries.cpp.
1973 QMatrix op{{cos(param/2), -sin(param/2)},{sin(param/2), cos(param/2)}};
1975 SECTION(
"correctness" ) {
1977 int target = GENERATE( range(0,
NUM_QUBITS) );
1979 SECTION(
"state-vector ") {
1981 rotateY(quregVec, target, param);
1983 REQUIRE(
areEqual(quregVec, refVec) );
1985 SECTION(
"density-matrix" ) {
1987 rotateY(quregMatr, target, param);
1989 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
1992 SECTION(
"input validation" ) {
1994 SECTION(
"qubit indices" ) {
1997 REQUIRE_THROWS_WITH(
rotateY(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), NUM_QUBITS, PREPARE_TEST, qreal, and rotateY().
◆ TEST_CASE() [95/106]
TEST_CASE |
( |
"rotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateZ
- Author
- Tyson Jones
Definition at line 2009 of file test_unitaries.cpp.
2015 SECTION(
"correctness" ) {
2017 int target = GENERATE( range(0,
NUM_QUBITS) );
2019 SECTION(
"state-vector ") {
2021 rotateZ(quregVec, target, param);
2023 REQUIRE(
areEqual(quregVec, refVec) );
2025 SECTION(
"density-matrix" ) {
2027 rotateZ(quregMatr, target, param);
2029 REQUIRE(
areEqual(quregMatr, refMatr) );
2032 SECTION(
"input validation" ) {
2034 SECTION(
"qubit indices" ) {
2037 REQUIRE_THROWS_WITH(
rotateZ(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), NUM_QUBITS, PREPARE_TEST, qreal, and rotateZ().
◆ TEST_CASE() [96/106]
TEST_CASE |
( |
"setAmps" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- setAmps
- Author
- Tyson Jones
Definition at line 368 of file test_state_initialisations.cpp.
376 SECTION(
"correctness" ) {
378 SECTION(
"state-vector" ) {
381 int startInd = GENERATE_COPY( range(0,maxInd) );
382 int numAmps = GENERATE_COPY( range(0,1+maxInd-startInd) );
385 for (
int i=0; i<numAmps; i++) {
394 setAmps(vec, startInd, reals, imags, numAmps);
395 for (
int i=0; i<numAmps; i++)
396 vecRef[startInd+i] = reals[i] + 1i*(imags[i]);
401 SECTION(
"input validation" ) {
403 SECTION(
"start index" ) {
405 int startInd = GENERATE_COPY( -1, maxInd );
407 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"Invalid amplitude index") );
410 SECTION(
"number of amplitudes" ) {
414 int numAmps = GENERATE_COPY( -1, maxInd+1 );
415 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"Invalid number of amplitudes") );
418 startInd = maxInd - 1;
420 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"More amplitudes given than exist") );
422 SECTION(
"density-matrix" ) {
425 REQUIRE_THROWS_WITH(
setAmps(mat, 0, reals, imags, 0), Contains(
"valid only for state-vectors") );
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getRandomReal(), initDebugState(), NUM_QUBITS, Qureg::numAmpsTotal, qreal, QUEST_ENV, setAmps(), and toQVector().
◆ TEST_CASE() [97/106]
TEST_CASE |
( |
"setDiagonalOpElems" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- setDiagonalOpElems
- Author
- Tyson Jones
Definition at line 721 of file test_data_structures.cpp.
729 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
732 SECTION(
"correctness" ) {
735 long long int len = (1LL << numQb);
739 for (n=0; n<len; n++) {
740 reals[n] = (
qreal) n;
741 imags[n] = (
qreal) -2*n;
745 for (n=0; n<len; n++)
753 SECTION(
"input validation" ) {
755 long long int maxInd = (1LL << numQb);
759 SECTION(
"start index" ) {
761 int startInd = GENERATE_COPY( -1, maxInd );
763 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"Invalid element index") );
766 SECTION(
"number of amplitudes" ) {
770 int numAmps = GENERATE_COPY( -1, maxInd+1 );
771 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"Invalid number of elements") );
774 startInd = maxInd - 1;
776 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"More elements given than exist") );
References areEqual(), calcLog2(), createDiagonalOp(), destroyDiagonalOp(), QuESTEnv::numRanks, qreal, QUEST_ENV, setDiagonalOpElems(), and toQVector().
◆ TEST_CASE() [98/106]
TEST_CASE |
( |
"setWeightedQureg" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- setWeightedQureg
- Author
- Tyson Jones
Definition at line 438 of file test_state_initialisations.cpp.
440 SECTION(
"correctness" ) {
443 GENERATE( range(0,10) );
449 SECTION(
"state-vector" ) {
476 refOut = numA*refA + numB*refB + numC*refC;
486 refOut = numB*refB + numC*refC + numA*refC;
487 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
495 refOut = numC*refC + numB*refB + numA*refC;
496 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
504 refOut = numA*refC + numB*refC + numC*refC;
505 REQUIRE(
areEqual(vecC, refOut, 1E3*REAL_EPS) );
512 SECTION(
"density-matrix" ) {
539 refOut = numA*refA + numB*refB + numC*refC;
549 refOut = numB*refB + numC*refC + numA*refC;
550 REQUIRE(
areEqual(matC, refOut, 10*REAL_EPS) );
558 refOut = numC*refC + numB*refB + numA*refC;
559 REQUIRE(
areEqual(matC, refOut, 1E2*REAL_EPS) );
567 refOut = numA*refC + numB*refC + numC*refC;
568 REQUIRE(
areEqual(matC, refOut, 1E3*REAL_EPS) );
576 SECTION(
"input validation" ) {
578 SECTION(
"qureg types" ) {
585 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, vec, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
586 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, mat, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
587 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, vec, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
590 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, mat, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
591 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, vec, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
592 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, mat, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
597 SECTION(
"qureg dimensions" ) {
606 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecA, f, vecB, f, vecB), Contains(
"Dimensions") );
607 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecB, f, vecA, f, vecB), Contains(
"Dimensions") );
608 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecB, f, vecB, f, vecA), Contains(
"Dimensions") );
611 REQUIRE_THROWS_WITH(
setWeightedQureg(f, matA, f, matB, f, matB), Contains(
"Dimensions") );
612 REQUIRE_THROWS_WITH(
setWeightedQureg(f, matB, f, matA, f, matB), Contains(
"Dimensions") );
613 REQUIRE_THROWS_WITH(
setWeightedQureg(f, matB, f, matB, f, matA), Contains(
"Dimensions") );
References areEqual(), copyStateToGPU(), createDensityQureg(), createQureg(), destroyQureg(), getRandomReal(), NUM_QUBITS, Qureg::numAmpsPerChunk, qcomp, QUEST_ENV, Complex::real, setWeightedQureg(), Qureg::stateVec, toComplex, toQMatrix(), and toQVector().
◆ TEST_CASE() [99/106]
TEST_CASE |
( |
"sGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- sGate
- Author
- Tyson Jones
Definition at line 2049 of file test_unitaries.cpp.
2054 SECTION(
"correctness" ) {
2056 int target = GENERATE( range(0,
NUM_QUBITS) );
2058 SECTION(
"state-vector ") {
2060 sGate(quregVec, target);
2062 REQUIRE(
areEqual(quregVec, refVec) );
2064 SECTION(
"density-matrix" ) {
2066 sGate(quregMatr, target);
2068 REQUIRE(
areEqual(quregMatr, refMatr) );
2071 SECTION(
"input validation" ) {
2073 SECTION(
"qubit indices" ) {
2076 REQUIRE_THROWS_WITH(
sGate(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, PREPARE_TEST, and sGate().
◆ TEST_CASE() [100/106]
TEST_CASE |
( |
"sqrtSwapGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- sqrtSwapGate
- Author
- Tyson Jones
Definition at line 2088 of file test_unitaries.cpp.
2091 qcomp a = (1. + 1i)/2.;
2092 qcomp b = (1. - 1i)/2.;
2093 QMatrix op{{1,0,0,0},{0,a,b,0},{0,b,a,0},{0,0,0,1}};
2095 SECTION(
"correctness" ) {
2098 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2099 int targs[] = {targ1, targ2};
2101 SECTION(
"state-vector" ) {
2105 REQUIRE(
areEqual(quregVec, refVec) );
2107 SECTION(
"density-matrix" ) {
2111 REQUIRE(
areEqual(quregMatr, refMatr) );
2114 SECTION(
"input validation" ) {
2116 SECTION(
"qubit indices" ) {
2120 REQUIRE_THROWS_WITH(
sqrtSwapGate(quregVec, targ1, targ2), Contains(
"Invalid target") );
2121 REQUIRE_THROWS_WITH(
sqrtSwapGate(quregVec, targ2, targ1), Contains(
"Invalid target") );
2123 SECTION(
"repetition of targets" ) {
2126 REQUIRE_THROWS_WITH(
sqrtSwapGate(quregVec, qb, qb), Contains(
"target") && Contains(
"unique") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, PREPARE_TEST, qcomp, and sqrtSwapGate().
◆ TEST_CASE() [101/106]
TEST_CASE |
( |
"swapGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- swapGate
- Author
- Tyson Jones
Definition at line 2138 of file test_unitaries.cpp.
2141 QMatrix op{{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};
2143 SECTION(
"correctness" ) {
2146 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2147 int targs[] = {targ1, targ2};
2149 SECTION(
"state-vector" ) {
2153 REQUIRE(
areEqual(quregVec, refVec) );
2155 SECTION(
"density-matrix" ) {
2159 REQUIRE(
areEqual(quregMatr, refMatr) );
2162 SECTION(
"input validation" ) {
2164 SECTION(
"qubit indices" ) {
2168 REQUIRE_THROWS_WITH(
swapGate(quregVec, targ1, targ2), Contains(
"Invalid target") );
2169 REQUIRE_THROWS_WITH(
swapGate(quregVec, targ2, targ1), Contains(
"Invalid target") );
2171 SECTION(
"repetition of targets" ) {
2174 REQUIRE_THROWS_WITH(
swapGate(quregVec, qb, qb), Contains(
"target") && Contains(
"unique") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, PREPARE_TEST, and swapGate().
◆ TEST_CASE() [102/106]
TEST_CASE |
( |
"syncDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- syncDiagonalOp
- Author
- Tyson Jones
Definition at line 789 of file test_data_structures.cpp.
796 SECTION(
"correctness" ) {
799 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
822 REQUIRE( qureg.
stateVec.real[n] == 3*n );
823 REQUIRE( qureg.
stateVec.imag[n] == -n );
References applyDiagonalOp(), calcLog2(), copyStateFromGPU(), copyStateToGPU(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), DiagonalOp::imag, Qureg::numAmpsPerChunk, DiagonalOp::numElemsPerChunk, QuESTEnv::numRanks, qreal, QUEST_ENV, DiagonalOp::real, Qureg::stateVec, and syncDiagonalOp().
◆ TEST_CASE() [103/106]
TEST_CASE |
( |
"tGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- tGate
- Author
- Tyson Jones
Definition at line 2186 of file test_unitaries.cpp.
2191 SECTION(
"correctness" ) {
2193 int target = GENERATE( range(0,
NUM_QUBITS) );
2195 SECTION(
"state-vector ") {
2197 tGate(quregVec, target);
2199 REQUIRE(
areEqual(quregVec, refVec) );
2201 SECTION(
"density-matrix" ) {
2203 tGate(quregMatr, target);
2205 REQUIRE(
areEqual(quregMatr, refMatr) );
2208 SECTION(
"input validation" ) {
2210 SECTION(
"qubit indices" ) {
2213 REQUIRE_THROWS_WITH(
tGate(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), NUM_QUBITS, PREPARE_TEST, and tGate().
◆ TEST_CASE() [104/106]
TEST_CASE |
( |
"toComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [105/106]
TEST_CASE |
( |
"twoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- twoQubitUnitary
- Author
- Tyson Jones
Definition at line 2225 of file test_unitaries.cpp.
2230 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
2236 SECTION(
"correctness" ) {
2239 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2240 int targs[] = {targ1, targ2};
2242 SECTION(
"state-vector" ) {
2246 REQUIRE(
areEqual(quregVec, refVec) );
2248 SECTION(
"density-matrix" ) {
2252 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2255 SECTION(
"input validation" ) {
2257 SECTION(
"qubit indices" ) {
2261 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, targ1, targ2, matr), Contains(
"Invalid target") );
2262 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, targ2, targ1, matr), Contains(
"Invalid target") );
2264 SECTION(
"repetition of targets" ) {
2267 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, qb, qb, matr), Contains(
"target") && Contains(
"unique") );
2269 SECTION(
"unitarity" ) {
2271 matr.
real[0][0] = 0;
2272 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, 0, 1, matr), Contains(
"unitary") );
2274 SECTION(
"unitary fits in node" ) {
2277 quregVec.numAmpsPerChunk = 1;
2278 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, 0, 1, matr), Contains(
"targets too many qubits"));
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix4::real, toComplexMatrix4(), and twoQubitUnitary().
◆ TEST_CASE() [106/106]
TEST_CASE |
( |
"unitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- unitary
- Author
- Tyson Jones
Definition at line 2290 of file test_unitaries.cpp.
2298 SECTION(
"correctness" ) {
2300 int target = GENERATE( range(0,
NUM_QUBITS) );
2302 SECTION(
"state-vector" ) {
2304 unitary(quregVec, target, matr);
2306 REQUIRE(
areEqual(quregVec, refVec) );
2308 SECTION(
"density-matrix" ) {
2310 unitary(quregMatr, target, matr);
2312 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2315 SECTION(
"input validation" ) {
2317 SECTION(
"qubit indices" ) {
2320 REQUIRE_THROWS_WITH(
unitary(quregVec, target, matr), Contains(
"Invalid target") );
2322 SECTION(
"unitarity" ) {
2324 matr.
real[0][0] = 0;
2325 REQUIRE_THROWS_WITH(
unitary(quregVec, 0, matr), Contains(
"unitary") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, toComplexMatrix2(), and unitary().
void controlledRotateZ(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.
void mixDephasing(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit dephasing noise.
qreal getProbAmp(Qureg qureg, long long int index)
Get the probability of a state-vector at an index in the full state vector.
void initBlankState(Qureg qureg)
Initialises a qureg to have all-zero-amplitudes.
Represents a 3-vector of real numbers.
pauliOpType
Codes for specifying Pauli operators.
QMatrix getFullOperatorMatrix(int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op, int numQubits)
Takes a 2^numTargs-by-2^numTargs matrix op and a returns a 2^numQubits-by-2^numQubits matrix where op...
void applyMultiControlledMatrixN(Qureg qureg, int *ctrls, int numCtrls, int *targs, int numTargs, ComplexMatrixN u)
Apply a general N-by-N matrix, which may be non-unitary, with additional controlled qubits.
void twoQubitUnitary(Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general two-qubit unitary (including a global phase factor).
void controlledRotateX(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.
void copyStateFromGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from GPU memory (qureg....
void initPauliHamil(PauliHamil hamil, qreal *coeffs, enum pauliOpType *codes)
Initialise a PauliHamil instance with the given term coefficients and Pauli codes (one for every qubi...
QuESTEnv QUEST_ENV
The global QuESTEnv instance, to be created and destroyed once in this main(), so that the MPI enviro...
#define fromComplex(comp)
void initPureState(Qureg qureg, Qureg pure)
Initialise a set of qubits, which can be a state vector or density matrix, to a given pure state.
#define CLEANUP_TEST(quregVec, quregMatr)
Destroys the data structures made by PREPARE_TEST.
void rotateAroundAxis(Qureg qureg, int rotQubit, qreal angle, Vector axis)
Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere.
void mixDepolarising(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit homogeneous depolarising noise.
qreal calcTotalProb(Qureg qureg)
A debugging function which calculates the probability of the qubits in qureg being in any state,...
void mixDamping(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit amplitude damping (decay to 0 state).
void destroyComplexMatrixN(ComplexMatrixN m)
Destroy a ComplexMatrixN instance created with createComplexMatrixN()
int numChunks
The number of nodes between which the elements of this operator are split.
Complex getDensityAmp(Qureg qureg, long long int row, long long int col)
Get an amplitude from a density matrix at a given row and column.
int getRandomInt(int min, int max)
Returns a random integer between min (inclusive) and max (exclusive), from the uniform distribution.
std::vector< QMatrix > getRandomKrausMap(int numQb, int numOps)
Returns a random Kraus map of #numOps 2^numQb-by-2^numQb operators, from an undisclosed distribution.
ComplexMatrixN createComplexMatrixN(int numQubits)
Create (dynamically) a square complex matrix which can be passed to the multi-qubit general unitary f...
qreal getImagAmp(Qureg qureg, long long int index)
Get the imaginary component of the complex probability amplitude at an index in the state vector.
void controlledRotateAroundAxis(Qureg qureg, int controlQubit, int targetQubit, qreal angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
void mixKrausMap(Qureg qureg, int target, ComplexMatrix2 *ops, int numOps)
Apply a general single-qubit Kraus map to a density matrix, as specified by at most four Kraus operat...
void syncDiagonalOp(DiagonalOp op)
Copy the elements in DiagonalOp op.real and op.imag to the persisent GPU memory.
void destroyDiagonalOp(DiagonalOp op, QuESTEnv env)
Destroys a DiagonalOp created with createDiagonalOp(), freeing its memory.
void multiControlledTwoQubitUnitary(Qureg qureg, int *controlQubits, int numControlQubits, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general multi-controlled two-qubit unitary (including a global phase factor).
#define NUM_QUBITS
The default number of qubits in the registers created for unit testing (both statevectors and density...
qreal collapseToOutcome(Qureg qureg, int measureQubit, int outcome)
Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...
#define CLEANUP_TEST(quregVec, quregMatr)
Destroys the data structures made by PREPARE_TEST.
qreal calcPurity(Qureg qureg)
Calculates the purity of a density matrix, by the trace of the density matrix squared.
qreal calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome)
Gives the probability of a specified qubit being measured in the given outcome (0 or 1).
int measure(Qureg qureg, int measureQubit)
Measures a single qubit, collapsing it randomly to 0 or 1.
QMatrix getRandomUnitary(int numQb)
Returns a uniformly random (under Haar) 2^numQb-by-2^numQb unitary matrix.
qreal calcFidelity(Qureg qureg, Qureg pureState)
Calculates the fidelity of qureg (a statevector or density matrix) against a reference pure state (ne...
qreal getRandomReal(qreal min, qreal max)
Returns a random real between min (inclusive) and max (exclusive), from the uniform distribution.
void unitary(Qureg qureg, int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary (including a global phase factor).
int chunkId
The position of the chunk of the operator held by this process in the full operator.
QMatrix getKetBra(QVector ket, QVector bra)
Returns the matrix |ket><bra|, with ith-jth element ket(i) conj(bra(j)), since |ket><bra| = sum_i a_i...
void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit homogeneous depolarising noise.
Complex calcExpecDiagonalOp(Qureg qureg, DiagonalOp op)
Computes the expected value of the diagonal operator op for state qureg.
void sGate(Qureg qureg, int targetQubit)
Apply the single-qubit S gate.
void cloneQureg(Qureg targetQureg, Qureg copyQureg)
Set targetQureg to be a clone of copyQureg.
Represents a 4x4 matrix of complex numbers.
void rotateY(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.
void applyPauliHamil(Qureg inQureg, PauliHamil hamil, Qureg outQureg)
Modifies outQureg to be the result of applying PauliHamil (a Hermitian but not necessarily unitary op...
Information about the environment the program is running in.
PauliHamil createPauliHamilFromFile(char *fn)
Create a PauliHamil instance, a real-weighted sum of products of Pauli operators, populated with the ...
void multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
Introduce a phase factor on state of the passed qubits.
void setDiagonalOpElems(DiagonalOp op, long long int startInd, qreal *real, qreal *imag, long long int numElems)
Modifies a subset (starting at index startInd) of the elements in DiagonalOp op with the given elemen...
Represents a general 2^N by 2^N matrix of complex numbers.
void multiRotatePauli(Qureg qureg, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle)
Apply a multi-qubit multi-Pauli rotation on a selected number of qubits.
QMatrix toQMatrix(ComplexMatrix2 src)
Returns a copy of the given 2-by-2 matrix.
void toQureg(Qureg qureg, QVector vec)
Initialises the state-vector qureg to have the same amplitudes as vec.
void setAmps(Qureg qureg, long long int startInd, qreal *reals, qreal *imags, long long int numAmps)
Overwrites a subset of the amplitudes in qureg, with those passed in reals and imags.
unsigned int calcLog2(long unsigned int num)
returns log2 of numbers which must be gauranteed to be 2^n
void multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits)
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled paul...
void multiQubitUnitary(Qureg qureg, int *targs, int numTargs, ComplexMatrixN u)
Apply a general multi-qubit unitary (including a global phase factor) with any number of target qubit...
#define PREPARE_TEST(quregVec, quregMatr, refVec, refMatr)
Prepares the needed data structures for unit testing unitaries.
Complex getAmp(Qureg qureg, long long int index)
Get the complex amplitude at a given index in the state vector.
void controlledPauliY(Qureg qureg, int controlQubit, int targetQubit)
Apply the controlled pauliY (single control, single target) gate, also known as the c-Y and c-sigma-Y...
QMatrix getExponentialOfPauliMatrix(qreal angle, QMatrix a)
Returns the matrix exponential of a kronecker product of pauli matrices (or of any involutory matrice...
int measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb)
Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of ...
int numQubitsInStateVec
Number of qubits in the state-vector - this is double the number represented for mixed states.
qreal calcExpecPauliHamil(Qureg qureg, PauliHamil hamil, Qureg workspace)
Computes the expected value of qureg under Hermitian operator hamil.
void multiControlledMultiQubitUnitary(Qureg qureg, int *ctrls, int numCtrls, int *targs, int numTargs, ComplexMatrixN u)
Apply a general multi-controlled multi-qubit unitary (including a global phase factor).
void setRandomPauliSum(qreal *coeffs, pauliOpType *codes, int numQubits, int numTerms)
Populates the coeffs array with random qreals in (-5, 5), and populates codes with random Pauli codes...
void toComplexMatrixN(QMatrix qm, ComplexMatrixN cm)
Initialises cm with the values of qm.
void rotateX(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.
void setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out)
Modifies qureg out to the result of (facOut out + fac1 qureg1 + fac2 qureg2), imposing no constraints...
qreal calcHilbertSchmidtDistance(Qureg a, Qureg b)
Computes the Hilbert Schmidt distance between two density matrices a and b, defined as the Frobenius ...
qcomp expI(qreal phase)
Returns the unit-norm complex number exp(i*phase).
std::vector< qcomp > QVector
A complex vector, which can be zero-initialised with QVector(numAmps).
qreal * imag
The imaginary values of the 2^numQubits complex elements.
void pauliZ(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.
QVector toQVector(Qureg qureg)
Returns an equal-size copy of the given state-vector qureg.
long long int numAmpsPerChunk
Number of probability amplitudes held in stateVec by this process In the non-MPI version,...
void applyDiagonalOp(Qureg qureg, DiagonalOp op)
Apply a diagonal complex operator, which is possibly non-unitary and non-Hermitian,...
qreal * termCoeffs
The coefficient of each Pauli product. This is a length numSumTerms array.
void applyMatrix4(Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general 4-by-4 matrix, which may be non-unitary.
void swapGate(Qureg qureg, int qb1, int qb2)
Performs a SWAP gate between qubit1 and qubit2.
enum pauliOpType * pauliCodes
The Pauli operators acting on each qubit, flattened over every operator.
void initStateFromAmps(Qureg qureg, qreal *reals, qreal *imags)
Initialise qureg by specifying the complete statevector.
ComplexMatrix4 toComplexMatrix4(QMatrix qm)
Returns a ComplexMatrix4 copy of QMatix qm.
void copyStateToGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from RAM (qureg.stateVec) to VRAM / GPU...
#define toComplex(scalar)
qreal getRealAmp(Qureg qureg, long long int index)
Get the real component of the complex probability amplitude at an index in the state vector.
void controlledPhaseFlip(Qureg qureg, int idQubit1, int idQubit2)
Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate.
int numQubits
The number of qubits this operator can act on (informing its size)
int numSumTerms
The number of terms in the weighted sum, or the number of Pauli products.
Represents a diagonal complex operator on the full Hilbert state of a Qureg.
Represents a weighted sum of pauli products.
int getNumQubits(Qureg qureg)
Get the number of qubits in a qureg object.
Complex calcInnerProduct(Qureg bra, Qureg ket)
Computes the inner product of two equal-size state vectors, given by.
void destroyQureg(Qureg qureg, QuESTEnv env)
Deallocate a Qureg object representing a set of qubits.
void controlledMultiQubitUnitary(Qureg qureg, int ctrl, int *targs, int numTargs, ComplexMatrixN u)
Apply a general controlled multi-qubit unitary (including a global phase factor).
QVector getRandomStateVector(int numQb)
Returns a random numQb-length L2-normalised state-vector from an undisclosed distribution.
void mixTwoQubitKrausMap(Qureg qureg, int target1, int target2, ComplexMatrix4 *ops, int numOps)
Apply a general two-qubit Kraus map to a density matrix, as specified by at most sixteen Kraus operat...
void initDebugState(Qureg qureg)
Initialises qureg to be in the un-normalised, non-physical state with with n-th complex amplitude (2n...
void applyPauliSum(Qureg inQureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg outQureg)
Modifies outQureg to be the result of applying the weighted sum of Pauli products (a Hermitian but no...
QMatrix getRandomQMatrix(int dim)
Returns a dim-by-dim complex matrix, where the real and imaginary value of each element are independe...
void applyMatrixN(Qureg qureg, int *targs, int numTargs, ComplexMatrixN u)
Apply a general N-by-N matrix, which may be non-unitary, on any number of target qubits.
void compactUnitary(Qureg qureg, int targetQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
void initClassicalState(Qureg qureg, long long int stateInd)
Initialise a set of qubits to the classical state (also known as a "computational basis state") with...
void pauliY(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.
Represents a system of qubits.
void controlledPhaseShift(Qureg qureg, int idQubit1, int idQubit2, qreal angle)
Introduce a phase factor on state of qubits idQubit1 and idQubit2.
void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit dephasing noise.
void controlledUnitary(Qureg qureg, int controlQubit, int targetQubit, ComplexMatrix2 u)
Apply a general controlled unitary (single control, single target), which can include a global phase ...
void initDiagonalOp(DiagonalOp op, qreal *real, qreal *imag)
Updates the entire DiagonalOp op with the given elements, of which there must be 2^op....
void phaseShift(Qureg qureg, int targetQubit, qreal angle)
Shift the phase between and of a single qubit by a given angle.
ComplexArray stateVec
Computational state amplitudes - a subset thereof in the MPI version.
void controlledNot(Qureg qureg, int controlQubit, int targetQubit)
Apply the controlled not (single control, single target) gate, also known as the c-X,...
long long int getNumAmps(Qureg qureg)
Get the number of probability amplitudes in a qureg object, given by 2^numQubits.
long long int numElemsPerChunk
The number of the 2^numQubits amplitudes stored on each distributed node.
int isDensityMatrix
Whether this instance is a density-state representation.
void pauliX(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate.
Qureg createCloneQureg(Qureg qureg, QuESTEnv env)
Create a new Qureg which is an exact clone of the passed qureg, which can be either a statevector or ...
#define PREPARE_TEST(qureg, ref)
Prepares a density matrix in the debug state, and the reference QMatrix.
std::vector< std::vector< qcomp > > QMatrix
A complex square matrix.
qreal calcExpecPauliSum(Qureg qureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg workspace)
Computes the expected value of a sum of products of Pauli operators.
void controlledTwoQubitUnitary(Qureg qureg, int controlQubit, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general controlled two-qubit unitary (including a global phase factor).
ComplexMatrix2 toComplexMatrix2(QMatrix qm)
Returns a ComplexMatrix2 copy of QMatix qm.
int numQubits
The number of qubits for which this Hamiltonian is defined.
Catch::Generators::GeneratorWrapper< int * > sublists(int *list, int len, int sublen)
Returns a Catch2 generator of every length-sublen sublist of length-len list, in increasing lexograph...
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
qreal * real
The real values of the 2^numQubits complex elements.
void mixDensityMatrix(Qureg combineQureg, qreal otherProb, Qureg otherQureg)
Modifies combineQureg to become (1-prob)combineProb + prob otherQureg.
Qureg createQureg(int numQubits, QuESTEnv env)
Create a Qureg object representing a set of qubits which will remain in a pure state.
void destroyPauliHamil(PauliHamil h)
Destroy a PauliHamil instance, created with either createPauliHamil() or createPauliHamilFromFile().
void tGate(Qureg qureg, int targetQubit)
Apply the single-qubit T gate.
void multiRotateZ(Qureg qureg, int *qubits, int numQubits, qreal angle)
Apply a multi-qubit Z rotation on a selected number of qubits.
QMatrix getKroneckerProduct(QMatrix a, QMatrix b)
Returns the kronecker product of a and b, where a and b are square but possibly differently-sized com...
QMatrix getRandomDensityMatrix(int numQb)
Returns a random numQb-by-numQb density matrix, from an undisclosed distribution, in a very mixed sta...
QMatrix getExponentialOfDiagonalMatrix(QMatrix a)
Returns the matrix exponential of a diagonal, square, complex matrix.
void mixPauli(Qureg qureg, int qubit, qreal probX, qreal probY, qreal probZ)
Mixes a density matrix qureg to induce general single-qubit Pauli noise.
QMatrix getZeroMatrix(size_t dim)
Returns a dim-by-dim square complex matrix, initialised to all zeroes.
void hadamard(Qureg qureg, int targetQubit)
Apply the single-qubit Hadamard gate.
Represents one complex number.
void applyMatrix2(Qureg qureg, int targetQubit, ComplexMatrix2 u)
Apply a general 2-by-2 matrix, which may be non-unitary.
#define PREPARE_TEST(quregVec, quregMatr, refVec, refMatr)
Prepares the needed data structures for unit testing some operators.
void rotateZ(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase s...
QVector getRandomQVector(int dim)
Returns a dim-length vector with random complex amplitudes in the square joining {-1-i,...
void multiControlledUnitary(Qureg qureg, int *controlQubits, int numControlQubits, int targetQubit, ComplexMatrix2 u)
Apply a general multiple-control single-target unitary, which can include a global phase factor.
void applyReferenceMatrix(QVector &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op)
Modifies the state-vector state to be the result of left-multiplying the multi-target operator matrix...
void initZeroState(Qureg qureg)
Initialise a set of qubits to the classical zero state .
qreal calcDensityInnerProduct(Qureg rho1, Qureg rho2)
Computes the Hilbert-Schmidt scalar product (which is equivalent to the Frobenius inner product of ma...
bool areEqual(QVector a, QVector b)
Returns true if the absolute value of the difference between every amplitude in vectors a and b is le...
Qureg createDensityQureg(int numQubits, QuESTEnv env)
Create a Qureg for qubits which are represented by a density matrix, and can be in mixed states.
void applyReferenceOp(QVector &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op)
Modifies the state-vector state to be the result of applying the multi-target operator matrix op,...
void applyTrotterCircuit(Qureg qureg, PauliHamil hamil, qreal time, int order, int reps)
Applies a trotterisation of unitary evolution to qureg.
PauliHamil createPauliHamil(int numQubits, int numSumTerms)
Create a PauliHamil instance, which is a Hamiltonian expressed as a real-weighted sum of products of ...
Catch::Generators::GeneratorWrapper< int * > bitsets(int numBits)
Returns a Catch2 generator of every numBits-length bit-set, in increasing lexographic order,...
void initPlusState(Qureg qureg)
Initialise a set of qubits to the plus state (and similarly for density matrices).
qreal calcExpecPauliProd(Qureg qureg, int *targetQubits, enum pauliOpType *pauliCodes, int numTargets, Qureg workspace)
Computes the expected value of a product of Pauli operators.
void controlledCompactUnitary(Qureg qureg, int controlQubit, int targetQubit, Complex alpha, Complex beta)
Apply a controlled unitary (single control, single target) parameterised by two given complex scalars...
void multiStateControlledUnitary(Qureg qureg, int *controlQubits, int *controlState, int numControlQubits, int targetQubit, ComplexMatrix2 u)
Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary,...
void sqrtSwapGate(Qureg qureg, int qb1, int qb2)
Performs a sqrt SWAP gate between qubit1 and qubit2.
void mixMultiQubitKrausMap(Qureg qureg, int *targets, int numTargets, ComplexMatrixN *ops, int numOps)
Apply a general N-qubit Kraus map to a density matrix, as specified by at most (2N)^2 Kraus operators...
DiagonalOp createDiagonalOp(int numQubits, QuESTEnv env)
Creates a DiagonalOp representing a diagonal operator on the full Hilbert space of a Qureg.
Represents a 2x2 matrix of complex numbers.
void controlledRotateY(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.