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.12.dev1686545420-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4030d29a844c478ce9abf223e45045a9f7a0ca38ee7de036892ea46ec347f329 |
|
MD5 | 956c6973021cab5aabea96a3010dbb1c |
|
BLAKE2b-256 | fab511520176acd79d6cd75a7221c1811a4e43c8f70c7a51cea75659c20a608d |
Hashes for stim-1.12.dev1686545420-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 194a66e73174168d062552c7ab48264d32b07e515b660d2a2145cf383a290fff |
|
MD5 | 6564d402dfeb834658d1b1335facd68a |
|
BLAKE2b-256 | 45efcd3a1c6da44afe75e6bcef5138d1b578e183c55a7e1a3864e695002eb0ad |
Hashes for stim-1.12.dev1686545420-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f31444020ce0905b0ff7044b1acbd870cfddaa59684980cc5939bd0cecd6fa |
|
MD5 | 78bfdd08a909b30ad33be847d8e2002e |
|
BLAKE2b-256 | 0bf1553c0c2c506dd5064d9a4a1a3bee7358898aabf3a7d3e78506621d7cce75 |
Hashes for stim-1.12.dev1686545420-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3357770159e40311b5b0da226d40314650afa1d5b3de2149d64f7ee6749080f1 |
|
MD5 | 7cad051e503785eb6e7cadf2fe3ff142 |
|
BLAKE2b-256 | c52354ca73a48f5aedad338d687d05784b975f1a396dec5b2077dff3440fd986 |
Hashes for stim-1.12.dev1686545420-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e9fc7eddf6a84e24e883eb827bf50eac7ab4d2decae69b57b772fbc2ac44286 |
|
MD5 | 8214ca6ca44b06a298ab4d495df598b5 |
|
BLAKE2b-256 | f0237994055a247334fe6261025e2066a8b47d655d809fbd3b1e5bb76794bb66 |
Hashes for stim-1.12.dev1686545420-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dba98167948e3d032cfd8a4f8a37c70b7126853e1cfc1c9797de15b3d19dc4af |
|
MD5 | 128d40bf80e01a81349e85f08baf3377 |
|
BLAKE2b-256 | 7c7a04fc60d91f165ca154faf1085eb626a596f51d855fc1cf5ef8856bbb53d9 |
Hashes for stim-1.12.dev1686545420-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 254c35bd8d82f02b3691c99ee526d6633aeb0ef99b63bb3d37df849cc0afb734 |
|
MD5 | ed81e00a22411e3a312dc9ee854e9537 |
|
BLAKE2b-256 | b37015ecc145d84df05457ed249c728a938656d8b01f4330fcfe657923d1c466 |
Hashes for stim-1.12.dev1686545420-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a32fc90f8accf119a30e22fc3272d57e7c28afbeaf0e6768967ac4efd8c4c71 |
|
MD5 | 26e0086580c9991a7fc33e0fbebeb65d |
|
BLAKE2b-256 | 9e3f54648a3b708d3b8dd44be581210f207812d3e36270aee74e515a4570ec0a |
Hashes for stim-1.12.dev1686545420-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08ea97db9e65c4e36a784973a4b662992fefe18849f0310d232e0dda5443f434 |
|
MD5 | ce0a078f2d399c308a46bd54b442e559 |
|
BLAKE2b-256 | 6b401a5f22f2c7d7f96826b3f3d7ab573b2acb91dd965bc53f0ebd97700bb105 |
Hashes for stim-1.12.dev1686545420-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15f66007c7b7f99b70702543789ffd752962f71c4b3487d9a36a9ea06095692d |
|
MD5 | d3181e212fe2fb50f7369a73463affea |
|
BLAKE2b-256 | c82edae707d40ca26c9e211ebfa2fa174558c0dcdd67a1378387aa93068f4a0d |
Hashes for stim-1.12.dev1686545420-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0200871af0987c1506769cfa3359ae679f348fa2f48a9661f6a76a2ec36671a6 |
|
MD5 | 7b7ed9f9a7eec8176b45facb37f2f807 |
|
BLAKE2b-256 | 366cffc533dcad1021570db33fb0c94e23861e75b9fd03db5b38fc9b3572ec54 |
Hashes for stim-1.12.dev1686545420-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e04e9db47508eaa4f3fd557cf5e92849c97d937ef530960a087cc2854f7fc548 |
|
MD5 | 46d5772afa082fb5f07651d9a687eb38 |
|
BLAKE2b-256 | 18b537959ab79edb6d7c68318f07788067420a70bcb443ca42699812483606af |
Hashes for stim-1.12.dev1686545420-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ecc1b7055ce2858089f8a0e63a125dd5a7fac46b46f5027e5548c02bf182529 |
|
MD5 | bdbc2de6bdb1f9ff4ac31e0077ca03c5 |
|
BLAKE2b-256 | e5644a9e30ae70a9f3765da02089302c23a9c6326cc2aed31d333a5dedba71f8 |
Hashes for stim-1.12.dev1686545420-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fe5ba78d818fdd39a4b9188804266a1f9924eabfd2d83941a1e21b27887495d |
|
MD5 | 1a590baa3e594cf35565727d6d19bde0 |
|
BLAKE2b-256 | 0bc66a223dfaa77320592565a48d7d1aade34021beaec04b28a1b53e0b6220bf |
Hashes for stim-1.12.dev1686545420-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dd188f52d3e3b0d4c97ad49bbc26d59e2951d4b94917c3a30be7fe2f713f5b9 |
|
MD5 | 6134758a8667d8ec8d6b4539642f027a |
|
BLAKE2b-256 | 713496fa7855ba805ebf8152f992b13509edc5b1d62a6d0a8fcae118dced9838 |
Hashes for stim-1.12.dev1686545420-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcce223f4f3dc8ec506dbe188ef0868ad6572f5e8b4b289403552dbceb514223 |
|
MD5 | 2a74d42b8ebb309d66bef25ac9b64634 |
|
BLAKE2b-256 | d5c3f1952e516f0b22b43fd4f880eddc1a08edc85b5e0ca22505a0fbd9265227 |
Hashes for stim-1.12.dev1686545420-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf346ddf633b8f56a3cd5d5e09a3ba6ea9eefb6da42277cc990c4d41a429af73 |
|
MD5 | d85fe20e993d4501d3f16b02225ee82d |
|
BLAKE2b-256 | 58b21791c097aa16c621e992ef242d1c2d702575398a9c8fa570169cc74cc2f5 |
Hashes for stim-1.12.dev1686545420-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b7669ec63c32439831f7008dcb954d7c2fbca483a0ff3c4e05682f5c44d51da |
|
MD5 | 3319c3c2f8ba0a96cec4d4063645388a |
|
BLAKE2b-256 | 638ba440352c86b8d4e913dbfa02b25fe3c3e9819e1951753c978b0bcbb393df |
Hashes for stim-1.12.dev1686545420-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b336408fd97b5d3726c400d8b03a47a73a0f4e5ed0e94fe05951e33e4f165d6 |
|
MD5 | c57430098609ba61872a75d97deb4049 |
|
BLAKE2b-256 | 13acc9caddeded659bc959fbe6a1a8a0528801c2018cdb6f6ea2a6ba8408e5de |
Hashes for stim-1.12.dev1686545420-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36a11a60f727b3c929a5bb57ffb8bd38830c36e0f869dc6c29fa995a9d4b4c67 |
|
MD5 | fec0d577d114fa0119ae59642058e180 |
|
BLAKE2b-256 | 7b52fe8d45d11ce4b655a9227cbd9797b2efbdf372ed25b7a79053eeedccf9ac |
Hashes for stim-1.12.dev1686545420-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6acaf4b353cd06f770004266f50c8af36094ea3ff505dfe1c0c1e743dd39889b |
|
MD5 | 885f6268528cd7a267e63cefc8a08ec6 |
|
BLAKE2b-256 | 02c979c560c198586793444fb8b9b9b58514a5b044922caa22499b00f9ad2a1f |
Hashes for stim-1.12.dev1686545420-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b3a188629f7dfd296c176645900501cd9a35df4cec541ae336c8214c2c1bbd7 |
|
MD5 | 75e8d1d38003253d26a59a676f282a4f |
|
BLAKE2b-256 | 413890c7c3631db389acd0818f0b15b96618ccaa896c7bfb89812f5d101f5142 |
Hashes for stim-1.12.dev1686545420-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf3b9ea35a2628c4173c23a5fd91adb20e643f6d4684af7de9cbe8a82e06498 |
|
MD5 | a80e69d6ae63497841ec9b0459c56959 |
|
BLAKE2b-256 | 4b8f0f21c2fbe58d1860af1ea31cba08f591cef1d93558be83036e4664264685 |
Hashes for stim-1.12.dev1686545420-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729d28c13cacd41a88aed12fbad4459949b9446be6956fadf8e7c8e1fbb9258b |
|
MD5 | e13658c31dcb1f4715a05747e22c599e |
|
BLAKE2b-256 | e264dabd7ae64287e49e318120e71445f7d0af14cdaaa5f8e50c5425cbc76d5e |
Hashes for stim-1.12.dev1686545420-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e45a2ff0ccf866391f4d1f01a40e9a5add9af239a955e6bcdf9dbeec60036f41 |
|
MD5 | 7049b7ed47bd59197ac17e3a8395219b |
|
BLAKE2b-256 | 754a433ddfce0546939e71f45f427e58f357ce988e06b53b357111b40e31b0b0 |
Hashes for stim-1.12.dev1686545420-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6315c3f59694703c0da73e8f85d14234495131395dcf6593f4bf01d80ae582 |
|
MD5 | c3a6061a4a14120c880f6a19ff433438 |
|
BLAKE2b-256 | daa1fb406924f0113d03d65acb4ae47094c4847148863e8ae36aa22d53e370d0 |