qml.transforms.core.transform_dispatcher.TransformDispatcher¶
- class TransformDispatcher(*args, **kwargs)[source]¶
Bases:
object
Converts a transform that has the signature
(tape -> Sequence(tape), fn)
to a transform dispatcher that can act onpennylane.tape.QuantumTape
, quantum function,pennylane.QNode
,pennylane.devices.Device
.Warning
This class is developer-facing and should not be used directly. Instead, use
qml.transform
if you would like to make a custom transform.See also
Attributes
The classical co-transform.
The expand transform.
True
if the transformed tapes must be executed.True
if the transform is informative.The quantum transform.
- classical_cotransform¶
The classical co-transform.
- expand_transform¶
The expand transform.
- final_transform¶
True
if the transformed tapes must be executed.
- is_informative¶
True
if the transform is informative.
- transform¶
The quantum transform.
Methods
Register a custom QNode execution wrapper function for the batch transform.
default_qnode_transform
(qnode, targs, tkwargs)The default method that takes in a QNode and returns another QNode with the transform applied.
- custom_qnode_transform(fn)[source]¶
Register a custom QNode execution wrapper function for the batch transform.
Example
@transform def my_transform(tape, *targs, **tkwargs): ... return tapes, processing_fn @my_transform.custom_qnode_transform def my_custom_qnode_wrapper(self, qnode, targs, tkwargs): tkwargs = {**tkwargs, shots=100} return self.default_qnode_transform(qnode, targs, tkwargs)
The custom QNode execution wrapper must have arguments
self
(the batch transform object),qnode
(the input QNode to transform and execute),targs
andtkwargs
(the transform arguments and keyword arguments respectively).It should return a QNode that accepts the same arguments as the input QNode with the transform applied.
The default
default_qnode_transform()
method may be called if only pre- or post-processing dependent on QNode arguments is required.