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.14.dev1725679825-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c98b668910f7d1e5d7974275859fa86a970bb3dca5afe3d8d1d443833a265dcb |
|
MD5 | f0fb93cf1180ac4a76cd320bbc69a537 |
|
BLAKE2b-256 | c5508482bd13980985b666fb339bb76d1358933e30ffe299162ed4f823648b72 |
Hashes for stim-1.14.dev1725679825-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a59470b27fd0e9ab0fc625cf713df5b549c30ed78da45c0848591f17ce5b69d |
|
MD5 | 290184cab14e3d56c89f523c295bcba4 |
|
BLAKE2b-256 | 064e4c790f9f4e714a7d3c4565050a7620428d53536d2f945eb99a5873f09004 |
Hashes for stim-1.14.dev1725679825-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfae80e3a537d5d2a4b1c5ef7bf48b82ebef06a507278717481b6bfc0eb79221 |
|
MD5 | 6c0fe5164e62ba57ae1dec0cc401bd7a |
|
BLAKE2b-256 | 6965751af6199cfab54ff9146804965ca485ae30c15a0eb83ae6526a1e27fe23 |
Hashes for stim-1.14.dev1725679825-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8398cef02ea0f6d68153c6af82a33de135664e7fd7944dd3fd3aacf4f3851496 |
|
MD5 | 92457737cea1c0fdb20ce765a34595d9 |
|
BLAKE2b-256 | 03d6356c01a80a3c7072f51cea5547578503084f0359663871c6440f889637fa |
Hashes for stim-1.14.dev1725679825-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8d1eb5a9dfc016fb85703e76284d22882db5ca3ce9e0d3d2c57f2b6a8a29d01 |
|
MD5 | 1f659568932c8efda21641019018b2f0 |
|
BLAKE2b-256 | b4fed6d11ac7ae5e85498a5262fbd06bdf76b0d22caf2a6b8b191c877a283712 |
Hashes for stim-1.14.dev1725679825-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f0f898fd0450711ce20c3e4f6f224c0d7015f4b59d074ba12aafbe60a72ae6 |
|
MD5 | b001c564cff85956d7713ac4cb140739 |
|
BLAKE2b-256 | 0c4b11125d8c843ca42fb9f2b0398813a19a0a47836138e0d1cec1841f58c8d6 |
Hashes for stim-1.14.dev1725679825-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85d769d81b648fc61309490484cffccb565fcd10cc53709b559afcbab4244cba |
|
MD5 | 120f5511cf02284ac71cc2e62c182d9f |
|
BLAKE2b-256 | c8814c877cba34278332730f369742704e1d566fe017d774aa0d01b01d0193df |
Hashes for stim-1.14.dev1725679825-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 433527d3499efdbe00038dc752d34fcb84262a05ad0f14741baf852e3823380c |
|
MD5 | 0614c436b3f2225c8c4a72fbee51b560 |
|
BLAKE2b-256 | 92033142c160825daecede5f1441bed6da1b5ce5e1464f555dbc030db8829eaa |
Hashes for stim-1.14.dev1725679825-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e136cff3ce7e6883cd61a773f960968c00d8aee220a1c275ea1d14bbeb0784 |
|
MD5 | 9882d1af2b00512edbcf3434c4e0d0aa |
|
BLAKE2b-256 | 3e6b7374f034f5fc7a23dbdcc35d5f840a0377a22ffcb21e7c0fbfc5e7f1cbd3 |
Hashes for stim-1.14.dev1725679825-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4910c9d189ad12f29a9c1dca802b1f4f6ab08f5ca0f1ffe7d079e83d01b898d1 |
|
MD5 | cc6539ba52ee7484d86cab452bad6b83 |
|
BLAKE2b-256 | 033d7b656365aa6e428c8540fdb179cc21dba410d7c7deef3a4a4dfda73a6823 |
Hashes for stim-1.14.dev1725679825-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb371274371581223219148fae37598cefc5518e93eb8fecc2d722a97aede8f |
|
MD5 | 6f99cfb055c8d0403f182f37515cf886 |
|
BLAKE2b-256 | df3b64960b0f9fff29b3a394422deb22a7b9c7e4efd4f43d5b3949fd565778b0 |
Hashes for stim-1.14.dev1725679825-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03255390a529fa3ac284e4a64727eb6d1570eb47e7fbd2282316c06653b17404 |
|
MD5 | 0e68d70cd1b1c27cb7e6466e08863975 |
|
BLAKE2b-256 | 33f8e7cfba5a19a51cf5d942d40fbdded379671c588ff9630f8dd38135ce8c84 |
Hashes for stim-1.14.dev1725679825-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a272795c15b55d2375d7dd4550fa367e641af8aa7805f5da5303e0fd245aee4e |
|
MD5 | 16e19aabda6e77ff3cc23fb7236eef52 |
|
BLAKE2b-256 | aad3054e9688b38b9878023a1ed0185e61268b8c807bc1cc9b242d14de34a8b6 |
Hashes for stim-1.14.dev1725679825-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a6c199e496090b92b73b4c535ce2cde3fb6f894a71146f0cc19ccc00e6c6bf3 |
|
MD5 | 77ad16e0106b6610e078c712ade459e9 |
|
BLAKE2b-256 | 87af1617e7ff463ac067e0d7831c004ed8100a59f71f32f7396f1e8d71ef430d |
Hashes for stim-1.14.dev1725679825-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3376b6ab2becf429a316aa82e9f570fc40e89ab7c9a0f2c54842ae076b810895 |
|
MD5 | 4f7bb54c35d23dd63893b0ff664fa3db |
|
BLAKE2b-256 | 9e7cf4790105dd06d602890c48a5330e42caf2484379928e317fdef72ab77fc7 |
Hashes for stim-1.14.dev1725679825-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14354e09def6064f8f2bc8e4bb8a5e578d8fbfa1641e3343824cb78168a094ca |
|
MD5 | bf8979b082925e7c34c12925db9d59e0 |
|
BLAKE2b-256 | 094fc2c14703b889c6b1e96ea82b8208234acb298c79209735e98f97b0bba5f2 |
Hashes for stim-1.14.dev1725679825-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4758368ae96fd6570d3bd5140b20eafbf321251fac2c26db491afdc70688031 |
|
MD5 | ad10071b68bc0a735c6463214cceae68 |
|
BLAKE2b-256 | 7f0e64b0dc8a82c9dc5d1262a0de17b9e9b24c2fc62016c8d2d079c16599b52a |
Hashes for stim-1.14.dev1725679825-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 662a24676593c53ebc323581192548df4cb80d3cd13d2e438a97f89cb4f1e024 |
|
MD5 | b8c37e5c13dd7f9d0111555eaa8bd61d |
|
BLAKE2b-256 | 35d80c21e4ce2d042c28a3664182d4503f75b2f6caa7c7c55a4cb54ebac938ca |
Hashes for stim-1.14.dev1725679825-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e5f63904ba89a56ad0da8be2845c31321cf7aa7bee013a881e26eec58cef589 |
|
MD5 | 78ea8664f2ca40884df22deff911b9d3 |
|
BLAKE2b-256 | f92f1f8144b3b960313a0c706d33001857dd2e6bd0ff1534f476cb41cf62abb6 |
Hashes for stim-1.14.dev1725679825-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b76a98644489027362d18f5b2a73c550ffca591d29e8e097eeb265a438e08670 |
|
MD5 | 5d40733b058688a23b506185d2ab1e0b |
|
BLAKE2b-256 | 00ea52c2d205c59426961ad7a5335d1e5db7419050470d8fcd9b523eb7534119 |
Hashes for stim-1.14.dev1725679825-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3caa1a5bdbc2fb4e6dd5d849e3f259af907dc352e03837d0cbce5a08e513aa |
|
MD5 | bfeb2e9e37af85aa39b635204a2b6276 |
|
BLAKE2b-256 | 0abb8595d19c45583ac3d29e308c9b7737dcd3330b3177d738bef31880b4e2c5 |
Hashes for stim-1.14.dev1725679825-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d05c049e9ad77893dce0ca52f7cbd52e9b45103de86fa73a58be304544ded5a |
|
MD5 | 81370fb27b8765ba4cde73fc832e45f4 |
|
BLAKE2b-256 | 4d9c114b59586d21cf294bff2de7bd0b1288e72b5c3c9c459229c48e8a011696 |
Hashes for stim-1.14.dev1725679825-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c44bc66c531600cc6970ae67e2301a2a9e708af57ac94cfeb827d59b97fb920 |
|
MD5 | 4fd9366f46c80727871860449098e775 |
|
BLAKE2b-256 | 2686f3e3c48f018ef859d1c3e60784e96e304c00ca43bddc2a3fc92480970574 |
Hashes for stim-1.14.dev1725679825-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b9746a67aaa5823944fd0def95eb1d6f12903c65a97728d9e2021ba3e425d31 |
|
MD5 | 9667974038f1e48b2ad4d7a2b30c5ea4 |
|
BLAKE2b-256 | 71b3c4c67f2a11b183f22c6152961abb6537867cf13eb6bf165901183e38a02a |
Hashes for stim-1.14.dev1725679825-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b59d718c7d71180391848c0d81be96146329c46199ebf8eef3a8025ad43642cc |
|
MD5 | 2605f9afb35d022be49c308d4ec7b14c |
|
BLAKE2b-256 | 78aa6d1e125b42468a6d77885bf5af7abf74e67781ecc7c993c542f8f083a364 |
Hashes for stim-1.14.dev1725679825-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f9b30d9371d1f6e19b3bc61e303500e86999026a5889ccf0bae31ff6521686c |
|
MD5 | f004214a7fbe0ab4f47bff920ad89617 |
|
BLAKE2b-256 | f27c04bda0523061916cb929c8cdc7613bfdd961c0922fc45fe0703f4695a685 |
Hashes for stim-1.14.dev1725679825-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822a647e849ab04a711c3ea83d3d0135f4d194be4fe1f0744c24820279408f76 |
|
MD5 | b28675eb71b421624b7a7fc9de1ae5a3 |
|
BLAKE2b-256 | e746ca6a459a6da99e8c2174a583b55bbef01c0e9895b7fdecf41cb771d487dd |
Hashes for stim-1.14.dev1725679825-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a292f910c0c640652635347e00eaea36cfedb54d3eb045cb1632576888da32fe |
|
MD5 | ad9a45e046f37f5daa5791eecbed5885 |
|
BLAKE2b-256 | 428b6d35f86c98670defb38be5bb866747743ccc0a8d1e9644da38efb0ae8cb9 |
Hashes for stim-1.14.dev1725679825-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb384a85817d48b86358c03bc36704afd60fac0e0ab07d7bcd2c5fe84a970be4 |
|
MD5 | 39ad6182168b421799924c6e278a09cd |
|
BLAKE2b-256 | 071a7170c41fb117e6db6616dbb216349b12400d7b8ae5f97cecd479e0228fdd |
Hashes for stim-1.14.dev1725679825-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc34e11b3c17b5418c4397af941ec0c623debc4c84218cfe61b0dfe567d214a4 |
|
MD5 | bf391fd3c8b73fe08a9ac8badabab989 |
|
BLAKE2b-256 | d2fc950fc828d947836450653323a3df9d4eb098a987c79f83372c35b4d71a97 |