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.12.dev1683338168-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f976784424bb5be6927e0eccd89a996b1a1969a62791b8c85f234fb484cc13d |
|
MD5 | 5d7d5c1664c05ad3660db6bf76dd69b1 |
|
BLAKE2b-256 | 6c499fc7c55e74fc1f17fcfd715bd7dbf9e8071cc7de9f15f1ec537d04cc7e49 |
Hashes for stim-1.12.dev1683338168-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23b7e7cfdf52390b658adbb101825e03a36fa0cfa319e3213ddf02e7c530593 |
|
MD5 | e5cd9feff7d7982190a47b182d13026e |
|
BLAKE2b-256 | 290edff677c357ea3652b0dc57aec83fe49465c8e09346d643dc99f3f6eba7e3 |
Hashes for stim-1.12.dev1683338168-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a311409844468a6c687c69f45f17759d82c1593e9dcb8b442714513c4e79344e |
|
MD5 | b0f3f747cbf12ce4ea9e3432f17a84af |
|
BLAKE2b-256 | bef5d2f083afa249ada18575fbebf60b69a672fceb35e32df19391e40ba79e08 |
Hashes for stim-1.12.dev1683338168-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ffa2b9943be7922c12d438519aedac2a912f24030d6352a36e41e82a052803b |
|
MD5 | 9ac8d35e17e8d53147a92dc95d812952 |
|
BLAKE2b-256 | 6af4cec23ca53ba6e370222cbb571b204f49007c98527730bff2132e1f0e5b9c |
Hashes for stim-1.12.dev1683338168-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4f12511528e9c565700345532a3d69a26864fc2f96c6c4b9badf7e2cbdae5e0 |
|
MD5 | f4c3be3b9503c84386759409b7de1ccf |
|
BLAKE2b-256 | c13e93ffc3eca572ae4484d165941cf6accbf166b117b654333584048eb29e5b |
Hashes for stim-1.12.dev1683338168-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fe62f15811c7338e064c40bd18f97f9f137665f88a6cba6688d4df5a61ed23f |
|
MD5 | bfcb2638234fe21e8bb4d9ec30b2eb7b |
|
BLAKE2b-256 | afef3aab0a402df0447e78871fb341818587ab07971ebbd5f43fe017cdca980f |
Hashes for stim-1.12.dev1683338168-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bca3f6cb17122b66062f31afb7bc5ba5c8b998de14021600b3f1209236f2e27 |
|
MD5 | 34e6ac8c0c1e1bfabec9f2f26ae9ba9d |
|
BLAKE2b-256 | 42865f5fb9c256a2534bea1087680e08588da86f3cd3c103c86d2dfec1d3b845 |
Hashes for stim-1.12.dev1683338168-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57bbe0ccb5498fce4cb7372501315cdf21992322439807784b468a722a3e257a |
|
MD5 | 7318ed946ebe6f58da9bf522e37c29e2 |
|
BLAKE2b-256 | fd0e65fcda3da1c456b73d3d8cc8a3a4f5f8700030262cdf2754eff22a108cfa |
Hashes for stim-1.12.dev1683338168-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee8a0feddb906aa95ee2e85d139d2d34632b608efd824f19561ca6f037c9cf7 |
|
MD5 | fa9627bc114e5122900193d38e91e1c4 |
|
BLAKE2b-256 | fe20b76871d4b09f01ebe92f7ce081649dba2ba641a103dbb0ebf0be280765c4 |
Hashes for stim-1.12.dev1683338168-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd785ae60a51141dd269079330042e29c76513214fd5dd8a0504ab042d6d98ee |
|
MD5 | 0184760e5375f152bbfdb2f84f026bf6 |
|
BLAKE2b-256 | 688b0a97eda41b68c4aedc2a3768cd023c07f52e3c4d709426345b84be6f8e87 |
Hashes for stim-1.12.dev1683338168-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5097f471d17caa783b11f5d2aa1e5d6a2047e536fb430e0e2ebf8ae383aecbb4 |
|
MD5 | 83cb87ec7154fe24997deb1036e48851 |
|
BLAKE2b-256 | cb6e388dfedc3d754c7c0ca357dc62645399c7535543b81a80563bb767fb50ae |
Hashes for stim-1.12.dev1683338168-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76aa14ef6c76672c4de1311740372402c54938dc540910ea08261eada27f97dc |
|
MD5 | e2d971c47d71d917a64a9acb92d1e0d8 |
|
BLAKE2b-256 | 0ee17dc6e9610729587ef3684540b29c4f5b5a8c19579013be9d1bd491ab5d2f |
Hashes for stim-1.12.dev1683338168-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80bb3baf47b718d1f9af45d180ec1360667d6703d3727a55d1819688b60af36a |
|
MD5 | 3581456560fd8624da385abbd82fda06 |
|
BLAKE2b-256 | b5364e98b5336706ad6b2df0e3043a98343cd177c80c099e4ced1dda584531fd |
Hashes for stim-1.12.dev1683338168-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5f09667c1d3ad3c81fab3e7a3c6c5f6a416135192ffdf09c6f185f77d3866ca |
|
MD5 | b2dadd11e55374d3bb024b75e70760aa |
|
BLAKE2b-256 | 21cc6f5c12e382ffabd465f559543294910b5cef397cfa644fd464d0693f3323 |
Hashes for stim-1.12.dev1683338168-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 730dbcbf2526835d6088d4876927e73ead7d26eb80ed26a0bd5d195ef9c2153e |
|
MD5 | 792ee860cdb4586aec0625c2c5672495 |
|
BLAKE2b-256 | 7e6e842dfa023b1ffc066a1a9e721b2a9655bbb6f1a55d505a7f83909af40bac |
Hashes for stim-1.12.dev1683338168-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26a6019b9fb4f4284ca032747e45ead4685b5584fc19c6bf8da8895dad1956a |
|
MD5 | c2794c376e88e1584b241ec08327f287 |
|
BLAKE2b-256 | ef566371aa8fc9cf9f44be35b9142ee2ce3b3405cd247ab6c01deb1f9850bd09 |
Hashes for stim-1.12.dev1683338168-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72de2204a6c4cfb86921c4868ec8e152ca218dbef40d6b728f1076e9e2325855 |
|
MD5 | 9c67a5d48eeb01b6253b8782f196dd7f |
|
BLAKE2b-256 | 7bcb1567a0f5415c37d3320674716a48bf7b8a40d39ad398e8d5382c6f3cc055 |
Hashes for stim-1.12.dev1683338168-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19ced53333fbe6bb6e271c56e158fe0f3aebee9161951c109b31124874b091fa |
|
MD5 | 791268273fded63a6ecd3473fdba1d57 |
|
BLAKE2b-256 | 5a8d20b05f4770603ee1f440f573e9288dacb5b182fde029cf65514445e08c31 |
Hashes for stim-1.12.dev1683338168-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d5b50dfdee57acd405eb29e3b7a449787a8d1f8ae2910f655b420cd75e51ce9 |
|
MD5 | a37071532b37b39d5675cd193fbde6f2 |
|
BLAKE2b-256 | 7790a062a1d151f33088cca06e76daff77fb4c1af840c7f966c4f7d81d95c354 |
Hashes for stim-1.12.dev1683338168-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca0b101d8f5291bf284b7cb31389351cae3f1277872287a83d0c5c9f9932746 |
|
MD5 | f91bef55f40392c5dd49ed0d5b9bc18e |
|
BLAKE2b-256 | 0277a1412cc424b6dd7afdd08d148534a0333bd302f8f9c3f2e127f1dcb208d6 |
Hashes for stim-1.12.dev1683338168-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45faf20084c9ad7bdecd90afcae4538b897b31d030a413c550421bd27d2d2a50 |
|
MD5 | 6aeec77668aeb7310b5fc7ecd8ccfb34 |
|
BLAKE2b-256 | 24c9fb05fc56f8f252a63aec4855d2d49fd15628f25110c5a4b5851105ac10a4 |
Hashes for stim-1.12.dev1683338168-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 693d70d1fb521ee883e3a6a3f68387ed379ac2298086c428effe4a6e4b909a7f |
|
MD5 | f59e37c1335a41d0b8403be95aa7d21a |
|
BLAKE2b-256 | 480df17fd4e28580920dcbf2cd09a8d18a8e17099addd26c9a9975e014acd632 |
Hashes for stim-1.12.dev1683338168-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3172692ff2dc3f99095312ba469a0cfedb622e7a5fa99e2a2b2f7742e25f61b0 |
|
MD5 | 4d79bf418dc81709a25a6c6a78f184d1 |
|
BLAKE2b-256 | 2163a88bd5f741d4e13fc21a82f584cb0fb5199756256296150994e7e83e0e8e |
Hashes for stim-1.12.dev1683338168-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32398b9f3380d3f4e46e32e195c8fe1768a86f4e9794c0c6e0618a7f257dc93b |
|
MD5 | 2f569363b6ebf70ce6b786ce60ec7bf7 |
|
BLAKE2b-256 | 58554480d335e2d647d4b9a2aa6d42623e57c89cfa7481d20e02c8125392b92d |
Hashes for stim-1.12.dev1683338168-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af20e0bea98f75941007f6e4a5f29e371b74ea3b1271d11bb676058f382520d7 |
|
MD5 | 3a906dddc696951935fc568375d09a41 |
|
BLAKE2b-256 | d7c1754d9adf27ced0f6ddd1de5647a782decd9956596fa8a54f18b642b0cff6 |
Hashes for stim-1.12.dev1683338168-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45788381527d15ff18f5e5d5ea8894bfd1046c09ed10bc8280a3278f333c58c7 |
|
MD5 | ad69a50ca766a0e08376f64d747c33f4 |
|
BLAKE2b-256 | 2d0f6d8305f463605d3201113ce4f0c264f8f3c5b60720ea647813eb9341377f |