qml.transforms.core.transform_program.TransformProgram¶
-
class
TransformProgram
(initial_program=None)[source]¶ Bases:
object
Class that contains a transform program and the methods to interact with it.
The order of execution is the order in the list containing the containers.
The main case where one would have to interact directly with a transform program is when developing a
Device
. In this case, the pre-processing method of a device returns a transform program. You should directly refer to the device API documentation for more details.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
Implemented Dunder methods
Programs have several implemented dunder methods for easy manipulation.
>>> program = TransformProgram() >>> program.add_transform(qml.compile) >>> program.add_transform(qml.transforms.cancel_inverses) >>> [t for t in program] # Iteration [<compile([], {})>, <cancel_inverses([], {})>] >>> program[0] <compile([], {})> >>> program[::-1] TransformProgram(cancel_inverses, compile) >>> len(program) 2 >>> True if program else False True >>> True if TransformProgram() else False False >>> program2 = copy.copy(program) >>> program2 == program True >>> qml.compile in program True >>> qml.transforms.hamiltonian_expand in program False >>> program + program TransformProgram(compile, cancel_inverses, compile, cancel_inverses)
Attributes
True
if the transform program has a terminal transform.True
if the transform program is informative.-
has_final_transform
¶ True
if the transform program has a terminal transform.
-
is_informative
¶ True
if the transform program is informative.- Returns
Boolean
- Return type
bool
Methods
add_transform
(transform, *targs, **tkwargs)Add a transform (dispatcher) to the end of the program.
get_last
()Get the last transform container.
Check if the transform program has some classical cotransforms.
insert_front
(transform_container)Insert the transform container at the beginning of the program.
insert_front_transform
(transform, *targs, …)Add a transform (dispatcher) to the beginning of the program.
is_empty
()Check if the transform program is empty or not.
Pop the transform container at the beginning of the program.
push_back
(transform_container)Add a transform (container) to the end of the program.
-
add_transform
(transform, *targs, **tkwargs)[source]¶ Add a transform (dispatcher) to the end of the program.
Note that this should be a function decorated with/called by
qml.transforms.transform
, and not aTransformContainer
.- Parameters
transform (TransformDispatcher) – The transform to add to the transform program.
*targs – Any additional arguments that are passed to the transform.
- Keyword Arguments
**tkwargs – Any additional keyword arguments that are passed to the transform.
-
get_last
()[source]¶ Get the last transform container.
- Returns
The last transform in the program.
- Return type
- Raises
TransformError – It raises an error if the program is empty.
-
has_classical_cotransform
()[source]¶ Check if the transform program has some classical cotransforms.
- Returns
Boolean
- Return type
bool
-
insert_front
(transform_container)[source]¶ Insert the transform container at the beginning of the program.
- Parameters
transform_container (TransformContainer) – A transform represented by its container.
-
insert_front_transform
(transform, *targs, **tkwargs)[source]¶ Add a transform (dispatcher) to the beginning of the program.
- Parameters
transform (TransformDispatcher) – The transform to add to the front of the transform program.
*targs – Any additional arguments that are passed to the transform.
- Keyword Arguments
**tkwargs – Any additional keyword arguments that are passed to the transform.
-
is_empty
()[source]¶ Check if the transform program is empty or not.
- Returns
Boolean, True if empty, False otherwise.
- Return type
bool
-
pop_front
()[source]¶ Pop the transform container at the beginning of the program.
- Returns
The transform container at the beginning of the program.
- Return type
-
push_back
(transform_container)[source]¶ Add a transform (container) to the end of the program.
- Parameters
transform_container (TransformContainer) – A transform represented by its container.
-