Unit tests of the QuEST API, using Catch2 in C++14.
More...
|
| | TEST_CASE ("applyPauliSum", "[operators]") |
| |
| | TEST_CASE ("calcDensityInnerProduct", "[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 ("createQuESTEnv", "[data_structures]") |
| |
| | TEST_CASE ("createQureg", "[data_structures]") |
| |
| | TEST_CASE ("destroyComplexMatrixN", "[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 ("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 ("setWeightedQureg", "[state_initialisations]") |
| |
| | TEST_CASE ("sGate", "[unitaries]") |
| |
| | TEST_CASE ("sqrtSwapGate", "[unitaries]") |
| |
| | TEST_CASE ("swapGate", "[unitaries]") |
| |
| | 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/88]
| TEST_CASE |
( |
"applyPauliSum" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPauliSum
- Author
- Tyson Jones
Definition at line 15 of file test_operators.cpp.
25 SECTION(
"correctness" ) {
27 int numTerms = GENERATE( 1, 2, 10, 15);
31 qreal coeffs[numTerms];
32 for (
int i=0; i<numTerms; i++)
40 GENERATE( range(0,10) );
42 for (
int i=0; i<numPaulis; i++)
52 for (
int t=0; t<numTerms; t++) {
59 if (paulis[i] ==
PAULI_I) fac = iMatr;
60 if (paulis[i] ==
PAULI_X) fac = xMatr;
61 if (paulis[i] ==
PAULI_Y) fac = yMatr;
62 if (paulis[i] ==
PAULI_Z) fac = zMatr;
65 pauliSum += coeffs[t] * pauliProd;
68 SECTION(
"state-vector" ) {
77 REQUIRE(
areEqual(vecOut, pauliSum * vecRef) );
79 SECTION(
"density-matrix" ) {
88 REQUIRE(
areEqual(matOut, pauliSum * matRef, 1E2*REAL_EPS) );
91 SECTION(
"input validation" ) {
93 SECTION(
"number of terms" ) {
95 int numTerms = GENERATE( -1, 0 );
96 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, NULL, NULL, numTerms, vecOut), Contains(
"Invalid number of terms") );
98 SECTION(
"pauli codes" ) {
104 for (
int i=0; i<numPaulis; i++)
108 paulis[GENERATE_COPY( range(0,numPaulis) )] = (
pauliOpType) GENERATE( -1, 4 );
109 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, numTerms, vecOut), Contains(
"Invalid Pauli code") );
111 SECTION(
"qureg dimensions" ) {
115 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, 1, badVec), Contains(
"Dimensions of the qubit registers don't match") );
118 SECTION(
"qureg types" ) {
121 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(), getKroneckerProduct(), getRandomInt(), getRandomReal(), getZeroMatrix(), initDebugState(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, qreal, QUEST_ENV, toQMatrix(), and toQVector().
◆ TEST_CASE() [2/88]
| 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() [3/88]
| TEST_CASE |
( |
"calcExpecPauliProd" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliProd
- Author
- Tyson Jones
Definition at line 111 of file test_calculations.cpp.
123 SECTION(
"correctness" ) {
125 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
133 GENERATE( range(0,10) );
135 for (
int i=0; i<numTargs; i++)
144 for (
int i=0; i<numTargs; i++) {
146 if (paulis[i] ==
PAULI_I) fac = iMatr;
147 if (paulis[i] ==
PAULI_X) fac = xMatr;
148 if (paulis[i] ==
PAULI_Y) fac = yMatr;
149 if (paulis[i] ==
PAULI_Z) fac = zMatr;
153 SECTION(
"state-vector" ) {
160 for (
size_t i=0; i<vecRef.size(); i++)
161 prod += conj(vecRef[i]) * prodRef[i];
162 REQUIRE( imag(prod) == Approx(0).margin(REAL_EPS) );
165 REQUIRE( res == Approx(real(prod)).margin(REAL_EPS) );
167 SECTION(
"density matrix" ) {
173 matRef = fullOp * matRef;
177 for (
size_t i=0; i<matRef.size(); i++)
178 tr += real(matRef[i][i]);
182 REQUIRE( res == Approx(tr).margin(10*REAL_EPS) );
185 SECTION(
"validation" ) {
187 SECTION(
"number of targets" ) {
189 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
190 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, NULL, NULL, numTargs, vecWork), Contains(
"Invalid number of target") );
192 SECTION(
"target indices" ) {
195 int targs[3] = {0, 1, 2};
198 targs[GENERATE( range(0,3) )] = GENERATE( -1,
NUM_QUBITS );
199 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"Invalid target qubit") );
201 SECTION(
"repetition in targets" ) {
204 int targs[3] = {0, 1, 1};
205 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"target qubits must be unique") );
207 SECTION(
"pauli codes" ) {
210 int targs[3] = {0, 1, 2};
214 codes[GENERATE( range(0,3) )] = (
pauliOpType) GENERATE( -1, 4 );
215 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vecWork), Contains(
"Invalid Pauli code") );
217 SECTION(
"workspace type" ) {
223 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, matWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
224 REQUIRE_THROWS_WITH(
calcExpecPauliProd(mat, targs, codes, numTargs, vecWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
226 SECTION(
"workspace dimensions" ) {
233 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
237 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() [4/88]
| TEST_CASE |
( |
"calcExpecPauliSum" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliSum
- Author
- Tyson Jones
Definition at line 253 of file test_calculations.cpp.
265 SECTION(
"correctness" ) {
267 int numSumTerms = GENERATE( 1, 2, 10, 15 );
272 GENERATE( range(0,10) );
275 for (
int i=0; i<totNumCodes; i++)
279 qreal coeffs[numSumTerms];
280 for (
int i=0; i<numSumTerms; i++)
290 for (
int t=0; t<numSumTerms; t++) {
297 if (paulis[i] ==
PAULI_I) fac = iMatr;
298 if (paulis[i] ==
PAULI_X) fac = xMatr;
299 if (paulis[i] ==
PAULI_Y) fac = yMatr;
300 if (paulis[i] ==
PAULI_Z) fac = zMatr;
303 pauliSum += coeffs[t] * pauliProd;
305 SECTION(
"state-vector" ) {
309 QVector sumRef = pauliSum * vecRef;
311 for (
size_t i=0; i<vecRef.size(); i++)
312 prod += conj(vecRef[i]) * sumRef[i];
313 REQUIRE( imag(prod) == Approx(0).margin(10*REAL_EPS) );
316 REQUIRE( res == Approx(real(prod)).margin(10*REAL_EPS) );
318 SECTION(
"density matrix" ) {
321 matRef = pauliSum * matRef;
323 for (
size_t i=0; i<matRef.size(); i++)
324 tr += real(matRef[i][i]);
328 REQUIRE( res == Approx(tr).margin(1E2*REAL_EPS) );
331 SECTION(
"validation" ) {
333 SECTION(
"number of sum terms" ) {
335 int numSumTerms = GENERATE( -1, 0 );
336 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, NULL, NULL, numSumTerms, vecWork), Contains(
"Invalid number of terms in the Pauli sum") );
338 SECTION(
"pauli codes" ) {
342 qreal coeffs[numSumTerms];
349 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vecWork), Contains(
"Invalid Pauli code") );
351 SECTION(
"workspace type" ) {
355 qreal coeffs[1] = {0};
360 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, mat), Contains(
"Registers must both be state-vectors or both be density matrices") );
361 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, vec), Contains(
"Registers must both be state-vectors or both be density matrices") );
363 SECTION(
"workspace dimensions" ) {
367 qreal coeffs[1] = {0};
373 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
377 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
References calcExpecPauliSum(), createDensityQureg(), createQureg(), destroyQureg(), getKroneckerProduct(), getRandomInt(), getRandomReal(), getZeroMatrix(), initDebugState(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, qcomp, qreal, QUEST_ENV, toQMatrix(), and toQVector().
◆ TEST_CASE() [5/88]
| TEST_CASE |
( |
"calcFidelity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcFidelity
- Author
- Tyson Jones
Definition at line 393 of file test_calculations.cpp.
399 SECTION(
"correctness" ) {
402 GENERATE( range(0,10) );
404 SECTION(
"state-vector" ) {
408 SECTION(
"normalised" ) {
421 for (
size_t i=0; i<vecRef.size(); i++)
422 dotProd += conj(vecRef[i]) * pureRef[i];
423 qreal refFid = pow(abs(dotProd), 2);
427 SECTION(
"unnormalised" ) {
437 for (
size_t i=0; i<vecRef.size(); i++)
438 nv += pow(abs(vecRef[i]), 2);
444 for (
size_t i=0; i<vecRef.size(); i++)
445 dotProd += conj(vecRef[i]) * pureRef[i];
446 qreal refFid = pow(abs(dotProd), 2);
451 SECTION(
"density-matrix" ) {
472 for (
size_t i=0; i<r1.size(); i++)
473 dotProd += conj(r1[i]) * pureRef[i];
474 qreal refFid = pow(abs(dotProd), 2);
488 QVector rhs = matRef * pureRef;
490 for (
size_t i=0; i<rhs.size(); i++)
491 dotProd += conj(pureRef[i]) * rhs[i];
493 REQUIRE( imag(dotProd) == Approx(0).margin(REAL_EPS) );
494 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
496 SECTION(
"unnormalised" ) {
505 QVector rhs = matRef * pureRef;
507 for (
size_t i=0; i<rhs.size(); i++)
508 dotProd += conj(pureRef[i]) * rhs[i];
510 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
514 SECTION(
"input validation" ) {
516 SECTION(
"dimensions" ) {
520 REQUIRE_THROWS_WITH(
calcFidelity(vec2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
525 REQUIRE_THROWS_WITH(
calcFidelity(mat2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
528 SECTION(
"density-matrices" ) {
531 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() [6/88]
| TEST_CASE |
( |
"calcHilbertSchmidtDistance" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcHilbertSchmidtDistance
- Author
- Tyson Jones
Definition at line 545 of file test_calculations.cpp.
550 SECTION(
"correctness" ) {
553 GENERATE( range(0,10) );
555 SECTION(
"density-matrix" ) {
569 for (
size_t i=0; i<m1.size(); i++)
570 for (
size_t j=0; j<m1.size(); j++)
571 tr += pow(abs(m1[i][j] - m2[i][j]), 2);
574 REQUIRE( res == Approx(sqrt(tr)) );
577 SECTION(
"normalised" ) {
586 for (
size_t i=0; i<ref1.size(); i++)
587 for (
size_t j=0; j<ref1.size(); j++)
588 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
591 REQUIRE( res == Approx(sqrt(tr)) );
593 SECTION(
"unnormalised" ) {
603 for (
size_t i=0; i<ref1.size(); i++)
604 for (
size_t j=0; j<ref1.size(); j++)
605 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
608 REQUIRE( res == Approx(sqrt(tr)) );
612 SECTION(
"input validation") {
614 SECTION(
"dimensions" ) {
620 SECTION(
"state-vector" ) {
References calcHilbertSchmidtDistance(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [7/88]
| TEST_CASE |
( |
"calcInnerProduct" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcInnerProduct
- Author
- Tyson Jones
Definition at line 641 of file test_calculations.cpp.
646 SECTION(
"correctness" ) {
649 GENERATE( range(0,10) );
651 SECTION(
"state-vector" ) {
653 SECTION(
"normalised" ) {
659 for (
size_t i=0; i<r1.size(); i++)
660 prod += conj(r1[i]) * r2[i];
666 REQUIRE( res.
real == Approx(real(prod)) );
667 REQUIRE( res.
imag == Approx(imag(prod)) );
669 SECTION(
"unnormalised" ) {
675 for (
size_t i=0; i<r1.size(); i++)
676 prod += conj(r1[i]) * r2[i];
682 REQUIRE( res.
real == Approx(real(prod)) );
683 REQUIRE( res.
imag == Approx(imag(prod)) );
687 SECTION(
"input validation" ) {
689 SECTION(
"dimensions" ) {
692 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,vec3), Contains(
"Dimensions") && Contains(
"don't match") );
695 SECTION(
"density-matrix" ) {
699 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,mat), Contains(
"valid only for state-vectors") );
700 REQUIRE_THROWS_WITH(
calcInnerProduct(mat,vec1), Contains(
"valid only for state-vectors") );
701 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() [8/88]
| TEST_CASE |
( |
"calcProbOfOutcome" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcProbOfOutcome
- Author
- Tyson Jones
Definition at line 716 of file test_calculations.cpp.
721 SECTION(
"correctness" ) {
724 int outcome = GENERATE( 0, 1 );
726 SECTION(
"state-vector" ) {
728 SECTION(
"normalised" ) {
735 for (
size_t ind=0; ind<ref.size(); ind++) {
736 int bit = (ind >> target) & 1;
738 prob += pow(abs(ref[ind]), 2);
743 SECTION(
"unnormalised" ) {
751 for (
size_t ind=0; ind<ref.size(); ind++) {
752 int bit = (ind >> target) & 1;
754 prob += pow(abs(ref[ind]), 2);
762 SECTION(
"density-matrix" ) {
772 for (
size_t ind=0; ind<ref.size(); ind++) {
773 int bit = (ind >> target) & 1;
775 prob += pow(abs(ref[ind]), 2);
787 for (
size_t ind=0; ind<ref.size(); ind++) {
788 int bit = (ind >> target) & 1;
792 REQUIRE( imag(tr) == Approx(0).margin(REAL_EPS) );
796 SECTION(
"unnormalised" ) {
804 for (
size_t ind=0; ind<ref.size(); ind++) {
805 int bit = (ind >> target) & 1;
807 tr += real(ref[ind][ind]);
816 SECTION(
"validation" ) {
818 SECTION(
"qubit indices" ) {
821 REQUIRE_THROWS_WITH(
calcProbOfOutcome(vec, target, 0), Contains(
"Invalid target qubit") );
823 SECTION(
"outcome value" ) {
825 int outcome = GENERATE( -1, 2 );
826 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() [9/88]
| TEST_CASE |
( |
"calcPurity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcPurity
- Author
- Tyson Jones
Definition at line 839 of file test_calculations.cpp.
843 SECTION(
"correctness" ) {
846 GENERATE( range(1,10) );
848 SECTION(
"density-matrix" ) {
869 REQUIRE( purity < 1 );
875 for (
size_t i=0; i<prod.size(); i++)
876 tr += real(prod[i][i]);
877 REQUIRE( purity == Approx(tr) );
879 SECTION(
"unnormalised" ) {
884 for (
size_t i=0; i<ref.size(); i++)
885 for (
size_t j=0; j<ref.size(); j++)
886 tot += pow(abs(ref[i][j]), 2);
893 SECTION(
"input validation" ) {
895 SECTION(
"state-vector" ) {
898 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() [10/88]
| TEST_CASE |
( |
"calcTotalProb" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcTotalProb
- Author
- Tyson Jones
Definition at line 911 of file test_calculations.cpp.
916 SECTION(
"correctness" ) {
918 SECTION(
"state-vector" ) {
936 for (
size_t i=0; i<ref.size(); i++)
937 refProb += pow(abs(ref[i]), 2);
940 SECTION(
"density-matrix" ) {
958 for (
size_t i=0; i<ref.size(); i++)
959 refProb += real(ref[i][i]);
963 SECTION(
"input validation" ) {
References calcTotalProb(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), initBlankState(), initDebugState(), initPlusState(), NUM_QUBITS, qreal, QUEST_ENV, toQMatrix(), toQureg(), and toQVector().
◆ TEST_CASE() [11/88]
| 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() [12/88]
| 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() [13/88]
| 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() [14/88]
| 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() [15/88]
| 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() [16/88]
| 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() [17/88]
| 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() [18/88]
| 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() [19/88]
| 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() [20/88]
| 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() [21/88]
| 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() [22/88]
| 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() [23/88]
| 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) );
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() [24/88]
| 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() [25/88]
| 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() [26/88]
| 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() [27/88]
| TEST_CASE |
( |
"createComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [28/88]
| 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) - 1;
165 REQUIRE_THROWS_WITH(
createDensityQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
170 int minQb = GENERATE( range(3,10) );
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() [29/88]
| TEST_CASE |
( |
"createQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [30/88]
| TEST_CASE |
( |
"createQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createQureg
- Author
- Tyson Jones
Definition at line 202 of file test_data_structures.cpp.
209 SECTION(
"correctness" ) {
212 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
222 SECTION(
"input validation") {
224 SECTION(
"number of qubits" ) {
226 int numQb = GENERATE( -1, 0 );
229 SECTION(
"number of amplitudes" ) {
235 int maxQb = (int)
calcLog2(SIZE_MAX);
236 REQUIRE_THROWS_WITH(
createQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
239 int minQb = GENERATE( range(2,10) );
241 int numQb = GENERATE_COPY( range(1,minQb) );
242 REQUIRE_THROWS_WITH(
createQureg(numQb, env), Contains(
"Too few qubits") );
244 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), createQureg(), destroyQureg(), QuESTEnv::numRanks, and QUEST_ENV.
◆ TEST_CASE() [31/88]
| TEST_CASE |
( |
"destroyComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [32/88]
| TEST_CASE |
( |
"destroyQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [33/88]
| TEST_CASE |
( |
"destroyQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [34/88]
| TEST_CASE |
( |
"fromComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [35/88]
| TEST_CASE |
( |
"getAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getAmp
- Author
- Tyson Jones
Definition at line 978 of file test_calculations.cpp.
982 SECTION(
"correctness" ) {
984 SECTION(
"state-vector" ) {
994 SECTION(
"input validation" ) {
996 SECTION(
"state index" ) {
999 REQUIRE_THROWS_WITH(
getAmp(vec,ind), Contains(
"Invalid amplitude index") );
1001 SECTION(
"density-matrix" ) {
1004 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() [36/88]
| TEST_CASE |
( |
"getDensityAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getDensityAmp
- Author
- Tyson Jones
Definition at line 1017 of file test_calculations.cpp.
1021 SECTION(
"correctness" ) {
1023 SECTION(
"density-matrix" ) {
1028 int row = GENERATE( range(0,1<<
NUM_QUBITS) );
1029 int col = GENERATE( range(0,1<<
NUM_QUBITS) );
1035 SECTION(
"input validation" ) {
1037 SECTION(
"state index" ) {
1040 REQUIRE_THROWS_WITH(
getDensityAmp(mat,ind,0), Contains(
"Invalid amplitude index") );
1041 REQUIRE_THROWS_WITH(
getDensityAmp(mat,0,ind), Contains(
"Invalid amplitude index") );
1044 SECTION(
"state-vector" ) {
1047 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() [37/88]
| TEST_CASE |
( |
"getImagAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getImagAmp
- Author
- Tyson Jones
Definition at line 1060 of file test_calculations.cpp.
1064 SECTION(
"correctness" ) {
1066 SECTION(
"state-vector" ) {
1071 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1072 REQUIRE(
getImagAmp(vec,ind) == imag(ref[ind]) );
1075 SECTION(
"input validation" ) {
1077 SECTION(
"state index" ) {
1080 REQUIRE_THROWS_WITH(
getImagAmp(vec,ind), Contains(
"Invalid amplitude index") );
1082 SECTION(
"density-matrix" ) {
1085 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() [38/88]
| TEST_CASE |
( |
"getNumAmps" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [39/88]
| TEST_CASE |
( |
"getNumQubits" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [40/88]
| TEST_CASE |
( |
"getProbAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getProbAmp
- Author
- Tyson Jones
Definition at line 1161 of file test_calculations.cpp.
1165 SECTION(
"correctness" ) {
1167 SECTION(
"state-vector" ) {
1172 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1173 qreal refCalc = pow(abs(ref[ind]), 2);
1174 REQUIRE(
getProbAmp(vec,ind) == Approx(refCalc) );
1177 SECTION(
"input validation" ) {
1179 SECTION(
"state index" ) {
1182 REQUIRE_THROWS_WITH(
getProbAmp(vec,ind), Contains(
"Invalid amplitude index") );
1184 SECTION(
"density-matrix" ) {
1187 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() [41/88]
| TEST_CASE |
( |
"getRealAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getRealAmp
- Author
- Tyson Jones
Definition at line 1200 of file test_calculations.cpp.
1204 SECTION(
"correctness" ) {
1206 SECTION(
"state-vector" ) {
1211 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1212 REQUIRE(
getRealAmp(vec,ind) == real(ref[ind]) );
1215 SECTION(
"input validation" ) {
1217 SECTION(
"state index" ) {
1220 REQUIRE_THROWS_WITH(
getRealAmp(vec,ind), Contains(
"Invalid amplitude index") );
1222 SECTION(
"density-matrix" ) {
1225 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() [42/88]
| TEST_CASE |
( |
"getStaticComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [43/88]
| 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() [44/88]
| TEST_CASE |
( |
"initBlankState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [45/88]
| TEST_CASE |
( |
"initClassicalState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [46/88]
| TEST_CASE |
( |
"initComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [47/88]
| TEST_CASE |
( |
"initPlusState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [48/88]
| 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() [49/88]
| 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() [50/88]
| 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() [51/88]
| 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() [52/88]
| 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() [53/88]
| 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() [54/88]
| 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() [55/88]
| 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() [56/88]
| 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() [57/88]
| 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() [58/88]
| 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() [59/88]
| 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() [60/88]
| 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() [61/88]
| 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() [62/88]
| 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() [63/88]
| 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() [64/88]
| 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() [65/88]
| 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() [66/88]
| 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() [67/88]
| 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() [68/88]
| 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() [69/88]
| 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() [70/88]
| 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() [71/88]
| 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() [72/88]
| 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() [73/88]
| 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() [74/88]
| 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() [75/88]
| 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() [76/88]
| 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() [77/88]
| 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() [78/88]
| 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() [79/88]
| 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() [80/88]
| 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() [81/88]
| 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, 1E2*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() [82/88]
| 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() [83/88]
| 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() [84/88]
| 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() [85/88]
| 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() [86/88]
| TEST_CASE |
( |
"toComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [87/88]
| 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() [88/88]
| 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().
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.
void controlledPauliY(Qureg qureg, const int controlQubit, const int targetQubit)
Apply the controlled pauliY (single control, single target) gate, also known as the c-Y and c-sigma-Y...
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...
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 tGate(Qureg qureg, const int targetQubit)
Apply the single-qubit T gate.
qreal calcTotalProb(Qureg qureg)
A debugging function which calculates the probability of the qubits in qureg being in any state,...
void destroyComplexMatrixN(ComplexMatrixN m)
Destroy a ComplexMatrixN instance created with createComplexMatrixN()
void rotateZ(Qureg qureg, const 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...
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 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...
#define NUM_QUBITS
The default number of qubits in the registers created for unit testing (both statevectors and density...
void mixDephasing(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit dephasing noise.
qreal calcPurity(Qureg qureg)
Calculates the purity of a density matrix, by the trace of the density matrix squared.
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.
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.
void rotateX(Qureg qureg, const int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.
void cloneQureg(Qureg targetQureg, Qureg copyQureg)
Set targetQureg to be a clone of copyQureg.
void multiControlledTwoQubitUnitary(Qureg qureg, int *controlQubits, const int numControlQubits, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Apply a general multi-controlled two-qubit unitary (including a global phase factor).
Represents a 4x4 matrix of complex numbers.
Information about the environment the program is running in.
void pauliZ(Qureg qureg, const int targetQubit)
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.
void multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
Introduce a phase factor on state of the passed qubits.
Represents a general 2^N by 2^N matrix of complex numbers.
void controlledPhaseFlip(Qureg qureg, const int idQubit1, const int idQubit2)
Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate.
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 multiControlledUnitary(Qureg qureg, int *controlQubits, const int numControlQubits, const int targetQubit, ComplexMatrix2 u)
Apply a general multiple-control single-target unitary, which can include a global phase factor.
void multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits)
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled paul...
#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.
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.
void controlledMultiQubitUnitary(Qureg qureg, int ctrl, int *targs, const int numTargs, ComplexMatrixN u)
Apply a general controlled multi-qubit unitary (including a global phase factor).
void multiStateControlledUnitary(Qureg qureg, int *controlQubits, int *controlState, const int numControlQubits, const int targetQubit, ComplexMatrix2 u)
Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary,...
void toComplexMatrixN(QMatrix qm, ComplexMatrixN cm)
Initialises cm with the values of qm.
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...
void multiControlledMultiQubitUnitary(Qureg qureg, int *ctrls, const int numCtrls, int *targs, const int numTargs, ComplexMatrixN u)
Apply a general multi-controlled multi-qubit unitary (including a global phase factor).
void phaseShift(Qureg qureg, const int targetQubit, qreal angle)
Shift the phase between and of a single qubit by a given angle.
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).
void multiQubitUnitary(Qureg qureg, int *targs, const int numTargs, ComplexMatrixN u)
Apply a general multi-qubit unitary (including a global phase factor) with any number of target qubit...
void compactUnitary(Qureg qureg, const int targetQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
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 hadamard(Qureg qureg, const int targetQubit)
Apply the single-qubit Hadamard gate.
void rotateY(Qureg qureg, const int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.
void swapGate(Qureg qureg, int qb1, int qb2)
Performs a SWAP gate between qubit1 and qubit2.
void controlledUnitary(Qureg qureg, const int controlQubit, const int targetQubit, ComplexMatrix2 u)
Apply a general controlled unitary (single control, single target), which can include a global phase ...
void controlledRotateY(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.
void initStateFromAmps(Qureg qureg, qreal *reals, qreal *imags)
Initialise qureg by specifying the complete statevector.
void controlledNot(Qureg qureg, const int controlQubit, const int targetQubit)
Apply the controlled not (single control, single target) gate, also known as the c-X,...
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)
void controlledRotateAroundAxis(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
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 controlledTwoQubitUnitary(Qureg qureg, const int controlQubit, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Apply a general controlled two-qubit unitary (including a global phase factor).
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 controlledPhaseShift(Qureg qureg, const int idQubit1, const int idQubit2, qreal angle)
Introduce a phase factor on state of qubits idQubit1 and idQubit2.
void destroyQureg(Qureg qureg, QuESTEnv env)
Deallocate a Qureg object representing a set of qubits.
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...
void mixDamping(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit amplitude damping (decay to 0 state).
QMatrix getRandomQMatrix(int dim)
Returns a dim-by-dim complex matrix, where the real and imaginary value of each element are independe...
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 unitary(Qureg qureg, const int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary (including a global phase factor).
Represents a system of qubits.
void controlledRotateZ(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.
void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit dephasing noise.
ComplexArray stateVec
Computational state amplitudes - a subset thereof in the MPI version.
long long int getNumAmps(Qureg qureg)
Get the number of probability amplitudes in a qureg object, given by 2^numQubits.
void controlledCompactUnitary(Qureg qureg, const int controlQubit, const int targetQubit, Complex alpha, Complex beta)
Apply a controlled unitary (single control, single target) parameterised by two given complex scalars...
int isDensityMatrix
Whether this instance is a density-state representation.
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 ...
qreal collapseToOutcome(Qureg qureg, const int measureQubit, int outcome)
Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...
void controlledRotateX(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.
#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.
ComplexMatrix2 toComplexMatrix2(QMatrix qm)
Returns a ComplexMatrix2 copy of QMatix qm.
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.
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.
qreal calcProbOfOutcome(Qureg qureg, const int measureQubit, int outcome)
Gives the probability of a specified qubit being measured in the given outcome (0 or 1).
void multiRotateZ(Qureg qureg, int *qubits, int numQubits, qreal angle)
Apply a multi-qubit Z rotation on a selected number of qubits.
void pauliY(Qureg qureg, const int targetQubit)
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.
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.
Represents one complex number.
void twoQubitUnitary(Qureg qureg, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Apply a general two-qubit unitary (including a global phase factor).
QVector getRandomQVector(int dim)
Returns a dim-length vector with random complex amplitudes in the square joining {-1-i,...
void sGate(Qureg qureg, const int targetQubit)
Apply the single-qubit S gate.
void rotateAroundAxis(Qureg qureg, const int rotQubit, qreal angle, Vector axis)
Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere.
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,...
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 pauliX(Qureg qureg, const int targetQubit)
Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate.
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...
Represents a 2x2 matrix of complex numbers.
void mixDepolarising(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit homogeneous depolarising noise.