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.dev1700545551-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb4664d1e53cf2974f34c7d6f1fad51cbbc6d3a06918d061bd4020704d81eb7a |
|
MD5 | c947ea6539e9cee5ffff224a89f0ad8a |
|
BLAKE2b-256 | b20a8a0f30010c7096df379ce0c73a7f763b0c6d0179f518b9dd7c5f02c846ea |
Hashes for stim-1.13.dev1700545551-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 005c34390815dd62d11f6923ea5e5defe71e993627c014dd9a4b02332cd3e708 |
|
MD5 | 66773f79b66414de6d5e954e8d522bd1 |
|
BLAKE2b-256 | bb08ebc597140f58ca407e090d038c0876f8004cece2c799c861b8a29e1ff4e1 |
Hashes for stim-1.13.dev1700545551-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d63cc534e54943aa54226bab2613036c6135cf5c7714c190e1484b808647e09 |
|
MD5 | 99d0497a85e78e674a8b323b6a712e39 |
|
BLAKE2b-256 | 1501ab09fff4f3862adf4370a381e94e1ab9a598994d9b99db691467d89393eb |
Hashes for stim-1.13.dev1700545551-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c64e4a19f91bef4943b1e2a9410c2ff4aab95e8193828f7aaa43e367d7728cc5 |
|
MD5 | f1654005576a69857b243070e327970a |
|
BLAKE2b-256 | 9e8f3368b26f3c9cd0ebabe66fc44cea03c5f68b5a4077902260398ab069c0f4 |
Hashes for stim-1.13.dev1700545551-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f9500e8a3c5778347b169d638c92d534fe049b58ee072ee8480253424b7a401 |
|
MD5 | 140c27d25c8fdf8ee5c068136831f77f |
|
BLAKE2b-256 | 6c0a672c8c27fa79ac8ba6084d2534ab196787133034fc0b49bdb4849a5fd406 |
Hashes for stim-1.13.dev1700545551-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb7f9ae1b36e7dd5ea2bace0183edee0084c366edfc03a6be0b99fde8b79d95 |
|
MD5 | c49ee135fc8c5965703f2c8b2ae6ae60 |
|
BLAKE2b-256 | 1b2f5c37d4cf344a035a5a51c67acfa3b6ddc1000675a74f61c5b78218b83ea4 |
Hashes for stim-1.13.dev1700545551-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0dc77c8835a84d3ee88160f4d8774f59514c10304c05ecacad261fa330ada9c |
|
MD5 | 644b8c4deff9476160283d2c2c8f4d57 |
|
BLAKE2b-256 | d24eaafe1e6226887128e612c10cc77751f28668cf46ade28777ea2614c9cab1 |
Hashes for stim-1.13.dev1700545551-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95c657df7c4809abd47d7e07866105ecfac5a9138d25c9428c6e6608d15af8b4 |
|
MD5 | 62de4c3e5ec2cc962c8510a36f63000f |
|
BLAKE2b-256 | 047761d7deca4d5ba30d485d32ec3d4494e210aa2203df079592f9f414e70542 |
Hashes for stim-1.13.dev1700545551-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05c1fb9e06369691f79a1a3eaac47dbe97dfc95396fb3530e789d6e8d1ae7017 |
|
MD5 | 2ed55bcd2847c3caeb3a610b5a7bccdc |
|
BLAKE2b-256 | 05ab75bebc5c470097eddd915236298e02b92307bccaf99abcb4f556bf7eac36 |
Hashes for stim-1.13.dev1700545551-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d6eced293671a2de9c89abb0fa390dce84af7638f0bc5fe54b0d4280c9790ea |
|
MD5 | f007f8dbb1d70b8c675c82e7327f1017 |
|
BLAKE2b-256 | 0e0b2c1563e2ac80544702e22d60ca75f3a20adad584e5d809b4a0cbbb15f16e |
Hashes for stim-1.13.dev1700545551-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a45ee4fe5f2bc13476957cf42d567185074ad2778fd0db94517acb1411c5a50 |
|
MD5 | 7161d1f9f308cd08a44074e145ba2e34 |
|
BLAKE2b-256 | 5e4af4e646808c3a2793ca236376e1811ed6c9471927916a2f43eda46fd877a6 |
Hashes for stim-1.13.dev1700545551-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3fabcb73ee110d8fdd73c1eca41a769b11201f615977eab29e81eb6c853d025 |
|
MD5 | 6c9ddde56a0a441325c0c546e6057433 |
|
BLAKE2b-256 | 5390073c2d3e9d23508895eebffbe0bc327f9f05e3d24eb7221667ccb0d5b996 |
Hashes for stim-1.13.dev1700545551-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61df96624e3bb226ce66a6717abcceb0241c7a6a5394920f9d3dfeaa351c7ba6 |
|
MD5 | b20f531e4748e130adc1da940f7f4e93 |
|
BLAKE2b-256 | 42b2ce3787e4a3a4498d68a360bf6e6749d696e9735f15eb260dfeb22bfe82c2 |
Hashes for stim-1.13.dev1700545551-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8dfe1d26aeaa7721ca11a2b545fbaef4886fb344a6cf727167cd286680ebd00 |
|
MD5 | 7356b9ec6c2ba111303730ccdcb2998a |
|
BLAKE2b-256 | 2cf58bfb393aa4a99a7d94c087ddad019dea6ed078d28e2895dbda9eaaf5797d |
Hashes for stim-1.13.dev1700545551-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51a15d0fcb204e757a529a42d7ff98c196ce7ddd586b401c426e6c6fd86b4563 |
|
MD5 | 0885c62cc3fb49e88b13ec8657657a20 |
|
BLAKE2b-256 | dde843ca39712d7f6c0caf8adabc3dc00299928418e8d0f609dbc19f7f83af91 |
Hashes for stim-1.13.dev1700545551-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308aec3f617efeea252101f6d4880dc3feabf1f798398d37a1cef75eaee0b901 |
|
MD5 | 2a59956bca620b3969687afbf281511a |
|
BLAKE2b-256 | c0bd7e4f5e89926f5da4e47f70fb36776abda780ed19ac8efc0048b9e3c86413 |
Hashes for stim-1.13.dev1700545551-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e0396d432ca3037b79b76ff490b17b583bc003b426461e9222ffaf6e38167d |
|
MD5 | 61b5c0392514f13e9809fa3aee1ebe76 |
|
BLAKE2b-256 | b917a268667f2f722da8878f1d58e3c3f2ef585100d209f24cb9edbe9babccbb |
Hashes for stim-1.13.dev1700545551-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766ab399d401bca74156a239d0fe2ab65545be4185649dda21c065c729e55e01 |
|
MD5 | 849cd8db11dc9c3962661878ea90d3ba |
|
BLAKE2b-256 | d2432086b217134eb29e597034f1deac4c17bbcb0a5ecbe4167509dc9903b497 |
Hashes for stim-1.13.dev1700545551-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb843a79117aafb68c23646a5a71f27f7b29d6b0f2535c0982b2203d8e38038 |
|
MD5 | 934f625842bd0e546145706f17cc01b8 |
|
BLAKE2b-256 | 12c9c5201c80611dcb986e20d0d56e8eb2e1cae954683e49310b5b1a9aa723f6 |
Hashes for stim-1.13.dev1700545551-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3340ac6dff2922ae59dd5370cd6571bc801ab30c5a17b7077c27ec33bb0132d |
|
MD5 | fb25c3f1cb9e9eaa74d80064bb7e06bc |
|
BLAKE2b-256 | 0a09eb58954d5e4c2ac162dabced5c3f791bc55d673c0046a131a119bfbe1f5a |
Hashes for stim-1.13.dev1700545551-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c15e77344821656f0f481597b995741ddd41e087b83e0f9925957bcc167f7898 |
|
MD5 | 85a9eec181a175205b150c8ee08bf35a |
|
BLAKE2b-256 | f23b5740a4e70fae7cb80617fd8ec52cb6f2fdc4e6bc4465384f8f39bd9b46ab |
Hashes for stim-1.13.dev1700545551-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e437b5f317a4938a67d227128da26c0861e72bedccddee2b7e5c454ecd7e5c52 |
|
MD5 | 591e3c9dc30b39d52067890d473004c3 |
|
BLAKE2b-256 | c523444a6c25785e4adee7e7dfc88c2fd541974e4818135e31d99bfc0c91eee1 |
Hashes for stim-1.13.dev1700545551-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00de337eb0d0bc99f04345105b13f0c2974d40eaea7306a184bd734e4ac5d05f |
|
MD5 | b0c7bba867c0eb4cde00d60a6d9e041d |
|
BLAKE2b-256 | 97426832f3ae2aabb96ddf5e6cee432123dbf83862e5b64b942d6a3de85a97eb |
Hashes for stim-1.13.dev1700545551-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f131616572b5723bad1ee7b5483ee16858b6c2f5595fc0b7bc22cc67cdeedf66 |
|
MD5 | eb71ca88fb3dea73620feb25c8007c5f |
|
BLAKE2b-256 | c9c1472abd220faf7b0e1f8f07c131453541431584cc18b916096ae0687e2d7f |
Hashes for stim-1.13.dev1700545551-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf8123b6b607a8968ce73f49f4298b3919837577241a5f75445895b546b1c874 |
|
MD5 | 4872aa475ffb0f683aefcbb7b0d62859 |
|
BLAKE2b-256 | c16b11826f8077dc2d8daf07723fb76eeaee7f047cf6fa39e2af71e521b08ccb |
Hashes for stim-1.13.dev1700545551-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab946e532f23e46470d7425451e242b2531972cf872476e8fe380b210796312e |
|
MD5 | cece1a55d8e5d3e66763a6a5ee4e7bc4 |
|
BLAKE2b-256 | 0dd43d2458fa8dd439e24ba2ede1310c5fff782ba379f4a5c02a79233bf0d3a8 |
Hashes for stim-1.13.dev1700545551-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3510f8b4b5a707b32ef0d5533efb8b26da287ac009ff6e61ed76a321a27d5dfa |
|
MD5 | 5574ab56d8b6af60bfa7e9af861b309b |
|
BLAKE2b-256 | 51c8a7a35c4e46943c141ed83555ca2c4f0508a38bda346a606fa101cf8a291b |
Hashes for stim-1.13.dev1700545551-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938b43891b145a9814b0d9f7235e32808ae819872b30454c6ee9b64cb1bba8c2 |
|
MD5 | da249f5f0dc8a120e5aee823140255e6 |
|
BLAKE2b-256 | 41b6343679d5aa776f42a417a0349e3fbf02fb10d6dada3791d269b903aba32b |
Hashes for stim-1.13.dev1700545551-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7db8555d0a323ed297e96e5948cb24bb37fcd4ad1aec105ecb79931238dee85 |
|
MD5 | 5f881acf8781be622d22949184dcf410 |
|
BLAKE2b-256 | f9e7b84e998a9bfd2f3ff93a78415d0a0c7ba1ae18633172a3361f0fbcb95f7d |
Hashes for stim-1.13.dev1700545551-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e789f3d78f3575a5fcf3c832118cf0bcbfb4aa26610d794579f736bf6b4b4841 |
|
MD5 | 338f7028b2a6d5927cbf023d2a1bbaad |
|
BLAKE2b-256 | 71cab3ae512401e44a8494ecccb1a504aca9f46d3fcd8de1c0af38bd55f58c4f |