qml.devices.preprocess.validate_observables

validate_observables(tape, stopping_condition, stopping_condition_shots=None, 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 an observable is accepted.

  • stopping_condition_shots (callable) – a function that specifies whether an observable is accepted in finite-shots mode. This replaces stopping_condition if and only if the tape has shots.

  • 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)
DeviceError: Observable Z(0) + Y(0) not supported on device

Contents

Using PennyLane

Release news

Development

API

Internals