91TEST_CASE(
"createCloneQureg",
"[data_structures]" ) {
93 SECTION(
"state-vector" ) {
99 REQUIRE( b.isMultithreaded == a.isMultithreaded );
100 REQUIRE( b.isGpuAccelerated == a.isGpuAccelerated );
101 REQUIRE( b.isDistributed == a.isDistributed );
103 REQUIRE( b.rank == a.rank );
104 REQUIRE( b.numNodes == a.numNodes );
105 REQUIRE( b.logNumNodes == a.logNumNodes );
107 REQUIRE( b.isDensityMatrix == a.isDensityMatrix );
108 REQUIRE( b.numQubits == a.numQubits );
109 REQUIRE( b.numAmps == a.numAmps );
110 REQUIRE( b.logNumAmps == a.logNumAmps );
112 REQUIRE( b.numAmpsPerNode == a.numAmpsPerNode );
113 REQUIRE( b.logNumAmpsPerNode == a.logNumAmpsPerNode );
114 REQUIRE( b.logNumColsPerNode == a.logNumColsPerNode );
122 SECTION(
"density-matrix" ) {
128 REQUIRE( b.isMultithreaded == a.isMultithreaded );
129 REQUIRE( b.isGpuAccelerated == a.isGpuAccelerated );
130 REQUIRE( b.isDistributed == a.isDistributed );
132 REQUIRE( b.rank == a.rank );
133 REQUIRE( b.numNodes == a.numNodes );
134 REQUIRE( b.logNumNodes == a.logNumNodes );
136 REQUIRE( b.isDensityMatrix == a.isDensityMatrix );
137 REQUIRE( b.numQubits == a.numQubits );
138 REQUIRE( b.numAmps == a.numAmps );
139 REQUIRE( b.logNumAmps == a.logNumAmps );
141 REQUIRE( b.numAmpsPerNode == a.numAmpsPerNode );
142 REQUIRE( b.logNumAmpsPerNode == a.logNumAmpsPerNode );
143 REQUIRE( b.logNumColsPerNode == a.logNumColsPerNode );
159TEST_CASE(
"createComplexMatrixN",
"[data_structures]" ) {
161 SECTION(
"correctness" ) {
163 int numQb = GENERATE( range(1,10+1) );
164 ComplexMatrixN m = createComplexMatrixN(numQb);
169 destroyComplexMatrixN(m);
171 SECTION(
"input validation" ) {
173 SECTION(
"number of qubits" ) {
175 int numQb = GENERATE( -1, 0 );
176 REQUIRE_THROWS_WITH( createComplexMatrixN(numQb), ContainsSubstring(
"must target one or more qubits") );
262 int minNumQb =
calcLog2(env.numNodes);
266 SECTION(
"correctness" ) {
269 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
270 DiagonalOp op = createDiagonalOp(numQb, env);
273 REQUIRE( op.numQubits == numQb );
274 REQUIRE( op.numElemsPerNode == (1LL << numQb) / (op.isDistributed? env.numNodes : 1) );
275 REQUIRE( op.cpuElems != NULL );
282 destroyDiagonalOp(op, env);
284 SECTION(
"input validation" ) {
286 SECTION(
"number of qubits" ) {
288 int numQb = GENERATE( -1, 0 );
289 REQUIRE_THROWS_WITH( createDiagonalOp(numQb, env), ContainsSubstring(
"must target one or more qubits") );
291 SECTION(
"number of elements" ) {
294 int maxQb = (int)
calcLog2(SIZE_MAX);
295 REQUIRE_THROWS_WITH( createDiagonalOp(maxQb+1, env),
296 ContainsSubstring(
"the matrix would contain more elements") && ContainsSubstring(
"than the maximum which can be addressed by the qindex type") );
312 SECTION(
"available memory" ) {
769TEST_CASE(
"createSubDiagonalOp",
"[data_structures]" ) {
771 SECTION(
"correctness" ) {
773 int numQb = GENERATE( range(1,10+1) );
774 SubDiagonalOp op = createSubDiagonalOp(numQb);
779 destroySubDiagonalOp(op);
781 SECTION(
"input validation" ) {
783 SECTION(
"number of qubits" ) {
785 int numQb = GENERATE( -1, 0 );
786 REQUIRE_THROWS_WITH( createSubDiagonalOp(numQb), ContainsSubstring(
"must target one or more qubits") );
789 REQUIRE_THROWS_WITH( createSubDiagonalOp(numQb),
790 ContainsSubstring(
"the matrix would contain more elements") &&
791 ContainsSubstring(
"than the maximum which can be addressed by the qindex type") );
1211 SECTION(
"correctness" ) {
1214 int numQb = GENERATE_COPY( range(minNumQb, minNumQb+10) );
1225 for (n=0; n<op.numElemsPerNode; n++)
1226 op.cpuElems[n] = qcomp(n, -2*n);
1231 for (
long long int i=0; i<qureg.numAmpsPerNode; i++)
1232 qureg.cpuAmps[i] = qcomp(1,1);
1233 copyStateToGPU(qureg);
1236 applyDiagonalOp(qureg, op);
1237 copyStateFromGPU(qureg);
1238 for (n=0; n<qureg.numAmpsPerNode; n++) {
1239 REQUIRE( real(qureg.cpuAmps[n]) == 3*n );
1240 REQUIRE( imag(qureg.cpuAmps[n]) == -n );