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

# AddInjectNoise

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

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/transpiler/passes/add_inject_noise.py#L28-L185)

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

Inserts [`InjectNoise`](/docs/api/samplomatic/auto/inject-noise "samplomatic.InjectNoise") annotations to all the unique boxes with twirling annotation.

This pass finds boxes matching the conditions implied by `targets`, adds inject noise to their annotations, and replaces them with new boxes with the updated annotations.

**Parameters**

- **strategy** – The noise injection strategy.

- **site** – Whether to inject the noise before or after the associated hard content. Boxes containing a measurement or a reset always use the `'before'` site, regardless of this value; see the note below.

- **overwrite** – Whether to overwrite the inject noise annotations that are already present in the circuit.

- **prefix\_ref** – A prefix to all the `ref` generated by this class.

- **prefix\_modifier\_ref** – A prefix to all the `modifier_refs` generated by this class.

- **targets** –

  The class of annotated boxes to target. The supported values are:

  - `'none'` to avoid annotating boxes of any kind.

  - `'gates'` to target only the twirl-annotated boxes that contain entanglers.

  - **`'measures'` to target only the twirl-annotated boxes that own classical**

    registers.

  - **`'all'` to target all the twirl-annotated boxes that contain entanglers**

    and/or own classical registers.

> **Note**
>
> Boxes containing a measurement or a reset are annotated with the `'before'` site even when `site='after'`. Virtual Paulis cannot travel leftward across a measurement or a reset, so an injection placed after the hard content of such a box is discarded during [`build()`](/docs/api/samplomatic/auto/build "samplomatic.build") on the qubits those instructions act on, while its sign is still reported. Forcing the `'before'` site guarantees that the injection is realized. Since `site` is one of the inputs to `ref()` generation, such a box is assigned the same `ref` whichever `site` is requested, whereas the `ref` of every other box changes along with it.

> **Note**
>
> The `BoxKey()` to `prefix_ref`. This means this pass assigns boxes with the same [`BoxKey`](/docs/api/samplomatic/auto/utils-box-key "samplomatic.utils.BoxKey") the same `ref` from circuit to circuit.

> **Note**
>
> When using the `'uniform_modification'` strategy, the ``On the other hand, the `()``’individual\_modification’\`\` strategy appends the value of a counter to `modifier_ref` that is incremented following DAG traversal order.

**Methods Summary**

|                                                                                                                    |                               |
| ------------------------------------------------------------------------------------------------------------------ | ----------------------------- |
| [`run`](#samplomatic.transpiler.passes.AddInjectNoise.run "samplomatic.transpiler.passes.AddInjectNoise.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_inject_noise.py#L134-L185)

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.
