qml.devices.preprocess.validate_measurements

validate_measurements(tape, analytic_measurements=None, sample_measurements=None, name='device')[source]

Validates the supported state and sample based measurement processes.

Parameters
  • tape (QuantumTape, QNode, Callable) – a quantum circuit.

  • analytic_measurements (Callable[[MeasurementProcess], bool]) – a function from a measurement process to whether or not it is accepted in analytic simulations.

  • sample_measurements (Callable[[MeasurementProcess], bool]) – a function from a measurement process to whether or not it accepted for finite shot siutations

  • name (str) – the name to use in error messages.

Returns

The unaltered input circuit. The output type is explained in qml.transform.

Return type

qnode (pennylane.QNode) or quantum function (callable) or tuple[List[QuantumTape], function]

Raises

DeviceError – if a measurement process is not supported.

>>> def analytic_measurements(m):
...     return isinstance(m, qml.measurements.StateMP)
>>> def shots_measurements(m):
...     return isinstance(m, qml.measurements.CountsMP)
>>> tape = qml.tape.QuantumScript([], [qml.expval(qml.Z(0))])
>>> validate_measurements(tape, analytic_measurements, shots_measurements)
DeviceError: Measurement expval(Z(0)) not accepted for analytic simulation on device.
>>> tape = qml.tape.QuantumScript([], [qml.sample()], shots=10)
>>> validate_measurements(tape, analytic_measurements, shots_measurements)
DeviceError: Measurement sample(wires=[]) not accepted with finite shots on device

Contents

Using PennyLane

Release news

Development

API

Internals