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.dev1714789520-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ebc798604e6c1e29f43d93b1c46758771d8df3306065905642f71fd22414c1b |
|
MD5 | 27271f5f05c59b49da24a6cf2b27fe15 |
|
BLAKE2b-256 | 4871fcd02140b64c508153b1846952888c56ae17601278f7078c9c6021bc6507 |
Hashes for stim-1.14.dev1714789520-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90bc9f4871eaa7653e36b91209743ae091acbdd01b3d70cf9fc5680dbe128215 |
|
MD5 | 9799d30ac39dd2c106b844f74525acda |
|
BLAKE2b-256 | 7c978b9272549d0b9b8ac2977f1ab15f9e216e12a99052ce4997f054aec96e35 |
Hashes for stim-1.14.dev1714789520-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c41711a92f63350374a49e401d630b1670544b04a20ea7c90d4eb529a69a861 |
|
MD5 | 3e4cb137a7823bcd791db4e61fd6f16a |
|
BLAKE2b-256 | fbd0b18e7d95d7d9524b739dc639976eeb8560445b1f04be78e4ad42f5711b94 |
Hashes for stim-1.14.dev1714789520-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 810462d035ec974b98507b2930ff17b87c128db18b164c5568decd3d8abf1e62 |
|
MD5 | 7e34ee8e6977d7d58073f1a99498e2d6 |
|
BLAKE2b-256 | f94349367086d22b929368d370a16e4646c02352fc59f5e74f916a1d6753c688 |
Hashes for stim-1.14.dev1714789520-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6e0a9eb2f0e29d2416ac4310d71833573b00e17da82e0e97ceb381b1de8ec20 |
|
MD5 | a2ae17a12d83c90a3b3772272ce555ec |
|
BLAKE2b-256 | a473c8eefed5e2442aa6759e620648d778891609dc8a63be38114cc0fc58e7f1 |
Hashes for stim-1.14.dev1714789520-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b90449f586689603775e99e96fbe670b7821434eca7562e6ddcf30defe41a3b7 |
|
MD5 | 4ce85161fb86572ada2654515ea47527 |
|
BLAKE2b-256 | 524a2dfe8583e900c66a29b9bd9f94b4b4bca97c56a13c41d5dfbc8f962d6ead |
Hashes for stim-1.14.dev1714789520-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50479a808660a8d4d3c48d9738fc3ff6b48d569f30c41b7370f90b3d82fc552d |
|
MD5 | 4e81ab6bd578e44c5cca0a3dc94f587e |
|
BLAKE2b-256 | 3a27fd342e498e0ef9d26ea0cad952ca94f1adfb0c9f0929c88a14aafaea4a0a |
Hashes for stim-1.14.dev1714789520-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03976750db59af735711909c6513229d5da049a2e4bdbdf032b17587e8a22ec5 |
|
MD5 | b763353f00b809f6e255e117cd165e9f |
|
BLAKE2b-256 | fafa102ca1668e203f2431f447baa68507d6170d1de2d4f4bd7c6bff5f052ab1 |
Hashes for stim-1.14.dev1714789520-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2f52b7dba981f3ee0de1b2ef00101dda68958c0703261f9aa1133a1c72a3512 |
|
MD5 | 16904d3e7c694ed4ad12a3c025be487b |
|
BLAKE2b-256 | ee2ab2c86dd4dfc276bd4c24e0e0b456beeba247eb15456cd59a4a2c3a90c37f |
Hashes for stim-1.14.dev1714789520-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa664114aefc0150c9040f5fc9db6fcef4c7b3be3101862fc17c8d352f0b4d19 |
|
MD5 | c952ab128a7de778483bc90c83f48376 |
|
BLAKE2b-256 | 75253594c504219e7c9c5ee8bb933775eae43dc888bbc825833ea9978a53140f |
Hashes for stim-1.14.dev1714789520-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82130739485fb69d2c62acca2a4eb9a4c822f0079565c33711a65145194ccdaa |
|
MD5 | 93164a254bfa6ef557234f962c772929 |
|
BLAKE2b-256 | 6ffaa36a58c8686acc81e6c029ce3a88ca67bee7ce8f0cf3ae994efd29f559eb |
Hashes for stim-1.14.dev1714789520-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 257a6286570a2fcfac8f7d1813007ea2908a70f465201c1098ee5d327087d7af |
|
MD5 | e157e3e14874dbd9c4c96f94a5e94c65 |
|
BLAKE2b-256 | 95b6afde6bf10fe461f44b017cc195de7de9d256f54df7a7aff68aa4e109ae68 |
Hashes for stim-1.14.dev1714789520-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e25f5f36b4ccb479e02dae7a5ffce088dbf80c9555b753718f48a4a627b095c5 |
|
MD5 | f78cbf1c6ca7e3f9025461183cb74c43 |
|
BLAKE2b-256 | 47c46fa1d80a3b7160cf8d3ad5035c8d6ecfe8b6075a37d7ee2e94b29f2ec23f |
Hashes for stim-1.14.dev1714789520-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35152bdb5d1c784baa5798798014a58972b7adf94b7a078b03d252b4258b3d11 |
|
MD5 | 92564a890c28c97796e92af2947a2560 |
|
BLAKE2b-256 | 9f0f54e3ebc5241b98f96810ff3067bd5514d102693ed9a00638a798ab83de31 |
Hashes for stim-1.14.dev1714789520-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26adcbaa43a47e47f4a614225e3d9bf23d5f80d1c4825634c63604ac4a199600 |
|
MD5 | dff0c96d1575e2ed01ef69caa681c092 |
|
BLAKE2b-256 | c2579fc6a1eb34a12b3744e7567fac0cf419f79a2c94809b2b10d260baeee1a6 |
Hashes for stim-1.14.dev1714789520-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3a800091c4137319c3c96b9d021f850dc389a2bf16df967ab4b977daa8731dc |
|
MD5 | a60fd93e9e29e271b14127bb2f298b1b |
|
BLAKE2b-256 | ec35d39e1c4e81295730d0cefe00462e8fd733819c899f2eb46fa9c266cff2f5 |
Hashes for stim-1.14.dev1714789520-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94b340cd50cd1281f6ddcdd00743c9f3a7c02ccd2b6d5de44a404b12d3327bd6 |
|
MD5 | baf3c11405ab2275a3709004f386d79d |
|
BLAKE2b-256 | 5406fa926420dcc755dc6a4b3981663a743f75b057ea3fd032637bfac50caf64 |
Hashes for stim-1.14.dev1714789520-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 723cd3b77bb7f314cccdd71d67ace98d7420a0c86ba8ec8a266a1210f262104f |
|
MD5 | 0246bb6dc8ceeecb0a8552fb86909b19 |
|
BLAKE2b-256 | f5773d567412e935904670372eee486f0aae7c3bb894ffb057579b4cfbfd0b02 |
Hashes for stim-1.14.dev1714789520-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a972ce67167864dc95fca851833851da32cce7b7d45a35cc9754ec6a26473287 |
|
MD5 | 10712cdd0de522fa25295c4f43019465 |
|
BLAKE2b-256 | 372594f711e98fbba0dc2e24c6c78e4be3883a42c5261f4b88526f22ca84328d |
Hashes for stim-1.14.dev1714789520-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3641e0b7423923863303ed91598a8624d40aae8218a0ddf99ea0b14822226c90 |
|
MD5 | 89eac0c69c5d36ed2f0203cf81ba2039 |
|
BLAKE2b-256 | 3f72c6b030fc7fd50de5682ff1a699c2537eee9780240f9657d04d5f4ba00f7f |
Hashes for stim-1.14.dev1714789520-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d76c0e940d4f6c5d1d0dc49fd225703973894301581d55895b6ca274bfa31975 |
|
MD5 | 595685456c63978092bcbe142689dda2 |
|
BLAKE2b-256 | baca062c4432c95434fc3f8d2643aacfa122933b04eeeeda087da350860f3374 |
Hashes for stim-1.14.dev1714789520-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c1524aa0f9cd280e4fbb07af4716c37cac56b8e4eebc175b11e1f4d9c1daa97 |
|
MD5 | 20ce5b6b648c56931f8c8864a763c992 |
|
BLAKE2b-256 | f7b696bc22d0988ae46a3615c93f9a87802109d9ceb23d5d3be971442ffaefb3 |
Hashes for stim-1.14.dev1714789520-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53cde4d578f80582f8837ca83e168fb47bb23409b938f42361121adfc42356ec |
|
MD5 | b3feebded19de27e283b64998b7ae250 |
|
BLAKE2b-256 | e424336d320466388c130d4784f897520c42f4147d2a56730c0a7925063069e2 |
Hashes for stim-1.14.dev1714789520-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8915fadd719f073a1a0ca3dc19fe948edc9948ecbe23852f3b0181a41ed9362 |
|
MD5 | 2d8f8cda9cfbb38adff2abdf49f5648d |
|
BLAKE2b-256 | 24300d20a027a577001a1aa63db346989cc1d88c96ae890cc420ede29e1605e1 |
Hashes for stim-1.14.dev1714789520-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72c3d7b619c3e1ca70bfadb2b904daacdec7c316421a96dc7f09d387e09b6791 |
|
MD5 | 7e3dc23454c0c3db6532f7494d5b323f |
|
BLAKE2b-256 | f3b44d8921f8a262532ddcbe83c7fbd1b273e79a00781ecb868527f58ef4a11b |
Hashes for stim-1.14.dev1714789520-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e177e23851b190676b6b5c3afcb816de5772a29a609a739d55a4247afb17b4bc |
|
MD5 | cc3fa9c0bd5fbf8ad9da10a677099ddd |
|
BLAKE2b-256 | e23fe656a2401276c4c557d45f7601bd7bdef4e048d3034cb254c8207554c337 |
Hashes for stim-1.14.dev1714789520-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21fb377dd51aa8a3bcfc4641bc08cdb7a88033cd937e7c4de8676c92ad3f72aa |
|
MD5 | 07a4085ca3e0d583cb02e2d614dce3dc |
|
BLAKE2b-256 | dad5ef0e8351d51d72137bbf9197dd7af96290ec7b43a09cf730d10dbc873405 |
Hashes for stim-1.14.dev1714789520-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f666ffff55ef62429019263e3953f6611246916497ae59d2a9671e13d5539b60 |
|
MD5 | bd9a7fb9678adedbc2e15f5c16d2fd5a |
|
BLAKE2b-256 | a301a3ae14e5073b1025226d330dc223d989d1d5cce2d65dc86b75963b59df6a |
Hashes for stim-1.14.dev1714789520-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 264e263afbb332cfb4c474cc1cedebae529182591f4148aa503fd77f5b94ccc2 |
|
MD5 | 154aedc52e917c117822591f3761604f |
|
BLAKE2b-256 | 99b64332ad26fa1ad3c3a3329782a1e565110c9194e602262e17ca096395f2d1 |
Hashes for stim-1.14.dev1714789520-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1a8945d58f1768dfdd6fe781e0d079c362533ea0dc9836d517632cc7c9020e |
|
MD5 | 3f4f3f212282905c58364c5a19f2d091 |
|
BLAKE2b-256 | 3c65e607fd22f473a666f9920ed51564edd84ae60d68139b180d0f7816849984 |