Operators

Gate operations in PyQuest-cffi

Provides operators for unitary and error prone time evolution on digital quantum computers.

pyquest_cffi.ops.ops Python classes for Quest functions
pyquest_cffi.ops.errors Error operation in PyQuest-cffi

Unitary

Python classes for Quest functions

class pyquest_cffi.ops.ops.MolmerSorensenXX(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Molmer Sorensen gate

Implements a fixed phase MolmerSorensen XX gate (http://arxiv.org/abs/1705.02771) Uses decomposition according to http://arxiv.org/abs/quant-ph/0507171

\[\begin{split}U = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 0 & i\\ 0 & 1 & i & 0\\ 0 & i & 1 & 0\\ i & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.applyDiagonalOp(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a diagonal operator to state

Apply a diagonal complex operator, which is possibly non-unitary and non-Hermitian, on the entire quantum register.

Parameters:
  • qureg – quantum register input, is not changed
  • operator – operator acting on a certain number of qubits (operator[0]: int) and in a certain QuEST environment (operator[1]: tquestenv)
call_interactive(qureg: Qureg, operator: Tuple[int, QuESTEnv]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • operator – operator acting on a certain number of qubits (operator[0]: int) and in a certain QuEST environment (operator[1]: tquestenv)
Raises:

RuntimeError – Qureg and DiagonalOp must be defined for the same number of qubits

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.applyMatrix2(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a general 2-by-2 matrix, which may be non-unitary

The matrix is left-multiplied onto the state, for both state-vectors and density matrices. Hence, this function differs from unitary() by more than just permitting a non-unitary matrix.

Parameters:
  • qureg – quantum register input, is not changed
  • qubit – qubit to operate the matrix upon
  • matrix – matrix to apply

Warning

After applyMatrix2 the quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit to operate the matrix upon
  • matrix – matrix to apply
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 2 by 2 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.applyMatrix4(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a general 4-by-4 matrix, which may be non-unitary

The matrix is left-multiplied onto the state, for both state-vectors and density matrices. Hence, this function differs from twoQubitUnitary() by more than just permitting a non-unitary matrix.

Parameters:
  • qureg – quantum register input, is not changed
  • control – qubit that controls the application of the matrix
  • qubit – qubit to operate the matrix upon
  • matrix – matrix to apply

Warning

After applyMatrix2 the quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, control: int, qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the matrix
  • qubit – qubit to operate the matrix upon
  • matrix – matrix to apply
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.applyMatrixN(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a general N-by-N matrix, which may be non-unitary, on any number of target qubits

The matrix is left-multiplied onto the state, for both state-vectors and density matrices. Hence, this function differs from multiQubitUnitary() by more than just permitting a non-unitary matrix.

Parameters:
  • qureg – quantum register input, is not changed
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate

Warning

After applyMatrixN the quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, targets: Sequence[int], matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
Raises:

RuntimeError – Shape of matrix and length of targets are different

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – N by N matrix that defines the N qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.applyMultiControlledMatrixN(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Apply a general N-by-N matrix, which may be non-unitary, with additional controlled qubits

A sum of products of Pauli operators (including Identity) is applied to a state. The state is not changed but the corresponding copy with the Pauli sum applied is written to qureg_out For each qubit a Pauli operator must be given in each sum term (can be identity)

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate

Warning

After applyMultiControlledMatrixN the quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, controls: Sequence[int], targets: Sequence[int], matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
Raises:

RuntimeError – Shape of matrix and length of targets are different

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – N by N matrix that defines the N qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.applyPauliHamil(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying PauliHamil (a Hermitian but not necessarily unitary operator) to state

This is merely an encapsulation of applyPauliSum(), which can refer to for elaborated doc. Applies each Pauli product in pauli_hamil to qureg in turn, and adding the resulting state to the initially-blanked qureg_out. Ergo it should scale with the total number of Pauli operators specified (excluding identities), and the qureg dimension.

Parameters:
  • qureg – quantum register input, is not changed
  • paulis – List of Lists of Pauli operators in each product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • matrix – N by N matrix that defines the N qubit gate
  • qureg_out – quantum register after application of Pauli sum

Warning

After applyPauliHamil the output quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, pauli_hamil: PauliHamil, qureg_out: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • pauli_hamil – PauliHamil instance to be applied
  • qureg_out – quantum register after application of Pauli sum
Raises:

RuntimeError – Qureg and PauliHamil must be defined for the same number of qubits

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.applyPauliSum(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a sum of Products of Pauli operators to state

A sum of products of Pauli operators (including Identity) is applied to a state. The state is not changed but the corresponding copy with the Pauli sum applied is written to qureg_out For each qubit a Pauli operator must be given in each sum term (can be identity)

Parameters:
  • qureg – quantum register input, is not changed
  • paulis – List of Lists of Pauli operators in each product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • coefficients – coefficients of the paulis to be summed
  • qureg_out – quantum register after application of Pauli sum

Warning

After applyPauliSum the quantum register is in general no longer normalised and does no longer represent a physical valid state without normalisation.

call_interactive(qureg: Qureg, paulis: Sequence[Sequence[int]], coefficients: Sequence[float], qureg_out: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • paulis – List of Lists of Pauli operators in each product encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • coefficients – coefficients of the paulis to be summed
  • qureg_out – quantum register after application of Pauli sum
Raises:
  • RuntimeError – Size of Qureg and number of lenght of PauliProduct does not match
  • ValueError – Pauli arrays need to only have values in [0, 1, 2, 3]
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.applyTrotterCircuit(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a trotterisation of unitary evolution exp(-i*pauli_hamil*time) to qureg

This is a sequence of unitary operators, effected by multiRotatePauli(), which together approximate the action of full unitary-time evolution under the given Hamiltonian. These formulations are taken from ‘Finding Exponential Product Formulas of Higher Orders’, Naomichi Hatano and Masuo Suzuki (2005).

Parameters:
  • qureg – the register to modify under the approximate unitary-time evolution
  • pauli_hamil – PauliHamil under which to approxiamte unitary-time evolution
  • time – the target evolution time, which is permitted to be both positive and negative
  • order – the order of Trotter-Suzuki decomposition to use
  • repetitions – the number of repetitions of the decomposition of the given order
call_interactive(qureg: Qureg, pauli_hamil: PauliHamil, time: float, order: int, repetitions: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – the register to modify under the approximate unitary-time evolution
  • pauli_hamil – PauliHamil under which to approxiamte unitary-time evolution
  • time – the target evolution time, which is permitted to be both positive and negative
  • order – the order of Trotter-Suzuki decomposition to use
  • repetitions – the number of repetitions of the decomposition of the given order
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.collapseToOutcome(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Updates qureg to be consistent with measuring measureQubit and returns the probability.

Parameters:
  • qureg – quantum register
  • qubit – the measured qubit
  • outcome – where to set the probability of the occurred outcome
call_interactive(qureg: Qureg, qubit: int, outcome: int) → float[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • outcome – where to set the probability of the occurred outcome
Returns:

float

class pyquest_cffi.ops.ops.compactUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements general unitary gate U in compact notation

\[\begin{split}U = \begin{pmatrix} \alpha & -\beta^{*}\\ \beta & \alpha^{*} \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
call_interactive(qureg: Qureg, qubit: int, alpha: complex, beta: complex) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
Raises:

RuntimeError – compactUnitary needs parameters |alpha|**2+|beta|**2 == 1

matrix(alpha: complex, beta: complex, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledCompactUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled general unitary gate U in compact notation

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \alpha & -\beta^{*}\\ 0 & 0 & \beta & \alpha^{*} \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
call_interactive(qureg: Qureg, control: int, qubit: int, alpha: complex, beta: complex) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
Raises:

RuntimeError – compactUnitary needs parameters |alpha|**2+|beta|**2 == 1

matrix(alpha: complex, beta: complex, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • alpha – complex parameter \(\alpha\) of the unitary matrix
  • beta – complex parameter \(\beta\) of the unitary matrix
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledMultiQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Controlled general unitary gate acting on N qubits

Implements a general N-qubit gate defined by a matrix and controlled by a third qubit If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • control – controll qubit
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
call_interactive(qureg: Qureg, control: int, targets: Sequence[int], matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – controll qubit
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
Raises:

RuntimeError – Shape of matrix and length of targets are different

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|xy> |1xy> -> |1> U |xy>

Parameters:
  • matrix – N by N matrix that defines the N qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledNot(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled NOT gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0x> -> |0>|x> |1x> -> |1> NOT |x>

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.controlledPauliY(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled PauliY gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & -i\\ 0 & 0 & i & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.controlledPhaseFlip(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled phase flip gate also known as controlled Z gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.controlledPhaseShift(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled phase flip shift also known as controlled Z power gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & e^{i\theta} \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – The angle of the controlled Z-rotation
call_interactive(qureg: Qureg, control: int, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – The angle of the controlled Z-rotation
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • theta – The angle of the controlled Z-rotation
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledRotateAroundAxis(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Rotation around a general axis.

Implements a controlled rotation around a vector \(\vec{v}\) \(e^{-i \frac{\theta}{2} \vec{v} \vec{\sigma}}\)

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos(\frac{\theta}{2}) & 0\\ 0 & 0 & 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 0 & 0 & -i \sin(\frac{\theta}{2}) v_z & \sin(\frac{\theta}{2}) \left(-i v_x - v_y \right)\\ 0 & 0 & \sin(\frac{\theta}{2}) \left(-i v_x + v_y \right) & i \sin(\frac{\theta}{2}) v_z) \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
call_interactive(qureg: Qureg, control: int, qubit: int, theta: float, vector: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
Raises:

RuntimeError – vector needs to be a three component numpy array and unit-vector

matrix(theta: float, vector: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledRotateX(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled rotation around the X axis

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos(\frac{\theta}{2}) & 0\\ 0 & 0 & 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & -i \sin(\frac{\theta}{2}) \\ 0 & 0 & -i \sin(\frac{\theta}{2}) & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
call_interactive(qureg: Qureg, control: int, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • theta – Angle theta of the rotation
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledRotateY(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled rotation around the Y axis `

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos(\frac{\theta}{2}) & 0\\ 0 & 0 & 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & - \sin(\frac{\theta}{2}) \\ 0 & 0 & \sin(\frac{\theta}{2}) & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
call_interactive(qureg: Qureg, control: int, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • theta – Angle theta of the rotation
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledRotateZ(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled rotation around the Y axis `

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos(\frac{\theta}{2}) & 0\\ 0 & 0 & 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0\\ 0 & 0 & - i \sin(\frac{\theta}{2}) & 0 \\ 0 & 0 & 0 & i \sin(\frac{\theta}{2}) \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
call_interactive(qureg: Qureg, control: int, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • theta – Angle theta of the rotation
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledTwoQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Controlled two qubit unitary gate

Implements a general two-qubit gate defined by a matrix controlled by a third qubit If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • control – controll qubit
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
call_interactive(qureg: Qureg, control: int, target_qubit_1: int, target_qubit_2: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – controll qubit
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|xy> |1xy> -> |1> U |xy>

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.controlledUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a controlled arbitraty one-qubit gate given by a unitary matrix

Parameters:
  • qureg – quantum register
  • control – qubit that controls the unitary
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
call_interactive(qureg: Qureg, control: int, qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the unitary
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
Raises:

RuntimeError – vector needs to be a (2, 2) unitary numpy array

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

The control qubit is always assumed to be the most relevant qubit |0xy> -> |0>|x> |1x> -> |1> U |x>

Parameters:
  • matrix – Unitary matrix of the one qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.hadamard(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements Hadamard gate

\[\begin{split}U = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.invSqrtISwap(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements inverse square root ISwap gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \frac{1}{\sqrt{2}} & \frac{-i}{\sqrt{2}} & 0\\ 0 & \frac{-i}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.measure(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a one-qubit Measurement operation

Parameters:
  • qureg – quantum register
  • qubit – the measured qubit
  • readout – The readout register for static compilation
  • readout_index – The index in the readout register for static compilation
call_interactive(qureg: Qureg, qubit: int) → int[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
Returns:

int

class pyquest_cffi.ops.ops.measureWithStats(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Measures a single qubit and gives the probability of that outcome.

Parameters:
  • qureg – quantum register
  • qubit – the measured qubit
  • outcome_proba – where to set the probability of the occurred outcome
call_interactive(qureg: Qureg, qubit: int, outcome_proba: float) → int[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • outcome_proba – where to set the probability of the occurred outcome
Returns:

int

class pyquest_cffi.ops.ops.multiControlledMultiQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

General N-qubit unitary gate controlled by multiple qubits

Implements a general N-qubit gate defined by a matrix controlled by multipe qubits If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
call_interactive(qureg: Qureg, controls: Sequence[int], targets: Sequence[int], matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
Raises:

RuntimeError – Shape of matrix and length of targets are different

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiControlledPhaseFlip(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Phase Flip controlled by multipe qubits

Implements a multi controlled phase flip gate also known as controlled Z gate. If all qubits in the controls are \(\left|1\right\rangle\) the sign is flipped. No change occurs otherwise

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • number_controls – number of the control qubits
call_interactive(qureg: Qureg, controls: Sequence[int], number_controls: Optional[int] = None) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • number_controls – number of the control qubits
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Raises:NotImplementedError – not implemented
class pyquest_cffi.ops.ops.multiControlledPhaseShift(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Phase Shift controlled by multiple qubits

Implements a multi controlled phase flip gate also known as controlled Z power gate. If all qubits in the controls are \(\left|1\right\rangle\) the phase is shifter by theta. No change occurs otherwise

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • number_controls – number of the control qubits
  • theta – Angle of the rotation around Z-axis
call_interactive(qureg: Qureg, controls: Sequence[int], number_controls: Optional[int] = None, theta: float = 0) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • number_controls – number of the control qubits
  • theta – Angle of the rotation around Z-axis
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle of the rotation around Z-axis
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiControlledTwoQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Two qubit unitary gate controlled by multiple qubits

Implements a general two-qubit gate defined by a matrix controlled by multipe qubits If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • control – controll qubit
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
call_interactive(qureg: Qureg, controls: Sequence[int], target_qubit_1: int, target_qubit_2: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – control qubits
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiControlledUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Generic unitary gate controlled by multiple qubits

Implements a multi-controlled arbitraty one-qubit gate given by a unitary matrix

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
call_interactive(qureg: Qureg, controls: Sequence[int], qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – qubits that control the application of the unitary
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
Raises:

RuntimeError – vector needs to be a (2, 2) unitary numpy array

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – Unitary matrix of the one qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

General unitary gate acting on N qubits

Implements a general N-qubit gate defined by a matrix If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
call_interactive(qureg: Qureg, targets: Sequence[int], matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
Raises:

RuntimeError – Shape of matrix and length of targets are different

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – N by N matrix that defines the N qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.multiRotatePauli(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a set of different Pauli rotations to multiple qubits

A set of Pauli rotations with a given angle is applied to multiple qubits

Parameters:
  • qureg – quantum register
  • qubits – target qubits
  • paulis – Pauli operators encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • matrix – N by N matrix that defines the N qubit gate
call_interactive(qureg: Qureg, qubits: Sequence[int], paulis: Sequence[int], angle: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubits – target qubits
  • paulis – Pauli operators encoded as int via IDENTITY=0, PAULI_X=1, PAULI_Y=2, PAULI_Z=3
  • angle – Angle of rotation of paulis
Raises:

RuntimeError – Number of qubits different from number of applied Paulis

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiRotateZ(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Applying a Z-Rotation to multiple qubits

A Z-Rotation with a given angle is applyied to multiple qubits

Parameters:
  • qureg – quantum register
  • qubits – target qubits
  • targets – list of target qubits of the N qubit gate the first qubit in targets is treated as the least significant one the second as the second least significant one etc.
  • matrix – N by N matrix that defines the N qubit gate
call_interactive(qureg: Qureg, qubits: Sequence[int], angle: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubits – target qubits
  • angle – Angle of rotation of the RotateZ gate
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.multiStateControlledUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

One qubit unitary controlled by multiple states

Implements a general one-qubit gate defined by a matrix controlled by the state of multiple qubits Contrary to the multiControlled function the unitary operation here can be executed either when the controlling qubit is in state |0> or in state |1> depending on the control_states

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • controll_states – list of ints defining if the controlling gate acts like a a normal control or anti-control (unitary is applied when state is |0>) For each entry: 1 -> normal controlled, 0 -> anti-controlled
  • qubit – The qubit the unitary is acting on
  • matrix – 2 by 2 matrix that defines the one qubit gate
call_interactive(qureg: Qureg, controls: Sequence[int], control_states: Sequence[int], qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • controls – controll qubits
  • control_states – list of ints defining if the controlling gate acts like a a normal control or anti-control (unitary is applied when state is |0>) For each entry: 1 -> normal controlled, 0 -> anti-controlled
  • qubit – The qubit the unitary is acting on
  • matrix – 2 by 2 matrix that defines the one qubit gate
Raises:

RuntimeError – Different Number of controls and control states

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.ops.pauliX(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements Pauli X gate

\[\begin{split}U = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.pauliY(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements Pauli Y gate

\[\begin{split}U = \begin{pmatrix} 0 & -i\\ i & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.pauliZ(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements Pauli Z gate

\[\begin{split}U = \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.phaseShift(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements pure \(\left|1 \right\rangle\) phase shift gate

\[\begin{split}U = \begin{pmatrix} 1 & 0\\ 0 & e^{i \theta} \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the ro
call_interactive(qureg: Qureg, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the ro
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the ro
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.rotateAroundAxis(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements rotation around arbitraty axis on Bloch sphere

\[\begin{split}U = \begin{pmatrix} \cos(\frac{\theta}{2}) & 0\\ 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} -i \sin(\frac{\theta}{2}) v_z & \sin(\frac{\theta}{2}) \left(-i v_x - v_y \right) \\ \sin(\frac{\theta}{2}) \left(-i v_x + v_y \right) & i \sin(\frac{\theta}{2}) v_z) \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
call_interactive(qureg: Qureg, qubit: int, theta: float, vector: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
Raises:

RuntimeError – vector needs to be a three component numpy array and unit-vector

matrix(theta: float, vector: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.rotateAroundSphericalAxis(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements rotation around an axis given in spherical coordinates

\[\begin{split}U &= \begin{pmatrix} \cos(\frac{\theta}{2}) & 0\\ 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} -i \sin(\frac{\theta}{2}) v_z & \sin(\frac{\theta}{2}) \left(-i v_x - v_y \right) \\ \sin(\frac{\theta}{2}) \left(-i v_x + v_y \right) & i \sin(\frac{\theta}{2}) v_z) \end{pmatrix}\\ v_x &= \sin(\theta_{sph}) \cos(\phi_{sph})\\ v_y &= \sin(\theta_{sph}) \sin(\phi_{sph})\\ v_z &= \cos(\theta_{sph})\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • spherical_theta – Rotation axis, unit-vector spherical coordinates theta
  • spherical_phi – Rotation axis, unit-vector spherical coordinates phi
call_interactive(qureg: Qureg, qubit: int, theta: float, spherical_theta: float, spherical_phi: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation
  • spherical_theta – Rotation axis, unit-vector spherical coordinates theta
  • spherical_phi – Rotation axis, unit-vector spherical coordinates phi
matrix(theta: float, vector: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the rotation
  • vector – Direction of the rotation axis, unit-vector
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.rotateX(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements \(e^{-i \frac{\theta}{2} \sigma^x}\) XPower gate

\[\begin{split}U = \begin{pmatrix} \cos(\frac{\theta}{2}) & 0\\ 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & -i \sin(\frac{\theta}{2}) \\ -i \sin(\frac{\theta}{2}) & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
call_interactive(qureg: Qureg, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.rotateY(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements \(e^{-i \frac{\theta}{2} \sigma^y}\) XPower gate

\[\begin{split}U = \begin{pmatrix} \cos(\frac{\theta}{2}) & 0\\ 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} 0 & - \sin(\frac{\theta}{2}) \\ \sin(\frac{\theta}{2}) & 0 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
call_interactive(qureg: Qureg, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.rotateZ(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements \(e^{-i \frac{\theta}{2} \sigma^z}\) XPower gate

\[\begin{split}U = \begin{pmatrix} \cos(\frac{\theta}{2}) & 0\\ 0 & \cos(\frac{\theta}{2}) \end{pmatrix} + \begin{pmatrix} - i \sin(\frac{\theta}{2}) & 0 \\ 0 & i \sin(\frac{\theta}{2}) \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
call_interactive(qureg: Qureg, qubit: int, theta: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
matrix(theta: float, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • theta – Angle theta of the rotation, in interval 0 to 2 \(2 \pi\)
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.sGate(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements S gate

\[\begin{split}U = \begin{pmatrix} 1 & 0\\ 0 & i \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.sqrtISwap(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a square root ISwap gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \frac{1}{\sqrt{2}} & \frac{i}{\sqrt{2}} & 0\\ 0 & \frac{i}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.sqrtSwapGate(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a square root SWAP gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \frac{1}{2}(1+i) & \frac{1}{2}(1-i) & 0\\ 0 & \frac{1}{2}(1-i) & \frac{1}{2}(1+i) & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.swapGate(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements a SWAP gate

\[\begin{split}U = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, control: int, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • control – qubit that controls the application of the unitary
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.tGate(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements T gate

\[\begin{split}U = \begin{pmatrix} 1 & 0\\ 0 & e^{i \frac{\pi}{4}} \end{pmatrix}\end{split}\]
Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
call_interactive(qureg: Qureg, qubit: int) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
matrix(**kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:**kwargs – Additional keyword arguments
Returns:np.ndarray
class pyquest_cffi.ops.ops.twoQubitUnitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

General two qubit unitary gate

Implements a general two-qubit gate defined by a matrix If the matrix basis states are given by 0=|00> 1=|01> 2=|10> 3=|11> the least significant qubit is the right qubit and the most significant qubit is the left qubit

Parameters:
  • qureg – quantum register
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
call_interactive(qureg: Qureg, target_qubit_1: int, target_qubit_2: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • target_qubit_1 – least significant qubit
  • target_qubit_2 – most sifnificant qubit
  • matrix – 4 by 4 matrix that defines the two qubit gate
matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – 4 by 4 matrix that defines the two qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.ops.unitary(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Implements an arbitraty one-qubit gate given by a unitary matrix

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
call_interactive(qureg: Qureg, qubit: int, matrix: numpy.ndarray) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register
  • qubit – qubit the unitary gate is applied to
  • matrix – Unitary matrix of the one qubit gate
Raises:

RuntimeError – matrix needs to be a (2, 2) unitary numpy array

matrix(matrix: numpy.ndarray, **kwargs) → numpy.ndarray[source]

The definition of the gate as a unitary matrix

Parameters:
  • matrix – Unitary matrix of the one qubit gate
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

Errors

Error operation in PyQuest-cffi

class pyquest_cffi.ops.errors.applyOneQubitDampingError(*args, **kwargs)[source]

Bases: pyquest_cffi.ops.errors.mixDamping

One Qubit Damping - deprecated

Initialisation

Parameters:
  • *args – Arguments
  • **kwargs – Additional keyword arguments
class pyquest_cffi.ops.errors.applyOneQubitDephaseError(*args, **kwargs)[source]

Bases: pyquest_cffi.ops.errors.mixDephasing

One Qubit Dephasing - deprecated

Initialisation

Parameters:
  • *args – Arguments
  • **kwargs – Additional keyword arguments
class pyquest_cffi.ops.errors.applyOneQubitDepolariseError(*args, **kwargs)[source]

Bases: pyquest_cffi.ops.errors.mixDepolarising

One Qubit Depolarisation - deprecated

Initialisation

Parameters:
  • *args – Arguments
  • **kwargs – Additional keyword arguments
class pyquest_cffi.ops.errors.applyTwoQubitDephaseError(*args, **kwargs)[source]

Bases: pyquest_cffi.ops.errors.mixTwoQubitDephasing

Two Qubit Dephasing - deprecated

Initialisation

Parameters:
  • *args – Arguments
  • **kwargs – Additional keyword arguments
class pyquest_cffi.ops.errors.applyTwoQubitDepolariseError(*args, **kwargs)[source]

Bases: pyquest_cffi.ops.errors.mixTwoQubitDepolarising

Two Qubit Depolarisation - deprecated

Initialisation

Parameters:
  • *args – Arguments
  • **kwargs – Additional keyword arguments
class pyquest_cffi.ops.errors.mixDamping(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

One qubit damping error

Apply a pure damping error corresponding to zero temperature environments

\[\begin{split}\rho &= \mathcal{K} \rho \mathcal{K}\\\end{split}\]
Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The damped qubit
  • probability – The probability/ relative amplitude with which the dephasing occurs
Kraus_matrices(probability: float, **kwargs) → Tuple[numpy.ndarray, numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit: int, probability: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The damped qubit
  • probability – The probability/relative amplitude with which the dephasing occurs
Raises:

RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used

superoperator_matrix(probability: float, **kwargs) → numpy.ndarray[source]

The definition of the Superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixDensityMatrix(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Modifies qureg to become (1-probability)*qureg + probability*qureg_other

Both registers must be equal-dimension density matrices, and prob must be in [0, 1].

Parameters:
  • qureg – quantum register to be modified
  • probability – the probability of qureg_other in the modified qureg
  • qureg_other – the quantum register to be mixed into qureg
Kraus_matrices(probability: float, **kwargs) → Tuple[numpy.ndarray, numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

call_interactive(qureg: Qureg, probability: float, qureg_other: Qureg) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – quantum register to be modified
  • probability – the probability of qureg_other in the modified qureg
  • qureg_other – the quantum register to be mixed into qureg
Raises:
  • RuntimeError – Both quregs must be density matrix, but at least one of them is a wavefunction
  • RuntimeError – Qureg and Qureg_other must be defined for the same number of qubits
superoperator_matrix(probability: float, **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.errors.mixDephasing(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

One qubit dephasing error

Apply the dephasing \(\sigma^z\) operator to a qubit q with probability p
Can also be expressed as a Kraus operator \(\mathcal{K}\)
\[\begin{split}\rho &= (1-p) \rho + p \sigma^z_q \rho \sigma^z_q \\ \rho &= \mathcal{K} \rho \mathcal{K} \\ \vec{\rho} &= \mathcal{L} \vec{\rho} \\ \mathcal{L} &= \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1-2p & 0 & 0\\ 0 & 0 & 1-2p & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Kraus_matrices(probability: float, **kwargs) → Tuple[numpy.ndarray, numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit: int, probability: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit dephasing
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
Raises:
  • RuntimeError – Probability of mixDephasing needs to be smaller that 1/2
  • RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
superoperator_matrix(probability: float, **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixDepolarising(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

One qubit depolarisation error

Apply the depolarisation operators \(\sigma^x\), \(\sigma^y\) and \(\sigma^z\) to a qubit q with an evenly distributed probability p`

\[\rho = (1-p) \rho + \frac{p}{3} \left( \sigma^x_q \rho \sigma^x_q + \sigma^y_q \rho \sigma^y_q + \sigma^z_q \rho \sigma^z_q \right)\]
Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit depolarising
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 3/4
Kraus_matrices(probability: float, **kwargs) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit: int, probability: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit depolarising
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
Raises:
  • RuntimeError – Probability of mixDepolarising needs to be smaller that 3/4
  • RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
superoperator_matrix(probability: float, **kwargs) → numpy.ndarray[source]

The definition of the Superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixKrausMap(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

General error affecting one qubit

An error acting on one qubit is defined by a set of Kraus operators

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit the Kraus operators are acting on
  • operators – The Kraus operators
Kraus_matrices(operators: Sequence[numpy.ndarray], **kwargs) → Sequence[numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit: int, operators: Sequence[numpy.ndarray]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit the Kraus operators are acting on
  • operators – The Kraus operators
Raises:
  • RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
  • RuntimeError – Target qubit is not in the Qureg
  • RuntimeError – Too many operators given, must be in [1, 4]
  • RuntimeError – Number of target qubits and dimension of Kraus operators mismatch
  • RecursionError – Not a valid Kraus map
superoperator_matrix(operators: Sequence[numpy.ndarray], **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixMultiQubitKrausMap(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Error affecting multiple qubits

An error acting on multiple qubtis simultaneously is defined by a set of Kraus operators

Parameters:
  • qureg – a qureg containing a density matrix
  • qubits – The qubits the Kraus operators are acting on
  • operators – The Kraus operators
Kraus_matrices(operators: Sequence[numpy.ndarray], **kwargs) → Sequence[numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubits: Sequence[int], operators: Sequence[numpy.ndarray]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubits – The qubits the Kraus operators are acting on
  • operators – The Kraus operators
Raises:
  • RuntimeError – Number of target qubits and dimension of Kraus operators mismatch
  • RuntimeError – Not a valid Kraus map
superoperator_matrix(operators: Sequence[numpy.ndarray], **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixPauli(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Error on qubit defined by three Pauli operator weights

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit the Pauli operators are acting on
  • probX – The probability that Pauli X is acting on qubit as Kraus operator
  • probY – The probability that Pauli Y is acting on qubit as Kraus operator
  • probZ – The probability that Pauli Z is acting on qubit as Kraus operator
Kraus_matrices(probX: float, probY: float, probZ: float, **kwargs) → List[numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probX – The probability that Pauli X is acting on qubit as Kraus operator
  • probY – The probability that Pauli Y is acting on qubit as Kraus operator
  • probZ – The probability that Pauli Z is acting on qubit as Kraus operator
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit: int, probX: float, probY: float, probZ: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit – The qubit the Pauli operators are acting on
  • probX – The probability that Pauli X is acting on qubit as Kraus operator
  • probY – The probability that Pauli Y is acting on qubit as Kraus operator
  • probZ – The probability that Pauli Z is acting on qubit as Kraus operator
superoperator_matrix(probX: float, probY: float, probZ: float, **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

Parameters:
  • probX – The probability that Pauli X is acting on qubit as Kraus operator
  • probY – The probability that Pauli Y is acting on qubit as Kraus operator
  • probZ – The probability that Pauli Z is acting on qubit as Kraus operator
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

class pyquest_cffi.ops.errors.mixTwoQubitDephasing(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Two qubit dephasing error

Apply the dephasing \(\sigma^z\) operator to two qubits q1 and q2 with probability p
Can also be expressed as a Kraus operator \(\mathcal{K}\)
\[\begin{split}\rho &= (1-p) \rho + \frac{p}{3} \left( \sigma^z_{q1} \rho \sigma^z_{q1} + \sigma^z_{q2} \rho \sigma^z_{q2} + \sigma^z_{q1}\sigma^z_{q2} \rho \sigma^z_{q2} \sigma^z_{q1} \right)\\ \rho &= \mathcal{K} \rho \mathcal{K}\end{split}\]
Parameters:
  • qureg – a qureg containing a density matrix
  • qubit1 – The first qubit dephasing
  • qubit2 – The second qubit dephasing
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 3/4
Kraus_matrices(probability: float, **kwargs) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, qubit1: int, qubit2: int, probability: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit1 – The first qubit dephasing
  • qubit2 – The second qubit dephasing
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 3/4
Raises:
  • RuntimeError – Probability of twoQubitDepolariseErrors needs to be smaller that 3/4
  • RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
superoperator_matrix(probability: float, **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray

Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.errors.mixTwoQubitDepolarising(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Two qubit depolarisation error

Apply any tensor product of two operators \(U\) \(\sigma^x\), \(\sigma^y\) and \(\sigma^z\) to two qubits q1 and q2 with an evenly distributed probability p`

\[\begin{split}\rho &= (1-p) \rho + \frac{p}{15} \sum_{A, B \in \{ I, \sigma^x, \sigma^y, \sigma^z\}} A_{q1}B_{q2} \rho B_{q2}A_{q1} \\ \rho &= \mathcal{K} \rho \mathcal{K}\end{split}\]
Parameters:
  • qureg – a qureg containing a density matrix
  • qubit1 – The first qubit dephasing
  • qubit2 – The second qubit dephasing
  • probability – The probability/ relative amplitude with which the depolarisation occurs. Needs to be smaller than \(\frac{15}{16}\)
call_interactive(qureg: Qureg, qubit1: int, qubit2: int, probability: float) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • qubit1 – The first qubit dephasing
  • qubit2 – The second qubit dephasing
  • probability – The probability/ relative amplitude with which the depolarisation occurs. Needs to be smaller than \(\frac{15}{16}\)
Raises:
  • RuntimeError – Probability of twoQubitDepolariseErrors needs to be smaller that 15/16
  • RuntimeError – Qureg has to be a density matrix qureg but wavefunction qureg was used
superoperator_matrix(probability: float, **kwargs) → None[source]

The definition of the superoperator acting on the density matrix written as a vector

\[\begin{split}\rho = A \rho B \\ \vec{\rho} = \mathcal{L} \vec{\rho}\end{split}\]

where A and B are arbitrary matrices

Parameters:
  • probability – The probability/ relative amplitude with which the dephasing occurs, probability needs to be smaller than 1/2
  • **kwargs – Additional keyword arguments
Raises:

NotImplementedError – not implemented

class pyquest_cffi.ops.errors.mixTwoQubitKrausMap(interactive: bool = True)[source]

Bases: pyquest_cffi.questlib._abstract._PYQUEST

Error affecting two qubits

An error acting on two qubtis simultaneously is defined by a set of Kraus operators

Parameters:
  • qureg – a qureg containing a density matrix
  • target_qubit_1 – The least significant qubit the Kraus operators are acting on
  • target_qubit_2 – The most significant qubit the Kraus operators are acting on
  • operators – The Kraus operators
Kraus_matrices(operators: Sequence[numpy.ndarray], **kwargs) → Sequence[numpy.ndarray][source]

The definition of the Kraus Operator as a matrix

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

Tuple[np.ndarray]

call_interactive(qureg: Qureg, target_qubit_1: Sequence[int], target_qubit_2: Sequence[int], operators: Sequence[numpy.ndarray]) → None[source]

Interactive call of PyQuest-cffi

Parameters:
  • qureg – a qureg containing a density matrix
  • target_qubit_1 – The least significant qubit the Kraus operators are acting on
  • target_qubit_2 – The most significant qubit the Kraus operators are acting on
  • operators – The Kraus operators
Raises:
  • RuntimeError – Number of target qubits and dimension of Kraus operators mismatch
  • RuntimeError – Not a valid Kraus map
superoperator_matrix(operators: Sequence[numpy.ndarray], **kwargs) → numpy.ndarray[source]

The definition of the superoperator acting on the density matrix written as a vector

Parameters:
  • operators – The Kraus operators
  • **kwargs – Additional keyword arguments
Returns:

np.ndarray