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.dev1712946644-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 086ef171bd060314a318b4f62b1f1411b3dafc29ff40da7cdf6e832c998b9670 |
|
MD5 | f2f2357192ec74f8dc0716dc4e01e4d8 |
|
BLAKE2b-256 | 48726644fee4195ae6eaa54c35e2de8562b23d54fa0b5ee33c897a3b33a95bf8 |
Hashes for stim-1.14.dev1712946644-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | addb29f13b20fc203ef1561d14376c869dc0169ca7f32a4d0001f5b5ce110a72 |
|
MD5 | 663f3c0beccc57b5a52057c1a22e2c74 |
|
BLAKE2b-256 | affa79e6a3af302971f3f53efbdd20be1d61dc8bc9aa8d20b15d01a31cda755a |
Hashes for stim-1.14.dev1712946644-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4c0fb984c5cee8afeb4de27f4bd75543fac8e9bb5d315b4c19f1f55c35928a |
|
MD5 | c4da8b70760adac038dab7c43418d7b3 |
|
BLAKE2b-256 | 3d266d96b1c9d1514bc0df00bc9e2bde3cab7787f94475ef84235efd1e9f5e7a |
Hashes for stim-1.14.dev1712946644-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f25fd798492bd9b134fb477178aba1dce363297e5e9a1ee19bfded6aa3e96c2 |
|
MD5 | ba4560f2dd7459b69a32a7f269a80985 |
|
BLAKE2b-256 | e08ae1a77b921aecc0172aea0d10176f062012f5ea427984f3e34972dec171a7 |
Hashes for stim-1.14.dev1712946644-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f6feef89c42700920b70655d8380f59b07630e04ae15d4673bf2a3594f98ea2 |
|
MD5 | afbefc04d6acf1bba333088be73f5d61 |
|
BLAKE2b-256 | e18b51b2699bc68fb21ef15c6ecee8a9690b4764317c3e2e8f69b12cac5d55b7 |
Hashes for stim-1.14.dev1712946644-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 254c6cc4b65b91ab8604890c2b92f23fc7f13f6df7cc062825102bd1ecc65e27 |
|
MD5 | 8b0bf7b7f142e2cb65c08d7a19302ad0 |
|
BLAKE2b-256 | dfd488bd2978f4dbc4ac2db12f6384840fa8392b066e544baa2fcf78b468f976 |
Hashes for stim-1.14.dev1712946644-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14aabbc7a5861e01856f1ea5ad5650bfea3a5fc9a5cac9a68a4a318d00452feb |
|
MD5 | 0c2356393e40763b62b5bde0afe40fec |
|
BLAKE2b-256 | b98224d05a65c636218f7cf95a1c2b82f3858d161e71eee4c099021e6cc315ed |
Hashes for stim-1.14.dev1712946644-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afa104f614acdb71557cc841643d81f4866b70c06a9cba9b793f4b000350bc14 |
|
MD5 | 099a0f61b0531f4461f7bc6e3c85dae5 |
|
BLAKE2b-256 | 8e9995aeff4342391f16b12027370cb52d2b23cba70e69f81d81c92b401e1ab6 |
Hashes for stim-1.14.dev1712946644-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6c53d03385059ac17ca0c845984d5a58eea2c5f50da6ab76bd131fbe9073edf |
|
MD5 | 3918fe2fece4c2bae3cdb15633a6edaf |
|
BLAKE2b-256 | ca1171d1e13751ec989108005f60acc740e66662656a86c6d503bfe36a989695 |
Hashes for stim-1.14.dev1712946644-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3cb233791685798497cebc5b30e18920e97dc3c367add2c8314f7dfba8b897f |
|
MD5 | d7e7171a176a98ca473629f905d0767b |
|
BLAKE2b-256 | bb962b87845eb08c9fafd9e0efdff7e3f7dd42c7cb11ee031c5b78ace85bc777 |
Hashes for stim-1.14.dev1712946644-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4404abf24b0144986dfb0b378379045a32ef3aec6effc9eb8d8ecec323c99ec8 |
|
MD5 | 5c012b577f4f1f303bfe4c4d48790f31 |
|
BLAKE2b-256 | bb997e66651be99e5cde981cd1af40e08a93a88f1d31788393a60d850bbaa9c3 |
Hashes for stim-1.14.dev1712946644-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 641047a9ce89dbef944cdc711088cb9fe34ae368532a342e97cd82529f781cae |
|
MD5 | b465f8de2d8c4673940aaf8b787e1edd |
|
BLAKE2b-256 | 3eab9d104cf0ff73ca7b56a3b0aabe6e6635e7682fa31365498bd89e98b54d4f |
Hashes for stim-1.14.dev1712946644-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7766fb8e97cd35d661cd595645857959b977ef2d6c40c5b0c40dc87eb8ec45f |
|
MD5 | aa4806ea799914bae3f2d9b3c8017608 |
|
BLAKE2b-256 | ad5ae5465f627c31f3e9590e404a9d6d9225a115fc2386e4db6a85c90afc5413 |
Hashes for stim-1.14.dev1712946644-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6da156521b758c73abb9b4903b098c5c7569d041a68f66ee97333c26b23e277 |
|
MD5 | 9873b1628c7181458a05d92f0dc8f2a3 |
|
BLAKE2b-256 | 7fafb5311c199994d050082d8d620f292a53d8ade7faf8d2c2711957dd8e7cab |
Hashes for stim-1.14.dev1712946644-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be8be7d9a9fffc9495fadc1fbfe54e362c61227cc30e2ce9a85fc100cd4e0db |
|
MD5 | a392206699c008ac0d118855c159cb79 |
|
BLAKE2b-256 | affea05d481455deeb78a984350b24dfe9baddab74bb9adc2451c5e07e7e55a7 |
Hashes for stim-1.14.dev1712946644-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1ff3e444bef074c8988d2be4cc6cde0e9d5e453b9f8d45a285cbc19379e03be |
|
MD5 | 40fc7aee52a4d2a255b1f684b9c23310 |
|
BLAKE2b-256 | b822ed204eb920ae96fa6f6667ff44818447c9991253dd378c68aab3ff24b88d |
Hashes for stim-1.14.dev1712946644-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d882074537500a5c74a3f7da26d5c6d0cc1c03d91aa30bebe6843847d928926f |
|
MD5 | 0c9f7a9ba2e0a60891ef5bb1fafa3a88 |
|
BLAKE2b-256 | 45897942dcfabe3422d2606850548f187dee075d834026e9969dabc99fb5f330 |
Hashes for stim-1.14.dev1712946644-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc75f2d010d904635cbfb1519e95d4972fb435f485d80d5d6431260dd4e971d |
|
MD5 | 435d206039f45061b05bae8bad34d228 |
|
BLAKE2b-256 | 40f1a3b92193179c04163cddbf271ec9472385033b7d2c267bfc6a280178817b |
Hashes for stim-1.14.dev1712946644-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2761699b75510310f572ad09a59407e6197abfef06ca029ab609a0acfef895ab |
|
MD5 | 223089695f2d394e45e1f92a5aa155bb |
|
BLAKE2b-256 | 2bcb3fe2a8075f94e5aa5416d290a1cd2de8db2d35daa4e69f3a79e7cdcc4e94 |
Hashes for stim-1.14.dev1712946644-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ef6c18d6657d366e925fc9eefe9e25a2a27dfe725c6ca35f8d8c5a6bd5166d |
|
MD5 | 5303decbfdca42149d77695f5af1653c |
|
BLAKE2b-256 | 57e9a9807fbe3b9a127b11df83208860c7443d57f2771701c09503e38d3f5f39 |
Hashes for stim-1.14.dev1712946644-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18aa54686d01dd8f52c6ffbd670023585ded617ce152859c61d991852a434eec |
|
MD5 | d591448157669bb6bbcc33023e73a13e |
|
BLAKE2b-256 | 7ea7c17de8463569887359ba3f82d27c1966d8e8fa2848713e44a178848c0bc8 |
Hashes for stim-1.14.dev1712946644-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cce207942be1b39a22c8b45fae61f1f11e1b17e8ebfbe4ffc852e9bcd779c73e |
|
MD5 | c1067238571f2793af35db0e9939705f |
|
BLAKE2b-256 | 63b46234156deb5c0843e8a08d7e08c04629382d8a92e3881bff2ba360e8d82a |
Hashes for stim-1.14.dev1712946644-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5ae64a8faf0d346af4ad0201ab132aa44bba71f628be0c45999aa084dffcd01 |
|
MD5 | 49d9a7f889d3e2e5fe693fa04395cf8a |
|
BLAKE2b-256 | 12fdd5da4953127acf2773d14af6c7603f0ddedeeefb9b0f79d327a279127847 |
Hashes for stim-1.14.dev1712946644-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e2012d947d486fd7bbb4cbb22a095cccff3f79ba67085e1dc224bfa5d1428c |
|
MD5 | 628df4542fb44a9a9fcc2fc7c53e30a9 |
|
BLAKE2b-256 | dbb74c84a862f841f87443b7aa4e5fd996f6996c8065c0de8575c2abbe49acbf |
Hashes for stim-1.14.dev1712946644-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c0ac5a0207bf282b22465444410fc1952fd4be1d5846e50dd466eac298b3dd5 |
|
MD5 | 7e26591aaf2e2a0ac0f1159c8aad783b |
|
BLAKE2b-256 | d875a18ce26a7685fc0c901d23b655d6202c8863735352264d75ca001c66ba05 |
Hashes for stim-1.14.dev1712946644-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0060ed8fe0e512de0ef0ee12521545f85aab5da7bf3a3a0cbc6dc7a8714b281 |
|
MD5 | 89032f8c00f6c16ad1be9a83e4ff6608 |
|
BLAKE2b-256 | 856b0d284c8058cb936d2f773d5cb981fafe9f66da27df43c1693193dbaaf21f |
Hashes for stim-1.14.dev1712946644-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb51345a4e31549fc9831024427174003597e2fbfa531be1880fb833edb4cd9 |
|
MD5 | f3c8089b5ac54e9571176ad4f179f408 |
|
BLAKE2b-256 | c5d598816704391f6f9a940b6e4fe7103dfbd6d1d60072612116a96501379a9f |
Hashes for stim-1.14.dev1712946644-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93eed98351d45a1836f42ed8b809fa286fda8d6335bc4838e1536837def817ed |
|
MD5 | 88885df6cf32cfec4a7fdc9bfb4f0953 |
|
BLAKE2b-256 | 43703790e0f244fdda6eae69344bc315527f3281b1c8e83fb95a59cde03c1e50 |
Hashes for stim-1.14.dev1712946644-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18081fa308cbe1825ec78a3aa21e16d8efdc3e1ccc958d8761d569ab48bb6554 |
|
MD5 | 55a1c8657a9820a1f531b240807bcf05 |
|
BLAKE2b-256 | 2f7bf2053cf237e924640a7523a389b1f12b6999b4afd7dc1c5ed392f750ee74 |
Hashes for stim-1.14.dev1712946644-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f090d0c918c9b738ce47b914b38d1dd917a3901556b95cd13d5e49e71e7042 |
|
MD5 | 51a07a4aff819ab0d0256f2d714105e7 |
|
BLAKE2b-256 | 71b3edd2c3a5ce03ff2c0b0f96c34479fad15b215e1ceaced6273e6d91e6688e |