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.dev1712661380-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d66f5c8c8f6e0e64cc5177f2bc62a443ad9f9207f3781f3daa127302b58da1 |
|
MD5 | cdef1703c1128acd2df7ee4c873decc6 |
|
BLAKE2b-256 | c35549434370f748d7134beaa37533453a41549f32505399c795830f56419742 |
Hashes for stim-1.14.dev1712661380-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b96f0299559f5541e15a3dbdf1c1c0b1f599da0f2a62cbc11edac6a55e11b9b |
|
MD5 | c7601931b6e92e617b50a552f806f24c |
|
BLAKE2b-256 | 5e631b4008d5c089ca3a337ab4fba083f0375bbd94b422abf1641c1df73b8e8c |
Hashes for stim-1.14.dev1712661380-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a803de6f241a50abe7852f1d31bf71e492f83839bbeddc3dd6fc808a42c3e0 |
|
MD5 | ba5e4ba4d7a50d67c3714fe11641bc97 |
|
BLAKE2b-256 | 614f0e6c6245f7a6b5877c09ad26a3278d150a32f0e6ba86fc03c4578cd72108 |
Hashes for stim-1.14.dev1712661380-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6667924f4b8055cfc30c0ff8bd2757c00a80470bd50e456ef07256044d1b972a |
|
MD5 | 0f722e442c747055a48ea2f026e4e1ee |
|
BLAKE2b-256 | a4cfd4adb85fa482fead1e59df03c34b47b1a179ace542e2f31bfae7cd908300 |
Hashes for stim-1.14.dev1712661380-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8471d5abbdeb007198f5ac3dca480618227db4c406131c9ef8da2760d8b5140c |
|
MD5 | 5daf16628f9ba4d3b28473ac9abcfee4 |
|
BLAKE2b-256 | e704c0c75b4efe12242a2a9cdccd9370252e8bc1c2b5a095d7b39683f6469403 |
Hashes for stim-1.14.dev1712661380-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cefe0769e15371091a63b6d46630ddd56b4c52133e5dee9a8ef8716749c65ecd |
|
MD5 | bb6243461848569c27bdfed4460b43d4 |
|
BLAKE2b-256 | 4b73067aa3968b42782c5a738a9fec98e0acfd283abd5c5ee8b289343dfa1720 |
Hashes for stim-1.14.dev1712661380-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa74bb3f2629942b4363f7b4e3d55397e5a421c217518063b0387d9a4c8bd38a |
|
MD5 | 3f38eb59d0dfd5875ef18ac49eb35bb1 |
|
BLAKE2b-256 | d5fdadaa9e1580f5932655b2cc3572f194971009ec471849e3503f3533d0908c |
Hashes for stim-1.14.dev1712661380-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7742da730b0e2404d993e87278ed9001d9ee2e5b25c1bf2cf5d687954fce3082 |
|
MD5 | d209048d3c6611ab4de4ccf7aae6a780 |
|
BLAKE2b-256 | 9be6390e85452e9ab81b13591157a1ba82882f7805b37634500f139584c9cdc3 |
Hashes for stim-1.14.dev1712661380-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf1bae3205fae31bb122f0870b31ff94a94ae6ccc3f7d78c1146366f9db5733d |
|
MD5 | 35b28378d079df49214d9ba7f6518e25 |
|
BLAKE2b-256 | c098b24229ddf3c8b2fb837e450822cab03cb1999f2ce697b171e91435e6f4eb |
Hashes for stim-1.14.dev1712661380-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d7f69a32b1985a283954c52e0df2d360509fe64344c5059ad404046f4b05886 |
|
MD5 | e1f9982817d68068a93582ed447f5137 |
|
BLAKE2b-256 | b59bd7a5e816eecacc9d1151a18bde139e9cd3dd5a14d9799076dbdb6908a155 |
Hashes for stim-1.14.dev1712661380-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca8101afc10678c2888b48548159f31592e114cff2b5dcb6ebf5b9137a25690 |
|
MD5 | 17132ad5b47aad5779820f96c076e51b |
|
BLAKE2b-256 | 2a1960a92a9fd3fd557ec28ccb1b936468509a03108e9526eaaff7e55de22901 |
Hashes for stim-1.14.dev1712661380-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b41f8ad76a16df577cda55def24e5a725e33d13af5200122b6a4a665a08b47 |
|
MD5 | 66d93c57e1864047de55e206cb5913cc |
|
BLAKE2b-256 | 905cbed911f7a449f1c37d9e68271bfc254a0981f16847b45a2f195c8ec4c47c |
Hashes for stim-1.14.dev1712661380-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c59f2314a657ea97c97c6d5b72f08287eef692821ab86d994cab4935082be93 |
|
MD5 | 7815b83c9ddeefd142bd195eca69bf4d |
|
BLAKE2b-256 | b91517d3eb06c7b64acfc3126bca61eb52ac92ca314900510fab52caf1b8d643 |
Hashes for stim-1.14.dev1712661380-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f6903ae54d70094cf3be92fb99f4528ebf0d8a80e3ef5fb16e87d32b9306d9 |
|
MD5 | 276c4bb4519076d20ec79ba7317cdc90 |
|
BLAKE2b-256 | af3a57af16d8d01c029e4ac8aaba2526bc74f4e9840b5a0a879f3aaa6da3f43e |
Hashes for stim-1.14.dev1712661380-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d83de2178ca9306d9a1b9a844b1fcb86e9f4e6663d9ea4b8db93c1fd9e28c511 |
|
MD5 | 2e4b90a23a9a09bff1466f9bbaf40150 |
|
BLAKE2b-256 | f6a13618e1bca8ec2ce3702f0ce3771d321a7888352beafef142af654817be4b |
Hashes for stim-1.14.dev1712661380-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7cc609c9653023e66777b4f80da845cfd224c2e4b589fa15b6bb55364c03684 |
|
MD5 | c14d4a2bab00ce3813eba8e0015f02de |
|
BLAKE2b-256 | da933baffec5545d22e395e685a4b9cae9eed4535bfdc8e1eebc174bb6931f52 |
Hashes for stim-1.14.dev1712661380-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b138b53ad53d9b7b3ff29a2a32edd40156bb57f82c6688734f6972863611fb73 |
|
MD5 | 8647d988f5999c1b4ccec2e8bf2060e2 |
|
BLAKE2b-256 | 8c326223c3eb3670fd5c8bdcd4b4ffc21e89544d6a5efac81de88c2d5214bcc7 |
Hashes for stim-1.14.dev1712661380-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8472cce9b203189d4c313bcfdfeafa2cf82b731bc80ea4304bb443143a9a27ca |
|
MD5 | b502f75a87600f233a783b79aa6c3734 |
|
BLAKE2b-256 | 564cb4c3ff38f3ad20001229f836c82b7f0da7c65db31694e1e5ee1fa1451aa9 |
Hashes for stim-1.14.dev1712661380-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5b48533a950f0ddaf5624614853eceb8a094f97a7721af9c853afb353446033 |
|
MD5 | 96bd0acb8e3784454b9787b9d46cf221 |
|
BLAKE2b-256 | e99ebd12f1081d4ba84983595dbf460c8604ef1365651eaf224cbe8e38252253 |
Hashes for stim-1.14.dev1712661380-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6855410d2543bbea84e4ef76c56615dbcf3a96ad4d5617f0829b6dc73c0aea37 |
|
MD5 | 7193c94eb20b04020ddd0af11fe737a5 |
|
BLAKE2b-256 | e057f613d00a38569241e2612f0e13e79597a62675f7e3754d0db4c1b6058cb9 |
Hashes for stim-1.14.dev1712661380-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4a13e3adc224ebad0ce54c79640de38dfc48480174ce5b93c8a22b4e3ee2d7d |
|
MD5 | a95b86d9a53c7df7ecd8543f6ea5b99f |
|
BLAKE2b-256 | 14e27cf769506e52e6ccb748a9b06324c80f2168d2d156f0ab541cca0685f9b2 |
Hashes for stim-1.14.dev1712661380-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ddd8509a3f63498908dbf3369cb372d9dc48702122c7fbb7421312869134361 |
|
MD5 | dd08db5120c213f828c16caeec56b686 |
|
BLAKE2b-256 | f27b832bde7c144583c2266dd206a5c6a7c89298cc5b680fb5ced0f5fc99d1dc |
Hashes for stim-1.14.dev1712661380-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ee2c25919f82605bfcdad9967f15b649c68eea6ab7812071f6c96b62a1ce5fc |
|
MD5 | bffe0dc679cc34e7c02a02881eef7354 |
|
BLAKE2b-256 | ff610a14056bd84b6eda03ef5a323e1e038a8fd7d102d2854ac174948d7e861f |
Hashes for stim-1.14.dev1712661380-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48edf279930e5eb77647bb5089cb729502a6381757ff238033be29dcaec1c832 |
|
MD5 | 8d8244556456860f9c8c0717846f33de |
|
BLAKE2b-256 | c2942380f25ba9530bc52f721479c75ff9ef754a4746ef96daa6779f65e5a8bc |
Hashes for stim-1.14.dev1712661380-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1597fc0d81598acc44ce680ca105bb099fa13dce891711eb2030f5f13d4abb5a |
|
MD5 | 833ca43ee2a4e171f4999c5460ba63b5 |
|
BLAKE2b-256 | df7d3b601403a44136d3ce7b30ccc206aefbbec7b6f4986db6e3cc6af50cb895 |
Hashes for stim-1.14.dev1712661380-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f400f241af49694194acdf589f0b72c576035c94bd1ab134ea6715aaf5dee76b |
|
MD5 | 322db38f0d5c444c5537d11ee471ca4a |
|
BLAKE2b-256 | 0d6b124a2b65ef12ddb88b1509d1e132c7d127beb666208ffa5cb7d58ae3f26a |
Hashes for stim-1.14.dev1712661380-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68adc43fff137efb6031edd6778a0b68d7b4036dcb62274ffa16ef332f9d9d80 |
|
MD5 | 331fa34d51cedec332f92ea8d2ea6a55 |
|
BLAKE2b-256 | 659c9e3940e052ee8dca6e1a402cdb3229ac267db499251840bd6790e93b3e6e |
Hashes for stim-1.14.dev1712661380-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca41f6160b5a7498c37106f8cd7014a378fc7f807ca8475c6b0c14e53112fbd |
|
MD5 | f880e63ee684a4cd8480a83fe77b24e5 |
|
BLAKE2b-256 | 3cffbe0454e3cd5f0a674cae5fedc78b3aef537e963b6108986e6a3b5dd101db |
Hashes for stim-1.14.dev1712661380-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1464bd66e6382a6b653c1798d9d878f9bc3704637cc8dabc4aeccd5904b4840 |
|
MD5 | 3a1432954cd9ba19064469a9c98ae8ba |
|
BLAKE2b-256 | e03f2b3941eb837561bbc2286686ecc323893079916b566e7e66552c4b59d4d7 |
Hashes for stim-1.14.dev1712661380-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 181bbde7775d4a02d55ef03381c4f4708a8b860d8ffb4e05f4bb90b33b4e1c77 |
|
MD5 | be128d8326d5170032be79a0c650d23a |
|
BLAKE2b-256 | a68a9ba3766f5fb87e5d4fed4ca5f46fd8f25c7f0165d1b98a65d755a0f067ff |