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.dev1686532921-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e0e2dca0b60af4410fa0fd6c3b06ca065f57be4a6946d36d48d75bee9295f66 |
|
MD5 | ce80394c96dd4860df007039b9c7a6e0 |
|
BLAKE2b-256 | 87f7c0deb9f85f15bcabe9d2c5cdcee45691a3811fa95531ca1e1af225acba48 |
Hashes for stim-1.12.dev1686532921-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ba485dd2cacf6bdd2842d2697a259bbeeec0e7026cf75112cd9fa6efd7fe7b |
|
MD5 | 7402e734860dc2edc710c610612927d8 |
|
BLAKE2b-256 | 2a5053b30f2d6645cd867f34e542b1e60ab4c892a11131377e2e4bb7792f50a2 |
Hashes for stim-1.12.dev1686532921-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b1c20f19219cff99bffd04bd486f4868f57a0f82a19f145c7d8833637b39614 |
|
MD5 | 488476991b8629af317c36a1408be661 |
|
BLAKE2b-256 | f42bbe10a5594aad04851cda3a1eda561ed6364fe0cbd855c44dcb8e3337d7f9 |
Hashes for stim-1.12.dev1686532921-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57445f5a2ee89bfc9bf6e6064ec553bab3f0a79aeff8774bb009b6836f76d848 |
|
MD5 | e087588cd7d870e0d495d74fb337a717 |
|
BLAKE2b-256 | 795dde54d630119e8ab253843490928463c1c49f4f7d378b146bf1e93ac40d28 |
Hashes for stim-1.12.dev1686532921-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f83768656d6faf2665e23b59266852f673e504a33391676d660800b4b025918 |
|
MD5 | 837801445eeb315ed76a9f887aff782f |
|
BLAKE2b-256 | 21f61c0a5e7c9712a0f0352bc6c4df50de1c7e5a97606f066cfbce02afa43f0d |
Hashes for stim-1.12.dev1686532921-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc23b289eb2e8f387449319460be959030ba3631abe0a576bc072b1f31176e01 |
|
MD5 | 769b84e7f771342b1018e8836aaa77bc |
|
BLAKE2b-256 | 97a8279d8c57bbd533785777f4d44bf7eaaa4c1e1df442924e76a88f64014497 |
Hashes for stim-1.12.dev1686532921-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36850a4aaf2a57cd8c0fdf571732f51e2947604aba906eab15ca81ffbf8afa5d |
|
MD5 | 12fb8a16069475533fde6faef2fbc086 |
|
BLAKE2b-256 | f90195fb6275b3e56faf968b162bceb53e335ad4cd34b472e7ea419d483a15e8 |
Hashes for stim-1.12.dev1686532921-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2574d488a3e937888d6fcce8b825a19bc0b679b9a76ca6f9d2c1f9efba66f18d |
|
MD5 | 3fa5345453d3b5c7630c878d26b34d17 |
|
BLAKE2b-256 | 7fa753ee9dafb61bebcc472dda4bedbc2b61ef1c99a0c4c331727dfa9d93a583 |
Hashes for stim-1.12.dev1686532921-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e069da32f59933583b05a28e13161894ff93d2c116eee2734e0437c79a7ab9a |
|
MD5 | d567f58b8d361c9fb3137c9a83859545 |
|
BLAKE2b-256 | be9997c5d611665fb6096f6f4f796a600c748c54750ff4a4add75b204a991625 |
Hashes for stim-1.12.dev1686532921-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44a0ea2f2b6fd3d82da9aa781e6cad54ec793d2bb578721a751c9e0c29575f7c |
|
MD5 | 32bd0b5ad673d208ecbb49537e517f1c |
|
BLAKE2b-256 | ad2656133c28fc0b36907e79dfba8a9f27fb2253a336ee322f0384d44d937ea5 |
Hashes for stim-1.12.dev1686532921-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e74ae04ad237d087a700ee00f8bfd009627f9181f61013d193a179d5d9b5fcea |
|
MD5 | 86caa063f3e8ecb433ad6a0d218d3fa7 |
|
BLAKE2b-256 | 692eaffb4565d90c29bd6bd1ed562ea64e7907e7ddbfae63ee7ce5b8709b593a |
Hashes for stim-1.12.dev1686532921-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5baba1c2e1e9d1beec68a4b6311051977b9cc8d4e43eb2d6e7d948f1f8a533 |
|
MD5 | 6234cc3632b244e18292a47a7b44c2bc |
|
BLAKE2b-256 | 2586c6bd20d03cc04dc0eda00b99c6ac7ee5f53bc8257dad1d8f74ab9aa2345a |
Hashes for stim-1.12.dev1686532921-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc3426c5cf807988d14a88dfef4fdf525fc92699892d836f86259faa33aeb113 |
|
MD5 | 6208f837fe727aba3b6303581ee1d1ef |
|
BLAKE2b-256 | bc7af875cbb9361d0a982469e421556c2ad2b93053da41b33228a335cf4142df |
Hashes for stim-1.12.dev1686532921-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c909b6ccd3856dfb1aa949bbe661747a7b102f73624636636982cb86312e1a0 |
|
MD5 | f17f80193a16b60d1fd44f009cf96764 |
|
BLAKE2b-256 | a1b3a54a692ef3fd3136d20bc2ea9478c1dd3f4d9522bfe105eb281e26320bf4 |
Hashes for stim-1.12.dev1686532921-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c6ebbf79a15ba280547b39780f3312018e4a7f13a4b19633a9c7bc06b5aa69 |
|
MD5 | 073fc2afadd4188a06a38dfaef7ca535 |
|
BLAKE2b-256 | a05315845ab6ff58c73329dfa728981dfe646ed745af39f1f9de34f7ce7618df |
Hashes for stim-1.12.dev1686532921-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a74b2493521ba35d88b40d50e3a3979fed3a27f5ba53d4f2bc3328f28dfcfc3 |
|
MD5 | 904878f705dbac819cc57d157a8b6274 |
|
BLAKE2b-256 | 23e8ebfa68039f5714cb2acce0702f54faadc7dcc711af98459e1f7fe52cd147 |
Hashes for stim-1.12.dev1686532921-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 617181669365941741701419ce71277886e4d3ddffbcb0953acaf5359919c30d |
|
MD5 | 00b5d3a1c2d7fa39f7845ed01a3107d1 |
|
BLAKE2b-256 | d952dbe9f48d35f18d7e9ca7c7c2a83bfd95b43021b434ee58f4b50802c5abdf |
Hashes for stim-1.12.dev1686532921-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cdc70631966a2316eca16d667783505027b10f9594bc8ef739578b28ffd78d2 |
|
MD5 | f315ac151a426bbf94e1903a1d65e307 |
|
BLAKE2b-256 | 107dba99472273e780f827614661873d63356df01749a031455982764721829d |
Hashes for stim-1.12.dev1686532921-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7365a8a269269cddb35542863e91960b33aad109b35ab3fcdb1f04e2bd4c471c |
|
MD5 | 2116fd4c129d01af3305e91d7caedc7f |
|
BLAKE2b-256 | fe432917cb96c680b721e74743c239c769fb2bcbd833738321e402096f05b58d |
Hashes for stim-1.12.dev1686532921-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b42e9ea3dea08101e595c7d4f013f16564aac462f69a7f42f3b7d1c4028388ea |
|
MD5 | f618ba59309a49ca4ad12c924ff46d34 |
|
BLAKE2b-256 | 50b1f202951820915d0c8408ca9673de055b2616c611d7b26b7163311fc87560 |
Hashes for stim-1.12.dev1686532921-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3410d7830949fa8f37d089094564a08c698eb5592a067650ec7dbd1b47deb1f6 |
|
MD5 | 4230bdff86dcc244fe98be6ee8fee123 |
|
BLAKE2b-256 | 05f249160d6b438bd11598e3aec241e8e5d4a665b0921b025f60d57adfbc105f |
Hashes for stim-1.12.dev1686532921-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1624baf515437f44f6df807bae22f5bcc1a95fc94b1bf06dea1c231c9a575e4 |
|
MD5 | fe5b20c162ecb67752c7196bc66b12e2 |
|
BLAKE2b-256 | 743ee0d19054bddf326a9fb0c9917e72c3f32978714b12191120096eb5eca222 |
Hashes for stim-1.12.dev1686532921-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc080cbbae9f23f31355bb38bcb4f1a28d912faa51206618a80e1b3c796f96a |
|
MD5 | 0d6adacc6460d50a09a7bac35fce582c |
|
BLAKE2b-256 | 0dfcb85451d9063a14cffa5793b8e05d730535acb1fd6825c36e5bdcd8029af4 |
Hashes for stim-1.12.dev1686532921-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99e90bd967bb7f1fd544be7cb194085abd9778c03b07176a6a87fc25fd89a8f2 |
|
MD5 | 72b1ffbbe61e1634fe4b44e72a57bb12 |
|
BLAKE2b-256 | f27614b212fec15b69d39cb535686ebb7964dd8a5da529ad75b519a386c51a63 |
Hashes for stim-1.12.dev1686532921-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e984c666f31470d4395daedfec07865e117909b6b52e8cf176241c51505f0f6b |
|
MD5 | 78881c3ab6179b3884d420a6d4f6276a |
|
BLAKE2b-256 | 148eda97c435e13a363ac4ea9e39448d35df82044c3546e3fd68aba1053f0dab |
Hashes for stim-1.12.dev1686532921-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57fb31f91820c2a588ac592a03ff46acef14c15e6521b01d2bb0522c487c3dbd |
|
MD5 | e452fc42b9c944d788cff7e8d20ccab2 |
|
BLAKE2b-256 | 3ff28d499bee14dc22166c654198c0571c97ff768630e4244413cfafc082b777 |