test_state_initialisations.cpp
Go to the documentation of this file.
1 
2 #include "catch.hpp"
3 #include "QuEST.h"
4 #include "utilities.hpp"
5 
6 /* allows concise use of Contains in catch's REQUIRE_THROWS_WITH */
7 using Catch::Matchers::Contains;
8 
9 
10 
15 TEST_CASE( "cloneQureg", "[state_initialisations]" ) {
16 
19 
20  SECTION( "correctness" ) {
21 
22  SECTION( "state-vector" ) {
23 
25 
26  // make sure states start differently
27  initDebugState(vec1);
28  initBlankState(vec2);
29  REQUIRE( !areEqual(vec1, vec2) );
30 
31  // make sure vec2 is changed
32  QVector copy1 = toQVector(vec1);
33  cloneQureg(vec2, vec1);
34  REQUIRE( areEqual(vec1, vec2) );
35 
36  // make sure vec1 unaffected
37  REQUIRE( areEqual(vec1, copy1) );
38 
39  destroyQureg(vec2, QUEST_ENV);
40  }
41  SECTION( "density-matrix" ) {
42 
44 
45  // make sure states start differently
46  initDebugState(mat1);
47  initBlankState(mat2);
48  REQUIRE( !areEqual(mat1, mat2) );
49 
50  // make sure vec2 is changed
51  QMatrix copy1 = toQMatrix(mat1);
52  cloneQureg(mat2, mat1);
53  REQUIRE( areEqual(mat1, mat2) );
54 
55  // make sure vec1 unaffected
56  REQUIRE( areEqual(mat1, copy1) );
57 
58  destroyQureg(mat2, QUEST_ENV);
59  }
60  }
61  SECTION( "input validation" ) {
62 
63  SECTION( "qureg type" ) {
64 
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") );
67  }
68  SECTION( "qureg dimensions" ) {
69 
72 
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") );
75 
76  destroyQureg(vec3, QUEST_ENV);
77  destroyQureg(mat3, QUEST_ENV);
78  }
79  }
80  destroyQureg(vec1, QUEST_ENV);
81  destroyQureg(mat1, QUEST_ENV);
82 }
83 
84 
85 
90 TEST_CASE( "initBlankState", "[state_initialisations]" ) {
91 
94 
95  SECTION( "correctness" ) {
96 
97  SECTION( "state-vector" ) {
98 
99  initBlankState(vec);
100  REQUIRE( areEqual(vec, QVector(1<<NUM_QUBITS)) );
101  }
102  SECTION( "density-matrix" ) {
103 
104  initBlankState(mat);
105  REQUIRE( areEqual(mat, getZeroMatrix(1<<NUM_QUBITS)) );
106  }
107  }
108  SECTION( "input validation" ) {
109 
110  // no user validation
111  SUCCEED( );
112  }
113  destroyQureg(vec, QUEST_ENV);
114  destroyQureg(mat, QUEST_ENV);
115 }
116 
117 
118 
123 TEST_CASE( "initClassicalState", "[state_initialisations]" ) {
124 
127 
128  SECTION( "correctness" ) {
129 
130  int numInds = (1<<NUM_QUBITS);
131  int ind = GENERATE_COPY( range(0,numInds) );
132 
133  SECTION( "state-vector" ) {
134 
135  initClassicalState(vec, ind);
136  QVector vecRef = QVector(1<<NUM_QUBITS);
137  vecRef[ind] = 1;
138  REQUIRE( areEqual(vec, vecRef) );
139  }
140  SECTION( "density-matrix" ) {
141 
142  initClassicalState(mat, ind);
143  QMatrix matRef = getZeroMatrix(1<<NUM_QUBITS);
144  matRef[ind][ind] = 1;
145  REQUIRE( areEqual(mat, matRef) );
146  }
147  }
148  SECTION( "input validation" ) {
149 
150  SECTION( "state index" ) {
151 
152  int ind = GENERATE( -1, (1<<NUM_QUBITS) );
153  REQUIRE_THROWS_WITH( initClassicalState(vec, ind), Contains("Invalid state index") );
154  }
155  }
156  destroyQureg(vec, QUEST_ENV);
157  destroyQureg(mat, QUEST_ENV);
158 }
159 
160 
161 
166 TEST_CASE( "initPlusState", "[state_initialisations]" ) {
167 
170 
171  SECTION( "correctness" ) {
172 
173  SECTION( "state-vector" ) {
174 
175  // |+> = 1/sqrt(N^2) sum_i |i>
176  // = 1/sqrt(N^2) {1, ..., 1}
177  initPlusState(vec);
178  QVector vecRef = QVector(1<<NUM_QUBITS);
179  for (size_t i=0; i<vecRef.size(); i++)
180  vecRef[i] = 1./sqrt(pow(2,NUM_QUBITS));
181  REQUIRE( areEqual(vec, vecRef) );
182  }
183  SECTION( "density-matrix" ) {
184 
185  // |+><+| = 1/sqrt(N^2) sum_i |i> 1/sqrt(N^2) sum_j <j|
186  // = 1/(N^2) sum_{ij} |i><j|
187  // = 1/(N^2) {{1, ..., 1}, ...}
188  initPlusState(mat);
189  QMatrix matRef = getZeroMatrix(1<<NUM_QUBITS);
190  for (size_t i=0; i<matRef.size(); i++)
191  for (size_t j=0; j<matRef.size(); j++)
192  matRef[i][j] = 1./pow(2, NUM_QUBITS);
193  REQUIRE( areEqual(mat, matRef) );
194  }
195  }
196  SECTION( "input validation" ) {
197 
198  // no user validation
199  SUCCEED( );
200  }
201  destroyQureg(vec, QUEST_ENV);
202  destroyQureg(mat, QUEST_ENV);
203 }
204 
205 
206 
211 TEST_CASE( "initPureState", "[state_initialisations]" ) {
212 
215 
216  SECTION( "correctness" ) {
217 
218  SECTION( "state-vector" ) {
219 
220  /* state-vector version just performs cloneQureg */
221 
223 
224  // make sure states start differently
225  initDebugState(vec1);
226  initBlankState(vec2);
227  REQUIRE( !areEqual(vec1, vec2) );
228 
229  // make sure vec2 is overwritten with vec1
230  QVector copy1 = toQVector(vec1);
231  initPureState(vec2, vec1);
232  REQUIRE( areEqual(vec1, vec2) );
233 
234  // make sure vec1 was not modified
235  REQUIRE( areEqual(vec1, copy1) );
236 
237  destroyQureg(vec2, QUEST_ENV);
238  }
239  SECTION( "density-matrix" ) {
240 
241  /* density matrix version initialises matrix in |pure><pure| */
242 
243  initDebugState(vec1); // |vec1> = sum_i a_i |i>
244  QVector copy1 = toQVector(vec1);
245 
246  // make sure mat1 is modified correctly
247  initBlankState(mat1);
248  initPureState(mat1, vec1); // mat1 = |vec1><vec1| = sum_{ij} a_i a_j* |i><j|
249 
250  QMatrix matRef = getZeroMatrix(1<<NUM_QUBITS);
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]);
254  REQUIRE( areEqual(mat1, matRef) );
255 
256  // make sure vec1 was not modified
257  REQUIRE( areEqual(vec1, copy1) );
258  }
259  }
260  SECTION( "input validation" ) {
261 
262  SECTION( "qureg types" ) {
263 
264  // density matrix as second arg is illegal (regardless of first arg)
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") );
267  }
268  SECTION( "qureg dimensions" ) {
269 
270  Qureg vec2 = createQureg(NUM_QUBITS + 1, QUEST_ENV);
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") );
273  destroyQureg(vec2, QUEST_ENV);
274  }
275  }
276  destroyQureg(vec1, QUEST_ENV);
277  destroyQureg(mat1, QUEST_ENV);
278 }
279 
280 
281 
286 TEST_CASE( "initStateFromAmps", "[state_initialisations]" ) {
287 
290 
291  SECTION( "correctness" ) {
292 
293  SECTION( "state-vector" ) {
294 
295  // create random (unnormalised) vector
296  QVector vecRef = getRandomQVector(1<<NUM_QUBITS);
297 
298  qreal ampsRe[vec.numAmpsTotal];
299  qreal ampsIm[vec.numAmpsTotal];
300  for (size_t i=0; i<vecRef.size(); i++) {
301  ampsRe[i] = real(vecRef[i]);
302  ampsIm[i] = imag(vecRef[i]);
303  }
304 
305  initStateFromAmps(vec, ampsRe, ampsIm);
306  REQUIRE( areEqual(vec, vecRef) );
307  }
308  SECTION( "density-matrix" ) {
309 
310  // create random (unnormalised) matrix
311  QMatrix matRef = getRandomQMatrix(1<<NUM_QUBITS);
312 
313  qreal ampsRe[mat.numAmpsTotal];
314  qreal ampsIm[mat.numAmpsTotal];
315 
316  // populate column-wise
317  long long int i=0;
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]);
322  i++;
323  }
324  }
325 
326  initStateFromAmps(mat, ampsRe, ampsIm);
327  REQUIRE( areEqual(mat, matRef) );
328  }
329  }
330  destroyQureg(vec, QUEST_ENV);
331  destroyQureg(mat, QUEST_ENV);
332 }
333 
334 
335 
340 TEST_CASE( "initZeroState", "[state_initialisations]" ) {
341 
344 
345  SECTION( "correctness" ) {
346 
347  SECTION( "state-vector" ) {
348 
349  initBlankState(vec);
350  initZeroState(vec);
351 
352  QVector refVec = QVector(vec.numAmpsTotal);
353  refVec[0] = 1;
354  REQUIRE( areEqual(vec, refVec) );
355  }
356  SECTION( "density-matrix" ) {
357 
358  initBlankState(mat);
359  initZeroState(mat);
360 
361  QMatrix refMat = getZeroMatrix(1<<mat.numQubitsRepresented);
362  refMat[0][0] = 1;
363  REQUIRE( areEqual(mat, refMat) );
364  }
365  }
366  SECTION( "input validation" ) {
367 
368  // no input validation
369  SUCCEED( );
370  }
371  destroyQureg(vec, QUEST_ENV);
372  destroyQureg(mat, QUEST_ENV);
373 }
374 
375 
376 
381 TEST_CASE( "setAmps", "[state_initialisations]" ) {
382 
384 
385  int maxInd = vec.numAmpsTotal;
386  qreal reals[maxInd];
387  qreal imags[maxInd];
388 
389  SECTION( "correctness" ) {
390 
391  SECTION( "state-vector" ) {
392 
393  // all valid number of amplitudes and offsets
394  int startInd = GENERATE_COPY( range(0,maxInd) );
395  int numAmps = GENERATE_COPY( range(0,1+maxInd-startInd) ); // upper-bound allows all amps specified
396 
397  // generate random amplitudes
398  for (int i=0; i<numAmps; i++) {
399  reals[i] = getRandomReal(-5,5);
400  imags[i] = getRandomReal(-5,5);
401  }
402 
403  // check both specified and un-specified amplitudes are correctly handled
404  initDebugState(vec);
405  QVector vecRef = toQVector(vec);
406 
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;
410 
411  REQUIRE( areEqual(vec, vecRef) );
412  }
413  }
414  SECTION( "input validation" ) {
415 
416  SECTION( "start index" ) {
417 
418  int startInd = GENERATE_COPY( -1, maxInd );
419  int numAmps = 0;
420  REQUIRE_THROWS_WITH( setAmps(vec, startInd, reals, imags, numAmps), Contains("Invalid amplitude index") );
421  }
422 
423  SECTION( "number of amplitudes" ) {
424 
425  // independent
426  int startInd = 0;
427  int numAmps = GENERATE_COPY( -1, maxInd+1 );
428  REQUIRE_THROWS_WITH( setAmps(vec, startInd, reals, imags, numAmps), Contains("Invalid number of amplitudes") );
429 
430  // invalid considering start-index
431  startInd = maxInd - 1;
432  numAmps = 2;
433  REQUIRE_THROWS_WITH( setAmps(vec, startInd, reals, imags, numAmps), Contains("More amplitudes given than exist") );
434  }
435  SECTION( "density-matrix" ) {
436 
438  REQUIRE_THROWS_WITH( setAmps(mat, 0, reals, imags, 0), Contains("valid only for state-vectors") );
439  destroyQureg(mat, QUEST_ENV);
440  }
441  }
442  destroyQureg(vec, QUEST_ENV);
443 }
444 
445 
446 
451 TEST_CASE( "setWeightedQureg", "[state_initialisations]" ) {
452 
453  SECTION( "correctness" ) {
454 
455  // repeat each test below 10 times
456  GENERATE( range(0,10) );
457 
458  /* note tolerance in areEqual increases with tests, since
459  * small differences propogate in vecC which is not re-initialised
460  */
461 
462  SECTION( "state-vector" ) {
463 
464  // make three random vectors
468  for (int j=0; j<vecA.numAmpsPerChunk; j++) {
469  vecA.stateVec.real[j] = getRandomReal(-5,5); vecA.stateVec.imag[j] = getRandomReal(-5,5);
470  vecB.stateVec.real[j] = getRandomReal(-5,5); vecB.stateVec.imag[j] = getRandomReal(-5,5);
471  vecC.stateVec.real[j] = getRandomReal(-5,5); vecC.stateVec.imag[j] = getRandomReal(-5,5);
472  }
473  copyStateToGPU(vecA); copyStateToGPU(vecB); copyStateToGPU(vecC);
474  QVector refA = toQVector(vecA);
475  QVector refB = toQVector(vecB);
476  QVector refC = toQVector(vecC);
477  QVector refOut;
478 
479  // get three random factors
480  qcomp numA = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
481  qcomp numB = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
482  qcomp numC = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
483  Complex facA = toComplex(numA);
484  Complex facB = toComplex(numB);
485  Complex facC = toComplex(numC);
486 
487  // check out-qureg is correct, when all quregs are unique...
488  setWeightedQureg(facA, vecA, facB, vecB, facC, vecC);
489  refOut = numA*refA + numB*refB + numC*refC;
490  REQUIRE( areEqual(vecC, refOut) );
491 
492  // ... and that other qureg's aren't modified
493  REQUIRE( areEqual(vecA, refA) );
494  REQUIRE( areEqual(vecB, refB) );
495 
496  // check quregOut correct, when it's also qureg2
497  refC = toQVector(vecC);
498  setWeightedQureg(facB, vecB, facC, vecC, facA, vecC);
499  refOut = numB*refB + numC*refC + numA*refC;
500  REQUIRE( areEqual(vecC, refOut, 10*REAL_EPS) );
501 
502  // ... and that the remaining qureg is not modified
503  REQUIRE( areEqual(vecB, refB) );
504 
505  // check quregOut correct, when it's also qureg1
506  refC = toQVector(vecC);
507  setWeightedQureg(facC, vecC, facB, vecB, facA, vecC);
508  refOut = numC*refC + numB*refB + numA*refC;
509  REQUIRE( areEqual(vecC, refOut, 10*REAL_EPS) );
510 
511  // ... and that the remaining qureg is not modified
512  REQUIRE( areEqual(vecB, refB) );
513 
514  // check quregOut is correct when it's both input quregs
515  refC = toQVector(vecC);
516  setWeightedQureg(facA, vecC, facB, vecC, facC, vecC);
517  refOut = numA*refC + numB*refC + numC*refC;
518  REQUIRE( areEqual(vecC, refOut, 1E3*REAL_EPS) );
519 
520  // cleanup
521  destroyQureg(vecA, QUEST_ENV);
522  destroyQureg(vecB, QUEST_ENV);
523  destroyQureg(vecC, QUEST_ENV);
524  }
525  SECTION( "density-matrix" ) {
526 
527  // make three random matrices
531  for (int j=0; j<matA.numAmpsPerChunk; j++) {
532  matA.stateVec.real[j] = getRandomReal(-5,5); matA.stateVec.imag[j] = getRandomReal(-5,5);
533  matB.stateVec.real[j] = getRandomReal(-5,5); matB.stateVec.imag[j] = getRandomReal(-5,5);
534  matC.stateVec.real[j] = getRandomReal(-5,5); matC.stateVec.imag[j] = getRandomReal(-5,5);
535  }
536  copyStateToGPU(matA); copyStateToGPU(matB); copyStateToGPU(matC);
537  QMatrix refA = toQMatrix(matA);
538  QMatrix refB = toQMatrix(matB);
539  QMatrix refC = toQMatrix(matC);
540  QMatrix refOut;
541 
542  // get three random factors
543  qcomp numA = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
544  qcomp numB = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
545  qcomp numC = getRandomReal(-5,5) + getRandomReal(-5,5) * (qcomp) 1i;
546  Complex facA = toComplex(numA);
547  Complex facB = toComplex(numB);
548  Complex facC = toComplex(numC);
549 
550  // check out-qureg is correct, when all quregs are unique...
551  setWeightedQureg(facA, matA, facB, matB, facC, matC);
552  refOut = numA*refA + numB*refB + numC*refC;
553  REQUIRE( areEqual(matC, refOut) );
554 
555  // ... and that other qureg's aren't modified
556  REQUIRE( areEqual(matA, refA) );
557  REQUIRE( areEqual(matB, refB) );
558 
559  // check quregOut correct, when it's also qureg2
560  refC = toQMatrix(matC);
561  setWeightedQureg(facB, matB, facC, matC, facA, matC);
562  refOut = numB*refB + numC*refC + numA*refC;
563  REQUIRE( areEqual(matC, refOut, 10*REAL_EPS) );
564 
565  // ... and that the remaining qureg is not modified
566  REQUIRE( areEqual(matB, refB) );
567 
568  // check quregOut correct, when it's also qureg1
569  refC = toQMatrix(matC);
570  setWeightedQureg(facC, matC, facB, matB, facA, matC);
571  refOut = numC*refC + numB*refB + numA*refC;
572  REQUIRE( areEqual(matC, refOut, 1E2*REAL_EPS) );
573 
574  // ... and that the remaining qureg is not modified
575  REQUIRE( areEqual(matB, refB) );
576 
577  // check quregOut is correct when it's both input quregs
578  refC = toQMatrix(matC);
579  setWeightedQureg(facA, matC, facB, matC, facC, matC);
580  refOut = numA*refC + numB*refC + numC*refC;
581  REQUIRE( areEqual(matC, refOut, 1E3*REAL_EPS) );
582 
583  // cleanup
584  destroyQureg(matA, QUEST_ENV);
585  destroyQureg(matB, QUEST_ENV);
586  destroyQureg(matC, QUEST_ENV);
587  }
588  }
589  SECTION( "input validation" ) {
590 
591  SECTION( "qureg types" ) {
592 
595  Complex f = {.real=0, .imag=0};
596 
597  // two state-vecs, one density-matrix
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") );
601 
602  // one state-vec, two 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") );
606 
607  destroyQureg(vec, QUEST_ENV);
608  destroyQureg(mat, QUEST_ENV);
609  }
610  SECTION( "qureg dimensions" ) {
611 
613  Qureg vecB = createQureg(NUM_QUBITS + 1, QUEST_ENV);
616  Complex f = {.real=0, .imag=0};
617 
618  // state-vecs
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") );
622 
623  // density-matrices
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") );
627 
628  destroyQureg(vecA, QUEST_ENV);
629  destroyQureg(vecB, QUEST_ENV);
630  destroyQureg(matA, QUEST_ENV);
631  destroyQureg(matB, QUEST_ENV);
632  }
633  }
634 }
635 
void initBlankState(Qureg qureg)
Initialises a qureg to have all-zero-amplitudes.
Definition: QuEST.c:119
QuESTEnv QUEST_ENV
The global QuESTEnv instance, to be created and destroyed once in this main(), so that the MPI enviro...
Definition: main.cpp:20
void initPureState(Qureg qureg, Qureg pure)
Initialise qureg into to a given pure state of an equivalent Hilbert dimension.
Definition: QuEST.c:145
#define NUM_QUBITS
The default number of qubits in the registers created for unit testing (both statevectors and density...
Definition: utilities.hpp:36
qreal getRandomReal(qreal min, qreal max)
Returns a random real between min (inclusive) and max (exclusive), from the uniform distribution.
Definition: utilities.cpp:421
void cloneQureg(Qureg targetQureg, Qureg copyQureg)
Overwrite the amplitudes of targetQureg with those from copyQureg.
Definition: QuEST.c:164
#define qreal
QMatrix toQMatrix(ComplexMatrix2 src)
Returns a copy of the given 2-by-2 matrix.
Definition: utilities.cpp:1044
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.
Definition: QuEST.c:1021
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...
Definition: QuEST.c:1037
std::vector< qcomp > QVector
A complex vector, which can be zero-initialised with QVector(numAmps).
Definition: utilities.hpp:60
QVector toQVector(Qureg qureg)
Returns an equal-size copy of the given state-vector qureg.
Definition: utilities.cpp:1113
long long int numAmpsPerChunk
Number of probability amplitudes held in stateVec by this process In the non-MPI version,...
Definition: QuEST.h:332
#define qcomp
void initStateFromAmps(Qureg qureg, qreal *reals, qreal *imags)
Initialise qureg by specifying all amplitudes.
Definition: QuEST.c:157
void copyStateToGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from RAM (qureg.stateVec) to VRAM / GPU...
Definition: QuEST_cpu.c:42
#define toComplex(scalar)
void destroyQureg(Qureg qureg, QuESTEnv env)
Deallocate a Qureg, freeing its memory.
Definition: QuEST.c:77
void initDebugState(Qureg qureg)
Initialises qureg to be in the un-normalised, non-physical state with with -th complex amplitude give...
Definition: QuEST.c:1578
QMatrix getRandomQMatrix(int dim)
Returns a dim-by-dim complex matrix, where the real and imaginary value of each element are independe...
Definition: utilities.cpp:379
void initClassicalState(Qureg qureg, long long int stateInd)
Initialise qureg into the classical state (also known as a "computational basis state") with index st...
Definition: QuEST.c:134
Represents a system of qubits.
Definition: QuEST.h:322
ComplexArray stateVec
Computational state amplitudes - a subset thereof in the MPI version.
Definition: QuEST.h:341
std::vector< std::vector< qcomp > > QMatrix
A complex square matrix.
Definition: utilities.hpp:49
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
Definition: QuEST.h:327
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
Definition: QuEST.h:334
qreal real
Definition: QuEST.h:105
Qureg createQureg(int numQubits, QuESTEnv env)
Creates a state-vector Qureg object representing a set of qubits which will remain in a pure state.
Definition: QuEST.c:36
QMatrix getZeroMatrix(size_t dim)
Returns a dim-by-dim square complex matrix, initialised to all zeroes.
Definition: utilities.cpp:153
Represents one complex number.
Definition: QuEST.h:103
QVector getRandomQVector(int dim)
Returns a dim-length vector with random complex amplitudes in the square joining {-1-i,...
Definition: utilities.cpp:435
void initZeroState(Qureg qureg)
Initialise qureg into the zero state.
Definition: QuEST.c:113
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...
Definition: utilities.cpp:398
Qureg createDensityQureg(int numQubits, QuESTEnv env)
Creates a density matrix Qureg object representing a set of qubits which can enter noisy and mixed st...
Definition: QuEST.c:50
void initPlusState(Qureg qureg)
Initialise qureg into the plus state.
Definition: QuEST.c:125
TEST_CASE("cloneQureg", "[state_initialisations]")