---
title: GroupMeasIntoBoxes (latest version)
description: API reference for samplomatic.transpiler.passes.GroupMeasIntoBoxes in the latest version of samplomatic
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/samplomatic/auto/transpiler-passes-group-meas-into-boxes
---

# GroupMeasIntoBoxes

*class* `samplomatic.transpiler.passes.GroupMeasIntoBoxes(*args, **kwargs)`

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/transpiler/passes/group_meas_into_boxes.py#L30-L150)

Bases: [`TransformationPass`](/docs/api/qiskit/qiskit.transpiler.TransformationPass)

Collect the measurements in a circuit inside boxes.

This pass collects all of the measurements in the input circuit in boxes. 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:

  - `'twirl'` for a [`Twirl`](/docs/api/samplomatic/auto/twirl "samplomatic.Twirl") annotation.
  - `'change_basis'` for a [`ChangeBasis`](/docs/api/samplomatic/auto/change-basis "samplomatic.ChangeBasis") annotation with mode `'measure'`.
  - `'all'` for both [`Twirl`](/docs/api/samplomatic/auto/twirl "samplomatic.Twirl") and [`ChangeBasis`](/docs/api/samplomatic/auto/change-basis "samplomatic.ChangeBasis") annotations.

- **decomposition** –

  The gate sequence into which single-qubit dressing gates are synthesized.

  - `'rzsx'` synthesizes single-qubit gates with rz-sx-rz-sx-rz.
  - `'rzrx'` synthesizes single-qubit gates with rz-rx-rz.

- **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, two-qubit gates, and resets act as delimiters. This means that when the pass encounters one of these on a subset of qubits, it immediately terminates the collection for those qubits and flushes the collected measurements into a box.

**Methods Summary**

|                                                                                                                            |                                                              |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| [`run`](#samplomatic.transpiler.passes.GroupMeasIntoBoxes.run "samplomatic.transpiler.passes.GroupMeasIntoBoxes.run")(dag) | Collect the operations in the dag inside left-dressed boxes. |

**Methods Documentation**

### run

`run(dag: DAGCircuit) → DAGCircuit`

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/transpiler/passes/group_meas_into_boxes.py#L91-L150)

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 measurement nodes 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.
