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.dev1709175168-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c254a2b7241a94bef60a61980680d043681477843a8ecf34d112062d6cafa974 |
|
MD5 | 4eb9f1fa86c7a0306ef33e22bdf1fef5 |
|
BLAKE2b-256 | 35d0fef9e170bfe829d5b35736e2023bf6a488548cccfde2d4d3dfe223f57a91 |
Hashes for stim-1.13.dev1709175168-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9010d738b9b6117307c25619aae788273b9152b5aafa2f3ae2ae5d1eeeef67f1 |
|
MD5 | 55b31ddbad130218062265a64284897d |
|
BLAKE2b-256 | 1fc7320c360917276bd8f6df417ce3ec9a9e6bd05fdec7a710f06799dfd22c07 |
Hashes for stim-1.13.dev1709175168-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 973d62ab10b5598f7cae7a4b7692e90952f6b4bfa0a0e895c19efc843b8eecab |
|
MD5 | e28f05feb41083b1e54972dc1cc1a12b |
|
BLAKE2b-256 | f51fa1c3819129f4d022f00b9eec0400d75fcc48e73e9bc2ea0d8abf923f1611 |
Hashes for stim-1.13.dev1709175168-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff6e1a40beeb09b09fc5ba05e6d798c54bbc50ef76ad3283699f77d105ed169f |
|
MD5 | 0f0a857c764f6e5b38107edb4f9cd0cf |
|
BLAKE2b-256 | 4024f86b1917c5a73588ed2fb2fb08a6fa3655bf198f0b2c1cf104bdc4dedf18 |
Hashes for stim-1.13.dev1709175168-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 961def1a1beb27b1b877a449b2804f65b453e0001288fb4eeefd68e7fd774d9e |
|
MD5 | 27cb5fdb9e22189aff021ad38fac7ca4 |
|
BLAKE2b-256 | 3a1b13e08de487297a76656f67d3a9381f624b230c5bc00f8e3e68e659db6994 |
Hashes for stim-1.13.dev1709175168-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17e573636da6d40ef51bd02d1521d0f7ac996d23efd0354d27432206a00d1d90 |
|
MD5 | 00be6b7e40e296684b5c153f35728b3d |
|
BLAKE2b-256 | 2a1baaa9817c1e57d8eea956055f43a5b46df4c78147a4c08e8e96c056405e14 |
Hashes for stim-1.13.dev1709175168-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41c75e0a28ad2bc60e9b4cbf472c8062518e088ae6feb0e28c31a754373d36c2 |
|
MD5 | c7644a00c5cd1b9997311f81a8af2c86 |
|
BLAKE2b-256 | 03e8bd3c1d1a720098e167237a835a3dd42e652e056ad66e43751e303b867589 |
Hashes for stim-1.13.dev1709175168-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7da306b2d1036b2183327288d92b0dc199f5cc2b327b4b7add4808a130dd6f3 |
|
MD5 | 32ba73031938f7d735ef458ab07bc3a1 |
|
BLAKE2b-256 | 0e61fde58b187ac3c45ab63910437da3e43127a0140a7635596e02675a387243 |
Hashes for stim-1.13.dev1709175168-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ac7738bb43bc4c395f71ac58c583c8fca7926c2f8430002aa6b22e8e62c577 |
|
MD5 | b9f98b9516bfb301bf5a359a5f72dea0 |
|
BLAKE2b-256 | 1c1ddf5a5d0b1904e1a08f11db24e1799712a3bc53545d05b5a02b61adb0b6c3 |
Hashes for stim-1.13.dev1709175168-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f445f6384988e28a58314fe8650435b25dd239ce0238432a5ec53daaa975dbe |
|
MD5 | 86dcc5ef726d430d5f2ee276262bae0b |
|
BLAKE2b-256 | 4a81263e36685aafd91a4a576f75420c54155c7bf1ba38e16ed491b02f6f2db2 |
Hashes for stim-1.13.dev1709175168-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3a2dd65188d7f2c2144ce362b496c4919807659541e329987b8b55c65dec59 |
|
MD5 | 9f26bb993d996d2813f05ca844c78540 |
|
BLAKE2b-256 | cf11ec91024d72e4a3d7542cdad17bb11ec3cc12794e81cc93ee8d1f03b069c3 |
Hashes for stim-1.13.dev1709175168-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25ebf6294348f281e9e5c24d5e051982c14a0961c5874a4957154e869feb0b10 |
|
MD5 | 429dcd15549b3348500282e036427199 |
|
BLAKE2b-256 | d4e448a062233351eed0ceae48ab4506607e697c1e5303021891aa8004afe343 |
Hashes for stim-1.13.dev1709175168-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69830b0aea91323984c9e35f64b3a3d1c1792712181bec8c17673971a3e64394 |
|
MD5 | aa9154e239a03c9f09c9a4af7e616167 |
|
BLAKE2b-256 | cb075da2cc52cf7ed14201b580b41064e97be62c00a2d9c922a6a6e16bbc5fa5 |
Hashes for stim-1.13.dev1709175168-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deae13ddbaec7d25987a81f2be70d0fb828633735ae6819ba6b9683bdd069e85 |
|
MD5 | 3cde7dff61a4818fa9dd47e288d5e6c5 |
|
BLAKE2b-256 | e7b939f1056d06e8a7aa3d034cc33c96ae9aae275383edcefc2da3af71b154cf |
Hashes for stim-1.13.dev1709175168-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31a6d6f1b5fba1dad467198c01776c18cf287632492f4c3d1305201a146807b3 |
|
MD5 | 5e4533b4a3443aca896c52a9a2d70f92 |
|
BLAKE2b-256 | 73fbcb3690e7b294786f49da5a78f44b109c55cf9e8ad92cb86971aafcd5fe57 |
Hashes for stim-1.13.dev1709175168-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb081459bc3c23bfaa59725c28efebfaa7866db037517b9e4a010823fa76b516 |
|
MD5 | 73bab54aefbed6607b2928bf7e6305c2 |
|
BLAKE2b-256 | daf657484f40b971dcfac4c82243ca1273250a4f0bbde32bc3b5d90c89e14dd0 |
Hashes for stim-1.13.dev1709175168-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e992d5f97f1777a3b989431558e84278198f27263fea980cabdc541ec95e8b46 |
|
MD5 | 4855c26c469590c6f6b3b0ed4b6c3e6e |
|
BLAKE2b-256 | e70dfa1533ad2d3e23298894d839bd4662a16ac9ef7d53cbc65b6ef81fa3cb7b |
Hashes for stim-1.13.dev1709175168-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf2b8dec463eb3957424712f8991ffb67cfc151fa3f606004d960ca44b8f16a3 |
|
MD5 | 701e86bfd06804aeec490114fd255518 |
|
BLAKE2b-256 | 6a769a785b2a00c4d32197167d24f69a7cdb607b3201391be4ab8cf97076dd1e |
Hashes for stim-1.13.dev1709175168-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d34e5cfdec4721683a4048e5df69cf2e86ce9c8cdbf16d9488e0132e5921eb7 |
|
MD5 | d520951ed819e78ef9645d0856a5187c |
|
BLAKE2b-256 | 97c686d8f5316c5d6fee92a547947c73f4046050755bfa80c939ce6e5d20ae65 |
Hashes for stim-1.13.dev1709175168-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02dd98ef645bd160279d44d7d1d33d2f74bb6c657af0088d4a012b66aeefbef5 |
|
MD5 | e98fffbdc289e4b55630de1b4dc49ffe |
|
BLAKE2b-256 | 571dc4ce505b17ab0b19a064c6353f9cb3712e85b1f9d4be476cf7c3b7b5cf52 |
Hashes for stim-1.13.dev1709175168-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d85e41c3818bcf3833652d2172c2ee65b670b055596ce1937b016520b1975132 |
|
MD5 | 26c4a2c059d03eb5dfe8ddd9ef76d5c4 |
|
BLAKE2b-256 | a9da5f4e2b71abf8aea62de01bfc91322b1fb022b573bb0c2466cf8c3c12349d |
Hashes for stim-1.13.dev1709175168-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c472782835b956b8383cbb1ca5d419df9f96329f6f9cf72482d9645ae03bd0f3 |
|
MD5 | 2656e96260e9895f4e34f79230e3349d |
|
BLAKE2b-256 | 64aa11bdd51cc01efff27b67cd1aaa12d1cbf6c500dff5a946855c87304fc1f2 |
Hashes for stim-1.13.dev1709175168-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2a59fc0ff8ba1d856e51818aac37325e93fc06b163f112ce6c7bf43bbb6a71 |
|
MD5 | c3cfaf78d08996c015a1e6f8b7481d02 |
|
BLAKE2b-256 | 9a55112d46de1a4331b1447dde4d4efe86ae1de4db8621a8029d7eba969cd28d |
Hashes for stim-1.13.dev1709175168-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f960253520aa15be74af1d30e92007654bc16eb5687b717e3990984baa8387 |
|
MD5 | 3324044ad07b2b1fb5793bfd48068179 |
|
BLAKE2b-256 | 01d5afb75e98464c432377fd9811e4d566b78feb834dff50d7ea54033bfab391 |
Hashes for stim-1.13.dev1709175168-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b8122c8a0e5072574f19aea59ac9b673f9d3fcefcd9d0e13f0833b8891e6d47 |
|
MD5 | e428717e3c821ef52a1762d08e60bc2b |
|
BLAKE2b-256 | 9c8e5a78d39d434e41213f3b61f24d7ce18530ba16aeb6caecc6264eeec4f79a |
Hashes for stim-1.13.dev1709175168-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 218cafe01b5570046a9bb337a2aa83568e825333cf18237f3d5ac07bfb7fbd0f |
|
MD5 | 256668b865040d24ab38356f62285ab0 |
|
BLAKE2b-256 | 8673e7eb25e0ecc7c5f3e55d074ae5183be1c94159fbb8745c51cc067eac51e3 |
Hashes for stim-1.13.dev1709175168-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c032923137071bc719be8ebf29ef1874984631553c99e5d3ec15082b98bee88a |
|
MD5 | fde73408b0b1b25493e01d41fc6b0d07 |
|
BLAKE2b-256 | 01be6cf467a566c95c600602d6e1e237f29876b6c4836e1ad0b8be13fadcb835 |
Hashes for stim-1.13.dev1709175168-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33ea3f2a5040e1b60beb56f8af6f733babcdf2e07815d3abba95285a8b6ba065 |
|
MD5 | b1a77fe8f87ec3c62ca0497164e635f2 |
|
BLAKE2b-256 | 99a74b7aeaaaa81d9cba2f3179dcccd468d520ae69a2eea0441b9723522234b0 |
Hashes for stim-1.13.dev1709175168-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f49046cd035b552274d1c866bc90d215f51b0ad9860bf32a61c3862cd8826a8 |
|
MD5 | 32c2a3fe601d80b4f852702a3e526677 |
|
BLAKE2b-256 | e1fd26b4eca93d69f31eaca016d6824c81476502a8576d8b629b60b77687f56a |
Hashes for stim-1.13.dev1709175168-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eafd4ebf3ecbb04e2ce6de53dee4969d4cd9400c5dee6fdd3f0e538d306bf7a |
|
MD5 | c8ad2909cff5258a61f928b15f6d3ce7 |
|
BLAKE2b-256 | 0d0328b9d956ab95418cd43cff952d8f03405320558d9408259c3cdc96ad53e8 |