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.13.dev1710218260-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb30288638c07012809776994153688a6d1736622ead23e911dbbe4be73928a |
|
MD5 | f329d4b3d70d2b5b33b8bebc0c66e818 |
|
BLAKE2b-256 | a620fd25710da2bd18f7019d60d788a0f162f961000c50b3d06f4e27ed9018c3 |
Hashes for stim-1.13.dev1710218260-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8075a228b28fa93d67e5a739cd9c6011714363600d6b111b845b4f51430035ae |
|
MD5 | 2fe6ffd968ab77932b186354d5a8d7f4 |
|
BLAKE2b-256 | 8dac7729c7c486cc66288eabeb9bc91f5712b5c82c0c71ad5df622816e40462a |
Hashes for stim-1.13.dev1710218260-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b76a54f4548e39b2f8c741d33f1bdea49e49a9e5c3e999c015b2218a75b7eff6 |
|
MD5 | ba22c8c8152a4ee19b0b2fc96bcf4ec6 |
|
BLAKE2b-256 | aaf7599292c1e6585ed8dac5ecf356731cbe96d3f9ec7f557f4e5fd5b481c6c7 |
Hashes for stim-1.13.dev1710218260-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 920f7463a480f86fe70efec9476a77278e3bd9c6a1176b2496cc4d9df6134cc1 |
|
MD5 | 58f8d1cb71139ad0e568082ffb04839f |
|
BLAKE2b-256 | ddd734dbb4eae48ef05d5cddc16db101ec9f6b7d4d30a48343bb906088ecc9d4 |
Hashes for stim-1.13.dev1710218260-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c401c9ff716e4b26db62cb4c0b21e6e00c1a7f757f928b19afdb2e3b554cdf01 |
|
MD5 | 9eea1c7c4bec13b40afc85e959bdf840 |
|
BLAKE2b-256 | c7f7db76ddf2afeedf233e86f978ab644ad0e8cd16a0048ecfd01502b2dac34f |
Hashes for stim-1.13.dev1710218260-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ba68e09cbbcf5b869fca2f4d2a566f72de2e48ffdaf43fc330e34688028215 |
|
MD5 | 3ad1a5c090ad9d8b5844720320d0a79f |
|
BLAKE2b-256 | 298e7f1f036610e6ed8058885d8b1adb88d8f94436b3d5d0b561629946078282 |
Hashes for stim-1.13.dev1710218260-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14675a1fc60ebc7cb430e2c68b8accb42152e035fd34fd68db5c5501dafe4f1e |
|
MD5 | f4b1417f735ed4226b05a85b2a99c05a |
|
BLAKE2b-256 | 298ee38be837b9713a5fc6df670743ba68b2d0315c871c7c5c1c65820babfaf0 |
Hashes for stim-1.13.dev1710218260-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d25f9ca65cdf226bec8b297eb0ea192ff7e61e6a50556c8925d57b6e28d9a6fc |
|
MD5 | 147d2e8ad6ec7a076cdcce591a0710fe |
|
BLAKE2b-256 | 8a466b9fe907b53646c9e458c1f3309a261bc8c8f3cfb9ddf2a735a1641374d1 |
Hashes for stim-1.13.dev1710218260-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 626c58ead9a4c1c4cd5f4a2f1aceff33bdd3cfbf3894862aa0f0dcbc8c3606fa |
|
MD5 | 7bf49afc8e64e38429d0a936bb375bbf |
|
BLAKE2b-256 | ab16f644078b3a770baeff7adafeee251e8bf878f297c418b2b982b1bbb4792e |
Hashes for stim-1.13.dev1710218260-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55b9b282a52e8f9d9b7a08822280644414f6152bd20b16e2eaf80285d520eabc |
|
MD5 | 949ef23516578f571400461bf31ae3f0 |
|
BLAKE2b-256 | 6360529854688e94e8bd4407d001b640ac2814491ba395438f20febfa12b96ab |
Hashes for stim-1.13.dev1710218260-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eda86219981b9d6e2c4daec897279c0d79c3728827367d58bc94183d3c16405 |
|
MD5 | a34d17dfc3c5306d08d7cc2e36a69f6f |
|
BLAKE2b-256 | 34f86992c84e5448eef2214472940bd9bc39768452bc0008d2a92643cf6efc04 |
Hashes for stim-1.13.dev1710218260-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eee2572ffb68cc5f02d35f14229f86aba80604f81669d1f4dc2e1a45946280c |
|
MD5 | 5c222673351c959e4a49973e652ea821 |
|
BLAKE2b-256 | 68117bf3a742d8dedb625be8de6f7a597f017b89c143329e1a961c2274ed88b7 |
Hashes for stim-1.13.dev1710218260-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6515ff7e1c8cf42d8af74aa993e4dca8c852046c3f0daceade347ac18484e29a |
|
MD5 | dc402c351eebcae5ca8c128af6c2b418 |
|
BLAKE2b-256 | 0d42e361574e1bea48813e062a0aa3656c5359d28167ec389e93d7f139de8aa6 |
Hashes for stim-1.13.dev1710218260-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d94f006b1ad5c1dd1723e0c8818699db3a5d555ca30ab34faf878cca6818cca |
|
MD5 | da341a335db8c4960190d7a26170f28c |
|
BLAKE2b-256 | dccad6a64ebc30f433bb1a8b2672c56548b61623633de6e8640455e0d97e3213 |
Hashes for stim-1.13.dev1710218260-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a9718fec871f03dcaa6ab6ce8e2a956528f325420601b946f49c755b755b23 |
|
MD5 | 811eeec6b89ab68e8ce02a3c4b9c514b |
|
BLAKE2b-256 | 4bee74457ae03efbcde945f2c83ca260eb6a86ab86904a4818180a45b1a305b0 |
Hashes for stim-1.13.dev1710218260-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e89c7a77ec6565840a34fb51ba177004e5514cd96bd570c6d51710fc6666f76f |
|
MD5 | 1846a63e1a1a35335349aef0b48a0a6f |
|
BLAKE2b-256 | 80c0d9da7e2412918a001ac726ac9b09dc44cd47c33918adb793e1f8c950c7a7 |
Hashes for stim-1.13.dev1710218260-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34b0d48904f472a3de75d3228072b7fe16f46d4ac317a1b9f8e19c47fc863fd |
|
MD5 | 73bd5cb0b1eca599ccf64d78437713f3 |
|
BLAKE2b-256 | 017b3a5f87beaeb0ef9a2690ddc1beeebe76b5f7ebf83c26a680ea1152c0bc1f |
Hashes for stim-1.13.dev1710218260-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8b623d7417791a8d419c114c65c0727e295304bdf3a1944da1a9824bb6de04 |
|
MD5 | e8102b161a6ece63b0ce8d64048d647b |
|
BLAKE2b-256 | 335eda6fc0725e3ae0d36731678bf5ecfef0d53ef35e4d2ab36fb17bfcf4098a |
Hashes for stim-1.13.dev1710218260-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3cd51d09fd19ff6cc03b41dd384ce276520dbf737cb474f4f6dbf9b65be686b |
|
MD5 | 8e66fb4d55a40ea8c0c05c273d0e978b |
|
BLAKE2b-256 | 70067d6b3aa6e08c9fb4dc392b259ba1696ae77c7b584fe1e36186d85667eb19 |
Hashes for stim-1.13.dev1710218260-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d093fed9843d9bb5a9d87e1a4c0d99ddf097321c185e0a9006ce5a91071e753 |
|
MD5 | fc3bb6817d4f8b162bb0a546257b2dc1 |
|
BLAKE2b-256 | 10ea53bbd666472caf7106c32cea0a7bbf4edeedcb735629ffdeff2d9f16acc4 |
Hashes for stim-1.13.dev1710218260-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec8adb8028711f6e12e23390ef59ae41d9967cf60d78a29e2265fe2ba3db7583 |
|
MD5 | f70a2f600059367e459faef5eb92d3f4 |
|
BLAKE2b-256 | eb045218c2879a729aa204f84fc14bcd4029cb3455e1f0d10e913702806b0100 |
Hashes for stim-1.13.dev1710218260-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a92dd4c67fe0b76f6ea4ea765926f56584481505c6b5cb4f03258b3fd004409 |
|
MD5 | b37a0e7e9c1896ec6d42c9cee5056dc7 |
|
BLAKE2b-256 | df7ebdf925cc4e9692120812c288777489f24efe89d8ae2b25d93fc8c77f1c62 |
Hashes for stim-1.13.dev1710218260-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e613c2578e99fc392a8926806c8c4433783402c64503bdad4fae0fad040426a |
|
MD5 | 1fe11ac1f50ffe795a5741af346690c7 |
|
BLAKE2b-256 | 3f1fd58add3b1fa348838dd5ffe9e85b0d33e2bada24c4548b87b628ba704c6c |
Hashes for stim-1.13.dev1710218260-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44d6b83ce1c1a477281e8c49e6ab6df7f56af78c15b53e2057057560fe016497 |
|
MD5 | 53749632ee1b137e380a4877dc8e5350 |
|
BLAKE2b-256 | 904134067b7d4b42f624af335997ff57a86504924412eed0b5984144a7a5ac6b |
Hashes for stim-1.13.dev1710218260-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36ac093891801800db5e29116a53e81d1f6487c2bb2e0d89a15990e333db56d7 |
|
MD5 | 65041f2b2ff06f5602c357e46aa8b435 |
|
BLAKE2b-256 | 103958f7cdcb5fe363bbc3d5d730bd095182d99c9f4a4f411b21f1ec6c7df781 |
Hashes for stim-1.13.dev1710218260-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afa7dd2ea77880b388f48539050f0d6984da219804cab456008d13d1dd4d0bdc |
|
MD5 | 602113090a4fa2d2d79a6bd9c0046867 |
|
BLAKE2b-256 | 31f86470a2ebc3f14b9e9958fef06a85db4d32d0c73b33d02f244bcd356e4e32 |
Hashes for stim-1.13.dev1710218260-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d016e3b737b01cd0f88f9d4ae9c78ed76b4d13a22ff823d42c0193c05b46b533 |
|
MD5 | 3a3efe81a39c801af242c12282d3f9d2 |
|
BLAKE2b-256 | de5e522703ea9693a6ae1913930bcfee29109b89b60d69dca2b49dada472286f |
Hashes for stim-1.13.dev1710218260-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6ac79268fa9a2d5d4e6117e1ad1bf150315116395c07a176e813856c19dc69 |
|
MD5 | 9af4b96df29463a82335d47ddc5cc5f2 |
|
BLAKE2b-256 | c0d2f96edfb3038dac42dc3e6328b61cc2dfd8d737eb96a508144f7ca5ea1610 |
Hashes for stim-1.13.dev1710218260-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a8af1d7ed1e9b825a1b0c1c5ff32ab143d18cbed49e675589bb955481b3e892 |
|
MD5 | 75081070952cd75a1337c28ab6d16c4d |
|
BLAKE2b-256 | 5cc9c9fe169a9a94634bf2ed5f763578bf94a5640399b759bcee2e30ea96f452 |
Hashes for stim-1.13.dev1710218260-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1faa952e024eb00c19699d0d9a62db03e459837c3c2674a304ce4a23fd9700a1 |
|
MD5 | 74b95670555d214f0e4b0f60cbaf568c |
|
BLAKE2b-256 | ccebe41e9ece1f1344645a5ad72251b4fae0c66d9436c489d46d23c7b59fe194 |