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{locher2025local,
  doi = {10.1038/s41467-025-66773-x},
  url = {https://doi.org/10.1038/s41467-025-66773-x},
  title = {Local clustering decoder: beating the trade-off of code distance and circuit depth in quantum error correction},
  author = {Locher, Dominik F. and Bohdanowicz, Thomas C. and Lao, Lingling and Leroux, Ian and Beale, Stefanie J. and Verdon, Guillaume and Vuillot, Christophe and Brown, Natalie C.},
  journal = {Nature Communications},
  volume = {16},
  number = {1},
  pages = {554},
  year = {2025},
  publisher = {Nature Publishing Group}
}

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.1.tar.gz (895.3 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.1-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.1-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.1-cp313-cp313-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

deltakit_stim-0.1.1-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.1-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.1-cp312-cp312-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

deltakit_stim-0.1.1-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.1-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.1-cp311-cp311-macosx_15_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

deltakit_stim-0.1.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: deltakit_stim-0.1.1.tar.gz
  • Upload date:
  • Size: 895.3 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.1.tar.gz
Algorithm Hash digest
SHA256 57b83848d095194614a1346a26b074a87f1a0a01723fd1806dd735de1d6bcc4c
MD5 8990f70949a868b0a1c76c13172ab3a8
BLAKE2b-256 9fe3d0af9c28cdd9e41fb6805e2dc262ae64ed00e15c1a21ae6e9a034496d022

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1.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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f1ee459ead5bd3f936bc9c2b4984f5e55caaeaa395705b055a039c33ddad924e
MD5 0fe4c5a7ce6ed6ee754920ff9fe97683
BLAKE2b-256 59f56838776180763706e684a0b26e32646f376ef61e1e5fb963aa8d836fe0b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp313-cp313-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 670dadf4e88e9aa4c80c7ea61e1e34f8c6b763693d1c748c6edbc655505d0bbd
MD5 81d3bd40c4b48692c28d8aeb072ed333
BLAKE2b-256 11d61eb150dce170f52b35f2afb27e671edfb16e0a02fc774dbaca98cf1a368a

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c3b0d519bd8bae12239f5759b0b4aae2a4c9d35650830e04f06d0eeecb25a09b
MD5 9a5b80b8e31e0aba8f86cedbb9a51444
BLAKE2b-256 4a16afa5668a75c63410449edd23c6233532793942569791956b8239aef34cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cad56dd865076c19f99568311ace79a9ff9d2f25c344d1d1d0291f03b890e7ad
MD5 958948c361ec199e745ddc95173e9903
BLAKE2b-256 695accd65693f92dbf06665e3ce0bf81d07d8c4c894115f18625f4459e03a5b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp312-cp312-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 07f70f9ff198c94066dad4d8eb33679c278eb7a7a8c9e29a5c56c183f252e2b4
MD5 54366029fff6d967d4069bc4385cf298
BLAKE2b-256 5c1936fdf24e5ab6c6e9bcded7df18b828d984e7ed76383f7eb1f50e42c9a0b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 131c9e0c2ea9bd07a9d544edeab0cef64e027aada4522d023c8d4d2d8675bd5b
MD5 466a63654329a671bcfad62a6d594cfd
BLAKE2b-256 847fb62543315dfd2db7b8285e0c14566c4321c297f32f59c7df8a4abbe55e28

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 85d47310814b203b5c92b34756ac9d94f6915d15771d86c02d61c315d757a5a5
MD5 a03cdfbf44aa619a255f9ea1a1c75a52
BLAKE2b-256 94b7e3f95a8a1c9024859e0137b55db1857ef6fd2ae7a488d619b8e5dbd19cbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp311-cp311-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d5bc9200dc7bcb9c31189ebf08382182651899cbc4707159aeae781e474fa210
MD5 3115e30346dfe6a7be0d798dba920d52
BLAKE2b-256 a0b499476e038fe3f76a667b86f77cff6787f76a0a1612ff782df019f97a856e

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cea83dee0644b84ab2420a6db7d98c3b0015b942ed2fbe9fadde165e3d19382e
MD5 5865ec096a564c33335765ebaf0c7a8f
BLAKE2b-256 a40392f872354a8704794c05d0c2b02fd67a6a727c439aed999249d9cb5b5431

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 395100a58ad4fc807fc926660a7e148f314c663b8439c2b7b2de04f369b2052b
MD5 aeb2480f3e48be61e31c5df02fec61e9
BLAKE2b-256 a7129abbece63616cc12b775300d20e5da08e13dd6089691798457ac7d77b936

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp310-cp310-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4023b0e2c364c9ea489f818970afb39426f615cf32b2b12efef8d8a90a3d4fc3
MD5 ab1eed08be591ed8e2297d6bc2976120
BLAKE2b-256 e7759b18f92a35ced6bff809d5b273273e6b8ac908da7dc6157b9e757b3860c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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.1-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for deltakit_stim-0.1.1-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b4f403e2e78d6bfeb7fb4c0fc56a1a72188d4881a0be5a365a5b6b806d2bc9e3
MD5 189492594e2a5ee5922a5b68eb2bba1a
BLAKE2b-256 d4f982c266f0bebf1cbf3260b045e80de5fa5d74d67114a71f503c93b372dff0

See more details on using hashes here.

Provenance

The following attestation bundles were made for deltakit_stim-0.1.1-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