qml.ftqc.ParametricMidMeasureMP¶
- class ParametricMidMeasureMP(wires, *, angle, plane, reset=False, postselect=None, id=None)[source]¶
Bases:
MidMeasureMP
Parametric 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_mcms
transform 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 data of the measurement.
Whether or not the MeasurementProcess returns a defined decomposition when calling
expand
.Whether there are gates that need to be applied to diagonalize the measurement
Returns an integer hash uniquely representing the measurement process
The name of the measurement.
The number of parameters.
The Python numeric type of the measurement result.
The wires the measurement process acts on.
Whether or not the MeasurementProcess measures in the computational basis.
The wires the measurement process acts on.
- data¶
The data of the measurement. Needed to match the Operator API.
- has_decomposition¶
Whether or not the MeasurementProcess returns a defined decomposition when calling
expand
.- Type:
Bool
- has_diagonalizing_gates¶
Whether there are gates that need to be applied to diagonalize the measurement
- hash¶
Returns an integer hash uniquely representing the measurement process
- Type:
int
- name¶
The name of the measurement. Needed to match the Operator API.
- num_params¶
The number of parameters. Needed to match the Operator API.
- numeric_type¶
The Python numeric type of the measurement result.
- Returns:
The output numeric type;
int
,float
orcomplex
.- Return type:
type
- Raises:
QuantumFunctionError – the return type of the measurement process is unrecognized and cannot deduce the numeric type
- raw_wires¶
The wires the measurement process acts on.
For measurements involving more than one set of wires (such as mutual information), this is a list of the Wires objects. Otherwise, this is the same as
wires()
- samples_computational_basis¶
- wires¶
The wires the measurement process acts on.
This is the union of all the Wires objects of the measurement.
Methods
Decompose to a diagonalizing gate and a standard MCM in the computational basis
eigvals
()Eigenvalues associated with the measurement process.
expand
()Expand the measurement of an observable to a unitary rotation and a measurement in the computational basis.
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 measurement process with its wires changed according to the given wire map.
queue
([context])Append the measurement process to an annotated queue.
shape
([shots, num_device_wires])Calculate the shape of the result object tensor.
simplify
()Reduce the depth of the observable to the minimum.
- diagonalizing_gates()[source]¶
Decompose to a diagonalizing gate and a standard MCM in the computational basis
- eigvals()¶
Eigenvalues associated with the measurement process.
If the measurement process has an associated observable, the eigenvalues will correspond to this observable. Otherwise, they will be the eigenvalues provided when the measurement process was instantiated.
Note that the eigenvalues are not guaranteed to be in any particular order.
Example:
>>> m = MeasurementProcess(Expectation, obs=qml.X(1)) >>> m.eigvals() array([1, -1])
- Returns:
eigvals representation
- Return type:
array
- expand()¶
Expand the measurement of an observable to a unitary rotation and a measurement in the computational basis.
- Returns:
a quantum tape containing the operations required to diagonalize the observable
- Return type:
.QuantumTape
Example:
Consider a measurement process consisting of the expectation value of an Hermitian observable:
>>> H = np.array([[1, 2], [2, 4]]) >>> obs = qml.Hermitian(H, wires=['a']) >>> m = MeasurementProcess(Expectation, obs=obs)
Expanding this out:
>>> tape = m.expand()
We can see that the resulting tape has the qubit unitary applied, and a measurement process with no observable, but the eigenvalues specified:
>>> print(tape.operations) [QubitUnitary(array([[-0.89442719, 0.4472136 ], [ 0.4472136 , 0.89442719]]), wires=['a'])] >>> print(tape.measurements[0].eigvals()) [0. 5.] >>> print(tape.measurements[0].obs) None
- 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 measurement process 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 measurement process
- Return type:
.MeasurementProcess
- queue(context=<class 'pennylane.queuing.QueuingManager'>)¶
Append the measurement process to an annotated queue.
- shape(shots=None, num_device_wires=0)¶
Calculate the shape of the result object tensor.
- Parameters:
shots (Optional[int]) – the number of shots used execute the circuit.
None
indicates an analytic simulation. Shot vectors are handled by calling this method multiple times.num_device_wires (int) – The number of wires that will be used if the measurement is broadcasted across all available wires (
len(mp.wires) == 0
). If the device itself doesn’t provide a number of wires, the number of tape wires will be provided here instead:
- Returns:
An arbitrary length tuple of ints. May be an empty tuple.
- Return type:
tuple[int,…]
>>> qml.probs(wires=(0,1)).shape() (4,) >>> qml.sample(wires=(0,1)).shape(shots=50) (50, 2) >>> qml.state().shape(num_device_wires=4) (16,) >>> qml.expval(qml.Z(0)).shape() ()
- simplify()¶
Reduce the depth of the observable to the minimum.
- Returns:
A measurement process with a simplified observable.
- Return type:
.MeasurementProcess