qml.CompilePipeline

class CompilePipeline(*transforms, cotransform_cache=None)[source]

Bases: object

Class that contains a compile pipeline and the methods to interact with it.

The order of execution is the order in the list containing the containers.

Parameters:
  • initial_program (Optional[Sequence[BoundTransform]]) – A sequence of transforms with which to initialize the program.

  • cotransform_cache (Optional[CotransformCache]) – A named tuple containing the qnode, args, and kwargs required to compute classical cotransforms.

The main case where one would have to interact directly with a compile pipeline is when developing a Device. In this case, the pre-processing method of a device returns a compile pipeline. 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

transform()

Implemented Dunder methods

Programs have several implemented dunder methods for easy manipulation.

>>> from pennylane import CompilePipeline
>>> from copy import copy
>>> program = CompilePipeline()
>>> 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]
CompilePipeline(cancel_inverses, compile)
>>> len(program)
2
>>> True if program else False
True
>>> True if CompilePipeline() else False
False
>>> program2 = copy(program)
>>> program2 == program
True
>>> qml.compile in program
True
>>> qml.transforms.split_non_commuting in program
False
>>> program + program
CompilePipeline(compile, cancel_inverses, compile, cancel_inverses)

has_final_transform

True if the compile pipeline has a terminal transform.

is_informative

True if the compile pipeline is informative.

has_final_transform

True if the compile pipeline has a terminal transform.

is_informative

True if the compile pipeline is informative.

Returns:

Boolean

Return type:

bool

add_transform(transform, *targs, **tkwargs)

Add a transform to the end of the program.

append(transform)

Add a transform to the end of the program.

has_classical_cotransform()

Check if the compile pipeline has some classical cotransforms.

insert(index, transform)

Insert a transform at a given index.

pop([index])

Pop the transform container at a given index of the program.

remove(obj)

In place remove the input containers, specifically, 1.

set_classical_component(qnode, args, kwargs)

Set the classical jacobians and argnums if the transform is hybrid with a classical cotransform.

add_transform(transform, *targs, **tkwargs)[source]

Add a transform to the end of the program.

Note that this should be a function decorated with/called by qml.transform, and not a BoundTransform.

Parameters:
  • transform (Transform) – The transform to add to the compile pipeline.

  • *targs – Any additional arguments that are passed to the transform.

Keyword Arguments:

**tkwargs – Any additional keyword arguments that are passed to the transform.

append(transform)[source]

Add a transform to the end of the program.

Parameters:

transform (Transform or BoundTransform) – A transform represented by its container.

has_classical_cotransform()[source]

Check if the compile pipeline has some classical cotransforms.

Returns:

Boolean

Return type:

bool

insert(index, transform)[source]

Insert a transform at a given index.

Parameters:
  • index (int) – The index to insert the transform.

  • transform (transform or BoundTransform) – the transform to insert

pop(index=-1)[source]

Pop the transform container at a given index of the program.

Parameters:

index (int) – the index of the transform to remove.

Returns:

The removed transform.

Return type:

BoundTransform

remove(obj)[source]

In place remove the input containers, specifically, 1. if the input is a Transform, remove all containers matching the transform; 2. if the input is a BoundTransform, remove all containers exactly matching the input.

Parameters:

obj (BoundTransform or Transform) – The object to remove from the program.

set_classical_component(qnode, args, kwargs)[source]

Set the classical jacobians and argnums if the transform is hybrid with a classical cotransform.