Unitary gates. More...
Functions | |
void | compactUnitary (Qureg qureg, int targetQubit, Complex alpha, Complex beta) |
Apply a single-qubit unitary parameterised by two given complex scalars. More... | |
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. More... | |
void | controlledMultiQubitUnitary (Qureg qureg, int ctrl, int *targs, int numTargs, ComplexMatrixN u) |
Apply a general controlled multi-qubit unitary (including a global phase factor). More... | |
void | controlledNot (Qureg qureg, int controlQubit, int targetQubit) |
Apply the controlled not (single control, single target) gate, also known as the c-X, c-sigma-X, c-Pauli-X and c-bit-flip gate. More... | |
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 gate. More... | |
void | controlledPhaseFlip (Qureg qureg, int idQubit1, int idQubit2) |
Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate. More... | |
void | controlledPhaseShift (Qureg qureg, int idQubit1, int idQubit2, qreal angle) |
Introduce a phase factor ![]() ![]() idQubit1 and idQubit2 . More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | controlledTwoQubitUnitary (Qureg qureg, int controlQubit, int targetQubit1, int targetQubit2, ComplexMatrix4 u) |
Apply a general controlled two-qubit unitary (including a global phase factor). More... | |
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 factor. More... | |
void | hadamard (Qureg qureg, int targetQubit) |
Apply the single-qubit Hadamard gate. More... | |
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). More... | |
void | multiControlledPhaseFlip (Qureg qureg, int *controlQubits, int numControlQubits) |
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled pauliZ gate. More... | |
void | multiControlledPhaseShift (Qureg qureg, int *controlQubits, int numControlQubits, qreal angle) |
Introduce a phase factor ![]() ![]() | |
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). More... | |
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. More... | |
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 qubits. More... | |
void | multiRotatePauli (Qureg qureg, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle) |
Apply a multi-qubit multi-Pauli rotation on a selected number of qubits. More... | |
void | multiRotateZ (Qureg qureg, int *qubits, int numQubits, qreal angle) |
Apply a multi-qubit Z rotation on a selected number of qubits. More... | |
void | multiStateControlledUnitary (Qureg qureg, int *controlQubits, int *controlState, int numControlQubits, int targetQubit, ComplexMatrix2 u) |
Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary, which can include a global phase factor. More... | |
void | pauliX (Qureg qureg, int targetQubit) |
Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate. More... | |
void | pauliY (Qureg qureg, int targetQubit) |
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate. More... | |
void | pauliZ (Qureg qureg, int targetQubit) |
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate. More... | |
void | phaseShift (Qureg qureg, int targetQubit, qreal angle) |
Shift the phase between ![]() ![]() | |
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. More... | |
void | rotateX (Qureg qureg, int rotQubit, qreal angle) |
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere. More... | |
void | rotateY (Qureg qureg, int rotQubit, qreal angle) |
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere. More... | |
void | rotateZ (Qureg qureg, int rotQubit, qreal angle) |
Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase shift gate). More... | |
void | sGate (Qureg qureg, int targetQubit) |
Apply the single-qubit S gate. More... | |
void | sqrtSwapGate (Qureg qureg, int qb1, int qb2) |
Performs a sqrt SWAP gate between qubit1 and qubit2 . More... | |
void | swapGate (Qureg qureg, int qubit1, int qubit2) |
Performs a SWAP gate between qubit1 and qubit2 . More... | |
void | tGate (Qureg qureg, int targetQubit) |
Apply the single-qubit T gate. More... | |
void | twoQubitUnitary (Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u) |
Apply a general two-qubit unitary (including a global phase factor). More... | |
void | unitary (Qureg qureg, int targetQubit, ComplexMatrix2 u) |
Apply a general single-qubit unitary (including a global phase factor). More... | |
Detailed Description
Unitary gates.
Function Documentation
◆ compactUnitary()
Apply a single-qubit unitary parameterised by two given complex scalars.
Given valid complex numbers and
, applies the unitary
which is general up to a global phase factor.
Valid ,
satisfy
.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on [in] alpha complex unitary parameter (row 1, column 1) [in] beta complex unitary parameter (row 2, column 1)
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
), or ifalpha
,beta
don't satisfy |alpha|^2
+ |beta|^2
= 1.
Definition at line 405 of file QuEST.c.
References getConjugateScalar(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordCompactUnitary(), statevec_compactUnitary(), validateTarget(), and validateUnitaryComplexPair().
Referenced by TEST_CASE().
◆ controlledCompactUnitary()
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.
Given valid complex numbers and
, applies the two-qubit unitary
to the control and target qubits. Valid ,
satisfy
. The target unitary is general up to a global phase factor.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit apply the target unitary if this qubit has value 1 [in] targetQubit qubit on which to apply the target unitary [in] alpha complex unitary parameter (row 1, column 1) [in] beta complex unitary parameter (row 2, column 1)
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal, or ifalpha
,beta
don't satisfy |alpha|^2
+ |beta|^2
= 1.
Definition at line 418 of file QuEST.c.
References getConjugateScalar(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledCompactUnitary(), statevec_controlledCompactUnitary(), validateControlTarget(), and validateUnitaryComplexPair().
Referenced by TEST_CASE().
◆ controlledMultiQubitUnitary()
void controlledMultiQubitUnitary | ( | Qureg | qureg, |
int | ctrl, | ||
int * | targs, | ||
int | numTargs, | ||
ComplexMatrixN | u | ||
) |
Apply a general controlled multi-qubit unitary (including a global phase factor).
One control and any number of target qubits can be specified. This effects the many-qubit unitary
on the control and target qubits.
The target qubits in targs
are treated as ordered least significant to most significant in u
.
The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.
Note that in multithreaded mode, each thread will clone 2^numTargs
amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^numTargs
. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).
Note too that in distributed mode, this routine requires that each node contains at least 2^numTargs
amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs
nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] ctrl the control qubit [in] targs a list of the target qubits, ordered least to most significant [in] numTargs the number of target qubits [in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if ctrl
or any index intargs
is outside of [0,qureg.numQubitsRepresented
), or iftargs
are not unique, or iftargs
containsctrl
, or if matrixu
is not unitary, or if a node cannot fit the required number of target amplitudes in distributed mode.
Definition at line 314 of file QuEST.c.
References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_controlledMultiQubitUnitary(), validateMultiControlsMultiTargets(), and validateMultiQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ controlledNot()
void controlledNot | ( | Qureg | qureg, |
int | controlQubit, | ||
int | targetQubit | ||
) |
Apply the controlled not (single control, single target) gate, also known as the c-X, c-sigma-X, c-Pauli-X and c-bit-flip gate.
This applies pauliX to the target qubit if the control qubit has value 1. This effects the two-qubit unitary
on the control and target qubits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit nots the target if this qubit is 1 [in] targetQubit qubit to not
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
), or are equal.
Definition at line 525 of file QuEST.c.
References GATE_SIGMA_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledNot(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledPauliY()
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 gate.
This applies pauliY to the target qubit if the control qubit has value 1. This effects the two-qubit unitary
on the control and target qubits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit applies pauliY to the target if this qubit is 1 [in] targetQubit qubit to not
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
), or are equal.
Definition at line 537 of file QuEST.c.
References GATE_SIGMA_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledPauliY(), statevec_controlledPauliYConj(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledPhaseFlip()
void controlledPhaseFlip | ( | Qureg | qureg, |
int | idQubit1, | ||
int | idQubit2 | ||
) |
Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate.
For each state, if both input qubits have value one, multiply the amplitude of that state by -1. This applies the two-qubit unitary:
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] idQubit1,idQubit2 qubits to operate upon
- Exceptions
-
invalidQuESTInputError if idQubit1
oridQubit2
are outside [0,qureg.numQubitsRepresented
), or are equal
Definition at line 549 of file QuEST.c.
References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledPhaseFlip(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledPhaseShift()
Introduce a phase factor on state
of qubits
idQubit1
and idQubit2
.
For angle , this effects the unitary
on idQubit1
and idQubit2
.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] idQubit1 first qubit in the state to phase shift [in] idQubit2 second qubit in the state to phase shift [in] angle amount by which to shift the phase in radians
- Exceptions
-
invalidQuESTInputError if idQubit1
oridQubit2
are outside [0,qureg.numQubitsRepresented
), or are equal
Definition at line 499 of file QuEST.c.
References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledPhaseShift(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledRotateAroundAxis()
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.
The vector must not be zero (else an error is thrown), but needn't be unit magnitude.
For angle and axis vector
, applies
to states where the target qubit is 1 (
is the vector of Pauli matrices).
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit qubit with value 1 in the rotated states [in] targetQubit qubit to rotate [in] angle angle by which to rotate in radians [in] axis vector around which to rotate (can be non-unit; will be normalised)
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal or ifaxis
is the zero vector
Definition at line 588 of file QuEST.c.
References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledAxisRotation(), statevec_controlledRotateAroundAxis(), statevec_controlledRotateAroundAxisConj(), validateControlTarget(), and validateVector().
Referenced by TEST_CASE().
◆ controlledRotateX()
Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.
The target qubit is rotated in states where the control qubit has value 1.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit qubit which has value 1 in the rotated states [in] targetQubit qubit to rotate [in] angle angle by which to rotate the target qubit in radians
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal.
Definition at line 221 of file QuEST.c.
References GATE_ROTATE_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateX(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledRotateY()
Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.
The target qubit is rotated in states where the control qubit has value 1.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit qubit which has value 1 in the rotated states [in] targetQubit qubit to rotate [in] angle angle by which to rotate the target qubit in radians
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal.
Definition at line 233 of file QuEST.c.
References GATE_ROTATE_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateY(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledRotateZ()
Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.
The target qubit is rotated in states where the control qubit has value 1.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit qubit which has value 1 in the rotated states [in] targetQubit qubit to rotate [in] angle angle by which to rotate the target qubit in radians
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal.
Definition at line 245 of file QuEST.c.
References GATE_ROTATE_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateZ(), and validateControlTarget().
Referenced by TEST_CASE().
◆ controlledTwoQubitUnitary()
void controlledTwoQubitUnitary | ( | Qureg | qureg, |
int | controlQubit, | ||
int | targetQubit1, | ||
int | targetQubit2, | ||
ComplexMatrix4 | u | ||
) |
Apply a general controlled two-qubit unitary (including a global phase factor).
The given unitary is applied to the target amplitudes where the control qubit has value 1. This effects the many-qubit unitary
on the control and target qubits.
targetQubit1
is treated as the least
significant qubit in u
, such that a row in u
is dotted with the vector
The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.
Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit the control qubit which must be in state 1 to effect the given unitary [in] targetQubit1 first qubit to operate on, treated as least significant in u
[in] targetQubit2 second qubit to operate on, treated as most significant in u
[in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if controlQubit
,targetQubit1
ortargetQubit2
are outside [0,qureg.numQubitsRepresented
), or if any ofcontrolQubit
,targetQubit1
andtargetQubit2
are equal, or matrixu
is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Definition at line 270 of file QuEST.c.
References getConjugateMatrix4(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_controlledTwoQubitUnitary(), validateMultiControlsMultiTargets(), and validateTwoQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ controlledUnitary()
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 factor.
The given unitary is applied to the target qubit if the control qubit has value 1, effecting the two-qubit unitary
on the control and target qubits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubit apply unitary if this qubit is 1 [in] targetQubit qubit to operate on [in] u single-qubit unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if either controlQubit
ortargetQubit
are outside [0,qureg.numQubitsRepresented
) or are equal, or ifu
is not unitary.
Definition at line 361 of file QuEST.c.
References getConjugateMatrix2(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledUnitary(), statevec_controlledUnitary(), validateControlTarget(), and validateOneQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ hadamard()
void hadamard | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit Hadamard gate.
This takes to
and
to
, and is equivalent to a rotation of
around the x-axis then
about the y-axis on the Bloch-sphere. I.e.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 177 of file QuEST.c.
References GATE_HADAMARD, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_hadamard(), and validateTarget().
Referenced by TEST_CASE().
◆ multiControlledMultiQubitUnitary()
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).
Any number of control and target qubits can be specified. This effects the many-qubit unitary
on the control and target qubits.
The target qubits in targs
are treated as ordered least significant to most significant in u
.
The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.
Note that in multithreaded mode, each thread will clone 2^numTargs
amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^numTargs
. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).
Note that in distributed mode, this routine requires that each node contains at least 2^numTargs
amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs
nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] ctrls a list of the control qubits [in] numCtrls the number of control qubits [in] targs a list of the target qubits, ordered least to most significant [in] numTargs the number of target qubits [in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if any index in ctrls
andtargs
is outside of [0,qureg.numQubitsRepresented
), or ifctrls
andtargs
are not unique, or if matrixu
is not unitary, or if a node cannot fit the required number of target amplitudes in distributed mode.
Definition at line 331 of file QuEST.c.
References getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_multiControlledMultiQubitUnitary(), validateMultiControlsMultiTargets(), and validateMultiQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ multiControlledPhaseFlip()
void multiControlledPhaseFlip | ( | Qureg | qureg, |
int * | controlQubits, | ||
int | numControlQubits | ||
) |
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled pauliZ gate.
For each state, if all control qubits have value one, multiply the amplitude of that state by -1. This applies the many-qubit unitary:
on the control qubits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubits array of input qubits [in] numControlQubits number of input qubits
- Exceptions
-
invalidQuESTInputError if numControlQubits
is outside [1,qureg.numQubitsRepresented
), or if any qubit incontrolQubits
is outside [0,qureg.numQubitsRepresented
), or if any qubit inqubits
is repeated.
Definition at line 561 of file QuEST.c.
References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledGate(), shiftIndices(), statevec_multiControlledPhaseFlip(), and validateMultiQubits().
Referenced by TEST_CASE().
◆ multiControlledPhaseShift()
void multiControlledPhaseShift | ( | Qureg | qureg, |
int * | controlQubits, | ||
int | numControlQubits, | ||
qreal | angle | ||
) |
Introduce a phase factor on state
of the passed qubits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubits array of qubits to phase shift [in] numControlQubits the length of array controlQubits
[in] angle amount by which to shift the phase in radians
- Exceptions
-
invalidQuESTInputError if numControlQubits
is outside [1,qureg.numQubitsRepresented
]), or if any qubit index incontrolQubits
is outside [0,qureg.numQubitsRepresented
]), or if any qubit incontrolQubits
is repeated.
Definition at line 511 of file QuEST.c.
References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledParamGate(), shiftIndices(), statevec_multiControlledPhaseShift(), and validateMultiQubits().
Referenced by TEST_CASE().
◆ multiControlledTwoQubitUnitary()
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).
Any number of control qubits can be specified, and if all have value 1, the given unitary is applied to the target qubit. This effects the many-qubit unitary
on the control and target qubits.
targetQubit1
is treated as the least
significant qubit in u
, such that a row in u
is dotted with the vector
The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.
Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubits the control qubits which all must be in state 1 to effect the given unitary [in] numControlQubits the number of control qubits [in] targetQubit1 first target qubit, treated as least significant in u
[in] targetQubit2 second target qubit, treated as most significant in u
[in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if targetQubit1
ortargetQubit2
are outside [0,qureg.numQubitsRepresented
), or iftargetQubit1
equalstargetQubit2
, or if any qubit incontrolQubits
is outside [0,qureg.numQubitsRepresented
), or ifcontrolQubits
are not unique, or if eithertargetQubit1
andtargetQubit2
are incontrolQubits
, or if matrixu
is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Definition at line 283 of file QuEST.c.
References getConjugateMatrix4(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_multiControlledTwoQubitUnitary(), validateMultiControlsMultiTargets(), and validateTwoQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ multiControlledUnitary()
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.
Any number of control qubits can be specified, and if all have value 1, the given unitary is applied to the target qubit. This effects the many-qubit unitary
on the control and target qubits. The given 2x2 ComplexMatrix must be unitary, otherwise an error is thrown.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubits applies unitary if all qubits in this array equal 1 [in] numControlQubits number of control qubits [in] targetQubit qubit to operate on [in] u single-qubit unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if numControlQubits
is outside [1,qureg.numQubitsRepresented
]), or if any qubit index (targetQubit
or one incontrolQubits
) is outside [0,qureg.numQubitsRepresented
]), or if any qubit incontrolQubits
is repeated, or ifcontrolQubits
containstargetQubit
, or ifu
is not unitary.
Definition at line 374 of file QuEST.c.
References getConjugateMatrix2(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledUnitary(), statevec_multiControlledUnitary(), validateMultiControlsTarget(), and validateOneQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ multiQubitUnitary()
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 qubits.
The first target qubit in targs
is treated as least significant in u
. For example,
multiQubitUnitary(qureg, (int []) {a, b, c}, 3, u);
will invoke multiplication
The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.
Note that in multithreaded mode, each thread will clone 2^numTargs
amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^numTargs
. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).
Note too that in distributed mode, this routine requires that each node contains at least 2^numTargs
amplitudes in the register. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs
nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targs a list of the target qubits, ordered least significant to most in u
[in] numTargs the number of target qubits [in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if any index in targs
is outside of [0,qureg.numQubitsRepresented
), or iftargs
are not unique, or if matrixu
is not unitary, or ifu
is not of a compatible size withnumTargs
, or if a node cannot fit the required number of target amplitudes in distributed mode.
Definition at line 297 of file QuEST.c.
References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_multiQubitUnitary(), validateMultiQubitUnitaryMatrix(), and validateMultiTargets().
Referenced by TEST_CASE().
◆ multiRotatePauli()
void multiRotatePauli | ( | Qureg | qureg, |
int * | targetQubits, | ||
enum pauliOpType * | targetPaulis, | ||
int | numTargets, | ||
qreal | angle | ||
) |
Apply a multi-qubit multi-Pauli rotation on a selected number of qubits.
This is the unitary
where is a Pauli operator (indicated by codes 1, 2, 3 respectively in
targetPaulis
, or by enums PAULI_X, PAULI_Y and PAULI_Z) operating upon the qubit targetQubits
[j], and is the passed
angle
. The operators specified in targetPaulis
act on the corresponding qubit in targetQubits
. For example:
multiRotatePauli(qureg, (int[]) {4,5,8,9}, (int[]) {0,1,2,3}, 4, .1)
effects
on qureg
, where unspecified qubits (along with those specified with Pauli code 0) are assumed to receive the identity operator (excluded from exponentiation). Note that specifying the identity Pauli (code=0 or PAULI_I) on a qubit is superfluous but allowed for convenience. This is means a global phase factor of is NOT induced by supplying 0 pauli-codes. Hence, if all
targetPaulis
are identity, then this function does nothing to qureg
.
This function effects this unitary by first rotating the qubits which are nominated to receive X or Y Paulis into alternate basis, performing multiRotateZ on all target qubits receiving X, Y or Z Paulis, then restoring the original basis. In the worst case, this means that 1+2*numTargets
primitive unitaries are performed on the statevector, and double this on density matrices.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubits a list of the indices of the target qubits [in] targetPaulis a list of the Pauli codes (0=PAULI_I, 1=PAULI_X, 2=PAULI_Y, 3=PAULI_Z) to apply to the corresponding qubits in targetQubits
[in] numTargets number of target qubits, i.e. the length of targetQubits
andtargetPaulis
[in] angle the angle by which the multi-qubit state is rotated
- Exceptions
-
invalidQuESTInputError if numQubits
is outside [1,qureg.numQubitsRepresented
]), or if any qubit inqubits
is outside [0,qureg.numQubitsRepresented
)) or if any qubit inqubits
is repeated.
Definition at line 642 of file QuEST.c.
References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), shiftIndices(), statevec_multiRotatePauli(), validateMultiTargets(), and validatePauliCodes().
Referenced by TEST_CASE().
◆ multiRotateZ()
Apply a multi-qubit Z rotation on a selected number of qubits.
This is the unitary
where the Pauli Z gates operate upon the passed list
qubits
, and cause rotations of
angle
. All qubits not appearing in qubits
are assumed to receive the identity operator. This has the effect of premultiplying every amplitude with where the sign is determined by the parity of the target qubits for that amplitude.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] qubits a list of the indices of the target qubits [in] numQubits number of target qubits [in] angle the angle by which the multi-qubit state is rotated around the Z axis
- Exceptions
-
invalidQuESTInputError if numQubits
is outside [1,qureg.numQubitsRepresented
]), or if any qubit inqubits
is outside [0,qureg.numQubitsRepresented
]) or if any qubit inqubits
is repeated.
Definition at line 626 of file QuEST.c.
References getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_multiRotateZ(), and validateMultiTargets().
Referenced by TEST_CASE().
◆ multiStateControlledUnitary()
void multiStateControlledUnitary | ( | Qureg | qureg, |
int * | controlQubits, | ||
int * | controlState, | ||
int | numControlQubits, | ||
int | targetQubit, | ||
ComplexMatrix2 | u | ||
) |
Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary, which can include a global phase factor.
Any number of control qubits can be specified, along with which of their states (0 or 1) to condition upon; when the specified controls are in the specified state, the given unitary is applied to the target qubit. This is equivalent to NOTing the control bits which are conditioned on 0, calling multiControlledUnitary then NOTing the same control bits.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] controlQubits the indices of the control qubits [in] controlState the bit values (0 or 1) of each control qubit, upon which to condition [in] numControlQubits number of control qubits [in] targetQubit qubit to operate the unitary upon [in] u single-qubit unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if numControlQubits
is outside [1,qureg.numQubitsRepresented
]), or if any qubit index (targetQubit
or one incontrolQubits
) is outside [0,qureg.numQubitsRepresented
]), or if any qubit incontrolQubits
is repeated., or ifcontrolQubits
containstargetQubit
, or if any element of controlState is not a bit (0 or 1), or ifu
is not unitary.
Definition at line 389 of file QuEST.c.
References getConjugateMatrix2(), getControlFlipMask(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiStateControlledUnitary(), statevec_multiControlledUnitary(), validateControlState(), validateMultiControlsTarget(), and validateOneQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ pauliX()
void pauliX | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate.
This is a rotation of around the x-axis on the Bloch sphere. I.e.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 433 of file QuEST.c.
References GATE_SIGMA_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliX(), and validateTarget().
Referenced by TEST_CASE().
◆ pauliY()
void pauliY | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.
This is a rotation of around the Y-axis on the Bloch sphere. I.e.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 444 of file QuEST.c.
References GATE_SIGMA_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliY(), statevec_pauliYConj(), and validateTarget().
Referenced by TEST_CASE().
◆ pauliZ()
void pauliZ | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.
This is a rotation of around the Z-axis (a phase shift) on the Bloch sphere. I.e.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 455 of file QuEST.c.
References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliZ(), and validateTarget().
Referenced by TEST_CASE().
◆ phaseShift()
Shift the phase between and
of a single qubit by a given angle.
This is equivalent to a rotation Z-axis of the Bloch-sphere up to a global phase factor. For angle , applies
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to undergo a phase shift [in] angle amount by which to shift the phase in radians
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 488 of file QuEST.c.
References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_phaseShift(), and validateTarget().
Referenced by TEST_CASE().
◆ rotateAroundAxis()
Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere.
The vector must not be zero (else an error is thrown), but needn't be unit magnitude, since it will be normalised by QuEST.
For angle and axis vector
, applies
where
is the vector of Pauli matrices.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] rotQubit qubit to rotate [in] angle angle by which to rotate in radians [in] axis vector around which to rotate (can be non-unit; will be normalised)
- Exceptions
-
invalidQuESTInputError if rotQubit
is outside [0,qureg.numQubitsRepresented
), or ifaxis
is the zero vector
Definition at line 575 of file QuEST.c.
References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordAxisRotation(), statevec_rotateAroundAxis(), statevec_rotateAroundAxisConj(), validateTarget(), and validateVector().
Referenced by TEST_CASE().
◆ rotateX()
Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.
For angle , applies
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] rotQubit qubit to rotate [in] angle angle by which to rotate in radians
- Exceptions
-
invalidQuESTInputError if rotQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 188 of file QuEST.c.
References GATE_ROTATE_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateX(), and validateTarget().
Referenced by TEST_CASE().
◆ rotateY()
Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.
For angle , applies
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] rotQubit qubit to rotate [in] angle angle by which to rotate in radians
- Exceptions
-
invalidQuESTInputError if rotQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 199 of file QuEST.c.
References GATE_ROTATE_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateY(), and validateTarget().
Referenced by TEST_CASE().
◆ rotateZ()
Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase shift gate).
For angle , applies
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] rotQubit qubit to rotate [in] angle angle by which to rotate in radians
- Exceptions
-
invalidQuESTInputError if rotQubit
is outside [0,qureg.numQubitsRepresented
).
Definition at line 210 of file QuEST.c.
References GATE_ROTATE_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateZ(), and validateTarget().
Referenced by TEST_CASE().
◆ sGate()
void sGate | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit S gate.
This is a rotation of around the Z-axis on the Bloch sphere, or the unitary:
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate upon
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
)
Definition at line 466 of file QuEST.c.
References GATE_S, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_sGate(), statevec_sGateConj(), and validateTarget().
Referenced by TEST_CASE().
◆ sqrtSwapGate()
void sqrtSwapGate | ( | Qureg | qureg, |
int | qb1, | ||
int | qb2 | ||
) |
Performs a sqrt SWAP gate between qubit1
and qubit2
.
This effects
on the designated qubits, though is performed internally by three CNOT gates.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] qubit1 qubit to sqrt swap [in] qubit2 other qubit to sqrt swap
- Exceptions
-
invalidQuESTInputError if either qubit1
orqubit2
are outside [0,qureg.numQubitsRepresented
), or are equal.
Definition at line 613 of file QuEST.c.
References GATE_SQRT_SWAP, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_sqrtSwapGate(), statevec_sqrtSwapGateConj(), validateMultiQubitMatrixFitsInNode(), and validateUniqueTargets().
Referenced by TEST_CASE().
◆ swapGate()
void swapGate | ( | Qureg | qureg, |
int | qubit1, | ||
int | qubit2 | ||
) |
Performs a SWAP gate between qubit1
and qubit2
.
This effects
on the designated qubits, though is performed internally by three CNOT gates.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] qubit1 qubit to swap [in] qubit2 other qubit to swap
- Exceptions
-
invalidQuESTInputError if either qubit1
orqubit2
are outside [0,qureg.numQubitsRepresented
), or are equal.
Definition at line 601 of file QuEST.c.
References GATE_SWAP, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_swapQubitAmps(), and validateUniqueTargets().
Referenced by TEST_CASE().
◆ tGate()
void tGate | ( | Qureg | qureg, |
int | targetQubit | ||
) |
Apply the single-qubit T gate.
This is a rotation of around the Z-axis on the Bloch sphere, or the unitary:
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate upon
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
)
Definition at line 477 of file QuEST.c.
References GATE_T, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_tGate(), statevec_tGateConj(), and validateTarget().
Referenced by TEST_CASE().
◆ twoQubitUnitary()
void twoQubitUnitary | ( | Qureg | qureg, |
int | targetQubit1, | ||
int | targetQubit2, | ||
ComplexMatrix4 | u | ||
) |
Apply a general two-qubit unitary (including a global phase factor).
targetQubit1
is treated as the least
significant qubit in u
, such that a row in u
is dotted with the vector
For example,
twoQubitUnitary(qureg, a, b, u);
will invoke multiplication
The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.
Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit1 first qubit to operate on, treated as least significant in u
[in] targetQubit2 second qubit to operate on, treated as most significant in u
[in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if targetQubit1
ortargetQubit2
are outside [0,qureg.numQubitsRepresented
), or iftargetQubit1
equalstargetQubit2
, or matrixu
is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Definition at line 257 of file QuEST.c.
References getConjugateMatrix4(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_twoQubitUnitary(), validateMultiTargets(), and validateTwoQubitUnitaryMatrix().
Referenced by TEST_CASE().
◆ unitary()
void unitary | ( | Qureg | qureg, |
int | targetQubit, | ||
ComplexMatrix2 | u | ||
) |
Apply a general single-qubit unitary (including a global phase factor).
The passed 2x2 ComplexMatrix must be unitary, otherwise an error is thrown.
If qureg
is a state-vector, then the resulting state is . If
qureg
is a density-matrix , then the resulting state is
.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] targetQubit qubit to operate on [in] u unitary matrix to apply
- Exceptions
-
invalidQuESTInputError if targetQubit
is outside [0,qureg.numQubitsRepresented
), or matrixu
is not unitary.
Definition at line 349 of file QuEST.c.
References getConjugateMatrix2(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordUnitary(), statevec_unitary(), validateOneQubitUnitaryMatrix(), and validateTarget().
Referenced by TEST_CASE().