qml.devices.preprocess.validate_observables

validate_observables(tape, stopping_condition, name='device')[source]

Validates the observables and measurements for a circuit.

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

  • stopping_condition (callable) – a function that specifies whether or not an observable is accepted.

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

Returns

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

Return type

qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]

Raises

DeviceError – if an observable is not supported

Example:

>>> def accepted_observable(obj):
...    return obj.name in {"PauliX", "PauliY", "PauliZ"}
>>> tape = qml.tape.QuantumScript([], [qml.expval(qml.Z(0) + qml.Y(0))])
>>> validate_observables(tape, accepted_observable)
qml.DeviceError: Observable Z(0) + Y(0) not supported on device

Note that if the observable is a Tensor, the validation is run on each object in the Tensor instead.

Contents

Using PennyLane

Release news

Development

API

Internals