qml.tape.MeasurementProcess¶

class
MeasurementProcess
(return_type, obs=None, wires=None, eigvals=None)[source]¶ Bases:
object
Represents a measurement process occurring at the end of a quantum variational circuit.
 Parameters
return_type (ObservableReturnTypes) – The type of measurement process. This includes
Expectation
,Variance
,Sample
,State
, orProbability
.obs (Observable) – The observable that is to be measured as part of the measurement process. Not all measurement processes require observables (for example
Probability
); this argument is optional.wires (Wires) – The wires the measurement process applies to. This can only be specified if an observable was not provided.
eigvals (array) – A flat array representing the eigenvalues of the measurement. This can only be specified if an observable was not provided.
Attributes
Eigenvalues associated with the measurement process.
The wires the measurement process acts on.

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.PauliX(wires=1)) >>> m.eigvals array([1, 1])
 Returns
eigvals representation
 Return type
array

wires
¶ The wires the measurement process acts on.
Methods
expand
()Expand the measurement of an observable to a unitary rotation and a measurement in the computational basis.
queue
()Append the measurement process to an annotated queue.

expand
()[source]¶ 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
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
Contents
Using PennyLane
Development
API
Downloads