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.dev1711525906-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8d01034be2bb635f992eba7253b6e579bd94797896eb00f6fd10cdcb1999f89 |
|
MD5 | e1dbc46988d9d0c764c8c98650f32c55 |
|
BLAKE2b-256 | a4d322bf27399033ed571dcd7cde1e5ee0a621688b8d545a14b7df4a222e93ca |
Hashes for stim-1.14.dev1711525906-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32e84994f3ae2ec203501a1b2901c4f72d21242438dfb107ca4457c5c5850695 |
|
MD5 | 90e444823754181dc0f79f3b1e73bb49 |
|
BLAKE2b-256 | fc849454902f02506bf3865c8c1f5772178f4b6f28489036a73bd7c915845d6b |
Hashes for stim-1.14.dev1711525906-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82e9b4812c5414af350f71674f0c2f8bb47aeb268e36ecd5e37b1dfcbb0aca94 |
|
MD5 | 150f66c720b469d6c80ca9c43c645362 |
|
BLAKE2b-256 | 91d58e9f635f132593b06457af3251ad10687d4cb80d24a7aedcc0dc236d2063 |
Hashes for stim-1.14.dev1711525906-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cae713789ea3570989932cee7a3add133596a6780df2bc9bbb6b245f2c305746 |
|
MD5 | 2b1859845c2b06aa695737ddafbd92ea |
|
BLAKE2b-256 | 9ca86db25f9d27ff87aad325ee14a8d42d4038966139954ed923d9dbb9fb6eda |
Hashes for stim-1.14.dev1711525906-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73f106950b8729a6f45decededdc2f78758a07558d7d82d0c7960c83d06105bc |
|
MD5 | d9f66a60d1e8f4ddecfca5840f24c5cf |
|
BLAKE2b-256 | a8b4cac0fc7fd7eb41480bbc15a87044b573733e922bf28c8269d0e3daad347d |
Hashes for stim-1.14.dev1711525906-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb7361b48b82b8370b4a05b26e053ec317cc8b024a05ce0711de6aefc1af4a17 |
|
MD5 | 06ab5bfc71e0df31c660240aa3e4a375 |
|
BLAKE2b-256 | 0265d83d7380fa54943cafbab2a37e1d849f1f173103499b3b1809a9584f8001 |
Hashes for stim-1.14.dev1711525906-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1bffe830584f5ce9b549e70122344820919099cdcba66ab51e56b4fe0c8e47b |
|
MD5 | 3bcc5af9408da3e7ab517031e73b75b6 |
|
BLAKE2b-256 | 4bec8c84b8b69e35f3c97e560b0a98f1029e85182dac7670b8415282bfb84042 |
Hashes for stim-1.14.dev1711525906-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92eaa7b9f416a460d4175b8b374ad2c9345b297be96db0c0833a274283659881 |
|
MD5 | 7d6faf8ed49e9de6b3848d8d6cc1040d |
|
BLAKE2b-256 | 000cdba4c22c6cdd7709231944283295c7b778d7913fdd3568dd39e5179438db |
Hashes for stim-1.14.dev1711525906-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1a49100571171174423c49a2a19a4c1a7ab99264ec964193228697fe5e5d00 |
|
MD5 | 57dc486d8b9cac2f36046859600f3b90 |
|
BLAKE2b-256 | aed9d6b31a139f3d9c231546e57022f4d3b95e8bfc1d9d749212dd6ffb9b0b1a |
Hashes for stim-1.14.dev1711525906-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b960c9c5e5ee0470f7d2c025a1acc0f12bbeecb3aec5faa9fbe9bcb32c8fcfb |
|
MD5 | e7b371d31b1b8e77822607fb181e0faf |
|
BLAKE2b-256 | c3367abc6ec776b9c9bb0d41816abf2420b250f6e3426f95b1f9d404bc8572d4 |
Hashes for stim-1.14.dev1711525906-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 860589440bc916bd840ccbee7d66d7bf12c39cef67b15c45978272f16ea45835 |
|
MD5 | 4a5ae3a07a52b42114f391767652f5eb |
|
BLAKE2b-256 | 24f0f269460c99317ffa5ccf4e8ae05de13b2319adc1846f0bbe66fd50863f15 |
Hashes for stim-1.14.dev1711525906-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9c5307b057355f6f79cfd53dbcde8c2e19efbbec2498c5da8a7d1177070d02d |
|
MD5 | aeb16ff99da94b9701748677325e74e8 |
|
BLAKE2b-256 | cd8de26a569d96f47f7584777731669d7d8cca3ed7cfd3f36cc28c9c8692e92d |
Hashes for stim-1.14.dev1711525906-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc5b97e47cadaa97b8796f0a849c497c45321072809e9da21e4df986561d2c3d |
|
MD5 | 14e91cf728420863d9a3dc73f3fb832b |
|
BLAKE2b-256 | a9b166717fd97c6b24c798604200eadc05715e8ea8d68e368e9aefba51358c19 |
Hashes for stim-1.14.dev1711525906-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35b7bd5ca43574bfb41e67ab401544309090240f3a6bc7cadbc652fccd4e6300 |
|
MD5 | 32ce4d41215f3692aff6903a953cf722 |
|
BLAKE2b-256 | 99ee83a2408b1e08b34552ec6a065901ddc146fa6e63a3c8050cc93d07b9d9ce |
Hashes for stim-1.14.dev1711525906-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be81a7687249096e8a9132d2e62030c7057d5159cdae7710431a8208ecbf7823 |
|
MD5 | 3b069121d7404b42329a449a145d904b |
|
BLAKE2b-256 | 92230385c2d1e9da7dfbf3558f71e1dfdd66c85921c941dbd22787ab12718cee |
Hashes for stim-1.14.dev1711525906-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101f3260b15e1e1139d40c11af7a085c69d6e2dea80174fdb2d0e79e3dd3faa9 |
|
MD5 | d29b1b1eb428e527f642323c53dc6516 |
|
BLAKE2b-256 | 34e098eb79eb61b4b81ad5bcaf3cb05f59868c2a493f2703084777721e0e6e8c |
Hashes for stim-1.14.dev1711525906-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f36c071242ef75d26d10196345a69523025b02dc96c116d82ecbe1dd3829a2e |
|
MD5 | 14ade13ef527e9bca6280c31d1c20add |
|
BLAKE2b-256 | 87184383825935904dc98d64c6e0f807976205c303276e0aef6ea6e4c2a583e4 |
Hashes for stim-1.14.dev1711525906-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62a9fa2abfa42d702d3edfe916a2e3f3803e6dc6f29499b509de677fbe840411 |
|
MD5 | 34ed4afa399fe6e97719eabaf756b191 |
|
BLAKE2b-256 | 4f203c941ff35009abb7ccf6fd8bae0cd6e7bfe59fda6499a299d7fd4aa0cea7 |
Hashes for stim-1.14.dev1711525906-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c34391b2ab9b8ba6916955122b570d5ab6bdc531c939045763f54a6f333a4160 |
|
MD5 | 87f486c5084353ec4be049ea6ce1be7b |
|
BLAKE2b-256 | c4dfc5ccf79d370a9ff09270c0baa01a053c2362bbfb2ed33b53d05f1eb5df0f |
Hashes for stim-1.14.dev1711525906-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88d6487ba8ead959d0b589646f1214c8a57bae0e2f2db1c7d16f97f7bd9d1619 |
|
MD5 | 835f52dd5e601943bbaec4bdbb421eba |
|
BLAKE2b-256 | d110e92d3549d1e81ee7986f177afc70dda6792ace442b0e6e159e18613f0e65 |
Hashes for stim-1.14.dev1711525906-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a76b3e59318748395b5f3e159214211925438618ce5048f159b59cce49e3b34d |
|
MD5 | b59c29b2feec38017e841597749078c9 |
|
BLAKE2b-256 | d6a7bbf56f52acc4d505f44fc55f48cf6cb04ef20af1a2d47919415d742575fc |
Hashes for stim-1.14.dev1711525906-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 319be1659f3d5eab53b8ba909eaeaf86f7b2199772eb19fc5c5cbe11f11c5dec |
|
MD5 | 890f75a61ad98afe812a3ee0012ba57f |
|
BLAKE2b-256 | e358492c6e8f94c079a75928504717bd4cc309513e81caecfc945ab0d20159f5 |
Hashes for stim-1.14.dev1711525906-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6ddecf2460946a2f5dd93c63b9a62c340d853186b845b421950d0c08cf2d14e |
|
MD5 | e5278507c12d3800e314e1d64c999a31 |
|
BLAKE2b-256 | adb7cc37df504746098c81d25ca30f2273a720f01c0e8458c1d83ee0f95c8665 |
Hashes for stim-1.14.dev1711525906-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0685fb49f793cacc22f785fd52b2bb7482d6e029cb57844170763d63b9ea6ea |
|
MD5 | 4382f4edcc93e74b773f57dbd3efdbd1 |
|
BLAKE2b-256 | 1df5c49fe235933294e780e1ba571526b311b52061d7edd9255f759664ef5c82 |
Hashes for stim-1.14.dev1711525906-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c6f1d8029a2828e27b7aa2203a503a2214d5ca037e738a48860d91b028b03fa |
|
MD5 | fd4ed1caf0f4ecb2b9659e936b666bb8 |
|
BLAKE2b-256 | a4eb7665e7b2c08d5df2259dec24a25830d93fbbcaf03f8c8a713826618de421 |
Hashes for stim-1.14.dev1711525906-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 119d027e1e897a87e9ee60876826130a9ad077736a8af7d230d54156ddf43170 |
|
MD5 | b2f898da381bab6837946b5c07a072cd |
|
BLAKE2b-256 | d9b9ce052314bc0950c99f9ffc30d9c8d3961cd9c5cdb7b652fda98f20dde3d5 |
Hashes for stim-1.14.dev1711525906-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20935220e0ab5b6d79e8bd0128fdb2a80ef2833307ddc313dbb90f095f3e3eb1 |
|
MD5 | 25a2563b9af9e893aa69fd11fc49a949 |
|
BLAKE2b-256 | b123d034e217fc5f0bc039c33b9487d055b789cb646f3613b5cc9c82d501e2ce |
Hashes for stim-1.14.dev1711525906-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5adfac6859808169a2b614c735d7df37e1b40892e2d5cda0afa377095c8b36f |
|
MD5 | 62a3dddf142ef94ecd39d3d53ce5264c |
|
BLAKE2b-256 | e551fb0cffb817a0fb0c0704e7192919a7dc6449e96ba2d572925bea78020dbb |
Hashes for stim-1.14.dev1711525906-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4387c9a20645fffa8ea8f40706f3a0a31d68c44432e1d96d7b1255646dd99886 |
|
MD5 | 7ac49047f6263581436f644875d65b77 |
|
BLAKE2b-256 | 94d29e5cdc6dfb6cc078b16c4975d5fbdc7be9d5b85bc3b57fe12b8f50c8bd9c |
Hashes for stim-1.14.dev1711525906-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f5fba6f4e44bd4dd6c92b9dcc3f37f3b0bed7ec2a17e342d21f83122c28cef |
|
MD5 | d4ef70f4d15afa35facd03e689ce4c84 |
|
BLAKE2b-256 | b5a91f29f3d0bb85b5a40ab888186b1bc7c1ca5891408166da5e72ace726b5fb |