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.dev1692168330-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a35a02522d2422418ce95dbc2bc7ecd17e20dcfc3e0c675b32cf70e3143901f2 |
|
MD5 | f6062a6315cc6ed4560c2b82eefc9b1d |
|
BLAKE2b-256 | bc04caad019fca61a2a75e42761ba00832b839ab830728abdf5f0d2712f8bf65 |
Hashes for stim-1.12.dev1692168330-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee2695a02fe958047b8fe1235bb63a8d281befb2dc5f2e932d67c5a539c461d |
|
MD5 | 052bc7ccf1281fecaf64180fe7e7b83b |
|
BLAKE2b-256 | 55aaa2946e3c323c203ff7253e9a0a2b0a3a27d414bacc98820f6a8421253a15 |
Hashes for stim-1.12.dev1692168330-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4723d2e76cff28f4f984c78692bc2c4743654595776578980ad21ff2b10149 |
|
MD5 | 4a4a7b5ba97fe44faf790bde59bd6543 |
|
BLAKE2b-256 | f3d3e686772d6b057a8409429e2ba110ea1e4a9658c3d77eb52b439c60cb74b6 |
Hashes for stim-1.12.dev1692168330-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 581d69a4c3c9286b23f2b8532a2d8fc6fd5988f7762fe032d6506e09169753b7 |
|
MD5 | c8cbf942a18c555c41f32f502dbb03b0 |
|
BLAKE2b-256 | fcd5d89795e2514f2d5d601eed0a0f3e409cf12bcfe7162772d500c8b02d6577 |
Hashes for stim-1.12.dev1692168330-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d287a2578560223790615dfe3481d8eb70abb206e0208829bf8faf91d6e9d73c |
|
MD5 | 1a99eaee481517db25f696fd061a61d0 |
|
BLAKE2b-256 | d86a975ed74fdca31a28d356ff623392bb27d6b15b0c467851ce9d06906cfa32 |
Hashes for stim-1.12.dev1692168330-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31c5bb03f10a1eea10e881bbbef6479d37585ecaaa3831ae7eaaa1d30432413e |
|
MD5 | 5a0b3b1527cd2ff6d9f4dcb8d7b24fc9 |
|
BLAKE2b-256 | 1c544a6f30e3ac3390a5a1725f75727693bd009bf9bdb655c1df9fcab14f9b97 |
Hashes for stim-1.12.dev1692168330-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4764a43c04ca952d088cf680eaffc9be655c7ca51f0bb3d7014c00aa3ca0e1f |
|
MD5 | 9cbad681b004385347c5626061ae04da |
|
BLAKE2b-256 | 5c78b70cf7c00fb919a43cf6bbaaf852242ec73107312617983930c08aad20df |
Hashes for stim-1.12.dev1692168330-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6071184ada4652ca14c7752ed213c24fb7b84b6990b6f4b1aab411ab0c26f59 |
|
MD5 | 6b6b4f19630c0ef3cf00414be42bc6f1 |
|
BLAKE2b-256 | 91971e66b33d80fad884a2904fec0c849b5c92d3ed48c633a81a597e7bd22428 |
Hashes for stim-1.12.dev1692168330-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b4b011d95b7b1ef093833cecd63333f28a04005f5ef83f4623f558ec72e2be3 |
|
MD5 | 4737dc98d61978880d93f95a47e1325c |
|
BLAKE2b-256 | d3b62e12472f79d97472ecf6678f126be008c4aa134f4396e1b97b1aa8d8439f |
Hashes for stim-1.12.dev1692168330-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a5b086929ae43c3a23dc95379fd7bcee08c9e3cd4b5b48f5bda4c007b74d981 |
|
MD5 | 814263fc6f982afb80ec98e39d06d81a |
|
BLAKE2b-256 | 2e8c4ea7ffb5ca1114cc8e32b86fe1c0ac10c656ca6ca010be2eb3cbdbcc2b5c |
Hashes for stim-1.12.dev1692168330-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c55af84232e0df36a09fd7cb9614ed1866afc424ac5f70a89c8180739a1e1185 |
|
MD5 | c7c686faf45bea5614915ecd1b80f407 |
|
BLAKE2b-256 | f28e65b81c066bde0f15d25e0f247f16f69fa1d16f0d5cd5e69bcd9217ff59a7 |
Hashes for stim-1.12.dev1692168330-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f69af59d9da465a578b72cbc57c7fb0f93be7f8b4d50403b5302bec51ba84a5b |
|
MD5 | 14ab612ddbd83eecdb87d89bef8ed64c |
|
BLAKE2b-256 | 6d9aea9c5f499cdf036fc6c97f0105fada2ad033b0461d6015f6d75d60914f48 |
Hashes for stim-1.12.dev1692168330-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff38d18a1947bebbd5b54a64bdac816e260b99587c8b87d439bbe9bd07bdb530 |
|
MD5 | 73a553ebeec2c9dde57d6cc684232b37 |
|
BLAKE2b-256 | dc8a6999db1c3bd9c73c9f239b4bccc5231291cd11f83315c72e0db8236775a2 |
Hashes for stim-1.12.dev1692168330-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aae1ffc4cdc7141ba3540a68cd380d48e845b44767c9f5aeb3e7a26c3ee7564 |
|
MD5 | a4107d4c8691d611da9d72fb99e7c72a |
|
BLAKE2b-256 | d55530ef79f1bcd877a05c1477844abcd37398fcf588e2d98d11805ae978fadb |
Hashes for stim-1.12.dev1692168330-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0fef7381b29e541c71a5cc89642bcc992c0f7cf222f6d3565ca2f8d02af2c2e |
|
MD5 | 8eacefbbdcb41972a79f3dce5f2bc034 |
|
BLAKE2b-256 | c65c33eee0e32eeca9c1445182721c5a918319e42dbc58869bee32c65d73fd6c |
Hashes for stim-1.12.dev1692168330-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fa8b785334257481ff12a87131ab1c80b4492ae75bd6d5f758593c4e4f9baa3 |
|
MD5 | 37f6b4d8b395d345663c3a6cd76f2f39 |
|
BLAKE2b-256 | 4e5b0b3eec15c8a63499b840313fcb80065426a108ec34e58249943522ad47ff |
Hashes for stim-1.12.dev1692168330-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 579cad58f3a8608df9abab78eb3a21506e70ba806a47e1011890abb759d82166 |
|
MD5 | 3acd5da189ba0e52da3d5c74fd40100a |
|
BLAKE2b-256 | 8d64c6117f11c0380cf95b4e63a6e5ebacffd6dbe5b8eceeb24c71de64c3e0be |
Hashes for stim-1.12.dev1692168330-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938a8f6f127461fe753c61400e9616ac636aa7befa8f0a0b775414bcada22103 |
|
MD5 | a821ae0fad518a74afd1937d43a18f30 |
|
BLAKE2b-256 | ea778ab7f72d6675da8deeea4be1ea1d24ba6b800ea3a357a991fd3cfe02fef2 |
Hashes for stim-1.12.dev1692168330-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 982ba81c3eda848fd66a15b23fb0db0d905586c4092f0c26527f4ba9bd3f873b |
|
MD5 | 01fc488c350f3147df72af1f382ff732 |
|
BLAKE2b-256 | 0bfb3b438a9c18eaa68983ec7b75ef3da317aa8095a7ed223ff728548314d8ec |
Hashes for stim-1.12.dev1692168330-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59bded93c33f7861e82808321d724991804edb85d89f7ff210ddc835851b524a |
|
MD5 | 85e6f140639dfefa26373c748e06ff10 |
|
BLAKE2b-256 | 39e765ff7c420126e64e78879aa6c0a0f3a347a12f7e979291fa8a92c5e5b9b5 |
Hashes for stim-1.12.dev1692168330-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdc83e57a98e1e439e6d7262815e501686bc6ef79930c6d7f398811bfcfd38fb |
|
MD5 | 5609d20606d64d82c2731547ac191c24 |
|
BLAKE2b-256 | 8ab0ea51b02557b3f2c904b40e92a2098dd8a4700d70eb71c523ffd7dab79907 |
Hashes for stim-1.12.dev1692168330-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a43b573aad83b81a441fe6e29f05f7c3566908b731f3c47aa41fff4d5ba9d1e1 |
|
MD5 | 80ef3f266a8c4f8428e704cfd1ac5148 |
|
BLAKE2b-256 | 138ce318295247207e45c160d240e73c22c8bf43d467d83c3cb833fe6f257236 |
Hashes for stim-1.12.dev1692168330-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 104358b9406d203d166b1e7fb7f1cc8374f83441f95923f435d3eb6d594e3c64 |
|
MD5 | 5cb29c8b581e4803db718daae97ffe7d |
|
BLAKE2b-256 | 8d48d3e07e0ef9038b61b8a0c4404f8f9ae3cdec1e7cd29e8f6d32ceb5b8cad8 |
Hashes for stim-1.12.dev1692168330-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 630b5dcd9cf8654dca7e9187a5e566e2c09ca2c683b49d4866fe1fe4caa1d8e9 |
|
MD5 | 8a88343ae4595f582b62f25fc3dfaa07 |
|
BLAKE2b-256 | 3ede6f030871cf2d0603d38337dc5804213f8ed0fad7819de42fa9df418ab384 |
Hashes for stim-1.12.dev1692168330-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6fca24780c066b47779c4dcc898a274feb1568c18e219ccc6f225cecddfc7d5 |
|
MD5 | c95df28f349469505f91fc8af68c19d2 |
|
BLAKE2b-256 | 834889c08331a2d1c067934a6617fa5fffb28c9576b39080a83083572477e4be |
Hashes for stim-1.12.dev1692168330-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3858b165e65933434ec3631b14d91c9021f7887aa2f75b19809b7aa384dcf3b1 |
|
MD5 | 7ab8e59549d9e3a0b53a54adf774eaaf |
|
BLAKE2b-256 | 432f431673c6a7bb6eaebb2743b30e04d23641ff28f13601401a61725d525642 |