GroupGatesIntoBoxes

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

Bases: TransformationPass

Collect the gates in a circuit inside left-dressed boxes.

This pass collects all of the gates in the input circuit in left-dressed boxes. Each box in the returned circuit contains potentially multiple single-qubit gates followed by a layer of multi-qubit gates. To assign the gates to these boxes, it uses a greedy collection strategy that tries to collect gates in the earliest possible box that they can fit. In addition to the left- dressed boxes, the pass also adds a right-dressed box at the end of the circuit to collect virtual gates.

Note

Barriers and boxes that are present in the input circuit act as delimiters. This means that when the pass encounters one of these delimiters acting on a subset of qubits, it immediately terminates the collection for those qubits and flushes the collected gates into a left-dressed box. The delimiters themselves remain present in the output circuit, but are placed outside of any boxes.

Note

Measurements also act as delimiters. However, any group of single-qubit gates that preceed the measurements are left unboxed. This allows grouping these single-qubit gates in an optimal way with a subsequent pass, depending on whether the user wants to also group the measurements into boxes and on their grouping strategy.

Note

The circuits returned by this pass may not be buildable. To make them buildable, one can either use :class`~.AddTerminalRightDressedBoxes` to add right-dressed “collector” boxes.

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- and two-qubit gate 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 topological ordering.

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