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.dev1682618140-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 855e50c92f8cbe52fbe957f8b175547e4118736e7b912c61efc9047f3de156b1 |
|
MD5 | 6202beff173128129e301893f300a629 |
|
BLAKE2b-256 | c5f972df0713c0aff2c97ea00b3b8cb37f513d35132e5109953b7f6abb6a613d |
Hashes for stim-1.12.dev1682618140-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a77dbe15e105086ca0742265d32f1789190c85a49e86efb184e6861c585cda |
|
MD5 | 020319d0b95b3ce121257ef77274fbd2 |
|
BLAKE2b-256 | b41ba97044382ca03d615cc8f4d3effbec6829910d06f471bc6675f3401754ba |
Hashes for stim-1.12.dev1682618140-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8960c2eaae5e1de1acb9bcc953ba4e00868e805034c8e4c115ff186e1ba95eb2 |
|
MD5 | 2f83aa363ef13ee1767772beb8545e90 |
|
BLAKE2b-256 | 29f529d5209e3223ffc87c7ba8114ea42f8248c2191207e1d94f5dfdb52b6fb0 |
Hashes for stim-1.12.dev1682618140-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b438c4fb7c6d30d6a62b4c4b9437f953650f919911572a26088213479d3eb113 |
|
MD5 | f37e998c01d3927c50f8aef0f6cfb59c |
|
BLAKE2b-256 | 041b7055b9e2c511ca62e91289ca9d0264ceb88fd3eed94a01f81d62a00a72b1 |
Hashes for stim-1.12.dev1682618140-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6cdf811ada2d3876fd3a5a348276ed11a97fa390ef204bde164888cd9f7d81b |
|
MD5 | 4295b5d9fef42a9dfd4331b214284482 |
|
BLAKE2b-256 | c308ccf360d4161f0ba9bfa92d634fa95fbf6d8b792020cf8e8fdbb14ca7673b |
Hashes for stim-1.12.dev1682618140-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfc328126af59b6003658767f069efcbefb8c33beba255fc18aa494406160211 |
|
MD5 | dae716f7dec77cef7574630b6a908e15 |
|
BLAKE2b-256 | 5b128ce09784cab68a9969ab77e02ac8585684f84b2638306f996ebb23564539 |
Hashes for stim-1.12.dev1682618140-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c0fa1bda89c17d6dd8590a75c3134f603e261c8b38691257c4a9fd87eb1d64d |
|
MD5 | dc9f971ff93eb60418c9e576ce1c0fd4 |
|
BLAKE2b-256 | a121d3d130bdaf3d6012d29caf8ab7297bec787bad947e70a0bff6a4bba8a2b8 |
Hashes for stim-1.12.dev1682618140-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 889864d8cd297df7fee6e551af3195fa9938c71266f8682b661ff14afe0c9f76 |
|
MD5 | 6dc108d429c9d0e23aefcaa14abb3d92 |
|
BLAKE2b-256 | b4f786d4814d4e52f040189ea00380d80fefd4d5a038619f470bdc522510a939 |
Hashes for stim-1.12.dev1682618140-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32c060bf801936b9defa6150e2d72de5bcf4e06f032674e450753360e238d167 |
|
MD5 | d715072c7adee59c1fbef30ffd976fba |
|
BLAKE2b-256 | c3de7dca980292a12b48c9a6d7409201e3a04288a2f47ff71e6b7de15e79eaba |
Hashes for stim-1.12.dev1682618140-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5b077a30a94e288e2d0387c19d0d3073774b37c1a38e444b533e87536207f4 |
|
MD5 | 06f217d2bb819da31230f899b947dd0b |
|
BLAKE2b-256 | e690eb61c07e5edd45cc5d873c6903c81466c47194f3b522b85b0cd1231c9103 |
Hashes for stim-1.12.dev1682618140-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c72ba2defaa243afa7e70b4968ee3f028014f69439b037e83a0dcf748496d2cc |
|
MD5 | 4fc131d6755e944714e63fedc2659b0b |
|
BLAKE2b-256 | b260dea01eeff5650b3a1603726495d1a8c9fd0e49cf497f5fcd13a72db3d4c3 |
Hashes for stim-1.12.dev1682618140-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a2c4d2ffb5dd1ef937fa4c4944be7add029ed0d1b205399b9091d97d13ca54 |
|
MD5 | 4591609e53866945215337f48faa9409 |
|
BLAKE2b-256 | 94ee0b52a1ef5dab2fbd3e9c9b6918ef1900853786575f1c04a9ca1d25b9dd81 |
Hashes for stim-1.12.dev1682618140-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adca18a193230b6a4cc59907b8d534b43dd4307f95707130536fc5257fa3438e |
|
MD5 | f9da27f4f8f84e062c86d492a82265e4 |
|
BLAKE2b-256 | 7f52192ee7e9e7d0588f3004f549afafcadbc955a20fa6d881f869765557b69f |
Hashes for stim-1.12.dev1682618140-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf05faf58f6e9c2343dd0740b8675858da2dfa5b7f10701356d095621a51f83 |
|
MD5 | 89879f6d72b9bbcda1018a872a869e5e |
|
BLAKE2b-256 | 84009e9a1cdb33fa02a2e5d7101d3fa57e527cad7694ff27acce520e70498403 |
Hashes for stim-1.12.dev1682618140-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abb8d2467e4598a969ce28b47ff430f30b8f7fca6ce72ecb9289f189a8f747cb |
|
MD5 | 81e3aa13f77e1620d472ac153aa24188 |
|
BLAKE2b-256 | 3231a5e21d28ce2a661b63719864ae660bcaa77a5ad21ab8654356e7b8d9848d |
Hashes for stim-1.12.dev1682618140-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2c0e6cb98d7651f592be0682ae2a504c529e145395c763cb6134f33c84578ed |
|
MD5 | 74de80d57345c35ef7315190254444fe |
|
BLAKE2b-256 | f25a9fe390c76f4785f003a2fa92b1f60e0e2f0b2e4da9f510fcddd8c8679759 |
Hashes for stim-1.12.dev1682618140-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 322cf878b7a497c185e280e7cadc5eb12658187100be93de41301bd2b1291de6 |
|
MD5 | f91f998a7b5ca44fbed54cb1787c02fa |
|
BLAKE2b-256 | ed68eae453c4145ccfa4613c9c3e54b77e5a71058e77537a64d72f25a97ace8c |
Hashes for stim-1.12.dev1682618140-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7b2db2ab982fa1555f9dce870bd98b1f4c4523599eb137b14088967d9f30385 |
|
MD5 | 223f295fa172bc45647e191d9ca6b5e6 |
|
BLAKE2b-256 | b75bc07ab69820c92dfad31a058b93ed33680a2e52b361b2591831d6abe19f7f |
Hashes for stim-1.12.dev1682618140-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caae8765ea66982674d17d51b8b37ccb396a6a1035fc8a4beb6f4c5941ced871 |
|
MD5 | 03a91eeb9e52d47525b291d2bce935e6 |
|
BLAKE2b-256 | d65dbbebe19a10bfc3f445a1170513b8a05c832f447f4a8183bbbd3831cb07f9 |
Hashes for stim-1.12.dev1682618140-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb9690b0e43a32fd7d906730dff90100b11395b4697b05c6793072690a4d465 |
|
MD5 | 80a4355974638f98b45e1499be688dcf |
|
BLAKE2b-256 | c19e82905df9cda275dc141be41d8e1a197ef02454cd03e127bdcbcfdb7aeb52 |
Hashes for stim-1.12.dev1682618140-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95c68524b4656daea45e911bcc98fce1ed7ca453e39b49b04b0ab8dc14c240f8 |
|
MD5 | 8a7148f157b099633907692cb7a99797 |
|
BLAKE2b-256 | 96be0f25d68f77a80024c73a096f6b62b3b19eaa1a52449442d596bb56c23ad3 |
Hashes for stim-1.12.dev1682618140-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa3c11633835700a8661de12bac8315b73c30fcf9cf3488f647f658ce96eea75 |
|
MD5 | 0dfaf91c8623959cd707a24a12d33040 |
|
BLAKE2b-256 | 026a420451f938926dc5d514e3c0ddc36a7430c22b6a264cce766b6f8f1f1ada |
Hashes for stim-1.12.dev1682618140-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adbf63bc3299acd7fa7d1541e7c015a69e5a06d6b24424659c8051a8e5e72257 |
|
MD5 | a14b15f4896902807c81c422b7f1b41d |
|
BLAKE2b-256 | e26b56e5a629d93f51349d02bb640623e7e90cbd13d5937c3e6b6fc0f9f68b2a |
Hashes for stim-1.12.dev1682618140-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 519424d8299dd87f857f338c3a9634355ff3d907ef690f83f44e485635575828 |
|
MD5 | cfc0944ff1bbf97098f3fc209bbebd54 |
|
BLAKE2b-256 | 3fee09d36d7c2a4ff196515469a22ac84c2b41d90ef80f1fad96b5cc3bc513b9 |
Hashes for stim-1.12.dev1682618140-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa18ecd4ec3671ce26b91ebeeb2791376278cf9a2ff32b9a1e7b0ebc170f0ea1 |
|
MD5 | 4bcec1070b81e88bf9d11e870ed932b2 |
|
BLAKE2b-256 | ac341ae3f918a5334d6051f5b923dd57cd94475294a7bd2d38b581547746443a |
Hashes for stim-1.12.dev1682618140-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6922b620202e9ad5fc111a68b9a8da8672925eaf429bb004452f40769f63e162 |
|
MD5 | 8c98eef591ce35807ecce888c0fd8309 |
|
BLAKE2b-256 | 83f2770b67253775cfc4e180443828c58ad5e2df935eef0af50ff3fcb95ca7f6 |