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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.12macOS 15.0+ ARM64

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

Uploaded CPython 3.11macOS 15.0+ ARM64

deltakit_stim-0.1.3-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.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: deltakit_stim-0.1.3.tar.gz
  • Upload date:
  • Size: 895.2 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.3.tar.gz
Algorithm Hash digest
SHA256 7b613f26c71ed167d6e112b61aafb21c3a3dc05c8c359cef019930922cc5d5bf
MD5 f8bc0f7d8f39dd87d40ec431a162fd72
BLAKE2b-256 407b2e6bf8415db482e28eec14a03eaef8de2f031cada1851ca5a76438a681c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f555214ae4ebf0ff411f68553b6f03cb651c5fa5d9beeb46696b57fc148831e5
MD5 426327cce6373052b43da904b2683999
BLAKE2b-256 a3cfec0e0d4601a8428f65a0134ec6270f72444a743be183371a83e8d4a4b8f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 96bc415cb9bd5eef918ddc9cd528cbadea17985357797411bab2881322ab2457
MD5 346e23b5f87b18006c1d92e31ca90e50
BLAKE2b-256 b899037ab2ea9cbfb579fc969b01fa57af4e59b7a0232d548000986ce0d25753

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a7d90920c3eaad02d91629711d8660eee041bad77ec895b82fc15e7d4bf4824f
MD5 28789b8d8ed51bc9269761a52e4e87ec
BLAKE2b-256 ee5a19990d5201cc83c7c9ab75ca8a33f453c0f05cfbbb9c9e243768aa44d2fe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ada0990fb1ab7f92b6c2c84e6c6aaeb882285f71f2e7c72162b84aa78fbb6618
MD5 ecbe9bb23cf9886bf6a6e7481b4fbea5
BLAKE2b-256 db25f3da3692669b8915e3997ac5737bcb0dc32146077ee39fa2525496575d06

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 dd88502a16fe4eadc5f335cda8bd0f814b694728eb812054935158561157de5e
MD5 567ee190e81ea3d0cc36bc24bfef3197
BLAKE2b-256 240f1ea2b25d71f9aca07bfe430aa7d1291a6fc884001b25685aebfcec5a4a57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 57d7ac6a6010576526f71cdcfda23200dab8be782686ea7a26c0ac78fed616fa
MD5 346934f6fa0cc5a9a897bbe2456dc558
BLAKE2b-256 9aeb1b22b50cc4a7a107892c616e4c7e3fd520782aece32c5b0d2d0e645b6736

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d74dcee4029c1c1a481c9c96cc94fa56764de17fa60f814ffe6e38d5bee78c06
MD5 1109bc2672c5acdf834ffde6a0e30e4d
BLAKE2b-256 14e438bab09fb2ec3d5e56131e90b2041323ae23ace45a03e278c7936694be40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1851deaaf85e0434e6ed6aef8acee77e015fdfe06495c0ebbf81d3a67a2f0172
MD5 3733d97bead5af306d9a17caa6fdc3f2
BLAKE2b-256 ca584d480256557bb79f90e19050439fc4d971ebff7eb2c3c838879ffba2db46

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 25c6ea4de55547a07461921d0c1e0b339d09ee71fec7774abf77e47a8a56401e
MD5 b665dc4c6fea34995c78a6f65be8678c
BLAKE2b-256 95429477ba5fbb833ae73b4331c5e8bd95506c38b4b11a7dbc9dc2d1f568a66a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b660838b89c62bb7ec7c12d03248b636f733225b3bb6e0f832052f840a48723b
MD5 81f4848e740ada9e85ed3f0454dc0092
BLAKE2b-256 28a282429e04eae6eb4d1ca2983fbc97967c7b7a23d378d468dadb5fd4de1747

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f1de5ab303c2e608fd92db4200a93b465faaf650d008542813b5ffd79e160c44
MD5 0e122c8e3da11fb5b8afa33a78d2cf34
BLAKE2b-256 b0d649ac82937cf8c23fd426c77061da4c07fcab247e4ee1257c8cd83601cf2a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.1.3-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 948108df4125e86fa1692eafbc107cee739cbcfdaf957e2dbec4041b9f548dff
MD5 972f3fcb87f7f1ab0cb2e7a71124725d
BLAKE2b-256 9f8a6cd2af02bb5caecbc9b3f535a49de97024aa2542d5921245c327d6f72147

See more details on using hashes here.

Provenance

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