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 on pennylane.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

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.

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.

custom_qnode_transform(fn)

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 and tkwargs (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.

default_qnode_transform(qnode, targs, tkwargs)[source]

The default method that takes in a QNode and returns another QNode with the transform applied.