Functions used in the unit testing. These are mostly unoptimised, analytic implementations of the complex linear algebra that QuEST ultimately effects on quantum states. These are not part of the QuEST API, and require C++14. More...
Typedefs | |
typedef std::vector< std::vector< qcomp > > | QMatrix |
A complex square matrix. More... | |
typedef std::vector< qcomp > | QVector |
A complex vector, which can be zero-initialised with QVector(numAmps). More... | |
Functions | |
void | applyReferenceMatrix (QMatrix &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op) |
Modifies the density matrix state to be the result of left-multiplying the multi-target operator matrix op , with the specified control and target qubits (in ctrls and targs respectively). More... | |
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 op , with the specified control and target qubits (in ctrls and targs respectively). More... | |
void | applyReferenceOp (QMatrix &state, int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op) |
Modifies the density matrix state to be the result of applying the multi-target operator matrix op , with the specified control and target qubits (in ctrls and targs respectively). More... | |
void | applyReferenceOp (QMatrix &state, int *ctrls, int numCtrls, int targ1, int targ2, QMatrix op) |
Modifies the density matrix state to be the result of applying the two-target operator matrix op , with the specified control qubits (in ctrls ). More... | |
void | applyReferenceOp (QMatrix &state, int *ctrls, int numCtrls, int target, QMatrix op) |
Modifies the density matrix state to be the result of applying the single-target operator matrix op , with the specified control qubits (in ctrls ). More... | |
void | applyReferenceOp (QMatrix &state, int *targs, int numTargs, QMatrix op) |
Modifies the density matrix state to be the result of applying the multi-target operator matrix op , with no control qubits. More... | |
void | applyReferenceOp (QMatrix &state, int ctrl, int *targs, int numTargs, QMatrix op) |
Modifies the density matrix state to be the result of applying the multi-target operator matrix op , with a single control qubit ctrl . More... | |
void | applyReferenceOp (QMatrix &state, int ctrl, int targ, QMatrix op) |
Modifies the density matrix state to be the result of applying the single-control single-target operator matrix op . More... | |
void | applyReferenceOp (QMatrix &state, int ctrl, int targ1, int targ2, QMatrix op) |
Modifies the density matrix state to be the result of applying the two-target operator matrix op , with a single control qubit ctrl . More... | |
void | applyReferenceOp (QMatrix &state, int targ, QMatrix op) |
Modifies the density matrix state to be the result of applying the single-target operator matrix op , with no control qubit. More... | |
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 , with the specified control and target qubits (in ctrls and targs respectively). More... | |
void | applyReferenceOp (QVector &state, int *ctrls, int numCtrls, int targ1, int targ2, QMatrix op) |
Modifies the state-vector state to be the result of applying the two-target operator matrix op , with the specified control qubits (in ctrls ). More... | |
void | applyReferenceOp (QVector &state, int *ctrls, int numCtrls, int target, QMatrix op) |
Modifies the state-vector state to be the result of applying the single-target operator matrix op , with the specified control qubits (in ctrls ). More... | |
void | applyReferenceOp (QVector &state, int *targs, int numTargs, QMatrix op) |
Modifies the state-vector state to be the result of applying the multi-target operator matrix op , with no contorl qubits. More... | |
void | applyReferenceOp (QVector &state, int ctrl, int *targs, int numTargs, QMatrix op) |
Modifies the state-vector state to be the result of applying the multi-target operator matrix op , with a single control qubit (ctrl ) This updates state under. More... | |
void | applyReferenceOp (QVector &state, int ctrl, int targ, QMatrix op) |
Modifies the state-vector state to be the result of applying the single-target operator matrix op , with a single control qubit (ctrl ). More... | |
void | applyReferenceOp (QVector &state, int ctrl, int targ1, int targ2, QMatrix op) |
Modifies the state-vector state to be the result of applying the two-target operator matrix op , with a single control qubit (ctrl ). More... | |
void | applyReferenceOp (QVector &state, int targ, QMatrix op) |
Modifies the state-vector state to be the result of applying the single-target operator matrix op , with no contorl qubits. More... | |
bool | areEqual (QMatrix a, QMatrix b) |
Returns true if the absolute value of the difference between every amplitude in matrices a and b is less than REAL_EPS . More... | |
bool | areEqual (Qureg qureg, QMatrix matr) |
Performs a hardware-agnostic comparison of density-matrix qureg to matr , checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision. More... | |
bool | areEqual (Qureg qureg, QMatrix matr, qreal precision) |
Performs a hardware-agnostic comparison of density-matrix qureg to matr , checking whether the difference between the real and imaginary components of every amplitude is smaller than precision . More... | |
bool | areEqual (Qureg qureg, QVector vec) |
Performs a hardware-agnostic comparison of state-vector qureg to vec , checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision. More... | |
bool | areEqual (Qureg qureg, QVector vec, qreal precision) |
Performs a hardware-agnostic comparison of state-vector qureg to vec , checking whether the difference between the real and imaginary components of every amplitude is smaller than precision . More... | |
bool | areEqual (Qureg qureg1, Qureg qureg2) |
Performs a hardware-agnostic comparison of the given quregs, checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision. More... | |
bool | areEqual (Qureg qureg1, Qureg qureg2, qreal precision) |
Performs a hardware-agnostic comparison of the given quregs, checking whether the difference between the real and imaginary components of every amplitude is smaller than precision . More... | |
bool | areEqual (QVector a, QVector b) |
Returns true if the absolute value of the difference between every amplitude in vectors a and b is less than REAL_EPS . More... | |
bool | areEqual (QVector vec, qreal *reals, qreal *imags) |
Returns true if the absolute value of the difference between every element in vec and those implied by reals and imags , is less than REAL_EPS . More... | |
CatchGen< int * > | bitsets (int numBits) |
Returns a Catch2 generator of every numBits-length bit-set, in increasing lexographic order, where left-most (zero index) bit is treated as LEAST significant (opposite typical convention). More... | |
unsigned int | calcLog2 (long unsigned int res) |
Returns log2 of numbers which must be gauranteed to be 2^n. More... | |
QMatrix | getConjugateTranspose (QMatrix a) |
Returns the conjugate transpose of the complex square matrix a . More... | |
QMatrix | getExponentialOfDiagonalMatrix (QMatrix a) |
Returns the matrix exponential of a diagonal, square, complex matrix. More... | |
QMatrix | getExponentialOfPauliMatrix (qreal angle, QMatrix a) |
Returns the matrix exponential of a kronecker product of pauli matrices (or of any involutory matrices), with exponent factor (-i angle / 2). More... | |
QMatrix | getFullOperatorMatrix (int *ctrls, int numCtrls, int *targs, int numTargs, QMatrix op, int numQubits) |
Takes a 2^numTargs-by-2^ op and a returns a 2^numQubits-by-2^ where op is controlled on the given ctrls qubits. More... | |
QMatrix | getIdentityMatrix (size_t dim) |
Returns a dim-by-dim identity matrix. More... | |
QMatrix | getKetBra (QVector ket, QVector bra) |
Returns the matrix |ket>< with ith-jth element ket(i) conj(bra(j) ), since |ket>< sum_i a_i|i> sum_j b_j* <j| = sum_{ij} a_i b_j* |i><j|. More... | |
QMatrix | getKroneckerProduct (QMatrix a, QMatrix b) |
Returns the kronecker product of a and b , where a and b are square but possibly differently-sized complex matrices. More... | |
QVector | getNormalised (QVector vec) |
Returns an L2-normalised copy of vec , using Kahan summation for improved accuracy. More... | |
QMatrix | getRandomDensityMatrix (int numQb) |
Returns a random numQb-by- matrix, from an undisclosed distribution, in a very mixed state. More... | |
int | getRandomInt (int min, int max) |
Returns a random integer between min (inclusive) and max (exclusive), from the uniform distribution. More... | |
std::vector< QMatrix > | getRandomKrausMap (int numQb, int numOps) |
Returns a random Kraus map of #numOps 2^numQb-by-2^ , from an undisclosed distribution. More... | |
QMatrix | getRandomQMatrix (int dim) |
Returns a dim-by- matrix, where the real and imaginary value of each element are independently random, under the standard normal distribution (mean 0, standard deviation 1). More... | |
QVector | getRandomQVector (int dim) |
Returns a dim-length vector with random complex amplitudes in the square joining {-1-i, 1+i}, of an undisclosed distribution. More... | |
qreal | getRandomReal (qreal min, qreal max) |
Returns a random real between min (inclusive) and max (exclusive), from the uniform distribution. More... | |
QVector | getRandomStateVector (int numQb) |
Returns a random numQb-length L2-normalised state-vector from an undisclosed distribution. More... | |
QMatrix | getRandomUnitary (int numQb) |
Returns a uniformly random (under Haar) 2^numQb-by-2^ matrix. More... | |
QMatrix | getSwapMatrix (int qb1, int qb2, int numQb) |
Returns the 2^numQb-by-2^ matrix which swaps qubits qb1 and qb2 ; the SWAP gate of not-necessarily-adjacent qubits. More... | |
QMatrix | getZeroMatrix (size_t dim) |
Returns a dim-by-dim square complex matrix, initialised to all zeroes. More... | |
CatchGen< pauliOpType * > | pauliseqs (int numPaulis) |
Returns a Catch2 generator of every numPaulis-length set of Pauli-matrix types (or base-4 integers). More... | |
CatchGen< int * > | sequences (int base, int numDigits) |
Returns a Catch2 generator of every numDigits-length sequence in the given base , in increasing lexographic order, where left-most (zero index) bit is treated as LEAST significant (opposite typical convention). More... | |
void | setRandomPauliSum (PauliHamil hamil) |
Populates hamil with random coefficients and pauli codes. More... | |
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. More... | |
void | setSubMatrix (QMatrix &dest, QMatrix sub, size_t r, size_t c) |
Modifies dest by overwriting its submatrix (from top-left corner (r , c ) to bottom-right corner (r + dest.size() , c + dest.size() ) with the complete elements of sub. More... | |
CatchGen< int * > | sublists (CatchGen< int > &&gen, int numSamps, const int *exclude, int numExclude) |
Returns a Catch2 generator of every length-sublen sublist of the elements generated by gen , which exclude all elements in exclude , in increasing lexographic order. More... | |
CatchGen< int * > | sublists (CatchGen< int > &&gen, int numSamps, int excluded) |
Returns a Catch2 generator of every length-sublen sublist of the elements generated by gen which exclude element excluded , in increasing lexographic order. More... | |
CatchGen< int * > | sublists (CatchGen< int > &&gen, int sublen) |
Returns a Catch2 generator of every length-sublen sublist of the elements generated by gen , in increasing lexographic order. More... | |
CatchGen< int * > | sublists (int *list, int len, int sublen) |
Returns a Catch2 generator of every length-sublen sublist of length-len list , in increasing lexographic order. More... | |
ComplexMatrix2 | toComplexMatrix2 (QMatrix qm) |
Returns a ComplexMatrix2 copy of QMatix qm . More... | |
ComplexMatrix4 | toComplexMatrix4 (QMatrix qm) |
Returns a ComplexMatrix4 copy of QMatix qm . More... | |
void | toComplexMatrixN (QMatrix qm, ComplexMatrixN cm) |
Initialises cm with the values of qm . More... | |
QMatrix | toQMatrix (Complex alpha, Complex beta) |
Returns the matrix (where a=alpha , b=beta ) {{a, -conj(b)}, {b, conj(a)}} using the qcomp complex type. More... | |
QMatrix | toQMatrix (ComplexMatrix2 src) |
Returns a copy of the given 2-by-2 matrix. More... | |
QMatrix | toQMatrix (ComplexMatrix4 src) |
Returns a copy of the given 4-by-4 matrix. More... | |
QMatrix | toQMatrix (ComplexMatrixN src) |
Returns a copy of the given 2^N-by-2^ . More... | |
QMatrix | toQMatrix (DiagonalOp op) |
Returns a 2^N-by-2^ diagonal matrix form of the DiagonalOp. More... | |
QMatrix | toQMatrix (PauliHamil hamil) |
Returns a 2^N-by-2^ matrix form of the PauliHamil. More... | |
QMatrix | toQMatrix (qreal *coeffs, pauliOpType *paulis, int numQubits, int numTerms) |
Returns a 2^N-by-2^ matrix form of the specified weighted sum of Pauli products. More... | |
QMatrix | toQMatrix (Qureg qureg) |
Returns an equal-size copy of the given density matrix qureg . More... | |
void | toQureg (Qureg qureg, QMatrix mat) |
Initialises the density matrix qureg to have the same amplitudes as mat . More... | |
void | toQureg (Qureg qureg, QVector vec) |
Initialises the state-vector qureg to have the same amplitudes as vec . More... | |
QVector | toQVector (DiagonalOp op) |
Returns a vector with the same of the full diagonal operator, populated with op's elements. More... | |
QVector | toQVector (Qureg qureg) |
Returns an equal-size copy of the given state-vector qureg . More... | |
Detailed Description
Functions used in the unit testing. These are mostly unoptimised, analytic implementations of the complex linear algebra that QuEST ultimately effects on quantum states. These are not part of the QuEST API, and require C++14.
Typedef Documentation
◆ QMatrix
A complex square matrix.
Should be initialised with getZeroMatrix(). These have all the natural linear-algebra operator overloads, including left-multiplication onto a vector.
This data-structure is not partitioned between nodes in distributed mode. That is, every node has a complete copy, allowing for safe comparisons.
Definition at line 49 of file utilities.hpp.
◆ QVector
A complex vector, which can be zero-initialised with QVector(numAmps).
These have all the natural linear-algebra operator overloads.
This data-structure is not partitioned between nodes in distributed mode. That is, every node has a complete copy, allowing for safe comparisons.
Definition at line 60 of file utilities.hpp.
Function Documentation
◆ applyReferenceMatrix() [1/2]
void applyReferenceMatrix | ( | QMatrix & | state, |
int * | ctrls, | ||
int | numCtrls, | ||
int * | targs, | ||
int | numTargs, | ||
QMatrix | op | ||
) |
Modifies the density matrix state
to be the result of left-multiplying the multi-target operator matrix op
, with the specified control and target qubits (in ctrls
and targs
respectively).
Here, op
is treated like a simple matrix and is hence left-multiplied onto the state once.
Definition at line 692 of file utilities.cpp.
References calcLog2(), and getFullOperatorMatrix().
◆ applyReferenceMatrix() [2/2]
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 op
, with the specified control and target qubits (in ctrls
and targs
respectively).
This is an alias of applyReferenceOp(), since operators are always left-multiplied as matrices onto state-vectors.
Definition at line 686 of file utilities.cpp.
References applyReferenceOp().
Referenced by TEST_CASE().
◆ applyReferenceOp() [1/16]
void applyReferenceOp | ( | QMatrix & | state, |
int * | ctrls, | ||
int | numCtrls, | ||
int * | targs, | ||
int | numTargs, | ||
QMatrix | op | ||
) |
Modifies the density matrix state
to be the result of applying the multi-target operator matrix op
, with the specified control and target qubits (in ctrls
and targs
respectively).
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2^numTargs-by-2^
. Furthermore, every element of numTargs
matrixtargs
must not appear in ctrls
(and vice-versa), though this is not explicitly checked. Elements of targs
and ctrls
should be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 629 of file utilities.cpp.
References calcLog2(), getConjugateTranspose(), and getFullOperatorMatrix().
◆ applyReferenceOp() [2/16]
void applyReferenceOp | ( | QMatrix & | state, |
int * | ctrls, | ||
int | numCtrls, | ||
int | targ1, | ||
int | targ2, | ||
QMatrix | op | ||
) |
Modifies the density matrix state
to be the result of applying the two-target operator matrix op
, with the specified control qubits (in ctrls
).
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 4-by-4 matrix. Both targ1
and targ2
must not appear in ctrls
, though this is not explicitly checked. Elements of ctrls
, and targ1
and targ2
, should be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 637 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [3/16]
Modifies the density matrix state
to be the result of applying the single-target operator matrix op
, with the specified control qubits (in ctrls
).
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2-by-2 matrix. target
must not appear in ctrls
, though this is not explicitly checked.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 643 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [4/16]
Modifies the density matrix state
to be the result of applying the multi-target operator matrix op
, with no control qubits.
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2^numTargs-by-2^
. Every element in numTargs
matrixtargs
should be unique, though this is not explicitly checked.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 649 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [5/16]
Modifies the density matrix state
to be the result of applying the multi-target operator matrix op
, with a single control qubit ctrl
.
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2^numTargs-by-2^
, and numTargs
matrixctrl
must not appear in targs
(though this is not explicitly checked).
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 661 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [6/16]
Modifies the density matrix state
to be the result of applying the single-control single-target operator matrix op
.
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2-by-2 matrix, and ctrl
and targ
should be different.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 654 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [7/16]
Modifies the density matrix state
to be the result of applying the two-target operator matrix op
, with a single control qubit ctrl
.
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 4-by-4 matrix, and ctrl
, targ1
and targ2
must be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 667 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [8/16]
Modifies the density matrix state
to be the result of applying the single-target operator matrix op
, with no control qubit.
This updates state
under
even if op
is not unitary (which is useful for applying Kraus operators).
op
must be a 2-by-2 matrix.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multipling it to state
, then right-multiplying its conjugate transpose onto the result.
Definition at line 674 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [9/16]
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
, with the specified control and target qubits (in ctrls
and targs
respectively).
This updates state
under
even if op
is not unitary.
op
must be a 2^numTargs-by-2^
. Furthermore, every element of numTargs
matrixtargs
must not appear in ctrls
(and vice-versa), though this is not explicitly checked. Elements of targs
and ctrls
should be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 573 of file utilities.cpp.
References calcLog2(), and getFullOperatorMatrix().
Referenced by applyReferenceMatrix(), applyReferenceOp(), and TEST_CASE().
◆ applyReferenceOp() [10/16]
void applyReferenceOp | ( | QVector & | state, |
int * | ctrls, | ||
int | numCtrls, | ||
int | targ1, | ||
int | targ2, | ||
QMatrix | op | ||
) |
Modifies the state-vector state
to be the result of applying the two-target operator matrix op
, with the specified control qubits (in ctrls
).
This updates state
under
even if op
is not unitary.
op
must be a 4-by-4 matrix. Furthermore, ctrls
, targ1
and targ2
should all be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 580 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [11/16]
Modifies the state-vector state
to be the result of applying the single-target operator matrix op
, with the specified control qubits (in ctrls
).
This updates state
under
even if op
is not unitary.
op
must be a 2-by-2 matrix. Furthermore, elements in ctrls
and target
should all be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 586 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [12/16]
Modifies the state-vector state
to be the result of applying the multi-target operator matrix op
, with no contorl qubits.
This updates state
under
even if op
is not unitary.
op
must be a 2^numTargs-by-2^
. Furthermore, elements in numTargs
matrixtargs
should be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 592 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [13/16]
Modifies the state-vector state
to be the result of applying the multi-target operator matrix op
, with a single control qubit (ctrl
) This updates state
under.
even if op
is not unitary.
op
must be a 2^numTargs-by-2^
. Furthermore, elements in numTargs
matrixtargs
and ctrl
should be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 604 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [14/16]
Modifies the state-vector state
to be the result of applying the single-target operator matrix op
, with a single control qubit (ctrl
).
This updates state
under
even if op
is not unitary.
op
must be a 2-by-2 matrix. Furthermore, ctrl
and targ
must be different.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 597 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [15/16]
Modifies the state-vector state
to be the result of applying the two-target operator matrix op
, with a single control qubit (ctrl
).
This updates state
under
even if op
is not unitary.
op
must be a 4-by-4 matrix. Furthermore, ctrl
, targ1
and targ2
should all be unique.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 610 of file utilities.cpp.
References applyReferenceOp().
◆ applyReferenceOp() [16/16]
Modifies the state-vector state
to be the result of applying the single-target operator matrix op
, with no contorl qubits.
This updates state
under
even if op
is not unitary.
op
must be a 2-by-2 matrix.
This function works by computing getFullOperatorMatrix() from the given arguments, and left-multiplying it onto state
.
Definition at line 617 of file utilities.cpp.
References applyReferenceOp().
◆ areEqual() [1/9]
Returns true if the absolute value of the difference between every amplitude in matrices a
and b
is less than REAL_EPS
.
Definition at line 396 of file utilities.cpp.
References DEMAND.
◆ areEqual() [2/9]
Performs a hardware-agnostic comparison of density-matrix qureg
to matr
, checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision.
This function demands qureg
is a density matrix, and that qureg
and matr
have equal dimensions.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 819 of file utilities.cpp.
References areEqual().
◆ areEqual() [3/9]
Performs a hardware-agnostic comparison of density-matrix qureg
to matr
, checking whether the difference between the real and imaginary components of every amplitude is smaller than precision
.
This function demands qureg
is a density matrix, and that qureg
and matr
have equal dimensions.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 767 of file utilities.cpp.
References Qureg::chunkId, copyStateFromGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, qreal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
◆ areEqual() [4/9]
Performs a hardware-agnostic comparison of state-vector qureg
to vec
, checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision.
This function demands qureg
is a state-vector, and that qureg
and vec
have the same number of amplitudes.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 763 of file utilities.cpp.
References areEqual().
◆ areEqual() [5/9]
Performs a hardware-agnostic comparison of state-vector qureg
to vec
, checking whether the difference between the real and imaginary components of every amplitude is smaller than precision
.
This function demands qureg
is a state-vector, and that qureg
and vec
have the same number of amplitudes.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 728 of file utilities.cpp.
References Qureg::chunkId, copyStateFromGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, qreal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
◆ areEqual() [6/9]
Performs a hardware-agnostic comparison of the given quregs, checking whether the difference between the real and imaginary components of every amplitude is smaller than the QuEST_PREC-specific REAL_EPS (defined in QuEST_precision) precision.
This function demands that qureg1
and qureg2
are of the same type (i.e. both state-vectors or both density matrices), and of an equal number of qubits.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 724 of file utilities.cpp.
References areEqual().
◆ areEqual() [7/9]
Performs a hardware-agnostic comparison of the given quregs, checking whether the difference between the real and imaginary components of every amplitude is smaller than precision
.
This function demands that qureg1
and qureg2
are of the same type (i.e. both state-vectors or both density matrices), and of an equal number of qubits.
In GPU mode, this function involves a GPU to CPU memory copy overhead. In distributed mode, it involves a all-to-all single-int broadcast.
Definition at line 701 of file utilities.cpp.
References copyStateFromGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
◆ areEqual() [8/9]
Returns true if the absolute value of the difference between every amplitude in vectors a
and b
is less than REAL_EPS
.
Definition at line 387 of file utilities.cpp.
References DEMAND.
Referenced by areEqual(), getRandomKrausMap(), getRandomUnitary(), and TEST_CASE().
◆ areEqual() [9/9]
Returns true if the absolute value of the difference between every element in vec
and those implied by reals
and imags
, is less than REAL_EPS
.
Definition at line 823 of file utilities.cpp.
References qreal.
◆ bitsets()
CatchGen<int*> bitsets | ( | int | numBits | ) |
Returns a Catch2 generator of every numBits-length
bit-set, in increasing lexographic order, where left-most (zero index) bit is treated as LEAST significant (opposite typical convention).
Note that the produced bitset must not be modified during generation.
This function can be used like
int* bits = GENERATE( bitsets(3) );
to produce {0,0,0}, {1,0,0}, {0,1,0}, {1,1,0}, {0,0,1}, {1,0,1}, {0,1,1}, {1,1,1}.
Definition at line 1268 of file utilities.cpp.
Referenced by TEST_CASE().
◆ calcLog2()
unsigned int calcLog2 | ( | long unsigned int | num | ) |
Returns log2 of numbers which must be gauranteed to be 2^n.
Returns log2 of numbers which must be gauranteed to be 2^n.
Definition at line 292 of file QuEST_validation.c.
Referenced by applyReferenceMatrix(), applyReferenceOp(), TEST_CASE(), validateNumQubitsInDiagOp(), and validateNumQubitsInQureg().
◆ getConjugateTranspose()
Returns the conjugate transpose of the complex square matrix a
.
Definition at line 179 of file utilities.cpp.
Referenced by applyReferenceOp(), getRandomKrausMap(), and getRandomUnitary().
◆ getExponentialOfDiagonalMatrix()
Returns the matrix exponential of a diagonal, square, complex matrix.
This method explicitly checks that the passed matrix a
is diagonal.
Definition at line 187 of file utilities.cpp.
References DEMAND.
Referenced by TEST_CASE().
◆ getExponentialOfPauliMatrix()
Returns the matrix exponential of a kronecker product of pauli matrices (or of any involutory matrices), with exponent factor (-i angle
/ 2).
This method will not explicitly check that the passed matrix a
is kronecker product of involutory matrices, but will otherwise return an incorrect exponential.
Definition at line 205 of file utilities.cpp.
References getIdentityMatrix().
Referenced by TEST_CASE().
◆ getFullOperatorMatrix()
QMatrix getFullOperatorMatrix | ( | int * | ctrls, |
int | numCtrls, | ||
int * | targs, | ||
int | numTargs, | ||
QMatrix | op, | ||
int | numQubits | ||
) |
Takes a 2^numTargs-by-2^
numTargs
matrixop
and a returns a 2^numQubits-by-2^
where numQubits
matrixop
is controlled on the given ctrls
qubits.
The union of {ctrls}
and {targs}
must be unique (though this is not explicitly checked), and every element must be >= 0 (not checked). The passed {ctrls}
and {targs}
arrays are unmodified.
This funciton works by first swapping {targs}
and {ctrls}
(via swap unitaries) to be strictly increasing {0,1,...}, building controlled(op
), tensoring it to the full Hilbert space, and then 'unswapping'. The returned matrix has form: swap1 ... swapN . controlled(op
) . swapN ... swap1
Definition at line 293 of file utilities.cpp.
References DEMAND, getIdentityMatrix(), getKroneckerProduct(), getSwapMatrix(), setSubMatrix(), and updateIndices().
Referenced by applyReferenceMatrix(), applyReferenceOp(), and TEST_CASE().
◆ getIdentityMatrix()
QMatrix getIdentityMatrix | ( | size_t | dim | ) |
Returns a dim-by-dim identity matrix.
Definition at line 151 of file utilities.cpp.
References DEMAND, and getZeroMatrix().
Referenced by getExponentialOfPauliMatrix(), getFullOperatorMatrix(), getRandomKrausMap(), getRandomUnitary(), and getSwapMatrix().
◆ getKetBra()
Returns the matrix |ket><
with ith-jth element bra|
,ket(i)
conj(bra(j)
), since |ket><
sum_i a_i|i> sum_j b_j* <j| = sum_{ij} a_i b_j* |i><j|. bra|
=
The dimensions of bra and ket must agree, and the returned square complex matrix has dimensions size(bra) x size(bra).
Definition at line 159 of file utilities.cpp.
References DEMAND, and getZeroMatrix().
Referenced by getRandomDensityMatrix(), and TEST_CASE().
◆ getKroneckerProduct()
Returns the kronecker product of a
and b
, where a
and b
are square but possibly differently-sized complex matrices.
Definition at line 169 of file utilities.cpp.
References getZeroMatrix().
Referenced by getFullOperatorMatrix(), getSwapMatrix(), TEST_CASE(), and toQMatrix().
◆ getNormalised()
Returns an L2-normalised copy of vec
, using Kahan summation for improved accuracy.
Definition at line 431 of file utilities.cpp.
References qreal.
Referenced by getRandomStateVector().
◆ getRandomDensityMatrix()
QMatrix getRandomDensityMatrix | ( | int | numQb | ) |
Returns a random numQb-by-
matrix, from an undisclosed distribution, in a very mixed state. numQb
density
This function works by generating 2^numQb
random pure states, and mixing them with random probabilities.
Definition at line 457 of file utilities.cpp.
References DEMAND, getKetBra(), getRandomReal(), getRandomStateVector(), getZeroMatrix(), and qreal.
Referenced by TEST_CASE().
◆ getRandomInt()
int getRandomInt | ( | int | min, |
int | max | ||
) |
Returns a random integer between min
(inclusive) and max
(exclusive), from the uniform distribution.
Demands that max
> min
.
Definition at line 481 of file utilities.cpp.
References getRandomReal().
Referenced by setRandomPauliSum(), and TEST_CASE().
◆ getRandomKrausMap()
std::vector<QMatrix> getRandomKrausMap | ( | int | numQb, |
int | numOps | ||
) |
Returns a random Kraus map of #numOps
2^numQb-by-2^
, from an undisclosed distribution. numQb
operators
Note this method is very simple and cannot generate all possible Kraus maps. It works by generating numOps
random unitary matrices, and randomly re-normalising them, such that the sum of ops[j]^dagger ops[j] = 1
Definition at line 533 of file utilities.cpp.
References areEqual(), DEMAND, getConjugateTranspose(), getIdentityMatrix(), getRandomReal(), getRandomUnitary(), getZeroMatrix(), and qreal.
Referenced by TEST_CASE().
◆ getRandomQMatrix()
QMatrix getRandomQMatrix | ( | int | dim | ) |
Returns a dim-by-
matrix, where the real and imaginary value of each element are independently random, under the standard normal distribution (mean 0, standard deviation 1). dim
complex
Definition at line 368 of file utilities.cpp.
References DEMAND, getZeroMatrix(), and qreal.
Referenced by getRandomUnitary(), and TEST_CASE().
◆ getRandomQVector()
QVector getRandomQVector | ( | int | dim | ) |
Returns a dim-length
vector with random complex amplitudes in the square joining {-1-i, 1+i}, of an undisclosed distribution.
The resulting vector is NOT L2-normalised.
Definition at line 420 of file utilities.cpp.
References DEMAND, and getRandomReal().
Referenced by getRandomStateVector(), and TEST_CASE().
◆ getRandomReal()
Returns a random real between min
(inclusive) and max
(exclusive), from the uniform distribution.
Demands that max
> min
.
Definition at line 410 of file utilities.cpp.
Referenced by getRandomDensityMatrix(), getRandomInt(), getRandomKrausMap(), getRandomQVector(), setRandomPauliSum(), and TEST_CASE().
◆ getRandomStateVector()
QVector getRandomStateVector | ( | int | numQb | ) |
Returns a random numQb-length
L2-normalised state-vector from an undisclosed distribution.
This function works by randomly generating each complex amplitude, then L2-normalising.
Definition at line 453 of file utilities.cpp.
References getNormalised(), and getRandomQVector().
Referenced by getRandomDensityMatrix(), and TEST_CASE().
◆ getRandomUnitary()
QMatrix getRandomUnitary | ( | int | numQb | ) |
Returns a uniformly random (under Haar) 2^numQb-by-2^
matrix. numQb
unitary
This function works by first generating a complex matrix where each element is independently random; the real and imaginary component thereof are independent standard normally-distributed (mean 0, standard-dev 1). Then, the matrix is orthonormalised via the Gram Schmidt algorithm. The resulting unitary matrix MAY be uniformly distributed under the Haar measure, but we make no assurance. This routine may return an identity matrix if it was unable to sufficiently precisely produce a unitary of the given size.
Definition at line 485 of file utilities.cpp.
References areEqual(), DEMAND, getConjugateTranspose(), getIdentityMatrix(), getRandomQMatrix(), qcomp, and qreal.
Referenced by getRandomKrausMap(), and TEST_CASE().
◆ getSwapMatrix()
QMatrix getSwapMatrix | ( | int | qb1, |
int | qb2, | ||
int | numQb | ||
) |
Returns the 2^numQb-by-2^
matrix which swaps qubits numQb
unitaryqb1
and qb2
; the SWAP gate of not-necessarily-adjacent qubits.
If qb1
== qb2
, returns the identity matrix.
Definition at line 219 of file utilities.cpp.
References DEMAND, getIdentityMatrix(), getKroneckerProduct(), getZeroMatrix(), and setSubMatrix().
Referenced by getFullOperatorMatrix().
◆ getZeroMatrix()
QMatrix getZeroMatrix | ( | size_t | dim | ) |
Returns a dim-by-dim square complex matrix, initialised to all zeroes.
Definition at line 143 of file utilities.cpp.
References DEMAND.
Referenced by getIdentityMatrix(), getKetBra(), getKroneckerProduct(), getRandomDensityMatrix(), getRandomKrausMap(), getRandomQMatrix(), getSwapMatrix(), TEST_CASE(), and toQMatrix().
◆ pauliseqs()
CatchGen<pauliOpType*> pauliseqs | ( | int | numPaulis | ) |
Returns a Catch2 generator of every numPaulis-length
set of Pauli-matrix types (or base-4 integers).
Generates in increasing lexographic order, where the left-most (zero index) pauli is treated as LEAST significant. Note that the sequence must not be modified during generation.
This function can be used like
pauliOpType* set = GENERATE( pauliseqs(2) );
to produce {I,I}, {X,I}, {Y,I}, {Z,I}, {I,X}, {X,X}, {Y,X}, {Z,X}, {I,Y}, {X,Y}, {Y,Y}, {Z,Y}, {I,Z}, {X,Z}, {Y,Z}, {Z,Z}/
Definition at line 1278 of file utilities.cpp.
References PAULI_Z.
◆ sequences()
CatchGen<int*> sequences | ( | int | base, |
int | numDigits | ||
) |
Returns a Catch2 generator of every numDigits-length
sequence in the given base
, in increasing lexographic order, where left-most (zero index) bit is treated as LEAST significant (opposite typical convention).
Note that the sequence must not be modified during generation.
This function can be used like
int base = 3; int numDigits = 2; int* seq = GENERATE_COPY( sequences(base, numDigits) );
to produce {0,0}, {1,0}, {2,0}, {0,1}, {1,1}, {2,1}, {0,2}, {1,2}, {2,2}.
Definition at line 1273 of file utilities.cpp.
◆ setRandomPauliSum() [1/2]
void setRandomPauliSum | ( | PauliHamil | hamil | ) |
Populates hamil
with random coefficients and pauli codes.
Definition at line 1062 of file utilities.cpp.
References PauliHamil::numQubits, PauliHamil::numSumTerms, PauliHamil::pauliCodes, setRandomPauliSum(), and PauliHamil::termCoeffs.
◆ setRandomPauliSum() [2/2]
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.
Definition at line 1054 of file utilities.cpp.
References getRandomInt(), and getRandomReal().
Referenced by setRandomPauliSum(), and TEST_CASE().
◆ setSubMatrix()
Modifies dest
by overwriting its submatrix (from top-left corner (r
, c
) to bottom-right corner (r
+ dest.size()
, c
+ dest.size()
) with the complete elements of sub.
This demands that dest.size() >= sub.size() + max(r,c).
Definition at line 211 of file utilities.cpp.
References DEMAND.
Referenced by getFullOperatorMatrix(), and getSwapMatrix().
◆ sublists() [1/4]
CatchGen<int*> sublists | ( | CatchGen< int > && | gen, |
int | numSamps, | ||
const int * | exclude, | ||
int | numExclude | ||
) |
Returns a Catch2 generator of every length-sublen
sublist of the elements generated by gen
, which exclude all elements in exclude
, in increasing lexographic order.
This generates every fixed-length combination of gen's
elements the nominated exclusions, and every permutation of each.
There is on need for the elements of exclude
to actually appear in those of gen
. sublen
must less than or equal to the number of elements in gen
, after the nominated exclusions.
Note that the sublist must not be modified, else further generation may break (QuEST's internal functions will indeed modify but restore the qubit index lists given to them, which is ok). Assumes list
contains no duplicates, otherwise the generated sublists may be duplicated.
This function can be used like
int sublen = 2; int exclude[2] = {3,4}; int* sublist = GENERATE_COPY( sublists(range(1,6), sublen, exclude, 2) );
to generate {1,2}, {1,5}, {2,1}, {2,5}, {5,1}, {5,2}
◆ sublists() [2/4]
Returns a Catch2 generator of every length-sublen
sublist of the elements generated by gen
which exclude element excluded
, in increasing lexographic order.
This generates every fixed-length combination of gen's
elements the nominated exclusions, and every permutation of each.
sublen
must less than or equal to the number of elements in gen
, after the nominated exclusion. There is no need for excluded
to actually appear in the elements of gen
.
Note that the sublist must not be modified, else further generation may break (QuEST's internal functions will indeed modify but restore the qubit index lists given to them, which is ok). Assumes list
contains no duplicates, otherwise the generated sublists may be duplicated.
This function can be used like
int sublen = 2; int excluded = 1; int* sublist = GENERATE_COPY( sublists(range(1,4), sublen, excluded) );
to generate {2,3}, {3,2}.
◆ sublists() [3/4]
Returns a Catch2 generator of every length-sublen
sublist of the elements generated by gen
, in increasing lexographic order.
This generates every fixed-length combination of gen's
elements, and every permutation of each. Note that the produced sublist must not be modified, else further generation may break (QuEST's internal functions will indeed modify but restore the qubit index lists given to them, which is ok). Assumes list
contains no duplicates, otherwise the generated sublists may be duplicated.
This function can be used like
int sublen = 2; int* sublist = GENERATE_COPY( sublists(list, 4, sublen) );
to generate {1,2}, {1,3}, {1,4}, {2,1}, {2,3}, {2,4}, {3,1}, {3,2}, {3, 4}, {4,1}, {4,2}, {4, 3}.
◆ sublists() [4/4]
CatchGen<int*> sublists | ( | int * | list, |
int | len, | ||
int | sublen | ||
) |
Returns a Catch2 generator of every length-sublen
sublist of length-len
list
, in increasing lexographic order.
This generates every fixed-length combination of the given list and every permutation of each. & If the sublist length is the full list length, this generator produces every permutation correctly. Note that the sublist must not be modified, else further & generation may break (QuEST's internal functions will indeed modify but restore the qubit index lists given to them, which is ok). Assumes list
contains no duplicates, otherwise the generated sublists may be duplicated.
This function can be used like
int list[4] = {1,2,3,4}; int sublen = 2; int* sublist = GENERATE_COPY( sublists(list, 4, sublen) );
to generate {1,2}, {1,3}, {1,4}, {2,1}, {2,3}, {2,4}, {3,1}, {3,2}, {3, 4}, {4,1}, {4,2}, {4, 3}.
Definition at line 1199 of file utilities.cpp.
Referenced by TEST_CASE().
◆ toComplexMatrix2()
ComplexMatrix2 toComplexMatrix2 | ( | QMatrix | qm | ) |
Returns a ComplexMatrix2
copy of QMatix qm
.
Demands that qm
is a 2-by-2 matrix.
Definition at line 846 of file utilities.cpp.
References DEMAND, and macro_copyQMatrix.
Referenced by TEST_CASE().
◆ toComplexMatrix4()
ComplexMatrix4 toComplexMatrix4 | ( | QMatrix | qm | ) |
Returns a ComplexMatrix4
copy of QMatix qm
.
Demands that qm
is a 4-by-4 matrix.
Definition at line 852 of file utilities.cpp.
References DEMAND, and macro_copyQMatrix.
Referenced by TEST_CASE().
◆ toComplexMatrixN()
void toComplexMatrixN | ( | QMatrix | qm, |
ComplexMatrixN | cm | ||
) |
Initialises cm
with the values of qm
.
Demands that cm
is a previously created ComplexMatrixN instance, with the same dimensions as qm
.
Definition at line 858 of file utilities.cpp.
References DEMAND, macro_copyQMatrix, and ComplexMatrixN::numQubits.
Referenced by TEST_CASE().
◆ toQMatrix() [1/8]
Returns the matrix (where a=alpha
, b=beta
) {{a, -conj(b)}, {b, conj(a)}} using the qcomp
complex type.
Definition at line 887 of file utilities.cpp.
References Complex::imag, qcomp, and Complex::real.
◆ toQMatrix() [2/8]
QMatrix toQMatrix | ( | ComplexMatrix2 | src | ) |
Returns a copy of the given 2-by-2 matrix.
Definition at line 869 of file utilities.cpp.
References getZeroMatrix(), and macro_copyComplexMatrix.
Referenced by TEST_CASE(), and toQMatrix().
◆ toQMatrix() [3/8]
QMatrix toQMatrix | ( | ComplexMatrix4 | src | ) |
Returns a copy of the given 4-by-4 matrix.
Definition at line 874 of file utilities.cpp.
References getZeroMatrix(), and macro_copyComplexMatrix.
◆ toQMatrix() [4/8]
QMatrix toQMatrix | ( | ComplexMatrixN | src | ) |
Returns a copy of the given 2^N-by-2^
. N
matrix
Definition at line 879 of file utilities.cpp.
References DEMAND, getZeroMatrix(), ComplexMatrixN::imag, macro_copyComplexMatrix, ComplexMatrixN::numQubits, and ComplexMatrixN::real.
◆ toQMatrix() [5/8]
QMatrix toQMatrix | ( | DiagonalOp | op | ) |
Returns a 2^N-by-2^
diagonal matrix form of the DiagonalOp. N
complex
Definition at line 1018 of file utilities.cpp.
References getZeroMatrix(), DiagonalOp::numQubits, and toQVector().
◆ toQMatrix() [6/8]
QMatrix toQMatrix | ( | PauliHamil | hamil | ) |
Returns a 2^N-by-2^
matrix form of the PauliHamil. N
Hermitian
Definition at line 1095 of file utilities.cpp.
References PauliHamil::numQubits, PauliHamil::numSumTerms, PauliHamil::pauliCodes, PauliHamil::termCoeffs, and toQMatrix().
◆ toQMatrix() [7/8]
QMatrix toQMatrix | ( | qreal * | coeffs, |
pauliOpType * | paulis, | ||
int | numQubits, | ||
int | numTerms | ||
) |
Returns a 2^N-by-2^
matrix form of the specified weighted sum of Pauli products. N
Hermitian
Definition at line 1066 of file utilities.cpp.
References getKroneckerProduct(), getZeroMatrix(), NUM_QUBITS, PAULI_I, PAULI_X, PAULI_Y, and PAULI_Z.
◆ toQMatrix() [8/8]
Returns an equal-size copy of the given density matrix qureg
.
In GPU mode, this function involves a copy of qureg
from GPU memory to RAM. In distributed mode, this involves an all-to-all broadcast of qureg
.
Definition at line 896 of file utilities.cpp.
References copyStateFromGPU(), DEMAND, getZeroMatrix(), Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, Qureg::numQubitsRepresented, qcomp, qreal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
◆ toQureg() [1/2]
Initialises the density matrix qureg
to have the same amplitudes as mat
.
Demands qureg
is a density matrix of equal dimensions to mat
. In GPU mode, this function involves a copy from RAM to GPU memory. This function has no communication cost in distributed mode.
Definition at line 1039 of file utilities.cpp.
References Qureg::chunkId, copyStateToGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numQubitsRepresented, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
◆ toQureg() [2/2]
Initialises the state-vector qureg
to have the same amplitudes as vec
.
Demands qureg
is a state-vector of an equal size to vec
. In GPU mode, this function involves a copy from RAM to GPU memory. This function has no communication cost in distributed mode.
Definition at line 1026 of file utilities.cpp.
References Qureg::chunkId, copyStateToGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
Referenced by TEST_CASE().
◆ toQVector() [1/2]
QVector toQVector | ( | DiagonalOp | op | ) |
Returns a vector with the same of the full diagonal operator, populated with op's
elements.
In distributed mode, this involves an all-to-all broadcast of op
.
Definition at line 980 of file utilities.cpp.
References DEMAND, DiagonalOp::imag, DiagonalOp::numElemsPerChunk, DiagonalOp::numQubits, qcomp, qreal, and DiagonalOp::real.
◆ toQVector() [2/2]
Returns an equal-size copy of the given state-vector qureg
.
In GPU mode, this function involves a copy of qureg
from GPU memory to RAM. In distributed mode, this involves an all-to-all broadcast of qureg
.
Definition at line 938 of file utilities.cpp.
References copyStateFromGPU(), DEMAND, Qureg::isDensityMatrix, Qureg::numAmpsPerChunk, Qureg::numAmpsTotal, qcomp, qreal, QUEST_ENV, Qureg::stateVec, and syncQuESTEnv().
Referenced by TEST_CASE(), and toQMatrix().