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.dev1722326436-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e367310962addbf6667b84ff083ef0cfb5dcc8939bdbba6d338c3b735ad861 |
|
MD5 | 2a2bfe92289959467b26d4febd70c188 |
|
BLAKE2b-256 | 56a29a048e3f09c4d16b9255cf7b8bf4166794b701d0355ad280f53314b12d18 |
Hashes for stim-1.14.dev1722326436-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff83971fbae5a593e8205005c06d06b1a1ad3aac02ddc0d1095ed679ada92f59 |
|
MD5 | 564557cdab3e7160dd287708ba60f145 |
|
BLAKE2b-256 | de4a51b54256237eaad12b44ae042f86a26b34700c9fdefcbaaa181c6475fa0c |
Hashes for stim-1.14.dev1722326436-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95f305f5c711a77bb6371aebfb9f3b0de35acc4ee9317772d382b6b4c86f17d6 |
|
MD5 | 73a011bf20e1603cd73ce438195c0210 |
|
BLAKE2b-256 | 783791bdae96a853b279bd490a547a04b37566ed53d3f47e5cf18c24b2b69096 |
Hashes for stim-1.14.dev1722326436-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d389022dfc094579a734537bf754da3dd9947574668f77057cae9c14c304d682 |
|
MD5 | 656a0bf2d5fac23a6b9ebaf8ceb57f8b |
|
BLAKE2b-256 | 022fcd305f385c8c438262aa87fbecf2ef24479c11b7e1fb2f9af5cf61fee04e |
Hashes for stim-1.14.dev1722326436-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e082a52db9286182579a10240b395d9f76bd0a6526432e57fc4844ca449b20f |
|
MD5 | 9c7e505d67b43590dc204fc82b559e24 |
|
BLAKE2b-256 | fc3ed2878d33fae4541791a3b3ab8b240f0611d3eaecfcd98fa0dae24f7cc7f0 |
Hashes for stim-1.14.dev1722326436-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca0a88f249dff591ac36194f8311aee014af7b91f5189dc43b08cf13964003e |
|
MD5 | 717f6bd04c4bf4cfef08903c9f8870fa |
|
BLAKE2b-256 | 44c7fb7b8d93aa5b4f55bd3e2b36634a66c32218ba41c62810ae0c1284b7ae0e |
Hashes for stim-1.14.dev1722326436-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d902a4c2079270b6bb66569d7c70b9be241bca0595c5b85105263bcf443a38a |
|
MD5 | 6f2821bb1187bbf4e50bb66a8e1d4544 |
|
BLAKE2b-256 | 36ceddc03634eafcf4fa226cf1013fa7841239241aad5894d4b7c09c69d775b0 |
Hashes for stim-1.14.dev1722326436-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0e65431a0696ac7a087d3012a0cacba7ac60b2694d34d2f15dca61be602b022 |
|
MD5 | 059db07d3501e5ff66d32d49097d47f2 |
|
BLAKE2b-256 | 10838625efb7ca807a707ff9611ba712845822d54700dcc90fa2c9bcbbcc3e7f |
Hashes for stim-1.14.dev1722326436-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 703c3ca935f5e31ace6d7b8bbc7051828033413aa5ed3abd53526fbd24f866d7 |
|
MD5 | 9415742fe427ef7517830970839e29ce |
|
BLAKE2b-256 | a9a1e2728d5b694e46d892c2b0edf5318e5c0bf7936d8b658771f9b5690215c4 |
Hashes for stim-1.14.dev1722326436-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda1461107a6a6634807efdf431a15b2cbb23d5c8f436162bed67782cb3233d3 |
|
MD5 | 18c5a1617435b34a31bc68816b5210e6 |
|
BLAKE2b-256 | 6d48c7c18b7d2e1f1b441a0e3e8ad885fa06d97b34a3c48a4fe5267b8a176d3b |
Hashes for stim-1.14.dev1722326436-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b03a72bf2b00c88962b10c369c20904ab2d3317acd90f60556b73890ecc543cb |
|
MD5 | 4ab68f23846d064fbd961d1527b20dd8 |
|
BLAKE2b-256 | 39effd231ca41308dca730d822bd3ac66c0186161236873bd1348215c458aead |
Hashes for stim-1.14.dev1722326436-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67c1e1b7b5119103c2c539b3b3df169f9e5e10474ea93f31dcbd42400e7dbe8e |
|
MD5 | 8667496ef4f007b7b2159c34b8372a8c |
|
BLAKE2b-256 | 68aff7810935e57aa8fada0965824141440f6f6be84050d1e2cf52499d4f1d2f |
Hashes for stim-1.14.dev1722326436-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ba08b668b41694143140420c4a5c5ebb23d09c3c3091d0d0042414ebd5a6f7 |
|
MD5 | 13bbd22d8206d2caac0e2f01ad75240a |
|
BLAKE2b-256 | 477fc6c94158a8368c285292a6aad03a0214d7331213ac9a3a291fe7cda4c8ab |
Hashes for stim-1.14.dev1722326436-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 321fb33743620402842dbca15d3224a8b3d11f52b855467003e7f456935fe9a0 |
|
MD5 | 5fd264a091a8b2420edf52370ddf4b2e |
|
BLAKE2b-256 | 98c302f82ddcfca1c98721ceaa7b246f8ffc1cce7937ea7bb0f888cf184bb831 |
Hashes for stim-1.14.dev1722326436-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a0f09cf227a807c9ec3466d6cda93004b1d3b239c7d44d42b04c1337f903d12 |
|
MD5 | 195fdf63eb9e3c47bebe8640f25b4c6a |
|
BLAKE2b-256 | 81fd529aa29b8c939c6d0f17285d6e7e7b8aa84200bfbe68949e3dcb77ab9bd3 |
Hashes for stim-1.14.dev1722326436-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64030aee6e031a3afd6c1069ec57618dedb395098de1725043824732db51a572 |
|
MD5 | 40240e9ef97b05db5a398bb8d9c1af98 |
|
BLAKE2b-256 | d4a780b49e3f1bfb46872ecb42064e79ebe2a2c944c580007cbdb83cfcd0ea7a |
Hashes for stim-1.14.dev1722326436-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d60148dc0282156c7441f7225d8951fe1f9bd3a732fc772f7b95db57b365b602 |
|
MD5 | c148624db702fa709f65892912c14ae4 |
|
BLAKE2b-256 | 7a1bc03f7f6848a8bff2de444492ce380b7a832c0954806964b7db3765cee20f |
Hashes for stim-1.14.dev1722326436-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2463b39f9ed542338531d91d2ccc161c5043e9788bc7700f8ad5a456085018e |
|
MD5 | 4a8a8835ed9de2dd3969ed0202505e2c |
|
BLAKE2b-256 | a4491e63259c5dea2f126e41fc6e4762a75b7630cbf86d477ef08191ac1274fb |
Hashes for stim-1.14.dev1722326436-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c1c632601c438c883fc4590a0c212bfbba71a1d14f3f72138565e6a414ea3f |
|
MD5 | 88994e55a42be020190b5786bdabe9d5 |
|
BLAKE2b-256 | a1fd1d506f1d12e8624b7234a7c390fd7e692e4d172c950fe3be38ca263f7574 |
Hashes for stim-1.14.dev1722326436-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f85d785c2622b02ea3d732b69ef68baf408c86ae0bac0bf21576ea9281deb9c8 |
|
MD5 | 7a3f4abb8507d92fd7a6503524a8d98e |
|
BLAKE2b-256 | 55645f5805e7e22c543e8e01f2bd4f6f62ac0ed253ecff7faa60792725c43429 |
Hashes for stim-1.14.dev1722326436-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91d6f30b8c96d5d0225b108e256098709dd6994c2afb3a354c2d4a9a45d75a7a |
|
MD5 | 15cb1d23a91db436f2dd48879ce7815d |
|
BLAKE2b-256 | eb61a56fe7b845865621ccc1454eb4685159e228d2082b3438c37bc426cbd059 |
Hashes for stim-1.14.dev1722326436-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 860be281af251d6f7f3a0aa3ec2a85e3cfb55e4fb98d4391737c9c4581949d43 |
|
MD5 | d567ebc724bbb3a23a8e637762132695 |
|
BLAKE2b-256 | 12d4675198dbe7af1a6743d69bade32dd94534b122d93e4822d53a7178cd609a |
Hashes for stim-1.14.dev1722326436-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a4240c18729d9945f51fad5791867ccf3a88a0dc0017cf585d276b6fa2a2932 |
|
MD5 | 0d38916bc3ce0c4473ef6359793757f1 |
|
BLAKE2b-256 | 602fd98d990e39ae6a045801f1b18820e38be7bcdc4265060bbe7a263acd7362 |
Hashes for stim-1.14.dev1722326436-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eb29770a7d55112447e2a113940a02897e92b6de81c8d3126c12d5878bd2fa1 |
|
MD5 | 4a73a730b2908e232089470965e7dcb5 |
|
BLAKE2b-256 | 6f46bfde39771a5d93aefc6e517e2161d13585bcbf7023e71a2ddcb1633d1f3e |
Hashes for stim-1.14.dev1722326436-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5d03abd4b966b15bda0fb2f79f1abe5a3631c2ea27abfcf7adbaffc111a585 |
|
MD5 | adb25522a5b5f1ef5031049d4a3f8386 |
|
BLAKE2b-256 | 26b466d3a5c68bf29beca915551f0d83745c461594d340d007466f4c344d29a5 |
Hashes for stim-1.14.dev1722326436-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22ac02d870ed51af1d42d7a466fbeaec9f960f262070922826aaec06a802e28c |
|
MD5 | 72041ee0affc75953558a76c27c9d43a |
|
BLAKE2b-256 | b9bbe2a6b5133aee4251ba8e61c2093ac83ce1c6b99317a17e9ae080edd2aab6 |
Hashes for stim-1.14.dev1722326436-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c12eaa98ccf5fbd669871464deb56950c23d30070d243b3ad4c80084e42742bc |
|
MD5 | d241e78224e94964a9b167dbec242369 |
|
BLAKE2b-256 | 89f1558e56d378a9d03801a2ee5cf680a3995dac29dd56c0ba4dd596569a21a6 |
Hashes for stim-1.14.dev1722326436-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01fe28b48262c502298d7c1b4dd5692811b978abb51304b923956120581c9a8d |
|
MD5 | 54ec63202dac95bd4b63fd6a7f8cc598 |
|
BLAKE2b-256 | 7dcdb23b0be726d082bcec4ef5f34980e496290cf84f84b9a9e9981a291561f7 |
Hashes for stim-1.14.dev1722326436-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdeb5cd32ff29e23e919ccaaab97f327684b0355f3f49e1aa5a90804873b842d |
|
MD5 | 9ffe006902f22201d5b0978f44921a5c |
|
BLAKE2b-256 | 4709ce06e340600a97a7728b23921ec6f934cb6e54b8d953070f69054258008b |
Hashes for stim-1.14.dev1722326436-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e29aefbb78ab40995a892fa7a53d0c48242fadb2a800e3a0589b5a376ea0c96e |
|
MD5 | e67f679d451daac1c555480528c64e6e |
|
BLAKE2b-256 | 96260132b7db62ef047935f72101f208eb25747a858dc68e972067855e70087e |