API#

Submodules#

pyquest.core module#

Classes and attributes for the core functionality of pyQuEST.

This module contains classes that are needed for the core tasks of pyQuEST, like the QuEST environment and register, as well as some useful properties.

np_qreal#

Numpy equivalent to the precision of real float in the QuEST backend (qreal).

Type:

type

np_qcomp#

Numpy equivalent to the precision of the complex float type in QuEST (qcomp).

Type:

type

Classes:

QuESTEnvironment: Holds internals for the QuEST backend. Register: A quantum register holding a number of qubits. Circuit: A collection of operators to be applied to a Register at once.

class Circuit(operators=None)#

Bases: GlobalOperator

A collection of quantum operations in sequence.

For now, this class is just a glorified list of objects derived from BaseOperator, but will get more useful features in the future.

Create a new Circuit from an iterable of gates.

Parameters:

operators (iterable[BaseOperator]) – The individual operators to wrap in a Circuit.

inverse#

The inverse of a Circuit.

Can only be returned if every contained opartor itself has the inverse property implemented.

remove(self, op)#

Remove operator op from the self

class QuESTEnvironment#

Bases: object

Class holding internals for the QuEST library.

QuEST needs a QuESTEnv struct to create and destroy registers and other data structures, and this class wraps such a struct for pyQuEST to use for its operations. There should never be the need for the user to create an instance of this class, it should only be instantiated once by the __init__.py of the package.

Registers created in a QuESTEnvironment are tracked with weak references and destroyed before closing the environment.

A QuESTEnvironment object also holds information about the execution environment of QuEST, like number of threads, whether GPU acceleration is enabled, etc. These are object properties.

close_env(self)#

Close the QuEST environment.

Does not need to be called by the user during normal operation and has mainly debug purposes.

cuda#

Get whether the execution is GPU accelerated.

env_capsule#
logged_registers#

Get all alive registers created with this environment.

mpi#

Get whether distributed execution is enabled.

num_ranks#

Get the number of distributed processes in distributed mode.

Each rank is processed on a single node, but may utilise multiple local threads.

num_threads#

Get the number of threads for execution.

openmp#

Get whether multithreading is enabled.

precision#

Get the precision of the QuEST floating point data type.

Amplitudes and other variables in the QuEST library are stored in a float data type, whose size can be defined at compile time to be single (1), double (2), or quad (4) precision.

rank#

Get the rank of the host process in an MPI environment.

The rank can be used to identify a specific process within an MPI execution environment and execute code in only one of these processes. This is useful for printing messages and accessing the file system.

class Register(num_qubits=-1, density_matrix=False, copy_reg=None)#

Bases: object

A quantum register holding a quantum state.

Stores the amplitudes of a quantum states for a given number of qubits, either as a pure state vector, or a density matrix.

Create new register from scratch or copy an existing state.

Parameters:
  • num_qubits (int) – Number of qubits in the register. For density matrices the number of qubits internally required to represent the state is 2 * num_qubits. Must not be passed if copy_reg is not None.

  • density_matrix (bool) – True if the register should represent a density matrix, False otherwise. Ignored if copy_reg is not None. Defaults to False.

  • copy_reg (Register) – If given and not None, makes the newly created register an exact copy of copy_reg.

apply_circuit(self, Circuit circ)#

Apply a Circuit to the stored state.

If the circuit contains any measurements, their outcomes are returned as a (nested) list.

apply_operator(self, BaseOperator op)#

Apply a single quantum operator to the stored state.

If the operator is a measurement, returns the measured outcomes as a list.

copy(self) Register#

Return a new Register with a copy of the state.

copy_from(self, Register other) void#

Copy the state from another Register.

The other register must have the same number of qubits and be of the same type (state vector or density matrix).

copy_to(self, Register other) void#

Copy the state to another Register.

The other register must have the same number of qubits and be of the same type (state vector or density matrix).

destroy_reg(self)#

Free the resources of the underlying data structure.

Destroys the QuEST register and frees its resources. Memory is automatically freed when the object is garbage collected, but users may sometimes want to free a register manually. If the register has already been freed, do nothing.

fidelity(self, Register other) qreal#

Calculate fidelity with the pure state in another register.

Raises:

QuESTError – If other register is not a state vector.

init_blank_state(self)#

Set all amplitudes to zero.

inner_product(self, Register other) double complex#

Calculate the inner product of self with another state.

If both self and other are state vectors, returns the regular inner product of the vectors. If both are density matrices, returns the Hilbert-Schmidt inner product.

Raises:

QuESTError – If self and other are not both state vecotrs or both density matrices.

is_alive#

Return whether the underlying QuEST structure is valid.

is_density_matrix#

Return whether the register represents a density matrix.

num_amps#

Return the number of amplitudes stored in the register.

This is given by 2 ** num_qubits for pure states, and 2 ** (2 * num_qubits) for density matrices.

num_qubits#

Return the number of qubits in the register.

prob_of_all_outcomes(self, qubits)#

Calculate probabilities of all measurement outcomes.

For all possible states of the sub-register given by qubits, the probability of measuring each of the states is calculated and returned in an array.

Parameters:

qubits (int | array_like[int]) – An object, that numpy can convert into an array. That array will be flattened, and its elements are the indices of qubits to consider for the measurement outcomes. For the purpose of indexing the output array, the entries of qubits are considered to be in _increasing_ order of significance. The qubits need not be contiguous or in any specific order.

Returns:

Probabilities of measuring each output.

The elements in the returned array are ordered such that the qubits in qubits are ordered from low to high significance. The following table illustrates this by mapping the index in the returned array k to the measurement output corresponding to that index.

k

qubits[2]

qubits[1]

qubits[0]

0

0

0

0

1

0

0

1

2

0

1

0

3

0

1

1

4

1

0

0

Index 2 of the returned array, for example, contains the probability of measuring only qubits[1] in state 1, and all other qubits in state 0. The element at index 3 gives the probability of measuring both qubit[0] and qubit[1] in state 1, and all others in state 0.

The returned array has a size of 2**len(qubits).

Return type:

np.ndarray[qreal]

purity#

Return the purity of the stored quantum state.

total_prob#

Return the probability of being in any state.

For properly normalised pure states and density matrices, this will be 1. More accurate than self * self. For not-normalised density matrices, only the real part of the trace is returned.

static zero_like(Register other)#

Create a new register with the same properties as other.

The size and type (state vector or density matrix) of the newly created register are identical to other, but the returned register is initialised to the zero product state.

pyquest.decoherence module#

class Damping#

Bases: SingleQubitOperator

class Dephasing#

Bases: MultiQubitOperator

class Depolarising#

Bases: MultiQubitOperator

prob#
class KrausMap#

Bases: MultiQubitOperator

class MixDensityMatrix#

Bases: GlobalOperator

class PauliNoise#

Bases: SingleQubitOperator

pyquest.gates module#

Classes to represent norm-conserving operations in pyquest.

This module contains classes representing non-unitary but norm-conserving operations on a quantum state. They generally use short names, but often have more verbose aliases, which are defined at the end of the file and listed in the Classes section after each gate in square brackets.

Classes:

M [Measurement]: Measurement of one or more qubits.

class M#

Bases: MultiQubitOperator

Class implementing measurements.

When applied to a register, an object of this class performs a measurement of one or more qubits in the \(z\)-basis. Qubits are measured in the order they are given in the targets argument.

The results of the last time the gate was applied to a register are available in the results property, the corresponding probabilities are in the probabilities property.

For faster calculations (e.g. when post-selecting on a measurement outcome), the (unphysical) additional option of forcing the outcome of the measurement by providing it in the force arument.

Parameters:
  • targets (int | iterable[int]) – Indices of the qubits to measure, in the order they are supposed to be measured. Can be a scalar for a single target, or an iterable for multiple targets. Remember that measurements are destructive and the outcome of an earlier measurement can influence the probabilities of later measurements.

  • target (int | iterable[int]) – Alternative for targets; only one of target or targets may be not None.

  • force (int | iterable[int]) – Force the outcome of all or some measurements. Can be a scalar or an iterable of length 1, if a single qubit is measured. Must be None or an iterable of the same length as targets, if multiple qubits are measured. Each entry must be either None (meaning do not force the outcome of that specific measurement), 0, or 1. Defaults to None.

QuEST functions:
force#

What the measurment outcomes of this operator are forced to be.

Returns a list of the same length as targets with each element either 0, 1, or None, with 0 or 1 meaning force the outcome of that target to this result, and None meaning do not force the outcome of this target.

probabilities#

The probabilities of each outcome of the last measurement.

results#

The outcomes of the last measurement using this operator.

Measurement#

alias of M

pyquest.initialisations module#

class BlankState#

Bases: StateInit

Set all amplitudes in a Register to zero.

Applying this operator results in an unphysical state. Make sure to set the amplitudes appropriately afterwards.

QuEST function:
class ClassicalState#

Bases: StateInit

Initialise a Register to a specific computational basis state.

Applying this operator sets the amplitude of a pre-defined computational basis state to 1 and all others to 0.

Parameters:

state_ind (int) – The index of the computational basis state which should be set to 1. Its binary representation is the bit pattern of the appropriate basis state.

QuEST function:
class PlusState#

Bases: StateInit

Initialise a Register to a N-qubit plus-state.

Applying this operator puts each qubit in a Register in the plus-state and is thus equivalent to first initialising to the all-zero computational basis state followed by a Hadamard gate on every qubit (but this initialisation is faster).

QuEST function:
class PureState#

Bases: StateInit

Initialise a Register into a predefined pure state.

Applying this operator sets the state in a Register to a pure state that must be provided when the operator is created.

Parameters:
  • pure_state (Register) – A state vector (not density matrix) register containing the state a different register should later be set to (upon application of this operator).

  • copy_state (bool) – Whether the state in pure_state should be copied into a new memory location to be kept as reference. Setting this to True uses more memory to store the state, but does not rely on the reference register to remain unchanged. If set to False, changes to the register pure_state will also affect the action of applying this operator. However, it saves some memory as the state does not need to be duplicated.

QuEST function:
class StateInit#

Bases: GlobalOperator

class ZeroState#

Bases: StateInit

Initialise a Register to the computational all-zero state.

Applying this operator sets all amplitudes to 0, except for the index 0, which is set to 1. This operator is equivalent to calling PureState(0).

QuEST function:

pyquest.operators module#

Classes to represent generic operations in pyquest.

The most generic (possibly non-unitary, non-norm-preserving) operations on quantum states are contained in this module.

Classes:
BaseOperator:

Abstract generic base class for all operators.

ControlledOperator:

Base class for all controlled operators.

SingleQubitOperator:

Base class for operators acting on a single qubit.

MultiQubitOperator:

Base class for operators potentially acting on multiple qubits.

MatrixOperator:

Most generic operator, specified by its matrix representation.

PauliProduct:

A weighted product of Pauli operators.

PauliSum:

A sum of ´´PauliProduct´´s.

class BaseOperator#

Bases: object

Generic base class for every class representing an operator.

All operators on a quantum state must be derived from this class in order to work with pyquest. It only provides prototypes for the most basic tasks and returns a NotImplementedError if not properly overridden.

Cython attributes:
TYPE (pyquest.quest_interface.OP_TYPES): Identifier of the

operation for faster type checking than with IsInstance().

as_matrix(self, num_qubits=None)#

Return the operator in matrix representation.

inverse#

Calculate and return the inverse of an operator.

targets#

Return a list of qubits this operator acts on.

class ControlledOperator#

Bases: BaseOperator

Class implementing functionality for controlled operations.

Abstract base class handling the keyword-only controls argument in the constructor and providing an interface for accessing it.

controls#

The control qubits of the operator.

Always returns a list, which may be empty or contain only one element.

class DiagonalOperator#

Bases: GlobalOperator

class FullQFT#

Bases: GlobalOperator

class GlobalOperator#

Bases: BaseOperator

class MatrixOperator(targets=None, matrix=None, controls=None, target=None, **kwargs)#

Bases: MultiQubitOperator

matrix#
class MultiQubitOperator#

Bases: ControlledOperator

Class implementing an operator with multiple target qubits.

Abstract base class for operators with (potentially) more than one target qubit. Provides functionality for accessing the target qubits.

target#

The targets of the operator as integer or list.

If the operator has a single target, return it as an integer, otherwise return a list of integers (i.e. identical to the targets property). This exists mostly for consistency with single-target operators, which also return a scalar from their target property.

targets#

The targets of the operator as a list of integers.

class PauliProduct#

Bases: GlobalOperator

class PauliSum#

Bases: GlobalOperator

class PhaseFunc#

Bases: GlobalOperator

class BitEncoding(value)#

Bases: IntEnum

An enumeration.

UNSIGNED = 0#
TWOS_COMPLEMENT = 1#
class FuncType(value)#

Bases: IntEnum

An enumeration.

NORM = 0#
SCALED_NORM = 1#
INVERSE_NORM = 2#
SCALED_INVERSE_NORM = 3#
SCALED_INVERSE_SHIFTED_NORM = 4#
PRODUCT = 5#
SCALED_PRODUCT = 6#
INVERSE_PRODUCT = 7#
SCALED_INVERSE_PRODUCT = 8#
DISTANCE = 9#
SCALED_DISTANCE = 10#
INVERSE_DISTANCE = 11#
SCALED_INVERSE_DISTANCE = 12#
SCALED_INVERSE_SHIFTED_DISTANCE = 13#
EXPONENTIAL_POLYNOMIAL = 14#
bit_encoding#
divergence_override#
func_type#
inverse#
overrides#
scaling#
shifts#
targets#
terms#
class QFT#

Bases: MultiQubitOperator

class SingleQubitOperator#

Bases: ControlledOperator

Class implementing an operator with only one target qubit.

Abstract base class for all operator acting on a single qubit only. Provides properties for accessing the target qubit.

target#

The target qubit of the operator.

targets#

The target qubit of the operator as a single-item list.

This property exists mostly for consistency with multi-target operators, which also return a list from their targets property.

class TrotterCircuit#

Bases: GlobalOperator

pyquest.quest_error module#

exception QuESTError#

Bases: Exception

pyquest.unitaries module#

Classes to represent unitary operations in pyquest.

This module contains classes representing unitary operations on a quantum state. They generally use short names, but often have more verbose aliases, which are defined at the end of the file and listed in the Classes section after each gate in square brackets.

Classes:
U [Unitary]:

Generic unitary gate for which a matrix form must be given.

CompactU [CompactUnitary]:

Single-qubit unitary in a compact form with only 2 parameters.

X [NOT, PauliX]:

Single-qubit Pauli-X gate.

Y [PauliY]:

Single-qubit Pauli-Y gate.

Z [PauliZ]:

Single-qubit Pauli-Z gate.

Swap:

Swap gate on exactly two qubits.

SqrtSwap:

Square root of swap gate on exactly two qubits.

H [Hadamard]:

Single-qubit Hadamard gate.

S [SGate]:

Single-qubit phase shift gate with a phase of \(\pi/2\) (S-Gate).

T [TGate]:

Single-qubit phase shift gate with a phase of \(\pi/4\) (T-Gate).

BaseRotate:

Abstract base class for all rotation gates.

Rx [RotateX]:

Single-qubit gate rotating about the x-axis of the Bloch sphere.

Ry [RotateY]:

Single-qubit gate rotating about the y-axis of the Bloch sphere.

Rz [RotateZ]:

Single-qubit gate rotating about the z-axis of the Bloch sphere.

Phase [PhaseShift]:

Single-qubit gate shifting the phase of the \(\vert 1\rangle\) state.

RotateAroundAxis:

Single-qubit gate rotating the qubit about an arbitrary axis.

class BaseRotate#

Bases: SingleQubitOperator

Abstract base class for Pauli rotation gates.

This class does not usually need to be instantiated by the user.

angle#
inverse#
class CompactU(target, alpha, beta, controls=None)#

Bases: SingleQubitOperator

A single-qubit unitary in compact representation.

Because a unitary operator on a single qubit only has two degrees of freedom (up to an unphysical global phase factor), this operator allows the specification of such an operator with only two parameters \(\alpha\), \(\beta\), which make up the unitary

\[\begin{split}U = \begin{pmatrix} \alpha & -\beta^\ast \\ \beta & \alpha^\ast \end{pmatrix},\end{split}\]

where \(\lvert\alpha\rvert^2 + \lvert\beta\rvert^2 = 1\) must hold.

Parameters:
  • target (int) – The target qubit of the operator. CompactU only supports single targets.

  • alpha (float) – Parameter of the unitary \(U\) as specified above.

  • beta (float) – Parameter of the unitary \(U\) as specified above.

  • controls (int) – An optional control qubit of the operator. Passing None or an empty list means no controls. This operator supports at most one control qubit. Default: None.

QuEST functions:
CompactUnitary#

alias of CompactU

class H(target)#

Bases: SingleQubitOperator

A Hadamard gate on a single qubit.

The H operator interconverts between the \(\lvert 0\rangle, \lvert 1\rangle\) and the \(\lvert +\rangle, \lvert -\rangle\) basis. In the computational basis, it has the matrix representation

\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]
Parameters:

target (int) – The qubit to which the operator should be applied.

QuEST function:
inverse#
Hadamard#

alias of H

class MultiRotatePauli#

Bases: BaseRotate

NOT#

alias of X

class ParamSwap#

Bases: BaseRotate

PauliX#

alias of X

PauliY#

alias of Y

PauliZ#

alias of Z

class Phase(target, angle, controls=None)#

Bases: BaseRotate

Add a phase to the 1-state of a set of qubits.

When acting on a single target, the Phase operator has the following matrix representation.

\[\begin{split}P(\theta) = \begin{pmatrix} 1 & 0 \\ 0 & \exp{i\theta} \end{pmatrix}\end{split}\]

The Phase operator is somewhat similar to that of the Z operator in that it makes no difference which qubits are called targets and which are called controls. For consistency, exactly one target qubit must be named, the rest must go in the controls argument. However, the action of the operator is invariant under swapping the target for any of the controls.

Parameters:
  • target (int) – The qubit to phase shift.

  • angle (float) – The angle \(\theta\) as defined above.

  • controls (int | iterable[int]) – An optional list of control qubits. In the Phase operater, there is no functional difference between target and controls, but for more than a single target, all but one of the indices must be passed via the controls parameter. An empty list or None signifies only a single target. Default: None.

QuEST functions:
PhaseShift#

alias of Phase

class RotateAroundAxis(target, angle, axis, controls=None)#

Bases: BaseRotate

Rotate a single qubit around a defined vector on the Bloch-sphere.

The axis to rotate around is normalised by the QuEST backend, but must not be zero in magnitude. The resulting operator is

\[R_{\hat{n}}(\theta) = \exp\left(-i\frac{\theta}{2} \hat{n} \cdot \vec{\sigma}\right)\]

where \(\vec{\sigma}\) is a vector of Pauli-operators. The RotateAroundAxis operator supports at most one control qubit.

Parameters:
  • target (int) – The target qubit of the operator.

  • angle (float) – The angle \(\theta\) as defined above.

  • axis (indexable[float]) – The axis through the Bloch sphere about which the state should be rotated. The entries axis[0], axis[1], and axis[2] are interpreted as \(x\)- \(y\)- and \(z\)-components, respecively.

  • controls (int) – An optional control qubit. There is no functional difference between target and controls, one of the indices must be passed via the controls parameter. An empty list or None signifies only a single target. Default: None.

QuEST functions:
RotateX#

alias of Rx

RotateY#

alias of Ry

RotateZ#

alias of Rz

class Rx(target, angle, controls=None)#

Bases: BaseRotate

Rotate a single qubit about the X-axis of the Bloch sphere.

The Pauli-X rotation gate \(R_x(\theta)\) on a single qubit for a given angle \(\theta\) has the matrix representation

\[\begin{split}R_x(\theta) = \begin{pmatrix} \cos \theta / 2 & -i \sin \theta / 2 \\ -i \sin \theta / 2 & \cos \theta / 2 \end{pmatrix}\end{split}\]

The Rx operator supports at most one control qubit.

Parameters:
  • target (int) – The qubit to rotate.

  • angle (float) – The angle \(\theta\) as defined above.

  • controls (int) – An optional control qubit. Passing an empty list or None means no control qubit for the operation. Default: None.

QuEST functions:
class Ry(target, angle, controls=None)#

Bases: BaseRotate

Rotate a single qubit about the Y-axis of the Bloch sphere.

The Pauli-Y rotation gate \(R_y(\theta)\) on a single qubit for a given angle \(\theta\) has the matrix representation

\[\begin{split}R_y(\theta) = \begin{pmatrix} \cos \theta / 2 & - \sin \theta / 2 \\ \sin \theta / 2 & \cos \theta / 2 \end{pmatrix}\end{split}\]

The Ry operator supports at most one control qubit.

Parameters:
  • target (int) – The qubit to rotate.

  • angle (float) – The angle \(\theta\) as defined above.

  • controls (int) – An optional control qubit. Passing an empty list or None means no control qubit for the operation. Default: None.

QuEST functions:
class Rz(target, angle, controls=None)#

Bases: BaseRotate

Rotate a single qubit about the Z-axis of the Bloch sphere.

The Pauli-Z rotation gate \(R_z(\theta)\) on a single qubit for a given angle \(\theta\) has the matrix representation

\[\begin{split}R_z(\theta) = \begin{pmatrix} \exp -i \theta / 2 & 0 \\ 0 & \exp i\theta / 2 \end{pmatrix}\end{split}\]

The Rz operator supports at most one control qubit.

Parameters:
  • target (int) – The qubit to rotate.

  • angle (float) – The angle \(\theta\) as defined above.

  • controls (int) – An optional control qubit. Passing an empty list or None means no control qubit for the operation. Default: None.

QuEST functions:
class S(target)#

Bases: SingleQubitOperator

An S-gate on a single qubit.

The S operator adds a phase of \(i\) to the \(\lvert 1\rangle\). It thus has the matrix representation

\[\begin{split}S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\end{split}\]
Parameters:

target (int) – The qubit to which the operator should be applied.

QuEST function:
SGate#

alias of S

class SqrtSwap(targets=None, target=None)#

Bases: MultiQubitOperator

A \(\sqrt{\mathrm{SWAP}}\) operator on exactly two qubits.

The SqrtSwap exchanges the states of two qubits if applied twice (hence the name). In matrix representation using the ordering of the states like \(\lvert 00 \rangle, \lvert 01 \rangle, \lvert 10 \rangle, \lvert 11 \rangle\) it takes the form

\[\begin{split}\sqrt{\mathrm{SWAP}} = \frac{1}{2} \begin{pmatrix} 2 & 0 & 0 & 0 \\ 0 & (1+i) & (1-i) & 0 \\ 0 & (1-i) & (1+i) & 0 \\ 0 & 0 & 0 & 2 \end{pmatrix}\end{split}\]

Currently, QuEST does not support controlling this operation on other qubits.

Parameters:
  • targets (iterable[int]) – The indices of the two qubits the gate will act on.

  • target (iterable[int]) – Alias for targets. Exactly one of these two must be not None. Default: None.

QuEST function:
class Swap(targets=None, target=None)#

Bases: MultiQubitOperator

A SWAP operator on exactly two qubits.

The Swap operator exchanges the states of its two target qubits. In matrix representation using the ordering of the states like \(\lvert 00 \rangle, \lvert 01 \rangle, \lvert 10 \rangle, \lvert 11 \rangle\) it takes the form

\[\begin{split}\mathrm{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]

Currently, QuEST does not support controlling this operation on other qubits.

Parameters:
  • targets (iterable[int]) – The indices of the two qubits whose states will be swapped.

  • target (iterable[int]) – Alias for targets. Exactly one of these two must be not None. Default: None.

QuEST function:
inverse#
class T(target)#

Bases: SingleQubitOperator

A T-gate on a single qubit.

The T operator adds a phase of \(\sqrt{i}\) to the \(\lvert 1\rangle\)-state of a qubit. It thus has the matrix representation

\[\begin{split}T = \begin{pmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{4}} \end{pmatrix}\end{split}\]
Parameters:

target (int) – The qubit to which the operator should be applied.

QuEST function:
TGate#

alias of T

class U(targets=None, matrix=None, controls=None, target=None, control_pattern=None)#

Bases: MatrixOperator

A generic unitary operator.

An operator on one or more qubits, fully specified via its matrix representation. Its unitarity is checked by the QuEST backend only upon application to a state, not at object creation.

State vector registers \(\vert\psi\rangle\) are affected in the usual way by applying the operator from the left \(U\vert\psi\rangle\) with implicit identity operators on every qubit \(U\) does not act on. Density matrix registers \(\rho\) are multiplied from the left and right \(U\rho U^\dagger\) to achieve the equivalent action as for state vectors.

Because specifying the full matrix requires a comparatively large block of memory, and the backend cannot utilise specialised algorithms, this operator should only be used when no builtin alternatives are available.

Parameters:
  • targets (int | iterable[int]) – The qubits onto which the operator should act nontrivially. The order is important in that targets[0] is the least significant qubit in the matrix representation of \(U\), i.e. neighbouring entries in matrix will differ by the state of the qubit targets[0].

  • matrix (numpy.ndarray) – The matrix representation of the operator given as an array with dimensions \(2^{\mathrm{len(targets)}} \times 2^{\mathrm{len(targets)}}\).

  • controls (int | interable[int]) – The control qubits of the operator. May be None or an empty list to signify no controls. Default: None.

  • target (int) – Alias for targets. Only one of the two may be specified. Default: None.

  • control_pattern (iterable[int]) – For controlled operators, this parameter can be used to specify which qubits act as regular controls (operator only acts on the 1-state subspace), and which act as anti-controls (operator acts on the 0-state subspace). If specified, its length must match that of controls. A 1 means regular control, a 0 means anti-control, matching entries of control_pattern index-wise with those in controls. Default: None.

QuEST functions:
control_pattern#

The control/anti-control pattern of the operator.

Unitary#

alias of U

class X(targets, controls=None)#

Bases: MultiQubitOperator

A Pauli-X operator on one or more qubits.

When acting on a single target, the Pauli-X (also called NOT, X, sigma-X, or bit-flip) operator has the following matrix representation.

\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]

When applying a Pauli-X onto multiple qubits in sequence, using a single X with multiple targets is significantly faster than applying several individual single-qubit X-operators sequentially.

Parameters:
  • targets (int | iterable[int]) – The target qubit indices on which the operator should act.

  • controls (int | iterable[int]) – The optional control qubits of the operator. An empty list or None signify no controls. Default: None.

QuEST functions:
inverse#
class Y(target, controls=None)#

Bases: SingleQubitOperator

A Pauli-Y operator on one qubit.

The Pauli-Y (also known as Y or sigma-Y) operator has the following matrix representation.

\[\begin{split}Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\end{split}\]
Parameters:
  • target (int) – The qubit on which the operator should act. The Y operator supports only a single target.

  • controls (int) – The index of an optional control qubit. Passing None or an empty list means no controls. Default: None.

QuEST functions:
inverse#
class Z(target, controls=None)#

Bases: SingleQubitOperator

A Pauli-Z operator on one or more qubits.

When acting on a single target, the Pauli-Z (also called Z, sigma-Z, or phase-flip) operator has the following matrix representation.

\[\begin{split}Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\end{split}\]

The Z-operator is somewhat special in that it makes no difference which qubits are called targets and which are called controls. For consistency, exactly one target qubit must be named, the rest must go in the controls argument. However, the action of the operator is invariant under swapping the target for any of the controls.

Parameters:
  • target (int) – The target qubit of the operator.

  • controls (int | iterable[int]) – An optional list of control qubits. In the Z operater, there is no functional difference between target and controls, but for more than a single target, all but one of the indices must be passed via the controls parameter. An empty list or None signifies only a single target. Default: None.

QuEST functions:
inverse#

Module contents#

Python wrapper for the Quantum Exact Simulation Toolkit (QuEST).

This package provides an easy to use Python interface for the QuEST library, which is written in C.

env = QuESTEnvironment(gpu_accelerated=False, multithreaded=False, distributed=False, num_threads=1, rank=0, num_ranks=1, precision=2)#

Package level variable holding the only instance of QuESTEnvironment.

To properly initialize a QuESTEnv, create a single instance at package load time and have every function needing it use this instance. This also allows user checking of the environment via pyquest.env.

rank = 0#

Promote environment properties to the package level.

These attributes are only for convenience, so individual properties of the environment can be checked at the package level, e.g. with pyquest.precision.