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.dev1710997887-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb8a96336a6bb52f261ba8fabb8f382e4850d84f9dc6793f5d866c6204f08a1 |
|
MD5 | 3cb639efd51c0f8f8d118ce67c43466b |
|
BLAKE2b-256 | 5c6fef6908bb4e0d6e79570c6254924cfe1b50986c7f707ac27dbe0bbbac2938 |
Hashes for stim-1.14.dev1710997887-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f670e27b0d9c50a9b1a2a391125ec3829604ecc0d5f8dde22e8a6ccc3d8a1534 |
|
MD5 | edf3f20acf6bba9ada8208ec927e44de |
|
BLAKE2b-256 | cf8f117aeb71bb7d90db3fec5bde2d29c7999b2355a6301e425092a81f63f79e |
Hashes for stim-1.14.dev1710997887-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f04d3e00ddf98b9b20fd405d585bcdad3cabe52278cfb76160c6c93560c6807f |
|
MD5 | d7e23f591a3a7639985b6ee7bc37c4eb |
|
BLAKE2b-256 | 1008e7ff1b05f866db7c5a5475a1ef8055632a60c1bef3673c99a6150aa5be2d |
Hashes for stim-1.14.dev1710997887-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dc17657d7209f11222ac76a342ecaeb837ceb0eb92d0a13b24b943716a1d905 |
|
MD5 | da8b8ec86ed529c3dfcc6dde30ff48d4 |
|
BLAKE2b-256 | 791acb98dca4246e9a72bae1a6d5eee89b9bbf9be9f6031f02f2df7dc9811150 |
Hashes for stim-1.14.dev1710997887-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fca650215b5f8117ee4a582ca0279a6a062f752b13bac33c8775d72daf32bf0 |
|
MD5 | 677a94f80f2950280b698c3114136aa5 |
|
BLAKE2b-256 | 630230b4c11e42279a73f77c6fefea3ca787dc7bd416615fea4a7113e57e3483 |
Hashes for stim-1.14.dev1710997887-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4df350cae68a46f686d81dbda9087063ae3d42d9992d30627511715abffb50 |
|
MD5 | 4ab4e23f900415741a5528c21733385a |
|
BLAKE2b-256 | 00ee9fe9d0ef7e5f76aefa106bda8ad734d10583ccf947ec66a46342683d8574 |
Hashes for stim-1.14.dev1710997887-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 329bedde6b370ca19f34be8e19f1bd52e4114f2b21a7f13432fe5a0485e9ee2f |
|
MD5 | 404a2fd81a67352f56b6625c59441a12 |
|
BLAKE2b-256 | 1a6797de605d5656c56a3dad373bf1b1d731c16982442be6a57c94cad2396a98 |
Hashes for stim-1.14.dev1710997887-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a439f23133c5e22c9124ede57e34f80ac46dae3de7048ed3a926f116dae64d |
|
MD5 | ba0eaf9d6a5851974b55322f886d784b |
|
BLAKE2b-256 | 6c8670e2865b17cc84d750bd40a4ffedffad4e36acf7f4141cf61439bdf271d3 |
Hashes for stim-1.14.dev1710997887-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06f9c2bfdd98ead9737636cbdd763ca8dac1a43d6405572bd1cab9f9d0ffd956 |
|
MD5 | 39da0d70acfa7676bab7ce8022804697 |
|
BLAKE2b-256 | 60f0559070c36c77f84bb1f2a5073103119c286aafd9a765f1081c73a36ec404 |
Hashes for stim-1.14.dev1710997887-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf91aaa84838ee8c61c4b8af8a505fb11d35dc184c598e5226cee68c08d4cff |
|
MD5 | 421d129ac1cb97b84d1ed4c070464144 |
|
BLAKE2b-256 | 569257994bbc4c718033ba725c32d5bc2a8c7063152a07971f77c83744314efe |
Hashes for stim-1.14.dev1710997887-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec35ed641a50f4b15933c98ce425d7342ef7613645078010902738bf5857ec1 |
|
MD5 | 57d4ea996d27ff4df48a1606984d1c15 |
|
BLAKE2b-256 | 3765fe827f074e24d56840e295dd2284849fd221c1ff685a2971afaff7cf0a2a |
Hashes for stim-1.14.dev1710997887-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5db19447cb98dfbfabd836b3cc854ccfc97eb2f5fff7a054f23721859e723b8b |
|
MD5 | 8e4917318dacd9f32de7a50d1773e628 |
|
BLAKE2b-256 | a7860b63d0def57ee9a25c06ea73bc591ce523d4356b79ea7b4ea7a3b79896bc |
Hashes for stim-1.14.dev1710997887-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65df36493764c6e0bdead25a6302e0b030853d935867cc34fc37ab270f0ed64c |
|
MD5 | 01cfdcd10e95ac58d0e0db3604ac617f |
|
BLAKE2b-256 | 5539ac1bcffef5996ac0a2902ad8eb6566b25456df47e0d82369668f3d7688af |
Hashes for stim-1.14.dev1710997887-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c6cdfd8105247159f58a73dece6639d37ceea6e8c9406be7c8cd9ffd2ac2b06 |
|
MD5 | 2252b8d1209e933bb6246e07fa64b2a8 |
|
BLAKE2b-256 | 301918b9f08be6198a530e491e7c16ce847a5bf84c55bf8b4eeb173221689c9e |
Hashes for stim-1.14.dev1710997887-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd7d87877e7dd97ff3b2d0306ae30c897275ca27ada45b045da01293d5b2f4b |
|
MD5 | c6ebbcd889bdc667f28168a1aa5373e3 |
|
BLAKE2b-256 | 5e823284f7c5cb9780da112701ef20dab8052ccec3f47f81e82894938f55dbee |
Hashes for stim-1.14.dev1710997887-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e25139c70e764e6809fea0cecdb064417d347e5fcf9d0d8b521573727e881f27 |
|
MD5 | 82a984c5960891db7e82c679c4f2a6e9 |
|
BLAKE2b-256 | 01098955702bc46a6b9cdda5f826307cb7516307815e0cd552e3a1741f506eb6 |
Hashes for stim-1.14.dev1710997887-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 352a0e1f873dc6d635dbba712b1dab59132d276f6c14ff64614c4ab55ddca815 |
|
MD5 | a08afe4451269c480dba3e85ffe39865 |
|
BLAKE2b-256 | 8dd14d00ca9d675c349f3ed286a47e9fae1b4e16ea0882de0e7397e690cea8e3 |
Hashes for stim-1.14.dev1710997887-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3852eeaaa020fab573b46cdf611adfe1645e8d1b41e1dfead9bb5504956c4d17 |
|
MD5 | 37c7b6a0b45c5fbd8809cf4db436b4e1 |
|
BLAKE2b-256 | 8f4ac763b45b61076dc2f43cac5d8a85513d77428687613902332792063fab20 |
Hashes for stim-1.14.dev1710997887-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2c9fe1bdbb8f8fcacbff1dc8a6133afe20f18dfbe9b67688cdfd39c2c0a7802 |
|
MD5 | 5bb3ae3b87af5a048b93e68968696c00 |
|
BLAKE2b-256 | 6676c0e1de30b8720fbf60a0c8c5414a73a8f9b908ae1dae5863f4b89cdd5ac9 |
Hashes for stim-1.14.dev1710997887-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 833cc5eb1447778e733d54cff714c50f030c81707c6b53b60c7b261f3240d6e3 |
|
MD5 | c4a77172d31b8e4ef6049f991c334f4b |
|
BLAKE2b-256 | 4d120e1d99831a7b28fba327cdc02f462d174adc9297d407b594176658924024 |
Hashes for stim-1.14.dev1710997887-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f2b2ed6d9eade162d4c77dab1089b14d6e884ff9c23be0558e299056e76fae |
|
MD5 | 3806f9a019078f24683dd019ff0ede81 |
|
BLAKE2b-256 | ae997df8aa07a8a7c54b58407bbd39b21f374b9b91c13965d8e7bf1b01f3ef64 |
Hashes for stim-1.14.dev1710997887-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5624f976d95b5bfff35a1a33f23c1866c1ef2efae1c01dfd2b453e3c275e2160 |
|
MD5 | e59506111efe16a9e6bcb7ac471dc633 |
|
BLAKE2b-256 | 9db4fe04f4a601038b0480850b194b44beca70fbd3abea1a65707a9fd66210c4 |
Hashes for stim-1.14.dev1710997887-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b523507dfcd7a448bab088bfd4d67e84f7e9ecf32e47852d31f8f94356f38ea |
|
MD5 | 052390c074978fd2511e6ebbb7a7a7d6 |
|
BLAKE2b-256 | e7e485f5861b8dbe7e4aab069b973dc422e9075c8b012d11513f810754ed84e2 |
Hashes for stim-1.14.dev1710997887-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b2f7434340f3b0ef3149dbd2721f771c304dfca7617ba9e11c1add83f75c267 |
|
MD5 | 2771025b8acf4ac638aac7a016ae461e |
|
BLAKE2b-256 | b1aafd0c621e9e5ed1fa91280328f2f28d89a4baeed7c9702e93f90999031a00 |
Hashes for stim-1.14.dev1710997887-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dce94f541bf4b63e417a0dedfe8ec6d461bad7d4d045c7b8f18425e96808b25 |
|
MD5 | 697806273200c0be4925aa6b55727dd0 |
|
BLAKE2b-256 | 09f030d973ca4c4c98cd5014d6bd1f5457bfddc974d45d8017d89535ce21261f |
Hashes for stim-1.14.dev1710997887-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9aee4055c345206866165b3d5ac7ac0d0997d3da225a69f220ab5ba49de9fd7 |
|
MD5 | 8465eca18a860feb190e36d40bff8c6f |
|
BLAKE2b-256 | 688416eebe288a86bf2d782b813681019a5dc1df3037820e714bf1d0ff9efaff |
Hashes for stim-1.14.dev1710997887-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d75d8a3830b49899bbe61e98ad64041451b2fded03c375874dbfbb266ef72d12 |
|
MD5 | efe30bb769191c14ba591841741b67ec |
|
BLAKE2b-256 | 17c8a454b937bb5505c6167c43e4f9d954f6e1b2036bd2a5dd838aabd8d54e95 |
Hashes for stim-1.14.dev1710997887-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b762354c1bdbdb4a5aa79258627a5d32efed6811f1fcce769bcfccfb1ade9ef |
|
MD5 | 8669521b77cc7821c7e30d61296cda5e |
|
BLAKE2b-256 | 17faf4a1430859f4173572082611baca899245dfe205cfb158e5b034e59f3d30 |
Hashes for stim-1.14.dev1710997887-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ddaccfddaf6ff3f475ed465a1122866ef18b90c669fbe9907828649745123d |
|
MD5 | 0c49d9b3d4fe1aee57e0741c3a1304f9 |
|
BLAKE2b-256 | fa5ea35e70157f12ccf91978cfb8a6f3e0bf8cad1da4f9ebb6e82fdb88841504 |
Hashes for stim-1.14.dev1710997887-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad7514fac88f6fa2cdf5545ab0d094772f3a18173046a1ba9a22269c30fedd8d |
|
MD5 | a512b026c583ff23e4be61070cd192c5 |
|
BLAKE2b-256 | 0763d000067900a64ceceedbd95a0aa09bfcea2d8a8fa83b0b3f402005496198 |