qml.sample

sample(op)[source]

Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device.

Example:

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

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

Executing this QNode:

>>> circuit(0.5)
array([ 1.,  1.,  1., -1.])
Parameters

op (Observable) – a quantum observable object

Raises

QuantumFunctionErrorop is not an instance of Observable