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.dev1700449505-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06d1c530823d351af2bdd2abc3221929ca04c707a621f1f1f3c7fdab465b595 |
|
MD5 | 8efe9db41f7316f2f24a5c5e47f361db |
|
BLAKE2b-256 | 203860a8891a6b95c9011b17c584ef79c34c3c8c24a99202e8e7437af8460191 |
Hashes for stim-1.13.dev1700449505-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 747e9409b2b7574a15397d74bb8e0358adec789b4c7d57d9e7dc3ab75f806290 |
|
MD5 | fcb224dbc0705ff045617ca306b90966 |
|
BLAKE2b-256 | 28067a8b40eaa5f0143e6216286ce96c7dba308f7ba989930ff934befabb0711 |
Hashes for stim-1.13.dev1700449505-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92eab2bd4c00831022ce8fcd98af5695b8579145b6af68ea5eb4528d2a363969 |
|
MD5 | fa89364dc8bd54151ae79a9ba1905e49 |
|
BLAKE2b-256 | 226db271b8aecc99ed990fcdb9bc365dc7823f5ac17f1d82e7321a3a6806df8d |
Hashes for stim-1.13.dev1700449505-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 770404ab0c49643fc465eccaa03dae96b5f62c80b1561911da0861ec04ea5224 |
|
MD5 | c57a9148b49f2a785307569f5b04967d |
|
BLAKE2b-256 | 2f18efff181b0b387093d97edba968964d8cb690f76e458fdc97bcbd2c732806 |
Hashes for stim-1.13.dev1700449505-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1e0bbcafe11b1b36e88f46ea34b21575f5b1a19c8c845999a9ce5ec74247bd7 |
|
MD5 | 6c15fe620ac5a9af7440c18495aced7f |
|
BLAKE2b-256 | 74d81aaf9beed578ba7575ce2b65bbfb759119ed0177c04aeba98a48a0ff752e |
Hashes for stim-1.13.dev1700449505-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec332e66826e69597a4ce6f90bbd0c678b48c4cde33b86ef2addf836f614bd1 |
|
MD5 | 2f866e2d8a6d73930d1bd36458703f03 |
|
BLAKE2b-256 | 66ea9627f6c5879624d31ba4f32dd6350026dc0384663874f285aa446f7383c5 |
Hashes for stim-1.13.dev1700449505-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6602558c6853c34f94e43d28d03594d888b035cc5bdcb5131a559ee50bf66424 |
|
MD5 | 873716f7d1d31785e26d85457b399d3a |
|
BLAKE2b-256 | c8b47fea1e4830a94b0e6aaceba7d3f4bd3627684488d9e0a558d576d2100cf9 |
Hashes for stim-1.13.dev1700449505-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77556f0a28f53ec7cbf01839ae06245d8f210bfc767cc109f349fb6bd1166ca7 |
|
MD5 | e54bcef3ffe8720ac6ac001991f044ec |
|
BLAKE2b-256 | 0cde39f89525baef2c992770e0a9419e8390830bf431e5dd79d316bd6ea44452 |
Hashes for stim-1.13.dev1700449505-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5b89e88b213e1658fe511cb5e3748732da985261db3030d6956ab64c394c2db |
|
MD5 | 393387ed4c372980a08689656da7869d |
|
BLAKE2b-256 | ad3a02443beb61190004b2115b67a00a99ff425cfe69262f7fb749a45e907b1b |
Hashes for stim-1.13.dev1700449505-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4be34a9cac4c00c73eee28dedf61f65bb94cd19e6606209b742bb5c72a36aa0c |
|
MD5 | 8695a9e3d4431e4b05d0459f43d8a2aa |
|
BLAKE2b-256 | c19cecafbea25d1ee0bb624f9f256524027799bd4dae3513fe34c77f6992d229 |
Hashes for stim-1.13.dev1700449505-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e219ae1126e76ffe8c6a37fb2787ba218c5f0ebdca4203b341a18c9ffc48bf5f |
|
MD5 | 9a0a5337386a4e512f50db9e15e3e0c0 |
|
BLAKE2b-256 | 711bfe8ec55d1c6c26d3e6bb010a254d4976dafa6c7b58abbf66ac227ccc8fa7 |
Hashes for stim-1.13.dev1700449505-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb477ae22000f3a1e7178021c33d41fc804ac65adababe4a67b40b38871ee52 |
|
MD5 | d422e2769571ea2f730ca8ebc42dcd20 |
|
BLAKE2b-256 | 33be4f9e68b315de3a866d1c0cb6a6f4d1450b6965b71112f1a9811bd6c7c869 |
Hashes for stim-1.13.dev1700449505-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 268247376b9d64e047fcb4a19f6e6a1e06f988d14088eba4de4ece21ce166b2a |
|
MD5 | eff4493324f1048b3876b58ba959484f |
|
BLAKE2b-256 | 1d321bc193dea35d698284bc870fb25d05eb20fcfb5dc60139b5536e180e2306 |
Hashes for stim-1.13.dev1700449505-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aed8133f82a30af57fdbf4f4eebfb4f50926012082b3ca28c8f8ebb117a1814e |
|
MD5 | ad20c117fc6c81e386b1968625d3dfeb |
|
BLAKE2b-256 | ac952193b9aefb85a01df4c200d8f824fbb3b14be32b9622b85f97397cf9d95e |
Hashes for stim-1.13.dev1700449505-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b57b32564a4684e635107501371b8f2c170205e1d0195d7ad0398fb3a203649 |
|
MD5 | 05225955e49f0aaa4d874fc8f85a3683 |
|
BLAKE2b-256 | d521644ceb36cc9e81dd102b87bf1732b466125acc30bb544f99c7f577821837 |
Hashes for stim-1.13.dev1700449505-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29bc542336a7c9c04ff9eca711a0ad2b8696e3f1ea283c4437e128dca5412d67 |
|
MD5 | f3bd09c4cd09a61b448ccdde801e85c1 |
|
BLAKE2b-256 | 4f58ba001aebf220eb1afab57329d43ec463c21b19146af4c082f94c0d13a887 |
Hashes for stim-1.13.dev1700449505-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6206ba166aa8d0892a998143da8a872b059cb31706c195310be12da1c0d897a1 |
|
MD5 | 260b1fe7e94b51c087168cfdb25305e6 |
|
BLAKE2b-256 | 861b49f7b4e6fb0cfa2c7d843037610d0b2327bfe4246547a996804cb0a3ab89 |
Hashes for stim-1.13.dev1700449505-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa04cceaf3660ffd0181424ddfb74ea5b6bc9a21858028b28b0eac1c39015bda |
|
MD5 | 713784a40f02fdab2a94d6701f3b9a7c |
|
BLAKE2b-256 | a8659a2f2a511edc7d26fb6ea765559845cde7a56399c6b063240822361cc186 |
Hashes for stim-1.13.dev1700449505-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2c2de3b188209eae63f2041a6a3d2903ab71018e897b8cced7451df6129a3f |
|
MD5 | b13d3ba4fdb1c2fbade6da15596b34d0 |
|
BLAKE2b-256 | 3aaf1e144238b759a05ca3e57199658c90dff5aa1b293642a7e639b0e08007f8 |
Hashes for stim-1.13.dev1700449505-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 401372394dc56edf94f2e455c547ae03c09fa68a2b8461508b91d44ab36a13cb |
|
MD5 | 8dbc8a1c9e7f8ab6c7d5b67346a943c0 |
|
BLAKE2b-256 | 2ed3a540751a9b2ef26733cd664975258e880e6d8c80ef445c347082ada07643 |
Hashes for stim-1.13.dev1700449505-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2250ff6155af6ad8ffacf68b7812c630bf3c262760e0902e2beebbaa444e95 |
|
MD5 | 6e85104e0dd822b36f0eb7071310b5d3 |
|
BLAKE2b-256 | 3b6c9ecd5704a327cc72adfe1ecc73b61c4f7daf52d0e7b591f48529dcf3a46c |
Hashes for stim-1.13.dev1700449505-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b99132d64c16931ffdaf16917a5d8e4ee83c66edae2362ed706227c594c7605 |
|
MD5 | fa262c9b3adc35cdbf5ef8592f55e3b7 |
|
BLAKE2b-256 | d79dded7e666f8b0077973829fff9d08e357ee88e97d7de86dfc7b484a77b0d3 |
Hashes for stim-1.13.dev1700449505-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd75b4e9fb6cd16be7bc73d3f7993dc56ecd0e2fa994ea7d17134f18bc071f7a |
|
MD5 | 42ef09d804827cabe875519c0bda06f1 |
|
BLAKE2b-256 | 4a44190ef708ed2782195c3a01019b20675d8d139550cfd4e046bf3a9824472b |
Hashes for stim-1.13.dev1700449505-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | febde0b1e3d1d8fb9d3bd231e98d24634722945ebb1d92fdf333182c5f66da6d |
|
MD5 | 3ffa1ab8bb0dafd93e5394998379708f |
|
BLAKE2b-256 | f79a28595c4daa2f450c0ba14070d2bbf6375d5424c33a050412a63c7ade3255 |
Hashes for stim-1.13.dev1700449505-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10a7c070ff7d07f3ee02d54874b2f96eb891af8089b65d3d538f34dfaddb8eb1 |
|
MD5 | 8ce2e939b251750a1b427e011795b4ad |
|
BLAKE2b-256 | b419ecd17fdc24c8312c0a5091d625dfdfb7938c49d336d97d51370d3f43cac6 |
Hashes for stim-1.13.dev1700449505-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f016c10381724fc8042bd43f95a2b1cd1d478c2acfcaa941bbce97a87ea37a |
|
MD5 | 4df2ea6a0ba6d21eaff3cbe73cc683c8 |
|
BLAKE2b-256 | 453e0022981e7f7086cc1c2d024d7fadc137e1eedffbfebf78e7961feb6a8b70 |
Hashes for stim-1.13.dev1700449505-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b932b953d42b2d0d0857f4dfe2a2c701f015035b6fdcf89623881a5a9f297e4f |
|
MD5 | 54cd9ec166c45045b78a9ac9b741e75b |
|
BLAKE2b-256 | b4a4dff5885ac2daf4acca379a1008e3dd87e5e38b7c51566d27e8536ea6c332 |
Hashes for stim-1.13.dev1700449505-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3144fba06db95176fdbeb9168f6a5a0a9e5778798d210da7af4c0cc97ebce93a |
|
MD5 | 95789d8e6ed9546f45d735170de2782d |
|
BLAKE2b-256 | 782d16145dfc077f8a8bf3e8604f701dfcd9c70e66484b10a26f2c3a4dbe5f8d |
Hashes for stim-1.13.dev1700449505-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4146f360460bcededcd41c1464e755e2ee72105a31832e22a35e223303656e0 |
|
MD5 | 7ed2c8628da73d16ee84d63e43e2a2e8 |
|
BLAKE2b-256 | 78bcc83a1ba7bff839e0b41af9e53e19c8b8b8d22afae99aac5e02d151b09c8a |
Hashes for stim-1.13.dev1700449505-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee5a0348146c6e5c2e67c1501e51ace4a5f4a56719fe9a3802449ba0c6f49584 |
|
MD5 | 2b7291f6d090b1541140c92b35face3e |
|
BLAKE2b-256 | 62f98ab471c34434edbb7c2081ef8943cf682db55b61f2808274a0854888d765 |