qml.noise.partial_wires

partial_wires(operation, *args, **kwargs)[source]

Builds a partial function based on the given gate operation or measurement process with all argument frozen except wires.

Parameters
  • operation (Operation | MeasurementProcess | class | Callable) – Instance of an operation or the class (callable) corresponding to the operation (measurement).

  • *args – Positional arguments provided in the case where the keyword argument operation is a class for building the partially evaluated instance.

  • **kwargs – Keyword arguments for the building the partially evaluated instance. These will override any arguments present in the operation instance or args.

Returns

A wrapper function that accepts a sequence of wires as an argument or any object with a wires property.

Return type

Callable

Raises

ValueError – If args are provided when the given operation is an instance.

Example

One may give an instance of Operation for the operation argument:

>>> func = qml.noise.partial_wires(qml.RX(1.2, [12]))
>>> func(2)
qml.RX(1.2, wires=[2])
>>> func(qml.RY(1.0, ["wires"]))
qml.RX(1.2, wires=["wires"])

Additionally, an Operation class can also be provided, while providing required positional arguments via args:

>>> func = qml.noise.partial_wires(qml.RX, 3.2, [20])
>>> func(qml.RY(1.0, [0]))
qml.RX(3.2, wires=[0])

Moreover, one can use kwargs instead of positional arguments:

>>> func = qml.noise.partial_wires(qml.RX, phi=1.2)
>>> func(qml.RY(1.0, [2]))
qml.RX(1.2, wires=[2])
>>> rfunc = qml.noise.partial_wires(qml.RX(1.2, [12]), phi=2.3)
>>> rfunc(qml.RY(1.0, ["light"]))
qml.RX(2.3, wires=["light"])

Finally, one may also use this with an instance of MeasurementProcess

>>> func = qml.noise.partial_wires(qml.expval(qml.Z(0)))
>>> func(qml.RX(1.2, wires=[9]))
qml.expval(qml.Z(9))