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.dev1710726537-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df040b50189e477474adc95fde1177790d78ce6d1530bc73b362d67b80a8c9e7 |
|
MD5 | 924357196c484ef49c927bc903ec99aa |
|
BLAKE2b-256 | 8ad3fb856c5a386716ef5db831e41e1dc14e525310ff5b8d8f2f9c1ec87b2eda |
Hashes for stim-1.13.dev1710726537-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ac6a63892959d7f409d5b06faf1b627ed8ab688804ad005d8aef61df8ce11d5 |
|
MD5 | 055ae2a3680f8b258099cacf48d0938c |
|
BLAKE2b-256 | 2941900d600c15b108b76d8ec4dc49709a8bea720351b66e0c67df72acb4b3ba |
Hashes for stim-1.13.dev1710726537-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07bfb259fccf0dfae5c8fcbfc80fc9ea8b9c637b1cffb5981100332a9bc3b7df |
|
MD5 | 6d60509b9a3cea6d5bffe1ceceff617d |
|
BLAKE2b-256 | affc6066c657050c1958c20db8a68f877efc81d41f853f37cdce6fbb10caccab |
Hashes for stim-1.13.dev1710726537-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86466cf7e32c0e819c3dd29cec836b7f740ac06c8b2053dbc021885e1b9fe646 |
|
MD5 | ba2dae27b014b7a3d1d94a4e20060e73 |
|
BLAKE2b-256 | b36c01c5e4084ac8a2a02bdef69840e7afd0591af192b953ae1378c37e26c5be |
Hashes for stim-1.13.dev1710726537-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e799809db55f19d7499138a86bb935e507d0aa9056a8da3baa54902ea53ef480 |
|
MD5 | c429e8f88de4729dc06ffecd9e46d131 |
|
BLAKE2b-256 | 0d67377ea95538382020a73c5637a678de5b8864538b9eb6e40cb42c7923575c |
Hashes for stim-1.13.dev1710726537-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e0b3c531a835d0252fe6ca2d2feb037c343c818df0c30f1528f75cd8a7a8a38 |
|
MD5 | 800e21f4a38afc585b53934d6909955e |
|
BLAKE2b-256 | 77ab02c7f8440f5a7f2bef02af04e04a2db615f0aa4eef88ffddd870ae6e9861 |
Hashes for stim-1.13.dev1710726537-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0975fba9eeb0d71858b627ab9cd6561aa89907efe7dccd20de5b41946b6a630 |
|
MD5 | 358325e1448aca5ef77f6da4d891a939 |
|
BLAKE2b-256 | 9c36e704d5ddc2dd718403e747cee2bc7be48fe42b398ed0062cfbefaca64299 |
Hashes for stim-1.13.dev1710726537-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8b368a6fd6cb614a8b5636512160dd9317d052425d3014f5d0289d86ac2b3e0 |
|
MD5 | 528fdd905d630e01b55a5e7d15e7cf34 |
|
BLAKE2b-256 | 087df2f7dd7a0493dab92bd6e872700b0df403db0fe4f6d7aadf649b3c40ad4c |
Hashes for stim-1.13.dev1710726537-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 161244b6b839e53ebf13e18998233734f39632d23da5945936e07714e4446444 |
|
MD5 | 95f15768b1eac07c9f4ac2afd89381b1 |
|
BLAKE2b-256 | 7c215785b28cfc7911161db94a8a676b907d3ceb110cc953463ff5150cf48afe |
Hashes for stim-1.13.dev1710726537-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd281f27763ced74c7a64c54defffd6e2207a20ffdb3179a578a80725391110d |
|
MD5 | bb0ba2ef4b290d344f218d0a747a8825 |
|
BLAKE2b-256 | 57e73db5ca83244d52916ea96af00de2d41540e637b4d315466a1146f404fb22 |
Hashes for stim-1.13.dev1710726537-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e144f49f6d16b42d8097758466233c1df2b4418f18538563fdc9e726720fc40 |
|
MD5 | 61aa10e107713c842f30b125268fd29a |
|
BLAKE2b-256 | 134820f1d8869b154a2c9fe3b59b347ba1f80059a242c29dcaf5d640ff6ea2c0 |
Hashes for stim-1.13.dev1710726537-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 199059b4a9d91c77fb8c4d0560053170180a003bd17e7c917dcb9bead923b05f |
|
MD5 | b49cf2045939b318ab77dc48b01bf2b5 |
|
BLAKE2b-256 | 5ed9a4a7bbfd9600529f44919dfc4ba449cd8288ede6cd4a9de00f370ea1856f |
Hashes for stim-1.13.dev1710726537-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8545a22246fe32c252d00736eccc1d2f219a218823a2bd73e2b19e0203974ba1 |
|
MD5 | f285888774fba6e83cdb841ea4dcc318 |
|
BLAKE2b-256 | f31961b010de44b148857e221aea2d894cf593054cee50c6b821a23b05e52a21 |
Hashes for stim-1.13.dev1710726537-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39cdb77e9799767000a4d179479016c6416d53886a63332a70daa6a1cc754722 |
|
MD5 | f9980a06cce7400f3fd022bb29fe48b1 |
|
BLAKE2b-256 | c0a51e940b650ed0c812a3afeb686b2eb303b19a7b7fe7fa6b9b010a26cc3557 |
Hashes for stim-1.13.dev1710726537-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34899152166a046d583cb6e9680e2a0f692135863078d8531a8582741cf4c13d |
|
MD5 | e2949261bde36d64400dfc451981be01 |
|
BLAKE2b-256 | 09bd6dcc8e8469e645a1f2044adbc16faea260da958fcaf64538bb0547fb1459 |
Hashes for stim-1.13.dev1710726537-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c157130ab3d219289e3b1c0474e03f6bc1fad24e7f95aaeac5c176a3c998a988 |
|
MD5 | f9a77264f5aacae3ac79f2a8bb28d2c2 |
|
BLAKE2b-256 | 4a642a544aa997a801a9ccfae00f3fcc7122fc4dd5891e841113dc39c804dd4a |
Hashes for stim-1.13.dev1710726537-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 768fc7799e7d1737c8bc89a85e6a115950589b20d06ae10d3a5583786c4ace84 |
|
MD5 | 486f341a3fe4e49bb05c6151b2fdc5c8 |
|
BLAKE2b-256 | 01601257b14c313362013e0b3cc4b3e63c16d74679b421c8dad7b9e02ca8026c |
Hashes for stim-1.13.dev1710726537-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae966e6192f78592e2d148b6d06a7b07638172b35d7f3e230b5eb43dbc637f81 |
|
MD5 | b72fa925f6ac73cb4ddf91b71e095591 |
|
BLAKE2b-256 | f5afe28e430d04a13e35c02c816f49d8b27a6defdfb41b9f0c21f7f8aaa5491a |
Hashes for stim-1.13.dev1710726537-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c886e5fbe96315bfeba19ea669cd0a39720e7f5485c6c7da7222e2456022624c |
|
MD5 | ac835d3880e11f502961372c4a2348ed |
|
BLAKE2b-256 | b4622d1f529ac661fc27d7b4a382b4f57f8ef6ff2b503078d02e89b1c142bccc |
Hashes for stim-1.13.dev1710726537-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 402bedf28451df29769320cae096a829fe8c37a3e748361a75f820c39a7b9677 |
|
MD5 | 65e5ebbcff4ab4842609297818016899 |
|
BLAKE2b-256 | 4f37bba9f1b05c9735e13b30cd304a6dad18f47725f0d38d80727a2fc45ca4a6 |
Hashes for stim-1.13.dev1710726537-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3373f1a66488793a58685273c8aa485a67b256e8e2ff4fe3214558f87ec87716 |
|
MD5 | f9da23d2656b36fea38fc440db3f5b2a |
|
BLAKE2b-256 | 3f386da41b5fce47a260c0e3d0102fb2879f6a210b9ec78e4e5aa041d877cf50 |
Hashes for stim-1.13.dev1710726537-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba8a01620c526eacef8ff8736f02a53b17d4b6c5ae9c0e3c8c92c0c5fbe6fc1e |
|
MD5 | 1c0d26f6d640752a3972219f803abba6 |
|
BLAKE2b-256 | 701149e2d434914b8c5be439ce7dd528906a6ba165acf54d79bbe06a973bd87b |
Hashes for stim-1.13.dev1710726537-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5870729d7292a31b110846dab66b3906359ee249dd5550e1dfd196bb92edf2fc |
|
MD5 | ddee7b81ed15d23436134fc97780d9f0 |
|
BLAKE2b-256 | e8cbc29bf26360d789ccc0cb8fb873c76c79a4462c7a073bc955b1cdcac4c569 |
Hashes for stim-1.13.dev1710726537-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa6b31c074452999386390fae913a0cf4338a97033f71b8445c61fda6cf39e55 |
|
MD5 | 90ad156ca278e260a673945487a47f76 |
|
BLAKE2b-256 | 120d593c348638098f56725ed1ec853d096200770c447195322480d4f42876fa |
Hashes for stim-1.13.dev1710726537-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a69616b7e9b3c04fd15757b07264f27edbd6429f94a9f690032e0e7ceede4ba |
|
MD5 | 1f7e94514b7444578627765433c6fa5c |
|
BLAKE2b-256 | ad4d184b750d80c87e149eb5349fa51fe72bbdab744b3c3054c0c98fd3f5c261 |
Hashes for stim-1.13.dev1710726537-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d91987f6b00cacb1d93b04b5d346a07deb3cd46acff446c8b22993c31dd76650 |
|
MD5 | e122d33e0336bea197781f71b879c7f0 |
|
BLAKE2b-256 | 2d2a6fff70871d3bbc432b2d489f6fd1511600f616c1785e48fd5c0cc9e41ffb |
Hashes for stim-1.13.dev1710726537-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20fd6b31138ce399d7cb39ec1d2e64f3271842fc18c0c594b84c10a85ec8fed8 |
|
MD5 | f33abf32124c6790c9a23aa2e2c66fe8 |
|
BLAKE2b-256 | 0db548e88f7c8b0c3e16473bfdca6f42acd5a31710b6c52fc710875ba9ff1cf0 |
Hashes for stim-1.13.dev1710726537-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c890a4ae26bd309151119a9955b871a0db39d1f7eafbc5c0d2ef55895fcfc8b |
|
MD5 | bdca681defa83c107cc9dbcf09075372 |
|
BLAKE2b-256 | ee6f3061a5e7a640f4b8f6c6bd45ec22077141f0c45d661ada11b597476837bd |
Hashes for stim-1.13.dev1710726537-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc73139e0f2b18ddd814fc5f3153f58996dc1f821530f2e925352f65af8cb23 |
|
MD5 | a9272d74cebc7b93be1dde6cad371dc6 |
|
BLAKE2b-256 | fac0fa34f0554d4411ebceaee4b05ea46ec6dffe7ebba9f960550ac82492d0de |
Hashes for stim-1.13.dev1710726537-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace56fb1e2b94b29e4523da0ef5e2d4be481fa14a76b50776b3b819357c6b3a0 |
|
MD5 | 631a3672f24f7948378242bc26f6fe3d |
|
BLAKE2b-256 | 71b607e1b6cd8a5521011fab102cd7b1c486fb39b08fbf6f94a09b55ae2fa996 |