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.dev1706570159-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d46cfe1ee5cb3fe45eb9ad37321a93d65dc5041db514a2d5f9237fbaa3b3c25 |
|
MD5 | 219ae1fa75586b5aa21534228f0d10f6 |
|
BLAKE2b-256 | b1d259fddee22fbaf617877b1fd6ce1df5d86b1fc6dcd8a29a3cfa959dff671a |
Hashes for stim-1.13.dev1706570159-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42715a9cbe72a291cfbf4999eb1682da6425c91f6d8c243ab7afce56538bb155 |
|
MD5 | 7ecae49ff2384d838c50e41a2e50bb8a |
|
BLAKE2b-256 | aecf84b47928eed5bfd8b74c34e00d228a59e763605cd90227a2b2b8fb2ddeae |
Hashes for stim-1.13.dev1706570159-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b54afd13b27385b44b8ef04fad50d1ef427330e19fff3c1f55fede8dd1b30f18 |
|
MD5 | 01ea6f7edb58349e754dc3c6aca33d25 |
|
BLAKE2b-256 | 95dc0634d283715e358501add181953d7da5c4f65e1b24bbcd8b3a2d56998318 |
Hashes for stim-1.13.dev1706570159-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac2875eb4010964a350cd28d85aa68ffd95311a989fcf8cd7db0c503ed5d6196 |
|
MD5 | d58b2aa2fb4737cf2b4be2112ee235f0 |
|
BLAKE2b-256 | 38bf06d06de20639c41a6deaa86e381b2d1b534d6fdff4aa72cf7d449272d6eb |
Hashes for stim-1.13.dev1706570159-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d41eebcba683592f83feb7f98316035d4a30145024c45b86f618235bbf608d8 |
|
MD5 | 21b08425f4ce61af204227e0719442fe |
|
BLAKE2b-256 | 9c939c6a71494e2fd77ae59cbf68d94b09006093b3ed3f1026dca4abb2ff0f21 |
Hashes for stim-1.13.dev1706570159-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f7e9816d9b365bb55cc516b52737005fcbcb056fd1fb95f3ef4476ebb01fb2 |
|
MD5 | 9b2c509aad7d3a901f3a82e015fc15ca |
|
BLAKE2b-256 | 8ce8623e7652a91821b266404bb51819372ae393d3eadae6ae8b990c53f22b7d |
Hashes for stim-1.13.dev1706570159-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9311f864c9330b50994a1b180ccefcd1cebf7fa9c9b462e66c1d5df9fd2c8e7 |
|
MD5 | b0de351116eea2f6577ab5c1ba3e844e |
|
BLAKE2b-256 | 105f29461e0e5a39f08017d882820ad01f829713283577109768d57e931f578f |
Hashes for stim-1.13.dev1706570159-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a107dc1a693e3ce23d81f487e560a5a38a2e816a14c176e0e131c797a10222b |
|
MD5 | 28fea09cb72a69bb4eb37ea9a993d901 |
|
BLAKE2b-256 | 52589fb3471c8fa67db7374d84ed4c8d14438f073699b34388fded8c490becf8 |
Hashes for stim-1.13.dev1706570159-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a876b11398d5bee2aa6e78bf4b436f3f241f181f9105c48d4c69b8acf16084 |
|
MD5 | 0e41b25f9daa1bccc0475f2e0c0aede1 |
|
BLAKE2b-256 | 6bd53912ca6a68d5eb197a4ed293b604eefe8d9a829e8f1f7796229dd14ec6fd |
Hashes for stim-1.13.dev1706570159-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58d75949c1c63a1a01295320bdf4aa5838d4da30bd332000ca4c4f4e757c885 |
|
MD5 | a8fb1f84d3a424159be66e6ef22173f4 |
|
BLAKE2b-256 | 5d019714599929ddfe4d1dc6bc5dd52d0235a9bdcc8b5405d5683fc46467a82c |
Hashes for stim-1.13.dev1706570159-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92c35868ede3da3299309f28ef665f3a7f6decde26bc8a722eb88b1c85563ea |
|
MD5 | a279294dbfd793de592cfb392f7432df |
|
BLAKE2b-256 | cf6a23562b17ae32d2042a81f7880e8dd5491dcbabc501adb8e55d2094a8b06e |
Hashes for stim-1.13.dev1706570159-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94f4e197cc955e0da7f6193070bedc4917cfbbde006c8d1a3b174b6fbb611447 |
|
MD5 | eca55ad486a32136de728132a9338f77 |
|
BLAKE2b-256 | bda8211c76f4a57a31011d0b0d55f4ffafc30d0a5020f45c82b3ab0f86f0af99 |
Hashes for stim-1.13.dev1706570159-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b0891a06119135205d7589b6196649ec272e3e8a6b65d123c62a4f735857e42 |
|
MD5 | c5eb7dd5851f60e2f8f4333f6b2eff5e |
|
BLAKE2b-256 | b2620c38826d1079c8b08a685c7cfc4f2d7040d6ab7058f5c7a5520f7ab33da5 |
Hashes for stim-1.13.dev1706570159-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d036187c909b16e7e4c7271e8992c23204b74c728d456b9525efd08b77c0e1c |
|
MD5 | a64a8b4c85b499d57708ff5d48c07276 |
|
BLAKE2b-256 | 8e9e2d7a09411c758d31c55dbdfc8930ba3be8151c1663605a56805e02abe013 |
Hashes for stim-1.13.dev1706570159-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23c1e6bb87d7383fa863a02ca5d214605f84ee0c0a330ca901fd038b89030e63 |
|
MD5 | a53ac81b9a4bbedf4a8c203f2992c9c2 |
|
BLAKE2b-256 | 5419ccf7bcd394627f08a2f72eded5baf6bfd77e4a449c429324c448a4856543 |
Hashes for stim-1.13.dev1706570159-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 092a1409fb5df26102f29085e7666904aed664b322d8997bbb1bcdad61927a3c |
|
MD5 | 97ace2911f3d4c929968ac91bcc00231 |
|
BLAKE2b-256 | 6c4fdd201a155205eed2ffa2c7c08c9d98c0d9e04b04ca677ea61d242846bcf9 |
Hashes for stim-1.13.dev1706570159-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 382126204065c659f2b3bc840953f5002e10ed2ee7ad5f977d33d1323f3f0ce3 |
|
MD5 | 29331e5c0d0ecd6d0dfcf3dc2cf134f3 |
|
BLAKE2b-256 | f09c70e7ce71a7497adf67910fa2d2afbbfdf5c246ed966952a497ba3bcaefd6 |
Hashes for stim-1.13.dev1706570159-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d76f61f834cba4895f7a2a89020787563064fee38edc9cb9a8ca31f8583c60de |
|
MD5 | 51f991d2217f67afdd8b16bc802a6c98 |
|
BLAKE2b-256 | 5f74807db512e20601300099e097e2dab489592796a87b56be4914c98ed6a145 |
Hashes for stim-1.13.dev1706570159-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb05b5cec4f3100f36eb6b8fde117e16e47fc43918225920a5397edabc99d8c3 |
|
MD5 | 36ca1c2611a947bbc2ec4a5333e19968 |
|
BLAKE2b-256 | 97038356b64de0c18a77f24f943deddf9da87f59b0da9200c1941deb8e45dd17 |
Hashes for stim-1.13.dev1706570159-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 771928f93b845b0127be24a33da90799ceda1ed303d3c5d91214a6ac19750376 |
|
MD5 | 2bff1be3aa745c8736d8b029a9044e0d |
|
BLAKE2b-256 | 3f7be330fa895cfad2b4c63a208d16b98218c1cfe36ba461d3bf3bcc5f20c583 |
Hashes for stim-1.13.dev1706570159-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c83c13ded29418495f549c3fb2646a69d5f79dc24b24bab106aa98b459a8695 |
|
MD5 | af93bbaebd30c7ac81ca6592fe9257b6 |
|
BLAKE2b-256 | 7f7069a39bd8e1e8b1e68311a057970909c5e07beb841802935c6cf8421b9a25 |
Hashes for stim-1.13.dev1706570159-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27b8f600621b980ac9f158fea871a165b2e6a3c5232c288e2e04e34b10e7c742 |
|
MD5 | 5b8024db7108a61319091b46a4ca04f8 |
|
BLAKE2b-256 | 55676c64c77acec5111878eb976e6a0215ae60f3941ae575b4783176c976f967 |
Hashes for stim-1.13.dev1706570159-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a9d2c0edcd713f0cb1acb275156c5de546424bb7d5f6bc50bd9a0969af8fb4a |
|
MD5 | 671a46a21ffd89ac44516673f8c59bd1 |
|
BLAKE2b-256 | 2ec170328c59f6d4ae613103a2abb2cac4a7ac789ec29f64ed01a3478716e08e |
Hashes for stim-1.13.dev1706570159-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 270c8902634596c0522c6d602b4f57c1e1d99228f66c3dfd2677c9fd76c63e0e |
|
MD5 | 3bd516fb1eb036aa49ff4f0ac0399577 |
|
BLAKE2b-256 | 6ddc5dfe7489735f97b6c51783b472f7be78ce96531e81a8a3801df4bef373f7 |
Hashes for stim-1.13.dev1706570159-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d27bfb016bb2c0bec6bbee2e01376372c5040e76019e43b55490f89dd4f1f4a |
|
MD5 | 6d9c8fd0b7bf284dac1cf0c6875321b4 |
|
BLAKE2b-256 | 2af138547ebdcb22729d8c28b9aefcdbbc27a24d3e4077b3365e153412b03f05 |
Hashes for stim-1.13.dev1706570159-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a4b0a6c95b36ed869f43fc30d5d8638be26032de24c92ebafd3ea167bca617 |
|
MD5 | 88856d37edbbedbe17c8db2fcff91a28 |
|
BLAKE2b-256 | 8bac6086c1033328c1ebbbfd29cf9610227e171624c4248341e0000102be23a2 |
Hashes for stim-1.13.dev1706570159-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a6a3f279fd53c975d857debb99ec9a3257a83b2e3241ebc0722a7847e3ebc8 |
|
MD5 | 59fa98b22a116b44185bbcc025322275 |
|
BLAKE2b-256 | e54ddaab705ae748ddb8a5a8f597d838e5d7b586a19079b4e1a79e473d5b264e |
Hashes for stim-1.13.dev1706570159-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b284c60d74b432e8b8f8a7d3d2f5354ed54e3afe4355a733a98f502f84437f0b |
|
MD5 | 192e0b61eab1f436b55e1e4cb50f0a9d |
|
BLAKE2b-256 | 375feab8686e0f52b521b5ae0146b04b446c86698bfd2131a5ce7f09f1398b20 |
Hashes for stim-1.13.dev1706570159-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44039f8639d06332acba003f0335feba78bdbd4df30e64b645e9eab524b49b95 |
|
MD5 | 9f76efa8d70e112a7fd78322ce19525e |
|
BLAKE2b-256 | 3c3439a1e64aff7343ec12bb6cea753e6e4cbe55371db6917a12829bebf9793f |
Hashes for stim-1.13.dev1706570159-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d6b9612eff69cfde9dd3b980089a8cbfff1ce890c0a79eb278847d609c8558e |
|
MD5 | 5b7ffeed6435bb1395aecb64f207a114 |
|
BLAKE2b-256 | fbfcb47d76a92eac3cd07195774123b21514a48b73ff47526f9d3c0cfffa3ac6 |