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.dev1724712001-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6817698b182b2e9fb51e3198a03f2bdfc987d565737b10281fccaf443ad94e04 |
|
MD5 | 96c063a0f05ec9e5b0eea368511306c2 |
|
BLAKE2b-256 | 792b3bdb04cd66523e9c808b7a726a0bf8d7150a5fce551a9a3ffab6771de5e5 |
Hashes for stim-1.14.dev1724712001-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f222d08279d1e772fa6407c5e4899e61768e10fbfbcca487e6b259d193912422 |
|
MD5 | dc098095a9bf6dc3c2527af3c0691b45 |
|
BLAKE2b-256 | b5d6aae2dcf22d5c8d0634d908ce3434915dd692cb52ea883bffe3a0466a1e28 |
Hashes for stim-1.14.dev1724712001-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7563bffd925b6a547b60c34d8e7e175d5556f03ffc27b1158d2feccc97b41f82 |
|
MD5 | 8afe21b44df8b89a20b9236d581a9c85 |
|
BLAKE2b-256 | b730dfbaa224ca8dccb21a48a1c99a10d7babfb790c5f67e72213b8e543f5ce9 |
Hashes for stim-1.14.dev1724712001-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f018a3648ca08d766a6e12cd6c22cab90cf272dbc1d671565157e3d7b821d1f |
|
MD5 | 5bbbac764d5d77bdab855a7147411f5e |
|
BLAKE2b-256 | d9f74e61698e68f2eeaed1a55935a5a6e7b792d07715c00ac103aaa15a21c793 |
Hashes for stim-1.14.dev1724712001-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 539f20b7a09e3b35fb9f176c3d8e6429a7080096071dc18091278e073f4279a8 |
|
MD5 | 1fc02227e95462db9a149be33f6c56ea |
|
BLAKE2b-256 | 99776096866c6e825278bbd73d90be769db640f5501c0993cb81d509b5e39259 |
Hashes for stim-1.14.dev1724712001-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c694c394c29fdca61cd36e9eb17887a686704d2e872493091bac3ed93ed910 |
|
MD5 | 1bcf3bb496def9acf1b7ae53a98cad37 |
|
BLAKE2b-256 | 1a759793814f43cdc1fae71e640a71d4bad17d656aecaf2781459ce42d3d4d84 |
Hashes for stim-1.14.dev1724712001-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4c45dfe956b9de6989da574b3b4f5e6d17166e08aab66212f68d8e8801b3e4 |
|
MD5 | f9103bf017ef5b65f874dda3669fff3a |
|
BLAKE2b-256 | ae1c043521f98243d4a2b3c469f6cadcb427df20ad275aa5346c9dee2b46c3a0 |
Hashes for stim-1.14.dev1724712001-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8789a3929ae89188c31a124ed461737d279b49a382c17bd5f642e63a8ee5f922 |
|
MD5 | a0f54e1568ef054c377b4f35619cd007 |
|
BLAKE2b-256 | 0bf3f7a0cdf9be3fb18b21c24955daf3a547c7e3bc4a92a3b0d07c1e7faa6f4e |
Hashes for stim-1.14.dev1724712001-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 215c6a064b7c803e7aa03a24b0af336977fc3413eaedc89e62026f5884aaefa1 |
|
MD5 | b33aa9e35143391e4cee892778ed3766 |
|
BLAKE2b-256 | 0479698346b1fedd4a89de9bc466e769af6f6135a94e8e09577951e81d3f168b |
Hashes for stim-1.14.dev1724712001-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcf74527adc7763cd881cc1d0f5a3e0ac7b0ccd12c384de2393bf05a70906a45 |
|
MD5 | a5fd0ad2270b3ab18b71f2bd6d7d5306 |
|
BLAKE2b-256 | 9220230b69951fb3d306405fa2948f96c1f011f455acb2b5f3b8e4e271ab9766 |
Hashes for stim-1.14.dev1724712001-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3da724aa4a05b3e33fa2d60b29cfcea1c94e2123587962448cdec819c5008de6 |
|
MD5 | 4a80e6519f70460e28f5fad565a4fde6 |
|
BLAKE2b-256 | 3454388cef16962d1df5fcfb6bf6cd444ffaed20b3383da603b0197f5b854c83 |
Hashes for stim-1.14.dev1724712001-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f449ead3001d04ad300c0d1c1ed1d36bab2585713f7d7439bd6d12d1829b524 |
|
MD5 | 49de588d0ddfec51b9bca50030dae190 |
|
BLAKE2b-256 | 3ae57602dbffda401597be13608f415e23d16f57793977d968e6e788142e50aa |
Hashes for stim-1.14.dev1724712001-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16287e8fee41d189b6e37bb4e99e0a77d0128e84f14c000351f3dd73f64f0957 |
|
MD5 | 97bb24252ab71bf41659937ec33c2e0e |
|
BLAKE2b-256 | 2470a6db25fee107f3d246b6dda5a8a81afdbd8eaab6d9481bdb1828720b3d0c |
Hashes for stim-1.14.dev1724712001-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cdff856749d23f09d2d41b3d8291404e61af1da0ba7f5c55bdd0bd16777cac1 |
|
MD5 | 38d9dbc08424aeab17e8856f0759623e |
|
BLAKE2b-256 | abd41476aed10ce1682b9ff595f456d6ded9baa34192c2587b726b1a0f1bb2ca |
Hashes for stim-1.14.dev1724712001-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509bc62907dfd0ac7ef164f8af04636a07d88d63307e119a9b3acae6ee82a59e |
|
MD5 | 0c496e9584aafecd406a27507d3f6825 |
|
BLAKE2b-256 | ac66fc8c48768f716f681f9aceb8524a926cc0832551b048d8009c9630c962e9 |
Hashes for stim-1.14.dev1724712001-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de5908799316b5c181d0494131b230d98a8b5ef3d0a65efb365a87fe86accc36 |
|
MD5 | a2cbbcc787326718a0e71f7bf265aa6d |
|
BLAKE2b-256 | e0aebcb9ab2479ee612b13d259187b800f88a1772236672acfa8d3a7bfd657da |
Hashes for stim-1.14.dev1724712001-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f711848f73c54b379c57ba3ec605f48032448e9ab4d993a478af267ff138f11 |
|
MD5 | 5ca8bd8dcf144af843d015c42c790191 |
|
BLAKE2b-256 | 0a833d9594366bb1b25a0f95923b0e33c3524cd4c159c11bca1922fd21ca16da |
Hashes for stim-1.14.dev1724712001-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d4fff018031328d34746ba1fe8f658040a984ae30408db7f301c0f08b494926 |
|
MD5 | ce05c8ed6cb76cc308bc560b2a685be7 |
|
BLAKE2b-256 | 1b891c0cf78791de85d308a06d6799ab11f3b78e5d04de1d5324b1f195541708 |
Hashes for stim-1.14.dev1724712001-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 749016dcbfb962b5336ef001739aba77e0ec8e731fd1b0dab62718d0fffd3200 |
|
MD5 | 17798dad86b9f45cfa4beb09a06dbfd0 |
|
BLAKE2b-256 | 8c5739ffb079ffb07ebfaac95eb01b931bf5799ad44bb0d29a0280408581a208 |
Hashes for stim-1.14.dev1724712001-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca733b580df59e11a460fe89bd4caf1d46e1eafe3609986f7cffbd9ff4ed38e |
|
MD5 | b4ea166e9a458c3861eb0dfd7db61983 |
|
BLAKE2b-256 | c643122c238e9baa8632dcedd9e969f78aed993c2363070fc7ddf63879f251ce |
Hashes for stim-1.14.dev1724712001-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 694b3584dca2ace27778754957e2603c17c05029f52eb2061e17a38e31dc4a73 |
|
MD5 | 6aa2a2e72bde9de176e2bf49ee1bc7b2 |
|
BLAKE2b-256 | fc23f21634ae988a1e4274b4d98ed66b94e2f0cbaafce6645bab912126b5d0e3 |
Hashes for stim-1.14.dev1724712001-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c198b7245be3a3d9cae9dd2dd74ba14f3fb73c75dbc52457d3daed0f81975bc |
|
MD5 | a1fb16b34a09a282acf48d0dcd28a6ef |
|
BLAKE2b-256 | 29fcba76710728a03b73910f10333f4f68686f4211aed5c5d1d53fa11beb042c |
Hashes for stim-1.14.dev1724712001-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a94da3df0a7d62f47053efd6f096f00ff6271c526127a3edd7cebcbd3f94f732 |
|
MD5 | f405ef5dc17dc43d5ad64b7622b29eea |
|
BLAKE2b-256 | c9a658bbd9980e6d1b43f8c6c82b2be9e78010cd36e879f44a98b45d752a4962 |
Hashes for stim-1.14.dev1724712001-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18f9dfa695b4ff8424a118bcd2aa3fb58fe8be6350a49c3a6291e228252fb19 |
|
MD5 | 72b57f428d1ebd26041154877c5e29e8 |
|
BLAKE2b-256 | 4c236df069faebd54daa7f3cbd7b4518ea1b4f36937ce269c557644138b2a56d |
Hashes for stim-1.14.dev1724712001-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d802ca4ede5d51ad048130e5b03e8ddd5d0fbaa46724f11ad497461321f7bf2 |
|
MD5 | 87ff1906dd2bf1185fb73c6678802d6f |
|
BLAKE2b-256 | 8b1a8cbe501aa340d806583720afcc107f41d5e771d6653c6b9a36715c3923bc |
Hashes for stim-1.14.dev1724712001-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf2a87f79988cfe4e70d024803604259a54939c72ee6828e37ce7646d0a7f6d |
|
MD5 | 2781937cfa0fa28bb6a09a4b5640b9e9 |
|
BLAKE2b-256 | ae0e19f77a57792e489cefd106faa20fee5fe88029f60e4ae32daef52ceb0347 |
Hashes for stim-1.14.dev1724712001-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed3b3a1fee377efcf240579e4b2210045fc0ac5bd21f42e5af5bb73a7c2443d9 |
|
MD5 | e9a0e225c7f4b5c2cd160915e8518229 |
|
BLAKE2b-256 | 351addea1317e32080823bae6658d4f4bcad8545cd8429112c856b30c7647425 |
Hashes for stim-1.14.dev1724712001-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8fa695ab46afcd5e49774946747a6930b7f3a656bb09a269446b230b324c07 |
|
MD5 | 83b1960b8200ded793d42f370961d3fb |
|
BLAKE2b-256 | fd4b0f51298d680b64080ab8d878d686d64d2f872ff1f863a3c0a944a0aff3b0 |
Hashes for stim-1.14.dev1724712001-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13176f31079264234dc47fb8796d6c094dcb3ec1715f4966eb4bc42706560546 |
|
MD5 | 48198b950ead7393f59aac5370b487b2 |
|
BLAKE2b-256 | be4c217cd3b3d1292556f677561f8c06fa91013967b118a69579a2be70847a0a |
Hashes for stim-1.14.dev1724712001-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1de33f77420c40b01ab51370c3706a20823f139ba55ea728ec723bd2993bcaba |
|
MD5 | 0545d528f5ace869113a247001397af0 |
|
BLAKE2b-256 | 4467587d099bd6ae654f6fe289c6227a0c0321ca18a9eee9eb5e27d7db3868d1 |