Skip to main content
IBM Quantum Platform

map_annotations

samplomatic.utils.map_annotations(circuit: QuantumCircuit, fn: Callable[[list[Annotation]], list[Annotation]]) → QuantumCircuit

GitHub

Return a new circuit where each box’s annotations are replaced by fn(annotations).

The callable receives the current list of annotations on the box and must return a new list of annotations to use. Non-box instructions are copied unchanged, and the original circuit is not mutated.

Parameters

  • circuit – The circuit whose box annotations to transform.
  • fn – A callable that receives a box’s annotation list and returns the replacement list.

Returns

A new circuit with transformed annotations on every box.

from qiskit.circuit import QuantumCircuit
from samplomatic import Twirl, InjectNoise
from samplomatic.utils import map_annotations, strip_annotations

circuit = QuantumCircuit(2)
with circuit.box([Twirl(), InjectNoise("ref")]):
    circuit.cx(0, 1)

# Keep only Twirl annotations
filtered = map_annotations(circuit, lambda anns: [a for a in anns if isinstance(a, Twirl)])
Was this page helpful?
Report a bug, typo, or request content on GitHub.