---
title: count_unique_box_instructions (latest version)
description: API reference for samplomatic.utils.count_unique_box_instructions in the latest version of samplomatic
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/samplomatic/auto/utils-count-unique-box-instructions
---

# count\_unique\_box\_instructions

`samplomatic.utils.count_unique_box_instructions(instructions: Iterable[CircuitInstruction], undress_boxes: bool = True, normalize_annotations: Callable[[Iterable[Annotation]], list[Annotation]] | None = None) → list[tuple[CircuitInstruction, int]]`

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/utils/find_unique_box_instructions.py#L54-L99)

Return unique box instructions and their number of occurrences.

This function iterates through the given `instructions`, identifying those that contain a `BoxOp` operation and comparing them based on their content and annotations. It returns a list of pairs of instructions that contains unique boxes and their counts. Optionally, it allows undressing the boxes before comparison, as well as normalizing their annotations to ignore irrelevant fields.

**Parameters**

- **instructions** – The instructions to iterate through.
- **undress\_boxes** – Whether to call the `undress_box()` method on each box before comparison.
- **normalize\_annotations** – A callable mapping annotations to annotations, which is applied to the annotations of each box before comparison. If `None`, it discards every annotation that is not of type `Twirl` and `InjectNoise`, and it resets the `modifier_ref` field of `InjectNoise` annotations to the default value.

**Returns**

A list of tuples of unique instructions and their counts.
