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
QNodecontaining the compilation pipeline to be marked. IfNone, this function acts as a decorator for aQNode.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
QNodeor a decorator function ifobjis 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
Hadamardgates have been cancelled by usinglevel="after-cancel-inverses"withspecs():>>> 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_rotationstransform has been applied by passinglevel="after-merge-rotations"todraw():>>> 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