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.dev1706081724-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f2285a8c3366feff2d45d97c7e2dbbb12aa85c93ba195511f11ab4ce0321cd |
|
MD5 | f899e0a83fc82fdaa97dfe4c46a88b90 |
|
BLAKE2b-256 | 3578a481eb1a8b2ffe2bf0541c2b1090f0a2f43e5c12aab92cf012d66e45c405 |
Hashes for stim-1.13.dev1706081724-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15f3124066f311015726f31a3820fcdffa57d734a8965e4f078627986f7f878f |
|
MD5 | b3f382d977c3325c7dba5f69b8c5a659 |
|
BLAKE2b-256 | a6fcd29cfd858ccebeba5c9a7f61daa1df3748f6d77f3e83d4b211f01e955007 |
Hashes for stim-1.13.dev1706081724-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e1a767432554bcb12599c3d0ee9625ead003ee2093746c7f0d22101896b7c5f |
|
MD5 | 8f241184c1a7f0874b6ef8b3b3e5c9df |
|
BLAKE2b-256 | 61d9e361484f1cdf42b7ab28ebeaf19c9440919da001553a42e7d5b9d657610e |
Hashes for stim-1.13.dev1706081724-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6152617549250ee0f9fc45681162e4cd9a9190601c163074f6d6c5f708805f22 |
|
MD5 | 6642ccc49126b33ab67ef2c486ee50a0 |
|
BLAKE2b-256 | 47f467a43b69d9a5e7c5bab2ec0f8ffcd6173092854f324b0274e3f79d43bf4f |
Hashes for stim-1.13.dev1706081724-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc52a7347f77209d3c708d8c95a0a043bf95c2a2f4094aacf44cdd2fb210fb1 |
|
MD5 | 37ed37a173eee265564b5c862ab749e4 |
|
BLAKE2b-256 | 465416829af1b5400b6988607fcbabdaeae98604206fcbc94c310cde68017a7e |
Hashes for stim-1.13.dev1706081724-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c750dec6948f86cabf1df28b0762a20a6dc108425619cb136e84bb1827376302 |
|
MD5 | c81901fe255dd51a1f21303144516459 |
|
BLAKE2b-256 | a8269a9178f21aa43a4ab6d4a71856322a170f7a3d345efa9caa5df13adeb12e |
Hashes for stim-1.13.dev1706081724-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a84db94355047bc90efd6e722325c5a5436dfe5a9c52543a41e1a7780457f10 |
|
MD5 | 8e068a54d377047cbae6558b6a358dad |
|
BLAKE2b-256 | 683aa04890214503ccd2d9cc2a48d5fa7f944c1b3a72b5b1d16c0c77a8e426b3 |
Hashes for stim-1.13.dev1706081724-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 584c409c9e87759bf2d65fdded7aad83977b1c61ee8d8973b5999dc74cdbf93c |
|
MD5 | bf0178536260c148a3a6a6c75a91ae5e |
|
BLAKE2b-256 | 8a2585cc9a78f564a3c97018caa9550e8ee6f930e6f9ee3af3402de08f4e186c |
Hashes for stim-1.13.dev1706081724-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8baf8fb2033b2f52927d2cd19423a3eb2caabfa987ff67acfc6e9e2a880e63ee |
|
MD5 | b78c1b6a79477eb955137cd20622a4cb |
|
BLAKE2b-256 | 21fc7717639e29c17b209f316e324443f2934837d7c66cdf6c66871771d3a971 |
Hashes for stim-1.13.dev1706081724-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca4c595f242a4c24cccb50ea5aae76c1d7615d69c9a1976f96c017357e7d4b6 |
|
MD5 | ce8924647102f650b501fb9948f1c01b |
|
BLAKE2b-256 | 51f4600fda79d977c13ee4cfac226f2cbd3758aac674f3536155cc088f15e36f |
Hashes for stim-1.13.dev1706081724-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea94fd69c96835c739b3e2dc482f04a4d357f839405d17daa97450708b6679a |
|
MD5 | c5b86b23e3559e8c8a2cef09ed60ffa8 |
|
BLAKE2b-256 | 7865b11fb2b5ea64ffe4e1a80ddb4dfd69023602f00d2c1255590f35cead70c2 |
Hashes for stim-1.13.dev1706081724-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6883e746cb64aa510ea447be4f55108dd272f4f95a386333422af756115c621 |
|
MD5 | 9aec21e9c5731326a5d2d2098b1f5770 |
|
BLAKE2b-256 | 5fa95238a578a61a1646951a6116963ccd5dba9184ee2a33af18665eb3a0b14f |
Hashes for stim-1.13.dev1706081724-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12dab226c19b8b77dbef8d6a109a6fb2f6e9985f28dbcbe073b7928658463200 |
|
MD5 | b1c313ac81165f0a86877f4ed4c01ac0 |
|
BLAKE2b-256 | 8ed2e0f18e4233e8b361bcd96cce4e6c73aa0c63c351d35f6df2dd11f0897912 |
Hashes for stim-1.13.dev1706081724-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7d22a7b57976914ffba037babc744e9c8f4051d9f486b8ad7df53d001267fe |
|
MD5 | d7420c9963236b3c89707e406d9e4362 |
|
BLAKE2b-256 | e451e9400b3353d287fce2ee4c498a9ba46b87321b6b4c9e5b5e78cfd06f34f9 |
Hashes for stim-1.13.dev1706081724-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaebce2df04cbf7feca1745d73e2465f60ce3daa0275cd80134bd8a9fde6cbf6 |
|
MD5 | 3ab6a49267f52f0c0084920f203a019d |
|
BLAKE2b-256 | 2da240aa6d8714c5f171f4e68fcb4452f990f501d6a0a17c26421c1ea6971fa2 |
Hashes for stim-1.13.dev1706081724-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395fb8c7ebed32396ea838d6195d50b9139fa84a8020f972d14a842dcbecec77 |
|
MD5 | c7d1c9a4ba5235bde8d0a44485e84319 |
|
BLAKE2b-256 | fe60c8ab2ff3633258849ac31be38389b475fbee28d9bcb4022729f9e87c9a6a |
Hashes for stim-1.13.dev1706081724-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 722848ab2b215cbb6f04edc09dcd09226748213edde6aa930359e1f7aade2639 |
|
MD5 | 8bb965a385ec5713159a6d790032d4d6 |
|
BLAKE2b-256 | f9de67b0f15a481fd9ba50ecc27ffca8de92640978646e1b0d4f8c5941da39f5 |
Hashes for stim-1.13.dev1706081724-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f6d27c4ec9b20d29b5a4cc31cf69d0e287ad0a4be4296f9653e83dc0caad566 |
|
MD5 | ad8aac44b11062a2d2f0d0a5552af0d1 |
|
BLAKE2b-256 | bb76258af3c84e18e287f34b605296701d54daf90722f9ce3b0bb54cf81ffcec |
Hashes for stim-1.13.dev1706081724-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c99e3e30cc5540a36b43cf8f9413594198c7a9759f8ac378922bd7fc919dd20 |
|
MD5 | 97fe3e6767b234f62306711cbd8ec6d9 |
|
BLAKE2b-256 | dd238589978b19b106f4275ce747bb8637dedbdf3f480b30620a1fdfc3c6b356 |
Hashes for stim-1.13.dev1706081724-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6459138658671d48f09bb0f61e1345eef6617f1871c31a39ea479f7c1e82b1e |
|
MD5 | 53b246d9c747a78c24288c00f02ac47e |
|
BLAKE2b-256 | 6353fd11d82fe1aa1110e0380ec832f27bf93da57912fae5c8b081bce6cbb576 |
Hashes for stim-1.13.dev1706081724-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31dd2394dd61fb5f7136cb3e5e7f9431d116692de0f95ba2114ce88f946e87b5 |
|
MD5 | 499d72e2c74e9f8c4fbc3046275edfbe |
|
BLAKE2b-256 | 662e7483808a00287a2bf799c1e6462d45191fbda93561db34654397696d85e7 |
Hashes for stim-1.13.dev1706081724-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2be58762bae4005569fa14641944b9c17a1ed50710e9f8bdc3eedee1a00d7dd |
|
MD5 | eeb8c4bb5c089d1c9c9b11daba7a280a |
|
BLAKE2b-256 | e8b5492bbcab1c109d38d211d4901afca153a60b636e1d56ea738f6971e53e22 |
Hashes for stim-1.13.dev1706081724-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c88d11759290828dacfa529bca79780744ca31f95611e7a83c05bdc7ce2983d |
|
MD5 | 5cb6243f7ea2862ea8ac8b7b70fe5adc |
|
BLAKE2b-256 | ae2ecddc67d3a5a85472b36f0f4f84d5377193f3b40023211a2b1fd5ea77ac8c |
Hashes for stim-1.13.dev1706081724-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36647b9e2e6bcb1f501ada342b29d1131b434292faa6ebc5c674a88c9e2f31c3 |
|
MD5 | 702fefee1138b6157219c204f72bce2f |
|
BLAKE2b-256 | 9345ec002106a131513401254f816ae76c309afcf4df70a9d4a5ef76d509ac35 |
Hashes for stim-1.13.dev1706081724-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b9e53bb7cf5fef4ad966f557499b72919b1693ed80d0c887e49fa7c41f1b662 |
|
MD5 | b91bb863256e31ef574f4ba8c191b4e3 |
|
BLAKE2b-256 | d6c49b7f0c59eb7499c0b473e65790b11ee7bc3182b9b046c941a24bc66fb2db |
Hashes for stim-1.13.dev1706081724-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abc9d9e13c79a1af892e7e0e2fbf75c34795ff06d553d32f334090065323eda2 |
|
MD5 | 2cb29e29cee3f6735b3981d8ade5b881 |
|
BLAKE2b-256 | 738325e93e3e2410658532167dab24e4bcce07d1d7db97cb5d12cc52a62695d5 |
Hashes for stim-1.13.dev1706081724-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ded736697513e1516de34acb4569b30c51d87aa13c79ac2b9ddfc811d13113 |
|
MD5 | c0d2838415f62797ab1c15aa2e1b5621 |
|
BLAKE2b-256 | b61216dbc5e1be1e574b2fe6a93095b46e981aee388b8268623cd581d4d1ac5f |
Hashes for stim-1.13.dev1706081724-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89ccccb7ff141e1ffd4d25e96195f0ebb42a55acbcb79a44d465e80fe1878d45 |
|
MD5 | f9533c35e0ca8f7a9807f59eab1208a3 |
|
BLAKE2b-256 | 584530614c1f67c6b365c9d072a3fe665a054335c99290d94d755c2e4ba3cbf7 |
Hashes for stim-1.13.dev1706081724-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e76cefc631d291f5108870e1d12c7bec6c3931e56bbd00bbe0ff271d0803f600 |
|
MD5 | 595fc86fd0b648bcb1357578161f70c3 |
|
BLAKE2b-256 | c2630da16a83060e6c82d1198fd3d6f1f581ba4e79a4bd28c3929634a60303bd |
Hashes for stim-1.13.dev1706081724-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e642f36b53529af143924e26b283a0ca787cd5448d8525d8e8f7f785c2bc5c6a |
|
MD5 | 0121124da3cace5820a606a683be8159 |
|
BLAKE2b-256 | 539c1b8fdf109a4c11e0a37fa8e845eb79db7f3cbac207fae93390657236fbd0 |