A fast library for analyzing with quantum stabilizer circuits.
Project description
Stim
Stim is a fast simulator for quantum stabilizer circuits.
API references are available on the stim github wiki: https://github.com/quantumlib/stim/wiki
Stim can be installed into a python 3 environment using pip:
pip install stim
Once stim is installed, you can import stim
and use it.
There are three supported use cases:
- Interactive simulation with
stim.TableauSimulator
. - High speed sampling with samplers compiled from
stim.Circuit
. - Independent exploration using
stim.Tableau
andstim.PauliString
.
Interactive Simulation
Use stim.TableauSimulator
to simulate operations one by one while inspecting the results:
import stim
s = stim.TableauSimulator()
# Create a GHZ state.
s.h(0)
s.cnot(0, 1)
s.cnot(0, 2)
# Look at the simulator state re-inverted to be forwards:
t = s.current_inverse_tableau()
print(t**-1)
# prints:
# +-xz-xz-xz-
# | ++ ++ ++
# | ZX _Z _Z
# | _X XZ __
# | _X __ XZ
# Measure the GHZ state.
print(s.measure_many(0, 1, 2))
# prints one of:
# [True, True, True]
# or:
# [False, False, False]
High Speed Sampling
By creating a stim.Circuit
and compiling it into a sampler, samples can be generated very quickly:
import stim
# Create a circuit that measures a large GHZ state.
c = stim.Circuit()
c.append("H", [0])
for k in range(1, 30):
c.append("CNOT", [0, k])
c.append("M", range(30))
# Compile the circuit into a high performance sampler.
sampler = c.compile_sampler()
# Collect a batch of samples.
# Note: the ideal batch size, in terms of speed per sample, is roughly 1024.
# Smaller batches are slower because they are not sufficiently vectorized.
# Bigger batches are slower because they use more memory.
batch = sampler.sample(1024)
print(type(batch)) # numpy.ndarray
print(batch.dtype) # numpy.uint8
print(batch.shape) # (1024, 30)
print(batch)
# Prints something like:
# [[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# ...
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
# [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]
This also works on circuits that include noise:
import stim
import numpy as np
c = stim.Circuit("""
X_ERROR(0.1) 0
Y_ERROR(0.2) 1
Z_ERROR(0.3) 2
DEPOLARIZE1(0.4) 3
DEPOLARIZE2(0.5) 4 5
M 0 1 2 3 4 5
""")
batch = c.compile_sampler().sample(2**20)
print(np.mean(batch, axis=0).round(3))
# Prints something like:
# [0.1 0.2 0. 0.267 0.267 0.266]
You can also sample annotated detection events using stim.Circuit.compile_detector_sampler
.
For a list of gates that can appear in a stim.Circuit
, see the latest readme on github.
Independent Exploration
Stim provides data types stim.PauliString
and stim.Tableau
, which support a variety of fast operations.
import stim
xx = stim.PauliString("XX")
yy = stim.PauliString("YY")
assert xx * yy == -stim.PauliString("ZZ")
s = stim.Tableau.from_named_gate("S")
print(repr(s))
# prints:
# stim.Tableau.from_conjugated_generators(
# xs=[
# stim.PauliString("+Y"),
# ],
# zs=[
# stim.PauliString("+Z"),
# ],
# )
s_dag = stim.Tableau.from_named_gate("S_DAG")
assert s**-1 == s_dag
assert s**1000000003 == s_dag
cnot = stim.Tableau.from_named_gate("CNOT")
cz = stim.Tableau.from_named_gate("CZ")
h = stim.Tableau.from_named_gate("H")
t = stim.Tableau(5)
t.append(cnot, [1, 4])
t.append(h, [4])
t.append(cz, [1, 4])
t.prepend(h, [4])
assert t == stim.Tableau(5)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for stim-1.14.dev1720861949-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62b862f96d66a84b358c00da9599201ec51b516cba545b061b08d92e1a6cf269 |
|
MD5 | 23d360dd5b83f11be884d105ecb55d2d |
|
BLAKE2b-256 | 0198f3edda9e423365b235a1a0e661407d7b41ddc75024e61487bd43d975627b |
Hashes for stim-1.14.dev1720861949-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03032d23062b8c32b2d2d00652e62a7f553b03d16fa817ff858acd4f6b1274a4 |
|
MD5 | 93a404426629f714071f9254b412f753 |
|
BLAKE2b-256 | f7329ac824cd0675b6069f64f1b47b4ff0cb71bc8385c4d66445a3607552fdcc |
Hashes for stim-1.14.dev1720861949-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b1bdba4356de2ea42076d702502b13b5ec334e765533d753ff97c844571fe2 |
|
MD5 | b456a2d059d2be02338417d6a5ee2d3f |
|
BLAKE2b-256 | 14112a7b86ceab975318f5a89282586263483645dfdd8f386261508fb6a6617e |
Hashes for stim-1.14.dev1720861949-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b9b25abeefa2fb15a5565d906810d96f5cd76831c6fb543f7e4f1449aa053f3 |
|
MD5 | a7b1d0932a83db176b77818caf2fa0dc |
|
BLAKE2b-256 | 9ba26a5d0d043f604bad68029d7af608fd092221764d47e08cf1e856e6f9b6ce |
Hashes for stim-1.14.dev1720861949-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 844fdbaaf773190310a640269208a510fb83bbe3dca3e17323a715ca424a05d9 |
|
MD5 | 4e98ef256aeaea3e39283f35d72e0831 |
|
BLAKE2b-256 | 72932650b0544178fb51367f58ec4b4b81fbf1474b06ea938d03170de63b119c |
Hashes for stim-1.14.dev1720861949-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad247c0f798ce0b267f1066ebf936d5662ed6d5bb28815f4c2ea20eb5df868f7 |
|
MD5 | 190fc98d5310404ee12ee71b3ebc7b9d |
|
BLAKE2b-256 | affc7c3ab51684262dbce34f5a9bbd33b9ec1762c042533e97886dd9091fc10f |
Hashes for stim-1.14.dev1720861949-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a2fe14ff4096fa6e35df88149458a40b0ff3083cc1504185aa516c62f7dcdc2 |
|
MD5 | 79d9d3f46c19c631d2db28b208eda37b |
|
BLAKE2b-256 | aabfbcb9d6f66eda0f26c4a7e4131a6ac0defe3f179d39c9eec2881ea3bfce8d |
Hashes for stim-1.14.dev1720861949-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597d68df6e49621c74f012608e4e13a4157a864551854d1a7fafe16fc013cc87 |
|
MD5 | 6563e8f67eae189eceb719342dc97b2f |
|
BLAKE2b-256 | c8e78d0fe15d1c6a8ac46a7ec69e9843d302f905cdda698b24e99a1279a415a0 |
Hashes for stim-1.14.dev1720861949-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5627e73ca86a8c3da25431d7954998f407c644976dc77a913942dc87bad89a08 |
|
MD5 | 31f78118d2bb4840e5a490a3eab953c1 |
|
BLAKE2b-256 | 37dcb60aeaeac2fdf9c1038a59e5483475df49878ba2dc4f0286d8161b8acd0e |
Hashes for stim-1.14.dev1720861949-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6d217b945cbe2598ad9cc3fae4d929ee05248c36feb98dd2ef0902e7a7265de |
|
MD5 | c00f8aa3ef1a79d7c2918416c5d9f040 |
|
BLAKE2b-256 | 772e0c37a5102961e3cf5811af165c872290dde1717f11f3745cb2069e740e29 |
Hashes for stim-1.14.dev1720861949-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0179f4cb5a1cc33297cf34fe9e832599d1f64beefe10d9375b09a6d691e7d776 |
|
MD5 | cb7a62d8256c359b8908c1f555a626cb |
|
BLAKE2b-256 | bd57ec78f76e499d6b1985a6aa631f9f1c4ef9637b92a3e1dcd56d6ec5ce3e1e |
Hashes for stim-1.14.dev1720861949-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d820243002f2b4263b0489c616e4976ba8186c4c6b8c709164ea51df38c794ba |
|
MD5 | b3f80c75573fc6fe7b1002d80a3dcd77 |
|
BLAKE2b-256 | 2dd0381b33bca5a0f3a28c5c9fd8a5092c5d2dc265c00c04415bf70a6ae74d9d |
Hashes for stim-1.14.dev1720861949-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 457720bb951d9156698a699f651ac50c63db5b107879f6b7ea2e326a4b3d849b |
|
MD5 | a4af6903b3a5f40381dabbdfee6cc2e5 |
|
BLAKE2b-256 | 34f6c27d842a5927b23bcc3023af06a1e5285a837f7a3bb1a82592251ffd7f82 |
Hashes for stim-1.14.dev1720861949-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7d3ffe3be26dc6adf3cfbd86b7c88bc707a796fd15614935722464590c35652 |
|
MD5 | ee6c04a63e14892d4d025739bfbedde4 |
|
BLAKE2b-256 | a7370aaecdfd1ea99996b576b39cc80272e556265ce3457a7e23e79755ca0f52 |
Hashes for stim-1.14.dev1720861949-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16966f8345bef8c78f1ce48333d0210cac052153882917dd4fcb9f4bdb92f9a3 |
|
MD5 | fbf7243bd7ea9bea89b8b2cc3c7ab475 |
|
BLAKE2b-256 | f63a01bfa913e05d15fa73d1a8a2cc8279f43a64276b958a5a92db2aa0a090c8 |
Hashes for stim-1.14.dev1720861949-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5610aa883dc6bcfd28bc9695bed3703742320bf468557896aab1942d2a1ad9 |
|
MD5 | 8118f4759f3130e6607b75242e5150f3 |
|
BLAKE2b-256 | 9dbf602f4ae568199b9f9e3052f0c8ed93a40d977ed57c3f4acc034e31146e58 |
Hashes for stim-1.14.dev1720861949-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2998c3526434d59317c2d439923e23e344d543c9e36b039f95b832f2d24e6559 |
|
MD5 | 0f9afe157ab68bf80a5898d01da676e4 |
|
BLAKE2b-256 | 7a4ba7fa7a3cf114046dbc5e9d11c1ebe43108366f39643f95a69806a2155059 |
Hashes for stim-1.14.dev1720861949-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e30e80396b97a89f20e0439eab96f2535e653e3a026c3f0f06d6325472d14009 |
|
MD5 | 7b83b9037a6b68fa6efee09dfb5946c2 |
|
BLAKE2b-256 | 1abb00dd6b0a248a8c8b9918df2b2f0025c63562fa180f2ee6f852c597fdb4c1 |
Hashes for stim-1.14.dev1720861949-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91121332b1f2fb6f7481b4d7f8b15d73c1a9053988428584eebeb013d16c5b52 |
|
MD5 | 2529507c36318916054975801d8474d7 |
|
BLAKE2b-256 | 27b80b764e327e071606f98b0f2b9796b05fc06efb79bbb672bdcee8ee8e325f |
Hashes for stim-1.14.dev1720861949-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10ede0fcfdf7f90c7c840cfa667069ef3700e978ebe35a73d8d5efd46ec1c126 |
|
MD5 | 15b4df3601bda4a123748cc7451871fd |
|
BLAKE2b-256 | 362ca7ea81ddcc23555e93bef5f22050815f2df106d1abd35fa468baddcc41f1 |
Hashes for stim-1.14.dev1720861949-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 227a26afe2816ecea22e34fba4074ce004fc99470584ecbf9dbeb5222b55f86f |
|
MD5 | a9136bc0333f1a9dfc4e24f65dc0e099 |
|
BLAKE2b-256 | 109f8998f0652851ad4ade0edf6e8f221764801b560bc86a1508072dc1acf8c9 |
Hashes for stim-1.14.dev1720861949-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99607348e9f6c141696cfc060fd2c395f2744532fc8295b34eac9f8eb835c1ec |
|
MD5 | e4ee944e29a22bcaeb641ae5d3220623 |
|
BLAKE2b-256 | df656c545ef5c2aba15439fb20777440e4b6a6a69576508f4dc0995d64158479 |
Hashes for stim-1.14.dev1720861949-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e594036ebda990f2f75ee8d6191e9037397994f10572c67f10167dc10e5d42d |
|
MD5 | a6dbb24790a760d3cea3624b5c3fc4cb |
|
BLAKE2b-256 | f448f30947a8ac0ee92c22318467a1b15cf63549c862cfb3a3b233d2277641f6 |
Hashes for stim-1.14.dev1720861949-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4de56629177568f4a5f364f735d8288be994c503c61468047bc5051b341615b |
|
MD5 | a1bf4ef4e8a4b2e05c497b7a320d4e58 |
|
BLAKE2b-256 | 3f8c5c4b36636976e6e44070c48bf457c92f5e4a2812ca4bb897a7c49fc4303f |
Hashes for stim-1.14.dev1720861949-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a3734392107fc64a1ec63f7657baf86b0bac85f591fd6709ce43e5834cf9b82 |
|
MD5 | 514b588c9f5e678951481161cb15edcc |
|
BLAKE2b-256 | 729a3beeb8b5e7bc3854bce4f9779520fb3f9de4c7d5be75be01df597a6dce07 |
Hashes for stim-1.14.dev1720861949-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c3568722c782fad10454cdcc5a1dfd998cdedf0cd586573a2e9cde60393677 |
|
MD5 | 8a33d4884de6d095e5b6080e160b2522 |
|
BLAKE2b-256 | fdf51491e3e6a89ccf61cbbeb2b0d9681111fd6556546a873f627a429b66859e |
Hashes for stim-1.14.dev1720861949-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5877962326ac975ab8e6a59ed7c742e4a398112b4790a837c340409966367e24 |
|
MD5 | 82cd867ddf74d18f676bc23d38952db1 |
|
BLAKE2b-256 | 63eac5c78958bc12b4168c1a3b907764e86263d92047bf102689a27d043d61e7 |
Hashes for stim-1.14.dev1720861949-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c49f81fe17493b4cb9d56766c90d9d907fc723d2c080bd165e7fa217db1ca09 |
|
MD5 | 359f99dac241e30b0454465e01c08edd |
|
BLAKE2b-256 | ca48fc386e19b7e50f085695e0923cf59503b5d5b1dc94d9e7b5dc8c123d9939 |
Hashes for stim-1.14.dev1720861949-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a88e7a97d73bcfd5697e0c653b679d6bc2977a6253ab33fdf21e323edfcaeaa |
|
MD5 | d81447155df4e7fe6d433899b210fc07 |
|
BLAKE2b-256 | 2284582d6f27adef89c096977f752f33030484d2bb06a34c79f34b7ff8fefec5 |
Hashes for stim-1.14.dev1720861949-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e320efc5e39872dbd1751b4ede1eb070895b609311b2911027d3ff47ac9b954e |
|
MD5 | 942441fc23a2478d47026d52a93836b1 |
|
BLAKE2b-256 | be641fa1f59aaa6719464a666104faaf8f1af6c75e7e2d30189a4bf324a99fb0 |