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.12.dev1692153870-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdbe486c2af470a63388c079e262017c961f9bfc475376419871547b41c4cb41 |
|
MD5 | 0867cbf2cbaab714393c58c37bb0fe43 |
|
BLAKE2b-256 | 4592fe027bbf6d0dc3f3e2e898430eacb2229346597862142d8f31ac5ecc67b2 |
Hashes for stim-1.12.dev1692153870-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c848e26c71b37a377066578a6ba7e83ac71b66921a75800584d13f35afecf94 |
|
MD5 | c09cc34df068a50e0d883ec6d48d6062 |
|
BLAKE2b-256 | 89226684f0fe9e8ad1df7decba268ceb59c63525f66c9b7ee386009679bb7a54 |
Hashes for stim-1.12.dev1692153870-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84d3c504a957ad4a0fb65cef7d894442b7ca9a6069311d77d675ded5fb48be82 |
|
MD5 | e61de755c2309d6cb45a0db4f9a7d081 |
|
BLAKE2b-256 | bc8e66e31d0c9e8e50d2dc591cf586c3ad59672cba03d69187acae6e8d83a6da |
Hashes for stim-1.12.dev1692153870-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f50e9afa67eb9d5a6cd0b17e2f02bc00934fc6f07d997ed618ea7869b8edace |
|
MD5 | 0a82e40e74bd62b14ab2f5645af309a7 |
|
BLAKE2b-256 | 8c7fb57786c49889dc20cc36d108237ec0ab20ca5800b50922d3edab12eff52a |
Hashes for stim-1.12.dev1692153870-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c57f6cc120d933acd882855030e83b31c4eec105484a28c51728796924a97f7 |
|
MD5 | 122fc7c092f1184ea7fcbc24a6ac3de2 |
|
BLAKE2b-256 | d3f9e7c52ca923a3fa73b2ee1608d1b8540ab5deea4135b72b488339841da784 |
Hashes for stim-1.12.dev1692153870-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7954a1c890dd9329b7216ac568e9b37503dcb08d47a0898cdd0e82fb9cad80b3 |
|
MD5 | dc53e8adc89b71bcf837614f8e6c627e |
|
BLAKE2b-256 | 87bb3c0a5d0f1e624fbaacab5ae05d696b90f77dacb300f3aa556b30afc5f1cd |
Hashes for stim-1.12.dev1692153870-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b0eb78661bccd9beb233c569e27729f8bf213a4f34b0eed852a090d56ac08b2 |
|
MD5 | 37e935fcebcef65d0f304d002d04d044 |
|
BLAKE2b-256 | 27376f040b1e2c0c3a668bd317959c834a7502fa5665f50c424e9352c6ed9dde |
Hashes for stim-1.12.dev1692153870-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50b4335fea341b7066feb345215a3128ae1739cad699a2744ddd02973d18f0d |
|
MD5 | 423e4fc0b1c32965d5d1c296e50bc447 |
|
BLAKE2b-256 | 158c665d2343ec333ca2232ee9764b00db86cc0d7856db0194aa0e06c70f98c9 |
Hashes for stim-1.12.dev1692153870-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45452be4d5a98fffdd1a788dcd11e4f82398aaafe95626cebdee9846841de25c |
|
MD5 | 7824fbe0b552dacfe0df25ed4c335643 |
|
BLAKE2b-256 | d2cd42379eb6de1f53f7088cbe1044aa407a39da610ae3902f0f53fab324844a |
Hashes for stim-1.12.dev1692153870-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43eddfefb0f14f52a41cfe780d8b24ca2336b7fda144f9774620ab2867097376 |
|
MD5 | 4f1768923e2cd63024a2183942ab96bf |
|
BLAKE2b-256 | 8b0c1b907064dbb686e4f9d25e27392c1fdd1452938a3540d376103c55e0708c |
Hashes for stim-1.12.dev1692153870-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aa49803a608664859948c6c4ad6001f92f8d32f5690962e2e4ff127f38dbcee |
|
MD5 | 8289f81d01ba4e30f0053dd1d3dfbb74 |
|
BLAKE2b-256 | 0190f1915b69702978ccfaea7dc5d49f90cc633cb7544f760eacce249b433632 |
Hashes for stim-1.12.dev1692153870-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06a345cd3a40551289bd2d7c3d24c9239a6912250026fef2c873493116bdef8 |
|
MD5 | 32cc4146cf5c3d48c405f69dd9f22cde |
|
BLAKE2b-256 | b429075fe18635c9c2d0862d5d84aa9757dddd4c6331873bfa5b327719b8a60e |
Hashes for stim-1.12.dev1692153870-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d3118e39fdadc73782b907ca4057511b37cd847f10677e70172ea8dda730222 |
|
MD5 | 893a96e43d5e921bcc4b1e373e827859 |
|
BLAKE2b-256 | 496a01900459afecdead3d2ab3b4bfde6a9e73634b9a52a9947beade61835b84 |
Hashes for stim-1.12.dev1692153870-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9761240e3c12926b8edfb36b4534b8ff69f25ae4f9496165f5e3d0bfb97d1d5e |
|
MD5 | 9051de89b37493a53bed655f373b1c4c |
|
BLAKE2b-256 | 2a4b515470f71f9007eb13521c3a60dceb21dcd1528e53fdd76ee8fb9755b13d |
Hashes for stim-1.12.dev1692153870-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827693febefca2f8d74cc8e2e53071bb43ffe89c9f6ef669e922571a09f86a12 |
|
MD5 | 3823f62beca2bdcf07e5d013c6df38bb |
|
BLAKE2b-256 | 37bcbced838a82d848061021f02854dfea418300beb6d4540cd201f709f82b5c |
Hashes for stim-1.12.dev1692153870-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb1eed521dd634f31b02cd52ce8671d4d3c354d9f133ca6462b95950cdc07e30 |
|
MD5 | 60d8bf2b8969f5de42a35f7c7db6cb26 |
|
BLAKE2b-256 | e94567fd10c63b75076e95c4e85656a2b76f0fff0499baa571ad1b796beca1fb |
Hashes for stim-1.12.dev1692153870-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b984501b70e060dd4434e0cbae3fb39088760d5a30046571a1a2de973ea83c5b |
|
MD5 | d936278e52fdc9b8ec9273b8f9473081 |
|
BLAKE2b-256 | 54b6605462d254657dade2c8fb0bad606cfd27e208047e1abf7c41dd0294df6e |
Hashes for stim-1.12.dev1692153870-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2ec06f524fa532759d46fb8e9990e07c219b9ba66fcf700f3d8a9f1a6799f6 |
|
MD5 | 005b1a26c8c815322fc8328e61d9b5f6 |
|
BLAKE2b-256 | 6ea6454df7d64ed05387cfd1ac6da18ad5ca25320e72effdeecf59fd9f495291 |
Hashes for stim-1.12.dev1692153870-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a723667bdea6c2f99829fa59b2762f9735d7c82782c8c77628dcfb83f8628b90 |
|
MD5 | 2d2aecf3356463316caf1e79b9c08bcb |
|
BLAKE2b-256 | 940bdbbc527ca327200e1061409479c39f0b6313a422cfecc3275ae0f48dce88 |
Hashes for stim-1.12.dev1692153870-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ba3df8f0fbdfb1bf3c9b70de5a41b6b932b411b3a06539f6c860d8d08c50437 |
|
MD5 | d292e1c9d19251d09f6751ea792664bc |
|
BLAKE2b-256 | c3fd4e1e0cdd0c7699b6b61d850412bf19328b4faa18d3b72c0b9128676b3bcb |
Hashes for stim-1.12.dev1692153870-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df77d1be935a6e912dbdb750737a27fd7884def60a6b33440c4ebb16e8ea07e8 |
|
MD5 | dbeac4f43357b99bf20aa641fb56576d |
|
BLAKE2b-256 | 05e5a1608f84df3b2829258ccdc66c56534de8c525b729eed628cfede2b2b7ab |
Hashes for stim-1.12.dev1692153870-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 752345df81ceaa517ecf287a0498eb9038b9d41a96d6c757a1091edc5c831e5d |
|
MD5 | d606544d89b8fb820b5968fc2529432b |
|
BLAKE2b-256 | 23e8a8e69e511cbb498a9392c409016c60d87c5bec8b2368f0792d2ac24a1a34 |
Hashes for stim-1.12.dev1692153870-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e1850b548bfa2a619e78a9214ef1954bf94cfc553caaf9f3c60b17da13b75cd |
|
MD5 | a4afc468542f783e544c5aed032e9054 |
|
BLAKE2b-256 | c56934c581ba978a6a0e51dd4e153c5f607fad0505d2f70ce882d8bdbd2f1815 |
Hashes for stim-1.12.dev1692153870-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c72d2c1146040a1fa355eb556b9131fc811953fdb3948fc1c89ddeaccd443b86 |
|
MD5 | e9f955cbcc9416f9c0425ce21e073e8d |
|
BLAKE2b-256 | 51f1141a2845cea499051c67ee16ec2c89d40da9d0957192d4777696a5db19cd |
Hashes for stim-1.12.dev1692153870-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47c252002dd40dea763063591228b67de9b0c1641a71519b29446d96d576be47 |
|
MD5 | 11426730b67ef914caab485158e7ca33 |
|
BLAKE2b-256 | 9191af55f4391657289684e102f7b397c503fa635ed397e56ad03bde99e9b13d |
Hashes for stim-1.12.dev1692153870-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9e77c3a8dc5bcc80c4ffe666264e55763504e8f5cd05f1b9f853f7f32f0b799 |
|
MD5 | 5e9b54938f99b10bbefff41e32482a72 |
|
BLAKE2b-256 | 12efc413a3e4e85d525f8279c4c38aecf459f2ee76b591c039faeda60ebc4451 |