Perform a mid-circuit measurement in the computational basis on the supplied qubit.
Measurement outcomes can be obtained and used to conditionally apply operations.
If a device doesn’t support mid-circuit measurements natively, then the QNode will apply the
dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def func(x, y): qml.RY(x, wires=0) qml.CNOT(wires=[0, 1]) m_0 = qml.measure(1) qml.cond(m_0, qml.RY)(y, wires=0) return qml.probs(wires=)
Executing this QNode:
>>> pars = np.array([0.643, 0.246], requires_grad=True) >>> func(*pars) tensor([0.90165331, 0.09834669], requires_grad=True)
Mid circuit measurements can be manipulated using the following dunder methods +, -, *, /, ~ (not), & (and), | (or), ==, <=, >=, <, >. With other mid-circuit measurements or scalars.
python not, and, or, do not work since these do not have dunder methods. Instead use ~, &, |.
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry
- Quantum Datasets