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.dev1722854600-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9cf561afc71266bbf464bec7f5297eaac76d8f60939c32072b805be5291ff77 |
|
MD5 | a69aa4b475576513ebd74f0b0620c3d8 |
|
BLAKE2b-256 | acf3aefc750cfb6aee3c93d0f8b80daa607d5f3c3fc0193bbdc9ac70c3d7a361 |
Hashes for stim-1.14.dev1722854600-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba94d3b351ad64282bea47de42375db8d243a0bc9ba4d40bc41042c4034b920f |
|
MD5 | 37df1357985bbb64e79cff58a38de8ab |
|
BLAKE2b-256 | 8ada4922ec8e8aef3f2f55b738fe761e22da28c4e43a3f7db857fa69ce9e34b0 |
Hashes for stim-1.14.dev1722854600-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4f58a589058d694e9983eee5fff033da74244459ce1e96e03625820b02d6dc5 |
|
MD5 | 1430b91126dc7c28ec5c5015e9beb074 |
|
BLAKE2b-256 | f3fa7cb34b3e2a326a324ca0864630656891d667a1c35f03f16bfc7bcb47f975 |
Hashes for stim-1.14.dev1722854600-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9bb66cbf2e0d462f57e983936d514216be498a1ac0e5e6dc59d3b34f0b2f3dd |
|
MD5 | a6a5a7c249ac6eaecbbb7a80e6511ba1 |
|
BLAKE2b-256 | 433e2782cd1522d5e831ebd50727afee838e4b33e136990ac8fa5ad858fd362d |
Hashes for stim-1.14.dev1722854600-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4bcd04cf6471c4a0a0ce044f0960c315e2d466c49fb2baf3c379a1881fa4c52 |
|
MD5 | 00b73da0fc65d45aad4d60379dfbd9fd |
|
BLAKE2b-256 | 3000f86fdceec58a34acc1fd706aa31ec7afae367ed714a43b6383d554d4c525 |
Hashes for stim-1.14.dev1722854600-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa9a0362bc3005d22ab651816c43fd1dfaff04369ff769caa68af116bdf26997 |
|
MD5 | 2b0657913abb8b7dc8f95cc4fe3f92e5 |
|
BLAKE2b-256 | ab9fbcd58f55637f3daca888e1b08aa96219a605e33eba922f89f1d60906b910 |
Hashes for stim-1.14.dev1722854600-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca8cc18e10c50cfc525c408563ff8711532546f7bbfd24a1bffe8bf595829b8 |
|
MD5 | c3d826f021eecfb407335b1d8c75e7ef |
|
BLAKE2b-256 | 4e501ce9ecef3be8c4bb0f80f5b26417423301e5f2bb23b8fed4d2a10006aa8a |
Hashes for stim-1.14.dev1722854600-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112ee0c4ac6260aaa251154f65f346c2f7e40946da167cd67b4b0ceca11084c5 |
|
MD5 | ae1dc88d68adfa8543281f88a6308d66 |
|
BLAKE2b-256 | 7eb1f64ae4d3ac7f81afb24cd26ae7c41da7eaadcea8de38b95a3c2baa4fbe42 |
Hashes for stim-1.14.dev1722854600-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7ec927e89f99052e639b8089123ebdee29c55c5059cd81ee5555115657219a9 |
|
MD5 | cb3f1eb284e2b09cfce44f3dd124aa0b |
|
BLAKE2b-256 | 6f96ebc7f4e4fa588977fdbef030cbc8a95b40737342265b7920b1e51f2f0d7d |
Hashes for stim-1.14.dev1722854600-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10c90e53cfb578964640f4f83f45c5da65486486decd6951fe0c9d670370613d |
|
MD5 | 4f49293f89f5ba77fcb963201493f5d2 |
|
BLAKE2b-256 | 78d354c918ae7b8ecb5fe4b8ddf091a7a88e5dd3543f04002c66c2916bee93f5 |
Hashes for stim-1.14.dev1722854600-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7bc72165c050a039d1b8a6c0fde3707a0b5833749bb4d43cf885fab3635656 |
|
MD5 | e05dc9d2f9f1d800804eb7fbdd2faf8a |
|
BLAKE2b-256 | acb6c2f92be06caa0fd3695285f4e14fba11a8ec9da92a020eca6f260eec1687 |
Hashes for stim-1.14.dev1722854600-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75c97e45440d2ae2028e4fb133f59a98827733aa6365cf852191930c2d5d8f3c |
|
MD5 | e2b04b08d58f63752d959757f05ff566 |
|
BLAKE2b-256 | 13cd10981cd58a41d245b1ef8632e6b7a099942053be7619c7b3d56cddf84310 |
Hashes for stim-1.14.dev1722854600-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2535f5defa798d9587bbcc2180c3d067a353ce22e929b51dd7f144b6818e7e4b |
|
MD5 | 60fcb84803603e24301cdc9d588dc7df |
|
BLAKE2b-256 | bb93f5586db2a26e35e588f3e6a25fcd0ac888a60f6cbb2f53145aa2c031b483 |
Hashes for stim-1.14.dev1722854600-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c17af8282a07d562014827e9290e52ce242e916893098e0c77cb5ca960728718 |
|
MD5 | 28f121e6c8b67b2187a0c44e712b826c |
|
BLAKE2b-256 | 4814e8ef3569cbec66ba65082de74313716df974922ce5e3493cbdd91015f056 |
Hashes for stim-1.14.dev1722854600-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30809b71c66ac1e219dadb01c796c1035de0903890a2a6bdf7a7c40ee58513f3 |
|
MD5 | f4b201e6e2880223099e3ca34bc425f1 |
|
BLAKE2b-256 | 0b29d550d92126d057ddf1aad496f1932602d1e273b35560d74816d5b8a7bb43 |
Hashes for stim-1.14.dev1722854600-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b144190a8c38e2c53f43f7e6ed5552d436644b055640759b4d5ef11306938f8 |
|
MD5 | 04a247b577cd851a5e072115697950fc |
|
BLAKE2b-256 | 45600befa4ef607a14ca344ef6fce19315b6611764f01e8db54f7c0fcdb491fb |
Hashes for stim-1.14.dev1722854600-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14498ffa77fb28b639e5c02b8ae16f707f0b1163e0ff92a83de5c14f2ff713c4 |
|
MD5 | a6523d959fe4812817031ecfd2775093 |
|
BLAKE2b-256 | 137b61e8c881b1953450fa36189faf51b855a1aee72164e9e8e5d2f9a5609c3f |
Hashes for stim-1.14.dev1722854600-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 666279e7f9ab5d97eb7008cd1feed751da847af664936a5f9d26c0f0aab4c6b3 |
|
MD5 | e48b409586a3ed0298d66058d22c1237 |
|
BLAKE2b-256 | 8ca3460def93825bfc2f20732be3254c601bb0a1435af337ab679a23b06222d9 |
Hashes for stim-1.14.dev1722854600-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f67273a09eba0e14b3266abdeff1a8729e61ba4a0b75eff47d337204a7cd309 |
|
MD5 | 10347f6a780a80a437a28a0ac7114057 |
|
BLAKE2b-256 | 8c50022f1a17721fbcc352bdafa8f80b911fab6843e7a807a2f636cf643f609d |
Hashes for stim-1.14.dev1722854600-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 386a38cd86e5c0de06bdefb94c32b460bab5490ba7ffb8ef45b4e3865d1f31bf |
|
MD5 | 756ad59839ac1c0b7e9d4b1da25d7761 |
|
BLAKE2b-256 | e9365934bfee772faa16c2384559dd26fa021dcffbe78ce7f1c539c4a4dce8d5 |
Hashes for stim-1.14.dev1722854600-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5db09a22678801ae218451b3430b500e5d843a9193ffc189e2adf6e462b2f391 |
|
MD5 | 1506b05db24a3fa15641c54f0396b10b |
|
BLAKE2b-256 | 925ae7365c9b23bb880e507c7865ad958ad28d0620919d70c445858c30643884 |
Hashes for stim-1.14.dev1722854600-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84cb47e2ed8c2c6a1c4069705d1638cab9d24638a6a06d44a878f501601d330d |
|
MD5 | b7881ba0287a36f35f9dff7ff2d69eeb |
|
BLAKE2b-256 | a275a6e1b70c52a4693cd3ba7ce0a1d4cc34223b2ea7f3f0046f6b37139176d0 |
Hashes for stim-1.14.dev1722854600-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e4bcbb9e814155c5636b16a2453867ab9b26691861da9f4569df4a5a050ab7a |
|
MD5 | 3667b7903d75d570a7ef451d380e9cbe |
|
BLAKE2b-256 | 8f11c3f4ce139497048f69ecf56ac7b4dd6579dff41a1cb5e590541f36d0b0f0 |
Hashes for stim-1.14.dev1722854600-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ce57326cdfc06117310df5ac4beb5777cad0538ebf6e68b50366b1cad89cc56 |
|
MD5 | 2124eb4bbc32f3ce208ca237687ed634 |
|
BLAKE2b-256 | f133bf798a9238ee2fbaed70f15b7aa4d8c51ce9df3c38ff050148c4af37106d |
Hashes for stim-1.14.dev1722854600-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 197b890ca571e592e479b1323dd0a71bcefe3a4198d173871c86e482e707cb1e |
|
MD5 | 6cb857bd1ccd62215ca2c2d206231f97 |
|
BLAKE2b-256 | 617f2defaa8f4d93ddfa8e580ec38044126ee3dec5fa72bdc846587ffbebc7f7 |
Hashes for stim-1.14.dev1722854600-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7581dffddcb149e0b308bc707c4b3a22e98eb040740ebfbf7a486fc337ddc29a |
|
MD5 | 7e36f005e5e78e95a07ee9b14df4f64c |
|
BLAKE2b-256 | 43164d4b12710efbdccb7d81dce65d1eb0515a97eaee969a10a03b977a47ef5c |
Hashes for stim-1.14.dev1722854600-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9443e039abba966b21d9081f50b0a3275f8b6063f63ab811dac30f4a5358c93f |
|
MD5 | 372a60b6fb016bda7c5af11e9f04112d |
|
BLAKE2b-256 | 8c08badedbc8dd5cb527ca3d075d62273dfe6dc0fc859da52ebcb392d226371f |
Hashes for stim-1.14.dev1722854600-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8deeb3b5355eed9cfc2d48858c91723cee6111b5e4f6fde00514c9453ad48a54 |
|
MD5 | 43c48b4773da378fb02ba04393245ed3 |
|
BLAKE2b-256 | a7edc87f9891f3887ac92f6d1d9430850611359c4393eb60b2b64038a66131b6 |
Hashes for stim-1.14.dev1722854600-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17e1fc74563f0b03bf9cccf20235dea7ed172d5636ac30f92c23756b279b07f4 |
|
MD5 | 1d8b1c5ae2e7df63ebc5d2164a36cf75 |
|
BLAKE2b-256 | 2bf071609186924c998e387a197054a2238319c1b48942657b06ad6480f09b29 |
Hashes for stim-1.14.dev1722854600-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1368ec93aca81af502f9b712e6d36dc998dd9126685d64773d5b3050a20bb7a5 |
|
MD5 | f378e5492813bd388c16dea8c9bab4c2 |
|
BLAKE2b-256 | 75b97d4a43e97661d2cebd2b6e70146f6754db35f57fb135945c006342de1499 |