387 int maxInd = vec.numAmps;
390 SECTION(
"correctness" ) {
392 SECTION(
"state-vector" ) {
395 int startInd = GENERATE_COPY( range(0,maxInd) );
396 int numAmps = GENERATE_COPY( range(0,1+maxInd-startInd) );
403 for (
int i=0; i<numAmps; i++)
404 vecRef[startInd+i] = amps[i];
409 SECTION(
"input validation" ) {
411 SECTION(
"start index" ) {
413 int startInd = GENERATE_COPY( -1, maxInd );
415 REQUIRE_THROWS_WITH(
setQuregAmps(vec, startInd, amps.data(), numAmps), ContainsSubstring(
"starting basis state index") );
418 SECTION(
"number of amplitudes" ) {
422 int numAmps = GENERATE_COPY( -1, maxInd+1 );
423 REQUIRE_THROWS_WITH(
setQuregAmps(vec, startInd, amps.data(), numAmps), ContainsSubstring(
"number of amplitudes") );
426 startInd = maxInd - 1;
428 REQUIRE_THROWS_WITH(
setQuregAmps(vec, startInd, amps.data(), numAmps), ContainsSubstring(
"implies an end index") );
430 SECTION(
"density-matrix" ) {
433 REQUIRE_THROWS_WITH(
setQuregAmps(mat, 0, amps.data(), 0), ContainsSubstring(
"Expected a statevector Qureg but received a density matrix") );
596TEST_CASE(
"setWeightedQureg",
"[state_initialisations]" ) {
598 SECTION(
"correctness" ) {
601 GENERATE( range(0,10) );
607 SECTION(
"state-vector" ) {
613 for (
int j=0; j<vecA.numAmpsPerNode; j++) {
618 copyStateToGPU(vecA); copyStateToGPU(vecB); copyStateToGPU(vecC);
628 Complex facA; facA.real = real(numA); facA.imag = imag(numA);
629 Complex facB; facB.real = real(numB); facB.imag = imag(numB);
630 Complex facC; facC.real = real(numC); facC.imag = imag(numC);
633 setWeightedQureg(facA, vecA, facB, vecB, facC, vecC);
634 refOut = numA*refA + numB*refB + numC*refC;
643 setWeightedQureg(facB, vecB, facC, vecC, facA, vecC);
644 refOut = numB*refB + numC*refC + numA*refC;
645 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
652 setWeightedQureg(facC, vecC, facB, vecB, facA, vecC);
653 refOut = numC*refC + numB*refB + numA*refC;
654 REQUIRE(
areEqual(vecC, refOut, 10*REAL_EPS) );
661 setWeightedQureg(facA, vecC, facB, vecC, facC, vecC);
662 refOut = numA*refC + numB*refC + numC*refC;
663 REQUIRE(
areEqual(vecC, refOut, 1E3*REAL_EPS) );
737 SECTION(
"input validation" ) {
739 SECTION(
"qureg types" ) {
743 Complex f; f.real = 0; f.imag = 0;
746 REQUIRE_THROWS_WITH( setWeightedQureg(f, mat, f, vec, f, vec), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
747 REQUIRE_THROWS_WITH( setWeightedQureg(f, vec, f, mat, f, vec), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
748 REQUIRE_THROWS_WITH( setWeightedQureg(f, vec, f, vec, f, mat), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
751 REQUIRE_THROWS_WITH( setWeightedQureg(f, vec, f, mat, f, mat), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
752 REQUIRE_THROWS_WITH( setWeightedQureg(f, mat, f, vec, f, mat), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
753 REQUIRE_THROWS_WITH( setWeightedQureg(f, mat, f, mat, f, vec), ContainsSubstring(
"Cannot superpose a density matrix. All quregs must be statevectors") );
758 SECTION(
"qureg dimensions" ) {
764 Complex f; f.real = 0; f.imag = 0;
767 REQUIRE_THROWS_WITH( setWeightedQureg(f, vecA, f, vecB, f, vecB), ContainsSubstring(
"differing numbers of qubits") );
768 REQUIRE_THROWS_WITH( setWeightedQureg(f, vecB, f, vecA, f, vecB), ContainsSubstring(
"differing numbers of qubits") );
769 REQUIRE_THROWS_WITH( setWeightedQureg(f, vecB, f, vecB, f, vecA), ContainsSubstring(
"differing numbers of qubits") );