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.12.dev1692688921-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51efdccc05a1995968d6694010e16a52306ee1c0ce5e37d821d5c2f0896149f8 |
|
MD5 | 8119b346b65f38b59280644f3f65ee14 |
|
BLAKE2b-256 | 63a8118a311644d7c694eb8c5ab23157cc4db085b1237ab21b21f364a6b09f6f |
Hashes for stim-1.12.dev1692688921-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6fa15d093ede27875e13f84797516a815d848b2863bdb09d060cbb47aec93df |
|
MD5 | 702ad483d658ab9d201ea4e2e8249b39 |
|
BLAKE2b-256 | 3e098cd0f39ae527bb11504ed1cb337c05baeb7c7dc2ffcbe3a36ff978afb322 |
Hashes for stim-1.12.dev1692688921-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1439ea16046be6ce3f76c0eb88ea6190db84c0b8b60da8916b0fdae55a12fd68 |
|
MD5 | 7cb23afa687fceb9f8dcc4b8e812eeac |
|
BLAKE2b-256 | e33a3f59565e462bf8c981486b92574dbe27fff8faa00cce874ef24449b6ef57 |
Hashes for stim-1.12.dev1692688921-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4054baa3714bdcc61dbf6b94b8cdf21e9bfb1b14e4fb527b142d493dd57eed35 |
|
MD5 | 8786453d1fca7b6ddf3447b0300c7f8d |
|
BLAKE2b-256 | aa4d8c63042cfac75d1348cfb3eaf5841d6ac486e445567d7aba4f89a13f661a |
Hashes for stim-1.12.dev1692688921-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e8666314de426b95fe1790e61c50677b273976f46671e9934383182b16a1b7a |
|
MD5 | 08cb54121c3be06000732d2d8a8cbf78 |
|
BLAKE2b-256 | 2159dc1d149caec8824a928c388ff7a8fb222e3f7a825bb8e805e5f574064822 |
Hashes for stim-1.12.dev1692688921-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ee7c2c38ecf753c41fc7ab41099b36780f6d853f35583f780c76a902865d4c |
|
MD5 | 6492f94a57ea0071f9903df1d0b81a33 |
|
BLAKE2b-256 | aa2adcf05f3c7bc6e4986348f2c6e9468091668e022d73357e21d18fdc391662 |
Hashes for stim-1.12.dev1692688921-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f70ab4d2c31a07b0583c4c898ef68eaefe43d71036c44fc3d06162fc4bb109a7 |
|
MD5 | ecc847415c96ea008e0e605c7369a24e |
|
BLAKE2b-256 | 52ebe2598178080ecf51e30fad8adecf2d0c04680048bf1bda710e32159ffb8a |
Hashes for stim-1.12.dev1692688921-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90a7e45bfeab1915ee3a229cd7d1f085f050ed79e73569ecce87feddb7301cbe |
|
MD5 | 1d4da6a770a2ed0c6f90d37b0b00b338 |
|
BLAKE2b-256 | 4bef6d64a3c9a06cd7fab8580448dbbadcb1379f41675e468ac7e0d61fc1ac89 |
Hashes for stim-1.12.dev1692688921-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 324fdbc530d7a4e3f055b45133183e6fd41b91d4de69920148498c620d23530d |
|
MD5 | 24a4dafaec0a511256a5d7264a721a8d |
|
BLAKE2b-256 | 3e600c6096c319e4639a15dc60d105065fb46c951292f4df47df040cdcde9d8d |
Hashes for stim-1.12.dev1692688921-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc13d915a894d41c1e0716c42ed8b293e6dee5a05a6053ae3c0ba19db16b9e51 |
|
MD5 | c78994ab97d30d90705c28fdcf443028 |
|
BLAKE2b-256 | 007f4531bfec9e7c5bcfe8ade9d3183d50078c465a6fdad3b5ec1bc14c555aa9 |
Hashes for stim-1.12.dev1692688921-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8be0970fdbf23eb40f6d1617ab163232ba99d3758c525a1d389f62c942128b5 |
|
MD5 | c5976a72fbe8ec89464ed61010e91975 |
|
BLAKE2b-256 | abb725786bc0ee03c265fda52ddfeae14fe3d3af8953a718bbf1d9f03d93868a |
Hashes for stim-1.12.dev1692688921-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7e0e501bfecdbef64896836a2d7af3283ad40380689d8fd4e1156ec4bd9a69e |
|
MD5 | 17798b7e7434fb1229fb405c1451623c |
|
BLAKE2b-256 | a325db250ee1cc45b41da25db9e7ff39582eb84bee00c5cf7e1a0caa462e5d36 |
Hashes for stim-1.12.dev1692688921-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f0c06222ea0c5f499e347be157de2c64618d32887feda142fabe0739cbfd597 |
|
MD5 | 91e8c936f567b40d5152f3c040c2ab9a |
|
BLAKE2b-256 | b41e37c54770a883a453367b093c1fa0fde7fcbe850991e9e918cec870c5f7f9 |
Hashes for stim-1.12.dev1692688921-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca1338f855635028403f1492083f4f966cfebeb190fd0f00ea32f95ac3ffb54b |
|
MD5 | 594c948edd1226e4ea8da386580ca352 |
|
BLAKE2b-256 | ae4c5cced6c3f76a49620d6b056a7548d76a9e932419007a915e717e1874ba74 |
Hashes for stim-1.12.dev1692688921-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b7444be452ae3cefee4a2dd4bf20a7a399479d6c9d6083754f9806605f592e6 |
|
MD5 | 020635f05169478369c608533ccb1a0c |
|
BLAKE2b-256 | ce6b577b1c5b91e0672febf84ab8fadf98bfcd818b920bf8f2d17c192d0a379a |
Hashes for stim-1.12.dev1692688921-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eb9fb450f4ef82b18663bf94cb049dbe30f198d7b219c26eb4f7206a69c4bb4 |
|
MD5 | 35d6e2e34abe71dbfc795f5828d9e504 |
|
BLAKE2b-256 | 73c7702e96b695dfa94f2d294306d522b1e7fdf61f2844025b59df59a1d88050 |
Hashes for stim-1.12.dev1692688921-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ef590239b64a5aa7bcd78ce2428709851017e15c26494b6529626f0d288a9ee |
|
MD5 | 9a4f0e7a50d6dd871d5190dfe7d561f9 |
|
BLAKE2b-256 | 136f2d8f86dd131758c873979209fce7f7a61f10aae8148c06949ce449acf62b |
Hashes for stim-1.12.dev1692688921-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8280c0875f464863932ce639ed2ee18acfea720fecaab3304f91f321bb9c2ff1 |
|
MD5 | 0170d6583538ab3818cccddff190ccaf |
|
BLAKE2b-256 | e8b6d9a251aac64953b0484c2dc30610ed6386f1d4c9eec3c9a19d739f9b1e35 |
Hashes for stim-1.12.dev1692688921-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 740a06aa26416cd1155652272922b2f3b85826a964161259229829bd8d80b426 |
|
MD5 | bcca14aaae2359356a5a3e2b6e44ef85 |
|
BLAKE2b-256 | 0204c5cb0214137100f2acdf9016dc50cc26474a4557c057bae86d44dd3e7841 |
Hashes for stim-1.12.dev1692688921-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b3990e0866fa9ec2d219cac5ded9c6b0973fc9761ab85c2783fcf907a216962 |
|
MD5 | 2d10f07c7714c3658298e3beda6402a7 |
|
BLAKE2b-256 | 4aaeab556b16036065422fc5c837de55e8a6b89e37bfe1482ccb2396e7550906 |
Hashes for stim-1.12.dev1692688921-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df35618c5aadbb320ff47952b1aff58b9760275d2c9fa2254377b53547e43ce |
|
MD5 | e8176a7fa6746764d198b224ebabfd96 |
|
BLAKE2b-256 | 18be6018fb73d70d3a460f70454affc52cad6259b83d51244ae9b0d1cb8697da |
Hashes for stim-1.12.dev1692688921-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4663ad6689d9405f110fc90a15661fec711096186e53d663ed33546b126a7ea |
|
MD5 | b3a6dae38d373b479a0f6a6ccd511f20 |
|
BLAKE2b-256 | e30e6d9a76735e265e9f30b0e31ac2882768285e1fbf823d15f42c004ffb42f8 |
Hashes for stim-1.12.dev1692688921-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa7121975aeac38401287be3fed90fd2521da312f840641c762a67e1fdf10054 |
|
MD5 | ceba5f13e7ce89ae87e8d47f5046be91 |
|
BLAKE2b-256 | 978d0b158f3b7e4f131858214b865e4c4876aa3823d076d90d6c7abf4e4283fc |
Hashes for stim-1.12.dev1692688921-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de176baca7f53a8de3f8fb005ccb2e369cd6fcd8ecf977ca75d5064ed7769a2c |
|
MD5 | 697fc76d8c51100778afb6a2d8c06012 |
|
BLAKE2b-256 | 68dd2953d7053842ed9cc0fe6add6f63511b240b1d83382d89f81a3563f23a43 |
Hashes for stim-1.12.dev1692688921-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f35b216b65be0c32fd74e06c6b2e790bf412a5a39447719f065db08f4b0cd379 |
|
MD5 | 171311f633542385c11b76af0638f977 |
|
BLAKE2b-256 | 882b695ee20f72df6528dc81c8e7bb589bfd6c69704b6b1c9a485b9ee26f2027 |
Hashes for stim-1.12.dev1692688921-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f072f605473e7d06adf7821a1f8dcc0b84e715722acbafa3a8f94df3f996f7e |
|
MD5 | 9554a75860b73d190213421a59f9771d |
|
BLAKE2b-256 | ce57681b71c3a7d88dd8a2baeb4fba7cce3ba8ca0a1133d4513ad8a33f4b1355 |