Get Deltakit Stim working with Sinter to simulate leakage errors?
Quantum Computing SEArchived May 23, 2026✓ Full text saved
I'm trying to use Riverlane's newly released Deltakit-Stim (a fork of Stim which includes functionality to simulate leakage errors) to simulate leakage errors but am struggling to get it to work with Stim's circuit sampler Sinter . If I do: import deltakit_stim import sinter It breaks - gives: ImportError: generic_type: type "DemInstruction" is already registered! This can be temporarily fixed with: import sys import deltakit_stim injections = ['stim._detect_machine_architecture', 'stim._stim_po
Full text archived locally
✦ AI Summary· Claude Sonnet
Get Deltakit Stim working with Sinter to simulate leakage errors?
Ask Question
Asked 16 days ago
Modified 14 days ago
Viewed 105 times
2
I'm trying to use Riverlane's newly released Deltakit-Stim (a fork of Stim which includes functionality to simulate leakage errors) to simulate leakage errors but am struggling to get it to work with Stim's circuit sampler Sinter.
If I do:
import deltakit_stim
import sinter
It breaks - gives: ImportError: generic_type: type "DemInstruction" is already registered!
This can be temporarily fixed with:
import sys
import deltakit_stim
injections = ['stim._detect_machine_architecture', 'stim._stim_polyfill', 'stim']
for namespace in injections:
sys.modules[namespace] = sys.modules[f"deltakit_{namespace}"]
import sinter
Until I try to use sinter.collect(), for example (just using the in-built surface code circuit, not containing leakage instructions yet):
import sys
import deltakit_stim
injections = ['stim._detect_machine_architecture', 'stim._stim_polyfill', 'stim']
for namespace in injections:
sys.modules[namespace] = sys.modules[f"deltakit_{namespace}"] # setting the stim one equal to the deltakit_stim one
import sinter
import multiprocessing
from stimbposd import BPOSD, SinterDecoder_BPOSD
p = 1e-3
memory_basis = 'z'
circuit = deltakit_stim.Circuit.generated(
f"surface_code:rotated_memory_{memory_basis}",
rounds=9,
distance=3,
after_clifford_depolarization=p)
tasks = [
sinter.Task(
circuit = circuit,
json_metadata = {
"p": p,
"b": memory_basis
}
)]
samples = sinter.collect(
num_workers=multiprocessing.cpu_count(),
max_shots=1000,
print_progress = True,
max_errors=10,
tasks = tasks,
decoders=['bposd'],
custom_decoders = {
"bposd": SinterDecoder_BPOSD(
max_bp_iters = 10_000,
bp_method = "min_sum",
osd_method = "osd_cs",
osd_order = 5
)
},
)
Then I will get the error:
ValueError: Worker failed: traceback=Traceback (most recent call last):
File "/opt/homebrew/lib/python3.11/site-packages/sinter/_collection/_collection_worker_state.py", line 243, in run_message_loop
num_messages_processed = self.process_messages()
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/sinter/_collection/_collection_worker_state.py", line 160, in process_messages
message = self.inp.get_nowait()
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.13/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/queues.py", line 135, in get_nowait
return self.get(False)
^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.13/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/queues.py", line 122, in get
return _ForkingPickler.loads(res)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/deltakit_stim/__init__.py", line 19, in <module>
from deltakit_stim._stim_polyfill import *
ImportError: generic_type: type "DemInstruction" is already registered!```
stimstabilizer-codesinterleakage
Share
Improve this question
Follow
asked May 20 at 7:47
drumadoir
3671
1 silver badge
7
7 bronze badges
It seems this project ships its own version of sinter (deltakit-stim/glue/sample). I am not sure if it differs from the default Pypi's one, but it is worth a shot. With pip, you can install a local library with pip install relevant/path/to/glue/sample if you have cloned their repository. –
AG47
Commented
May 21 at 16:20
Add a comment
1 Answer
Sorted by:
Highest score (default)
Date modified (newest first)
Date created (oldest first)
2
I am one of the maintainers of deltakit-stim. First of all thank you for your interest in trying it out really. This incompatibility is a known issue to us and we will try internally to fix it so this is under our radar. In the meantime here are some hints on how to make it work with stim/sinter:
Move deltakit-stim import ahead of stim, and book its place:
# these lines may go inside `deltakit_stim/__init__.py`
import deltakit_stim
import sys
sys.modules["stim"] = deltakit_stim
# or if inside `deltakit_stim` this probably should work
sys.modules["stim"] = sys.modules[__name__]
import stim, sinter # will go well
If stim is already present, adding a check may be helpful. Smtg like:
try:
import deltakit_stim
except ImportError as ierr:
if "DemInstruction" in ierr.message:
raise ImportError("Known issue, please import deltakit_stim first") from ierr
else:
raise
For your question specifically, wrap your code in
if __name__ == "__main__":
...
should help.
Share
Improve this answer
Follow
answered May 21 at 17:27
Rolandriver
361
1 bronze badge
1
Thank you! Turns out trying to run it just in a jupyter notebook while I was troubleshooting was causing issues too. So I put import deltakit_stim import sys sys.modules["stim"] = deltakit_stim inside a python file as well as if __name__ == "__main__": and it's running with sinter! I have asked another question here: quantumcomputing.stackexchange.com/questions/46277/… –
drumadoir
Commented
May 25 at 11:49
Add a comment
Your Answer
Sign up or log in
Sign up using Google
Sign up using Email and Password
Post as a guest
Name
Email
Required, but never shown
Post Your Answer
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Ask question
Explore related questions
stimstabilizer-codesinterleakage
See similar questions with these tags.
The Overflow Blog
What it takes to be a player in the international AI...
Making the OWASP top ten in the vibe code...
Featured on Meta
Native Ads Coming To Comments
Linked
1
Simulating Mølmer-Sørensen leakage (replace gate with identity) in Deltakit Stim?
Related
2
how to simulate toric and surface codes with stim + PyMatching
1
Support for Qubit Leakage Errors in Stim
0
Pass stim flags to sinter
1
max_shots and max_errors to reduce uncerainty in threshold curves with sinter / stim?
1
Correlated errors in Stim
1
Computing pseudo-threshold with sinter and stim
1
What is the right way to do Stim/sinter simulations using an HPC cluster?
1
How to track multiple observables with stim/sinter?
0
Circuit-dependent custom decoder in stim/sinter
1
In Stim, how to get the exact information of sampled errors?
Hot Network Questions
Foxhole radio isn't picking up signal
Who is the MAHA"P?
How do we uniquely determine current density in classical electromagnetism and Maxwell's equations?
How to evenly extrude boundary edges of a plane in Geometry Nodes?
Does innodb_tmpdir have to be outside the data directory?
Automatically swtiched from interim release to LTS
Ten coins in straight lines
Older sci-fi paperback. Possibly 1970’s. Main protagonist was a Liquid Metal entity. Not terminator
Is 'Steed's Toppling Strike' in addition to or instead of the 2 actions you get for commanding an animal?
What would a player gain from giving his/her opponent an extra piece, or themselves an extra king?
How does the Slippery Bridge event work in Slay the Spire 2?
Is German national television generally bias-free regarding German parties?
Evenly spacing multiple rafters along a roof frame in Blender
Which connector is this 2 row x 6 rectangular 2 mm pitch?
How do I need to drain my plumbing to replace a stop valve?
Minor revisions stuck with editor for a long time
Ubuntu 26.04 - window positions not remembered
MOSFET single pulse thermal characteristics estimation
While casting a spell with a casting time of 1 minute or longer, when do you provide the spell components?
What can you do when authors refuse to share analysis code and the journal is not responsive?
What is the optimal variance of the forecasts according to Yates?
FOR XML EXPLICIT to make one column an attribute on another column's element
Driving On The....
Struggling with constraints
Question feed
By continuing to use this website, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. By exiting this window, default cookies will be accepted. To reject cookies, select an option from below.
Customize settings
Cookie consent preference center
When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences, or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
Cookie policy
Accept all cookies
Manage consent preferences
Strictly Necessary Cookies
Always Active
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
Targeting Cookies
Targeting Cookies
These cookies are used to make advertising messages more relevant to you and may be set through our site by us or by our advertising partners. They may be used to build a profile of your interests and show you relevant advertising on our site or on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device.
Performance Cookies
Performance Cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
Functional Cookies
Functional Cookies
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
Cookie List
Clear
checkbox label label
Apply Cancel
Consent Leg.Interest
checkbox label label
checkbox label label
checkbox label label
Necessary cookies only Confirm my choices