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.13.dev1693611570-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54bc71b8dcb86af830f8288edfdd72cb6a38a22516383023a5eb8f882676a4d0 |
|
MD5 | 80a19a06eb1f61046f7094f9fb2000e4 |
|
BLAKE2b-256 | 523876b71b668875f6b60e346a83cb9016fa6d2a0774015234071da916940c3e |
Hashes for stim-1.13.dev1693611570-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d82e830d7c86ec1b1b7b100f6c87847fa95cedf43d55c3d7431a77f89773c8c9 |
|
MD5 | dda02c3db251a1b949e142a25189f5b6 |
|
BLAKE2b-256 | 35ae73570c5b585f921a8ba7b6f8845e7e754186faf627717f0ba77b8b61ca4c |
Hashes for stim-1.13.dev1693611570-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 140e10e67f99f2279a3a61ea6e980bcdab4721ccde206c21b7e5ffb20a183abc |
|
MD5 | 4d9c53201f8c3f591de4fad9fd356e5d |
|
BLAKE2b-256 | 44245cf7e30cc5f5d633a74542e6b13a61403a5e63bda12c0e0b7ecfb6ca11e0 |
Hashes for stim-1.13.dev1693611570-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 620fc33a4fd52aa1d0424759ea25ae1ecb1e78ed97ad4f860aac7f83f6d2f45e |
|
MD5 | c12354174c3e3ace9146601c0af21be8 |
|
BLAKE2b-256 | 5208b3211ec3d6ebe67da865ea6ba0c255f020ada2a78f6c5c6a65ce592224fb |
Hashes for stim-1.13.dev1693611570-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93828072055553c8d3d82b58768edca1d17631075306921ec706220b1cf3c1a3 |
|
MD5 | 03d0056250e55f0480cb43925dd40087 |
|
BLAKE2b-256 | 00911de120b4eb0a18b40794f6d22e205413ab34123d261221c81e4109a0f7df |
Hashes for stim-1.13.dev1693611570-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867428faedf6afe7ccf24b05cc745f9fbaa85d14b976d010ad12b0342f754ac6 |
|
MD5 | 01a790683d72de31eacca95b67139652 |
|
BLAKE2b-256 | 9b2cc2b961c0d417963022ee0676c9378e0b5e9fe0a44f75e591cae6b610a7a4 |
Hashes for stim-1.13.dev1693611570-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3e76283f7db2f0bb5ff2957a0239788861398e134cbd2b53b665601378e9b05 |
|
MD5 | 98269284b263bd66542d1a50a26b22f7 |
|
BLAKE2b-256 | e098e3129e1173c2f133eb99ac399738938ac385fb3bab1633e5ae983c1c8ec6 |
Hashes for stim-1.13.dev1693611570-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a82e4de2abd941bc8373b316cb3ac293bac2ef6afb635c068c4166016551182f |
|
MD5 | 4c1a48e55a5c6c8ec5c40e2892af04db |
|
BLAKE2b-256 | e535a99a1aac440b18610ab729e5c9de06f335ba2eade70516abc98ab4e57579 |
Hashes for stim-1.13.dev1693611570-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 643c6dca0a5501aa373c94a1cc7495efe1f9f563f63262b9955bdf65b6c42025 |
|
MD5 | caba56a2e9d0969045675ce2282f1f99 |
|
BLAKE2b-256 | 3a4b450f3ffe8f14c20a0c0fdd53d275919d2bc9cf1f02075f04e5d112d55cf7 |
Hashes for stim-1.13.dev1693611570-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab4f4aca90574ae7080478d5cf8bb0a4e91de068f408c0a6317467f1c97372ae |
|
MD5 | 70ebdbba85b85cc9c059268a913366f3 |
|
BLAKE2b-256 | c09eddf86c25750d3b929d82df4e049dfe3df26e7819b97d48307443e0e170dc |
Hashes for stim-1.13.dev1693611570-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5d9b93850567118482930a949dd2323e99ee0cac51bde34a92c3e5cc591f709 |
|
MD5 | 793063a07c780e1ab30af16e5a5f8652 |
|
BLAKE2b-256 | 5f037c76ce6a32ee111aa3cf5b1f5cd0fe9100ba9e306d4639f9e3fd35e24dff |
Hashes for stim-1.13.dev1693611570-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df175880b5147853fd9e188a4af0acfe8353f16cb80ae4570800e6d3f5df320c |
|
MD5 | fcc72b9fccfff90784ee8aafda7575f4 |
|
BLAKE2b-256 | 7256979a933bb207bba1b63b95da750f88091eb67d862a5fad5ea1eb55fce8a2 |
Hashes for stim-1.13.dev1693611570-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82aeb430c44ae6fea02bf6c2a73407c24f615b50daa83cd641a91f35065b9086 |
|
MD5 | 6f744292bfc11fa9711b5e9c320f0c83 |
|
BLAKE2b-256 | 8a6df1d4ddeedf2ab9738622df11c81a777228006c09b54a00c33ad4b475e422 |
Hashes for stim-1.13.dev1693611570-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46ab7f115170402a507f16327ffd0a1815c5aa3c774b98221daa7faafc7628d6 |
|
MD5 | 935bfc4ceb3a67c30454f1df85f5b5dd |
|
BLAKE2b-256 | 0cbd43e8a0c334b100258fb57d3171d68a13f332cac1aeac4b389baa4a9d55a5 |
Hashes for stim-1.13.dev1693611570-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69f4469b2b66cc32a447b9d3f714357838f9fbb11da471f2ccfb64d347f787ec |
|
MD5 | e7350ffbc80313d03d37ef0329627620 |
|
BLAKE2b-256 | e31f920586ca98cf7bbee364d75759802672fe34b2e39e71f05ee206768ad1b2 |
Hashes for stim-1.13.dev1693611570-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bc75d7a92621f1c5ccf4a5a1a2f52bef24ad3d3bdc9076a2c894deeee2f12b6 |
|
MD5 | 854a2aabaaabc420d3428c0da21b3542 |
|
BLAKE2b-256 | d9da92df9275e5c2cc3bea82713d530088be97188c0b588cac8a206cf8e364bf |
Hashes for stim-1.13.dev1693611570-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68fb494d2c3bf20719b37e55077aa9416097dfcb80558abcab2a5af2eeed4d8 |
|
MD5 | 063dfb8433f4e8ab8ae24783ada3573c |
|
BLAKE2b-256 | 795d59a996b0210e1f1d7869b0ed770bb95aaad425d706338ff89c121243e470 |
Hashes for stim-1.13.dev1693611570-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12cefce425908dd941e2bc256c54d1d48809059f39bdfb3bfdcf27f9b0ae18a7 |
|
MD5 | f9560b7b19c3ba5b19e6b19711038097 |
|
BLAKE2b-256 | 5669bd9ad5311eeec9fee2687e6bb51a2a0652f76c38ff53309b316162b90b75 |
Hashes for stim-1.13.dev1693611570-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d97f93e757bb9098a68cb00dd7d55392132f108033f9a4252a94641438515bd |
|
MD5 | 1aca2018317dcf4c07f02ffbad35bbc0 |
|
BLAKE2b-256 | dd5b6fd87a581f48d08891b07170a9e56dc28f1ce2fdfabc85bf14189c53da2e |
Hashes for stim-1.13.dev1693611570-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 422e72412327f1b3b3140b133b7b092e051ffc9e62d06062763fa4b3ccb31db1 |
|
MD5 | 138078a84a1e8a7ce5f79d45cc349a3e |
|
BLAKE2b-256 | 9b01b8ea88d9b9449f8ca409a57a9f7e99a7f099d6fe16d7f8b17cab4aaada68 |
Hashes for stim-1.13.dev1693611570-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12607e90c0f1eaf7c22c63e03ffff4f6531961e631e5391525acd9fbdcbe892e |
|
MD5 | f867ec4bc6fae19b158375af2b6cd0b1 |
|
BLAKE2b-256 | 8917c2eda79f4f05f87d2bb2f85fb8d96afa0e01f584111b20631d9bfba19f4e |
Hashes for stim-1.13.dev1693611570-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0b886e0ab05ca5dcea5d76899134b0d08304ad659c00531cc29b7c5e4ef119d |
|
MD5 | 301ae8c38426e2d01768db8890737fd1 |
|
BLAKE2b-256 | 820b07cccc87d992032a6cb1c9eec3dff09ce3e7d12f25944dc1bee87cecd0ae |
Hashes for stim-1.13.dev1693611570-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 650b9c2fa4bc90a411b2fd752b01dc55037cc64497f9f63271a35a5a273eef4e |
|
MD5 | 1226c06b51cc79c2babb3f49d7f78cf9 |
|
BLAKE2b-256 | 5779ac672d91c1dd5cb21b2caddca626fb198aca58992f42f03595d7ec0b7714 |
Hashes for stim-1.13.dev1693611570-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edf25b556a0dcfe8966fd9961c475187bdbde5f64b4f9d8183ee969d187c4bd0 |
|
MD5 | acfa2b97c93af8cf28b75d75686f8460 |
|
BLAKE2b-256 | c9707036ac365425392556563c6c549f94e5b80f80edf4e3575acee91930d5be |
Hashes for stim-1.13.dev1693611570-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47bf75d70f4ba50ce4e2a744beda3d7b70bd31fae49ee038b84047cfd76fc0b1 |
|
MD5 | e697ee4215bf4118b0237e82431c647b |
|
BLAKE2b-256 | 2306087dabd01df2bc3f0bf33e170f295f6981289362c233b9866d8b1e4f473b |
Hashes for stim-1.13.dev1693611570-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dada43e9db1699b1ad128f31c1b239f0860b5522b75953a869f8526d7ce01e8f |
|
MD5 | f23bf47632fc4960a76a5ec48d79f9ad |
|
BLAKE2b-256 | 42e793f32f8f48f4d3cd9152789a2c16688d5679842fbc0b9097aa307d82db85 |