qml.noise.op_in¶
- op_in(ops)[source]¶
Builds a conditional as a
BooleanFn
for evaluating if a given operation exist in a specified set of operations.- Parameters
ops (str, class, Operation, list(Union[str, class, Operation, MeasurementProcess])) – Sequence of string representations, instances, or classes of the operation(s).
- Returns
A callable object that accepts an
Operation
orMeasurementProcess
and returns a boolean output. For an input from:Union[str, class, Operation, list(Union[str, class, Operation])]
and evaluates toTrue
if the input operation(s) exists in the set of operation(s) specified byops
. For aMeasurementProcess
input, similar evaluation happens on its observable. In both cases, comparison is based on the operation’s type, irrespective of wires.- Return type
Example
One may use
op_in
with a string representation of the name of the operation:>>> cond_func = qml.noise.op_in(["RX", "RY"]) >>> cond_func(qml.RX(1.23, wires=[0])) True
>>> cond_func(qml.RZ(1.23, wires=[3])) False
>>> cond_func([qml.RX(1.23, wires=[1]), qml.RY(4.56, wires=[2])]) True
Additionally, an instance of
Operation
can also be provided:>>> cond_func = qml.noise.op_in([qml.RX(1.0, "dino"), qml.RY(2.0, "rhino")]) >>> cond_func(qml.RX(1.23, wires=["eve"])) True
>>> cond_func(qml.RY(1.23, wires=["dino"])) True
>>> cond_func([qml.RX(1.23, wires=[1]), qml.RZ(4.56, wires=[2])]) False