---
title: AddTags (latest version)
description: API reference for samplomatic.transpiler.passes.AddTags in the latest version of samplomatic
source: https://quantum.cloud.ibm.com/docs/en/api/samplomatic/auto/transpiler-passes-add-tags
---

# AddTags

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

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/transpiler/passes/add_tags.py#L26-L120)

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

Inserts [`Tag`](/docs/api/samplomatic/auto/tag "samplomatic.Tag") annotations to all box instructions.

This pass finds all `box` nodes in the DAG and adds [`Tag`](/docs/api/samplomatic/auto/tag "samplomatic.Tag") annotations to them. The tagging mode controls how `ref` strings are assigned:

- `'unique_box'`: the `ref` is a truncated hash of the box’s structural content (i.e. ignoring single-qubit gate, and see [`BoxKey`](/docs/api/samplomatic/auto/utils-box-key "samplomatic.utils.BoxKey")), so structurally equivalent boxes share the same `ref` across circuits. Boxes with different [`Twirl`](/docs/api/samplomatic/auto/twirl "samplomatic.Twirl") specifications are treated as unique, but all other annotations are ignored when comparing boxes.
- `'unique_instance'`: the `ref` is an incrementing counter (`t0`, `t1`, …), so every box in a circuit gets a unique `ref`. The counter resets on each call to [`run()`](#samplomatic.transpiler.passes.AddTags.run "samplomatic.transpiler.passes.AddTags.run").
- `'noise_ref'`: the `ref` is taken from the box’s [`InjectNoise`](/docs/api/samplomatic/auto/inject-noise "samplomatic.InjectNoise") annotation’s `ref` field joined by an underscore with its `modifier_ref` field when present. Boxes without an [`InjectNoise`](/docs/api/samplomatic/auto/inject-noise "samplomatic.InjectNoise") annotation are skipped.

**Parameters**

- **mode** – The tagging mode. `'unique_box'` assigns the same ref to structurally equivalent boxes; `'unique_instance'` assigns a unique ref to every box.
- **overwrite** – Whether to overwrite [`Tag`](/docs/api/samplomatic/auto/tag "samplomatic.Tag") annotations that are already present in the circuit.
- **prefix\_ref** – A prefix to all the `ref` strings generated by this class.

**Methods Summary**

|                                                                                                      |                               |
| ---------------------------------------------------------------------------------------------------- | ----------------------------- |
| [`run`](#samplomatic.transpiler.passes.AddTags.run "samplomatic.transpiler.passes.AddTags.run")(dag) | Run a pass on the DAGCircuit. |

**Methods Documentation**

### run

`run(dag: DAGCircuit) → DAGCircuit`

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/transpiler/passes/add_tags.py#L80-L120)

Run a pass on the DAGCircuit. This is implemented by the pass developer.

**Parameters**

**dag** – the dag on which the pass is run.

**Raises**

[**NotImplementedError**](https://docs.python.org/3/builtins/exceptions.html#NotImplementedError) – when this is left unimplemented for a pass.
