qml.ftqc.ParametricMidMeasureMP¶
- class ParametricMidMeasureMP(wires, *, angle, plane, reset=False, postselect=None, id=None)[source]¶
Bases:
MidMeasureMPParametric mid-circuit measurement. The basis for the measurement is parametrized by a plane (“XY”, “YZ” or “ZX”), and an angle within the plane.
This class additionally stores information about unknown measurement outcomes in the qubit model. Measurements on a single qubit are assumed.
Warning
Measurements should be diagonalized before execution for any device that only natively supports mid-circuit measurements in the computational basis. To diagonalize, the
diagonalize_mcmstransform can be applied.Skipping diagonalization for a circuit containing parametric mid-circuit measurements may result in a completed execution with incorrect results.
- Parameters:
wires (.Wires) – The wires the measurement process applies to. This can only be specified if an observable was not provided.
- Keyword Arguments:
angle (float) – The angle in radians
plane (str) – The plane the measurement basis lies in. Options are “XY”, “ZX” and “YZ”
reset (bool) – Whether to reset the wire after measurement.
postselect (Optional[int]) – Which basis state to postselect after a mid-circuit measurement. None by default. If postselection is requested, only the post-measurement state that is used for postselection will be considered in the remaining circuit.
id (str) – Custom label given to a measurement instance.
Attributes
The angle in radians
Arithmetic depth of the operator.
Returns an integer hash uniquely representing the measurement process
Dictionary of non-trainable variables that this operation depends on.
Custom string to label a specific operator instance.
This property determines if an operator is likely hermitian.
String for the name of the operator.
Number of dimensions per trainable parameter of the operator.
Number of wires the operator acts on.
Trainable parameters that the operator depends on.
A
PauliSentencerepresentation of the Operator, orNoneif it doesn't have one.The plane the measurement basis lies in.
Which basis state to postselect after a mid-circuit measurement.
Whether to reset the wire into the zero state after the measurement.
A dictionary containing the minimal information needed to compute a resource estimate of the operator's decomposition.
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 = False¶
- 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 likely hermitian.
Note
It is recommended to use the
is_hermitian()function. Although this function may be expensive to calculate, theop.is_hermitianproperty can lead to technically incorrect results.If this property returns
True, the operator is guaranteed to be hermitian, but if it returnsFalse, the operator may still be hermitian.As an example, consider the following edge case:
>>> op = (qml.X(0) @ qml.Y(0) - qml.X(0) @ qml.Z(0)) * 1j >>> op.is_hermitian False
On the contrary, the
is_hermitian()function will give the correct answer:>>> qml.is_hermitian(op) 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
PauliSentencerepresentation of the Operator, orNoneif 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 = {}¶
- resource_params¶
A dictionary containing the minimal information needed to compute a resource estimate of the operator’s decomposition.
The keys of this dictionary should match the
resource_keysattribute of the operator class. Two instances of the same operator type should have identicalresource_paramsiff their decompositions exhibit the same counts for each gate type, even if the individual gate parameters differ.Examples
The
MultiRZhas non-emptyresource_keys:>>> qml.MultiRZ.resource_keys {'num_wires'}
The
resource_paramsof an instance ofMultiRZwill contain the number of wires:>>> op = qml.MultiRZ(0.5, wires=[0, 1]) >>> op.resource_params {'num_wires': 2}
Note that another
MultiRZmay have different parameters but the sameresource_params:>>> op2 = qml.MultiRZ(0.7, wires=[1, 2]) >>> op2.resource_params {'num_wires': 2}
Methods
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).
Representation of the operator as a product of other operators.
Decompose to a diagonalizing gate and a standard MCM in the computational basis
eigvals()Eigenvalues of the operator in the computational basis.
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
Adjointoperators constructed byadjoint().Adjointed operations are the conjugated and transposed version of the original operation. Adjointed ops are equivalent to the inverted operation for unitary gates.
Operator.adjointcan be optionally defined by Operator developers, whileadjoint()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_decompositionmethod.See also
- Parameters:
*params (list) – trainable parameters of the operator, as stored in the
parametersattributewires (Iterable[Any], Wires) – wires that the operator acts on
**hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparametersattribute
- 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.
See also
- Parameters:
params (list) – trainable parameters of the operator, as stored in the
parametersattributewires (Iterable[Any], Wires) – wires that the operator acts on
hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparametersattribute
- 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_gatesare 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.
See also
- Parameters:
*params (list) – trainable parameters of the operator, as stored in the
parametersattribute**hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparametersattribute
- 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.
See also
- Parameters:
*params (list) – trainable parameters of the operator, as stored in the
parametersattribute**hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparametersattribute
- 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, thecompute_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 withcompute_decomposition()(even if this method is defined), and not with this method.When
compute_qfunc_decompositionis 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.
See also
- 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
hyperparametersattribute
- 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
- Parameters:
*params (list) – trainable parameters of the operator, as stored in the
parametersattributeformat (str) – format of the returned scipy sparse matrix, for example ‘csr’
**hyperparams (dict) – non-trainable hyperparameters of the operator, as stored in the
hyperparametersattribute
- 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
DecompositionUndefinedErroris raised if no representation by decomposition is defined.See also
- 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_gatesare 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
EigvalsUndefinedErroris raised if the eigenvalues have not been defined and cannot be inferred from the matrix representation.See also
- 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
LinearCombinationandSparseHamiltonianrespectively).
- 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. Defaults to None.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_orderis 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
MatrixUndefinedErroris raised if the matrix representation has not been defined.See also
- 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
Powinstances created bypow()orop ** power.Operator.powcan be optionally defined by Operator developers, whilepow()orop ** powerare 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_orderis 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
SparseMatrixUndefinedErroris raised if the sparse matrix representation has not been defined.See also
- 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
TermsUndefinedErroris 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]]