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.dev1726895845-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d024132056147639d771e86d341e081a2a8b844f21a2c6a1c199146f554d0e0 |
|
MD5 | a2a61d626e5fa8ca65051125ee2835ac |
|
BLAKE2b-256 | 3ac804386617c74ea73de3b8fe79dbe48628fef49db4181477564fa3f122752a |
Hashes for stim-1.14.dev1726895845-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91ccd46ecf30ddb1a58aa432784ba78ec788fcc85b16a7bf3d038ada76b68431 |
|
MD5 | cef3a40e345ff41fb2033a8a7f08200a |
|
BLAKE2b-256 | 1fea63491e893b24b5231ae9dbc14d8ef30f8af6f96baec326e6b2dc5c429e53 |
Hashes for stim-1.14.dev1726895845-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e01382be7694668b8684cd8209fe98abb90d0b05640aeb9b7226fa99a02831ca |
|
MD5 | 0331daa752bc48e4164d5fea5a674a09 |
|
BLAKE2b-256 | 7224caee31ba6d6516bab079974cc2208687e15ea754532e4fcb01ed34f7e417 |
Hashes for stim-1.14.dev1726895845-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e7654f33f16f6eb0503e9d56c1e77805267da65632249eba324f392b1e02912 |
|
MD5 | af6d6cc99cb82a8803f944f91a0141c4 |
|
BLAKE2b-256 | a71838acd9a9532c452998af56d47d19f7830e1bb9d3642464b6ec9d64b4d4bc |
Hashes for stim-1.14.dev1726895845-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a637b0f6991eb64f226df7c500a167151ff3c9df43643eaa9b3988bfa1837373 |
|
MD5 | c87c715788198d8e0a81c8ab5479f57a |
|
BLAKE2b-256 | b16b9f3f1844c98d1544d82ecff9638efab1ea94c69d7938ef3dde1a8bf6e554 |
Hashes for stim-1.14.dev1726895845-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ccff53570f604a4711c39e2674bff8ff208803a9b334da2694ecf6e73478cc |
|
MD5 | 9008d3399e0015d1a73bd92312a023dd |
|
BLAKE2b-256 | 1b29ea061d6a9eaf60adfffaf39b2efeb5a41daf919dd19c8ac736b6230290bd |
Hashes for stim-1.14.dev1726895845-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b34a7e7eede27bcede195ae943ad8b640fa3e690dff782ae232f232f9e589728 |
|
MD5 | ad5fbf779f3d204ccfd7718247ef3342 |
|
BLAKE2b-256 | 4c00e5d0a7fd5c9bb35f8b783b426588ce54e281c11ad8df8be1e4ba30071c08 |
Hashes for stim-1.14.dev1726895845-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ba54e9e789ddb407ecf0f0ffa3936a0bf04984758d0536f5ac953e351fb50d |
|
MD5 | fc50b0339a9b1cd44963d0a6ab496649 |
|
BLAKE2b-256 | 501294b612164e59711290fc06870569e7f11fcb91be65328e2f7bdf967230bc |
Hashes for stim-1.14.dev1726895845-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 526201bb8c6b06ce1421343a8f99bf94ad8aeb68aa983d98e5c7f788988eb23f |
|
MD5 | 3bdd11a4f36695bf614ecdc74277613d |
|
BLAKE2b-256 | 35c5170e90327041647e07094c2787ff88f9c87a2c74cb7a3255df52fe88151c |
Hashes for stim-1.14.dev1726895845-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0de49db43214e3b8e1dceb686b52b3cff5b7d3bffc3d3508de7fc5945bfb2644 |
|
MD5 | c361b69dc750d1f5f9caf38f021da4b5 |
|
BLAKE2b-256 | 3979aae81f3de602da1a94f2141895cd7d63d19392aa63525a888994a24ea3e1 |
Hashes for stim-1.14.dev1726895845-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af6b3462414e183feb0aa615d744cda7d3f2031365b0c75c3e0df2b03c51a643 |
|
MD5 | ed1c4cfb448b27968c468d16f8e790b8 |
|
BLAKE2b-256 | 1bca58a81ab00f6d739917175db2f141fec1e7a195d61d1302ed683be515b8f0 |
Hashes for stim-1.14.dev1726895845-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48b6cbfa7df3bbc575cff4bffd5ceca77afc9f2482e35e827a3f121dde3cba3 |
|
MD5 | b4b5a7615edb439300a64a5d700ae080 |
|
BLAKE2b-256 | 28f37960a86f4a25a4708d807e35a90ada706f23e1a8f685dcfbf0c94f5fbdd1 |
Hashes for stim-1.14.dev1726895845-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b26446398d5af2c8fadb5013b91b01b40d187a5fc47806de9552561cac7807df |
|
MD5 | 8cfa6814e0fa3d422f1b442149f27884 |
|
BLAKE2b-256 | cc4b78141e5b59f62a10517299278919b8606bdb07063f576a158da318d26428 |
Hashes for stim-1.14.dev1726895845-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f677e311261adb28c96347e32b144b268c2c921d82a1dffa4dda4b17829933 |
|
MD5 | 97fd812c071476c98d235e287662e59b |
|
BLAKE2b-256 | 13ab2db6d30a64bb35b362266bb9d2950e8c197f5a51dbf7f96bedec93ff8e73 |
Hashes for stim-1.14.dev1726895845-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a35a609d84be64fe2ddcb3217035cda7a178bf844d80845c3f6a8950cb8bde73 |
|
MD5 | 903bb85539ee9bdc12158de8f3d4b06c |
|
BLAKE2b-256 | 547512c4b9c2aafb29d3991ce3a4c4304e3a090e5104afa1876fa13ce39e7f74 |
Hashes for stim-1.14.dev1726895845-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c63328ab7ffa45401b5e49a44339dca889e0bfd86992479cdf8661210ef5ec59 |
|
MD5 | 710eef4a58a886c06dfc115ea2175d2b |
|
BLAKE2b-256 | 25f600f117f48d2be8e4752b10e6081d214291009aa5b0ae2c4287295013682d |
Hashes for stim-1.14.dev1726895845-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb8b61f687a560f14a196266cda8613b073fea0d69c69909a9716eaf29fde4b |
|
MD5 | de1fddff7f3f60ef51e968b2adf56b48 |
|
BLAKE2b-256 | 577c148c88090fef9498aa285027cae13368aa2b8abdd6b581c0aedaab53bf97 |
Hashes for stim-1.14.dev1726895845-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8298859bc42d614904a7fc038f78aaddd7aa1c164d4db9c87c77a23b013a7756 |
|
MD5 | 9d171553f44c4429aa6e872d7f633cc1 |
|
BLAKE2b-256 | 96948ddc0c85a2283d15b5d489b27b5f563ea7227a4f6f440ee36b2969da64b6 |
Hashes for stim-1.14.dev1726895845-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f0df96062fe84be96197154379a78e39b20f96ed23619803eef39cd3e1d2ea2 |
|
MD5 | 4b606b64b92795c0d42d5899c96a9670 |
|
BLAKE2b-256 | 20f2de6aee653aff059b086b04b73f694c96675cc2344598a841cc114b2b33fc |
Hashes for stim-1.14.dev1726895845-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dc289d766f87f6336ba80974c8074bc727ff5274e955046ea6948a55b3029fe |
|
MD5 | 172f93c9aa15368c96241d62a775f68a |
|
BLAKE2b-256 | a17d68a1e18d8f20379222ef278463a8afda55733cc3ccb7bdb0b17a4ee41725 |
Hashes for stim-1.14.dev1726895845-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dd368969a4f7d9525a1ba0c70b9b17ad3b336fcf2bd0e040c6afe9fa2da49b4 |
|
MD5 | 1b96cb8cfda2d3c107569216035e4bfd |
|
BLAKE2b-256 | 544faf053294e176c915813651698ea809d61ae477ef3d27e17672fb2542a07e |
Hashes for stim-1.14.dev1726895845-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39af53739989afde8d97da18f30071f3ffaa6f25cad8660218f922ac5a14b049 |
|
MD5 | 4c9b8241f0346775580225e5515c0874 |
|
BLAKE2b-256 | e509f5e5654221f7289cef5455cd0a9843e807dd21655992e76d7ebd7a7d0b6e |
Hashes for stim-1.14.dev1726895845-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2cda97276881c022c0fefb574bf713b815522514f465f877693ea4d4786738a |
|
MD5 | d797cf3dc8a69aecbf6595ed46fc3d3f |
|
BLAKE2b-256 | c8e50c2c1f95cd515037d41813d59477b7840eb00ab03b7281150e9c1415b4ac |
Hashes for stim-1.14.dev1726895845-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eae55b7c8beacefdf1a00b329a5a909123d0a9858f8f1e239d6ce71ff187793 |
|
MD5 | 8dfa0758c1f16e4765ac0273e2f28e28 |
|
BLAKE2b-256 | 4fc91796b553f090e7a186b332ca7058e56d6eca38b4fdd2b4e51c08ae99cdc4 |
Hashes for stim-1.14.dev1726895845-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c98bd6c1d8f566348d8080fc8eab22706e6424ed6e52e0f834bf2ed22d2836 |
|
MD5 | 794ac777a2d6c5772d5e8870b640f69b |
|
BLAKE2b-256 | 87d5ef0749652abb348634d0ea4e0d8752c39d64ce73dc97aadf115468bf98ed |
Hashes for stim-1.14.dev1726895845-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c779aac1f969b84fb54508fd3e55916c1f7ee5046e87cb61611da1f1d6d3a53 |
|
MD5 | 09b3b69f782f8fb1657e2fc556c75957 |
|
BLAKE2b-256 | 6ef952f137b36f71ecc13f77c6d0ac0b570f3124efd8fae91eb9f0247a86c151 |
Hashes for stim-1.14.dev1726895845-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f634c3de72a0fde69480fde96ff7a59ae551aed66240fe552748773370b8e7f4 |
|
MD5 | 660a4e1bc9cba2dc6888d11f8f7d41b4 |
|
BLAKE2b-256 | 2983d5dfb07bd212edf1cde4b468eb632a7ce45f3d40605dcec00a84076ead43 |
Hashes for stim-1.14.dev1726895845-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ee32dbd8e8aeb4ca3bb3a4d3f92fd32ce993b9d3a707b5743c05b11fcb8d89 |
|
MD5 | d135c5634a42fc7643441673f72fcb08 |
|
BLAKE2b-256 | 38a3cd2bd471d30b2957defeeba47da8437643ac5cd415bd80cc1dd35990d24f |
Hashes for stim-1.14.dev1726895845-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd6f0d1287f80c023e05603c6ad935200858c3412fe7e846b223fe83f32a9cce |
|
MD5 | 1e05e592b079920c91ca87de20c6c30d |
|
BLAKE2b-256 | 29ff51a011d4cc1300becbde3d518353d5c75e033c9fe89e53018c0ff849da31 |
Hashes for stim-1.14.dev1726895845-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 770d0c83276088697c5226e27b91775583f8ff644836415de8161e0e99520744 |
|
MD5 | 64d93018b3ec0d205e580eff4e856aaa |
|
BLAKE2b-256 | d24445914e3ada8e3f0a847783ac7b5f0bcef56a58754a26d888516218eaed29 |