Processing math: 100%

qml.ftqc.measure_arbitrary_basis

measure_arbitrary_basis(wires, angle, plane, reset=False, postselect=None)[source]

Perform a mid-circuit measurement in the basis defined by the plane and angle on the supplied qubit.

The measurements are performed using the 0, 1 convention rather than the ±1 convention.

If a device doesn’t support mid-circuit measurements natively, then the desired mcm_method for executing mid-circuit measurements should be passed to the QNode.

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 wire to measure.

  • angle (float) – The angle of rotation defining the axis, specified in radians.

  • plane (str) – The plane the measurement basis lies in. Options are “XY”, “YZ” and “ZX”

  • reset (Optional[bool]) – Whether to reset the wire to the |0 state 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.

Returns

The mid-circuit measurement result linked to the created MidMeasureMP.

Return type

MeasurementValue

Raises

QuantumFunctionError – if multiple wires were specified

Note

Reset behaviour will depend on the execution method for mid-circuit measurements, and may not work for all configurations.

Example:

import pennylane as qml
from pennylane.ftqc import diagonalize_mcms, measure_arbitrary_basis

dev = qml.device("default.qubit", wires=3)

@diagonalize_mcms
@qml.qnode(dev, mcm_method="tree-traversal")
def func(x, y):
    qml.RY(x, wires=0)
    qml.CNOT(wires=[0, 1])
    m_0 = measure_arbitrary_basis(1, angle=np.pi/3, plane="XY")

    qml.cond(m_0, qml.RY)(y, wires=0)
    return qml.probs(wires=[0])

Executing this QNode:

>>> pars = np.array([0.643, 0.246])
>>> func(*pars)
array([0.91237915, 0.08762085])

The plane and angle are related to the axis of measurement by the following formulas:

MXY(ϕ)=12(|0+eiϕ|1),
MYZ(θ)=cosθ2|0+isinθ2|1, and
MZX(θ)=cosθ2|0+sinθ2|1

where, in terms of spherical coordinates in the physics convention, the angles ϕ and θ are the azimuthal and polar angles, respectively.

Measurement outcomes can be used to conditionally apply operations, and measurement statistics can be gathered and returned by a quantum function. Measurement outcomes can also be manipulated using arithmetic operators like +, -, *, /, etc. with other mid-circuit measurements or scalars.

See the qml.measure function for details on the available arithmetic operators for mid-circuit measurement results.

Mid-circuit measurement results can be processed with the usual measurement functions such as expval(). For QNodes with finite shots, sample() applied to a mid-circuit measurement result will return a binary sequence of samples. See here for more details.