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.dev1694469006-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c19552c25e06b3dd37b0546d1d52e098117aeb762aef7ce673116c44f04b132 |
|
MD5 | e470678790f4d501d10e2557a321e2c7 |
|
BLAKE2b-256 | 21d020efda5ed988bd315d768d2aef1abd853628f5ffa6e4e94e7ff573ccfefa |
Hashes for stim-1.13.dev1694469006-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fcd8c8340ae1e48437f974162f130272d15bcacaf6d95f369b751d381ec7939 |
|
MD5 | 46b3763d210720117cfd24b9ccd69cb7 |
|
BLAKE2b-256 | 9b8761d06c520233cededcdb315331833bb2332279a863638c653a7f8a3f6920 |
Hashes for stim-1.13.dev1694469006-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67f8bd9aa727e069a50b930110bd69056b4cb425513fe119255414c963387a31 |
|
MD5 | 63f3f9a1999d6c5ef3811eb6a853afc7 |
|
BLAKE2b-256 | 24804f60806bde26ce0d6490d600578bf787c3be2b3b397c177a298835e21f81 |
Hashes for stim-1.13.dev1694469006-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 499e23840b5a5b2607d6223bb4cfb591ece126ba20c7478c5db8b82dc92276df |
|
MD5 | 1f618d5c48ae35078a060a7f55bb321a |
|
BLAKE2b-256 | 80f94d6b04b82d02679952e475fa14b520eec7ee63dca73a0e126d4d783a0c4a |
Hashes for stim-1.13.dev1694469006-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2490331d6f47581a14ee0043f75fc339d3e7c5e9787d728772f9113e9af495ab |
|
MD5 | ff2629d0795c6988202325675eee5cab |
|
BLAKE2b-256 | f517cb64367522178852d6d20fc5d915724d08b1e0dca78690e9f6629b5055e0 |
Hashes for stim-1.13.dev1694469006-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b202ab7d94fb4a41ecd384034d9ecc273af683f040f499ed7f3c3953583c864 |
|
MD5 | 65ae34b6f55baae21b2f719bc7293121 |
|
BLAKE2b-256 | b421e508fcd1695e50a783ec6b0e7d4d4c7ca4b1d5034ad1bc4135d558a47d18 |
Hashes for stim-1.13.dev1694469006-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f430b9e7c398adb97b026dc93a682599a7184f814139d3c5b004f20e17619cdc |
|
MD5 | a7fb58640653357c3f8a15cd1b962dcc |
|
BLAKE2b-256 | 75c74a3b4162e72ae443d33838e2802e9bfd920b4d43e3688cf23f76db502864 |
Hashes for stim-1.13.dev1694469006-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17bd3ecad845892e65faccb19f32c65f20e7311ca125279a4c5fdeab1a22e7b0 |
|
MD5 | ceb7f04186aa28ab2b491a5d3f61b910 |
|
BLAKE2b-256 | 31e4e06cffb56194be5caa41054132cb448e61a027ed7a80925bb5ecf41dbfcc |
Hashes for stim-1.13.dev1694469006-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3db918629e6c3d6705f564d456bcaea682420c93e555715ce350ec38b740a6c |
|
MD5 | 1709d065b66aea043d8365ff1de3fe5a |
|
BLAKE2b-256 | 5e5b3fa7cb0c4c836a42bd2571540a7ff4c05c948d84c8370adf9ebb6fcd093d |
Hashes for stim-1.13.dev1694469006-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00186883deef8a9840cfa3989716c75378158495b34e764cbe61ad1f94de920b |
|
MD5 | c0a55d2277cbeb60b0217162d1fdae02 |
|
BLAKE2b-256 | 3cfcb711b2ba42b620bcae398d90bc5716ed769a0e1647d251b2da74c384d5f8 |
Hashes for stim-1.13.dev1694469006-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6bdd93447d78a867a5895fac902e739eff11400c51b7b059cc9d92099e45d2 |
|
MD5 | fc68889d547e75ff291c63b9524f0f9e |
|
BLAKE2b-256 | 44d2767d94303d7130ada3bd450c4373411c40874cd4dcb108251744823d0a21 |
Hashes for stim-1.13.dev1694469006-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 574868e7e36a3c7817438b52d252b029e16680da60c9b7e5675ab539c876b2b1 |
|
MD5 | 4e3eba2e3bb5f31c0474d6a629dfde96 |
|
BLAKE2b-256 | 4a29a1a67b6ac247708a377816cb73ccbc79823c44d9f30a80f7cd35e1247b8e |
Hashes for stim-1.13.dev1694469006-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b8e2607ca87e6ee99d87413bd295cc16e5825551a561bbab969960ae5cbd18e |
|
MD5 | c726395fdd54c1341fcb8919cf2fe8e4 |
|
BLAKE2b-256 | a521629e8835cddd6c160d57d6d988f48ef166e083c5f3608d05f324edc5b156 |
Hashes for stim-1.13.dev1694469006-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd04772b5a44d9d6500eb036637efbc457549e4e592a9b9c2d5dceb87923f91a |
|
MD5 | 8bea2deaa2b2e181ace3036f1db7046a |
|
BLAKE2b-256 | 4f10cefbe6f5f3311f4d5a366e75cc73db51ceed1b690077a823f8e94b05033f |
Hashes for stim-1.13.dev1694469006-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f2701b99965e2e7d06822fad31ad831ee6b6a0d00c8a60cbdd0cf2a4d3f070 |
|
MD5 | 80d9a70f30fc0a2b288478d4deda3f1b |
|
BLAKE2b-256 | 4ecdfeccc27e26a80a1c2b17597871a14a5a50f64765aff2f63d75f6f2195480 |
Hashes for stim-1.13.dev1694469006-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d363a4630b9ab2dd2ce7f68a3b0c1f1df899a0ee57e9bf190eec71611ca219de |
|
MD5 | 9ac24287e9353532bce3e0d8fe6f3ef6 |
|
BLAKE2b-256 | d8c7ee2bbb1ce0e2fa724cad510dc1e2b5613e219149d57400d6bc712d3cf8bf |
Hashes for stim-1.13.dev1694469006-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fe530fb92a83f101db38d2738a6ae00b6ad370927dc2a84a718ba084a9ef28e |
|
MD5 | e57e034cd2949bcead0c0d738bb9ee5f |
|
BLAKE2b-256 | 38f17dc1d38b5be5e39bd22f8f917e6479f7f00d07c254ef975a3873ec99ee81 |
Hashes for stim-1.13.dev1694469006-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd231fca5a9bc64fdcd7d207b0c84e3fa10257007658a4bce9aaab2a160a662e |
|
MD5 | 1b0ad4456d14f5448cf406732b26874d |
|
BLAKE2b-256 | 7bc903b32fcfa7dcf80bb43779a050fcba69b6aae01d90b3e5b9f32e621ec6d7 |
Hashes for stim-1.13.dev1694469006-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e20bbfc225ea45540919a4c6816d117d5805f9f822f61e6fc824b37213f9d1d |
|
MD5 | 1a66633dc1bd8caeb200bd938d5b3583 |
|
BLAKE2b-256 | 5dd99c739fb21d6264d4dd3704f0b7a26f1216d2b59e2b66a0f10e6dba7a8160 |
Hashes for stim-1.13.dev1694469006-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad00b87b7eebc6b37199b0d753e90c0acaf819fd009c56b0b0fec510769c3ae6 |
|
MD5 | 0426db662f0384f55202ca77ce2e053e |
|
BLAKE2b-256 | 9f1604ef8149b9591899c5738f2df6a3c003ca9865c9b6789a9423d0d89c4c2f |
Hashes for stim-1.13.dev1694469006-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87b1d2794528e9c52475a44d7e39628ede48e086a1c006a8bfcabdde35597e97 |
|
MD5 | 493c0886773090fd846f0d782b969f39 |
|
BLAKE2b-256 | 3b7303248b75cb57d31b5079cc37f5f208286703b71d6baee9c5b1dbb0f1035e |
Hashes for stim-1.13.dev1694469006-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdac8b2c77deec2d9317ce08e7f65eed87837545773b7bf724cf522e40c212fc |
|
MD5 | f42d2d6d251596d5658f0b7cbeef5142 |
|
BLAKE2b-256 | 4b9c5aa1d903975aa8ace1139218ba51257a6712dc1d83b67ad74c52d77fc967 |
Hashes for stim-1.13.dev1694469006-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49e28c848718af76df8bc5c65f2f24ff6eb77fde0173c6f4db8d07774bce66a2 |
|
MD5 | 5fe1ae846ca9c1fcd6a4e885752939d3 |
|
BLAKE2b-256 | 47e09c721f3cee538c1d061007e19717f64b2db17fb96506aebd20f8ca02a3ca |
Hashes for stim-1.13.dev1694469006-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af92ce15c599345d1e53101902ebc7c0adeb8ca9fbd2d543c4ff178537efe29a |
|
MD5 | dfc56a251311671072d65fc96f5afb9d |
|
BLAKE2b-256 | decfa4709dfe1877769727efb8f7011d3e67f7be5e178ee43979df9fad52ace3 |
Hashes for stim-1.13.dev1694469006-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 513b53bd10ed0d0d1c8056b674a6d26c25391ca3f60bb9dd945e958a882079d4 |
|
MD5 | 8df149abe28a2385a75ff2595a1ff06b |
|
BLAKE2b-256 | 388e84ad7c0aeb7b0b25dcb8bee01ead3748e423b419190ac0553581811c41a7 |
Hashes for stim-1.13.dev1694469006-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae48a4c8ea493d5330a56cf55c00f599e28661d2b5c04c4f4f2bfb161e6ec73 |
|
MD5 | 04abe23cef0ea1db12cd091201348280 |
|
BLAKE2b-256 | 151877605f2ff349b3fc4dcadc77e000ecdbbac2e2c0c3e335bcf3b27dc8edcc |