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.dev1723057703-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84a4d381a78f2f888b3bd920faeab10d045078475302a63f9a3c2872c35dca20 |
|
MD5 | 880ecb46efbe96757873a09456b7219a |
|
BLAKE2b-256 | 67af563304ae8ee16a58251583db2a3a9f41194b3c6c759e2c472a29867dcfec |
Hashes for stim-1.14.dev1723057703-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b1c60362c09012fd06796f8479f1bedbaa1d09dd993da0214c85ff221485005 |
|
MD5 | 229c47db4ee97ac438e8e6171e449a3f |
|
BLAKE2b-256 | 2774805082dd0c70f47ef210eeff0a929454a6166b7391e99b47331cab6b08cd |
Hashes for stim-1.14.dev1723057703-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce652192cc012b0547c48515102287629395b836c8f6efabd01249d288c1862c |
|
MD5 | 6f63971548d2730f57d8af9b8c99d6d2 |
|
BLAKE2b-256 | 80ac1e10efa1c6505f22dae488f6a3671d9a72ab9dc7ba741e55044ae0dd0b16 |
Hashes for stim-1.14.dev1723057703-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cffd3fb3558cdef5a22af4f90f24a5bc1c63f81dd3b6cd9442fce85f5d64d29 |
|
MD5 | 36629639d513a1d6dee402b252b9f191 |
|
BLAKE2b-256 | e7b012c7651804fb6c106441069c62c4217ab451e9df4922569fca17ca7e6e6f |
Hashes for stim-1.14.dev1723057703-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fb6634b74d7556fc924de596b4544fd3cbb3c3d4a2e36336936301b4daa9f0f |
|
MD5 | f598a858bce758fc2116751e2385d5e8 |
|
BLAKE2b-256 | f9b4d4379e7d2fbb443c5f9444bb8f89e771cc0f66f76c598814b07bad6f4b62 |
Hashes for stim-1.14.dev1723057703-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76668dfecab54e799956f02c15fc41bdd8bfa6f0d363baf39b0aafd4b22561b9 |
|
MD5 | 4c110cac45fc72af0ebde3174f316865 |
|
BLAKE2b-256 | 2c11637d391295e1c19d7fcdb4a19d7d223c8ba29233abf2f7e84c56b405fa38 |
Hashes for stim-1.14.dev1723057703-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b0a73284e63e3558e43fd608036c522e4daa275d098e4bc8ce665f03ea3a024 |
|
MD5 | e296abcf867cacfb9b0bf73c2eb2f0a7 |
|
BLAKE2b-256 | d8783f3b688ed7238953adcb32ed0efb33db24b93ffa6a724c682b6bee285572 |
Hashes for stim-1.14.dev1723057703-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 011e0bb549f3adafa97641c13ff21d2da23d9a4501256300039811d1ba7960d9 |
|
MD5 | d669ea4fbadc9ebedffef302b5d6ff71 |
|
BLAKE2b-256 | a831f3960fd3f4a7b9ad39e2b9e68b8e8f58ed4fa54e25c5a64f70a3a7e59a52 |
Hashes for stim-1.14.dev1723057703-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21378f99292d12b854c0df2d7989f03e4beef45a2052f91f36d7b1777cf0455b |
|
MD5 | 20f9055d4a7d4ba4c7c8f4eda74bcfea |
|
BLAKE2b-256 | 09501c22eed2b73190bcc7dea8e9e52d27e1ca479984e0ad7732e3e5171e05a9 |
Hashes for stim-1.14.dev1723057703-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33413bdbc35b1e96d4567225b76c80a2506f49855efd65cf759c8ca034b811d9 |
|
MD5 | 04fb2a15125839a52ec2ab15e2b3b290 |
|
BLAKE2b-256 | 337194803c85533f2bc2f7fa5e746c7d915780dc3d1b6ad1d796e9185d03a7e7 |
Hashes for stim-1.14.dev1723057703-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7f1a89bb05af66cc6463576fe5ae17fa58bc90822eb2749252fccebc13c6e60 |
|
MD5 | f6111f9c0f69eaf0b5d959f2191ab9ed |
|
BLAKE2b-256 | 81cdbcec11d3f9f2c049f2c79d45fde570b2c563b71cebe8889817449c3e021a |
Hashes for stim-1.14.dev1723057703-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeece841503271e90a22c87b376699edf0a1f599ff2b5a802955cb1363d62668 |
|
MD5 | 8a79c8dcb9097f4654a8df86c7f99e09 |
|
BLAKE2b-256 | c70a2db3acb91a18500227d606c70993b51600a089d70122255720459343d3ce |
Hashes for stim-1.14.dev1723057703-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ed1cbb1ec5a63c234ae82888ea6491f76d64c4f75c2bc9cb0ca55f2a9df46e |
|
MD5 | c6fcc856370048c1b40703eb16e94a03 |
|
BLAKE2b-256 | 6578bca87f0f3f3e590d1ef8a82674f6e3eb69e956a0aae0f9fc201833de7e9a |
Hashes for stim-1.14.dev1723057703-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acf70353943168754ca4fb81c0476dd79dc334617252f1e89aceda7a9a9cba30 |
|
MD5 | e0c959f554568596d6e2b025559cee2f |
|
BLAKE2b-256 | 8e00c8be5220317ce347fa4992e208947cfe9557320b1a238086db954eb103dd |
Hashes for stim-1.14.dev1723057703-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5675230a345730ab15adc7bcf71dc22ddf65533d430649131b46791c5993247 |
|
MD5 | 647e39f6e36515641542d97fa09e8b5d |
|
BLAKE2b-256 | ceacccc6d847fe69cf5615a3457dbbd29e2f94120f4689f83d82b93a0a36f4f9 |
Hashes for stim-1.14.dev1723057703-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55adf32e2f5888b405abb75930db83b1ed8d969e645fdeceb28036499b113698 |
|
MD5 | 699d5799f03d6434c6bb3cbc63861b56 |
|
BLAKE2b-256 | df5d29d4647d2ebe1d37b0fb66f752da32e2417bcb61c472b272e41aaff98715 |
Hashes for stim-1.14.dev1723057703-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed0da1b0ba3ce0b59f0c79101bab54c6dc34851b24f38686da7d9cadfcd5f18e |
|
MD5 | fb7656beb03f57d234faea1b718c939f |
|
BLAKE2b-256 | a0e0143454bddddfb5758a6f8075bae682d78db46f45b94e5421849e5c7abfd6 |
Hashes for stim-1.14.dev1723057703-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd37e77e0bfeeb41829e4184a441fbb285c9c7a3f0e0e412a6ef2a49fdc831cb |
|
MD5 | d3cf5fd1727fb1a6d9d87e883cea0159 |
|
BLAKE2b-256 | 78a151640e45243368544c88a2a177978f252a7f15aeff2687df2c694b0d72cc |
Hashes for stim-1.14.dev1723057703-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1117bbc9a892d2668b58740631444bc26a673250b6664ae16de0c39b3db757a4 |
|
MD5 | 04d52bb8cec20146b9ee639d5bbb5a87 |
|
BLAKE2b-256 | 4038cfb86a19beeac925abc1bef9233c740b40a9363bfff69bfaa4c655afd38c |
Hashes for stim-1.14.dev1723057703-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c383f696f129f5c13fd18400094101571b3d706d658615229d4360eae42d3fc8 |
|
MD5 | 5b86d09bdf3a550836eff2e3bef8b044 |
|
BLAKE2b-256 | 47846f495b538fb61ecc4ae97dccd3ca6147c60ca2d7b073e69cdc70d8fde014 |
Hashes for stim-1.14.dev1723057703-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5005a524606241e6540e6e9624047a031ad5a557626a6c91a31565b46f2341f2 |
|
MD5 | fb64b3e03d6b56b886000496ad26d74a |
|
BLAKE2b-256 | b7f03d4218a117d6484e8459657fd6fd59eb01fbfd3d68ec023cb4ec6809675c |
Hashes for stim-1.14.dev1723057703-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c1027255d21bef93408b110a02130bad3eb964407d92e0bbdef1faa8c6a8e09 |
|
MD5 | f070a08424841306d05438fabf314ab7 |
|
BLAKE2b-256 | b9cfc08a9c93c11a4a9a034a6cff2a0f8cd68d5ec6d455e6bb13862f6a87de3b |
Hashes for stim-1.14.dev1723057703-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 261a132b0819c238bf8d07d0d392e9cdcb4719b1a3eb016304f0fc5a33920446 |
|
MD5 | 92771c076fbc91b02869532815f2e307 |
|
BLAKE2b-256 | 85be7903e386362ec618216e4cddfc11f0374274ef33ca6596d2c1f2d18ddfcc |
Hashes for stim-1.14.dev1723057703-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08cb6e86a5915ee8e6a1f9eb0c1b103463aeda8a6e058e75c015eac634d8b5ae |
|
MD5 | 046ec7f2cf4e8c3caa5d8117f1909c3d |
|
BLAKE2b-256 | 77523a45971d24e8a1f87a72963ab357596b2e43655a107df36b7f68ee5e43d3 |
Hashes for stim-1.14.dev1723057703-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b57168f951d10ce251189bd59e9f33df36dcbf9f1346382d78b1ecf36eae5d37 |
|
MD5 | 39460e356ed60e3285daf6b994506d2f |
|
BLAKE2b-256 | 18358ac5998297a58d119010fe0bd54f6410db4b8f3626dc51db4f33098a7d6e |
Hashes for stim-1.14.dev1723057703-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33960082e48f14dcff4a98b1ba819623450206796af70b2815503a536f799f9a |
|
MD5 | 7458340dfa091208f2f724715e60ed34 |
|
BLAKE2b-256 | 5a1cd4461f8357fd5513e46c842a327ca341c56b847345171758db487e95a774 |
Hashes for stim-1.14.dev1723057703-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad682d6e497e1b6fad709949e451b9ed352734353239918261bbf3c07bf0311 |
|
MD5 | a06b304fee87db3699e894be64d6f7e8 |
|
BLAKE2b-256 | ed331905fa6b7e2aade18f07b7197b872488a3722052c41aa3adc8fa2eff8afb |
Hashes for stim-1.14.dev1723057703-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae0d3112a7a2981572ebaa6ab62aaa1c499363656485b008b49ec8d9233471a |
|
MD5 | 78706d7047d373089d1e62784b14c9e8 |
|
BLAKE2b-256 | 592a928eeb735dfd44c61a91170682e693cf874e12bf415237a76426ec0a068c |
Hashes for stim-1.14.dev1723057703-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68bd09fb653ddbe652f7bafb8eab06a2d1d5139e6375f13f7da175d36322518 |
|
MD5 | 96155a8099fc9e709209a6492a11edc6 |
|
BLAKE2b-256 | fa929dede65c549ca41cc66b0da7c4c203e70f07e607547403f97f5b3247eac6 |
Hashes for stim-1.14.dev1723057703-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db0f57bc17e7f859c38962cc595acad3a6c084da7e900fdb36701950afb14bd5 |
|
MD5 | 979342b4e88296cbb03823f4d01776c2 |
|
BLAKE2b-256 | 7285a2091e45b6025f2e722c5a46bd9e1e9c9949c011893d9affb84aa0bf56de |