qml.transforms.core.transform_dispatcher.TransformDispatcher¶
- class TransformDispatcher(*args, **__)[source]¶
Bases:
objectConverts 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.transformif you would like to make a custom transform.See also
Attributes
The classical co-transform.
The expand transform.
Trueif the transformed tapes must be executed.Trueif the transform is informative.Function for transforming plxpr.
The quantum transform.
- classical_cotransform¶
The classical co-transform.
- expand_transform¶
The expand transform.
- final_transform¶
Trueif the transformed tapes must be executed.
- is_informative¶
Trueif the transform is informative.
- plxpr_transform¶
Function for transforming plxpr.
- 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),targsandtkwargs(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.