Probability() usage

Hi @Miguel_Fernandez!

There is currently an open PR on our GitHub repo, adding a new prob() measurement function. You can install this branch using pip:

pip install git+https://github.com/XanaduAI/PennyLane.git@prob_fn

Once this branch is installed, you can import this new experimental measurement function and use it in a QNode like so:

import numpy as np
import pennylane as qml
from pennylane.beta import prob

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

@qml.qnode(dev)
def circuit(x):
    qml.Hadamard(wires=0)
    qml.RY(x, wires=0)
    qml.RX(x, wires=1)
    qml.CNOT(wires=[0, 1])
    return prob(wires=[0])

Note:

  • prob() must accept a wires argument, which specifies for which wires the marginal probability is returned.

  • This feature is experimental, and might change before the next release!

  • Currently, it only supports the default.qubit device, and the PennyLane-qiskit plugin under some modification, but additional device support will be coming soon.

1 Like