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.dev1718079560-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56088d517ca00bf225556caa84ab3b7828cd5ebe5983d1bc7fa423f19d17d209 |
|
MD5 | d0d36afa8dfc52f01acece9963d5262a |
|
BLAKE2b-256 | 9ac8481c75e0a97c112cc1473e15a8f01d1a90ed11d0476bbf3b60568ed08bfa |
Hashes for stim-1.14.dev1718079560-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 501e63992657252ae045df7d1afe9a14c5f154dee246c75e6f19b8783f725b11 |
|
MD5 | 46fcb159d9fe2b1d271864271dadf609 |
|
BLAKE2b-256 | f79cd67c44e592220e23654152ae788f32dd92268d2dcdfe9d3958a4d385f487 |
Hashes for stim-1.14.dev1718079560-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9d603acdf9ef4f6de737c0afff302bba4a44f9e716d97649ada0f72ce7069b |
|
MD5 | 41bfaa7366da8fa4463a7d66d628e774 |
|
BLAKE2b-256 | e0957df41469effa0a50305c53a6423060a8f03d7eca3dd12a36f12a3434923c |
Hashes for stim-1.14.dev1718079560-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fbdee477f67320c442db9700f4485c3ad3fc173e98e7328ffdf44b2942118bb |
|
MD5 | bdfb3e013389b721307a5f9eceda10f8 |
|
BLAKE2b-256 | bd2959ff6dc2162b0d124aa7c213e8c2e8c41f9fa35942abb1b6f2dbcdb938fd |
Hashes for stim-1.14.dev1718079560-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3605e48e604ef6955a2df9a2e50bbfcb6f66e34b2e209d5ffe89e632dff3b5fc |
|
MD5 | 23ce73406c1a98fdc5983a3b266218dd |
|
BLAKE2b-256 | cd9931acb68963c9a574223f372b2dd04661bd62f1e25f43f1d6385c13bb0e66 |
Hashes for stim-1.14.dev1718079560-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bbb3a89ee69b7359f52554dc83d37c936fb01c730f9cfff2c111e2ac4287311 |
|
MD5 | b10f3aabd7a706249ad6bbe92ed5cb64 |
|
BLAKE2b-256 | 2c0c49360aa7c9f0e21f70ef9382b24ae7e6efd7c5db257ab7223a6db8e922e8 |
Hashes for stim-1.14.dev1718079560-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c026ef6a3390d05417908f8f83d872221dc544005bb766211ee39fd1b39d19d |
|
MD5 | 8eef56b5e1025b7ebe408f21785cc117 |
|
BLAKE2b-256 | 11200abc94986a271bd6de870bea0ca106d5e4dd3132e9ae1035f7510d0a1499 |
Hashes for stim-1.14.dev1718079560-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91918cbe040fe19ea29ed57562bd0ef11461f0c33cb74461dd1b4c14cb501e0c |
|
MD5 | 4809691bd3975b64220f9c4eb65ebef7 |
|
BLAKE2b-256 | abe2dd326d97342470ff9262b3efb48b0864117dcb0268f642575e5a4c056348 |
Hashes for stim-1.14.dev1718079560-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d03a33ff0ce8ab2e121c40307cccb661d823d4afb93584b9127349dc2f349937 |
|
MD5 | 3da63dcddbbb007db517622aa0167d4d |
|
BLAKE2b-256 | ae22c327a3ca05b80353b9112ab4fb48f64d6e8f35381339217c7a19f1a3bf1e |
Hashes for stim-1.14.dev1718079560-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09d58a502607aeca162e6865ee3f8f20b91da7b480761fffcf01293f7404caa8 |
|
MD5 | 40f3c7d0387207a59a9965460316a07a |
|
BLAKE2b-256 | 3507278c77192c524fc8e0b6d9284e5f193f1e2c46f28f38e450cda75bb0f26b |
Hashes for stim-1.14.dev1718079560-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d96e0e10e78ed47f34881a3ceb2240aaec88d33ba4c50781b4901645fb617998 |
|
MD5 | 8b525e19fd5fd90efa85ec7f2983b2c0 |
|
BLAKE2b-256 | 0044498895b52cb7a114bf230b0513ac54bc92457c5b910a0552a970bb927dd3 |
Hashes for stim-1.14.dev1718079560-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1a8d864125d3e2b7ce24ba3b2ea04ca97d020300b1bc6aa8c70110af5b4dcf5 |
|
MD5 | 140ae1c604fa23dd5c84294703ec4e64 |
|
BLAKE2b-256 | 6d4818c8acfb7bf2560cd814d6338b0c4465cd23f306d9556bcd6b1f4ef51d30 |
Hashes for stim-1.14.dev1718079560-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8ef6e44751a597f65e561693cc096f148751ce63fbf4e67e520c25fba9f05ef |
|
MD5 | d8654660fce20d5c613cffe4a13b80e8 |
|
BLAKE2b-256 | df51461b59a8fd4c9c201bc53178abb9550ecb3b245b6f2b7fe5cf8f47de4cba |
Hashes for stim-1.14.dev1718079560-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0161edf71ad5416f86a0f5f0d2112c38feeb5aae91e5487e0ee9f0994009831 |
|
MD5 | e86f4c3ead94d98e522074527eb76278 |
|
BLAKE2b-256 | 47d64f1d8d332296e46beed384b488b820170e2cb56e0ab9a754bda58249666f |
Hashes for stim-1.14.dev1718079560-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c30b1310e2594a5d63b24a46cde780568ca635486d855513f0482117560c9d01 |
|
MD5 | 0c8af3a9f6f63d9d5eceb2892ba225d6 |
|
BLAKE2b-256 | 406144d7b8ecc2998145cfc565b7ac0f4959165a6b8f3dc49b25c73c1d5f99f5 |
Hashes for stim-1.14.dev1718079560-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7d0f801bcc9267a62847824651ff88bf5fc8caa2031771eace7840ed209f334 |
|
MD5 | 29d2fc5dab2cc2b95f0be79ba4641e90 |
|
BLAKE2b-256 | bf9710b685be2624e2afc96621cdcb9a8ddf5dbc68bb31ef767a7a201d727828 |
Hashes for stim-1.14.dev1718079560-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1258f8549c5ba39a9ba8d9c9bf7193032d78c2709c296482951254af887fce27 |
|
MD5 | 45dc77e1a9e0ebd4d35a72f1394846f5 |
|
BLAKE2b-256 | e411ebfb560bfa52128e4e6799ef67d00f2930daf66901345b359e596c6c9b9d |
Hashes for stim-1.14.dev1718079560-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7286a5e9f0e9141c876907c3e5aa7dee9754c8b2335851282157b641ea3d65a8 |
|
MD5 | 5a2d0525a77176b85645b24a0f20e84e |
|
BLAKE2b-256 | 50ec37deacbdb6d416e4f9f2c509938cc181c433b0c8dc904442e621921c4085 |
Hashes for stim-1.14.dev1718079560-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b40c0f76cb4f46b1d6067847a8cf3c4f8fe51bd88f12609e7a4fd128583c40c |
|
MD5 | 9a201e2f3d7011eddea39c82eeb7b048 |
|
BLAKE2b-256 | b0b0c61b4931d04dd183778ae52071cb91fc41580035f13f2202d4d7e301ecb9 |
Hashes for stim-1.14.dev1718079560-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 930213195804d9e7a45d068e4e505eda2206125764cfcbac9e4dfdd6277c3240 |
|
MD5 | 72d5e50cae0dc79fe2c26430b24411e6 |
|
BLAKE2b-256 | 1b7030a282cc2766206727d4c448192742f03145fbfef14621d0cecbe423b5da |
Hashes for stim-1.14.dev1718079560-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeaf6ae996301ba41ccb587316f96bfce445948f5cfa7c64cf95781ff04767bf |
|
MD5 | 7fe5bb9a37244fbd920ea3ee6573959e |
|
BLAKE2b-256 | f9d981885fd635f1058838f0eaefa113feaf9a9d429d08e20a165f62cc4bcd3f |
Hashes for stim-1.14.dev1718079560-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bbccb967e209cf01fe60975455329d14ab197130a1d982e9ae9d86eb2db2f14 |
|
MD5 | 5fdd2bb261dddaa6063d9bb93c5d555d |
|
BLAKE2b-256 | 66f78dec14fa40e0cf1f4e25a0b4dc9d78082a9d286b760c4d924d697db0cba1 |
Hashes for stim-1.14.dev1718079560-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c65914ed9e4d23f5a9154d3e819a0cd68d57ed934886ce0fac49a803f0208cb2 |
|
MD5 | ac8a81ddf0f3d573281edaae9d0b43ff |
|
BLAKE2b-256 | 985771ff6c455c02bf5f8ad023fa8aa2af4ff2725dac12e8c0b2c0561a05b0e0 |
Hashes for stim-1.14.dev1718079560-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21cca1c68f8cbbbdcd78603e99225e3cfc9e0b14977f7cad4ca4555368648a26 |
|
MD5 | 8ea2f5089a6091f9201262fddac1e8ce |
|
BLAKE2b-256 | 9eb86e9e0bb0007b8bccb7a7c8cb3b047e6bc4c415248dcb8531defc3176ec7b |
Hashes for stim-1.14.dev1718079560-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 944b1e8b72fb1ab24e446ee1c683509dd5fdcab4ec1f4f79b1395c132d44aff0 |
|
MD5 | 11bc65914309259fd9c82295e97a1a1e |
|
BLAKE2b-256 | b63e4e7fc3f630fbf59e3e238553b8fc1eba5e4716a9959d66797f5789994563 |
Hashes for stim-1.14.dev1718079560-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c43cc1dc7bd521305ebc5244e854ae84c7e58f7250d43af388423221d02ca6d |
|
MD5 | 9eaedc090a8dd46777fc2673a3bbe455 |
|
BLAKE2b-256 | 33fc5eea54e24f3805f49937e6af38bcc9f4c60eaf02c8aabc4e8d81191ee0b4 |
Hashes for stim-1.14.dev1718079560-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75d93dea590292166431e169b707e3b3f130cb6d885cd37d30faff282458f24e |
|
MD5 | cc7ea81ddecc46af3a96c7ec2c714ad8 |
|
BLAKE2b-256 | 845a4965f3c2f603326a5a710ffff842b07fc8366fb50dbd6c7a6cc81ac48845 |
Hashes for stim-1.14.dev1718079560-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8232266ed32454301f8703cb758baea1f2ec7d48b7383a9eb6f2332ddca8a9e2 |
|
MD5 | 76acfabfd00052b661535379d59655cd |
|
BLAKE2b-256 | d22a59689fd08f10f42af67a145c74b5f1acd176ed3f594574c7e6b8c4796690 |
Hashes for stim-1.14.dev1718079560-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538fa209a0b0f593c9373744eeb528079d33b686815f1fa3279211a85fa2a130 |
|
MD5 | 9383a724dcf928fc4aab285fdb28573b |
|
BLAKE2b-256 | 4e2dc0e31e79188aa02f25222aa482840c27cec693a4e47cd833adda8fa2c126 |
Hashes for stim-1.14.dev1718079560-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 398a362948b63edc418fb35bb84394d1e411b13fa68cf72359ca63ca4615d0bd |
|
MD5 | 0d214d63b960a53d8538af24c12b631c |
|
BLAKE2b-256 | 1e98f8ba61d4200e2407f5a5e472547cb66d2ff6417a55fe834784b205bb0f69 |