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.2.0.tar.gz (911.5 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.2.0-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.2.0-cp313-cp313-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

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

Uploaded CPython 3.13macOS 15.0+ ARM64

deltakit_stim-0.2.0-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.2.0-cp312-cp312-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

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

Uploaded CPython 3.12macOS 15.0+ ARM64

deltakit_stim-0.2.0-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.2.0-cp311-cp311-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

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

Uploaded CPython 3.11macOS 15.0+ ARM64

deltakit_stim-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.1 MB view details)

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

deltakit_stim-0.2.0-cp310-cp310-macosx_15_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

deltakit_stim-0.2.0-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.2.0.tar.gz.

File metadata

  • Download URL: deltakit_stim-0.2.0.tar.gz
  • Upload date:
  • Size: 911.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 a73b63f12b28681270a73e4b075828cd048c099d27bec5f1d0db90cc1fe39a0a
MD5 f0d43c508d6815d7c7a4b5dba6b55ad8
BLAKE2b-256 3f2800cd02c14860d422d22d52512b2c35799c96f720f1b52c05f34ad59a1861

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb57ac39aa5d113c0a93b7b47ebc92fc3b87e1b6ffca92c74bd4c6cccfebc848
MD5 6368e4e55a240c58050c805b60fe532e
BLAKE2b-256 e92ed3e36fe59951be84af2524f871ad9e2922f955a66dac7699fa574aaf2fa0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4cca5612bdbafe5ca9c6b933f57ec422b64f30b033e5f103e08adcc22ef3e6cc
MD5 bc736481c0e350eb6b18ddc4230322a4
BLAKE2b-256 5c1407d18cd2a661e4801e37c268ff59b2b60679bb2b287040ba9d9af5044988

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b3d8f380cc4c3a4c9d1862e9ebc2c071139ef29ccc3b4355d5d7b9680a678826
MD5 1ea65ce640626eca7d7b0564e2e08ea0
BLAKE2b-256 05f0193b560f1c9d9cc5353c7ea253545f93f4d847a39e86465f4e3b32749686

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 709808ed12037441e78595fb4ac7156a2024741d23f46e2b42a487b340d8e9ed
MD5 e34d4c30c8df270d7cf03cbff3954b37
BLAKE2b-256 574c965a71b1b1f993aab9fe6d6e4e9f079cfc808091db6adadf081ce6f4405b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6b6b0508475950310cdf4d4553449b1ef398b733b2be69a4df49cd62e22fef10
MD5 cbabf22ae4d5a4790c57fa6e53b16102
BLAKE2b-256 03485404cea22200176f17775675dae39ecb97cfa1fd8932a6c4af69f621ce58

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 13746e958b95eee7fb3a098c5a976ff036d35f5570ae7b95b8bc69a80af7a9df
MD5 2dd5651ab5ae9f0a76e2f700de2b6048
BLAKE2b-256 f4d745149c98eae0290ae29d703e2291b47967125681e06b17754a5b05190496

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5f89f01d6b892d23b21c95d4f07f2ef31be7a73d72d06d982e4d854993eb27b2
MD5 7c2dbfc1affcf626c4f6563bfa382c6b
BLAKE2b-256 735d61a1cc7985acaa0a578ec8a8fb59e1a72039f481dafd4191297c7d4b83ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 672b38efa9a08e1e2ce6286a4e76409677e618433893fe7dcdfe8f60ad7abe0f
MD5 5f0d31cac3840b3bda96c8d66a68d13f
BLAKE2b-256 f70bca2c6e52508f864a6ce6ad798a4971b7752f3f501d043978824a520406f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 af96a3d8e8cc61b0ef69cd7509c09cd300a195071ea69e6d9c4fd273b43a81bf
MD5 03284b41bb3fa40e2e6cc60da4200c70
BLAKE2b-256 21ea1b0d74a73f14160b738549f406c46dab3177794989dadecf85fe5338c3af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25a5876c36365b6b1b47ee26eb2e68df3fae23dbce216be554307dcc32586f09
MD5 03402f2525e07506d9a043d9aaf625bf
BLAKE2b-256 e42d22c5ebc4bac2b8e31cc9bf232350e73802f6ce50712492dfea0f23d1c400

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ebaba3825151bbf2c2d63dcb15ac9c48038b2f072bce4c0bf3b0be84a5bc42dd
MD5 4cd9aa1d0ece39ec0a1200acaf04b167
BLAKE2b-256 cd18bf6d8a9c2bb05a125f420e158d182aeb9c852de879be48ba5fc03e2b143c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for deltakit_stim-0.2.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8e8061f67015a50be7d9be761ea4851d02247b78b5a4af831ce4799e2d2d769d
MD5 9ddac41f63bf5d7dfe388b676864ac11
BLAKE2b-256 74c02552525b1ed90fc1ff6c24564fbb3ac3d41afab6864b9e62d76833ef2c6e

See more details on using hashes here.

Provenance

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