qp.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.

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 or the ‘label’ is a protected level.

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:

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

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

>>> print(c.compile_pipeline)
CompilePipeline(
   ├─▶ nothing-applied
  [0] cancel_inverses(),
   ├─▶ after-cancel-inverses
  [1] 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(qp.specs(qp.qjit(c), level="after-cancel-inverses")()) # or level=1
Device: null.qubit
Device wires: 1
Shots: Shots(total=None)
Level: after-cancel-inverses

Quantum operations:
- Total: 2
  - RX: 2
Measurement processes:
- probs(all wires): 1
Total wires: 1
Circuit Depth: Not computed

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

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

or even display our circuit before any transformations,

>>> print(qp.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