Skip to main content

A Stim extension package to account for non-computational errors.

Project description

Deltakit-Stim

Deltakit-Stim is a Stim fork that adds support for non-computational leakage errors and an adaptive detector error model (DEM). It consists of a set of instructions to handle single qubit leakage within Stim's API definition. Specifically:

  • A leakage reset RL as a new GateType. It returns the indexed qubits in the sealed state, that is the encoded quantum state.
  • A leakage channel LEAKAGE as a new GateType. It creates a noisy channel for leakage.
  • A heralded leakage event HERALD_LEAKAGE_EVENT as a new GateType. It records the noise event in the measurement record.

The adaptive DEM is an extension to current Stim's DEM datastructure to hold metadata associated with non-computational errors (leakage, erasure, atom loss) to be further interpreted by the decoder. It provides additional edge updates to the decoding graph from heralded leakage events which can be pre-processed by the decoder to improve the qubit footprint.

Installation as a Python dependency

Whenever using hatch, uv or any pyproject-compatible Python manager, edit file pyproject.toml to add the line

  "deltakit-stim"

to the list of dependencies.

Installation from source

The simplest way to contribute is to git clone Deltakit-Stim from the GitHub repository

git clone https://github.com/Deltakit/deltakit-stim.git

Then, the C++ package can be installed either using build managers CMake

cd deltakit-stim
mkdir build
cd build
cmake ..

or Bazel

bazel build //:stim

provided a C++ compiler is installed on the system.

How Deltakit-Stim works

To get started with deltakit-stim, an example demonstrating how deltakit-stim handles leakage will be introduced. Qubits are designed to operate in two computational states: |0⟩ and |1⟩. However, qubits can sometimes "leak" into higher energy states (|2⟩, |3⟩, etc.) that are outside the computational sub-space. Leakage is a significant source of error as leaked qubits can spread errors to other qubits through multi-qubit gates.

How Deltakit-Stim models leakage differently:

  1. Specify where leakage occurs: Use LEAKAGE(p) gates to introduce leakage, where p is the probability of each specified qubit leaking.
  2. Leakage propagation through gates: Deltakit-Stim models how two-qubit gates (CZ, CX, CY, etc.) spread leakage between qubits and introduce depolarizing errors when leaked qubits interact. Users can configure leakage spreading and transfer rates using optional gate parameters (see gate documentation for details).
  3. Detect accumulated leakage: HERALD_LEAKAGE_EVENT adds a bit to the measurement record (accessible via rec[-...]) indicating whether a qubit has leaked, based on the accumulated leakage from LEAKAGE gates and propagation through 2-qubit gates. Reset gates (R, RX etc.) clear the accumulated leakage for their target qubits.
  4. Leakage-aware decoding: The DEM contains heralded errors with probabilities derived from the accumulated leakage, enabling leakage-aware decoding strategies.

This differs from Stim's HERALDED_ERASE, which requires explicitly specifying each heralded error at a particular qubit and time step, without automatic tracking of leakage accumulation and propagation.

The example below demonstrates how HERALD_LEAKAGE_EVENT enables leakage detection.

Getting Started

This example demonstrates the use of the LEAKAGE and HERALD_LEAKAGE_EVENT gates. This is essential for leakage-aware error correction and represents the key difference from Stim.

import numpy as np
import deltakit_stim

circuit = deltakit_stim.Circuit("""
R 0 1 2
CZ 0 1
CZ 1 2
LEAKAGE(0.1) 1
HERALD_LEAKAGE_EVENT 1
M 0 1 2
DETECTOR rec[-4]
DETECTOR rec[-3]
DETECTOR rec[-2]
DETECTOR rec[-1]
""")

sampler = circuit.compile_detector_sampler()
detection_events = sampler.sample(shots=1000)

print(f"Detection events shape: {detection_events.shape}")
print(f"Number of detectors: {detection_events.shape[1]}")

# The first detector (index 0) references rec[-4], the result of HERALD_LEAKAGE_EVENT
herald_events = detection_events[:, 0]
leakage_detected = np.sum(herald_events)
print(f"\nLeakage events detected: {leakage_detected} out of {len(herald_events)} shots")
print(f"Leakage rate: {leakage_detected / len(herald_events) * 100:.2f}%")

# Generate the DEM to see the heralded errors
dem = circuit.detector_error_model()
print(f"\nDetector Error Model:\n{dem}")

The circuit uses LEAKAGE(0.1) to simulate a 10% probability of leakage on qubit 1. The HERALD_LEAKAGE_EVENT instruction adds an entry to the measurement record, which is captured by the first detector (DETECTOR rec[-4], labeled D0 in the DEM), creating a fourth detector specifically for heralding in this circuit. Running this circuit for 1000 shots detects approximately 100 leakage events, matching the 10% leakage probability.

The generated Detector Error Model includes heralded errors showing how leakage affects the detectors:

error(0.5) D0 D2

This heralded error indicates that when the herald detector D0 fires (showing qubit 1 leaked), detector D2 is affected with 50% probability because measuring a leaked qubit produces a random outcome. Without HERALD_LEAKAGE_EVENT, the DEM would only show three detectors without any errors.

Use in Error Correction

Leakage-aware decoders use the herald information from HERALD_LEAKAGE_EVENT to make better correction decisions. The Local Clustering Decoder demonstrates that leakage-aware decoding can reduce physical qubit requirements by a factor of 4 compared to standard non-adaptive decoding.

For complete examples of leakage-aware decoding workflows, see the Deltakit Decoding guide.

Citation

For any reference to Stim, please consider using the citation:

@article{gidney2021stim,
  doi = {10.22331/q-2021-07-06-497},
  url = {https://doi.org/10.22331/q-2021-07-06-497},
  title = {Stim: a fast stabilizer circuit simulator},
  author = {Gidney, Craig},
  journal = {{Quantum}},
  issn = {2521-327X},
  publisher = {{Verein zur F{\"{o}}rderung des Open Access Publizierens in den Quantenwissenschaften}},
  volume = {5},
  pages = {497},
  month = jul,
  year = {2021}
}

If you use Deltakit-Stim's leakage-aware features, please also consider citing the Local Clustering Decoder paper, which details the leakage-aware decoding method:

@article{ziad2025local,
  doi     = {10.1038/s41467-025-66773-x},
  url     = {https://doi.org/10.1038/s41467-025-66773-x},
  title   = {Local clustering decoder as a fast and adaptive hardware decoder for the surface code},
  author  = {Ziad, Abbas B. and Zalawadiya, Ankit and Topal, Canberk and Camps, Joan and Gehér, György P. and Stafford, Matthew P. and Turner, Mark L.},
  journal = {Nature Communications},
  volume  = {16},
  pages   = {11048},
  year    = {2025},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deltakit_stim-0.1.2.tar.gz (895.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

deltakit_stim-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

deltakit_stim-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

deltakit_stim-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

deltakit_stim-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file deltakit_stim-0.1.2.tar.gz.

File metadata

  • Download URL: deltakit_stim-0.1.2.tar.gz
  • Upload date:
  • Size: 895.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deltakit_stim-0.1.2.tar.gz
Algorithm Hash digest
SHA256 172ece6fa43bb86c383e2a9964347d09cb3ec94389bc42602e92c196acbab7a9
MD5 e21c728e662d4655909f010d62cf044d
BLAKE2b-256 1b271b8838fb4639c98902c5be9159600e80d67547a0a9d1aced2e42d20d988c

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2.tar.gz:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5adff0d2254c61601907d750fdfb6242ae8d94f42ddf2f39c1398b720806a0cc
MD5 767c705e6ff6ff60ef6eadd95c288333
BLAKE2b-256 a1741367a952467c4775775dc5f74d1b969616ed9cd8ce3ce08075d5a1c2d438

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ead3b7a3ee4a6296cbcea79be7d3a329c9750df84bb83a423a71ca7663e48cb1
MD5 a6982a2721fa9dcc26021264f46f8bb5
BLAKE2b-256 a404c84663c0c3660e72dafd690bfe73c150a0c6c6978ed0c51a8eba1edcb070

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e869408ce2eebbc074af4b2267702c589ade9aa2dfdc83bb7681c8228b75ac75
MD5 6df9739fd69f06f90d94b9a21647eae5
BLAKE2b-256 7c8a5bb06541c8f76564aa78f2cff4226d1b83c3c82037a913f2517a3081f909

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8d360ede6f2231b2cfa05b467225bc9e6a3576a8166bfe37a0703ed3ff7cc99b
MD5 9267d1311d4145495423bbe68391406d
BLAKE2b-256 bb9e93071172922bc8691fbf61a87cbaed718a01a007aa7c8ba65708e0352ae0

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f5c396657347658b9fa90b9f4007bd8c32ec01122666251f87eeac08ea527f91
MD5 bc7c3b729fcd63b74d95cc87e161579c
BLAKE2b-256 1fbaa6a1f19f92a77e95bdc01ce555ac4f40aab2837f6cdc1691383f856d6dc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fd79aea92c9962dbe5cf10871c792e270222d5f0b18a76e654894cf696a79ef7
MD5 45f55c990a55bd96682ae8b9b60e286f
BLAKE2b-256 a60473445ede44f9aa46e5df178f6952f359dc24af39667dd98bd840341b4019

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12f8eff3477e65e6d175c158ce5eaefa1dae739aa1f9bc2650b103aeee66afbb
MD5 f5cf729b15cee2509a6d0d8d0cf983d5
BLAKE2b-256 2cb32492b67a085f0f11d73aed719ad5ef1850e1e032acac6b79a7c3ad233368

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 eaa6abc28bb45a684999e800c26ea2b5ce7bf5ac4a4a18a8d71a62e68782c41d
MD5 bb5d45003c0ca121f5650f32be9872b3
BLAKE2b-256 8f2fee0a0a9d7eed6cc654bfb8adda5ec1f03d4bf143eeb7571d8e5f2484c01e

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f5d5fff7ffa5b3866836166cb84e3379ac51c250e88e3f465baf1c8bf918044b
MD5 17e83beb9a3bbf8f08bcc8e443e4c02f
BLAKE2b-256 04e1251c123f631b46f215c566e721b3c34fa728bdf9c3999b019e0379752cc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79f13e182de5a332794469f783dadea2d52370201dfe52714f0e44b751415a0e
MD5 736b557f82eae88a910abeeb4a4122e4
BLAKE2b-256 7580acd4586cdb9ee199730c9c63b81e7c5c4c040ed61dd26bb5382906bbd600

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 80edde771df782e152cc7d2b6d1426007040c8d13cdfcbcc551459e3b2b85b95
MD5 c9e1e879d0611c5a5a2807dd2ee9f2a5
BLAKE2b-256 0bae7b75edec75d88bfbca17d3093b369886856adf70327ed46137a8d5a4cb72

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_x86_64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b015213ba78e55e4842e5dfea6b8560001ad54c3cd07fe9502a9cbb717e2f358
MD5 f13ac0b9770eebcb23a72ceeafc10525
BLAKE2b-256 ea5bb403cc62c9df5b4dc7bca8d7bcd4e70d2b2aa7ca540a2e4772c99e0dcab1

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.2-cp310-cp310-macosx_15_0_arm64.whl:

Publisher: publish.yml on Deltakit/deltakit-stim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page