GroupMeasIntoBoxes

class samplomatic.transpiler.passes.GroupMeasIntoBoxes(*args, **kwargs)[source]

Bases: TransformationPass

Collect the measurements in a circuit inside boxes.

This pass collects all of the measurements in the input circuit in boxes, together with the single-qubit gates that precede them. To assign the measurements to these boxes, it uses a greedy collection strategy that tries to collect measurements in the earliest possible box that they can fit.

Parameters:
  • annotations

    The annotations placed on the measurement boxes. The supported values are:

  • prefix_ref – A prefix to all the ChangeBasis.ref generated by this class. Every ref is generated by appending a counter to prefix_ref. In order to avoid collisions, the counter is shared across all the instances of this class and it is incremented every time that a new ref is created.

Note

Barriers, boxes, and multi-qubit gates that are present in the input circuit act as delimiters. This means that when one of these delimiters stands between a group of single-qubit gates and a measurement, those single-qubit gates are not added to the box.

Methods Summary

run(dag)

Collect the operations in the dag inside left-dressed boxes.

Methods Documentation

run(dag: DAGCircuit) DAGCircuit[source]

Collect the operations in the dag inside left-dressed boxes.

The collection strategy undertakes the following steps:
  • Loop through the DAG’s op nodes in topological order.

  • Group together single-qubit gate nodes and measurement nodes that need to be placed in the same box.

  • Whenever a node can be placed in more than one group, place it in the earliest possible group–where “earliest” is with reference to opological ordering.

  • When looping is complete, replace each group with a box.