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.1-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bd9e04046e5b398499d74a94a9abacde70c9f2c3442d5f6a5f193f5f137025f |
|
MD5 | e0a937fb937e21f749cdbc88d5fdd805 |
|
BLAKE2b-256 | 454f68a957c528b56427b3ef4ffa3b7ef7181f4e95f9f02197394ba5d9d8f172 |
Hashes for stim-1.12.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1904dd8779dae758eb4fa95f2b881a6c7903a949e709f9b995f115a6f2ac8f86 |
|
MD5 | 02ab6007ba3d1500c0edde8c952778b1 |
|
BLAKE2b-256 | 9f7e985ade3720d82daa023086a9786be35f5d90c0976e464fa87ed137737d1a |
Hashes for stim-1.12.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61957d5cbb633a4efe5a9dc21b350fcd03a5767c441137e257517b223ec289be |
|
MD5 | 5628d2b5a7bec5c261e20b1fc772c61a |
|
BLAKE2b-256 | 5c2ab47f8166212a9f4baec4b9fb2098bbc7fd86412f3ffe68b1fc12fbdfe17e |
Hashes for stim-1.12.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebece3d630362516c39139dae0c321d2a6353fab78884b41a3f436ed923c1876 |
|
MD5 | bd6f8baca305ad9db0e3cbdc2ce05d4e |
|
BLAKE2b-256 | 1905de447fa2bd5530d60ab4925bb4543114a63da1603954ab99ba1214ad084d |
Hashes for stim-1.12.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c07f41ac40a0be6edeea03d50242d273e95d4590461a4b7599bab4e8dd29aa6d |
|
MD5 | 3e23a69dd9c2a6a2c2a5d0041e90e58f |
|
BLAKE2b-256 | 77e007df39a35954f15c3c7d0e8aebfcf7bb67958e70e5b50f920329a3c690ba |
Hashes for stim-1.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 475d91d3357d6f29baf08550b29e7fe5678c4ab3863e4ba25782e38f5b945790 |
|
MD5 | 2fbb3eb5a39e8a200062f927938a18f1 |
|
BLAKE2b-256 | 1fcc8ab4f14bdc4b8184eaa020982e8d545284d92eb9808be27eab5e8e42a85c |
Hashes for stim-1.12.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c26565a81096fb688190ffbbeae51d60289b49753f6c8dcf2ee9beeafc617a2 |
|
MD5 | b570ca90af7bb6db9846c3ca4804f11f |
|
BLAKE2b-256 | fb0a26222c07b5b9d0e34821e76671baff820d3a82430cc9efd1c94f7dc469be |
Hashes for stim-1.12.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2d674621ddce52bb0b0e54aaa2bd390707287454fbb0d6a03dc043eb16f752a |
|
MD5 | bbb073700100255918d641295f24339b |
|
BLAKE2b-256 | 3e65f52d6b21d97fa2471ea7cf739d93ed473771ca8068e4a25818767183eac0 |
Hashes for stim-1.12.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d62aee6b9265268c728eaefa971215454f9c93cf69bf04c24d1e78231124371 |
|
MD5 | 9d80d039c9fa7c6513679b2f958ef729 |
|
BLAKE2b-256 | eead1c31704a3a2f24ee2b991b095b4932b8084181a5cd320a9f31a57b935ea1 |
Hashes for stim-1.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14cb6400f49387ddc94c599556fec3f97a8f4c7d57300f984f3ca0cec838e00f |
|
MD5 | 99c520429ccf791667fc457f9c523495 |
|
BLAKE2b-256 | 10aa2ae925f5c56e76684e0531f7aba9fadf0694b9f7f5ed53407ef2b444ce86 |
Hashes for stim-1.12.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e066aaed805364bf27ffb2bc9d275111f5b0828156f599c2ab82b02f96134e6 |
|
MD5 | 2e130fa4f85cf83d891cffaa6d6309b5 |
|
BLAKE2b-256 | c5227b08beb900f007f0b615c76aa9f290e7028b0b4ac589b877f435745f7507 |
Hashes for stim-1.12.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be50861d1b4219a12264f0bbebb04900ccdd56819f51136283a1e03962d133b1 |
|
MD5 | 22f83b6c02c4dc95a330a5409b610973 |
|
BLAKE2b-256 | b53f2bd2ad88821b90755cc003c7d3c4ad4d17c05458a1a85b9d2fadc88c8d2e |
Hashes for stim-1.12.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86da45f618d5e8866a5197f10dd74ab23516865da2dbdc95edb54628195f67ff |
|
MD5 | 533f96f9a21f8eccd9dff206087ca8a3 |
|
BLAKE2b-256 | 734da26a1d04a7bc2fed154f8a5aac7caa2a5d5a323a63771ad10fdc69af5fcb |
Hashes for stim-1.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f2fe8c5a0906a8eb3ee3b3c840026912828e98a0dc44aace800e4d1d1b2b9b |
|
MD5 | d6a3ad803c281e1b7cb81a081028bcf6 |
|
BLAKE2b-256 | 75841e7a65d2e0d76d5680528c97eea6207bd07433115c3c59ef08bbac91e594 |
Hashes for stim-1.12.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdd744bca925fd4f78dd01a5068ebeb090d30d7bae9c4e379526838b8f5881fc |
|
MD5 | 922addeef030dc236bd94fea91db0d35 |
|
BLAKE2b-256 | 5bf357e4b6e845aa0efb129a81d9fb1ddcaf36b0f267a1060f46ac0d429b2922 |
Hashes for stim-1.12.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb3fb321a0d9f576f3655b525f34f1efccaccc57a1c21840b3f0cda0c93dce4 |
|
MD5 | eeb7b9cc4e4c2d15175aef8e5fa53b04 |
|
BLAKE2b-256 | 9c915282b96ec928d4ea658d806f3c92c67841ef127a50fe542c1d9442055aee |
Hashes for stim-1.12.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef6c69f9d222381e241af8f97ffe596a02a27eaa01a223b815b3350279515deb |
|
MD5 | 97e9a5811d2ff6528365ed26de4ab058 |
|
BLAKE2b-256 | bd5208b6cb1a6af6b6c3880594bcc54102f2db2b310749345abdd89c23b60561 |
Hashes for stim-1.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0587aeaa9791bf5b2b64c993c3211213fdfa247afffdbca5e8d6b329f1ee3926 |
|
MD5 | f461dacabff38b671a021ed4d59d9e91 |
|
BLAKE2b-256 | bf54c557a9dd41c1bd50573501a1c52a9f23dcfc2f53a13a556a1d235028aec2 |
Hashes for stim-1.12.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17d95d54d5bd163d22558369e67c1a4daeb21f4724c3cbd7f5dc954e5e90519 |
|
MD5 | 8a9ed1dac57f1ecfb808a2de9210a20a |
|
BLAKE2b-256 | f2369fac16e710b2fb4fb1c75639a15b3d414db8eba88b1fa87c83a95ed6d3a2 |
Hashes for stim-1.12.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e479614da248d95c98656985d2d132ca124259664a35a58f7d03b60cd4708ae |
|
MD5 | aa526750c8f2fafbcc00d407fd62d4e4 |
|
BLAKE2b-256 | 720892b46a7f9eb532402ae72bd0d45943d16c2f2c516939f7d6caf5b93b6f31 |
Hashes for stim-1.12.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf12de3f5ef03d3c248ff37df920aadec828b2f42c99687f0bdb54646ea9eb3a |
|
MD5 | 0246c5a9fe3395e15c55ad2ed33582d7 |
|
BLAKE2b-256 | 0634b39663cd71eef848e1da4916112dcedf90d00022cc55aaeed327aacf0a2f |
Hashes for stim-1.12.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985757b1d25b7b9b626c8cf646178dd931500820991832c82cff7ea0f6fa3665 |
|
MD5 | 3f3ddf4bb8dda68a17af0682a3c559d3 |
|
BLAKE2b-256 | 8070f35493dfb55c27521cfa4d749038dcbdfa47592593204365f572a7e1d798 |
Hashes for stim-1.12.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcde7ba4c91496b4d610df1db5976c3e153411a953e4e4969464cb7303a545f1 |
|
MD5 | 538efa1754415d1d4e3ca06524b80caf |
|
BLAKE2b-256 | ac5377860203503dafd832393879a031477c5dee6036ab69d24e39fa5c3adfee |
Hashes for stim-1.12.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b40f8748f21a12dfa1f40209706dc8dc4d4713d83a61f838361e6309ec97aa |
|
MD5 | 4be0745f9cac790c7557d5fb799ff764 |
|
BLAKE2b-256 | cd4bee5b0d7201ea2ac767f4ebd38beb4e6bc7d54db6d6c5e0b6e4d35114327a |
Hashes for stim-1.12.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3783158200ec395f9c40ecf4999b84fec7b8b31f9276993785d64847fa64a1f2 |
|
MD5 | b45aee7c55af5e8cfda52ce3aa1220c2 |
|
BLAKE2b-256 | ea7878e7860d632617bace1b8114d15c00f7c086277f460547524523b697f949 |
Hashes for stim-1.12.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee9d04f820164ac748f8fe999ecdda7dc3d4c0d3564805b522464ab0b1183e1e |
|
MD5 | dbdb8ad0777ecbed8ef75a4728d09fa6 |
|
BLAKE2b-256 | 051944c2ef09977e3ed09ca26499e826d38b7c1cdde07bb79678c1dae50b0aa7 |
Hashes for stim-1.12.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10fca3e2a4c07310d94710f29d42a808d0b4e0fbc9b6a80a69d37a6d188b60cb |
|
MD5 | 0b38577d78159b443a476eaa524df064 |
|
BLAKE2b-256 | 22364ca6ab464d546bd28f2196866581581c860d9c7f1c00ee2fdf22d04f0fe2 |
Hashes for stim-1.12.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78ba6371e3102e4c3dc40cb648c7e7dc4d2b53a8ff41b970253f3883b3bf439b |
|
MD5 | c81457efbc5848f72298a6ff316c51d0 |
|
BLAKE2b-256 | c2d5bfcc8765bde35b64fbc2001e4e736206b05a478c01cd673491fb995a6128 |
Hashes for stim-1.12.1-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f2d3da1d369e2eae45112caf80d4370a896f2caacfecae25393f030f76ca01b |
|
MD5 | 842edd766c57987d5185646c3beb3b59 |
|
BLAKE2b-256 | 0327212cee7b3325fa14ae464cf6649d4150562b84abfbbf32ee5e379cc4e5b6 |
Hashes for stim-1.12.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb52db06fe5b1e33f100dd07fbf9f4cf6acb83a40115177cc6b5b483b88cecc |
|
MD5 | f8fbf65719570a6f05ffa39aabb3ec2b |
|
BLAKE2b-256 | a93fda480d6412565821a911358b98bc6b29562857b640015a69cecfae26beba |