Serving all of your circuit sampling needs since 2025.
Actively maintained. Last release 3 months ago, commits in 15 of the last 26 weeks. A safe choice.
pip install samplomaticServing all of your circuit sampling needs since 2025.
[!NOTE] This library is in a beta stage of development where things are changing fast and in breaking ways. Although each version of this library is well-tested, while the major version is
0, please expect breaking changes between minor versions and pin your dependencies accordingly. We do not issue deprecation warnings presently, but we will document breaking changes in the changelog. Please see the deprecation policy for details. The location of this project may also move from https://github.com/Qiskit/samplomatic, where timelines are not yet determined.
Samplomatic is a library that helps you sample randomizations of your quantum circuits in exactly the way that you specify. Pauli twirling a static circuit is the simplest example, but the types of randomization available are extensible by design—we hope that you will contribute your own weird groups! Beyond twirling, which is a primary use-case, this library also supports other types of randomization, such as sampling-based noise injection.
Documentation
Documentation is hosted at https://qiskit.github.io/samplomatic.
Installation
You can install Samplomatic via pip from PyPI:
pip install samplomatic
For visualization support, include the visualization dependencies:
pip install samplomatic[vis]
See the contribution guidelines for details on developer dependencies and editable installations.
Hello World
In samplomatic, twirling intent is specified declaratively with annotated box instructions within a Qiskit quantum circuit. Other randomization intent is available via configuring the attributes of annotations, or other annotation types like InjectNoise.
These boxes can be constructed manually, as in the following example, or automatically, using transpiler passes defined in samplomatic.transpiler.
from samplomatic import build, Twirl
from qiskit.circuit import QuantumCircuit, Parameter
import numpy as np
circuit = QuantumCircuit(5)
with circuit.box([Twirl()]):
# twirled boxes are always "dressed": putting your single-qubit gates into
# the boxes will result in them being composed into the "dressing" layer
# that also includes random (in this case) Paulis
circuit.sx(0)
circuit.t(0)
# notice that twirl-annotated circuits can themselves be parametric
circuit.rx(Parameter("x"), 3)
circuit.rx(Parameter("y"), 4)
circuit.x(2)
circuit.cx(1, 0)
circuit.cz(3, 4)
with circuit.box([Twirl(decomposition="rzrx")]):
# this box Pauli-twirls measurement, folding hadamards into the dressing
circuit.h(range(5))
circuit.measure_all()
circuit.draw("mpl", scale=0.5)

