qml.marker

marker(obj=None, label=None)[source]

Mark a location in a compilation pipeline for easy access with inspectability.

Parameters:
  • obj (QNode | None) – The QNode containing the compilation pipeline to be marked. If None, this function acts as a decorator for a QNode.

  • label (str | None) – A descriptive label for this specific stage in the compilation process. Check get_transform_program() for more information on the allowed values and usage details of this argument.

Returns:

The marked QNode or a decorator function if obj is not provided.

Return type:

QNode | Callable

Raises:

ValueError – If the ‘label’ argument is not provided.

See also

Markers can also be manually added to pipelines with add_marker().

Example:

Consider the following circuit where several stages have been marked within the transforms applied:

@qml.marker("after-merge-rotations")
@qml.transforms.merge_rotations
@qml.marker("after-cancel-inverses")
@qml.transforms.cancel_inverses
@qml.marker("nothing-applied")
@qml.qnode(qml.device("null.qubit"))
def c():
    qml.RX(0.5, 0)
    qml.H(0)
    qml.H(0)
    qml.RX(0.5, 0)
    return qml.probs()

We can identify where each marker sits relative to the applied transforms by printing the pipeline,

>>> print(c.compile_pipeline)
CompilePipeline(
   ├─▶ nothing-applied
  [1] cancel_inverses(),
   ├─▶ after-cancel-inverses
  [2] merge_rotations()
   └─▶ after-merge-rotations
)
>>> print(c.compile_pipeline.markers)
['nothing-applied', 'after-cancel-inverses', 'after-merge-rotations']

These markers are then recognized by a few of our inspectability features. For example, we can verify the circuit resources after the Hadamard gates have been cancelled by using level="after-cancel-inverses" with specs():

>>> print(qml.specs(c, level="after-cancel-inverses")()) # or level=1
Device: null.qubit
Device wires: None
Shots: Shots(total=None)
Level: after-cancel-inverses

Resource specifications:
  Total wire allocations: 1
  Total gates: 2
  Circuit depth: 2

  Gate types:
    RX: 2

  Measurements:
    probs(all wires): 1

Similarly, we can print the circuit after the merge_rotations transform has been applied by passing level="after-merge-rotations" to draw():

>>> print(qml.draw(c, level="after-merge-rotations")()) # or level=2
0: ──RX(1.00)─┤  Probs

or even display our circuit before any transformations,

>>> print(qml.draw(c, level="nothing-applied")()) # or level=0
0: ──RX(0.50)──H──H──RX(0.50)─┤  Probs

Contents

Using PennyLane

Release news

Development

API

Internals