Unit tests of the QuEST API, using Catch2 in C++14.
More...
|
| TEST_CASE ("applyDiagonalOp", "[operators]") |
|
| TEST_CASE ("applyFullQFT", "[operators]") |
|
| TEST_CASE ("applyMatrix2", "[operators]") |
|
| TEST_CASE ("applyMatrix4", "[operators]") |
|
| TEST_CASE ("applyMatrixN", "[operators]") |
|
| TEST_CASE ("applyMultiControlledMatrixN", "[operators]") |
|
| TEST_CASE ("applyMultiVarPhaseFunc", "[operators]") |
|
| TEST_CASE ("applyMultiVarPhaseFuncOverrides", "[operators]") |
|
| TEST_CASE ("applyNamedPhaseFunc", "[operators]") |
|
| TEST_CASE ("applyNamedPhaseFuncOverrides", "[operators]") |
|
| TEST_CASE ("applyParamNamedPhaseFunc", "[operators]") |
|
| TEST_CASE ("applyParamNamedPhaseFuncOverrides", "[operators]") |
|
| TEST_CASE ("applyPauliHamil", "[operators]") |
|
| TEST_CASE ("applyPauliSum", "[operators]") |
|
| TEST_CASE ("applyPhaseFunc", "[operators]") |
|
| TEST_CASE ("applyPhaseFuncOverrides", "[operators]") |
|
| TEST_CASE ("applyProjector", "[operators]") |
|
| TEST_CASE ("applyQFT", "[operators]") |
|
| TEST_CASE ("applyTrotterCircuit", "[operators]") |
|
| TEST_CASE ("calcDensityInnerProduct", "[calculations]") |
|
| TEST_CASE ("calcExpecDiagonalOp", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliHamil", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliProd", "[calculations]") |
|
| TEST_CASE ("calcExpecPauliSum", "[calculations]") |
|
| TEST_CASE ("calcFidelity", "[calculations]") |
|
| TEST_CASE ("calcHilbertSchmidtDistance", "[calculations]") |
|
| TEST_CASE ("calcInnerProduct", "[calculations]") |
|
| TEST_CASE ("calcProbOfAllOutcomes", "[calculations]") |
|
| TEST_CASE ("calcProbOfOutcome", "[calculations]") |
|
| TEST_CASE ("calcPurity", "[calculations]") |
|
| TEST_CASE ("calcTotalProb", "[calculations]") |
|
| TEST_CASE ("cloneQureg", "[state_initialisations]") |
|
| TEST_CASE ("collapseToOutcome", "[gates]") |
|
| TEST_CASE ("compactUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledCompactUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledMultiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledNot", "[unitaries]") |
|
| TEST_CASE ("controlledPauliY", "[unitaries]") |
|
| TEST_CASE ("controlledPhaseFlip", "[unitaries]") |
|
| TEST_CASE ("controlledPhaseShift", "[unitaries]") |
|
| TEST_CASE ("controlledRotateAroundAxis", "[unitaries]") |
|
| TEST_CASE ("controlledRotateX", "[unitaries]") |
|
| TEST_CASE ("controlledRotateY", "[unitaries]") |
|
| TEST_CASE ("controlledRotateZ", "[unitaries]") |
|
| TEST_CASE ("controlledTwoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("controlledUnitary", "[unitaries]") |
|
| TEST_CASE ("createCloneQureg", "[data_structures]") |
|
| TEST_CASE ("createComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("createDensityQureg", "[data_structures]") |
|
| TEST_CASE ("createDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("createDiagonalOpFromPauliHamilFile", "[data_structures]") |
|
| TEST_CASE ("createPauliHamil", "[data_structures]") |
|
| TEST_CASE ("createPauliHamilFromFile", "[data_structures]") |
|
| TEST_CASE ("createQuESTEnv", "[data_structures]") |
|
| TEST_CASE ("createQureg", "[data_structures]") |
|
| TEST_CASE ("destroyComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("destroyDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("destroyPauliHamil", "[data_structures]") |
|
| TEST_CASE ("destroyQuESTEnv", "[data_structures]") |
|
| TEST_CASE ("destroyQureg", "[data_structures]") |
|
| TEST_CASE ("fromComplex", "[data_structures]") |
|
| TEST_CASE ("getAmp", "[calculations]") |
|
| TEST_CASE ("getDensityAmp", "[calculations]") |
|
| TEST_CASE ("getImagAmp", "[calculations]") |
|
| TEST_CASE ("getNumAmps", "[calculations]") |
|
| TEST_CASE ("getNumQubits", "[calculations]") |
|
| TEST_CASE ("getProbAmp", "[calculations]") |
|
| TEST_CASE ("getRealAmp", "[calculations]") |
|
| TEST_CASE ("getStaticComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("hadamard", "[unitaries]") |
|
| TEST_CASE ("initBlankState", "[state_initialisations]") |
|
| TEST_CASE ("initClassicalState", "[state_initialisations]") |
|
| TEST_CASE ("initComplexMatrixN", "[data_structures]") |
|
| TEST_CASE ("initDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("initDiagonalOpFromPauliHamil", "[data_structures]") |
|
| TEST_CASE ("initPauliHamil", "[data_structures]") |
|
| TEST_CASE ("initPlusState", "[state_initialisations]") |
|
| TEST_CASE ("initPureState", "[state_initialisations]") |
|
| TEST_CASE ("initStateFromAmps", "[state_initialisations]") |
|
| TEST_CASE ("initZeroState", "[state_initialisations]") |
|
| TEST_CASE ("measure", "[gates]") |
|
| TEST_CASE ("measureWithStats", "[gates]") |
|
| TEST_CASE ("mixDamping", "[decoherence]") |
|
| TEST_CASE ("mixDensityMatrix", "[decoherence]") |
|
| TEST_CASE ("mixDephasing", "[decoherence]") |
|
| TEST_CASE ("mixDepolarising", "[decoherence]") |
|
| TEST_CASE ("mixKrausMap", "[decoherence]") |
|
| TEST_CASE ("mixMultiQubitKrausMap", "[decoherence]") |
|
| TEST_CASE ("mixPauli", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitDephasing", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitDepolarising", "[decoherence]") |
|
| TEST_CASE ("mixTwoQubitKrausMap", "[decoherence]") |
|
| TEST_CASE ("multiControlledMultiQubitNot", "[unitaries]") |
|
| TEST_CASE ("multiControlledMultiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiControlledMultiRotatePauli", "[unitaries]") |
|
| TEST_CASE ("multiControlledMultiRotateZ", "[unitaries]") |
|
| TEST_CASE ("multiControlledPhaseFlip", "[unitaries]") |
|
| TEST_CASE ("multiControlledPhaseShift", "[unitaries]") |
|
| TEST_CASE ("multiControlledTwoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiControlledUnitary", "[unitaries]") |
|
| TEST_CASE ("multiQubitNot", "[unitaries]") |
|
| TEST_CASE ("multiQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("multiRotatePauli", "[unitaries]") |
|
| TEST_CASE ("multiRotateZ", "[unitaries]") |
|
| TEST_CASE ("multiStateControlledUnitary", "[unitaries]") |
|
| TEST_CASE ("pauliX", "[unitaries]") |
|
| TEST_CASE ("pauliY", "[unitaries]") |
|
| TEST_CASE ("pauliZ", "[unitaries]") |
|
| TEST_CASE ("phaseShift", "[unitaries]") |
|
| TEST_CASE ("rotateAroundAxis", "[unitaries]") |
|
| TEST_CASE ("rotateX", "[unitaries]") |
|
| TEST_CASE ("rotateY", "[unitaries]") |
|
| TEST_CASE ("rotateZ", "[unitaries]") |
|
| TEST_CASE ("setAmps", "[state_initialisations]") |
|
| TEST_CASE ("setDiagonalOpElems", "[data_structures]") |
|
| TEST_CASE ("setWeightedQureg", "[state_initialisations]") |
|
| TEST_CASE ("sGate", "[unitaries]") |
|
| TEST_CASE ("sqrtSwapGate", "[unitaries]") |
|
| TEST_CASE ("swapGate", "[unitaries]") |
|
| TEST_CASE ("syncDiagonalOp", "[data_structures]") |
|
| TEST_CASE ("tGate", "[unitaries]") |
|
| TEST_CASE ("toComplex", "[data_structures]") |
|
| TEST_CASE ("twoQubitUnitary", "[unitaries]") |
|
| TEST_CASE ("unitary", "[unitaries]") |
|
Unit tests of the QuEST API, using Catch2 in C++14.
◆ TEST_CASE() [1/124]
TEST_CASE |
( |
"applyDiagonalOp" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyDiagonalOp
- Author
- Tyson Jones
Definition at line 32 of file test_operators.cpp.
36 SECTION(
"correctness" ) {
39 GENERATE( range(0,10) );
49 SECTION(
"state-vector" ) {
55 SECTION(
"density-matrix" ) {
59 REQUIRE(
areEqual(quregMatr, ref, 100*REAL_EPS) );
64 SECTION(
"input validation" ) {
66 SECTION(
"mismatching size" ) {
70 REQUIRE_THROWS_WITH(
applyDiagonalOp(quregVec, op), Contains(
"equal number of qubits"));
71 REQUIRE_THROWS_WITH(
applyDiagonalOp(quregMatr, op), Contains(
"equal number of qubits"));
References applyDiagonalOp(), areEqual(), CLEANUP_TEST, createDiagonalOp(), destroyDiagonalOp(), getRandomReal(), DiagonalOp::imag, NUM_QUBITS, DiagonalOp::numElemsPerChunk, PREPARE_TEST, QUEST_ENV, DiagonalOp::real, syncDiagonalOp(), and toQMatrix().
◆ TEST_CASE() [2/124]
TEST_CASE |
( |
"applyFullQFT" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyFullQFT
- Author
- Tyson Jones
Definition at line 83 of file test_operators.cpp.
87 SECTION(
"correctness" ) {
90 GENERATE( range(0,10) );
92 SECTION(
"state-vector" ) {
94 SECTION(
"normalised" ) {
101 REQUIRE(
areEqual(quregVec, refVec) );
103 SECTION(
"unnormalised" ) {
110 REQUIRE(
areEqual(quregVec, refVec) );
113 SECTION(
"density-matrix" ) {
130 REQUIRE(
areEqual(quregMatr, refMatr) );
153 for (
int i=0; i<numStates; i++)
156 REQUIRE(
areEqual(quregMatr, refMatr) );
158 SECTION(
"unnormalised" ) {
166 std::vector<QVector> vecs;
167 std::vector<qcomp> coeffs;
168 for (
int i=0; i<numVecs; i++) {
175 for (
int i=0; i<numVecs; i++)
183 for (
int i=0; i<numVecs; i++)
186 REQUIRE(
areEqual(quregMatr, refMatr) );
190 SECTION(
"input validation" ) {
References applyFullQFT(), areEqual(), CLEANUP_TEST, getDFT(), getMixedDensityMatrix(), getPureDensityMatrix(), getRandomComplex(), getRandomOrthonormalVectors(), getRandomProbabilities(), getRandomQVector(), getRandomStateVector(), getZeroMatrix(), NUM_QUBITS, PREPARE_TEST, and toQureg().
◆ TEST_CASE() [3/124]
TEST_CASE |
( |
"applyMatrix2" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrix2
- Author
- Tyson Jones
Definition at line 203 of file test_operators.cpp.
211 SECTION(
"correctness" ) {
218 int targs[] = {target};
221 SECTION(
"state-vector" ) {
226 REQUIRE(
areEqual(quregVec, refVec) );
228 SECTION(
"density-matrix" ) {
233 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
236 SECTION(
"input validation" ) {
238 SECTION(
"qubit indices" ) {
241 REQUIRE_THROWS_WITH(
applyMatrix2(quregVec, target, matr), Contains(
"Invalid target") );
References applyMatrix2(), applyReferenceMatrix(), areEqual(), CLEANUP_TEST, getRandomQMatrix(), NUM_QUBITS, PREPARE_TEST, and toComplexMatrix2().
◆ TEST_CASE() [4/124]
TEST_CASE |
( |
"applyMatrix4" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrix4
- Author
- Tyson Jones
Definition at line 253 of file test_operators.cpp.
258 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
264 SECTION(
"correctness" ) {
267 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
272 int targs[] = {targ1, targ2};
275 SECTION(
"state-vector" ) {
279 REQUIRE(
areEqual(quregVec, refVec) );
281 SECTION(
"density-matrix" ) {
285 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
288 SECTION(
"input validation" ) {
290 SECTION(
"qubit indices" ) {
294 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, targ1, targ2, matr), Contains(
"Invalid target") );
295 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, targ2, targ1, matr), Contains(
"Invalid target") );
297 SECTION(
"repetition of targets" ) {
300 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, qb, qb, matr), Contains(
"target") && Contains(
"unique") );
302 SECTION(
"matrix fits in node" ) {
305 quregVec.numAmpsPerChunk = 1;
306 REQUIRE_THROWS_WITH(
applyMatrix4(quregVec, 0, 1, matr), Contains(
"targets too many qubits"));
References applyMatrix4(), applyReferenceMatrix(), areEqual(), CLEANUP_TEST, getRandomQMatrix(), NUM_QUBITS, PREPARE_TEST, and toComplexMatrix4().
◆ TEST_CASE() [5/124]
TEST_CASE |
( |
"applyMatrixN" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMatrixN
- Author
- Tyson Jones
Definition at line 318 of file test_operators.cpp.
323 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
325 SECTION(
"correctness" ) {
328 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
340 SECTION(
"state-vector" ) {
344 REQUIRE(
areEqual(quregVec, refVec) );
346 SECTION(
"density-matrix" ) {
350 REQUIRE(
areEqual(quregMatr, refMatr, 100*REAL_EPS) );
354 SECTION(
"input validation" ) {
356 SECTION(
"number of targets" ) {
359 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
363 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"Invalid number of target"));
366 SECTION(
"repetition in targets" ) {
369 int targs[] = {1,2,2};
372 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
375 SECTION(
"qubit indices" ) {
378 int targs[] = {1,2,3};
382 targs[GENERATE_COPY( range(0,numTargs) )] = inv;
383 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"Invalid target") );
387 SECTION(
"matrix creation" ) {
390 int targs[] = {1,2,3};
400 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, numTargs, matr), Contains(
"created") );
402 SECTION(
"matrix dimensions" ) {
404 int targs[2] = {1,2};
407 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, targs, 2, matr), Contains(
"matrix size"));
410 SECTION(
"matrix fits in node" ) {
413 quregVec.numAmpsPerChunk = 1;
416 REQUIRE_THROWS_WITH(
applyMatrixN(quregVec, qb, 2, matr), Contains(
"targets too many qubits"));
References applyMatrixN(), applyReferenceMatrix(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomQMatrix(), ComplexMatrixN::imag, NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [6/124]
TEST_CASE |
( |
"applyMultiControlledMatrixN" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMultiControlledMatrixN
- Author
- Tyson Jones
Definition at line 429 of file test_operators.cpp.
434 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
438 SECTION(
"correctness" ) {
441 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
443 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
447 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
454 SECTION(
"state-vector" ) {
458 REQUIRE(
areEqual(quregVec, refVec) );
460 SECTION(
"density-matrix" ) {
464 REQUIRE(
areEqual(quregMatr, refMatr, 100*REAL_EPS) );
468 SECTION(
"input validation" ) {
470 SECTION(
"number of targets" ) {
474 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
480 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 1, targs, numTargs, matr), Contains(
"Invalid number of target"));
483 SECTION(
"repetition in targets" ) {
487 int targs[] = {1,2,2};
491 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 1, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
494 SECTION(
"number of controls" ) {
502 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, numCtrls, targs, 1, matr), Contains(
"Invalid number of control"));
505 SECTION(
"repetition in controls" ) {
507 int ctrls[] = {0,1,1};
515 SECTION(
"control and target collision" ) {
517 int ctrls[] = {0,1,2};
518 int targs[] = {3,1,4};
522 REQUIRE_THROWS_WITH(
applyMultiControlledMatrixN(quregVec, ctrls, 3, targs, 3, matr), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
525 SECTION(
"qubit indices" ) {
536 qb1[GENERATE_COPY(range(0,numQb))] = inv;
542 SECTION(
"matrix creation" ) {
545 int targs[3] = {1,2,3};
557 SECTION(
"matrix dimensions" ) {
560 int targs[2] = {1,2};
567 SECTION(
"matrix fits in node" ) {
570 quregVec.numAmpsPerChunk = 1;
572 int targs[2] = {1,2};
References applyMultiControlledMatrixN(), applyReferenceMatrix(), areEqual(), calcLog2(), CLEANUP_TEST, createComplexMatrixN(), destroyComplexMatrixN(), getRandomQMatrix(), ComplexMatrixN::imag, NUM_QUBITS, PREPARE_TEST, ComplexMatrixN::real, sublists(), and toComplexMatrixN().
◆ TEST_CASE() [7/124]
TEST_CASE |
( |
"applyMultiVarPhaseFunc" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMultiVarPhaseFunc
- Author
- Tyson Jones
Definition at line 589 of file test_operators.cpp.
593 SECTION(
"correctness" ) {
606 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
610 int minTotalQubits = 0;
613 minTotalQubits = numRegs;
616 minTotalQubits = 2*numRegs;
617 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
623 int unallocQubits = totalNumQubits;
624 int numQubitsPerReg[numRegs];
625 for (
int i=0; i<numRegs; i++)
627 numQubitsPerReg[i] = 1;
631 numQubitsPerReg[i] = 2;
635 while (unallocQubits > 0) {
642 int numTermsPerReg[numRegs];
643 int numTermsTotal = 0;
644 for (
int r=0; r<numRegs; r++) {
646 numTermsPerReg[r] = numTerms;
647 numTermsTotal += numTerms;
653 qreal coeffs[numTermsTotal];
654 qreal expons[numTermsTotal];
655 for (
int r=0; r<numRegs; r++) {
656 for (
int t=0; t<numTermsPerReg[r]; t++) {
678 for (
int r=0; r<numRegs; r++) {
682 for (
size_t i=0; i<singleRegMatr.size(); i++) {
684 long long int ind = 0;
691 for (
int t=0; t<numTermsPerReg[r]; t++)
692 phase += coeffs[t+startInd] * pow(ind, expons[t+startInd]);
694 singleRegMatr[i][i] =
expI(phase);
697 startInd += numTermsPerReg[r];
700 SECTION(
"state-vector" ) {
702 applyMultiVarPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs, encoding, coeffs, expons, numTermsPerReg);
704 REQUIRE(
areEqual(quregVec, refVec, 1E4*REAL_EPS) );
706 SECTION(
"density-matrix" ) {
708 applyMultiVarPhaseFunc(quregMatr, regs, numQubitsPerReg, numRegs, encoding, coeffs, expons, numTermsPerReg);
710 REQUIRE(
areEqual(quregMatr, refMatr, 1E6*REAL_EPS) );
713 SECTION(
"input validation" ) {
716 int numQubitsPerReg[] = {2,3};
717 int qubits[] = {0,1,2,3,4};
719 SECTION(
"number of registers" ) {
722 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL), Contains(
"Invalid number of qubit subregisters") );
724 SECTION(
"number of qubits" ) {
726 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
727 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL), Contains(
"Invalid number of qubits") );
729 SECTION(
"repetition of qubits" ) {
731 qubits[GENERATE(2,3,4)] = qubits[1];
732 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL), Contains(
"The qubits must be unique") );
734 SECTION(
"qubit indices" ) {
737 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL), Contains(
"Invalid qubit index") );
739 SECTION(
"number of terms" ) {
741 int numTermsPerReg[] = {3, 3};
743 numTermsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0 );
744 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, numTermsPerReg), Contains(
"Invalid number of terms in the phase function") );
746 SECTION(
"bit encoding name" ) {
749 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs, enc, NULL, NULL, NULL), Contains(
"Invalid bit encoding") );
751 SECTION(
"two's complement register" ) {
753 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
754 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT, NULL, NULL, NULL), Contains(
"A sub-register contained too few qubits to employ TWOS_COMPLEMENT encoding") );
756 SECTION(
"fractional exponent" ) {
758 int numTermsPerReg[] = {3, 3};
759 qreal coeffs[] = {0,0,0, 0,0,0};
760 qreal expos[] = {1,2,3, 1,2,3};
762 expos[GENERATE(range(0,6))] = GENERATE( 0.5, 1.999, 5.0001 );
763 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT, coeffs, expos, numTermsPerReg), Contains(
"The phase function contained a fractional exponent, which is illegal in TWOS_COMPLEMENT") );
769 SECTION(
"negative exponent" ) {
771 int numTermsPerReg[] = {3, 3};
772 qreal coeffs[] = {0,0,0, 0,0,0};
773 qreal expos[] = {1,2,3, 1,2,3};
775 expos[GENERATE(range(0,6))] = GENERATE( -1, -2, -2.5 );
778 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFunc(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg), Contains(
"The phase function contained an illegal negative exponent") );
References applyMultiVarPhaseFunc(), applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getKroneckerProduct(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NUM_QUBITS, PREPARE_TEST, qreal, sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [8/124]
TEST_CASE |
( |
"applyMultiVarPhaseFuncOverrides" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyMultiVarPhaseFuncOverrides
- Author
- Tyson Jones
Definition at line 790 of file test_operators.cpp.
794 SECTION(
"correctness" ) {
807 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
811 int minTotalQubits = 0;
814 minTotalQubits = numRegs;
817 minTotalQubits = 2*numRegs;
818 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
824 int unallocQubits = totalNumQubits;
825 int numQubitsPerReg[numRegs];
826 for (
int i=0; i<numRegs; i++)
828 numQubitsPerReg[i] = 1;
832 numQubitsPerReg[i] = 2;
836 while (unallocQubits > 0) {
843 int numTermsPerReg[numRegs];
844 int numTermsTotal = 0;
845 for (
int r=0; r<numRegs; r++) {
847 numTermsPerReg[r] = numTerms;
848 numTermsTotal += numTerms;
854 qreal coeffs[numTermsTotal];
855 qreal expons[numTermsTotal];
856 for (
int r=0; r<numRegs; r++) {
857 for (
int t=0; t<numTermsPerReg[r]; t++) {
870 int numOverrides =
getRandomInt(0, (1<<totalNumQubits) + 1);
873 long long int overrideInds[numOverrides*numRegs];
875 for (
int v=0; v<numOverrides; v++) {
876 for (
int r=0; r<numRegs; r++) {
878 overrideInds[flatInd] =
getRandomInt(0, 1<<numQubitsPerReg[r]);
880 overrideInds[flatInd] =
getRandomInt(-(1<<(numQubitsPerReg[r]-1)), (1<<(numQubitsPerReg[r]-1))-1);
886 qreal overridePhases[numOverrides];
887 for (
int v=0; v<numOverrides; v++)
902 for (
int r=0; r<numRegs; r++) {
906 for (
size_t i=0; i<singleRegMatr.size(); i++) {
908 long long int ind = 0;
915 for (
int t=0; t<numTermsPerReg[r]; t++)
916 phase += coeffs[t+startInd] * pow(ind, expons[t+startInd]);
918 singleRegMatr[i][i] =
expI(phase);
921 startInd += numTermsPerReg[r];
923 setDiagMatrixOverrides(allRegMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
925 SECTION(
"state-vector" ) {
927 applyMultiVarPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, coeffs, expons, numTermsPerReg, overrideInds, overridePhases, numOverrides);
929 REQUIRE(
areEqual(quregVec, refVec, 1E4*REAL_EPS) );
931 SECTION(
"density-matrix" ) {
933 applyMultiVarPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, coeffs, expons, numTermsPerReg, overrideInds, overridePhases, numOverrides);
935 REQUIRE(
areEqual(quregMatr, refMatr, 1E6*REAL_EPS) );
938 SECTION(
"input validation" ) {
941 int numQubitsPerReg[] = {2,3};
942 int qubits[] = {0,1,2,3,4};
944 SECTION(
"number of registers" ) {
947 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"Invalid number of qubit subregisters") );
949 SECTION(
"number of qubits" ) {
951 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
952 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"Invalid number of qubits") );
954 SECTION(
"repetition of qubits" ) {
956 qubits[GENERATE(2,3,4)] = qubits[1];
957 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"The qubits must be unique") );
959 SECTION(
"qubit indices" ) {
962 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"Invalid qubit index") );
964 SECTION(
"number of terms" ) {
966 int numTermsPerReg[] = {3, 3};
968 numTermsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0 );
969 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, NULL, NULL, numTermsPerReg, NULL, NULL, 0), Contains(
"Invalid number of terms in the phase function") );
971 SECTION(
"bit encoding name" ) {
974 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"Invalid bit encoding") );
976 SECTION(
"two's complement register" ) {
978 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
979 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT, NULL, NULL, NULL, NULL, NULL, 0), Contains(
"A sub-register contained too few qubits to employ TWOS_COMPLEMENT encoding") );
981 SECTION(
"fractional exponent" ) {
983 int numTermsPerReg[] = {3, 3};
984 qreal coeffs[] = {0,0,0, 0,0,0};
985 qreal expos[] = {1,2,3, 1,2,3};
987 expos[GENERATE(range(0,6))] = GENERATE( 0.5, 1.999, 5.0001 );
988 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT, coeffs, expos, numTermsPerReg, NULL, NULL, 0), Contains(
"The phase function contained a fractional exponent, which is illegal in TWOS_COMPLEMENT") );
991 REQUIRE_NOTHROW(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, coeffs, expos, numTermsPerReg, NULL, NULL, 0) );
993 SECTION(
"negative exponent" ) {
995 int numTermsPerReg[] = {3, 3};
996 qreal coeffs[] = {0,0,0, 0,0,0};
997 qreal expos[] = {1,2,3, 1,2,3};
999 expos[GENERATE(range(0,6))] = GENERATE( -1, -2, -2.5 );
1002 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg, NULL, NULL, 0), Contains(
"The phase function contained an illegal negative exponent") );
1004 SECTION(
"number of overrides" ) {
1006 int numTermsPerReg[] = {3, 3};
1007 qreal coeffs[] = {0,0,0, 0,0,0};
1008 qreal expos[] = {1,2,3, 1,2,3};
1010 int numOverrides = -1;
1011 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs,
UNSIGNED, coeffs, expos, numTermsPerReg, NULL, NULL, numOverrides), Contains(
"Invalid number of phase function overrides specified") );
1013 SECTION(
"override indices" ) {
1015 int numTermsPerReg[] = {3, 3};
1016 qreal coeffs[] = {0,0,0, 0,0,0};
1017 qreal expos[] = {1,2,3, 1,2,3};
1020 int numOverrides = 3;
1021 long long int overrideInds[] = {0,0, 0,0, 0,0};
1022 qreal overridePhases[] = {.1, .1, .1};
1026 int badInd = GENERATE(0, 2, 4);
1027 overrideInds[badInd] = GENERATE( -1, (1<<2) );
1028 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
1029 overrideInds[badInd] = 0;
1033 overrideInds[badInd] = GENERATE( -1, (1<<3) );
1034 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
1035 overrideInds[badInd] = 0;
1039 int minInd = -(1<<(numQubitsPerReg[0]-1));
1040 int maxInd = (1<<(numQubitsPerReg[0]-1)) - 1;
1041 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
1042 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
1043 overrideInds[badInd] = 0;
1046 minInd = -(1<<(numQubitsPerReg[1]-1));
1047 maxInd = (1<<(numQubitsPerReg[1]-1)) -1;
1048 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
1049 REQUIRE_THROWS_WITH(
applyMultiVarPhaseFuncOverrides(quregVec, qubits, numQubitsPerReg, numRegs, enc, coeffs, expos, numTermsPerReg, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
References applyMultiVarPhaseFuncOverrides(), applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getKroneckerProduct(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NUM_QUBITS, PREPARE_TEST, qreal, setDiagMatrixOverrides(), sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [9/124]
TEST_CASE |
( |
"applyNamedPhaseFunc" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyNamedPhaseFunc
- Author
- Tyson Jones
Definition at line 1061 of file test_operators.cpp.
1065 SECTION(
"correctness" ) {
1078 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
1082 int minTotalQubits = 0;
1085 minTotalQubits = numRegs;
1088 minTotalQubits = 2*numRegs;
1089 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
1095 int unallocQubits = totalNumQubits;
1096 int numQubitsPerReg[numRegs];
1097 for (
int i=0; i<numRegs; i++)
1099 numQubitsPerReg[i] = 1;
1103 numQubitsPerReg[i] = 2;
1107 while (unallocQubits > 0) {
1113 qreal regVals[1<<totalNumQubits][numRegs];
1114 for (
long long int i=0; i<(1<<totalNumQubits); i++) {
1116 long long int bits = i;
1117 for (
int r=0; r<numRegs; r++) {
1118 regVals[i][r] = bits % (1 << numQubitsPerReg[r]);
1119 bits = bits >> numQubitsPerReg[r];
1134 for (
size_t i=0; i<diagMatr.size(); i++) {
1136 for (
int r=0; r<numRegs; r++)
1137 phase += pow(regVals[i][r], 2);
1138 phase = sqrt(phase);
1139 diagMatr[i][i] =
expI(phase);
1142 SECTION(
"state-vector" ) {
1146 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1148 SECTION(
"density-matrix" ) {
1152 REQUIRE(
areEqual(quregMatr, refMatr, 142*REAL_EPS) );
1155 SECTION(
"PRODUCT" ) {
1157 for (
size_t i=0; i<diagMatr.size(); i++) {
1159 for (
int r=0; r<numRegs; r++)
1160 phase *= regVals[i][r];
1161 diagMatr[i][i] =
expI(phase);
1164 SECTION(
"state-vector" ) {
1168 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1170 SECTION(
"density-matrix" ) {
1174 REQUIRE(
areEqual(quregMatr, refMatr, 142*REAL_EPS) );
1177 SECTION(
"DISTANCE" ) {
1180 if (numRegs%2 == 0) {
1182 for (
size_t i=0; i<diagMatr.size(); i++) {
1184 for (
int r=0; r<numRegs; r+=2)
1185 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
1186 phase = sqrt(phase);
1187 diagMatr[i][i] =
expI(phase);
1191 SECTION(
"state-vector" ) {
1193 if (numRegs%2 == 0) {
1196 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1199 SECTION(
"density-matrix" ) {
1201 if (numRegs%2 == 0) {
1204 REQUIRE(
areEqual(quregMatr, refMatr, 142*REAL_EPS) );
1209 SECTION(
"input validation" ) {
1212 int numQubitsPerReg[] = {2,3};
1213 int regs[] = {0,1,2,3,4};
1215 SECTION(
"number of registers" ) {
1218 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM), Contains(
"Invalid number of qubit subregisters") );
1220 SECTION(
"number of qubits" ) {
1222 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
1225 SECTION(
"repetition of qubits" ) {
1227 regs[GENERATE(2,3,4)] = regs[1];
1230 SECTION(
"qubit indices" ) {
1235 SECTION(
"bit encoding name" ) {
1238 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM), Contains(
"Invalid bit encoding") );
1240 SECTION(
"two's complement register" ) {
1242 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
1243 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT,
NORM), Contains(
"A sub-register contained too few qubits to employ TWOS_COMPLEMENT encoding") );
1245 SECTION(
"phase function name" ) {
1248 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func), Contains(
"Invalid named phase function") );
1250 SECTION(
"phase function parameters" ) {
1252 enum phaseFunc func = GENERATE(
SCALED_NORM,
INVERSE_NORM,
SCALED_INVERSE_NORM,
SCALED_INVERSE_SHIFTED_NORM,
SCALED_PRODUCT,
INVERSE_PRODUCT,
SCALED_INVERSE_PRODUCT,
SCALED_DISTANCE,
INVERSE_DISTANCE,
SCALED_INVERSE_DISTANCE,
SCALED_INVERSE_SHIFTED_DISTANCE );
1253 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func), Contains(
"Invalid number of parameters") );
1255 SECTION(
"distance pair registers" ) {
1257 int numQb[] = {1,1,1,1,1};
1258 int qb[] = {0,1,2,3,4};
1260 numRegs = GENERATE( 1, 3, 5 );
1261 REQUIRE_THROWS_WITH(
applyNamedPhaseFunc(quregVec, qb, numQb, numRegs,
UNSIGNED,
DISTANCE), Contains(
"Phase functions DISTANCE") && Contains(
"even number of sub-registers") );
References applyNamedPhaseFunc(), applyReferenceOp(), areEqual(), CLEANUP_TEST, DISTANCE, expI(), getRandomInt(), getTwosComplement(), getZeroMatrix(), INVERSE_DISTANCE, INVERSE_NORM, INVERSE_PRODUCT, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NORM, NUM_QUBITS, PREPARE_TEST, PRODUCT, qreal, SCALED_DISTANCE, SCALED_INVERSE_DISTANCE, SCALED_INVERSE_NORM, SCALED_INVERSE_PRODUCT, SCALED_INVERSE_SHIFTED_DISTANCE, SCALED_INVERSE_SHIFTED_NORM, SCALED_NORM, SCALED_PRODUCT, sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [10/124]
TEST_CASE |
( |
"applyNamedPhaseFuncOverrides" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyNamedPhaseFuncOverrides
- Author
- Tyson Jones
Definition at line 1273 of file test_operators.cpp.
1277 SECTION(
"correctness" ) {
1290 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
1294 int minTotalQubits = 0;
1297 minTotalQubits = numRegs;
1300 minTotalQubits = 2*numRegs;
1301 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
1307 int unallocQubits = totalNumQubits;
1308 int numQubitsPerReg[numRegs];
1309 for (
int i=0; i<numRegs; i++)
1311 numQubitsPerReg[i] = 1;
1315 numQubitsPerReg[i] = 2;
1319 while (unallocQubits > 0) {
1326 int numOverrides =
getRandomInt(0, (1<<totalNumQubits) + 1);
1329 long long int overrideInds[numOverrides*numRegs];
1331 for (
int v=0; v<numOverrides; v++) {
1332 for (
int r=0; r<numRegs; r++) {
1334 overrideInds[flatInd] =
getRandomInt(0, 1<<numQubitsPerReg[r]);
1336 overrideInds[flatInd] =
getRandomInt(-(1<<(numQubitsPerReg[r]-1)), (1<<(numQubitsPerReg[r]-1))-1);
1342 qreal overridePhases[numOverrides];
1343 for (
int v=0; v<numOverrides; v++)
1348 qreal regVals[1<<totalNumQubits][numRegs];
1349 for (
long long int i=0; i<(1<<totalNumQubits); i++) {
1351 long long int bits = i;
1352 for (
int r=0; r<numRegs; r++) {
1353 regVals[i][r] = bits % (1 << numQubitsPerReg[r]);
1354 bits = bits >> numQubitsPerReg[r];
1369 for (
size_t i=0; i<diagMatr.size(); i++) {
1371 for (
int r=0; r<numRegs; r++)
1372 phase += pow(regVals[i][r], 2);
1373 phase = sqrt(phase);
1374 diagMatr[i][i] =
expI(phase);
1376 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
1378 SECTION(
"state-vector" ) {
1382 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1384 SECTION(
"density-matrix" ) {
1388 REQUIRE(
areEqual(quregMatr, refMatr, 1E4*REAL_EPS) );
1391 SECTION(
"PRODUCT" ) {
1393 for (
size_t i=0; i<diagMatr.size(); i++) {
1395 for (
int r=0; r<numRegs; r++)
1396 phase *= regVals[i][r];
1397 diagMatr[i][i] =
expI(phase);
1400 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
1402 SECTION(
"state-vector" ) {
1406 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1408 SECTION(
"density-matrix" ) {
1412 REQUIRE(
areEqual(quregMatr, refMatr, 1E4*REAL_EPS) );
1415 SECTION(
"DISTANCE" ) {
1418 if (numRegs%2 == 0) {
1420 for (
size_t i=0; i<diagMatr.size(); i++) {
1422 for (
int r=0; r<numRegs; r+=2)
1423 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
1424 phase = sqrt(phase);
1425 diagMatr[i][i] =
expI(phase);
1428 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
1431 SECTION(
"state-vector" ) {
1433 if (numRegs%2 == 0) {
1436 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1439 SECTION(
"density-matrix" ) {
1441 if (numRegs%2 == 0) {
1444 REQUIRE(
areEqual(quregMatr, refMatr, 1E4*REAL_EPS) );
1449 SECTION(
"input validation" ) {
1452 int numQubitsPerReg[] = {2,3};
1453 int regs[] = {0,1,2,3,4};
1455 SECTION(
"number of registers" ) {
1460 SECTION(
"number of qubits" ) {
1462 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
1465 SECTION(
"repetition of qubits" ) {
1467 regs[GENERATE(2,3,4)] = regs[1];
1470 SECTION(
"qubit indices" ) {
1475 SECTION(
"bit encoding name" ) {
1480 SECTION(
"two's complement register" ) {
1482 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
1485 SECTION(
"phase function name" ) {
1490 SECTION(
"phase function parameters" ) {
1492 enum phaseFunc func = GENERATE(
SCALED_NORM,
INVERSE_NORM,
SCALED_INVERSE_NORM,
SCALED_INVERSE_SHIFTED_NORM,
SCALED_PRODUCT,
INVERSE_PRODUCT,
SCALED_INVERSE_PRODUCT,
SCALED_DISTANCE,
INVERSE_DISTANCE,
SCALED_INVERSE_DISTANCE,
SCALED_INVERSE_SHIFTED_DISTANCE );
1495 SECTION(
"distance pair registers" ) {
1497 int numQb[] = {1,1,1,1,1};
1498 int qb[] = {0,1,2,3,4};
1500 numRegs = GENERATE( 1, 3, 5 );
1503 SECTION(
"number of overrides" ) {
1505 int numOverrides = -1;
1506 REQUIRE_THROWS_WITH(
applyNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, NULL, numOverrides), Contains(
"Invalid number of phase function overrides specified") );
1508 SECTION(
"override indices" ) {
1511 int numOverrides = 3;
1512 long long int overrideInds[] = {0,0, 0,0, 0,0};
1513 qreal overridePhases[] = {.1, .1, .1};
1517 int badInd = GENERATE(0, 2, 4);
1518 overrideInds[badInd] = GENERATE( -1, (1<<2) );
1519 REQUIRE_THROWS_WITH(
applyNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
1520 overrideInds[badInd] = 0;
1524 overrideInds[badInd] = GENERATE( -1, (1<<3) );
1525 REQUIRE_THROWS_WITH(
applyNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
1526 overrideInds[badInd] = 0;
1530 int minInd = -(1<<(numQubitsPerReg[0]-1));
1531 int maxInd = (1<<(numQubitsPerReg[0]-1)) - 1;
1532 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
1533 REQUIRE_THROWS_WITH(
applyNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
1534 overrideInds[badInd] = 0;
1537 minInd = -(1<<(numQubitsPerReg[1]-1));
1538 maxInd = (1<<(numQubitsPerReg[1]-1)) -1;
1539 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
1540 REQUIRE_THROWS_WITH(
applyNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
References applyNamedPhaseFuncOverrides(), applyReferenceOp(), areEqual(), CLEANUP_TEST, DISTANCE, expI(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), INVERSE_DISTANCE, INVERSE_NORM, INVERSE_PRODUCT, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NORM, NUM_QUBITS, PREPARE_TEST, PRODUCT, qreal, SCALED_DISTANCE, SCALED_INVERSE_DISTANCE, SCALED_INVERSE_NORM, SCALED_INVERSE_PRODUCT, SCALED_INVERSE_SHIFTED_DISTANCE, SCALED_INVERSE_SHIFTED_NORM, SCALED_NORM, SCALED_PRODUCT, setDiagMatrixOverrides(), sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [11/124]
TEST_CASE |
( |
"applyParamNamedPhaseFunc" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyParamNamedPhaseFunc
- Author
- Tyson Jones
Definition at line 1552 of file test_operators.cpp.
1556 SECTION(
"correctness" ) {
1569 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
1573 int minTotalQubits = 0;
1576 minTotalQubits = numRegs;
1579 minTotalQubits = 2*numRegs;
1580 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
1586 int unallocQubits = totalNumQubits;
1587 int numQubitsPerReg[numRegs];
1588 for (
int i=0; i<numRegs; i++)
1590 numQubitsPerReg[i] = 1;
1594 numQubitsPerReg[i] = 2;
1598 while (unallocQubits > 0) {
1610 qreal regVals[1<<totalNumQubits][numRegs];
1611 for (
long long int i=0; i<(1<<totalNumQubits); i++) {
1613 long long int bits = i;
1614 for (
int r=0; r<numRegs; r++) {
1615 regVals[i][r] = bits % (1 << numQubitsPerReg[r]);
1616 bits = bits >> numQubitsPerReg[r];
1623 SECTION(
"INVERSE_NORM" ) {
1628 for (
size_t i=0; i<diagMatr.size(); i++) {
1630 for (
int r=0; r<numRegs; r++)
1631 phase += pow(regVals[i][r], 2);
1632 phase = (phase == 0.)? divPhase : 1/sqrt(phase);
1633 diagMatr[i][i] =
expI(phase);
1636 qreal params[] = {divPhase};
1639 SECTION(
"state-vector" ) {
1643 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1645 SECTION(
"density-matrix" ) {
1649 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1653 SECTION(
"SCALED_NORM" ) {
1658 for (
size_t i=0; i<diagMatr.size(); i++) {
1660 for (
int r=0; r<numRegs; r++)
1661 phase += pow(regVals[i][r], 2);
1662 phase = coeff * sqrt(phase);
1663 diagMatr[i][i] =
expI(phase);
1666 qreal params[] = {coeff};
1669 SECTION(
"state-vector" ) {
1673 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1675 SECTION(
"density-matrix" ) {
1679 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1682 SECTION(
"SCALED_INVERSE_NORM" ) {
1688 for (
size_t i=0; i<diagMatr.size(); i++) {
1690 for (
int r=0; r<numRegs; r++)
1691 phase += pow(regVals[i][r], 2);
1692 phase = (phase == 0.)? divPhase : coeff/sqrt(phase);
1693 diagMatr[i][i] =
expI(phase);
1696 qreal params[] = {coeff, divPhase};
1699 SECTION(
"state-vector" ) {
1703 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1705 SECTION(
"density-matrix" ) {
1709 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1712 SECTION(
"SCALED_INVERSE_SHIFTED_NORM" ) {
1715 int numParams = 2 + numRegs;
1716 qreal params[numParams];
1719 for (
int r=0; r<numRegs; r++)
1722 for (
size_t i=0; i<diagMatr.size(); i++) {
1724 for (
int r=0; r<numRegs; r++)
1725 phase += pow(regVals[i][r] - params[2+r], 2);
1726 phase = sqrt(phase);
1727 phase = (phase <= REAL_EPS)? params[1] : params[0]/phase;
1728 diagMatr[i][i] =
expI(phase);
1731 SECTION(
"state-vector" ) {
1735 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1737 SECTION(
"density-matrix" ) {
1741 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1744 SECTION(
"INVERSE_PRODUCT" ) {
1749 for (
size_t i=0; i<diagMatr.size(); i++) {
1751 for (
int r=0; r<numRegs; r++)
1752 phase *= regVals[i][r];
1753 phase = (phase == 0.)? divPhase : 1. / phase;
1754 diagMatr[i][i] =
expI(phase);
1757 qreal params[] = {divPhase};
1760 SECTION(
"state-vector" ) {
1764 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1766 SECTION(
"density-matrix" ) {
1770 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1773 SECTION(
"SCALED_PRODUCT" ) {
1778 for (
size_t i=0; i<diagMatr.size(); i++) {
1780 for (
int r=0; r<numRegs; r++)
1781 phase *= regVals[i][r];
1782 diagMatr[i][i] =
expI(coeff * phase);
1785 qreal params[] = {coeff};
1788 SECTION(
"state-vector" ) {
1792 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1794 SECTION(
"density-matrix" ) {
1798 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1801 SECTION(
"SCALED_INVERSE_PRODUCT" ) {
1806 qreal params[] = {coeff, divPhase};
1809 for (
size_t i=0; i<diagMatr.size(); i++) {
1811 for (
int r=0; r<numRegs; r++)
1812 phase *= regVals[i][r];
1813 phase = (phase == 0)? divPhase : coeff / phase;
1814 diagMatr[i][i] =
expI(phase);
1817 SECTION(
"state-vector" ) {
1821 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1823 SECTION(
"density-matrix" ) {
1827 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1830 SECTION(
"INVERSE_DISTANCE" ) {
1834 qreal params[] = {divPhase};
1838 if (numRegs%2 == 0) {
1840 for (
size_t i=0; i<diagMatr.size(); i++) {
1842 for (
int r=0; r<numRegs; r+=2)
1843 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
1844 phase = (phase == 0.)? divPhase : 1./sqrt(phase);
1845 diagMatr[i][i] =
expI(phase);
1849 SECTION(
"state-vector" ) {
1851 if (numRegs%2 == 0) {
1854 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1857 SECTION(
"density-matrix" ) {
1859 if (numRegs%2 == 0) {
1862 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1866 SECTION(
"SCALED_DISTANCE" ) {
1870 qreal params[] = {coeff};
1874 if (numRegs%2 == 0) {
1876 for (
size_t i=0; i<diagMatr.size(); i++) {
1878 for (
int r=0; r<numRegs; r+=2)
1879 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
1880 phase = coeff * sqrt(phase);
1881 diagMatr[i][i] =
expI(phase);
1885 SECTION(
"state-vector" ) {
1887 if (numRegs%2 == 0) {
1890 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1893 SECTION(
"density-matrix" ) {
1895 if (numRegs%2 == 0) {
1898 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1902 SECTION(
"SCALED_INVERSE_DISTANCE" ) {
1907 qreal params[] = {coeff, divPhase};
1911 if (numRegs%2 == 0) {
1913 for (
size_t i=0; i<diagMatr.size(); i++) {
1915 for (
int r=0; r<numRegs; r+=2)
1916 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
1917 phase = (phase == 0.)? divPhase : coeff/sqrt(phase);
1918 diagMatr[i][i] =
expI(phase);
1922 SECTION(
"state-vector" ) {
1924 if (numRegs%2 == 0) {
1927 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1930 SECTION(
"density-matrix" ) {
1932 if (numRegs%2 == 0) {
1935 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1939 SECTION(
"SCALED_INVERSE_SHIFTED_DISTANCE" ) {
1942 int numParams = 2 + numRegs/2;
1943 qreal params[numParams];
1946 if (numRegs%2 == 0) {
1950 for (
int r=0; r<numRegs/2; r++)
1953 for (
size_t i=0; i<diagMatr.size(); i++) {
1955 for (
int r=0; r<numRegs; r+=2)
1956 phase += pow(regVals[i][r]-regVals[i][r+1]-params[2+r/2], 2);
1957 phase = sqrt(phase);
1958 phase = (phase <= REAL_EPS)? params[1] : params[0]/phase;
1959 diagMatr[i][i] =
expI(phase);
1963 SECTION(
"state-vector" ) {
1965 if (numRegs%2 == 0) {
1968 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
1971 SECTION(
"density-matrix" ) {
1973 if (numRegs%2 == 0) {
1976 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
1981 SECTION(
"input validation" ) {
1984 int numQubitsPerReg[] = {2,3};
1985 int regs[] = {0,1,2,3,4};
1987 SECTION(
"number of registers" ) {
1992 SECTION(
"number of qubits" ) {
1994 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
1997 SECTION(
"repetition of qubits" ) {
1999 regs[GENERATE(2,3,4)] = regs[1];
2002 SECTION(
"qubit indices" ) {
2007 SECTION(
"bit encoding name" ) {
2010 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0), Contains(
"Invalid bit encoding") );
2012 SECTION(
"two's complement register" ) {
2014 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
2015 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT,
NORM, NULL, 0), Contains(
"A sub-register contained too few qubits to employ TWOS_COMPLEMENT encoding") );
2017 SECTION(
"phase function name" ) {
2020 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, NULL, 0), Contains(
"Invalid named phase function") );
2022 SECTION(
"phase function parameters" ) {
2024 qreal params[numRegs + 3];
2025 for (
int r=0; r<numRegs + 3; r++)
2028 SECTION(
"no parameter functions" ) {
2031 int numParams = GENERATE( -1, 1, 2 );
2032 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams), Contains(
"Invalid number of parameters") );
2034 SECTION(
"single parameter functions" ) {
2037 int numParams = GENERATE( -1, 0, 2 );
2038 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams), Contains(
"Invalid number of parameters") );
2040 SECTION(
"two parameter functions" ) {
2043 int numParams = GENERATE( 0, 1, 3 );
2044 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams), Contains(
"Invalid number of parameters") );
2046 SECTION(
"shifted distance" ) {
2048 if (numRegs%2 == 0) {
2050 int numParams = GENERATE_COPY( 0, 1, numRegs/2 - 1, numRegs/2, numRegs/2 + 1, numRegs/2 + 3 );
2051 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams), Contains(
"Invalid number of parameters") );
2054 SECTION(
"shifted norm" ) {
2057 int numParams = GENERATE_COPY( 0, 1, numRegs-1, numRegs, numRegs+1, numRegs+3 );
2058 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFunc(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams), Contains(
"Invalid number of parameters") );
2061 SECTION(
"distance pair registers" ) {
2063 int numQb[] = {1,1,1,1,1};
2064 int qb[] = {0,1,2,3,4};
2066 numRegs = GENERATE( 1, 3, 5 );
References applyParamNamedPhaseFunc(), applyReferenceOp(), areEqual(), CLEANUP_TEST, DISTANCE, expI(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), INVERSE_DISTANCE, INVERSE_NORM, INVERSE_PRODUCT, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NORM, NUM_QUBITS, PREPARE_TEST, PRODUCT, qreal, SCALED_DISTANCE, SCALED_INVERSE_DISTANCE, SCALED_INVERSE_NORM, SCALED_INVERSE_PRODUCT, SCALED_INVERSE_SHIFTED_DISTANCE, SCALED_INVERSE_SHIFTED_NORM, SCALED_NORM, SCALED_PRODUCT, sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [12/124]
TEST_CASE |
( |
"applyParamNamedPhaseFuncOverrides" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyParamNamedPhaseFuncOverrides
- Author
- Tyson Jones
Definition at line 2079 of file test_operators.cpp.
2083 SECTION(
"correctness" ) {
2096 numRegs = GENERATE_COPY( range(1, maxNumRegs+1) );
2100 int minTotalQubits = 0;
2103 minTotalQubits = numRegs;
2106 minTotalQubits = 2*numRegs;
2107 totalNumQubits = GENERATE_COPY( range(minTotalQubits,
NUM_QUBITS+1) );
2113 int unallocQubits = totalNumQubits;
2114 int numQubitsPerReg[numRegs];
2115 for (
int i=0; i<numRegs; i++)
2117 numQubitsPerReg[i] = 1;
2121 numQubitsPerReg[i] = 2;
2125 while (unallocQubits > 0) {
2132 int numOverrides =
getRandomInt(0, (1<<totalNumQubits) + 1);
2135 long long int overrideInds[numOverrides*numRegs];
2137 for (
int v=0; v<numOverrides; v++) {
2138 for (
int r=0; r<numRegs; r++) {
2140 overrideInds[flatInd] =
getRandomInt(0, 1<<numQubitsPerReg[r]);
2142 overrideInds[flatInd] =
getRandomInt(-(1<<(numQubitsPerReg[r]-1)), (1<<(numQubitsPerReg[r]-1))-1);
2148 qreal overridePhases[numOverrides];
2149 for (
int v=0; v<numOverrides; v++)
2154 qreal regVals[1<<totalNumQubits][numRegs];
2155 for (
long long int i=0; i<(1<<totalNumQubits); i++) {
2157 long long int bits = i;
2158 for (
int r=0; r<numRegs; r++) {
2159 regVals[i][r] = bits % (1 << numQubitsPerReg[r]);
2160 bits = bits >> numQubitsPerReg[r];
2174 SECTION(
"INVERSE_NORM" ) {
2178 qreal params[] = {divPhase};
2181 for (
size_t i=0; i<diagMatr.size(); i++) {
2183 for (
int r=0; r<numRegs; r++)
2184 phase += pow(regVals[i][r], 2);
2185 phase = (phase == 0.)? divPhase : 1/sqrt(phase);
2186 diagMatr[i][i] =
expI(phase);
2188 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2190 SECTION(
"state-vector" ) {
2192 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2194 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2196 SECTION(
"density-matrix" ) {
2198 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2200 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2203 SECTION(
"SCALED_NORM" ) {
2207 qreal params[] = {coeff};
2210 for (
size_t i=0; i<diagMatr.size(); i++) {
2212 for (
int r=0; r<numRegs; r++)
2213 phase += pow(regVals[i][r], 2);
2214 phase = coeff * sqrt(phase);
2215 diagMatr[i][i] =
expI(phase);
2217 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2219 SECTION(
"state-vector" ) {
2221 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2223 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2225 SECTION(
"density-matrix" ) {
2227 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2229 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2232 SECTION(
"SCALED_INVERSE_NORM" ) {
2237 qreal params[] = {coeff, divPhase};
2240 for (
size_t i=0; i<diagMatr.size(); i++) {
2242 for (
int r=0; r<numRegs; r++)
2243 phase += pow(regVals[i][r], 2);
2244 phase = (phase == 0.)? divPhase : coeff/sqrt(phase);
2245 diagMatr[i][i] =
expI(phase);
2247 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2249 SECTION(
"state-vector" ) {
2251 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2253 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2255 SECTION(
"density-matrix" ) {
2257 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2259 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2262 SECTION(
"SCALED_INVERSE_SHIFTED_NORM" ) {
2265 int numParams = 2 + numRegs;
2266 qreal params[numParams];
2269 for (
int r=0; r<numRegs; r++)
2272 for (
size_t i=0; i<diagMatr.size(); i++) {
2274 for (
int r=0; r<numRegs; r++)
2275 phase += pow(regVals[i][r] - params[2+r], 2);
2276 phase = sqrt(phase);
2277 phase = (phase <= REAL_EPS)? params[1] : params[0]/phase;
2278 diagMatr[i][i] =
expI(phase);
2280 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2282 SECTION(
"state-vector" ) {
2284 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2286 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2288 SECTION(
"density-matrix" ) {
2290 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2292 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2295 SECTION(
"INVERSE_PRODUCT" ) {
2299 qreal params[] = {divPhase};
2302 for (
size_t i=0; i<diagMatr.size(); i++) {
2304 for (
int r=0; r<numRegs; r++)
2305 phase *= regVals[i][r];
2306 phase = (phase == 0.)? divPhase : 1. / phase;
2307 diagMatr[i][i] =
expI(phase);
2309 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2311 SECTION(
"state-vector" ) {
2313 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2315 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2317 SECTION(
"density-matrix" ) {
2319 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2321 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2324 SECTION(
"SCALED_PRODUCT" ) {
2328 qreal params[] = {coeff};
2331 for (
size_t i=0; i<diagMatr.size(); i++) {
2333 for (
int r=0; r<numRegs; r++)
2334 phase *= regVals[i][r];
2335 diagMatr[i][i] =
expI(coeff * phase);
2337 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2339 SECTION(
"state-vector" ) {
2341 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2343 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2345 SECTION(
"density-matrix" ) {
2347 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2349 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2352 SECTION(
"SCALED_INVERSE_PRODUCT" ) {
2357 qreal params[] = {coeff, divPhase};
2360 for (
size_t i=0; i<diagMatr.size(); i++) {
2362 for (
int r=0; r<numRegs; r++)
2363 phase *= regVals[i][r];
2364 phase = (phase == 0)? divPhase : coeff / phase;
2365 diagMatr[i][i] =
expI(phase);
2367 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2369 SECTION(
"state-vector" ) {
2371 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2373 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2375 SECTION(
"density-matrix" ) {
2377 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2379 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2382 SECTION(
"INVERSE_DISTANCE" ) {
2386 qreal params[] = {divPhase};
2390 if (numRegs%2 == 0) {
2392 for (
size_t i=0; i<diagMatr.size(); i++) {
2394 for (
int r=0; r<numRegs; r+=2)
2395 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
2396 phase = (phase == 0.)? divPhase : 1./sqrt(phase);
2397 diagMatr[i][i] =
expI(phase);
2399 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2402 SECTION(
"state-vector" ) {
2404 if (numRegs%2 == 0) {
2405 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2407 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2410 SECTION(
"density-matrix" ) {
2412 if (numRegs%2 == 0) {
2413 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2415 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2419 SECTION(
"SCALED_DISTANCE" ) {
2423 qreal params[] = {coeff};
2427 if (numRegs%2 == 0) {
2429 for (
size_t i=0; i<diagMatr.size(); i++) {
2431 for (
int r=0; r<numRegs; r+=2)
2432 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
2433 phase = coeff * sqrt(phase);
2434 diagMatr[i][i] =
expI(phase);
2436 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2439 SECTION(
"state-vector" ) {
2441 if (numRegs%2 == 0) {
2442 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2444 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2447 SECTION(
"density-matrix" ) {
2449 if (numRegs%2 == 0) {
2450 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2452 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2456 SECTION(
"SCALED_INVERSE_DISTANCE" ) {
2461 qreal params[] = {coeff, divPhase};
2465 if (numRegs%2 == 0) {
2467 for (
size_t i=0; i<diagMatr.size(); i++) {
2469 for (
int r=0; r<numRegs; r+=2)
2470 phase += pow(regVals[i][r+1]-regVals[i][r], 2);
2471 phase = (phase == 0.)? divPhase : coeff/sqrt(phase);
2472 diagMatr[i][i] =
expI(phase);
2474 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2477 SECTION(
"state-vector" ) {
2479 if (numRegs%2 == 0) {
2480 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2482 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2485 SECTION(
"density-matrix" ) {
2487 if (numRegs%2 == 0) {
2488 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2490 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2494 SECTION(
"SCALED_INVERSE_SHIFTED_DISTANCE" ) {
2497 int numParams = 2 + numRegs/2;
2498 qreal params[numParams];
2501 if (numRegs%2 == 0) {
2505 for (
int r=0; r<numRegs/2; r++)
2508 for (
size_t i=0; i<diagMatr.size(); i++) {
2510 for (
int r=0; r<numRegs; r+=2)
2511 phase += pow(regVals[i][r]-regVals[i][r+1]-params[2+r/2], 2);
2512 phase = sqrt(phase);
2513 phase = (phase <= REAL_EPS)? params[1] : params[0]/phase;
2514 diagMatr[i][i] =
expI(phase);
2517 setDiagMatrixOverrides(diagMatr, numQubitsPerReg, numRegs, encoding, overrideInds, overridePhases, numOverrides);
2520 SECTION(
"state-vector" ) {
2522 if (numRegs%2 == 0) {
2523 applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2525 REQUIRE(
areEqual(quregVec, refVec, 1E2*REAL_EPS) );
2528 SECTION(
"density-matrix" ) {
2530 if (numRegs%2 == 0) {
2531 applyParamNamedPhaseFuncOverrides(quregMatr, regs, numQubitsPerReg, numRegs, encoding, func, params, numParams, overrideInds, overridePhases, numOverrides);
2533 REQUIRE(
areEqual(quregMatr, refMatr, 1E2*REAL_EPS) );
2538 SECTION(
"input validation" ) {
2541 int numQubitsPerReg[] = {2,3};
2542 int regs[] = {0,1,2,3,4};
2544 SECTION(
"number of registers" ) {
2547 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"Invalid number of qubit subregisters") );
2549 SECTION(
"number of qubits" ) {
2551 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = GENERATE( -1, 0, 1+
NUM_QUBITS );
2552 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"Invalid number of qubits") );
2554 SECTION(
"repetition of qubits" ) {
2556 regs[GENERATE(2,3,4)] = regs[1];
2557 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"The qubits must be unique") );
2559 SECTION(
"qubit indices" ) {
2562 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"Invalid qubit index") );
2564 SECTION(
"bit encoding name" ) {
2567 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"Invalid bit encoding") );
2569 SECTION(
"two's complement register" ) {
2571 numQubitsPerReg[GENERATE_COPY(range(0,numRegs))] = 1;
2572 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
TWOS_COMPLEMENT,
NORM, NULL, 0, NULL, NULL, 0), Contains(
"A sub-register contained too few qubits to employ TWOS_COMPLEMENT encoding") );
2574 SECTION(
"phase function name" ) {
2577 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, NULL, 0, NULL, NULL, 0), Contains(
"Invalid named phase function") );
2579 SECTION(
"phase function parameters" ) {
2581 qreal params[numRegs + 3];
2582 for (
int r=0; r<numRegs + 3; r++)
2585 SECTION(
"no parameter functions" ) {
2588 int numParams = GENERATE( -1, 1, 2 );
2589 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams, NULL, NULL, 0), Contains(
"Invalid number of parameters") );
2591 SECTION(
"single parameter functions" ) {
2594 int numParams = GENERATE( -1, 0, 2 );
2595 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams, NULL, NULL, 0), Contains(
"Invalid number of parameters") );
2597 SECTION(
"two parameter functions" ) {
2600 int numParams = GENERATE( 0, 1, 3 );
2601 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams, NULL, NULL, 0), Contains(
"Invalid number of parameters") );
2603 SECTION(
"shifted distance" ) {
2605 if (numRegs%2 == 0) {
2607 int numParams = GENERATE_COPY( 0, 1, numRegs/2 - 1, numRegs/2, numRegs/2 + 1, numRegs/2 + 3 );
2608 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams, NULL, NULL, 0), Contains(
"Invalid number of parameters") );
2611 SECTION(
"shifted norm" ) {
2614 int numParams = GENERATE_COPY( 0, 1, numRegs-1, numRegs, numRegs+1, numRegs+3 );
2615 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED, func, params, numParams, NULL, NULL, 0), Contains(
"Invalid number of parameters") );
2618 SECTION(
"distance pair registers" ) {
2620 int numQb[] = {1,1,1,1,1};
2621 int qb[] = {0,1,2,3,4};
2623 numRegs = GENERATE( 1, 3, 5 );
2624 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, qb, numQb, numRegs,
UNSIGNED,
DISTANCE, NULL, 0, NULL, NULL, 0), Contains(
"Phase functions DISTANCE") && Contains(
"even number of sub-registers") );
2626 SECTION(
"number of overrides" ) {
2628 int numOverrides = -1;
2629 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs,
UNSIGNED,
NORM, NULL, 0, NULL, NULL, numOverrides), Contains(
"Invalid number of phase function overrides specified") );
2631 SECTION(
"override indices" ) {
2634 int numOverrides = 3;
2635 long long int overrideInds[] = {0,0, 0,0, 0,0};
2636 qreal overridePhases[] = {.1, .1, .1};
2640 int badInd = GENERATE(0, 2, 4);
2641 overrideInds[badInd] = GENERATE( -1, (1<<2) );
2642 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
2643 overrideInds[badInd] = 0;
2647 overrideInds[badInd] = GENERATE( -1, (1<<3) );
2648 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
2649 overrideInds[badInd] = 0;
2653 int minInd = -(1<<(numQubitsPerReg[0]-1));
2654 int maxInd = (1<<(numQubitsPerReg[0]-1)) - 1;
2655 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
2656 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
2657 overrideInds[badInd] = 0;
2660 minInd = -(1<<(numQubitsPerReg[1]-1));
2661 maxInd = (1<<(numQubitsPerReg[1]-1)) -1;
2662 overrideInds[badInd] = GENERATE_COPY( minInd-1, maxInd+1 );
2663 REQUIRE_THROWS_WITH(
applyParamNamedPhaseFuncOverrides(quregVec, regs, numQubitsPerReg, numRegs, enc,
NORM, NULL, 0, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
References applyParamNamedPhaseFuncOverrides(), applyReferenceOp(), areEqual(), CLEANUP_TEST, DISTANCE, expI(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), INVERSE_DISTANCE, INVERSE_NORM, INVERSE_PRODUCT, MAX_NUM_REGS_APPLY_ARBITRARY_PHASE, NORM, NUM_QUBITS, PREPARE_TEST, PRODUCT, qreal, SCALED_DISTANCE, SCALED_INVERSE_DISTANCE, SCALED_INVERSE_NORM, SCALED_INVERSE_PRODUCT, SCALED_INVERSE_SHIFTED_DISTANCE, SCALED_INVERSE_SHIFTED_NORM, SCALED_NORM, SCALED_PRODUCT, setDiagMatrixOverrides(), sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [13/124]
TEST_CASE |
( |
"applyPauliHamil" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPauliHamil
- Author
- Tyson Jones
Definition at line 2675 of file test_operators.cpp.
2685 SECTION(
"correctness" ) {
2690 GENERATE( range(0,10) );
2692 int numTerms = GENERATE( 1, 2, 10, 15 );
2697 SECTION(
"state-vector" ) {
2703 REQUIRE(
areEqual(vecIn, vecRef) );
2706 REQUIRE(
areEqual(vecOut, refHamil * vecRef) );
2708 SECTION(
"density-matrix" ) {
2714 REQUIRE(
areEqual(matIn, matRef) );
2717 REQUIRE(
areEqual(matOut, refHamil * matRef, 1E2*REAL_EPS) );
2722 SECTION(
"input validation" ) {
2724 SECTION(
"pauli codes" ) {
2731 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, vecOut), Contains(
"Invalid Pauli code") );
2735 SECTION(
"qureg dimensions" ) {
2740 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, badVec), Contains(
"Dimensions of the qubit registers don't match") );
2745 SECTION(
"qureg types" ) {
2749 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, matOut), Contains(
"Registers must both be state-vectors or both be density matrices") );
2753 SECTION(
"matching hamiltonian qubits" ) {
2757 REQUIRE_THROWS_WITH(
applyPauliHamil(vecIn, hamil, vecOut), Contains(
"same number of qubits") );
2758 REQUIRE_THROWS_WITH(
applyPauliHamil(matIn, hamil, matOut), Contains(
"same number of qubits") );
References applyPauliHamil(), areEqual(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), initDebugState(), NUM_QUBITS, PauliHamil::pauliCodes, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [14/124]
TEST_CASE |
( |
"applyPauliSum" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPauliSum
- Author
- Tyson Jones
Definition at line 2775 of file test_operators.cpp.
2785 SECTION(
"correctness" ) {
2792 GENERATE( range(0,10) );
2794 int numTerms = GENERATE( 1, 2, 10, 15);
2798 qreal coeffs[numTerms];
2803 SECTION(
"state-vector" ) {
2809 REQUIRE(
areEqual(vecIn, vecRef) );
2812 REQUIRE(
areEqual(vecOut, pauliSum * vecRef) );
2814 SECTION(
"density-matrix" ) {
2820 REQUIRE(
areEqual(matIn, matRef) );
2823 REQUIRE(
areEqual(matOut, pauliSum * matRef, 1E2*REAL_EPS) );
2826 SECTION(
"input validation" ) {
2828 SECTION(
"number of terms" ) {
2830 int numTerms = GENERATE( -1, 0 );
2831 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, NULL, NULL, numTerms, vecOut), Contains(
"Invalid number of terms") );
2833 SECTION(
"pauli codes" ) {
2839 for (
int i=0; i<numPaulis; i++)
2843 paulis[GENERATE_COPY( range(0,numPaulis) )] = (
pauliOpType) GENERATE( -1, 4 );
2844 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, numTerms, vecOut), Contains(
"Invalid Pauli code") );
2846 SECTION(
"qureg dimensions" ) {
2850 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, 1, badVec), Contains(
"Dimensions of the qubit registers don't match") );
2853 SECTION(
"qureg types" ) {
2856 REQUIRE_THROWS_WITH(
applyPauliSum(vecIn, paulis, NULL, 1, matOut), Contains(
"Registers must both be state-vectors or both be density matrices") );
References applyPauliSum(), areEqual(), createDensityQureg(), createQureg(), destroyQureg(), initDebugState(), NUM_QUBITS, PAULI_I, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [15/124]
TEST_CASE |
( |
"applyPhaseFunc" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPhaseFunc
- Author
- Tyson Jones
Definition at line 2871 of file test_operators.cpp.
2875 SECTION(
"correctness" ) {
2881 int numQubits = GENERATE_COPY( range(1,
NUM_QUBITS+1) );
2895 qreal coeffs[numTerms];
2896 qreal expons[numTerms];
2897 for (
int t=0; t<numTerms; t++) {
2907 for (
size_t i=0; i<matr.size(); i++) {
2909 long long int ind = 0;
2916 for (
int t=0; t<numTerms; t++)
2917 phase += coeffs[t] * pow(ind, expons[t]);
2919 matr[i][i] =
expI(phase);
2922 SECTION(
"state-vector" ) {
2924 applyPhaseFunc(quregVec, qubits, numQubits, encoding, coeffs, expons, numTerms);
2926 REQUIRE(
areEqual(quregVec, refVec, 1E4*REAL_EPS) );
2928 SECTION(
"density-matrix" ) {
2930 applyPhaseFunc(quregMatr, qubits, numQubits, encoding, coeffs, expons, numTerms);
2932 REQUIRE(
areEqual(quregMatr, refMatr, 1E6*REAL_EPS) );
2935 SECTION(
"input validation" ) {
2938 int qubits[] = {0,1,2};
2940 SECTION(
"number of qubits" ) {
2942 numQubits = GENERATE_COPY( -1, 0,
NUM_QUBITS+1 );
2943 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, NULL, numQubits,
UNSIGNED, NULL, NULL, 1), Contains(
"Invalid number of qubits") );
2945 SECTION(
"repetition of qubits" ) {
2947 qubits[GENERATE(1,2)] = qubits[0];
2948 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, 1), Contains(
"The qubits must be unique") );
2950 SECTION(
"qubit indices" ) {
2953 qubits[ GENERATE_COPY( range(0,numQubits) )] = inv;
2954 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, 1), Contains(
"Invalid qubit index") );
2956 SECTION(
"number of terms" ) {
2958 int numTerms = GENERATE( -1, 0 );
2959 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, numTerms), Contains(
"Invalid number of terms in the phase function") );
2961 SECTION(
"bit encoding name" ) {
2964 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits, enc, NULL, NULL, 1), Contains(
"Invalid bit encoding") );
2966 SECTION(
"two's complement register" ) {
2969 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits,
TWOS_COMPLEMENT, NULL, NULL, 1), Contains(
"too few qubits to employ TWOS_COMPLEMENT") );
2971 SECTION(
"fractional exponent" ) {
2974 qreal coeffs[] = {0,0,0};
2975 qreal expos[] = {1,2,3};
2976 expos[GENERATE_COPY( range(0,numTerms) )] = GENERATE( 0.5, 1.999, 5.0001 );
2978 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits,
TWOS_COMPLEMENT, coeffs, expos, numTerms), Contains(
"fractional exponent") && Contains(
"TWOS_COMPLEMENT") && Contains(
"negative indices were not overriden") );
2980 SECTION(
"negative exponent" ) {
2983 qreal coeffs[] = {0,0,0};
2984 qreal expos[] = {1,2,3};
2985 expos[GENERATE_COPY( range(0,numTerms) )] = GENERATE( -1, -2, -1.5 );
2989 REQUIRE_THROWS_WITH(
applyPhaseFunc(quregVec, qubits, numQubits, encoding, coeffs, expos, numTerms), Contains(
"The phase function contained a negative exponent which would diverge at zero, but the zero index was not overriden") );
References applyPhaseFunc(), applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), NUM_QUBITS, PREPARE_TEST, qreal, sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [16/124]
TEST_CASE |
( |
"applyPhaseFuncOverrides" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyPhaseFuncOverrides
- Author
- Tyson Jones
Definition at line 3001 of file test_operators.cpp.
3005 SECTION(
"correctness" ) {
3011 int numQubits = GENERATE_COPY( range(1,
NUM_QUBITS+1) );
3026 qreal coeffs[numTerms];
3027 qreal expons[numTerms];
3028 for (
int t=0; t<numTerms; t++) {
3037 int numOverrides =
getRandomInt(1, (1<<numQubits) + 1);
3040 long long int overrideInds[numOverrides];
3041 overrideInds[0] = 0LL;
3042 for (
int i=1; i<numOverrides; i++)
3046 overrideInds[i] =
getRandomInt(-(1<<(numQubits-1)), (1<<(numQubits-1))-1);
3049 qreal overridePhases[numOverrides];
3050 for (
int i=0; i<numOverrides; i++)
3055 for (
size_t i=0; i<matr.size(); i++) {
3057 long long int ind = 0;
3065 bool overriden =
false;
3066 for (
int v=0; v<numOverrides; v++) {
3067 if (ind == overrideInds[v]) {
3068 phase = overridePhases[v];
3076 for (
int t=0; t<numTerms; t++)
3077 phase += coeffs[t] * pow(ind, expons[t]);
3080 matr[i][i] =
expI(phase);
3083 SECTION(
"state-vector" ) {
3085 applyPhaseFuncOverrides(quregVec, qubits, numQubits, encoding, coeffs, expons, numTerms, overrideInds, overridePhases, numOverrides);
3087 REQUIRE(
areEqual(quregVec, refVec, 1E4*REAL_EPS) );
3089 SECTION(
"density-matrix" ) {
3091 applyPhaseFuncOverrides(quregMatr, qubits, numQubits, encoding, coeffs, expons, numTerms, overrideInds, overridePhases, numOverrides);
3093 REQUIRE(
areEqual(quregMatr, refMatr, 1E6*REAL_EPS) );
3096 SECTION(
"input validation" ) {
3099 int qubits[] = {0,1,2};
3101 SECTION(
"number of qubits" ) {
3103 int numQubits = GENERATE_COPY( -1, 0,
NUM_QUBITS+1 );
3104 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, NULL, numQubits,
UNSIGNED, NULL, NULL, 1, NULL, NULL, 0), Contains(
"Invalid number of qubits") );
3106 SECTION(
"repetition qubits" ) {
3108 qubits[GENERATE(1,2)] = qubits[0];
3109 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, 1, NULL, NULL, 0), Contains(
"The qubits must be unique") );
3111 SECTION(
"qubit indices" ) {
3114 qubits[ GENERATE_COPY( range(0,numQubits) )] = inv;
3115 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, 1, NULL, NULL, 0), Contains(
"Invalid qubit index") );
3117 SECTION(
"number of terms" ) {
3119 int numTerms = GENERATE( -1, 0 );
3120 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
UNSIGNED, NULL, NULL, numTerms, NULL, NULL, 0), Contains(
"Invalid number of terms in the phase function") );
3122 SECTION(
"bit encoding name" ) {
3125 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits, enc, NULL, NULL, 1, NULL, NULL, 0), Contains(
"Invalid bit encoding") );
3127 SECTION(
"two's complement register" ) {
3130 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
TWOS_COMPLEMENT, NULL, NULL, 1, NULL, NULL, 0), Contains(
"too few qubits to employ TWOS_COMPLEMENT") );
3132 SECTION(
"number of overrides" ) {
3134 qreal dummyTerms[] = {0};
3136 int numOverrides = GENERATE_COPY( -1, 1 + (1<<numQubits) );
3137 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
UNSIGNED, dummyTerms, dummyTerms, 1, NULL, NULL, numOverrides), Contains(
"Invalid number of phase function overrides") );
3139 SECTION(
"override indices" ) {
3141 int numOverrides = 3;
3142 long long int overrideInds[] = {0,1,2};
3143 qreal overridePhases[] = {.1,.1,.1};
3144 qreal dummyTerms[] = {0};
3147 overrideInds[GENERATE(0,1,2)] = GENERATE_COPY( -1, (1<<numQubits) );
3148 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits, encoding, dummyTerms, dummyTerms, 1, overrideInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the UNSIGNED encoding") );
3151 long long int newInds[] = {0,1,2};
3152 int minInd = -(1<<(numQubits-1));
3153 int maxInd = (1<<(numQubits-1)) -1;
3154 newInds[GENERATE(0,1,2)] = GENERATE_COPY( minInd-1, maxInd+1 );
3155 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits, encoding, dummyTerms, dummyTerms, 1, newInds, overridePhases, numOverrides), Contains(
"Invalid phase function override index, in the TWOS_COMPLEMENT encoding") );
3157 SECTION(
"fractional exponent" ) {
3160 qreal coeffs[] = {0,0,0};
3161 qreal expos[] = {1,2,3};
3164 expos[GENERATE_COPY( range(0,numTerms) )] = GENERATE( 0.5, 1.999, 5.0001 );
3167 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
TWOS_COMPLEMENT, coeffs, expos, numTerms, NULL, NULL, 0), Contains(
"fractional exponent") && Contains(
"TWOS_COMPLEMENT") && Contains(
"negative indices were not overriden") );
3169 int numNegs = 1 << (numQubits-1);
3170 long long int overrideInds[numNegs];
3171 qreal overridePhases[numNegs];
3172 for (
int i=0; i<numNegs; i++) {
3173 overrideInds[i] = -(i+1);
3174 overridePhases[i] = 0;
3181 overrideInds[GENERATE_COPY( range(0,numNegs) )] = 0;
3182 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits,
TWOS_COMPLEMENT, coeffs, expos, numTerms, overrideInds, overridePhases, numNegs), Contains(
"fractional exponent") && Contains(
"TWOS_COMPLEMENT") && Contains(
"negative indices were not overriden") );
3184 SECTION(
"negative exponent" ) {
3187 qreal coeffs[] = {0,0,0};
3188 qreal expos[] = {1,2,3};
3189 expos[GENERATE_COPY( range(0,numTerms) )] = GENERATE( -1, -2 );
3194 int numOverrides = GENERATE( 0, 3 );
3195 long long int overrideInds[] = {1,2,3};
3196 qreal overridePhases[] = {0,0,0};
3197 REQUIRE_THROWS_WITH(
applyPhaseFuncOverrides(quregVec, qubits, numQubits, encoding, coeffs, expos, numTerms, overrideInds, overridePhases, numOverrides), Contains(
"The phase function contained a negative exponent which would diverge at zero, but the zero index was not overriden") );
3201 overrideInds[GENERATE_COPY(range(0,numOverrides))] = 0;
3202 REQUIRE_NOTHROW(
applyPhaseFuncOverrides(quregVec, qubits, numQubits, encoding, coeffs, expos, numTerms, overrideInds, overridePhases, numOverrides) );
References applyPhaseFuncOverrides(), applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomInt(), getRandomReal(), getTwosComplement(), getZeroMatrix(), NUM_QUBITS, PREPARE_TEST, qreal, sublists(), TWOS_COMPLEMENT, and UNSIGNED.
◆ TEST_CASE() [17/124]
TEST_CASE |
( |
"applyProjector" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyProjector
- Author
- Tyson Jones
Definition at line 3214 of file test_operators.cpp.
3219 SECTION(
"correctness" ) {
3222 int outcome = GENERATE( 0, 1 );
3225 GENERATE( range(0,10) );
3227 SECTION(
"state-vector" ) {
3229 SECTION(
"normalised" ) {
3236 for (
size_t ind=0; ind<vecRef.size(); ind++) {
3237 int bit = (ind >> qubit) & 1;
3245 SECTION(
"unnormalised" ) {
3252 for (
size_t ind=0; ind<vecRef.size(); ind++) {
3253 int bit = (ind >> qubit) & 1;
3262 SECTION(
"density-matrix" ) {
3273 for (
size_t r=0; r<matRef.size(); r++) {
3274 for (
size_t c=0; c<matRef.size(); c++) {
3275 int ketBit = (c >> qubit) & 1;
3276 int braBit = (r >> qubit) & 1;
3277 if (!(ketBit == outcome && braBit == outcome))
3284 SECTION(
"mixed" ) {
3292 for (
size_t r=0; r<matRef.size(); r++) {
3293 for (
size_t c=0; c<matRef.size(); c++) {
3294 int ketBit = (c >> qubit) & 1;
3295 int braBit = (r >> qubit) & 1;
3296 if (!(ketBit == outcome && braBit == outcome))
3303 SECTION(
"unnormalised" ) {
3311 for (
size_t r=0; r<matRef.size(); r++) {
3312 for (
size_t c=0; c<matRef.size(); c++) {
3313 int ketBit = (c >> qubit) & 1;
3314 int braBit = (r >> qubit) & 1;
3315 if (!(ketBit == outcome && braBit == outcome))
3324 SECTION(
"input validation" ) {
3326 SECTION(
"qubit index" ) {
3330 REQUIRE_THROWS_WITH(
applyProjector(mat, qubit, outcome), Contains(
"Invalid target qubit") );
3332 SECTION(
"outcome value" ) {
3335 int outcome = GENERATE( -1, 2 );
3336 REQUIRE_THROWS_WITH(
applyProjector(mat, qubit, outcome), Contains(
"Invalid measurement outcome") );
References applyProjector(), areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getPureDensityMatrix(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomQVector(), getRandomStateVector(), NUM_QUBITS, QUEST_ENV, and toQureg().
◆ TEST_CASE() [18/124]
TEST_CASE |
( |
"applyQFT" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyQFT
- Author
- Tyson Jones
Definition at line 3349 of file test_operators.cpp.
3353 SECTION(
"correctness" ) {
3356 int numQubits = GENERATE_COPY( range(1,
NUM_QUBITS+1) );
3361 SECTION(
"state-vector" ) {
3363 SECTION(
"normalised" ) {
3368 applyQFT(quregVec, qubits, numQubits);
3369 refVec =
getDFT(refVec, qubits, numQubits);
3371 REQUIRE(
areEqual(quregVec, refVec) );
3373 SECTION(
"unnormalised" ) {
3378 applyQFT(quregVec, qubits, numQubits);
3379 refVec =
getDFT(refVec, qubits, numQubits);
3381 REQUIRE(
areEqual(quregVec, refVec) );
3384 SECTION(
"density-matrix" ) {
3396 applyQFT(quregMatr, qubits, numQubits);
3397 refVec =
getDFT(refVec, qubits, numQubits);
3400 REQUIRE(
areEqual(quregMatr, refMatr) );
3402 SECTION(
"mixed" ) {
3419 applyQFT(quregMatr, qubits, numQubits);
3423 for (
int i=0; i<numStates; i++) {
3428 REQUIRE(
areEqual(quregMatr, refMatr) );
3430 SECTION(
"unnormalised" ) {
3438 std::vector<QVector> vecs;
3439 std::vector<qcomp> coeffs;
3440 for (
int i=0; i<numVecs; i++) {
3447 for (
int i=0; i<numVecs; i++)
3451 applyQFT(quregMatr, qubits, numQubits);
3455 for (
int i=0; i<numVecs; i++) {
3460 REQUIRE(
areEqual(quregMatr, refMatr) );
3464 SECTION(
"input validation" ) {
3466 SECTION(
"number of targets" ) {
3469 int numQubits = GENERATE( -1, 0,
NUM_QUBITS+1 );
3472 REQUIRE_THROWS_WITH(
applyQFT(quregVec, qubits, numQubits), Contains(
"Invalid number of target"));
3474 SECTION(
"repetition in targets" ) {
3477 int qubits[] = {1,2,2};
3479 REQUIRE_THROWS_WITH(
applyQFT(quregVec, qubits, numQubits), Contains(
"target") && Contains(
"unique"));
3481 SECTION(
"qubit indices" ) {
3484 int qubits[] = {1,2,3};
3487 qubits[GENERATE_COPY( range(0,numQubits) )] = inv;
3488 REQUIRE_THROWS_WITH(
applyQFT(quregVec, qubits, numQubits), Contains(
"Invalid target") );
References applyQFT(), areEqual(), CLEANUP_TEST, getDFT(), getMixedDensityMatrix(), getPureDensityMatrix(), getRandomComplex(), getRandomOrthonormalVectors(), getRandomProbabilities(), getRandomQVector(), getRandomStateVector(), getZeroMatrix(), NUM_QUBITS, PREPARE_TEST, sublists(), and toQureg().
◆ TEST_CASE() [19/124]
TEST_CASE |
( |
"applyTrotterCircuit" |
, |
|
|
"" |
[operators] |
|
) |
| |
- See also
- applyTrotterCircuit
- Author
- Tyson Jones
Definition at line 3500 of file test_operators.cpp.
3510 SECTION(
"correctness" ) {
3512 SECTION(
"one term" ) {
3520 int targs[] = {0, 1, 2};
3523 for (
int i=0; i<numTargs; i++)
3530 int reps = GENERATE( range(1,5) );
3535 SECTION(
"state-vector" ) {
3537 int order = GENERATE( 1, 2, 4 );
3541 REQUIRE(
areEqual(vec, vecRef, 10*REAL_EPS) );
3543 SECTION(
"density-matrix" ) {
3545 int order = GENERATE( 1, 2 );
3549 REQUIRE(
areEqual(mat, matRef, 1E2*REAL_EPS) );
3554 SECTION(
"commuting terms" ) {
3560 int targs[] = {0, 1, 2};
3576 SECTION(
"state-vector" ) {
3578 int reps = GENERATE( range(1,5) );
3579 int order = GENERATE( 1, 2, 4 );
3584 REQUIRE(
areEqual(vec, vecRef, 10*REAL_EPS) );
3586 SECTION(
"density-matrix" ) {
3588 int reps = GENERATE( range(1,5) );
3589 int order = GENERATE( 1, 2 );
3594 REQUIRE(
areEqual(mat, matRef, 1E2*REAL_EPS) );
3599 SECTION(
"general" ) {
3627 qreal fidNorm = 728359.8336;
3629 SECTION(
"absolute" ) {
3637 REQUIRE( fid == Approx(1).epsilon(1E-8) );
3639 SECTION(
"repetitions scaling" ) {
3642 int order = GENERATE( 2, 4, 6 );
3645 int reps[] = {1, 5, 10};
3648 for (
int i=0; i<3; i++) {
3653 REQUIRE( fid >= prevFid );
3657 SECTION(
"order scaling" ) {
3660 int reps = GENERATE( 5, 10 );
3663 int orders[] = {1, 2, 4, 6};
3666 for (
int i=0; i<4; i++) {
3671 REQUIRE( fid >= prevFid );
3679 SECTION(
"input validation" ) {
3681 SECTION(
"repetitions" ) {
3684 int reps = GENERATE( -1, 0 );
3686 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, reps), Contains(
"repetitions must be >=1") );
3690 SECTION(
"order" ) {
3693 int order = GENERATE( -1, 0, 3, 5, 7 );
3695 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, order, 1), Contains(
"order must be 1, or an even number") );
3699 SECTION(
"pauli codes" ) {
3706 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, 1), Contains(
"Invalid Pauli code") );
3710 SECTION(
"matching hamiltonian qubits" ) {
3714 REQUIRE_THROWS_WITH(
applyTrotterCircuit(vec, hamil, 1, 1, 1), Contains(
"same number of qubits") );
3715 REQUIRE_THROWS_WITH(
applyTrotterCircuit(mat, hamil, 1, 1, 1), Contains(
"same number of qubits") );
References applyTrotterCircuit(), areEqual(), calcFidelity(), createCloneQureg(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), getRandomReal(), initDebugState(), initPauliHamil(), M_PI, multiRotatePauli(), NUM_QUBITS, PauliHamil::numSumTerms, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PauliHamil::pauliCodes, qreal, QUEST_ENV, and PauliHamil::termCoeffs.
◆ TEST_CASE() [20/124]
TEST_CASE |
( |
"calcDensityInnerProduct" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcDensityInnerProduct
- Author
- Tyson Jones
Definition at line 21 of file test_calculations.cpp.
26 SECTION(
"correctness" ) {
29 GENERATE( range(0,10) );
31 SECTION(
"density-matrix" ) {
45 for (
size_t i=0; i<r1.size(); i++)
46 prod += conj(r1[i]) * r2[i];
47 qreal densProd = pow(abs(prod),2);
60 for (
size_t i=0; i<ref1.size(); i++)
61 for (
size_t j=0; j<ref1.size(); j++)
62 refProd += conj(ref1[i][j]) * ref2[i][j];
63 REQUIRE( imag(refProd) == Approx(0).margin(REAL_EPS) );
70 SECTION(
"unnormalised" ) {
80 for (
size_t i=0; i<ref1.size(); i++)
81 for (
size_t j=0; j<ref1.size(); j++)
82 refProd += conj(ref1[i][j]) * ref2[i][j];
88 SECTION(
"input validation" ) {
90 SECTION(
"dimensions" ) {
96 SECTION(
"state-vectors" ) {
References calcDensityInnerProduct(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), NUM_QUBITS, qcomp, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [21/124]
TEST_CASE |
( |
"calcExpecDiagonalOp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecDiagonalOp
- Author
- Tyson Jones
Definition at line 117 of file test_calculations.cpp.
126 SECTION(
"correctness" ) {
129 GENERATE( range(0,10) );
139 SECTION(
"state-vector" ) {
145 for (
size_t i=0; i<vecRef.size(); i++)
146 prod += conj(vecRef[i]) * sumRef[i];
149 REQUIRE( res.
real == Approx(real(prod)).margin(REAL_EPS) );
150 REQUIRE( res.
imag == Approx(imag(prod)).margin(REAL_EPS) );
152 SECTION(
"density-matrix" ) {
157 for (
size_t i=0; i<matRef.size(); i++)
161 REQUIRE( res.
real == Approx(real(tr)).margin(100*REAL_EPS) );
162 REQUIRE( res.
imag == Approx(imag(tr)).margin(100*REAL_EPS) );
167 SECTION(
"input validation" ) {
169 SECTION(
"mismatching size" ) {
References calcExpecDiagonalOp(), createDensityQureg(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), getRandomReal(), Complex::imag, DiagonalOp::imag, initDebugState(), NUM_QUBITS, DiagonalOp::numElemsPerChunk, qcomp, QUEST_ENV, Complex::real, DiagonalOp::real, syncDiagonalOp(), toQMatrix(), and toQVector().
◆ TEST_CASE() [22/124]
TEST_CASE |
( |
"calcExpecPauliHamil" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliHamil
- Author
- Tyson Jones
Definition at line 189 of file test_calculations.cpp.
201 SECTION(
"correctness" ) {
206 GENERATE( range(0,10) );
208 int numTerms = GENERATE( 1, 2, 10, 15 );
213 SECTION(
"state-vector" ) {
217 QVector sumRef = refHamil * vecRef;
219 for (
size_t i=0; i<vecRef.size(); i++)
220 prod += conj(vecRef[i]) * sumRef[i];
221 REQUIRE( imag(prod) == Approx(0).margin(10*REAL_EPS) );
224 REQUIRE( res == Approx(real(prod)).margin(10*REAL_EPS) );
226 SECTION(
"density-matrix" ) {
229 matRef = refHamil * matRef;
231 for (
size_t i=0; i<matRef.size(); i++)
232 tr += real(matRef[i][i]);
236 REQUIRE( res == Approx(tr).margin(1E2*REAL_EPS) );
241 SECTION(
"input validation" ) {
243 SECTION(
"pauli codes" ) {
250 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vecWork), Contains(
"Invalid Pauli code") );
254 SECTION(
"workspace type" ) {
259 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, mat), Contains(
"Registers must both be state-vectors or both be density matrices") );
260 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, vec), Contains(
"Registers must both be state-vectors or both be density matrices") );
264 SECTION(
"workspace dimensions" ) {
270 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
274 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
279 SECTION(
"matching hamiltonian qubits" ) {
284 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(vec, hamil, vecWork), Contains(
"same number of qubits") );
285 REQUIRE_THROWS_WITH(
calcExpecPauliHamil(mat, hamil, matWork), Contains(
"same number of qubits") );
References calcExpecPauliHamil(), createDensityQureg(), createPauliHamil(), createQureg(), destroyPauliHamil(), destroyQureg(), initDebugState(), NUM_QUBITS, PauliHamil::pauliCodes, qcomp, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [23/124]
TEST_CASE |
( |
"calcExpecPauliProd" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliProd
- Author
- Tyson Jones
Definition at line 302 of file test_calculations.cpp.
314 SECTION(
"correctness" ) {
316 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
324 GENERATE( range(0,10) );
326 for (
int i=0; i<numTargs; i++)
335 for (
int i=0; i<numTargs; i++) {
337 if (paulis[i] ==
PAULI_I) fac = iMatr;
338 if (paulis[i] ==
PAULI_X) fac = xMatr;
339 if (paulis[i] ==
PAULI_Y) fac = yMatr;
340 if (paulis[i] ==
PAULI_Z) fac = zMatr;
344 SECTION(
"state-vector" ) {
351 for (
size_t i=0; i<vecRef.size(); i++)
352 prod += conj(vecRef[i]) * prodRef[i];
353 REQUIRE( imag(prod) == Approx(0).margin(REAL_EPS) );
356 REQUIRE( res == Approx(real(prod)).margin(REAL_EPS) );
358 SECTION(
"density-matrix" ) {
364 matRef = fullOp * matRef;
368 for (
size_t i=0; i<matRef.size(); i++)
369 tr += real(matRef[i][i]);
373 REQUIRE( res == Approx(tr).margin(10*REAL_EPS) );
376 SECTION(
"input validation" ) {
378 SECTION(
"number of targets" ) {
380 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
381 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, NULL, NULL, numTargs, vecWork), Contains(
"Invalid number of target") );
383 SECTION(
"target indices" ) {
386 int targs[3] = {0, 1, 2};
389 targs[GENERATE( range(0,3) )] = GENERATE( -1,
NUM_QUBITS );
390 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"Invalid target qubit") );
392 SECTION(
"repetition in targets" ) {
395 int targs[3] = {0, 1, 1};
396 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, NULL, numTargs, vecWork), Contains(
"target qubits must be unique") );
398 SECTION(
"pauli codes" ) {
401 int targs[3] = {0, 1, 2};
405 codes[GENERATE( range(0,3) )] = (
pauliOpType) GENERATE( -1, 4 );
406 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vecWork), Contains(
"Invalid Pauli code") );
408 SECTION(
"workspace type" ) {
414 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, matWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
415 REQUIRE_THROWS_WITH(
calcExpecPauliProd(mat, targs, codes, numTargs, vecWork), Contains(
"Registers must both be state-vectors or both be density matrices") );
417 SECTION(
"workspace dimensions" ) {
424 REQUIRE_THROWS_WITH(
calcExpecPauliProd(vec, targs, codes, numTargs, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
428 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() [24/124]
TEST_CASE |
( |
"calcExpecPauliSum" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcExpecPauliSum
- Author
- Tyson Jones
Definition at line 444 of file test_calculations.cpp.
456 SECTION(
"correctness" ) {
458 int numSumTerms = GENERATE( 1, 2, 10, 15 );
463 GENERATE( range(0,10) );
466 qreal coeffs[numSumTerms];
472 SECTION(
"state-vector" ) {
476 QVector sumRef = pauliSum * vecRef;
478 for (
size_t i=0; i<vecRef.size(); i++)
479 prod += conj(vecRef[i]) * sumRef[i];
480 REQUIRE( imag(prod) == Approx(0).margin(10*REAL_EPS) );
483 REQUIRE( res == Approx(real(prod)).margin(10*REAL_EPS) );
485 SECTION(
"density-matrix" ) {
488 matRef = pauliSum * matRef;
490 for (
size_t i=0; i<matRef.size(); i++)
491 tr += real(matRef[i][i]);
495 REQUIRE( res == Approx(tr).margin(1E2*REAL_EPS) );
498 SECTION(
"input validation" ) {
500 SECTION(
"number of sum terms" ) {
502 int numSumTerms = GENERATE( -1, 0 );
503 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, NULL, NULL, numSumTerms, vecWork), Contains(
"Invalid number of terms in the Pauli sum") );
505 SECTION(
"pauli codes" ) {
509 qreal coeffs[numSumTerms];
516 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vecWork), Contains(
"Invalid Pauli code") );
518 SECTION(
"workspace type" ) {
522 qreal coeffs[1] = {0};
527 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, mat), Contains(
"Registers must both be state-vectors or both be density matrices") );
528 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, vec), Contains(
"Registers must both be state-vectors or both be density matrices") );
530 SECTION(
"workspace dimensions" ) {
534 qreal coeffs[1] = {0};
540 REQUIRE_THROWS_WITH(
calcExpecPauliSum(vec, codes, coeffs, numSumTerms, vec2), Contains(
"Dimensions") && Contains(
"don't match") );
544 REQUIRE_THROWS_WITH(
calcExpecPauliSum(mat, codes, coeffs, numSumTerms, mat2), Contains(
"Dimensions") && Contains(
"don't match") );
References calcExpecPauliSum(), createDensityQureg(), createQureg(), destroyQureg(), initDebugState(), NUM_QUBITS, PAULI_I, qcomp, qreal, QUEST_ENV, setRandomPauliSum(), toQMatrix(), and toQVector().
◆ TEST_CASE() [25/124]
TEST_CASE |
( |
"calcFidelity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcFidelity
- Author
- Tyson Jones
Definition at line 560 of file test_calculations.cpp.
566 SECTION(
"correctness" ) {
569 GENERATE( range(0,10) );
571 SECTION(
"state-vector" ) {
575 SECTION(
"normalised" ) {
588 for (
size_t i=0; i<vecRef.size(); i++)
589 dotProd += conj(vecRef[i]) * pureRef[i];
590 qreal refFid = pow(abs(dotProd), 2);
594 SECTION(
"unnormalised" ) {
604 for (
size_t i=0; i<vecRef.size(); i++)
605 nv += pow(abs(vecRef[i]), 2);
611 for (
size_t i=0; i<vecRef.size(); i++)
612 dotProd += conj(vecRef[i]) * pureRef[i];
613 qreal refFid = pow(abs(dotProd), 2);
618 SECTION(
"density-matrix" ) {
639 for (
size_t i=0; i<r1.size(); i++)
640 dotProd += conj(r1[i]) * pureRef[i];
641 qreal refFid = pow(abs(dotProd), 2);
655 QVector rhs = matRef * pureRef;
657 for (
size_t i=0; i<rhs.size(); i++)
658 dotProd += conj(pureRef[i]) * rhs[i];
660 REQUIRE( imag(dotProd) == Approx(0).margin(REAL_EPS) );
661 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
663 SECTION(
"unnormalised" ) {
672 QVector rhs = matRef * pureRef;
674 for (
size_t i=0; i<rhs.size(); i++)
675 dotProd += conj(pureRef[i]) * rhs[i];
677 REQUIRE(
calcFidelity(mat,pure) == Approx(real(dotProd)) );
681 SECTION(
"input validation" ) {
683 SECTION(
"dimensions" ) {
687 REQUIRE_THROWS_WITH(
calcFidelity(vec2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
692 REQUIRE_THROWS_WITH(
calcFidelity(mat2,vec), Contains(
"Dimensions") && Contains(
"don't match") );
695 SECTION(
"density-matrices" ) {
698 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() [26/124]
TEST_CASE |
( |
"calcHilbertSchmidtDistance" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcHilbertSchmidtDistance
- Author
- Tyson Jones
Definition at line 712 of file test_calculations.cpp.
717 SECTION(
"correctness" ) {
720 GENERATE( range(0,10) );
722 SECTION(
"density-matrix" ) {
736 for (
size_t i=0; i<m1.size(); i++)
737 for (
size_t j=0; j<m1.size(); j++)
738 tr += pow(abs(m1[i][j] - m2[i][j]), 2);
741 REQUIRE( res == Approx(sqrt(tr)) );
744 SECTION(
"normalised" ) {
753 for (
size_t i=0; i<ref1.size(); i++)
754 for (
size_t j=0; j<ref1.size(); j++)
755 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
758 REQUIRE( res == Approx(sqrt(tr)) );
760 SECTION(
"unnormalised" ) {
770 for (
size_t i=0; i<ref1.size(); i++)
771 for (
size_t j=0; j<ref1.size(); j++)
772 tr += pow(abs(ref1[i][j] - ref2[i][j]), 2);
775 REQUIRE( res == Approx(sqrt(tr)) );
779 SECTION(
"input validation") {
781 SECTION(
"dimensions" ) {
787 SECTION(
"state-vector" ) {
References calcHilbertSchmidtDistance(), createDensityQureg(), createQureg(), destroyQureg(), getKetBra(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomStateVector(), NUM_QUBITS, qreal, QUEST_ENV, and toQureg().
◆ TEST_CASE() [27/124]
TEST_CASE |
( |
"calcInnerProduct" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcInnerProduct
- Author
- Tyson Jones
Definition at line 808 of file test_calculations.cpp.
813 SECTION(
"correctness" ) {
816 GENERATE( range(0,10) );
818 SECTION(
"state-vector" ) {
820 SECTION(
"normalised" ) {
826 for (
size_t i=0; i<r1.size(); i++)
827 prod += conj(r1[i]) * r2[i];
833 REQUIRE( res.
real == Approx(real(prod)) );
834 REQUIRE( res.
imag == Approx(imag(prod)) );
836 SECTION(
"unnormalised" ) {
842 for (
size_t i=0; i<r1.size(); i++)
843 prod += conj(r1[i]) * r2[i];
849 REQUIRE( res.
real == Approx(real(prod)) );
850 REQUIRE( res.
imag == Approx(imag(prod)) );
854 SECTION(
"input validation" ) {
856 SECTION(
"dimensions" ) {
859 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,vec3), Contains(
"Dimensions") && Contains(
"don't match") );
862 SECTION(
"density-matrix" ) {
866 REQUIRE_THROWS_WITH(
calcInnerProduct(vec1,mat), Contains(
"valid only for state-vectors") );
867 REQUIRE_THROWS_WITH(
calcInnerProduct(mat,vec1), Contains(
"valid only for state-vectors") );
868 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() [28/124]
TEST_CASE |
( |
"calcProbOfAllOutcomes" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcProbOfAllOutcomes
- Author
- Tyson Jones
Definition at line 883 of file test_calculations.cpp.
888 SECTION(
"correctness" ) {
891 int numQubits = GENERATE_COPY( range(1,
NUM_QUBITS+1) );
894 int numOutcomes = 1<<numQubits;
895 qreal probs[numOutcomes];
898 SECTION(
"state-vector" ) {
900 SECTION(
"normalised" ) {
906 for (
size_t i=0; i<ref.size(); i++) {
908 for (
int q=0; q<numQubits; q++) {
909 int bit = (i >> qubits[q]) & 1;
910 outcome += bit * (1 << q);
912 refProbs[outcome] += pow(abs(ref[i]), 2);
916 REQUIRE(
areEqual(refProbs, probs) );
918 SECTION(
"unnormalised" ) {
924 for (
size_t i=0; i<ref.size(); i++) {
926 for (
int q=0; q<numQubits; q++) {
927 int bit = (i >> qubits[q]) & 1;
928 outcome += bit * (1 << q);
930 refProbs[outcome] += pow(abs(ref[i]), 2);
934 REQUIRE(
areEqual(refProbs, probs) );
937 SECTION(
"density-matrix" ) {
939 SECTION(
"normalised" ) {
945 for (
size_t i=0; i<ref.size(); i++) {
947 for (
int q=0; q<numQubits; q++) {
948 int bit = (i >> qubits[q]) & 1;
949 outcome += bit * (1 << q);
951 refProbs[outcome] += real(ref[i][i]);
955 REQUIRE(
areEqual(refProbs, probs) );
957 SECTION(
"unnormalised" ) {
963 for (
size_t i=0; i<ref.size(); i++) {
965 for (
int q=0; q<numQubits; q++) {
966 int bit = (i >> qubits[q]) & 1;
967 outcome += bit * (1 << q);
969 refProbs[outcome] += real(ref[i][i]);
973 REQUIRE(
areEqual(refProbs, probs) );
977 SECTION(
"input validation" ) {
980 int qubits[] = {0, 1, 2};
983 SECTION(
"number of qubits" ) {
986 REQUIRE_THROWS_WITH(
calcProbOfAllOutcomes(probs, mat, qubits, numQubits), Contains(
"Invalid number of target qubits") );
988 SECTION(
"qubit indices" ) {
990 qubits[GENERATE_COPY(range(0,numQubits))] = GENERATE( -1,
NUM_QUBITS );
991 REQUIRE_THROWS_WITH(
calcProbOfAllOutcomes(probs, mat, qubits, numQubits), Contains(
"Invalid target qubit") );
993 SECTION(
"repetition of qubits" ) {
995 qubits[GENERATE_COPY(1,2)] = qubits[0];
996 REQUIRE_THROWS_WITH(
calcProbOfAllOutcomes(probs, mat, qubits, numQubits), Contains(
"qubits must be unique") );
References areEqual(), calcProbOfAllOutcomes(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomQMatrix(), getRandomQVector(), getRandomStateVector(), NUM_QUBITS, qreal, QUEST_ENV, sublists(), and toQureg().
◆ TEST_CASE() [29/124]
TEST_CASE |
( |
"calcProbOfOutcome" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcProbOfOutcome
- Author
- Tyson Jones
Definition at line 1010 of file test_calculations.cpp.
1015 SECTION(
"correctness" ) {
1017 int target = GENERATE( range(0,
NUM_QUBITS) );
1018 int outcome = GENERATE( 0, 1 );
1020 SECTION(
"state-vector" ) {
1022 SECTION(
"normalised" ) {
1029 for (
size_t ind=0; ind<ref.size(); ind++) {
1030 int bit = (ind >> target) & 1;
1032 prob += pow(abs(ref[ind]), 2);
1037 SECTION(
"unnormalised" ) {
1045 for (
size_t ind=0; ind<ref.size(); ind++) {
1046 int bit = (ind >> target) & 1;
1048 prob += pow(abs(ref[ind]), 2);
1056 SECTION(
"density-matrix" ) {
1066 for (
size_t ind=0; ind<ref.size(); ind++) {
1067 int bit = (ind >> target) & 1;
1069 prob += pow(abs(ref[ind]), 2);
1074 SECTION(
"mixed" ) {
1081 for (
size_t ind=0; ind<ref.size(); ind++) {
1082 int bit = (ind >> target) & 1;
1084 tr += ref[ind][ind];
1086 REQUIRE( imag(tr) == Approx(0).margin(REAL_EPS) );
1090 SECTION(
"unnormalised" ) {
1098 for (
size_t ind=0; ind<ref.size(); ind++) {
1099 int bit = (ind >> target) & 1;
1101 tr += real(ref[ind][ind]);
1110 SECTION(
"input validation" ) {
1112 SECTION(
"qubit indices" ) {
1115 REQUIRE_THROWS_WITH(
calcProbOfOutcome(vec, target, 0), Contains(
"Invalid target qubit") );
1117 SECTION(
"outcome value" ) {
1119 int outcome = GENERATE( -1, 2 );
1120 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() [30/124]
TEST_CASE |
( |
"calcPurity" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcPurity
- Author
- Tyson Jones
Definition at line 1133 of file test_calculations.cpp.
1137 SECTION(
"correctness" ) {
1140 GENERATE( range(1,10) );
1142 SECTION(
"density-matrix" ) {
1157 SECTION(
"mixed" ) {
1163 REQUIRE( purity < 1 );
1169 for (
size_t i=0; i<prod.size(); i++)
1170 tr += real(prod[i][i]);
1171 REQUIRE( purity == Approx(tr) );
1173 SECTION(
"unnormalised" ) {
1178 for (
size_t i=0; i<ref.size(); i++)
1179 for (
size_t j=0; j<ref.size(); j++)
1180 tot += pow(abs(ref[i][j]), 2);
1187 SECTION(
"input validation" ) {
1189 SECTION(
"state-vector" ) {
1192 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() [31/124]
TEST_CASE |
( |
"calcTotalProb" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- calcTotalProb
- Author
- Tyson Jones
Definition at line 1205 of file test_calculations.cpp.
1210 SECTION(
"correctness" ) {
1212 SECTION(
"state-vector" ) {
1230 for (
size_t i=0; i<ref.size(); i++)
1231 refProb += pow(abs(ref[i]), 2);
1234 SECTION(
"density-matrix" ) {
1252 for (
size_t i=0; i<ref.size(); i++)
1253 refProb += real(ref[i][i]);
1257 SECTION(
"input validation" ) {
References calcTotalProb(), createDensityQureg(), createQureg(), destroyQureg(), getRandomDensityMatrix(), getRandomStateVector(), initBlankState(), initDebugState(), initPlusState(), NUM_QUBITS, qreal, QUEST_ENV, toQMatrix(), toQureg(), and toQVector().
◆ TEST_CASE() [32/124]
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() [33/124]
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() [34/124]
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(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, Complex::real, toComplex, and toQMatrix().
◆ TEST_CASE() [35/124]
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(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, Complex::real, toComplex, and toQMatrix().
◆ TEST_CASE() [36/124]
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() [37/124]
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() [38/124]
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, PREPARE_TEST, and qcomp.
◆ TEST_CASE() [39/124]
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() [40/124]
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(), M_PI, NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [41/124]
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);
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(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, qreal, Vector::x, Vector::y, and Vector::z.
◆ TEST_CASE() [42/124]
TEST_CASE |
( |
"controlledRotateX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateX
- Author
- Tyson Jones
Definition at line 542 of file test_unitaries.cpp.
547 {cos(param/2), -sin(param/2)*
qcomp(0,1)},
548 {-sin(param/2)*
qcomp(0,1), cos(param/2)}};
550 SECTION(
"correctness" ) {
553 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
555 SECTION(
"state-vector" ) {
559 REQUIRE(
areEqual(quregVec, refVec) );
561 SECTION(
"density-matrix" ) {
565 REQUIRE(
areEqual(quregMatr, refMatr) );
568 SECTION(
"input validation" ) {
570 SECTION(
"control and target collision" ) {
573 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
575 SECTION(
"qubit indices" ) {
578 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, qb, 0, param), Contains(
"Invalid control") );
579 REQUIRE_THROWS_WITH(
controlledRotateX(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateX(), getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, and qreal.
◆ TEST_CASE() [43/124]
TEST_CASE |
( |
"controlledRotateY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateY
- Author
- Tyson Jones
Definition at line 591 of file test_unitaries.cpp.
595 QMatrix op{{cos(param/2), -sin(param/2)},{sin(param/2), cos(param/2)}};
597 SECTION(
"correctness" ) {
600 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
602 SECTION(
"state-vector" ) {
606 REQUIRE(
areEqual(quregVec, refVec) );
608 SECTION(
"density-matrix" ) {
612 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
615 SECTION(
"input validation" ) {
617 SECTION(
"control and target collision" ) {
620 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
622 SECTION(
"qubit indices" ) {
625 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, qb, 0, param), Contains(
"Invalid control") );
626 REQUIRE_THROWS_WITH(
controlledRotateY(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateY(), getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [44/124]
TEST_CASE |
( |
"controlledRotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledRotateZ
- Author
- Tyson Jones
Definition at line 638 of file test_unitaries.cpp.
644 SECTION(
"correctness" ) {
647 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
649 SECTION(
"state-vector" ) {
653 REQUIRE(
areEqual(quregVec, refVec) );
655 SECTION(
"density-matrix" ) {
659 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
662 SECTION(
"input validation" ) {
664 SECTION(
"control and target collision" ) {
667 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, qb, qb, param), Contains(
"Control") && Contains(
"target") );
669 SECTION(
"qubit indices" ) {
672 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, qb, 0, param), Contains(
"Invalid control") );
673 REQUIRE_THROWS_WITH(
controlledRotateZ(quregVec, 0, qb, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledRotateZ(), expI(), getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [45/124]
TEST_CASE |
( |
"controlledTwoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledTwoQubitUnitary
- Author
- Tyson Jones
Definition at line 685 of file test_unitaries.cpp.
690 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
696 SECTION(
"correctness" ) {
699 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
700 int control = GENERATE_COPY( filter([=](
int c){
return c!=targ1 && c!=targ2; }, range(0,
NUM_QUBITS)) );
702 SECTION(
"state-vector" ) {
706 REQUIRE(
areEqual(quregVec, refVec) );
708 SECTION(
"density-matrix" ) {
712 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
715 SECTION(
"input validation" ) {
717 SECTION(
"repetition of targets" ) {
720 REQUIRE_THROWS_WITH(
controlledTwoQubitUnitary(quregVec, ctrl, targ, targ, matr), Contains(
"target") && Contains(
"unique") );
722 SECTION(
"control and target collision" ) {
726 int ctrl = GENERATE( 1,2 );
727 REQUIRE_THROWS_WITH(
controlledTwoQubitUnitary(quregVec, ctrl, targ1, targ2, matr), Contains(
"Control") && Contains(
"target") );
729 SECTION(
"qubit indices" ) {
741 SECTION(
"unitarity" ) {
746 SECTION(
"unitary fits in node" ) {
749 quregVec.numAmpsPerChunk = 1;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, controlledTwoQubitUnitary(), getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix4::real, and toComplexMatrix4().
◆ TEST_CASE() [46/124]
TEST_CASE |
( |
"controlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- controlledUnitary
- Author
- Tyson Jones
Definition at line 762 of file test_unitaries.cpp.
768 SECTION(
"correctness" ) {
771 int control = GENERATE_COPY( filter([=](
int c){
return c!=target; }, range(0,
NUM_QUBITS)) );
773 SECTION(
"state-vector" ) {
777 REQUIRE(
areEqual(quregVec, refVec) );
779 SECTION(
"density-matrix" ) {
783 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
786 SECTION(
"input validation" ) {
788 SECTION(
"control and target collision" ) {
791 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, qb, qb, matr), Contains(
"Control") && Contains(
"target") );
793 SECTION(
"qubit indices" ) {
796 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, qb, 0, matr), Contains(
"Invalid control") );
797 REQUIRE_THROWS_WITH(
controlledUnitary(quregVec, 0, qb, matr), Contains(
"Invalid target") );
799 SECTION(
"unitarity" ) {
802 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() [47/124]
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() [48/124]
TEST_CASE |
( |
"createComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [49/124]
TEST_CASE |
( |
"createDensityQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createDensityQureg
- Author
- Tyson Jones
Definition at line 131 of file test_data_structures.cpp.
138 SECTION(
"correctness" ) {
141 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
151 SECTION(
"input validation") {
153 SECTION(
"number of qubits" ) {
155 int numQb = GENERATE( -1, 0 );
158 SECTION(
"number of amplitudes" ) {
164 int maxQb = (int)
calcLog2(SIZE_MAX) / 2;
165 REQUIRE_THROWS_WITH(
createDensityQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
170 int minQb = GENERATE_COPY( range(3,maxQb) );
171 env.
numRanks = (int) pow(2, 2*minQb);
172 int numQb = GENERATE_COPY( range(1,minQb) );
175 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), createDensityQureg(), destroyQureg(), getZeroMatrix(), QuESTEnv::numRanks, and QUEST_ENV.
◆ TEST_CASE() [50/124]
TEST_CASE |
( |
"createDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createDiagonalOp
- Author
- Tyson Jones
Definition at line 190 of file test_data_structures.cpp.
197 SECTION(
"correctness" ) {
200 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
208 REQUIRE( op.
real != NULL );
209 REQUIRE( op.
imag != NULL );
218 SECTION(
"input validation" ) {
220 SECTION(
"number of qubits" ) {
222 int numQb = GENERATE( -1, 0 );
225 SECTION(
"number of elements" ) {
231 int maxQb = (int)
calcLog2(SIZE_MAX);
232 REQUIRE_THROWS_WITH(
createDiagonalOp(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
235 int minQb = GENERATE_COPY( range(2,maxQb) );
237 int numQb = GENERATE_COPY( range(1,minQb) );
238 REQUIRE_THROWS_WITH(
createDiagonalOp(numQb, env), Contains(
"Too few qubits") && Contains(
"distributed"));
240 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), DiagonalOp::chunkId, createDiagonalOp(), destroyDiagonalOp(), DiagonalOp::imag, DiagonalOp::numChunks, DiagonalOp::numElemsPerChunk, DiagonalOp::numQubits, QuESTEnv::numRanks, QUEST_ENV, QuESTEnv::rank, DiagonalOp::real, and toQVector().
◆ TEST_CASE() [51/124]
TEST_CASE |
( |
"createDiagonalOpFromPauliHamilFile" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createDiagonalOpFromPauliHamilFile
- Author
- Tyson Jones
Definition at line 255 of file test_data_structures.cpp.
258 char fnPrefix[] =
"temp_createDiagonalOpFromPauliHamilFile";
271 SECTION(
"correctness" ) {
273 SECTION(
"general" ) {
276 int numQb = GENERATE_COPY( range(minNumQb, 6+minNumQb) );
277 int numTerms = GENERATE_COPY( 1, minNumQb, 10*minNumQb );
285 FILE* file = fopen(fn,
"w");
287 for (
int n=0; n<numTerms; n++) {
288 fprintf(file, REAL_STRING_FORMAT, hamil.
termCoeffs[n]);
290 for (
int q=0; q<numQb; q++)
291 fprintf(file,
"%d ", (
int) hamil.
pauliCodes[i++]);
306 SECTION(
"edge cases" ) {
309 qreal coeffs[] = {.1};
311 for (
int q=0; q<minNumQb; q++)
317 string line = to_string(coeffs[0]) +
" ";
318 for (
int q=0; q<minNumQb; q++)
319 line += to_string(codes[q]) + ((q<minNumQb-1)?
" ":
"");
321 SECTION(
"no trailing newline or space" ) {
330 SECTION(
"trailing newlines" ) {
339 SECTION(
"trailing spaces" ) {
350 SECTION(
"input validation") {
352 SECTION(
"number of qubits" ) {
357 SECTION(
"number of elements" ) {
360 int maxQb = (int)
calcLog2(SIZE_MAX);
364 for (
int q=0; q<(maxQb+1); q++)
374 int minQb = GENERATE_COPY( range(2,maxQb) );
376 int numQb = GENERATE_COPY( range(1,minQb) );
379 for (
int q=0; q<numQb; q++)
386 SECTION(
"coefficient type" ) {
391 SECTION(
"pauli code" ) {
References areEqual(), calcLog2(), createDiagonalOpFromPauliHamilFile(), createPauliHamil(), deleteFilesWithPrefixSynch(), destroyDiagonalOp(), destroyPauliHamil(), QuESTEnv::numRanks, PAULI_I, PAULI_Z, PauliHamil::pauliCodes, qreal, QUEST_ENV, QuESTEnv::rank, setRandomDiagPauliHamil(), setUniqueFilename(), syncQuESTEnv(), PauliHamil::termCoeffs, toQMatrix(), and writeToFileSynch().
◆ TEST_CASE() [52/124]
TEST_CASE |
( |
"createPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createPauliHamil
- Author
- Tyson Jones
Definition at line 420 of file test_data_structures.cpp.
422 SECTION(
"correctness" ) {
424 int numQb = GENERATE( range(1,5) );
425 int numTerms = GENERATE( range(1,5) );
433 int numPaulis = numQb * numTerms;
434 for (
int i=0; i<numPaulis; i++) {
439 for (
int j=0; j<numTerms; j++) {
446 SECTION(
"input validation") {
448 SECTION(
"number of qubits" ) {
450 int numQb = GENERATE( -1, 0 );
451 REQUIRE_THROWS_WITH(
createPauliHamil(numQb, 1), Contains(
"The number of qubits and terms in the PauliHamil must be strictly positive.") );
453 SECTION(
"number of terms" ) {
455 int numTerms = GENERATE( -1, 0 );
456 REQUIRE_THROWS_WITH(
createPauliHamil(1, numTerms), Contains(
"The number of qubits and terms in the PauliHamil must be strictly positive.") );
References createPauliHamil(), destroyPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PAULI_I, PauliHamil::pauliCodes, and PauliHamil::termCoeffs.
◆ TEST_CASE() [53/124]
TEST_CASE |
( |
"createPauliHamilFromFile" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createPauliHamilFromFile
- Author
- Tyson Jones
Definition at line 467 of file test_data_structures.cpp.
470 char fnPrefix[] =
"temp_createPauliHamilFromFile";
478 SECTION(
"correctness" ) {
480 SECTION(
"general" ) {
483 int numQb = GENERATE( 1, 5, 10, 15 );
484 int numTerms = GENERATE( 1, 10, 30 );
485 int numPaulis = numQb*numTerms;
488 qreal coeffs[numTerms];
494 FILE* file = fopen(fn,
"w");
496 for (
int n=0; n<numTerms; n++) {
497 fprintf(file, REAL_STRING_FORMAT, coeffs[n]);
499 for (
int q=0; q<numQb; q++)
500 fprintf(file,
"%d ", (
int) paulis[i++]);
517 for (
int n=0; n<numTerms; n++) {
518 REQUIRE( absReal(hamil.
termCoeffs[n] - coeffs[n]) <= REAL_EPS );
519 for (
int q=0; q<numQb; q++) {
527 SECTION(
"edge cases" ) {
529 SECTION(
"no trailing newline or space" ) {
539 SECTION(
"trailing newlines" ) {
549 SECTION(
"trailing spaces" ) {
561 SECTION(
"input validation") {
563 SECTION(
"number of qubits" ) {
567 REQUIRE_THROWS_WITH(
createPauliHamilFromFile(fn), Contains(
"The number of qubits") && Contains(
"strictly positive"));
569 SECTION(
"coefficient type" ) {
575 SECTION(
"pauli code" ) {
References createPauliHamilFromFile(), deleteFilesWithPrefixSynch(), destroyPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PauliHamil::pauliCodes, qreal, QUEST_ENV, QuESTEnv::rank, setRandomPauliSum(), setUniqueFilename(), syncQuESTEnv(), PauliHamil::termCoeffs, and writeToFileSynch().
◆ TEST_CASE() [54/124]
TEST_CASE |
( |
"createQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [55/124]
TEST_CASE |
( |
"createQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- createQureg
- Author
- Tyson Jones
Definition at line 610 of file test_data_structures.cpp.
617 SECTION(
"correctness" ) {
620 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
630 SECTION(
"input validation") {
632 SECTION(
"number of qubits" ) {
634 int numQb = GENERATE( -1, 0 );
637 SECTION(
"number of amplitudes" ) {
643 int maxQb = (int)
calcLog2(SIZE_MAX);
644 REQUIRE_THROWS_WITH(
createQureg(maxQb+1, env), Contains(
"Too many qubits") && Contains(
"size_t type") );
647 int minQb = GENERATE_COPY( range(2,maxQb) );
649 int numQb = GENERATE_COPY( range(1,minQb) );
650 REQUIRE_THROWS_WITH(
createQureg(numQb, env), Contains(
"Too few qubits") );
652 SECTION(
"available memory" ) {
References areEqual(), calcLog2(), createQureg(), destroyQureg(), QuESTEnv::numRanks, and QUEST_ENV.
◆ TEST_CASE() [56/124]
TEST_CASE |
( |
"destroyComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [57/124]
TEST_CASE |
( |
"destroyDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [58/124]
TEST_CASE |
( |
"destroyPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [59/124]
TEST_CASE |
( |
"destroyQuESTEnv" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [60/124]
TEST_CASE |
( |
"destroyQureg" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [61/124]
TEST_CASE |
( |
"fromComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [62/124]
TEST_CASE |
( |
"getAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getAmp
- Author
- Tyson Jones
Definition at line 1272 of file test_calculations.cpp.
1276 SECTION(
"correctness" ) {
1278 SECTION(
"state-vector" ) {
1283 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1288 SECTION(
"input validation" ) {
1290 SECTION(
"state index" ) {
1293 REQUIRE_THROWS_WITH(
getAmp(vec,ind), Contains(
"Invalid amplitude index") );
1295 SECTION(
"density-matrix" ) {
1298 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() [63/124]
TEST_CASE |
( |
"getDensityAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getDensityAmp
- Author
- Tyson Jones
Definition at line 1311 of file test_calculations.cpp.
1315 SECTION(
"correctness" ) {
1317 SECTION(
"density-matrix" ) {
1322 int row = GENERATE( range(0,1<<
NUM_QUBITS) );
1323 int col = GENERATE( range(0,1<<
NUM_QUBITS) );
1329 SECTION(
"input validation" ) {
1331 SECTION(
"state index" ) {
1334 REQUIRE_THROWS_WITH(
getDensityAmp(mat,ind,0), Contains(
"Invalid amplitude index") );
1335 REQUIRE_THROWS_WITH(
getDensityAmp(mat,0,ind), Contains(
"Invalid amplitude index") );
1338 SECTION(
"state-vector" ) {
1341 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() [64/124]
TEST_CASE |
( |
"getImagAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getImagAmp
- Author
- Tyson Jones
Definition at line 1354 of file test_calculations.cpp.
1358 SECTION(
"correctness" ) {
1360 SECTION(
"state-vector" ) {
1365 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1366 REQUIRE(
getImagAmp(vec,ind) == imag(ref[ind]) );
1369 SECTION(
"input validation" ) {
1371 SECTION(
"state index" ) {
1374 REQUIRE_THROWS_WITH(
getImagAmp(vec,ind), Contains(
"Invalid amplitude index") );
1376 SECTION(
"density-matrix" ) {
1379 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() [65/124]
TEST_CASE |
( |
"getNumAmps" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [66/124]
TEST_CASE |
( |
"getNumQubits" |
, |
|
|
"" |
[calculations] |
|
) |
| |
◆ TEST_CASE() [67/124]
TEST_CASE |
( |
"getProbAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getProbAmp
- Author
- Tyson Jones
Definition at line 1455 of file test_calculations.cpp.
1459 SECTION(
"correctness" ) {
1461 SECTION(
"state-vector" ) {
1466 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1467 qreal refCalc = pow(abs(ref[ind]), 2);
1468 REQUIRE(
getProbAmp(vec,ind) == Approx(refCalc) );
1471 SECTION(
"input validation" ) {
1473 SECTION(
"state index" ) {
1476 REQUIRE_THROWS_WITH(
getProbAmp(vec,ind), Contains(
"Invalid amplitude index") );
1478 SECTION(
"density-matrix" ) {
1481 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() [68/124]
TEST_CASE |
( |
"getRealAmp" |
, |
|
|
"" |
[calculations] |
|
) |
| |
- See also
- getRealAmp
- Author
- Tyson Jones
Definition at line 1494 of file test_calculations.cpp.
1498 SECTION(
"correctness" ) {
1500 SECTION(
"state-vector" ) {
1505 int ind = GENERATE( range(0,1<<
NUM_QUBITS) );
1506 REQUIRE(
getRealAmp(vec,ind) == real(ref[ind]) );
1509 SECTION(
"input validation" ) {
1511 SECTION(
"state index" ) {
1514 REQUIRE_THROWS_WITH(
getRealAmp(vec,ind), Contains(
"Invalid amplitude index") );
1516 SECTION(
"density-matrix" ) {
1519 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() [69/124]
TEST_CASE |
( |
"getStaticComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [70/124]
TEST_CASE |
( |
"hadamard" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- hadamard
- Author
- Tyson Jones
Definition at line 814 of file test_unitaries.cpp.
820 SECTION(
"correctness" ) {
824 SECTION(
"state-vector ") {
828 REQUIRE(
areEqual(quregVec, refVec) );
830 SECTION(
"density-matrix" ) {
834 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
837 SECTION(
"input validation" ) {
839 SECTION(
"qubit indices" ) {
842 REQUIRE_THROWS_WITH(
hadamard(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, hadamard(), NUM_QUBITS, PREPARE_TEST, and qreal.
◆ TEST_CASE() [71/124]
TEST_CASE |
( |
"initBlankState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [72/124]
TEST_CASE |
( |
"initClassicalState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [73/124]
TEST_CASE |
( |
"initComplexMatrixN" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [74/124]
TEST_CASE |
( |
"initDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- initDiagonalOp
- Author
- Tyson Jones
Definition at line 768 of file test_data_structures.cpp.
775 SECTION(
"correctness" ) {
778 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
781 long long int len = (1LL << numQb);
785 for (n=0; n<len; n++) {
786 reals[n] = (
qreal) n;
787 imags[n] = (
qreal) -2*n;
809 REQUIRE(
areEqual(prodRef, result) );
References applyDiagonalOp(), areEqual(), calcLog2(), copyStateFromGPU(), copyStateToGPU(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), initDiagonalOp(), Qureg::numAmpsPerChunk, QuESTEnv::numRanks, qreal, QUEST_ENV, Qureg::stateVec, toQMatrix(), and toQVector().
◆ TEST_CASE() [75/124]
TEST_CASE |
( |
"initDiagonalOpFromPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- initDiagonalOpFromPauliHamil
- Author
- Tyson Jones
Definition at line 822 of file test_data_structures.cpp.
829 SECTION(
"correctness" ) {
832 int numQb = GENERATE_COPY( range(minNumQb, min(10,minNumQb+10)) );
836 int numTerms = GENERATE_COPY( 1, numQb, 5*numQb );
846 SECTION(
"input validation" ) {
848 SECTION(
"hamiltonian parameters" ) {
863 SECTION(
"mismatching dimensions" ) {
865 int numQbA = minNumQb+1;
866 int numQbB = GENERATE_COPY( numQbA-1, numQbA+1 );
871 REQUIRE_THROWS_WITH(
initDiagonalOpFromPauliHamil(op, hamil), Contains(
"Pauli Hamiltonian and diagonal operator have different, incompatible dimensions") );
876 SECTION(
"pauli codes" ) {
883 int ind = GENERATE_COPY( range(0,numCodes) );
References areEqual(), calcLog2(), createDiagonalOp(), createPauliHamil(), destroyDiagonalOp(), destroyPauliHamil(), initDiagonalOpFromPauliHamil(), PauliHamil::numQubits, QuESTEnv::numRanks, PauliHamil::numSumTerms, PAULI_X, PAULI_Y, PauliHamil::pauliCodes, QUEST_ENV, setRandomDiagPauliHamil(), and toQMatrix().
◆ TEST_CASE() [76/124]
TEST_CASE |
( |
"initPauliHamil" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- initPauliHamil
- Author
- Tyson Jones
Definition at line 900 of file test_data_structures.cpp.
902 SECTION(
"correctness" ) {
906 qreal coeffs[] = {-5, 5};
913 for (
int t=0; t<2; t++) {
915 for (
int q=0; q<3; q++) {
917 REQUIRE( codes[ind] == hamil.
pauliCodes[ind] );
923 SECTION(
"input validation" ) {
925 SECTION(
"parameters" ) {
934 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"number of qubits") && Contains(
"strictly positive") );
938 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"terms") && Contains(
"strictly positive") );
940 SECTION(
"Pauli codes" ) {
944 int numCodes = numQb * numTerms;
945 qreal coeffs[numTerms];
949 for (
int i=0; i<numCodes; i++)
951 codes[GENERATE_COPY( range(0,numCodes) )] = (
pauliOpType) GENERATE( -1, 4 );
954 REQUIRE_THROWS_WITH(
initPauliHamil(hamil, coeffs, codes), Contains(
"Invalid Pauli code") );
References createPauliHamil(), destroyPauliHamil(), initPauliHamil(), PauliHamil::numQubits, PauliHamil::numSumTerms, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PauliHamil::pauliCodes, qreal, and PauliHamil::termCoeffs.
◆ TEST_CASE() [77/124]
TEST_CASE |
( |
"initPlusState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
◆ TEST_CASE() [78/124]
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() [79/124]
TEST_CASE |
( |
"initStateFromAmps" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- initStateFromAmps
- Author
- Tyson Jones
Definition at line 286 of file test_state_initialisations.cpp.
291 SECTION(
"correctness" ) {
293 SECTION(
"state-vector" ) {
300 for (
size_t i=0; i<vecRef.size(); i++) {
301 ampsRe[i] = real(vecRef[i]);
302 ampsIm[i] = imag(vecRef[i]);
308 SECTION(
"density-matrix" ) {
318 for (
size_t c=0; c<matRef.size(); c++) {
319 for (
size_t r=0; r<matRef.size(); r++) {
320 ampsRe[i] = real(matRef[r][c]);
321 ampsIm[i] = imag(matRef[r][c]);
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getRandomQMatrix(), getRandomQVector(), initStateFromAmps(), NUM_QUBITS, Qureg::numAmpsTotal, qreal, and QUEST_ENV.
◆ TEST_CASE() [80/124]
TEST_CASE |
( |
"initZeroState" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- initZeroState
- Author
- Tyson Jones
Definition at line 340 of file test_state_initialisations.cpp.
345 SECTION(
"correctness" ) {
347 SECTION(
"state-vector" ) {
356 SECTION(
"density-matrix" ) {
366 SECTION(
"input validation" ) {
References areEqual(), createDensityQureg(), createQureg(), destroyQureg(), getZeroMatrix(), initBlankState(), initZeroState(), NUM_QUBITS, Qureg::numAmpsTotal, Qureg::numQubitsRepresented, and QUEST_ENV.
◆ TEST_CASE() [81/124]
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() [82/124]
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() [83/124]
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() [84/124]
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() [85/124]
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() [86/124]
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, qcomp, qreal, and QUEST_ENV.
◆ TEST_CASE() [87/124]
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() [88/124]
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() [89/124]
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, qcomp, qreal, and QUEST_ENV.
◆ TEST_CASE() [90/124]
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() [91/124]
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, qcomp, qreal, and QUEST_ENV.
◆ TEST_CASE() [92/124]
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() [93/124]
TEST_CASE |
( |
"multiControlledMultiQubitNot" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledMultiQubitNot
- Author
- Tyson Jones
Definition at line 854 of file test_unitaries.cpp.
858 SECTION(
"correctness" ) {
861 int numTargs = GENERATE_COPY( range(1,
NUM_QUBITS) );
863 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
867 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
872 SECTION(
"state-vector" ) {
875 for (
int t=0; t<numTargs; t++)
878 REQUIRE(
areEqual(quregVec, refVec) );
880 SECTION(
"density-matrix" ) {
883 for (
int t=0; t<numTargs; t++)
886 REQUIRE(
areEqual(quregMatr, refMatr) );
889 SECTION(
"input validation" ) {
891 SECTION(
"number of targets" ) {
895 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
900 SECTION(
"repetition in targets" ) {
904 int targs[] = {1,2,2};
907 SECTION(
"number of controls" ) {
914 SECTION(
"repetition in controls" ) {
916 int ctrls[] = {0,1,1};
920 SECTION(
"control and target collision" ) {
922 int ctrls[] = {0,1,2};
923 int targs[] = {3,1,4};
924 REQUIRE_THROWS_WITH(
multiControlledMultiQubitNot(quregVec, ctrls, 3, targs, 3), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
926 SECTION(
"qubit indices" ) {
935 qb1[GENERATE_COPY(range(0,numQb))] = inv;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, multiControlledMultiQubitNot(), NUM_QUBITS, PREPARE_TEST, and sublists().
◆ TEST_CASE() [94/124]
TEST_CASE |
( |
"multiControlledMultiQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledMultiQubitUnitary
- Author
- Tyson Jones
Definition at line 950 of file test_unitaries.cpp.
955 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
959 SECTION(
"correctness" ) {
962 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
964 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
968 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
975 SECTION(
"state-vector" ) {
979 REQUIRE(
areEqual(quregVec, refVec) );
981 SECTION(
"density-matrix" ) {
985 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
989 SECTION(
"input validation" ) {
991 SECTION(
"number of targets" ) {
995 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1004 SECTION(
"repetition in targets" ) {
1008 int targs[] = {1,2,2};
1015 SECTION(
"number of controls" ) {
1026 SECTION(
"repetition in controls" ) {
1028 int ctrls[] = {0,1,1};
1036 SECTION(
"control and target collision" ) {
1038 int ctrls[] = {0,1,2};
1039 int targs[] = {3,1,4};
1043 REQUIRE_THROWS_WITH(
multiControlledMultiQubitUnitary(quregVec, ctrls, 3, targs, 3, matr), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
1046 SECTION(
"qubit indices" ) {
1057 qb1[GENERATE_COPY(range(0,numQb))] = inv;
1063 SECTION(
"unitarity" ) {
1066 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
1067 int targs[numTargs];
1068 for (
int i=0; i<numTargs; i++)
1075 SECTION(
"unitary creation" ) {
1078 int targs[3] = {1,2,3};
1090 SECTION(
"unitary dimensions" ) {
1093 int targs[2] = {1,2};
1100 SECTION(
"unitary fits in node" ) {
1103 quregVec.numAmpsPerChunk = 1;
1105 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() [95/124]
TEST_CASE |
( |
"multiControlledMultiRotatePauli" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledMultiRotatePauli
- Author
- Tyson Jones
Definition at line 1122 of file test_unitaries.cpp.
1127 SECTION(
"correctness" ) {
1130 int numTargs = GENERATE_COPY( range(1,
NUM_QUBITS) );
1132 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
1136 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
1144 for (
int i=0; i<numTargs; i++)
1148 int refTargs[numTargs];
1149 int numRefTargs = 0;
1157 for (
int i=0; i<numTargs; i++) {
1159 if (paulis[i] ==
PAULI_I)
continue;
1160 if (paulis[i] ==
PAULI_X) fac = xMatr;
1161 if (paulis[i] ==
PAULI_Y) fac = yMatr;
1162 if (paulis[i] ==
PAULI_Z) fac = zMatr;
1166 refTargs[numRefTargs++] = targs[i];
1171 if (numRefTargs > 0)
1174 SECTION(
"state-vector" ) {
1177 if (numRefTargs > 0)
1179 REQUIRE(
areEqual(quregVec, refVec) );
1181 SECTION(
"density-matrix" ) {
1184 if (numRefTargs > 0)
1186 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1189 SECTION(
"input validation" ) {
1194 Qureg regs[] = {quregVec, quregMatr};
1195 Qureg qureg = regs[GENERATE(0,1)];
1202 SECTION(
"pauli codes" ) {
1207 int targs[3] = {0, 1, 2};
1210 paulis[GENERATE_COPY(range(0,numTargs))] = (
pauliOpType) GENERATE( -1, 4 );
1214 SECTION(
"number of targets" ) {
1218 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1225 SECTION(
"repetition in targets" ) {
1230 int targs[] = {1,2,2};
1232 REQUIRE_THROWS_WITH(
multiControlledMultiRotatePauli(qureg, ctrls, numCtrls, targs, paulis, numTargs, param), Contains(
"target") && Contains(
"unique"));
1234 SECTION(
"number of controls" ) {
1243 SECTION(
"repetition in controls" ) {
1247 int ctrls[] = {0,1,1};
1250 REQUIRE_THROWS_WITH(
multiControlledMultiRotatePauli(qureg, ctrls, numCtrls, targs, paulis, numTargs, param), Contains(
"control") && Contains(
"unique"));
1252 SECTION(
"control and target collision" ) {
1256 int ctrls[] = {0,1,2};
1257 int targs[] = {3,1,4};
1259 REQUIRE_THROWS_WITH(
multiControlledMultiRotatePauli(qureg, ctrls, numCtrls, targs, paulis, numTargs, param), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
1261 SECTION(
"qubit indices" ) {
1270 qb1[GENERATE_COPY(range(0,numQb))] = inv;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfPauliMatrix(), getKroneckerProduct(), getRandomInt(), getRandomReal(), M_PI, multiControlledMultiRotatePauli(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PREPARE_TEST, qcomp, qreal, and sublists().
◆ TEST_CASE() [96/124]
TEST_CASE |
( |
"multiControlledMultiRotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledMultiRotateZ
- Author
- Tyson Jones
Definition at line 1285 of file test_unitaries.cpp.
1290 SECTION(
"correctness" ) {
1293 int numTargs = GENERATE_COPY( range(1,
NUM_QUBITS) );
1295 int numCtrls = GENERATE_COPY( range(1,maxNumCtrls+1) );
1299 int* ctrls = GENERATE_COPY(
sublists(range(0,
NUM_QUBITS), numCtrls, targs, numTargs) );
1304 for (
int t=0; t<numTargs-1; t++)
1310 SECTION(
"state-vector" ) {
1314 REQUIRE(
areEqual(quregVec, refVec) );
1316 SECTION(
"density-matrix" ) {
1320 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
1323 SECTION(
"input validation" ) {
1328 Qureg regs[] = {quregVec, quregMatr};
1329 Qureg qureg = regs[GENERATE(0,1)];
1331 SECTION(
"number of targets" ) {
1335 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1340 REQUIRE_THROWS_WITH(
multiControlledMultiRotateZ(qureg, ctrls, numCtrls, targs, numTargs, param), Contains(
"Invalid number of target") );
1342 SECTION(
"repetition in targets" ) {
1347 int targs[] = {1,2,2};
1349 REQUIRE_THROWS_WITH(
multiControlledMultiRotateZ(qureg, ctrls, numCtrls, targs, numTargs, param), Contains(
"target") && Contains(
"unique"));
1351 SECTION(
"number of controls" ) {
1358 REQUIRE_THROWS_WITH(
multiControlledMultiRotateZ(qureg, ctrls, numCtrls, targs, numTargs, param), Contains(
"Invalid number of control"));
1360 SECTION(
"repetition in controls" ) {
1364 int ctrls[] = {0,1,1};
1367 REQUIRE_THROWS_WITH(
multiControlledMultiRotateZ(qureg, ctrls, numCtrls, targs, numTargs, param), Contains(
"control") && Contains(
"unique"));
1369 SECTION(
"control and target collision" ) {
1373 int ctrls[] = {0,1,2};
1374 int targs[] = {3,1,4};
1376 REQUIRE_THROWS_WITH(
multiControlledMultiRotateZ(qureg, ctrls, numCtrls, targs, numTargs, param), Contains(
"Control") && Contains(
"target") && Contains(
"disjoint"));
1378 SECTION(
"qubit indices" ) {
1387 qb1[GENERATE_COPY(range(0,numQb))] = inv;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfDiagonalMatrix(), getKroneckerProduct(), getRandomReal(), M_PI, multiControlledMultiRotateZ(), NUM_QUBITS, PREPARE_TEST, qcomp, qreal, and sublists().
◆ TEST_CASE() [97/124]
TEST_CASE |
( |
"multiControlledPhaseFlip" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledPhaseFlip
- Author
- Tyson Jones
Definition at line 1402 of file test_unitaries.cpp.
1409 SECTION(
"correctness" ) {
1412 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1415 SECTION(
"state-vector" ) {
1419 REQUIRE(
areEqual(quregVec, refVec) );
1421 SECTION(
"density-matrix" ) {
1425 REQUIRE(
areEqual(quregMatr, refMatr) );
1428 SECTION(
"input validation" ) {
1430 SECTION(
"number of controls" ) {
1432 int numCtrls = GENERATE( -1, 0,
NUM_QUBITS+1 );
1436 SECTION(
"repetition of controls" ) {
1439 int ctrls[] = {0,1,1};
1442 SECTION(
"qubit indices" ) {
1445 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
References applyReferenceOp(), areEqual(), CLEANUP_TEST, multiControlledPhaseFlip(), NUM_QUBITS, PREPARE_TEST, and sublists().
◆ TEST_CASE() [98/124]
TEST_CASE |
( |
"multiControlledPhaseShift" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledPhaseShift
- Author
- Tyson Jones
Definition at line 1458 of file test_unitaries.cpp.
1464 SECTION(
"correctness" ) {
1467 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1470 SECTION(
"state-vector" ) {
1474 REQUIRE(
areEqual(quregVec, refVec) );
1476 SECTION(
"density-matrix" ) {
1480 REQUIRE(
areEqual(quregMatr, refMatr) );
1483 SECTION(
"input validation" ) {
1485 SECTION(
"number of controls" ) {
1487 int numCtrls = GENERATE( -1, 0,
NUM_QUBITS+1 );
1489 REQUIRE_THROWS_WITH(
multiControlledPhaseShift(quregVec, ctrls, numCtrls, param), Contains(
"Invalid number of qubits"));
1491 SECTION(
"repetition of controls" ) {
1494 int ctrls[] = {0,1,1};
1497 SECTION(
"qubit indices" ) {
1500 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), M_PI, multiControlledPhaseShift(), NUM_QUBITS, PREPARE_TEST, qreal, and sublists().
◆ TEST_CASE() [99/124]
TEST_CASE |
( |
"multiControlledTwoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledTwoQubitUnitary
- Author
- Tyson Jones
Definition at line 1513 of file test_unitaries.cpp.
1518 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
1524 SECTION(
"correctness" ) {
1528 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
1529 int targs[] = {targ1, targ2};
1530 int numCtrls = GENERATE( range(1,
NUM_QUBITS-1) );
1533 SECTION(
"state-vector" ) {
1537 REQUIRE(
areEqual(quregVec, refVec) );
1539 SECTION(
"density-matrix" ) {
1543 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1546 SECTION(
"input validation" ) {
1548 SECTION(
"number of controls" ) {
1555 SECTION(
"repetition of controls" ) {
1558 int ctrls[] = {0,1,1};
1563 SECTION(
"repetition of targets" ) {
1566 int ctrls[] = {0,1,2};
1571 SECTION(
"control and target collision" ) {
1574 int ctrls[] = {0,1,2};
1576 int targ2 = ctrls[GENERATE_COPY( range(0,numCtrls) )];
1579 SECTION(
"qubit indices" ) {
1585 int ctrls[] = { 2, 3, 4 };
1591 ctrls[numCtrls-1] = inv;
1594 SECTION(
"unitarity " ) {
1597 matr.
real[0][0] = 0;
1600 SECTION(
"unitary fits in node" ) {
1603 quregVec.numAmpsPerChunk = 1;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), multiControlledTwoQubitUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix4::real, sublists(), and toComplexMatrix4().
◆ TEST_CASE() [100/124]
TEST_CASE |
( |
"multiControlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiControlledUnitary
- Author
- Tyson Jones
Definition at line 1617 of file test_unitaries.cpp.
1625 SECTION(
"correctness" ) {
1627 int target = GENERATE( range(0,
NUM_QUBITS) );
1628 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
1631 SECTION(
"state-vector" ) {
1635 REQUIRE(
areEqual(quregVec, refVec) );
1637 SECTION(
"density-matrix" ) {
1641 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1644 SECTION(
"input validation" ) {
1646 SECTION(
"number of controls" ) {
1650 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, numCtrls, 0, matr), Contains(
"Invalid number of control"));
1652 SECTION(
"repetition of controls" ) {
1654 int ctrls[] = {0,1,1};
1655 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, 2, matr), Contains(
"control") && Contains(
"unique"));
1657 SECTION(
"control and target collision" ) {
1659 int ctrls[] = {0,1,2};
1660 int targ = ctrls[GENERATE( range(0,3) )];
1661 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, targ, matr), Contains(
"Control") && Contains(
"target") );
1663 SECTION(
"qubit indices" ) {
1665 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
1670 REQUIRE_THROWS_WITH(
multiControlledUnitary(quregVec, ctrls, 3, targ, matr), Contains(
"Invalid target") );
1672 SECTION(
"unitarity" ) {
1674 matr.
real[0][0] = 0;
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), multiControlledUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, sublists(), and toComplexMatrix2().
◆ TEST_CASE() [101/124]
TEST_CASE |
( |
"multiQubitNot" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiQubitNot
- Author
- Tyson Jones
Definition at line 1688 of file test_unitaries.cpp.
1692 SECTION(
"correctness" ) {
1695 int numTargs = GENERATE_COPY( range(1,
NUM_QUBITS+1) );
1703 SECTION(
"state-vector" ) {
1706 for (
int t=0; t<numTargs; t++)
1709 REQUIRE(
areEqual(quregVec, refVec) );
1711 SECTION(
"density-matrix" ) {
1714 for (
int t=0; t<numTargs; t++)
1717 REQUIRE(
areEqual(quregMatr, refMatr) );
1720 SECTION(
"input validation" ) {
1722 SECTION(
"number of targets" ) {
1725 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1727 REQUIRE_THROWS_WITH(
multiQubitNot(quregVec, targs, numTargs), Contains(
"Invalid number of target"));
1729 SECTION(
"repetition in targets" ) {
1732 int targs[] = {1,2,2};
1733 REQUIRE_THROWS_WITH(
multiQubitNot(quregVec, targs, numTargs), Contains(
"target") && Contains(
"unique"));
1735 SECTION(
"target indices" ) {
1739 int qubits[] = {0,1,2,3,4};
1742 qubits[GENERATE_COPY(range(0,numQb))] = GENERATE( -1,
NUM_QUBITS );
1743 REQUIRE_THROWS_WITH(
multiQubitNot(quregVec, qubits, numQb), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, multiQubitNot(), NUM_QUBITS, PREPARE_TEST, and sublists().
◆ TEST_CASE() [102/124]
TEST_CASE |
( |
"multiQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiQubitUnitary
- Author
- Tyson Jones
Definition at line 1755 of file test_unitaries.cpp.
1760 int maxNumTargs =
calcLog2(quregVec.numAmpsPerChunk);
1762 SECTION(
"correctness" ) {
1765 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
1773 SECTION(
"state-vector" ) {
1777 REQUIRE(
areEqual(quregVec, refVec) );
1779 SECTION(
"density-matrix" ) {
1783 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1787 SECTION(
"input validation" ) {
1789 SECTION(
"number of targets" ) {
1792 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1796 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"Invalid number of target"));
1799 SECTION(
"repetition in targets" ) {
1802 int targs[] = {1,2,2};
1805 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"target") && Contains(
"unique"));
1808 SECTION(
"qubit indices" ) {
1811 int targs[] = {1,2,3};
1815 targs[GENERATE_COPY( range(0,numTargs) )] = inv;
1816 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"Invalid target") );
1820 SECTION(
"unitarity" ) {
1822 int numTargs = GENERATE_COPY( range(1,maxNumTargs) );
1823 int targs[numTargs];
1824 for (
int i=0; i<numTargs; i++)
1829 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"unitary") );
1832 SECTION(
"unitary creation" ) {
1835 int targs[] = {1,2,3};
1845 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, numTargs, matr), Contains(
"created") );
1847 SECTION(
"unitary dimensions" ) {
1849 int targs[2] = {1,2};
1852 REQUIRE_THROWS_WITH(
multiQubitUnitary(quregVec, targs, 2, matr), Contains(
"matrix size"));
1855 SECTION(
"unitary fits in node" ) {
1858 quregVec.numAmpsPerChunk = 1;
1861 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() [103/124]
TEST_CASE |
( |
"multiRotatePauli" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiRotatePauli
- Author
- Tyson Jones
Definition at line 1874 of file test_unitaries.cpp.
1879 SECTION(
"correctness" ) {
1881 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
1889 GENERATE( range(0,10) );
1891 for (
int i=0; i<numTargs; i++)
1895 int refTargs[numTargs];
1896 int numRefTargs = 0;
1904 for (
int i=0; i<numTargs; i++) {
1906 if (paulis[i] ==
PAULI_I)
continue;
1907 if (paulis[i] ==
PAULI_X) fac = xMatr;
1908 if (paulis[i] ==
PAULI_Y) fac = yMatr;
1909 if (paulis[i] ==
PAULI_Z) fac = zMatr;
1913 refTargs[numRefTargs++] = targs[i];
1918 if (numRefTargs > 0)
1921 SECTION(
"state-vector" ) {
1924 if (numRefTargs > 0)
1926 REQUIRE(
areEqual(quregVec, refVec) );
1928 SECTION(
"density-matrix" ) {
1931 if (numRefTargs > 0)
1933 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
1936 SECTION(
"input validation" ) {
1938 SECTION(
"number of targets" ) {
1940 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
1943 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid number of target"));
1945 SECTION(
"repetition of targets" ) {
1948 int targs[3] = {0, 1, 1};
1950 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"target") && Contains(
"unique"));
1952 SECTION(
"qubit indices" ) {
1955 int targs[3] = {0, 1, 2};
1956 targs[GENERATE_COPY(range(0,numTargs))] = GENERATE( -1,
NUM_QUBITS );
1958 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid target"));
1960 SECTION(
"pauli codes" ) {
1962 int targs[3] = {0, 1, 2};
1964 paulis[GENERATE_COPY(range(0,numTargs))] = (
pauliOpType) GENERATE( -1, 4 );
1965 REQUIRE_THROWS_WITH(
multiRotatePauli(quregVec, targs, paulis, numTargs, param), Contains(
"Invalid Pauli code"));
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfPauliMatrix(), getKroneckerProduct(), getRandomInt(), getRandomReal(), M_PI, multiRotatePauli(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, PAULI_Z, PREPARE_TEST, qcomp, qreal, and sublists().
◆ TEST_CASE() [104/124]
TEST_CASE |
( |
"multiRotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiRotateZ
- Author
- Tyson Jones
Definition at line 1977 of file test_unitaries.cpp.
1982 SECTION(
"correctness" ) {
1984 int numTargs = GENERATE( range(1,
NUM_QUBITS+1) );
1990 for (
int t=0; t<numTargs-1; t++)
2005 SECTION(
"state-vector" ) {
2009 REQUIRE(
areEqual(quregVec, refVec) );
2011 SECTION(
"density-matrix" ) {
2015 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
2018 SECTION(
"input validation" ) {
2020 SECTION(
"number of targets" ) {
2022 int numTargs = GENERATE( -1, 0,
NUM_QUBITS+1 );
2024 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"Invalid number of target"));
2027 SECTION(
"repetition of targets" ) {
2030 int targs[3] = {0, 1, 1};
2031 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"target") && Contains(
"unique"));
2033 SECTION(
"qubit indices" ) {
2036 int targs[3] = {0, 1, 2};
2037 targs[GENERATE_COPY(range(0,numTargs))] = GENERATE( -1,
NUM_QUBITS );
2038 REQUIRE_THROWS_WITH(
multiRotateZ(quregVec, targs, numTargs, param), Contains(
"Invalid target"));
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getExponentialOfDiagonalMatrix(), getFullOperatorMatrix(), getKroneckerProduct(), getRandomReal(), M_PI, multiRotateZ(), NUM_QUBITS, PREPARE_TEST, qcomp, qreal, and sublists().
◆ TEST_CASE() [105/124]
TEST_CASE |
( |
"multiStateControlledUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- multiStateControlledUnitary
- Author
- Tyson Jones
Definition at line 2050 of file test_unitaries.cpp.
2061 SECTION(
"correctness" ) {
2063 int target = GENERATE( range(0,
NUM_QUBITS) );
2064 int numCtrls = GENERATE( range(1,
NUM_QUBITS) );
2066 int* ctrlState = GENERATE_COPY(
bitsets(numCtrls) );
2068 SECTION(
"state-vector" ) {
2073 for (
int i=0; i<numCtrls; i++)
2074 if (ctrlState[i] == 0)
2077 for (
int i=0; i<numCtrls; i++)
2078 if (ctrlState[i] == 0)
2081 REQUIRE(
areEqual(quregVec, refVec) );
2083 SECTION(
"density-matrix" ) {
2088 for (
int i=0; i<numCtrls; i++)
2089 if (ctrlState[i] == 0)
2092 for (
int i=0; i<numCtrls; i++)
2093 if (ctrlState[i] == 0)
2096 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2099 SECTION(
"input validation" ) {
2101 SECTION(
"number of controls" ) {
2106 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, numCtrls, 0, matr), Contains(
"Invalid number of control"));
2108 SECTION(
"repetition of controls" ) {
2110 int ctrls[] = {0,1,1};
2111 int ctrlState[] = {0, 1, 0};
2112 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, 3, 2, matr), Contains(
"control") && Contains(
"unique"));
2114 SECTION(
"control and target collision" ) {
2116 int ctrls[] = {0,1,2};
2117 int ctrlState[] = {0, 1, 0};
2118 int targ = ctrls[GENERATE( range(0,3) )];
2119 REQUIRE_THROWS_WITH(
multiStateControlledUnitary(quregVec, ctrls, ctrlState, 3, targ, matr), Contains(
"Control") && Contains(
"target") );
2121 SECTION(
"qubit indices" ) {
2123 int ctrls[] = { 1, 2, GENERATE( -1,
NUM_QUBITS ) };
2124 int ctrlState[] = {0, 1, 0};
2131 SECTION(
"unitarity" ) {
2133 matr.
real[0][0] = 0;
2135 int ctrlState[1] = {0};
2138 SECTION(
"control state bits" ) {
2141 int ctrls[] = {0, 1, 2};
2142 int ctrlState[] = {0, 0, 0};
2146 ctrlState[2] = GENERATE(-1, 2);
References applyReferenceOp(), areEqual(), bitsets(), CLEANUP_TEST, getRandomUnitary(), multiStateControlledUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, sublists(), and toComplexMatrix2().
◆ TEST_CASE() [106/124]
TEST_CASE |
( |
"pauliX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliX
- Author
- Tyson Jones
Definition at line 2159 of file test_unitaries.cpp.
2164 SECTION(
"correctness" ) {
2166 int target = GENERATE( range(0,
NUM_QUBITS) );
2168 SECTION(
"state-vector" ) {
2170 pauliX(quregVec, target);
2172 REQUIRE(
areEqual(quregVec, refVec) );
2174 SECTION(
"density-matrix correctness" ) {
2176 pauliX(quregMatr, target);
2178 REQUIRE(
areEqual(quregMatr, refMatr) );
2181 SECTION(
"input validation" ) {
2183 SECTION(
"qubit indices" ) {
2186 REQUIRE_THROWS_WITH(
pauliX(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliX(), and PREPARE_TEST.
◆ TEST_CASE() [107/124]
TEST_CASE |
( |
"pauliY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliY
- Author
- Tyson Jones
Definition at line 2198 of file test_unitaries.cpp.
2203 SECTION(
"correctness" ) {
2205 int target = GENERATE( range(0,
NUM_QUBITS) );
2207 SECTION(
"state-vector" ) {
2209 pauliY(quregVec, target);
2211 REQUIRE(
areEqual(quregVec, refVec) );
2213 SECTION(
"density-matrix correctness" ) {
2215 pauliY(quregMatr, target);
2217 REQUIRE(
areEqual(quregMatr, refMatr) );
2220 SECTION(
"input validation" ) {
2222 SECTION(
"qubit indices" ) {
2225 REQUIRE_THROWS_WITH(
pauliY(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliY(), PREPARE_TEST, and qcomp.
◆ TEST_CASE() [108/124]
TEST_CASE |
( |
"pauliZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- pauliZ
- Author
- Tyson Jones
Definition at line 2237 of file test_unitaries.cpp.
2242 SECTION(
"correctness" ) {
2244 int target = GENERATE( range(0,
NUM_QUBITS) );
2246 SECTION(
"state-vector" ) {
2248 pauliZ(quregVec, target);
2250 REQUIRE(
areEqual(quregVec, refVec) );
2252 SECTION(
"density-matrix correctness" ) {
2254 pauliZ(quregMatr, target);
2256 REQUIRE(
areEqual(quregMatr, refMatr) );
2259 SECTION(
"input validation" ) {
2261 SECTION(
"qubit indices" ) {
2264 REQUIRE_THROWS_WITH(
pauliZ(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, pauliZ(), and PREPARE_TEST.
◆ TEST_CASE() [109/124]
TEST_CASE |
( |
"phaseShift" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- phaseShift
- Author
- Tyson Jones
Definition at line 2276 of file test_unitaries.cpp.
2282 SECTION(
"correctness" ) {
2284 int target = GENERATE( range(0,
NUM_QUBITS) );
2286 SECTION(
"state-vector ") {
2290 REQUIRE(
areEqual(quregVec, refVec) );
2292 SECTION(
"density-matrix" ) {
2296 REQUIRE(
areEqual(quregMatr, refMatr) );
2299 SECTION(
"input validation" ) {
2301 SECTION(
"qubit indices" ) {
2304 REQUIRE_THROWS_WITH(
phaseShift(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), M_PI, NUM_QUBITS, phaseShift(), PREPARE_TEST, and qreal.
◆ TEST_CASE() [110/124]
TEST_CASE |
( |
"rotateAroundAxis" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateAroundAxis
- Author
- Tyson Jones
Definition at line 2316 of file test_unitaries.cpp.
2326 qreal c = cos(param/2);
2327 qreal s = sin(param/2);
2328 qreal m = sqrt(vec.
x*vec.
x + vec.
y*vec.
y + vec.
z*vec.
z);
2330 {(vec.
y -
qcomp(0,1)*vec.
x)*s/m, c +
qcomp(0,1)*vec.
z*s/m}};
2332 SECTION(
"correctness" ) {
2334 int target = GENERATE( range(0,
NUM_QUBITS) );
2336 SECTION(
"state-vector ") {
2340 REQUIRE(
areEqual(quregVec, refVec) );
2342 SECTION(
"density-matrix" ) {
2346 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2349 SECTION(
"input validation" ) {
2351 SECTION(
"qubit indices" ) {
2354 REQUIRE_THROWS_WITH(
rotateAroundAxis(quregVec, target, param, vec), Contains(
"Invalid target") );
2356 SECTION(
"zero rotation axis" ) {
2359 vec = {.
x=0, .y=0, .z=0};
2360 REQUIRE_THROWS_WITH(
rotateAroundAxis(quregVec, target, param, vec), Contains(
"Invalid axis") && Contains(
"zero") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, qreal, rotateAroundAxis(), Vector::x, Vector::y, and Vector::z.
◆ TEST_CASE() [111/124]
TEST_CASE |
( |
"rotateX" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateX
- Author
- Tyson Jones
Definition at line 2372 of file test_unitaries.cpp.
2377 {cos(param/2), - sin(param/2)*
qcomp(0,1)},
2378 {- sin(param/2)*
qcomp(0,1), cos(param/2)}};
2380 SECTION(
"correctness" ) {
2382 int target = GENERATE( range(0,
NUM_QUBITS) );
2384 SECTION(
"state-vector ") {
2386 rotateX(quregVec, target, param);
2388 REQUIRE(
areEqual(quregVec, refVec) );
2390 SECTION(
"density-matrix" ) {
2392 rotateX(quregMatr, target, param);
2394 REQUIRE(
areEqual(quregMatr, refMatr) );
2397 SECTION(
"input validation" ) {
2399 SECTION(
"qubit indices" ) {
2402 REQUIRE_THROWS_WITH(
rotateX(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, qcomp, qreal, and rotateX().
◆ TEST_CASE() [112/124]
TEST_CASE |
( |
"rotateY" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateY
- Author
- Tyson Jones
Definition at line 2414 of file test_unitaries.cpp.
2418 QMatrix op{{cos(param/2), -sin(param/2)},{sin(param/2), cos(param/2)}};
2420 SECTION(
"correctness" ) {
2422 int target = GENERATE( range(0,
NUM_QUBITS) );
2424 SECTION(
"state-vector ") {
2426 rotateY(quregVec, target, param);
2428 REQUIRE(
areEqual(quregVec, refVec) );
2430 SECTION(
"density-matrix" ) {
2432 rotateY(quregMatr, target, param);
2434 REQUIRE(
areEqual(quregMatr, refMatr, 2*REAL_EPS) );
2437 SECTION(
"input validation" ) {
2439 SECTION(
"qubit indices" ) {
2442 REQUIRE_THROWS_WITH(
rotateY(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, qreal, and rotateY().
◆ TEST_CASE() [113/124]
TEST_CASE |
( |
"rotateZ" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- rotateZ
- Author
- Tyson Jones
Definition at line 2454 of file test_unitaries.cpp.
2460 SECTION(
"correctness" ) {
2462 int target = GENERATE( range(0,
NUM_QUBITS) );
2464 SECTION(
"state-vector ") {
2466 rotateZ(quregVec, target, param);
2468 REQUIRE(
areEqual(quregVec, refVec) );
2470 SECTION(
"density-matrix" ) {
2472 rotateZ(quregMatr, target, param);
2474 REQUIRE(
areEqual(quregMatr, refMatr) );
2477 SECTION(
"input validation" ) {
2479 SECTION(
"qubit indices" ) {
2482 REQUIRE_THROWS_WITH(
rotateZ(quregVec, target, param), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), getRandomReal(), M_PI, NUM_QUBITS, PREPARE_TEST, qreal, and rotateZ().
◆ TEST_CASE() [114/124]
TEST_CASE |
( |
"setAmps" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- setAmps
- Author
- Tyson Jones
Definition at line 381 of file test_state_initialisations.cpp.
389 SECTION(
"correctness" ) {
391 SECTION(
"state-vector" ) {
394 int startInd = GENERATE_COPY( range(0,maxInd) );
395 int numAmps = GENERATE_COPY( range(0,1+maxInd-startInd) );
398 for (
int i=0; i<numAmps; i++) {
407 setAmps(vec, startInd, reals, imags, numAmps);
408 for (
int i=0; i<numAmps; i++)
409 vecRef[startInd+i] = reals[i] + imags[i] * (
qcomp) 1i;
414 SECTION(
"input validation" ) {
416 SECTION(
"start index" ) {
418 int startInd = GENERATE_COPY( -1, maxInd );
420 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"Invalid amplitude index") );
423 SECTION(
"number of amplitudes" ) {
427 int numAmps = GENERATE_COPY( -1, maxInd+1 );
428 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"Invalid number of amplitudes") );
431 startInd = maxInd - 1;
433 REQUIRE_THROWS_WITH(
setAmps(vec, startInd, reals, imags, numAmps), Contains(
"More amplitudes given than exist") );
435 SECTION(
"density-matrix" ) {
438 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, qcomp, qreal, QUEST_ENV, setAmps(), and toQVector().
◆ TEST_CASE() [115/124]
TEST_CASE |
( |
"setDiagonalOpElems" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- setDiagonalOpElems
- Author
- Tyson Jones
Definition at line 966 of file test_data_structures.cpp.
974 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
977 SECTION(
"correctness" ) {
980 long long int len = (1LL << numQb);
984 for (n=0; n<len; n++) {
985 reals[n] = (
qreal) n;
986 imags[n] = (
qreal) -2*n;
990 for (n=0; n<len; n++)
998 SECTION(
"input validation" ) {
1000 long long int maxInd = (1LL << numQb);
1004 SECTION(
"start index" ) {
1006 int startInd = GENERATE_COPY( -1, maxInd );
1008 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"Invalid element index") );
1011 SECTION(
"number of elements" ) {
1015 int numAmps = GENERATE_COPY( -1, maxInd+1 );
1016 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"Invalid number of elements") );
1019 startInd = maxInd - 1;
1021 REQUIRE_THROWS_WITH(
setDiagonalOpElems(op, startInd, reals, imags, numAmps), Contains(
"More elements given than exist") );
References areEqual(), calcLog2(), createDiagonalOp(), destroyDiagonalOp(), QuESTEnv::numRanks, qreal, QUEST_ENV, setDiagonalOpElems(), and toQVector().
◆ TEST_CASE() [116/124]
TEST_CASE |
( |
"setWeightedQureg" |
, |
|
|
"" |
[state_initialisations] |
|
) |
| |
- See also
- setWeightedQureg
- Author
- Tyson Jones
Definition at line 451 of file test_state_initialisations.cpp.
453 SECTION(
"correctness" ) {
456 GENERATE( range(0,10) );
462 SECTION(
"state-vector" ) {
489 refOut = numA*refA + numB*refB + numC*refC;
499 refOut = numB*refB + numC*refC + numA*refC;
500 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
508 refOut = numC*refC + numB*refB + numA*refC;
509 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
517 refOut = numA*refC + numB*refC + numC*refC;
518 REQUIRE(
areEqual(vecC, refOut, 1E3*REAL_EPS) );
525 SECTION(
"density-matrix" ) {
552 refOut = numA*refA + numB*refB + numC*refC;
562 refOut = numB*refB + numC*refC + numA*refC;
563 REQUIRE(
areEqual(matC, refOut, 10*REAL_EPS) );
571 refOut = numC*refC + numB*refB + numA*refC;
572 REQUIRE(
areEqual(matC, refOut, 1E2*REAL_EPS) );
580 refOut = numA*refC + numB*refC + numC*refC;
581 REQUIRE(
areEqual(matC, refOut, 1E3*REAL_EPS) );
589 SECTION(
"input validation" ) {
591 SECTION(
"qureg types" ) {
598 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, vec, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
599 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, mat, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
600 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, vec, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
603 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vec, f, mat, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
604 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, vec, f, mat), Contains(
"state-vectors or") && Contains(
"density matrices") );
605 REQUIRE_THROWS_WITH(
setWeightedQureg(f, mat, f, mat, f, vec), Contains(
"state-vectors or") && Contains(
"density matrices") );
610 SECTION(
"qureg dimensions" ) {
619 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecA, f, vecB, f, vecB), Contains(
"Dimensions") );
620 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecB, f, vecA, f, vecB), Contains(
"Dimensions") );
621 REQUIRE_THROWS_WITH(
setWeightedQureg(f, vecB, f, vecB, f, vecA), Contains(
"Dimensions") );
624 REQUIRE_THROWS_WITH(
setWeightedQureg(f, matA, f, matB, f, matB), Contains(
"Dimensions") );
625 REQUIRE_THROWS_WITH(
setWeightedQureg(f, matB, f, matA, f, matB), Contains(
"Dimensions") );
626 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() [117/124]
TEST_CASE |
( |
"sGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- sGate
- Author
- Tyson Jones
Definition at line 2494 of file test_unitaries.cpp.
2499 SECTION(
"correctness" ) {
2501 int target = GENERATE( range(0,
NUM_QUBITS) );
2503 SECTION(
"state-vector ") {
2505 sGate(quregVec, target);
2507 REQUIRE(
areEqual(quregVec, refVec) );
2509 SECTION(
"density-matrix" ) {
2511 sGate(quregMatr, target);
2513 REQUIRE(
areEqual(quregMatr, refMatr) );
2516 SECTION(
"input validation" ) {
2518 SECTION(
"qubit indices" ) {
2521 REQUIRE_THROWS_WITH(
sGate(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, PREPARE_TEST, qcomp, and sGate().
◆ TEST_CASE() [118/124]
TEST_CASE |
( |
"sqrtSwapGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- sqrtSwapGate
- Author
- Tyson Jones
Definition at line 2533 of file test_unitaries.cpp.
2538 QMatrix op{{1,0,0,0},{0,a,b,0},{0,b,a,0},{0,0,0,1}};
2540 SECTION(
"correctness" ) {
2543 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2544 int targs[] = {targ1, targ2};
2546 SECTION(
"state-vector" ) {
2550 REQUIRE(
areEqual(quregVec, refVec) );
2552 SECTION(
"density-matrix" ) {
2556 REQUIRE(
areEqual(quregMatr, refMatr) );
2559 SECTION(
"input validation" ) {
2561 SECTION(
"qubit indices" ) {
2565 REQUIRE_THROWS_WITH(
sqrtSwapGate(quregVec, targ1, targ2), Contains(
"Invalid target") );
2566 REQUIRE_THROWS_WITH(
sqrtSwapGate(quregVec, targ2, targ1), Contains(
"Invalid target") );
2568 SECTION(
"repetition of targets" ) {
2571 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() [119/124]
TEST_CASE |
( |
"swapGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- swapGate
- Author
- Tyson Jones
Definition at line 2583 of file test_unitaries.cpp.
2586 QMatrix op{{1,0,0,0},{0,0,1,0},{0,1,0,0},{0,0,0,1}};
2588 SECTION(
"correctness" ) {
2591 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2592 int targs[] = {targ1, targ2};
2594 SECTION(
"state-vector" ) {
2598 REQUIRE(
areEqual(quregVec, refVec) );
2600 SECTION(
"density-matrix" ) {
2604 REQUIRE(
areEqual(quregMatr, refMatr) );
2607 SECTION(
"input validation" ) {
2609 SECTION(
"qubit indices" ) {
2613 REQUIRE_THROWS_WITH(
swapGate(quregVec, targ1, targ2), Contains(
"Invalid target") );
2614 REQUIRE_THROWS_WITH(
swapGate(quregVec, targ2, targ1), Contains(
"Invalid target") );
2616 SECTION(
"repetition of targets" ) {
2619 REQUIRE_THROWS_WITH(
swapGate(quregVec, qb, qb), Contains(
"target") && Contains(
"unique") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, NUM_QUBITS, PREPARE_TEST, and swapGate().
◆ TEST_CASE() [120/124]
TEST_CASE |
( |
"syncDiagonalOp" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
- See also
- syncDiagonalOp
- Author
- Tyson Jones
Definition at line 1034 of file test_data_structures.cpp.
1041 SECTION(
"correctness" ) {
1044 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
1067 REQUIRE( qureg.
stateVec.real[n] == 3*n );
1068 REQUIRE( qureg.
stateVec.imag[n] == -n );
References applyDiagonalOp(), calcLog2(), copyStateFromGPU(), copyStateToGPU(), createDiagonalOp(), createQureg(), destroyDiagonalOp(), destroyQureg(), DiagonalOp::imag, Qureg::numAmpsPerChunk, DiagonalOp::numElemsPerChunk, QuESTEnv::numRanks, qreal, QUEST_ENV, DiagonalOp::real, Qureg::stateVec, and syncDiagonalOp().
◆ TEST_CASE() [121/124]
TEST_CASE |
( |
"tGate" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- tGate
- Author
- Tyson Jones
Definition at line 2631 of file test_unitaries.cpp.
2636 SECTION(
"correctness" ) {
2638 int target = GENERATE( range(0,
NUM_QUBITS) );
2640 SECTION(
"state-vector ") {
2642 tGate(quregVec, target);
2644 REQUIRE(
areEqual(quregVec, refVec) );
2646 SECTION(
"density-matrix" ) {
2648 tGate(quregMatr, target);
2650 REQUIRE(
areEqual(quregMatr, refMatr) );
2653 SECTION(
"input validation" ) {
2655 SECTION(
"qubit indices" ) {
2658 REQUIRE_THROWS_WITH(
tGate(quregVec, target), Contains(
"Invalid target") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, expI(), M_PI, NUM_QUBITS, PREPARE_TEST, and tGate().
◆ TEST_CASE() [122/124]
TEST_CASE |
( |
"toComplex" |
, |
|
|
"" |
[data_structures] |
|
) |
| |
◆ TEST_CASE() [123/124]
TEST_CASE |
( |
"twoQubitUnitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- twoQubitUnitary
- Author
- Tyson Jones
Definition at line 2670 of file test_unitaries.cpp.
2675 REQUIRE( quregVec.numAmpsPerChunk >= 4 );
2681 SECTION(
"correctness" ) {
2684 int targ2 = GENERATE_COPY( filter([=](
int t){
return t!=targ1; }, range(0,
NUM_QUBITS)) );
2685 int targs[] = {targ1, targ2};
2687 SECTION(
"state-vector" ) {
2691 REQUIRE(
areEqual(quregVec, refVec) );
2693 SECTION(
"density-matrix" ) {
2697 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2700 SECTION(
"input validation" ) {
2702 SECTION(
"qubit indices" ) {
2706 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, targ1, targ2, matr), Contains(
"Invalid target") );
2707 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, targ2, targ1, matr), Contains(
"Invalid target") );
2709 SECTION(
"repetition of targets" ) {
2712 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, qb, qb, matr), Contains(
"target") && Contains(
"unique") );
2714 SECTION(
"unitarity" ) {
2716 matr.
real[0][0] = 0;
2717 REQUIRE_THROWS_WITH(
twoQubitUnitary(quregVec, 0, 1, matr), Contains(
"unitary") );
2719 SECTION(
"unitary fits in node" ) {
2722 quregVec.numAmpsPerChunk = 1;
2723 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() [124/124]
TEST_CASE |
( |
"unitary" |
, |
|
|
"" |
[unitaries] |
|
) |
| |
- See also
- unitary
- Author
- Tyson Jones
Definition at line 2735 of file test_unitaries.cpp.
2743 SECTION(
"correctness" ) {
2745 int target = GENERATE( range(0,
NUM_QUBITS) );
2747 SECTION(
"state-vector" ) {
2749 unitary(quregVec, target, matr);
2751 REQUIRE(
areEqual(quregVec, refVec) );
2753 SECTION(
"density-matrix" ) {
2755 unitary(quregMatr, target, matr);
2757 REQUIRE(
areEqual(quregMatr, refMatr, 10*REAL_EPS) );
2760 SECTION(
"input validation" ) {
2762 SECTION(
"qubit indices" ) {
2765 REQUIRE_THROWS_WITH(
unitary(quregVec, target, matr), Contains(
"Invalid target") );
2767 SECTION(
"unitarity" ) {
2769 matr.
real[0][0] = 0;
2770 REQUIRE_THROWS_WITH(
unitary(quregVec, 0, matr), Contains(
"unitary") );
References applyReferenceOp(), areEqual(), CLEANUP_TEST, getRandomUnitary(), NUM_QUBITS, PREPARE_TEST, ComplexMatrix2::real, toComplexMatrix2(), and unitary().
void controlledRotateZ(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.
void mixDephasing(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit dephasing noise.
qreal getProbAmp(Qureg qureg, long long int index)
Get the probability of a state-vector at an index in the full state vector.
void initBlankState(Qureg qureg)
Initialises a qureg to have all-zero-amplitudes.
Represents a 3-vector of real numbers.
pauliOpType
Codes for specifying Pauli operators.
void applyPhaseFunc(Qureg qureg, int *qubits, int numQubits, enum bitEncoding encoding, qreal *coeffs, qreal *exponents, int numTerms)
Induces a phase change upon each amplitude of qureg, determined by the passed exponential polynomial ...
QMatrix getFullOperatorMatrix(int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op, int numQubits)
Takes a 2^numTargs-by-2^numTargs matrix op and a returns a 2^numQubits-by-2^numQubits matrix where op...
void applyMultiControlledMatrixN(Qureg qureg, int *ctrls, int numCtrls, int *targs, int numTargs, ComplexMatrixN u)
Apply a general N-by-N matrix, which may be non-unitary, with additional controlled qubits.
void twoQubitUnitary(Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general two-qubit unitary (including a global phase factor).
void controlledRotateX(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.
void applyNamedPhaseFuncOverrides(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, enum phaseFunc functionNameCode, long long int *overrideInds, qreal *overridePhases, int numOverrides)
Induces a phase change upon each amplitude of qureg, determined by a named (and potentially multi-var...
void copyStateFromGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from GPU memory (qureg....
void initPauliHamil(PauliHamil hamil, qreal *coeffs, enum pauliOpType *codes)
Initialise PauliHamil instance hamil with the given term coefficients and Pauli codes (one for every ...
QuESTEnv QUEST_ENV
The global QuESTEnv instance, to be created and destroyed once in this main(), so that the MPI enviro...
void syncQuESTEnv(QuESTEnv env)
Guarantees that all code up to the given point has been executed on all nodes (if running in distribu...
#define fromComplex(comp)
void initPureState(Qureg qureg, Qureg pure)
Initialise qureg into to a given pure state of an equivalent Hilbert dimension.
#define CLEANUP_TEST(quregVec, quregMatr)
Destroys the data structures made by PREPARE_TEST.
void applyProjector(Qureg qureg, int qubit, int outcome)
Force the target qubit of qureg into the given classical outcome, via a non-renormalising projection.
void rotateAroundAxis(Qureg qureg, int rotQubit, qreal angle, Vector axis)
Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere.
QVector getKroneckerProduct(QVector b, QVector a)
Returns b (otimes) a.
void mixDepolarising(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit homogeneous depolarising noise.
qreal calcTotalProb(Qureg qureg)
A debugging function which calculates the probability of the qubits in qureg being in any state,...
void mixDamping(Qureg qureg, int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit amplitude damping (decay to 0 state).
void destroyComplexMatrixN(ComplexMatrixN m)
Destroy a ComplexMatrixN instance created with createComplexMatrixN()
int numChunks
The number of nodes between which the elements of this operator are split.
void applyNamedPhaseFunc(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, enum phaseFunc functionNameCode)
Induces a phase change upon each amplitude of qureg, determined by a named (and potentially multi-var...
void calcProbOfAllOutcomes(qreal *retProbs, Qureg qureg, int *qubits, int numQubits)
Populates outcomeProbs with the probabilities of every outcome of the sub-register contained in qubit...
void multiControlledMultiQubitNot(Qureg qureg, int *ctrls, int numCtrls, int *targs, int numTargs)
Apply a NOT (or Pauli X) gate with multiple control and target qubits.
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.
DiagonalOp createDiagonalOpFromPauliHamilFile(char *fn, QuESTEnv env)
Creates and initialiases a diagonal operator from the Z Pauli Hamiltonian encoded in file with filena...
ComplexMatrixN createComplexMatrixN(int numQubits)
Allocate dynamic memory for a square complex matrix of any size, which can be passed to functions lik...
qreal getImagAmp(Qureg qureg, long long int index)
Get the imaginary component of the complex probability amplitude at an index in the state vector.
void controlledRotateAroundAxis(Qureg qureg, int controlQubit, int targetQubit, qreal angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
void mixKrausMap(Qureg qureg, int target, ComplexMatrix2 *ops, int numOps)
Apply a general single-qubit Kraus map to a density matrix, as specified by at most four Kraus operat...
QMatrix getMixedDensityMatrix(std::vector< qreal > probs, std::vector< QVector > states)
Returns a mixed density matrix formed from mixing the given pure states, which are assumed normalised...
void syncDiagonalOp(DiagonalOp op)
Update the GPU memory with the current values in op.real and op.imag.
void destroyDiagonalOp(DiagonalOp op, QuESTEnv env)
Destroys a DiagonalOp created with createDiagonalOp(), freeing its memory.
void multiControlledTwoQubitUnitary(Qureg qureg, int *controlQubits, int numControlQubits, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general multi-controlled two-qubit unitary (including a global phase factor).
#define NUM_QUBITS
The default number of qubits in the registers created for unit testing (both statevectors and density...
qreal collapseToOutcome(Qureg qureg, int measureQubit, int outcome)
Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...
#define CLEANUP_TEST(quregVec, quregMatr)
Destroys the data structures made by PREPARE_TEST.
qreal calcPurity(Qureg qureg)
Calculates the purity of a density matrix, by the trace of the density matrix squared.
qreal calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome)
Gives the probability of a specified qubit being measured in the given outcome (0 or 1).
int measure(Qureg qureg, int measureQubit)
Measures a single qubit, collapsing it randomly to 0 or 1.
QMatrix getRandomUnitary(int numQb)
Returns a uniformly random (under Haar) 2^numQb-by-2^numQb unitary matrix.
qreal calcFidelity(Qureg qureg, Qureg pureState)
Calculates the fidelity of qureg (a state-vector or density matrix) against a reference pure state (n...
void writeToFileSynch(char *fn, const string &contents)
Writes contents to the file with filename fn, which is created and/or overwritten.
qreal getRandomReal(qreal min, qreal max)
Returns a random real between min (inclusive) and max (exclusive), from the uniform distribution.
void unitary(Qureg qureg, int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary (including a global phase factor).
int chunkId
The position of the chunk of the operator held by this process in the full operator.
void setDiagMatrixOverrides(QMatrix &matr, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, long long int *overrideInds, qreal *overridePhases, int numOverrides)
Modifies the given diagonal matrix such that the diagonal elements which correspond to the coordinate...
QMatrix getKetBra(QVector ket, QVector bra)
Returns the matrix |ket><bra|, with ith-jth element ket(i) conj(bra(j)), since |ket><bra| = sum_i a_i...
void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit homogeneous depolarising noise.
Complex calcExpecDiagonalOp(Qureg qureg, DiagonalOp op)
Computes the expected value of the diagonal operator op for state qureg.
void sGate(Qureg qureg, int targetQubit)
Apply the single-qubit S gate.
void cloneQureg(Qureg targetQureg, Qureg copyQureg)
Overwrite the amplitudes of targetQureg with those from copyQureg.
std::vector< QVector > getRandomOrthonormalVectors(int numQb, int numStates)
Returns a list of random orthonormal complex vectors, from an undisclosed distribution.
Represents a 4x4 matrix of complex numbers.
@ SCALED_INVERSE_DISTANCE
void rotateY(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.
void applyPauliHamil(Qureg inQureg, PauliHamil hamil, Qureg outQureg)
Modifies outQureg to be the result of applying PauliHamil (a Hermitian but not necessarily unitary op...
Information about the environment the program is running in.
void applyQFT(Qureg qureg, int *qubits, int numQubits)
Applies the quantum Fourier transform (QFT) to a specific subset of qubits of the register qureg.
PauliHamil createPauliHamilFromFile(char *fn)
Creates a PauliHamil instance, a real-weighted sum of products of Pauli operators,...
void applyPhaseFuncOverrides(Qureg qureg, int *qubits, int numQubits, enum bitEncoding encoding, qreal *coeffs, qreal *exponents, int numTerms, long long int *overrideInds, qreal *overridePhases, int numOverrides)
Induces a phase change upon each amplitude of qureg, determined by the passed exponential polynomial ...
void multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
Introduce a phase factor on state of the passed qubits.
void setDiagonalOpElems(DiagonalOp op, long long int startInd, qreal *real, qreal *imag, long long int numElems)
Modifies a subset (starting at index startInd, and ending at index startInd + numElems) of the elemen...
Represents a general 2^N by 2^N matrix of complex numbers.
void multiRotatePauli(Qureg qureg, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle)
Apply a multi-qubit multi-Pauli rotation, also known as a Pauli gadget, on a selected number of qubit...
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 state-vector qureg, with those passed in reals and imags.
unsigned int calcLog2(long unsigned int num)
returns log2 of numbers which must be gauranteed to be 2^n
void multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits)
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled paul...
void multiQubitUnitary(Qureg qureg, int *targs, int numTargs, ComplexMatrixN u)
Apply a general multi-qubit unitary (including a global phase factor) with any number of target qubit...
#define PREPARE_TEST(quregVec, quregMatr, refVec, refMatr)
Prepares the needed data structures for unit testing unitaries.
void multiControlledMultiRotateZ(Qureg qureg, int *controlQubits, int numControls, int *targetQubits, int numTargets, qreal angle)
Apply a multi-controlled multi-target Z rotation, also known as a controlled phase gadget.
Complex getAmp(Qureg qureg, long long int index)
Get the complex amplitude at a given index in the state vector.
void controlledPauliY(Qureg qureg, int controlQubit, int targetQubit)
Apply the controlled pauliY (single control, single target) gate, also known as the c-Y and c-sigma-Y...
QMatrix getExponentialOfPauliMatrix(qreal angle, QMatrix a)
Returns the matrix exponential of a kronecker product of pauli matrices (or of any involutory matrice...
int measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb)
Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of ...
int numQubitsInStateVec
Number of qubits in the state-vector - this is double the number represented for mixed states.
qreal calcExpecPauliHamil(Qureg qureg, PauliHamil hamil, Qureg workspace)
Computes the expected value of qureg under Hermitian operator hamil.
void setUniqueFilename(char *outFn, char *prefix)
Modifies outFn to be a filename of format prefix_NUM.txt where NUM is a new unique integer so far.
void multiControlledMultiQubitUnitary(Qureg qureg, int *ctrls, int numCtrls, int *targs, int numTargs, ComplexMatrixN u)
Apply a general multi-controlled multi-qubit unitary (including a global phase factor).
void setRandomPauliSum(qreal *coeffs, pauliOpType *codes, int numQubits, int numTerms)
Populates the coeffs array with random qreals in (-5, 5), and populates codes with random Pauli codes...
void toComplexMatrixN(QMatrix qm, ComplexMatrixN cm)
Initialises cm with the values of qm.
void rotateX(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.
void setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out)
Modifies qureg out to the result of (facOut out + fac1 qureg1 + fac2 qureg2), imposing no constraints...
void multiControlledMultiRotatePauli(Qureg qureg, int *controlQubits, int numControls, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle)
Apply a multi-controlled multi-target multi-Pauli rotation, also known as a controlled Pauli gadget.
qreal calcHilbertSchmidtDistance(Qureg a, Qureg b)
Computes the Hilbert Schmidt distance between two density matrices a and b, defined as the Frobenius ...
qcomp expI(qreal phase)
Returns the unit-norm complex number exp(i*phase).
std::vector< qcomp > QVector
A complex vector, which can be zero-initialised with QVector(numAmps).
qreal * imag
The imaginary values of the 2^numQubits complex elements.
void pauliZ(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.
phaseFunc
Flags for specifying named phase functions.
QVector toQVector(Qureg qureg)
Returns an equal-size copy of the given state-vector qureg.
long long int numAmpsPerChunk
Number of probability amplitudes held in stateVec by this process In the non-MPI version,...
void applyDiagonalOp(Qureg qureg, DiagonalOp op)
Apply a diagonal operator, which is possibly non-unitary and non-Hermitian, to the entire qureg.
qreal * termCoeffs
The real coefficient of each Pauli product. This is an array of length PauliHamil....
void applyMatrix4(Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general 4-by-4 matrix, which may be non-unitary.
void swapGate(Qureg qureg, int qb1, int qb2)
Performs a SWAP gate between qubit1 and qubit2.
enum pauliOpType * pauliCodes
The Pauli operators acting on each qubit, flattened over every operator.
void initStateFromAmps(Qureg qureg, qreal *reals, qreal *imags)
Initialise qureg by specifying all amplitudes.
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 MAX_NUM_REGS_APPLY_ARBITRARY_PHASE
#define toComplex(scalar)
qreal getRealAmp(Qureg qureg, long long int index)
Get the real component of the complex probability amplitude at an index in the state vector.
void controlledPhaseFlip(Qureg qureg, int idQubit1, int idQubit2)
Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate.
int numQubits
The number of qubits this operator can act on (informing its size)
int numSumTerms
The number of terms in the weighted sum, or the number of Pauli products.
Represents a diagonal complex operator on the full Hilbert state of a Qureg.
A Pauli Hamiltonian, expressed as a real-weighted sum of pauli products, and which can hence represen...
int getNumQubits(Qureg qureg)
Returns the number of qubits represented by qureg.
Complex calcInnerProduct(Qureg bra, Qureg ket)
Computes the inner product of two equal-size state vectors, given by.
void destroyQureg(Qureg qureg, QuESTEnv env)
Deallocate a Qureg, freeing its memory.
void applyParamNamedPhaseFuncOverrides(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, enum phaseFunc functionNameCode, qreal *params, int numParams, long long int *overrideInds, qreal *overridePhases, int numOverrides)
Induces a phase change upon each amplitude of qureg, determined by a named, parameterised (and potent...
@ SCALED_INVERSE_SHIFTED_NORM
void controlledMultiQubitUnitary(Qureg qureg, int ctrl, int *targs, int numTargs, ComplexMatrixN u)
Apply a general controlled multi-qubit unitary (including a global phase factor).
QVector getRandomStateVector(int numQb)
Returns a random numQb-length L2-normalised state-vector from an undisclosed distribution.
void setRandomDiagPauliHamil(PauliHamil hamil)
Populates hamil with random coefficients and a random amount number of PAULI_I and PAULI_Z operators.
void multiQubitNot(Qureg qureg, int *targs, int numTargs)
Apply a NOT (or Pauli X) gate with multiple target qubits, which has the same effect as (but is much ...
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 -th complex amplitude give...
void applyPauliSum(Qureg inQureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg outQureg)
Modifies outQureg to be the result of applying the weighted sum of Pauli products (a Hermitian but no...
QMatrix getRandomQMatrix(int dim)
Returns a dim-by-dim complex matrix, where the real and imaginary value of each element are independe...
void applyMatrixN(Qureg qureg, int *targs, int numTargs, ComplexMatrixN u)
Apply a general N-by-N matrix, which may be non-unitary, on any number of target qubits.
void applyMultiVarPhaseFunc(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, qreal *coeffs, qreal *exponents, int *numTermsPerReg)
Induces a phase change upon each amplitude of qureg, determined by a multi-variable exponential polyn...
void compactUnitary(Qureg qureg, int targetQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
void initClassicalState(Qureg qureg, long long int stateInd)
Initialise qureg into the classical state (also known as a "computational basis state") with index st...
void pauliY(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.
long long int getTwosComplement(long long int decimal, int numBits)
Returns the two's complement signed encoding of the unsigned number decimal, which must be a number b...
Represents a system of qubits.
void controlledPhaseShift(Qureg qureg, int idQubit1, int idQubit2, qreal angle)
Introduce a phase factor on state of qubits idQubit1 and idQubit2.
void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit dephasing noise.
void controlledUnitary(Qureg qureg, int controlQubit, int targetQubit, ComplexMatrix2 u)
Apply a general controlled unitary (single control, single target), which can include a global phase ...
void initDiagonalOp(DiagonalOp op, qreal *real, qreal *imag)
Overwrites the entire DiagonalOp op with the given real and imag complex elements.
void phaseShift(Qureg qureg, int targetQubit, qreal angle)
Shift the phase between and of a single qubit by a given angle.
ComplexArray stateVec
Computational state amplitudes - a subset thereof in the MPI version.
void controlledNot(Qureg qureg, int controlQubit, int targetQubit)
Apply the controlled not (single control, single target) gate, also known as the c-X,...
long long int getNumAmps(Qureg qureg)
Returns the number of complex amplitudes in a state-vector qureg.
void applyMultiVarPhaseFuncOverrides(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, qreal *coeffs, qreal *exponents, int *numTermsPerReg, long long int *overrideInds, qreal *overridePhases, int numOverrides)
Induces a phase change upon each amplitude of qureg, determined by a multi-variable exponential polyn...
long long int numElemsPerChunk
The number of the 2^numQubits amplitudes stored on each distributed node.
void initDiagonalOpFromPauliHamil(DiagonalOp op, PauliHamil hamil)
Populates the diagonal operator op to be equivalent to the given Pauli Hamiltonian hamil,...
int isDensityMatrix
Whether this instance is a density-state representation.
void pauliX(Qureg qureg, int targetQubit)
Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate.
Qureg createCloneQureg(Qureg qureg, QuESTEnv env)
Create a new Qureg which is an exact clone of the passed qureg, which can be either a state-vector or...
#define PREPARE_TEST(qureg, ref)
Prepares a density matrix in the debug state, and the reference QMatrix.
std::vector< std::vector< qcomp > > QMatrix
A complex square matrix.
qreal calcExpecPauliSum(Qureg qureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg workspace)
Computes the expected value of a sum of products of Pauli operators.
void controlledTwoQubitUnitary(Qureg qureg, int controlQubit, int targetQubit1, int targetQubit2, ComplexMatrix4 u)
Apply a general controlled two-qubit unitary (including a global phase factor).
ComplexMatrix2 toComplexMatrix2(QMatrix qm)
Returns a ComplexMatrix2 copy of QMatix qm.
void applyFullQFT(Qureg qureg)
Applies the quantum Fourier transform (QFT) to the entirety of qureg.
int numQubits
The number of qubits informing the Hilbert dimension of the Hamiltonian.
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.
std::vector< qreal > getRandomProbabilities(int numProbs)
Returns a list of random real scalars, each in [0, 1], which sum to unity.
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
qreal * real
The real values of the 2^numQubits complex elements.
void mixDensityMatrix(Qureg combineQureg, qreal otherProb, Qureg otherQureg)
Modifies combineQureg to become (1-prob)combineProb + prob otherQureg.
Qureg createQureg(int numQubits, QuESTEnv env)
Creates a state-vector Qureg object representing a set of qubits which will remain in a pure state.
void destroyPauliHamil(PauliHamil h)
Destroy a PauliHamil instance, created with either createPauliHamil() or createPauliHamilFromFile().
QMatrix getPureDensityMatrix(QVector state)
Returns a density matrix initialised into the given pure state.
void tGate(Qureg qureg, int targetQubit)
Apply the single-qubit T gate.
void multiRotateZ(Qureg qureg, int *qubits, int numQubits, qreal angle)
Apply a multi-qubit Z rotation, also known as a phase gadget, on a selected number of qubits.
void deleteFilesWithPrefixSynch(char *prefix)
Deletes all files with filename starting with prefix.
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 applyParamNamedPhaseFunc(Qureg qureg, int *qubits, int *numQubitsPerReg, int numRegs, enum bitEncoding encoding, enum phaseFunc functionNameCode, qreal *params, int numParams)
Induces a phase change upon each amplitude of qureg, determined by a named, paramaterized (and potent...
@ SCALED_INVERSE_SHIFTED_DISTANCE
void mixPauli(Qureg qureg, int qubit, qreal probX, qreal probY, qreal probZ)
Mixes a density matrix qureg to induce general single-qubit Pauli noise.
QMatrix getZeroMatrix(size_t dim)
Returns a dim-by-dim square complex matrix, initialised to all zeroes.
void hadamard(Qureg qureg, int targetQubit)
Apply the single-qubit Hadamard gate.
Represents one complex number.
void applyMatrix2(Qureg qureg, int targetQubit, ComplexMatrix2 u)
Apply a general 2-by-2 matrix, which may be non-unitary.
#define PREPARE_TEST(quregVec, quregMatr, refVec, refMatr)
Prepares the needed data structures for unit testing some operators.
void rotateZ(Qureg qureg, int targetQubit, qreal angle)
Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase s...
QVector getRandomQVector(int dim)
Returns a dim-length vector with random complex amplitudes in the square joining {-1-i,...
void multiControlledUnitary(Qureg qureg, int *controlQubits, int numControlQubits, int targetQubit, ComplexMatrix2 u)
Apply a general multiple-control single-target unitary, which can include a global phase factor.
void applyReferenceMatrix(QVector &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op)
Modifies the state-vector state to be the result of left-multiplying the multi-target operator matrix...
void initZeroState(Qureg qureg)
Initialise qureg into the zero state.
QVector getDFT(QVector in)
Returns the discrete fourier transform of vector in.
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)
Creates a density matrix Qureg object representing a set of qubits which can enter noisy and mixed st...
void applyReferenceOp(QVector &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op)
Modifies the state-vector state to be the result of applying the multi-target operator matrix op,...
void applyTrotterCircuit(Qureg qureg, PauliHamil hamil, qreal time, int order, int reps)
Applies a trotterisation of unitary evolution to qureg.
PauliHamil createPauliHamil(int numQubits, int numSumTerms)
Dynamically allocates a Hamiltonian expressed as a real-weighted sum of products of Pauli operators.
Catch::Generators::GeneratorWrapper< int * > bitsets(int numBits)
Returns a Catch2 generator of every numBits-length bit-set, in increasing lexographic order,...
qcomp getRandomComplex()
Returns a random complex number within the square closing (-1-i) and (1+i), from a distribution unifo...
void initPlusState(Qureg qureg)
Initialise qureg into the plus state.
qreal calcExpecPauliProd(Qureg qureg, int *targetQubits, enum pauliOpType *pauliCodes, int numTargets, Qureg workspace)
Computes the expected value of a product of Pauli operators.
void controlledCompactUnitary(Qureg qureg, int controlQubit, int targetQubit, Complex alpha, Complex beta)
Apply a controlled unitary (single control, single target) parameterised by two given complex scalars...
void multiStateControlledUnitary(Qureg qureg, int *controlQubits, int *controlState, int numControlQubits, int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary with multiple control qubits, conditioned upon a specific bit se...
void sqrtSwapGate(Qureg qureg, int qb1, int qb2)
Performs a sqrt SWAP gate between qubit1 and qubit2.
bitEncoding
Flags for specifying how the bits in sub-register computational basis states are mapped to indices in...
void mixMultiQubitKrausMap(Qureg qureg, int *targets, int numTargets, ComplexMatrixN *ops, int numOps)
Apply a general N-qubit Kraus map to a density matrix, as specified by at most (2N)^2 Kraus operators...
DiagonalOp createDiagonalOp(int numQubits, QuESTEnv env)
Creates a DiagonalOp representing a diagonal operator on the full Hilbert space of a Qureg.
Represents a 2x2 matrix of complex numbers.
void controlledRotateY(Qureg qureg, int controlQubit, int targetQubit, qreal angle)
Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.