Measurements#

A measurement function turns the final quantum state into numbers the loss can use. Pass one as measure_fn, and name the wires with measure_wires:

from pyqit.core import measure_probs
from pyqit.models import VQCClassifier

model = VQCClassifier(
    n_qubits=4,
    n_classes=2,
    measure_fn=measure_probs,
    measure_wires=[0],
)

A model picks a default when you leave measure_fn unset, and its page says which. The classifiers read probabilities; VQCRegressor reads the parity Z ⊗ ... ⊗ Z, one scalar per sample.

Available measurements#

measure_probs

Return the 2 ** len(wires) basis-state probabilities of wires.

measure_expval_z

Return the PauliZ expectation of each wire in wires.

measure_expval_x

Return the PauliX expectation of each wire in wires.

measure_parity_z

Return the expectation of the PauliZ parity over wires.

Writing your own#

A measurement function takes the list of wires and returns a PennyLane measurement, or a tuple of them. The model calls it as the last step of the circuit.

import pennylane as qml

def measure_expval_y(wires):
    return tuple(qml.expval(qml.PauliY(w)) for w in wires)

Local and global cost#

The choice also affects the barren-plateau baseline. Measuring fewer wires than you have qubits counts as a local cost, with a floor of 1 / 2 ** n_qubits. Measuring all of them counts as global, and the floor drops to 1 / (3 * 4 ** (n_qubits - 1)), which is far harder to clear.