qml.transforms.core.BoundTransform¶
- class BoundTransform(transform, args=(), kwargs=None, *, use_argnum=False, **transform_config)[source]¶
Bases:
objectA transform with bound inputs.
- Parameters:
transform – Any transform.
args (Sequence[Any]) – The positional arguments to use with the transform.
kwargs (Dict | None) – The keyword arguments for use with the transform.
- Keyword Arguments:
use_argnum (bool) – An advanced option used in conjunction with calculating classical cotransforms of jax workflows.
See also
>>> bound_t = BoundTransform(qml.transforms.merge_rotations, (), {"atol": 1e-4}) >>> bound_t <merge_rotations((), {'atol': 0.0001})>
The class can also be created by directly calling the transform with its inputs:
>>> qml.transforms.merge_rotations(atol=1e-4) <merge_rotations((), {'atol': 0.0001})>
These objects can now directly applied to anything individual transforms can apply to:
@bound_t @qml.qnode(qml.device('null.qubit', wires=2)) def c(x): qml.RX(x, 0) qml.RX(-x + 1e-6, 0) qml.RY(x, 1) qml.RY(-x + 1e-2, 1) return qml.probs(wires=(0,1))
If we draw this circuit, we can see that the
merge_rotationstransforms was applied with a tolerance of1e-4. TheRXgates sufficiently close to zero disappear, while theRYgates that are further from zero remain.>>> print(qml.draw(c)(1.0)) 0: ───────────┤ ╭Probs 1: ──RY(0.01)─┤ ╰Probs
Repeated versions of the bound transform can be created with multiplication:
>>> bound_t * 3 CompilePipeline(merge_rotations, merge_rotations, merge_rotations)
And it can be used in conjunction with both individual transforms, bound transforms, and compile pipelines.
>>> bound_t + qml.transforms.cancel_inverses CompilePipeline(merge_rotations, cancel_inverses) >>> bound_t + qml.transforms.cancel_inverses + bound_t CompilePipeline(merge_rotations, cancel_inverses, merge_rotations)
Attributes
The stored quantum transform's
args.The stored quantum transform's classical co-transform.
The expand_transform associated with this transform.
Whether or not the transform must be the last one to be executed in a
CompilePipeline.Whether or not a transform is informative.
The stored quantum transform's
kwargs.The name of the corresponding Catalyst pass, if it exists.
The stored quantum transform's PLxPR transform.
The raw tape transform definition for the transform.
The raw tape transform definition of the transform.
- args¶
The stored quantum transform’s
args.
- classical_cotransform¶
The stored quantum transform’s classical co-transform.
- expand_transform¶
The expand_transform associated with this transform.
- is_final_transform¶
Whether or not the transform must be the last one to be executed in a
CompilePipeline.This property is
Truefor most gradient transforms.
- is_informative¶
Whether or not a transform is informative. If true the transform is queued at the end of the transform program and the tapes or qnode aren’t executed.
This property is rare, but used by such transforms as
qml.transforms.commutation_dag.
- kwargs¶
The stored quantum transform’s
kwargs.
- pass_name¶
The name of the corresponding Catalyst pass, if it exists.
- plxpr_transform¶
The stored quantum transform’s PLxPR transform.
UNMAINTAINED AND EXPERIMENTAL
- tape_transform¶
The raw tape transform definition for the transform.
- transform¶
The raw tape transform definition of the transform.