qml.ftqc.XMidMeasure

class XMidMeasure(wires, reset=False, postselect=None, id=None)[source]

Bases: ParametricMidMeasure

A subclass of ParametricMidMeasure that uses the X measurement basis (angle=0, plane=”XY”). For labels and visualizations, this will be represented as a X measurement. It is otherwise identical to the parent class.

angle

The angle in radians

arithmetic_depth

Arithmetic depth of the operator.

batch_size

has_adjoint

has_decomposition

Whether or not the Operator returns a defined decomposition.

has_diagonalizing_gates

has_generator

has_matrix

has_qfunc_decomposition

has_sparse_matrix

hash

Returns an integer hash uniquely representing the measurement process

hyperparameters

Dictionary of non-trainable variables that this operation depends on.

id

Custom string to label a specific operator instance.

is_hermitian

This property determines if an operator is verified to be Hermitian.

is_verified_hermitian

This property determines if an operator is verified to be Hermitian.

name

String for the name of the operator.

ndim_params

Number of dimensions per trainable parameter of the operator.

num_params

num_wires

Number of wires the operator acts on.

parameters

Trainable parameters that the operator depends on.

pauli_rep

A PauliSentence representation of the Operator, or None if it doesn't have one.

plane

The plane the measurement basis lies in.

postselect

Which basis state to postselect after a mid-circuit measurement.

reset

Whether to reset the wire into the zero state after the measurement.

resource_keys

The set of parameters that affects the resource requirement of the operator.

resource_params

A dictionary containing the minimal information needed to compute a resource estimate of the operator's decomposition.

wires

Wires that the operator acts on.

angle

The angle in radians

arithmetic_depth

Arithmetic depth of the operator.

batch_size = None
has_adjoint = False
has_decomposition

Whether or not the Operator returns a defined decomposition.

Type:

Bool

has_diagonalizing_gates = True
has_generator = False
has_matrix = False
has_qfunc_decomposition = False
has_sparse_matrix = False
hash

Returns an integer hash uniquely representing the measurement process

Type:

int

hyperparameters

Dictionary of non-trainable variables that this operation depends on.

Type:

dict

id

Custom string to label a specific operator instance.

is_hermitian

This property determines if an operator is verified to be Hermitian.

Warning

The is_hermitian property is deprecated and has been renamed to is_verified_hermitian as it better reflects the functionality of this property. The deprecated access through is_hermitian will be removed in PennyLane v0.45. Alternatively, consider using the is_hermitian() function instead as it provides a more reliable check for hermiticity. Please be aware that it comes with a higher computational cost.

Note

This property provides a fast, non-exhaustive check used for internal optimizations. It relies on quick, provable shortcuts (e.g., operator properties) rather than a full, computationally expensive check.

For a definitive check, use the pennylane.is_hermitian() function. Please note that this comes with increased computational cost.

Returns:

The property will return True if the operator is guaranteed to be Hermitian and False if the check is inconclusive and the operator may or may not be Hermitian.

Return type:

bool

Consider this operator,

>>> op = (qml.X(0) @ qml.Y(0) - qml.X(0) @ qml.Z(0)) * 1j

In this case, Hermicity cannot be verified and leads to an inconclusive result:

>>> op.is_verified_hermitian # inconclusive
False

However, using pennylane.is_hermitian() will give the correct answer:

>>> qml.is_hermitian(op) # definitive
True
is_verified_hermitian

This property determines if an operator is verified to be Hermitian.

Note

This property provides a fast, non-exhaustive check used for internal optimizations. It relies on quick, provable shortcuts (e.g., operator properties) rather than a full, computationally expensive check.

For a definitive check, use the pennylane.is_hermitian() function. Please note that this comes with increased computational cost.

Returns:

The property will return True if the operator is guaranteed to be Hermitian and False if the check is inconclusive and the operator may or may not be Hermitian.

Return type:

bool

Consider this operator,

>>> op = (qml.X(0) @ qml.Y(0) - qml.X(0) @ qml.Z(0)) * 1j

In this case, Hermicity cannot be verified and leads to an inconclusive result:

>>> op.is_verified_hermitian # inconclusive
False

However, using pennylane.is_hermitian() will give the correct answer:

>>> qml.is_hermitian(op) # definitive
True
name

String for the name of the operator.

ndim_params

Number of dimensions per trainable parameter of the operator.

By default, this property returns the numbers of dimensions of the parameters used for the operator creation. If the parameter sizes for an operator subclass are fixed, this property can be overwritten to return the fixed value.

Returns:

Number of dimensions for each trainable parameter.

Return type:

tuple

num_params = 0
num_wires = 1

Number of wires the operator acts on.

parameters

Trainable parameters that the operator depends on.

pauli_rep

A PauliSentence representation of the Operator, or None if it doesn’t have one.

plane

The plane the measurement basis lies in. Options are “XY”, “ZX” and “YZ

postselect

Which basis state to postselect after a mid-circuit measurement.

reset

Whether to reset the wire into the zero state after the measurement.

resource_keys = {}

The set of parameters that affects the resource requirement of the operator.

All decomposition rules for this operator class are expected to have a resource function that accepts keyword arguments that match these keys exactly. The resource_rep() function will also expect keyword arguments that match these keys when called with this operator type.

The default implementation is an empty set, which is suitable for most operators.

See also

resource_params()

resource_params
wires

Wires that the operator acts on.

Returns:

wires

Return type:

Wires

adjoint()

Create an operation that is the adjoint of this one.

compute_decomposition(*params[, wires])

Representation of the operator as a product of other operators (static method).

compute_diagonalizing_gates(*params, wires, ...)

Sequence of gates that diagonalize the operator in the computational basis (static method).

compute_eigvals(*params, **hyperparams)

Eigenvalues of the operator in the computational basis (static method).

compute_matrix(*params, **hyperparams)

Representation of the operator as a canonical matrix in the computational basis (static method).

compute_qfunc_decomposition(*args, ...)

Experimental method to compute the dynamic decomposition of the operator with program capture enabled.

compute_sparse_matrix(*params[, format])

Representation of the operator as a sparse matrix in the computational basis (static method).

decomposition()

Representation of the operator as a product of other operators.

diagonalizing_gates()

Decompose to a diagonalizing gate and a standard MCM in the computational basis

eigvals()

Eigenvalues of the operator in the computational basis.

generator()

Generator of an operator that is in single-parameter-form.

label([decimals, base_label, cache])

How the mid-circuit measurement is represented in diagrams and drawings.

map_wires(wire_map)

Returns a copy of the current operator with its wires changed according to the given wire map.

matrix([wire_order])

Representation of the operator as a matrix in the computational basis.

pow(z)

A list of new operators equal to this one raised to the given power.

queue([context])

Append the operator to the Operator queue.

simplify()

Reduce the depth of nested operators to the minimum.

sparse_matrix([wire_order, format])

Representation of the operator as a sparse matrix in the computational basis.

terms()

Representation of the operator as a linear combination of other operators.

adjoint()

Create an operation that is the adjoint of this one. Used to simplify Adjoint operators constructed by adjoint().

Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.

Operator.adjoint can be optionally defined by Operator developers, while adjoint() is the entry point for constructing generic adjoint representations.

Returns:

The adjointed operation.

>>> class MyClass(qml.operation.Operator):
...
...     def adjoint(self):
...         return self
...
>>> op = qml.adjoint(MyClass(wires=0))
>>> op
Adjoint(MyClass(wires=[0]))
>>> op.decomposition()
[MyClass(wires=[0])]
>>> op.simplify()
MyClass(wires=[0])
static compute_decomposition(*params, wires=None, **hyperparameters)

Representation of the operator as a product of other operators (static method).

\[O = O_1 O_2 \dots O_n.\]

Note

Operations making up the decomposition should be queued within the compute_decomposition method.

See also

decomposition().

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • wires (Iterable[Any], Wires) – wires that the operator acts on

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

decomposition of the operator

Return type:

list[Operator]

static compute_diagonalizing_gates(*params, wires, **hyperparams)

Sequence of gates that diagonalize the operator in the computational basis (static method).

Given the eigendecomposition \(O = U \Sigma U^{\dagger}\) where \(\Sigma\) is a diagonal matrix containing the eigenvalues, the sequence of diagonalizing gates implements the unitary \(U^{\dagger}\).

The diagonalizing gates rotate the state into the eigenbasis of the operator.

Parameters:
  • params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • wires (Iterable[Any], Wires) – wires that the operator acts on

  • hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

list of diagonalizing gates

Return type:

list[.Operator]

static compute_eigvals(*params, **hyperparams)

Eigenvalues of the operator in the computational basis (static method).

If diagonalizing_gates are specified and implement a unitary \(U^{\dagger}\), the operator can be reconstructed as

\[O = U \Sigma U^{\dagger},\]

where \(\Sigma\) is the diagonal matrix containing the eigenvalues.

Otherwise, no particular order for the eigenvalues is guaranteed.

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

eigenvalues

Return type:

tensor_like

static compute_matrix(*params, **hyperparams)

Representation of the operator as a canonical matrix in the computational basis (static method).

The canonical matrix is the textbook matrix representation that does not consider wires. Implicitly, this assumes that the wires of the operator correspond to the global wire order.

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

matrix representation

Return type:

tensor_like

static compute_qfunc_decomposition(*args, **hyperparameters)

Experimental method to compute the dynamic decomposition of the operator with program capture enabled.

When the program capture feature is enabled with qml.capture.enable(), the decomposition of the operator is computed with this method if it is defined. Otherwise, the compute_decomposition() method is used.

The exception to this rule is when the operator is returned from the compute_decomposition() method of another operator, in which case the decomposition is performed with compute_decomposition() (even if this method is defined), and not with this method.

When compute_qfunc_decomposition is defined for an operator, the control flow operations within the method (specifying the decomposition of the operator) are recorded in the JAX representation.

Note

This method is experimental and subject to change.

Parameters:
  • *args (list) – positional arguments passed to the operator, including trainable parameters and wires

  • **hyperparameters (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

static compute_sparse_matrix(*params, format='csr', **hyperparams)

Representation of the operator as a sparse matrix in the computational basis (static method).

The canonical matrix is the textbook matrix representation that does not consider wires. Implicitly, this assumes that the wires of the operator correspond to the global wire order.

See also

sparse_matrix()

Parameters:
  • *params (list) – trainable parameters of the operator, as stored in the parameters attribute

  • format (str) – format of the returned scipy sparse matrix, for example ‘csr’

  • **hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the hyperparameters attribute

Returns:

sparse matrix representation

Return type:

scipy.sparse._csr.csr_matrix

decomposition()

Representation of the operator as a product of other operators.

\[O = O_1 O_2 \dots O_n\]

A DecompositionUndefinedError is raised if no representation by decomposition is defined.

Returns:

decomposition of the operator

Return type:

list[Operator]

diagonalizing_gates()[source]

Decompose to a diagonalizing gate and a standard MCM in the computational basis

eigvals()

Eigenvalues of the operator in the computational basis.

If diagonalizing_gates are specified and implement a unitary \(U^{\dagger}\), the operator can be reconstructed as

\[O = U \Sigma U^{\dagger},\]

where \(\Sigma\) is the diagonal matrix containing the eigenvalues.

Otherwise, no particular order for the eigenvalues is guaranteed.

Note

When eigenvalues are not explicitly defined, they are computed automatically from the matrix representation. Currently, this computation is not differentiable.

A EigvalsUndefinedError is raised if the eigenvalues have not been defined and cannot be inferred from the matrix representation.

Returns:

eigenvalues

Return type:

tensor_like

generator()

Generator of an operator that is in single-parameter-form.

For example, for operator

\[U(\phi) = e^{i\phi (0.5 Y + Z\otimes X)}\]

we get the generator

>>> U.generator() 
0.5 * Y(0) + Z(0) @ X(1)

The generator may also be provided in the form of a dense or sparse Hamiltonian (using LinearCombination and SparseHamiltonian respectively).

label(decimals=None, base_label=None, cache=None)[source]

How the mid-circuit measurement is represented in diagrams and drawings.

Parameters:
  • decimals – If None, no parameters are included. Else, how to round the parameters. Required to match general call signature. Not used.

  • base_label – overwrite the non-parameter component of the label. Required to match general call signature. Not used.

  • cache – dictionary that carries information between label calls in the same drawing. Required to match general call signature. Not used.

Returns:

label to use in drawings

Return type:

str

map_wires(wire_map)

Returns a copy of the current operator with its wires changed according to the given wire map.

Parameters:

wire_map (dict) – dictionary containing the old wires as keys and the new wires as values

Returns:

new operator

Return type:

.Operator

matrix(wire_order=None)

Representation of the operator as a matrix in the computational basis.

If wire_order is provided, the numerical representation considers the position of the operator’s wires in the global wire order. Otherwise, the wire order defaults to the operator’s wires.

If the matrix depends on trainable parameters, the result will be cast in the same autodifferentiation framework as the parameters.

A MatrixUndefinedError is raised if the matrix representation has not been defined.

See also

compute_matrix()

Parameters:

wire_order (Iterable) – global wire order, must contain all wire labels from the operator’s wires

Returns:

matrix representation

Return type:

tensor_like

pow(z)

A list of new operators equal to this one raised to the given power. This method is used to simplify Pow instances created by pow() or op ** power.

Operator.pow can be optionally defined by Operator developers, while pow() or op ** power are the entry point for constructing generic powers to exponents.

Parameters:

z (float) – exponent for the operator

Returns:

list[Operator]

>>> class MyClass(qml.operation.Operator):
...
...     def pow(self, z):
...         return [MyClass(self.data[0]*z, self.wires)]
...
>>> op = MyClass(0.5, 0) ** 2
>>> op
MyClass(0.5, wires=[0])**2
>>> op.decomposition()
[MyClass(1.0, wires=[0])]
>>> op.simplify()
MyClass(1.0, wires=[0])
queue(context=<class 'pennylane.queuing.QueuingManager'>)

Append the operator to the Operator queue.

simplify()

Reduce the depth of nested operators to the minimum.

Returns:

simplified operator

Return type:

.Operator

sparse_matrix(wire_order=None, format='csr')

Representation of the operator as a sparse matrix in the computational basis.

If wire_order is provided, the numerical representation considers the position of the operator’s wires in the global wire order. Otherwise, the wire order defaults to the operator’s wires.

A SparseMatrixUndefinedError is raised if the sparse matrix representation has not been defined.

Parameters:
  • wire_order (Iterable) – global wire order, must contain all wire labels from the operator’s wires

  • format (str) – format of the returned scipy sparse matrix, for example ‘csr’

Returns:

sparse matrix representation

Return type:

scipy.sparse._csr.csr_matrix

terms()

Representation of the operator as a linear combination of other operators.

\[O = \sum_i c_i O_i\]

A TermsUndefinedError is raised if no representation by terms is defined.

Returns:

list of coefficients \(c_i\) and list of operations \(O_i\)

Return type:

tuple[list[tensor_like or float], list[.Operation]]