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.dev1686939303-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a3a192e61e16f485a58e188234ac074fed5ac7c097da541dbe06def4cadbd5d |
|
MD5 | 388a42b0a3262e36a5c097abc127ad43 |
|
BLAKE2b-256 | 783a39dea0fbbd13dd7dd29a53419fe08a29eaaa950898a54dfe1de39fb34be3 |
Hashes for stim-1.12.dev1686939303-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b5bbcd10c6213109456545fbe452cb7accfe5fbf33a157c0471a9a204745e7 |
|
MD5 | adcd5a62280d5eb9c6d178ee1fc531da |
|
BLAKE2b-256 | 3ba3a97622e26ccb54eab76b2d641cf3c6107bb1fd690f026d9ea27331b4a947 |
Hashes for stim-1.12.dev1686939303-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15b2b496dc29ed82c4d5ab3d77f984293907fa49972f9c4d033b6bcf47c0abd9 |
|
MD5 | 9b887238b7700fac23ce8a5c6ad4ae39 |
|
BLAKE2b-256 | 341faa0d8389ffd0899d5290ed8123f5882a05b4e161aa085bfdfd0ccc6a5694 |
Hashes for stim-1.12.dev1686939303-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38826079eab243937e8d8e0f0c176105e72f130c389fff743530a2263d71cb44 |
|
MD5 | 893916f3f146e1fbc723d838a79c292c |
|
BLAKE2b-256 | a521a89324a734aab1676237be77d3266a1d093a41f10663ce5f6bbfe72a801e |
Hashes for stim-1.12.dev1686939303-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 189da308c6d0881e18b96505d5ac2277020694f72a0010c16f06e60eb9f6c1fa |
|
MD5 | 041fd533e914953dc14956ccdeedd4b2 |
|
BLAKE2b-256 | b80494fdf375f546b4ba88ba61059898f2504b2bc0715c04e9c7aab39ea2d5a6 |
Hashes for stim-1.12.dev1686939303-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26f4460856b650e45feb7624c1e0dce71d5b7882c7085add64c059529350cba5 |
|
MD5 | c2411ef73afa8a06246e90e14fefc593 |
|
BLAKE2b-256 | f88f2df6d4adf68f399039537632749af5d286d2ebf340c5463d9fe0c7433037 |
Hashes for stim-1.12.dev1686939303-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23c3a35503d7df03bd792369c7dc28cdc5169582a66d57de1dcd0055ba92d51 |
|
MD5 | af3a0cbc983c06ef5fd83b8498643bba |
|
BLAKE2b-256 | 6df7e485499818755124adf597b11aa0d14b838375b53982ce7ea589664520c7 |
Hashes for stim-1.12.dev1686939303-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f54ba750c195314cd245cccbca8d326175cf9121f4bf5e7245bec33fc8f900e8 |
|
MD5 | 322d57faed1b074889a0cfe04e92240b |
|
BLAKE2b-256 | 254a26556a28b92f8e8dd056c52c56a38b16c8cba573af59dc6382742679b0d4 |
Hashes for stim-1.12.dev1686939303-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b26214fd33f24a995817c9610d06aed65763bd966a25cc2eb30cd46552bded |
|
MD5 | cd2168af8c123d5852c75f233d5824f5 |
|
BLAKE2b-256 | 8ae3bf1eb62482dd60e247e7a586df48ef5a3ea19e88f9772047555a8242f793 |
Hashes for stim-1.12.dev1686939303-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 847eaecb10291edb1d20d4c099017630d7d76344098da6b9b72884596069e401 |
|
MD5 | cccce9c702fb382c68739bc8fc4aa14b |
|
BLAKE2b-256 | 8cec3d8273a21c1304731ada24238dd9d2266e8e10807a17318a8efa51f741ee |
Hashes for stim-1.12.dev1686939303-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc80cec379715b6c890808a528d5b635f3e34231da2d535839de6c92b11d5ab7 |
|
MD5 | 9f279cafc39ecb404b37d94af8e633c6 |
|
BLAKE2b-256 | 48079944112db18cc6875e5b47df83b5349c07e1714bb39493e777fab68d501e |
Hashes for stim-1.12.dev1686939303-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbd6033dac6b1a1a00ff573e569e366ec2e4917ca50c0f01623d9e5c7330405 |
|
MD5 | 64a9f0dcb51926f46e120abd0175612e |
|
BLAKE2b-256 | 49f1616908d97e882a57f69214b9b559fe7b7527d4825c9278c12eaa09dcc200 |
Hashes for stim-1.12.dev1686939303-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a8314b2e71d958a4d30efe4d12bcb3e3b9deb4458773754adf6e98184617c8 |
|
MD5 | c0e91e6fcccc87005ed8095f9c490a88 |
|
BLAKE2b-256 | ae2ba3a5a3dc2400602b82620534b82433f3a7cb00015a971652b4ce9442dc44 |
Hashes for stim-1.12.dev1686939303-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fa31b563c28d37d0de3f01810e82c38e4916c31a6d8a63d2f580cf0f523b30f |
|
MD5 | 3379292772b744b0a13c73089dd396cc |
|
BLAKE2b-256 | 759ab4bc91696eab7dad4d9092dc0ef75fefb24699276979b5283a0aa5d6284f |
Hashes for stim-1.12.dev1686939303-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c30d242286a4f7af585fa163d80526c428bbfd172d081f59eb32474bdf1d0e9b |
|
MD5 | a209efa24dae9d456497a3c3fd2941d5 |
|
BLAKE2b-256 | a592159d807f49567ee01a5e869668ff0d9d6ef74fada72e0afdb7062bf06eef |
Hashes for stim-1.12.dev1686939303-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 443989e29c20734edc62e36b76c83b9a0af191fe8a6d48190f840c50cac58bc5 |
|
MD5 | 69d27742916568e412ee7907f07a280b |
|
BLAKE2b-256 | 9da8b67dd0fa49a14c3d28d80795974c9f84baa5be6fdfcb1c051d498c0a7d00 |
Hashes for stim-1.12.dev1686939303-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98673e3a1a5e88bbccd7062874c2861ffaf224b963719f3ae0afba6d08283517 |
|
MD5 | e44417a448f32a7158fbb76a7f4deeef |
|
BLAKE2b-256 | 573a6b3d92d24fdbfcd024808f0b661ea72c3100b60814c4a5e5d5d062c6b608 |
Hashes for stim-1.12.dev1686939303-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adcd629d0aa390fa8d0952a9bfd37bae0af507e8d24e9a4fca18f96e16aca31d |
|
MD5 | 244ac4086b29b842d07a61a25d8792c7 |
|
BLAKE2b-256 | a63f5c37b1d15db581379ccee0f58caf52957cef8ac623f081fc74fe636c233b |
Hashes for stim-1.12.dev1686939303-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6fe41d412d0d1f063e7d53a7e4d5bdf0f33dc3d4b8eb9af4e6aa09c22195a16 |
|
MD5 | 3bc14626015b353b2350c39cb498e9ec |
|
BLAKE2b-256 | 6b3f5eb434b85009756fc007e0c69e2af185cca681885ee114ab6abdc23a8b92 |
Hashes for stim-1.12.dev1686939303-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9865ac52f3c80f21a6919d9a7f2f26291eb4c4470a76e96b294b075db643d880 |
|
MD5 | b6d21bac9e5460ca672bc7736c420bf1 |
|
BLAKE2b-256 | 8b6147c35354ce1904399047d42d8ee961b2c0f1b4cd5f383a3d3040bdcc6abf |
Hashes for stim-1.12.dev1686939303-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7668dc887f77dc9dac5fd3509a4d4daf4f2a8c3f26168fa94d64c6c70c3a1a9 |
|
MD5 | 3f2865fb35f8e0a3a1ab0832d5e65551 |
|
BLAKE2b-256 | 016f0de701e8c4ccf1e518a769635f85bdc2f5407562f95aa09283e932606690 |
Hashes for stim-1.12.dev1686939303-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c506c7ec31c4d37d8d16cb39d3305795c5bbfb04a5ce0d35c98d7d6327d1b50 |
|
MD5 | d3a36187ea330f7606e914c053044132 |
|
BLAKE2b-256 | 7c704af5abb09fdc36a24f1b78b05fc011556e6b22b2d214df537d3c84d898eb |
Hashes for stim-1.12.dev1686939303-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ab464b3bfbb317d2b0651d8a1379b8399b025e3b8c230064ecc1c46a6771cf8 |
|
MD5 | 9568e1491771d9d56346010e46b6d0cb |
|
BLAKE2b-256 | 59b5b161a51312bccb051fe11542b6d81739842a3f4d6ef9f95460999c947ab1 |
Hashes for stim-1.12.dev1686939303-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f591da30ac79f1b329e571f9927ca674805cebe852f150d1829419dbb0989e9 |
|
MD5 | b9ca9efb1d064661ceaaefe2f446e650 |
|
BLAKE2b-256 | 285729c5de7882d1722429d2576e26f6fcc7f00fa005af7846de6529fdbe6dba |
Hashes for stim-1.12.dev1686939303-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4841c95c01d291559aa40ba79598979a6d1382d26bcf8d359d33f2ed02f018fd |
|
MD5 | 292f1c3b1246b55a5dcf162c405354d2 |
|
BLAKE2b-256 | c32ac0cfe780968472c5041e56f1047fff44f51e448a494c43d2039e346854e5 |
Hashes for stim-1.12.dev1686939303-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 892493bffbe9d68b2d1029035ab3f09814a1da4c76eb4472c898904398fb61b4 |
|
MD5 | 246a3ee64beb113a157dd763eb2de361 |
|
BLAKE2b-256 | e836aa2c687590a9fae5d0dc272e1b5dacc30ddf312e76dcdd293ac849584b5f |