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.dev1690241034-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bff6a3f40c11ecc755aa8c4e24e0e6c9ec146ca7fcf91dcf04c2df9bdf6c7f8b |
|
MD5 | 39f77b97a2ffe24f67c92ef2710e6a57 |
|
BLAKE2b-256 | 4c800cc9bd18391fe0596c1acab827bb95d563b61aa0e0e39e537d959cc8adce |
Hashes for stim-1.12.dev1690241034-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c10836c9604cecb02adc942cc511b73e10ffe351ae328cff45243d8020044bb |
|
MD5 | 7a7f863e7b9672640a76ea9d644dce67 |
|
BLAKE2b-256 | 97240dfab8d039b038c252c6a5e80e315e23a074d325d63a8b19366a7669e3c6 |
Hashes for stim-1.12.dev1690241034-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b600b8109f906cb866ebced206d99602511c7eb15d4634ed28addff81281db1 |
|
MD5 | cb821ba67e5eb0c9ffa318dd797a5ebb |
|
BLAKE2b-256 | fd6515f7f4b63e34f3f992b3e704b2353f008dbd04465d10e658b93afc5ef67e |
Hashes for stim-1.12.dev1690241034-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb0cb27c0a6ea9cafd00c76b808a189c2318a5b5dff3ddf839ef615e271c35eb |
|
MD5 | 3ec8a362e2c64eb1f1c63a4089cd81c6 |
|
BLAKE2b-256 | 7196c255f185d94e47cbedcf33318ff89d2e1b774c4a3b113a4291a0c70b69e1 |
Hashes for stim-1.12.dev1690241034-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfcfde0afdd59c16047c7613516e6d24cdd6d1582f451ebeeedaea3835465100 |
|
MD5 | 9418d3c5749148e8545d7d97aaca9ee5 |
|
BLAKE2b-256 | f2f7501ab1c6ae86fdf1147e9014f9a0d64c65040d105b7ed706bbf3033e38b9 |
Hashes for stim-1.12.dev1690241034-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 464f46967246172d28f7b8e9eb98a762b63037ba20a5903c91ecb0c3149d3948 |
|
MD5 | ca4edd9c55223981d6244ba104f9fe13 |
|
BLAKE2b-256 | e45bc7e2858dd0191a2bd9a0bed95ff807493521a9665d896637b998994d2b56 |
Hashes for stim-1.12.dev1690241034-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60fcb7bb2f8d45e71fda1106213172dbd41606aeecd79fd50190e0443a810642 |
|
MD5 | 020fac5267abc9284c5d745dc6189d3a |
|
BLAKE2b-256 | cf01ae7c26e918729b7a571533632574812e2d7804c5d333699dfe4530e0d869 |
Hashes for stim-1.12.dev1690241034-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e972b7c0b4d8d5456c4082e3f45fb662e4b7f76bfecfeee2638b537f8d00c5b |
|
MD5 | e56f52f200698957de7579309c95c2ac |
|
BLAKE2b-256 | 30844e815272b0851686130fdfee7e4ce08cb10fc17635661bcd47331b8ea685 |
Hashes for stim-1.12.dev1690241034-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d6c61314528780b18baec2f4b0ac02da81cae37218c5eea864371a1c9a953a8 |
|
MD5 | 66a415f77c34732c5d91ea8db45116ec |
|
BLAKE2b-256 | b83526841613468547237efe1419427c6334a51515faae4aaba1b6e62696331a |
Hashes for stim-1.12.dev1690241034-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168535317c9be1e82b9972dbf1f011a625d4f9f5664047e92df6b55dec34f02f |
|
MD5 | c25ce10dbf82f91fe31b064805f51445 |
|
BLAKE2b-256 | e5dc842807499b569aa96acedfcd3ebf6122fa71fcebd44ab4c1795539edaff9 |
Hashes for stim-1.12.dev1690241034-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b26e1d172aecbd0b23c04e186c2afb171bd261a9c13eb89bb8a4c245ee38f2e0 |
|
MD5 | c4a3e52f1bec2ae25691fca96fcf6f2f |
|
BLAKE2b-256 | 9016d67a2157b2fd5c493cf3dd66b3c0ef738ab4b5be89a78edd99a3be3c0191 |
Hashes for stim-1.12.dev1690241034-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0022c48d9aa583305c69acfa91f2db153fffa953064096c0b083d915db66a09 |
|
MD5 | e1af436f0d37476a21069d45c40f52e5 |
|
BLAKE2b-256 | 0a27bc8e638a4f24153e9070863e83f84449148cfa2c4f52eceea31fe365cc5b |
Hashes for stim-1.12.dev1690241034-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9ddabf9b7e45ff74b8016ccef8ad00fa125b6077e94bb7a2dececbffb1c32c1 |
|
MD5 | 4a0c723c5b2384837a9dd7edbfd253de |
|
BLAKE2b-256 | 4bebe5acdce29d01058e49905779d635e6de6ff807ee6b87bca67c031c3f7a5c |
Hashes for stim-1.12.dev1690241034-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad8ef823a529dc2370d770906e9740cffd62a373185a23f9e35c679b0512c5ce |
|
MD5 | 3c57c69a5b6f39a017bc9b91a2b99636 |
|
BLAKE2b-256 | 870b9999f3ec1b87817273bf7782f5d982430e5dd009a589c9dc86030680c7c7 |
Hashes for stim-1.12.dev1690241034-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11b6bc992204be7c3d7048943c0f97fd5ac3ec46d21b9cc6b5e8d1b294ab095a |
|
MD5 | 90e288661d9087035da15eb175d0dcf4 |
|
BLAKE2b-256 | 308f05e01a5fe740acd301e872ed8533b4558b0fbd2735f0e7d6aefce37077cc |
Hashes for stim-1.12.dev1690241034-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7c6d2206c7f27554f5db0c8c89410617e01dd4f6f6d846d66a58476905a5142 |
|
MD5 | 1c2346d270de0f2cfb7d5c174c144e6c |
|
BLAKE2b-256 | a743a820f3120c50127eef78f54570d771703ec053131e7f953116e463683a09 |
Hashes for stim-1.12.dev1690241034-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0afc91f479d72a55bd58a3d8733825ff77519c880b52425f7d7b942ae7a53feb |
|
MD5 | 388484d24e038bd728db4e3224ac6aef |
|
BLAKE2b-256 | 66394641ada3d7f12edf04180f640d4ea41b2e9a6115c9e3a688d5b210d8a369 |
Hashes for stim-1.12.dev1690241034-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccc0a3a24976d8af8f62d6b4f97e1c90773c22007c9bda47708b6361574b139f |
|
MD5 | 76bce02e5b4a5331d95599adb705a344 |
|
BLAKE2b-256 | 0bb697e2e6f5329ac14d824304b8d9f58f683e8f95488151dfa1013f55963cb1 |
Hashes for stim-1.12.dev1690241034-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8058f9957966de976a23ee1b296f9a2cd8e55b6cd31557b3f44cef053a7d45e4 |
|
MD5 | 01c778d9abe3c0118e10b82de414a94c |
|
BLAKE2b-256 | aada3420d5c0885b86c7e5ebd290044459746f137b07e423a1071813d6ecf222 |
Hashes for stim-1.12.dev1690241034-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd06de93b48bdc3249817f7219532ec6227248dee84b109c5c32177a53f9d6c0 |
|
MD5 | 8c66fca94a5e2a9841a4bf535ed482d8 |
|
BLAKE2b-256 | 0060602d15a0da81ef1b8c7608bddf6e760ece07b5f33503271ee71726e933d8 |
Hashes for stim-1.12.dev1690241034-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd823045074f3ca4d98195303272ae72aa721a38f8ca3bffe17894bd0a1e1f42 |
|
MD5 | 7df4464dcc19fd82ef65980bd5d46b87 |
|
BLAKE2b-256 | f2f3edbc32c3dfca464e515598cba32b0089634d21b4faacec35ef21e0d8bd90 |
Hashes for stim-1.12.dev1690241034-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97027b7e7060e689db97382be2e1f0c48bca2ab94c36f808176a7ff1a8b8fac1 |
|
MD5 | aecd9bac62b7b6066817701bd3cc913a |
|
BLAKE2b-256 | 2f58877286739856c03846822c960552c8f76812cdde03e87023fc9d75f4c5c3 |
Hashes for stim-1.12.dev1690241034-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29243b151d00a4ea66c680e04f1831b7912600c250ba70227a572ba7037bfc51 |
|
MD5 | 7a2664751620932b5525cc613067a91f |
|
BLAKE2b-256 | 03b5d7f62c69511ba5165f5f861b7320ecb609a6e8ef4e40aca11509aa59c10d |
Hashes for stim-1.12.dev1690241034-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fc450d31abe41509e0d64ab78a94103566764317210d448d52593518e32ea0b |
|
MD5 | ce0563537c5233549260b0f7fa331800 |
|
BLAKE2b-256 | 53e6774ff10bdc16be15397aca23c40429e4a7f805e6561bb079d4354f493315 |
Hashes for stim-1.12.dev1690241034-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4622333cab445f51be870b60c7af9cc38d62ea2dda46865d4105ab69f22198a |
|
MD5 | 365a4552b8d20c0f7bff0bdee69b4b3b |
|
BLAKE2b-256 | 4d43cfc1d73c2e3a27a9688add40fe5e656a5f0065bfa1f1dce5b55b12328b97 |
Hashes for stim-1.12.dev1690241034-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dc5cac4927bcf089ca43041692b6839430e75f7d00cd00791381d1b1b068f2f |
|
MD5 | 024d83f61f1a0d05679a06c8f0c7fac4 |
|
BLAKE2b-256 | a86c256bfbdf5017e5c6470a93416cca722000c55c43248e8853e408b9b4de0e |