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.dev1700958181-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cad13060d50cc4bf4df0f6553e317f0152eb6d2cf0c870946615df22d3af145 |
|
MD5 | 154a4ef8b75d6c42c72d8c488bedf72f |
|
BLAKE2b-256 | c3240c66e043b8846233b07b814928e700371213d89018b26310dd5875931e64 |
Hashes for stim-1.13.dev1700958181-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89546cc7f1fff7b635d5677ca8f6bc57be298302477d44b15c77f83b5df5cc14 |
|
MD5 | c287941abc76e80763188c06ba0b3c0f |
|
BLAKE2b-256 | dc90bdadb308bc2b6fdfbe656c52b3ce9e1fcde9f49050204654b9af56ba82dc |
Hashes for stim-1.13.dev1700958181-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f49a6e186459e7be256410580eb2b06d99c2f4573b8ad9ee9632388dab0f8517 |
|
MD5 | c46f05d2c166fd07a69ed71bc24584a0 |
|
BLAKE2b-256 | e40af52f7d47912539d84df62241bde0e9f62cb75df7f711159464d45bef5dc5 |
Hashes for stim-1.13.dev1700958181-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85f19ee8e1c6d8f2c9dc7aa730bb752981e72ad56fe818ad69407b0c4bac930b |
|
MD5 | 28375dd28ffd9398d76672535181e9ba |
|
BLAKE2b-256 | aaaf3d155b4d7d0a7b83b00f3f954fe10392582dc975c286301d7b89856168f9 |
Hashes for stim-1.13.dev1700958181-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 755d6fac075cdf7cc0876d171bcec2723f527aa874ee8f14f13c6aadea44bb71 |
|
MD5 | a49ddad2765f2a15e6f4b43c61621394 |
|
BLAKE2b-256 | b69ffc53cc04d397673d07c2419bfafa70ed360ef7bb732d9f5fac28187ca6d0 |
Hashes for stim-1.13.dev1700958181-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4155616b82a42cbfddc89bf6a2650604032ce1a38fb84dcc9f03933b4bf1fb0 |
|
MD5 | e9bba04914fec2c1d6ed2bd0efb8c2cb |
|
BLAKE2b-256 | e1a0f5b615e3d1bc245a95c2078aa94459a8ce7a91e172e16aa6a16cb5ababd1 |
Hashes for stim-1.13.dev1700958181-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2708f809c4e7f50fb9377b9a60651f0fed3f9352430cc9ac4a4a7c56beff3e8e |
|
MD5 | 1b78aeac812293594da7dd6ef422181b |
|
BLAKE2b-256 | 0dbb73808b6b7d68756bc14dd847a889dd52773de2a088c986bcdcb7183eac69 |
Hashes for stim-1.13.dev1700958181-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 995390ba6203b8079dbd10d8ec315d5a63b21eb83722dd96b6315c85106db754 |
|
MD5 | ad1c1ed1baa5a0db987d05197a895f93 |
|
BLAKE2b-256 | 01882f5bc58fe103cf0226c591cf2b4ec0f1a13f9c31d9a43d5e022fb02cda93 |
Hashes for stim-1.13.dev1700958181-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df00c916117ced26e7b85327dc1f828a7c0302d11cac0e399f26e48faeb1144 |
|
MD5 | 722797cbb2aa06e29aa10f00f7ff95fa |
|
BLAKE2b-256 | 84cd4e027c26fdfd2a35b7d2012fccb23d756594274790a436d3a9692d4618ac |
Hashes for stim-1.13.dev1700958181-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2c1eeb1be8667cf1a852bc6d882f499796e40b2855dc7ebbf6602a6dad119b3 |
|
MD5 | f7d4b9eb875f0d1001aaa68ab510e256 |
|
BLAKE2b-256 | fd68e215c92fa720dfbd22393d421b8ab1c631ef602482c400c55e77cb0a3072 |
Hashes for stim-1.13.dev1700958181-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25d13f9145281fbbe9e93f868c0e6c6985d08e59cb8190545a89be62a64f5130 |
|
MD5 | b9e50e6a95ed72dec8f47025efa965e8 |
|
BLAKE2b-256 | 1181c8138a46572e0109abe1aa6d1709f92641d0d6bdf7558e103b1effe73ae0 |
Hashes for stim-1.13.dev1700958181-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01dcea13c8c766798ebe27310212256e09346f1ddf38b6b33fc7353f57cd51ce |
|
MD5 | e7c5f9438d225a3d36a358289701be44 |
|
BLAKE2b-256 | eb832ca410ba8828a2444ce679493e75129ccced16720bc4bc3a5e2074dabf67 |
Hashes for stim-1.13.dev1700958181-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01ae65c241e09ca4610d20d85902c7e6d50beb70c431145835be484ff7928e4 |
|
MD5 | 673d6a77f4c2435b62914e0173b3533f |
|
BLAKE2b-256 | fbe8cc3e630ea0af73c3ea21907885a976d7dd92a0482541ab0decee1fc510e4 |
Hashes for stim-1.13.dev1700958181-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbcfe93f450db06039efbbf20d27075c407551b55296645aa2a5dc5d452ca5cf |
|
MD5 | 1f1aa2ed8378fe67b6940867fe370408 |
|
BLAKE2b-256 | db38698d7f4b71288d88b421e5b5b3afd366d8fc6152c2675216f80681c840c2 |
Hashes for stim-1.13.dev1700958181-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c71fa28bc255dbc6b18a04af51a74a1a0d0246c05202e57db419c6eac5416933 |
|
MD5 | 13904fc499fc3bba28f180006d091315 |
|
BLAKE2b-256 | 7d141c539e0ca313935c53cc8fcaf29ca5ea39226ff03f8cb9a2d16fe10e67b2 |
Hashes for stim-1.13.dev1700958181-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7188bb0b7152e827b51c8cecc9dada5a3a50af9dd7904c2a105cee0238a7d5df |
|
MD5 | 1c9ce0feb80c57fcdaf8ac382e9fe378 |
|
BLAKE2b-256 | c538917d7d474addb3314f02b89a446ebe43907aeeb07785a57fa52c860125b0 |
Hashes for stim-1.13.dev1700958181-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10729e83bc1df1a7a9c2b786393c298e71d37c784ed7f35ba9980067b48cb3cf |
|
MD5 | 8c8c960021b23c83d586cef2d29480dd |
|
BLAKE2b-256 | 26e80bc11fc735f6d21661c4b17ff7fd0b714fadfa879b410eb9793fd15b91d8 |
Hashes for stim-1.13.dev1700958181-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d701d738122b022a5acea33de39561bb65531a91bff314ff04bce3c98e80ebbe |
|
MD5 | f703faec1a38f419faa6f8cc669e0981 |
|
BLAKE2b-256 | a515dbfc9ea599db66d0ed30017f8e8c8b49270a7746c6d7c27e8956e54a7ce7 |
Hashes for stim-1.13.dev1700958181-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b14e3e66f4d43aaa7745f6d4e053f10b98d9e79c2e7c9fed1d315866833ed619 |
|
MD5 | d510dd9d9cb4249448add0758a684cbd |
|
BLAKE2b-256 | 81f6f8c8903809f8a3c04e7c5df5dde91d051faae0f57741cbece3d8273524ca |
Hashes for stim-1.13.dev1700958181-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f233e3becb65dc47187562d5c66946bb0c9972ddda5cc8064321ca1c0443aa42 |
|
MD5 | d2d714b05dd7ef17f8b53609a16da4a7 |
|
BLAKE2b-256 | b7b9022d7c23aaeca99ae6232c3447c0b68350a2d402824b415159835161070b |
Hashes for stim-1.13.dev1700958181-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab532812c2dc1dcb50fe8310a2544b23765624c41a17701410812d77a41fbf87 |
|
MD5 | 9a74c4e3a640eba99f003fb4685891e9 |
|
BLAKE2b-256 | 16999487102fa291a87458b1dece57fc125c940f4d26598353d0005991766f35 |
Hashes for stim-1.13.dev1700958181-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8643053b05e5deed2f92ce1822fd5146bed8bd42f9dedbd6de34a934b416ea7 |
|
MD5 | 737ccba9bdc22273743d9aee3a7ae6df |
|
BLAKE2b-256 | 6c1cbc2129987ece7399cfd655007572ac1d9833ba941bdd9b5010fce40e3d4a |
Hashes for stim-1.13.dev1700958181-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eec0840b1d88ff0d5865285f4db57c91e09a8c94301801c147159d30fca4328 |
|
MD5 | 856e559ed19640c171cdd237ee0626a5 |
|
BLAKE2b-256 | ccf8c3885de5c6ec9c246a7413228f13f4b7cb15b8be2cce7838411c566be676 |
Hashes for stim-1.13.dev1700958181-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92bb73fc5570880be58e82cf87d23ce9e3f2be35d263f9fcc862c219ccfee6a8 |
|
MD5 | 02928e7b68309cffbac558f675fc7022 |
|
BLAKE2b-256 | 35d6914aacdbadae3f3b47d26b620e055cca3d0eb07602904c6e42e512dd5221 |
Hashes for stim-1.13.dev1700958181-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb1f45d7fbf85c1dc45ad12ea6a3d8a6816dcbc92482eaa62608a6df1755c83 |
|
MD5 | 044b8ee73669381674e913400cfff458 |
|
BLAKE2b-256 | 3e1090432a9ab51f37e4e51ab7d3ab71533f73a1461562367b9a6cbfd849887e |
Hashes for stim-1.13.dev1700958181-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 022249ba725ad0310713852b4fa5eeb7438ce960282e74376b7e67e33a80f7e6 |
|
MD5 | ab7cdc93b82d8a7d1487a16d6afc85cf |
|
BLAKE2b-256 | 3df6c151e1dd6ff91674ed41841e49018baf5908fb3ab35d148f3610958cdd81 |
Hashes for stim-1.13.dev1700958181-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a47f56cb4e0c61bc7a5f395393fc3773489631bc7e83fc43280d278daa022bad |
|
MD5 | 46e835a9fdf42d00fe506c6c8e0ceb18 |
|
BLAKE2b-256 | 1c7fe68d08185b44e6b94a354eecceb0576676158933f088f29ca7d5d26afb77 |
Hashes for stim-1.13.dev1700958181-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49e48bf28ea4b9e4b6214c2110b164353a4ca57aa67198005db10f3e2e394175 |
|
MD5 | 80c79b3be2505de6e55d99b1ef21c0de |
|
BLAKE2b-256 | 0420cbdf2038f599e952f0640e4c19a278c7ad0d74ee3fbbf79eec2308249ff2 |
Hashes for stim-1.13.dev1700958181-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f64bb840b2875668406907095d79afd5901d26a1e76b67185d58226ea9682a |
|
MD5 | 605be4a8e6a10616bc4721cdcec198eb |
|
BLAKE2b-256 | b25fc6d5878ae433c2a7191493ea2d3adc02beaf8a1db4275925d567ef09a9ec |
Hashes for stim-1.13.dev1700958181-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05ca059c3ef0810aaf0968f4a204597822326e21d9b67de1bcfc9ee5f67b5ba7 |
|
MD5 | df1d10439522d5d17b21ec1b5e784924 |
|
BLAKE2b-256 | c0782c4e13873822cd07ba0d5f70ffe6145263628679578b260893dac012bb91 |