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.dev1701315447-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff0558245cb9580750755b8e9bade3af23a681969a2dc18e2e3d210a409a8ab6 |
|
MD5 | 5ff96a7ce1da501880dfdae4f9f9c62a |
|
BLAKE2b-256 | 96358e4a5b1e128eaf6ec9cde8e2b86f091b7de5fbb3ed4d50d155f8fcfc5759 |
Hashes for stim-1.13.dev1701315447-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de7aa553f1468259063d481fe32c044f3df556dfe5e74973af6a21e5236e6b87 |
|
MD5 | 15988d619c62781d38f8fc06d972c668 |
|
BLAKE2b-256 | ea6ece67965ba78c8ba749873d97812fffc018987e204b2c9555e98545b746f2 |
Hashes for stim-1.13.dev1701315447-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 968d1c950d45eb2f2fc5bf8be299d31eab2648de60cd5053e46355e445b8661d |
|
MD5 | 7d91ec6827c319821e4b7786909663f8 |
|
BLAKE2b-256 | 1f0f9ab767632e260f38c53712c29704ec44442528b0d21ec2003512f573e6b1 |
Hashes for stim-1.13.dev1701315447-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6666d6144085ab94c27b2ba9d186b2663d5994646c0c19591317582131ac955 |
|
MD5 | c3cf2c79ce55e01b86951d5db38edd56 |
|
BLAKE2b-256 | 18061c380d33f47f767e84847f327d06ba3a2f5f572da7f86341495e034930d2 |
Hashes for stim-1.13.dev1701315447-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88728367dd1f2d4e5f2c7bcb7367313a240613dcad01516bd4f6c188e91dbd1b |
|
MD5 | 3b645fcf0eff7bb12b4d2cd08e3d4637 |
|
BLAKE2b-256 | 0c8a09ecb0a890dc54a36c87a1743527c8e8f372c5d180facbe05b87b784a454 |
Hashes for stim-1.13.dev1701315447-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49898d5f7580f5357214865ad84236f2e36bf018efe60649137183f178936069 |
|
MD5 | 921ab334a0fb4921245a59a68ee545aa |
|
BLAKE2b-256 | d858349648fe8a553e1cc014028c7576c120ddb2b417f37ed978925d17b091e4 |
Hashes for stim-1.13.dev1701315447-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b20cd520a1c82468ef8396fb30556852d438ba8d6c2a788840918f84be80402 |
|
MD5 | 98dc096ca081f7a1fb54ff3d490b517d |
|
BLAKE2b-256 | 720b20a8cd347b3b001060cf3b919a2d3845c8ecda275dd4e9182d254b44e584 |
Hashes for stim-1.13.dev1701315447-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15c1ab8676d8031819c19a75e83e24ad71fc6f6c7d069375b6475da3a55711b8 |
|
MD5 | 9b157e59c84ec7e18d8a6512c51bedf6 |
|
BLAKE2b-256 | 81f0d6b56760bce0ef2dd6bca22e0e4a4f6d807a00cd5e49c98b66c3f561e049 |
Hashes for stim-1.13.dev1701315447-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f6fb0113a5a7622bdb215eb675669e5703895bcbadc854216cfcbd932c2b7fb |
|
MD5 | 54d7943c99b861a8c0aa799da7c0a506 |
|
BLAKE2b-256 | c24d14e385dbfea1f0be550e24cde712895115def66a53e7414b3c162574715c |
Hashes for stim-1.13.dev1701315447-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01d488b8680276a9ec4c5a93de70d6fdae102f5e9bd1e6f18057f600c07e855 |
|
MD5 | a009f88e64ae42fdc85c95d3fce35124 |
|
BLAKE2b-256 | e689d2c39efab35b256f8671ceace0eca7f456dbac63295920e405230f8a071a |
Hashes for stim-1.13.dev1701315447-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e1341d18e21feb9ebf6b0672ef5fb723f62cde48d50f0e07ef603dda1084335 |
|
MD5 | 8961c7f98e0922ecd49812c49fe1a737 |
|
BLAKE2b-256 | 3a65d02a91d4dd069fce6f8a04706031c040d5051b5a1390ff07f63ed064bf88 |
Hashes for stim-1.13.dev1701315447-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a16d0224b6a65b3b2911589e0061b824115149d179d6e9944b76f0f191a2800 |
|
MD5 | 64009b853b830ca91976ddbe04363386 |
|
BLAKE2b-256 | 0035a2cab40b490269d7f70cf2eeb9a15d1d03b1cfc8a83debe1aa41d5d45862 |
Hashes for stim-1.13.dev1701315447-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 991aaee73f5edda2c308788d7462de505eb21549c78a19fab009c6ea71aa3534 |
|
MD5 | e15576d4d1de80629bd01261ab6ec0cb |
|
BLAKE2b-256 | 8208f2a9d45993ea8b23ec36b7c59f7583c3ed31ed56a5fc330bf9e9afb18eae |
Hashes for stim-1.13.dev1701315447-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9931f0f69f79e112b860be8d4aa31657534b82b6e065529645a8a029c3bceb5 |
|
MD5 | d30ac3f0e0c32c0b18e069f77fb56c91 |
|
BLAKE2b-256 | eda69f4c69dab42162ce55af425af6fcce129b3163b8c141657c40e32ab77038 |
Hashes for stim-1.13.dev1701315447-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd84a6545447d958cca4751ad877f9a20f2ce344c8634940d934fe6cd446b227 |
|
MD5 | 0fc9ff0b0f661afb55178d1787a2c4c7 |
|
BLAKE2b-256 | f69f37d6517d0948f910594ad71558ed0ac62da6bbb945fec7eabba865ec068f |
Hashes for stim-1.13.dev1701315447-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caf84f1a42f6f36156ca92a4a7c4713ad8c3d135fbad7bbb542c127d76834995 |
|
MD5 | 7a388dad501ed805c1972ba10a391a7f |
|
BLAKE2b-256 | bb7eb8a113f45f3687a69fb92b78942411eb1ac6b29556dacacb570f53ab2fc8 |
Hashes for stim-1.13.dev1701315447-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae19b64017f6476d0e5bede0226537e848098457b4ea0cf5cf6088e7c95207cf |
|
MD5 | d8fc25d6bee7ebca5a063397748a6de0 |
|
BLAKE2b-256 | 64101d9b5310054e570df723e5c50f0cf8c7731c94d6d5d4501ffecb8c7d8463 |
Hashes for stim-1.13.dev1701315447-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da2d75586827bd0b6f9dc4b06bd9a4b126fb328b9ca9e998ad6a45b7671584bb |
|
MD5 | fd91b350f83e84cf07673e54200573f4 |
|
BLAKE2b-256 | 5004f0ebbc076b54079a3b32d722800414e0770a60ebadd073be89da4375c222 |
Hashes for stim-1.13.dev1701315447-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8802daa0ad67eda4b259565c0bbe4417e2c459cede3de8eb5c1abab3281b68c |
|
MD5 | 61eae068f3fb69dd1f0853e765b4cacd |
|
BLAKE2b-256 | 18b1126d60acc29f8b6037af90b81b3de11c0066f2a931e6e5785aab428cb892 |
Hashes for stim-1.13.dev1701315447-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f34cc942db96a8e71b6f0dd9247d0ea82d1175aaded1e0714e799d204e6bed86 |
|
MD5 | a66282f2848ffd7f3e8e2bfe4ab85341 |
|
BLAKE2b-256 | d3e8d45833fb48d150fae33dc8eef77a441aa66bdbb6ef51cceca2eb9a75c3f3 |
Hashes for stim-1.13.dev1701315447-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d799ff581bbb5ee87339e89eda6c5507efcf8983fa9bf59ae1801a356d579738 |
|
MD5 | 625ee103420a5f7ea82fc8ac7aeef017 |
|
BLAKE2b-256 | e0c2f4e328243c27fb37b39e72e690efe28936b46bb781ba6305c7e85e054caf |
Hashes for stim-1.13.dev1701315447-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0cf569910d86524aa3f6231bc815daf3e24b01b8314d8e7f223c7db39f3cd28 |
|
MD5 | 679588978ffcf335cb41cdb83d522254 |
|
BLAKE2b-256 | 372006f0f301ed8d8fe537e63323e2985a37ae968f9d77e37e35312693ade079 |
Hashes for stim-1.13.dev1701315447-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01f4adee18f3a30c2dfb1f7ec0d8d507d4ff2b03ad538d7fef635d865dcccf54 |
|
MD5 | 0a51d4dcb8be6c5bbb765d3b2b410056 |
|
BLAKE2b-256 | d9452b62c8114a2ae5f246b7d1dbc3361d74cf51bd1eec05263064e500b5b363 |
Hashes for stim-1.13.dev1701315447-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbe824fe74f04a4983a6b1b775ddca9e1cfb69a4163b0136394a359eb7de487 |
|
MD5 | 281a53ba76aa0ef0912d22573169940a |
|
BLAKE2b-256 | 0025882df081047951040f4e3fae0f2844541c3c3dccc6427e1617e905e1e836 |
Hashes for stim-1.13.dev1701315447-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8e9ef1f93ca7d4ca35b20598ceb4a8213e5250436a01efa2968ff066843e6aa |
|
MD5 | 28750babdf61053d84b19695c088715b |
|
BLAKE2b-256 | d96e4fd3e69f7fe3624ebe5c12b333e91fbd1c93f69c7e129b3c34b8990fa333 |
Hashes for stim-1.13.dev1701315447-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfe81b4ef2b7930fb95f16284147cd283c4c7904ae993edd6f259af9188b12c7 |
|
MD5 | ed27439ebf9e957c1f772f92279c8b66 |
|
BLAKE2b-256 | 9e2cb4e05f0f870abd370e59fd2b54f226f923de2c5ab1e189c22495b7fc030f |
Hashes for stim-1.13.dev1701315447-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d3debab80b6abd552b175e1c9e0dca98bc5b6eb9eef30489a840b21c941a72 |
|
MD5 | 9c6a9ab0855a84b9712f330112cadea4 |
|
BLAKE2b-256 | 89bdced7862ace659dfba9532857682a3b4761ed9090bfe95d8174676063d438 |
Hashes for stim-1.13.dev1701315447-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bf3780d862be5d64cbefab8473a47f7acb7cb60ea963187426f6e3905905f17 |
|
MD5 | 66689b0ec9c82ebcfa960a709c28c83d |
|
BLAKE2b-256 | f720de94d56982ac9fa460578fd461e9d0f834bb00bec1d4873c0626fbb4af7f |
Hashes for stim-1.13.dev1701315447-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ee43e8cea4c7d6f390c819a72e2e5e271bf4422c6d1f41a06739b545e50c9d1 |
|
MD5 | 003f126b1ab818aad51a22e57f423bdb |
|
BLAKE2b-256 | 387b919f0ca6e51f6311153413a93dee567feeada12d16f0f1a616e653c60bac |
Hashes for stim-1.13.dev1701315447-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc682bd8a4b27ce9ac7b11290ad146a3490633ae41979c37e8ad5bb98d75defe |
|
MD5 | dfec4a71a40700604d23e59a30afa3e7 |
|
BLAKE2b-256 | c9f1b8fb6e8f137078bd91c9631d279fb70cc41165b91d5c588236daa1620fdb |