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.dev1686512864-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ae45008416d7760f18f6ab6c69226e157adb14984242a6855afdb6cf4b86d6f |
|
MD5 | 74d3040e6801295dd584b55f1a5a08f9 |
|
BLAKE2b-256 | a422b60f113aeb2a8fe7dde526acfe10f20b2ddceb9c3d4dd9ffb581d1e3166d |
Hashes for stim-1.12.dev1686512864-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acf74f71d5b355f1d7db53b1d586dfa40bf9f812761e617d8d9937ddb97fcfa0 |
|
MD5 | 655cb6449ff2c7a128224c38c9467ecf |
|
BLAKE2b-256 | c3751fefa6446ba5d629c88c3931ebec9cb7889ad106938945aabf1e3a1e5146 |
Hashes for stim-1.12.dev1686512864-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8500bd3df1db5dc4502d1566aec61f8745a07910fb7faf60e4f76b4f695e1642 |
|
MD5 | b97f1c2fa24162bea0c22995aac2ac5a |
|
BLAKE2b-256 | 6a77faef20b5859845bd11c33f2a48bff3f1f5bf165ca1b3712a646e52723b95 |
Hashes for stim-1.12.dev1686512864-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06136325c0ad0a644b4e4cff80f2d0225b7594aa62e288664b07de87bc681081 |
|
MD5 | 6a2c2f95a9027dd3ee33f0a6c00db2ae |
|
BLAKE2b-256 | c04e60f14b746c65696026d795a1b8057ed1820bf10a92cf68d68af690911c8f |
Hashes for stim-1.12.dev1686512864-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fed145956bbfe5c8b527f75d0fcccaa5a986612006d7782bc2966154caddb31 |
|
MD5 | fd52b5cc3a9a6163d119f4fa20275b04 |
|
BLAKE2b-256 | 5d26b8f12623fa851716b88ca9c5cc0eff8915c874a06e05a87c180a080ce5cb |
Hashes for stim-1.12.dev1686512864-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0612a451530b0e3094db0c6d06c566d7257287d1c46b03688fcaf621040f259 |
|
MD5 | 9bfc239bc63cd7cc2fe79b9266a6ad15 |
|
BLAKE2b-256 | 67d9d584299f28f9075f2723b182b66f687a93ce99adfea6d142f807c1e247c3 |
Hashes for stim-1.12.dev1686512864-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0b7c097cfc8df7677fd6fb241dd3f6ac8d48c595fa614e3a279ef86816f8b28 |
|
MD5 | e290b4cecb09cb1ef84c0c87770f49bb |
|
BLAKE2b-256 | 5c3bbfdc8bf3b24781352536697e8f0e2223d39ad02243c1542308065d2ddc6c |
Hashes for stim-1.12.dev1686512864-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06b6a48b6201d8f8816abc4bcdae45f9625e8ec9c8e6081d171c587e2cc9c84d |
|
MD5 | 9a7b704a7d896df4489f7f472f3012e5 |
|
BLAKE2b-256 | 74f981fc8b7376bfe62516f9a4b413df0c2bda7e7fb592048f44caf2908362b5 |
Hashes for stim-1.12.dev1686512864-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02f40d1672b821d133a48dc4231dd398fe926aea58315fa6c4c74d6356701d88 |
|
MD5 | 42c49fbf68c34226f938a078c4af037c |
|
BLAKE2b-256 | 5808dcbf4c7026d3742eb0da19730010f9b1bb9dd0858d0ddbc6bb38957ed399 |
Hashes for stim-1.12.dev1686512864-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a094e091456e2be8f02c1d9b5ceeabf56c5bca7436c80ea108cdf68f69f07ac |
|
MD5 | 7bfc455408757f91a3bca0127e6be16e |
|
BLAKE2b-256 | c8a8574f20608d1f08e6c5a6a2c95779d54245439d1710acdf8b4884ecf25c4b |
Hashes for stim-1.12.dev1686512864-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a0afb8fee1a6cb74a69280ea956247ff872595ed81e121253e66ee99b2fb0e |
|
MD5 | 254fa39e3c24586485a711759e845592 |
|
BLAKE2b-256 | 81ed0a5bb765cf739f9a48c723d85729fe3ab62b0cbb749b9db4b5408ce6f0c4 |
Hashes for stim-1.12.dev1686512864-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a54a080d2733e4ddc25b183089da4bead1d48bfbaeae51a302128006a4f0abe8 |
|
MD5 | bb55b5014606cd3b17d4db7685679f12 |
|
BLAKE2b-256 | 55a54ccf46285d90353fa593d2492e74b56def32f100a92434e817cbc33e9002 |
Hashes for stim-1.12.dev1686512864-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce94b4aecd591d451884a61080117daa1f1969405ed76055c2bb0572e3495e65 |
|
MD5 | e08d70ffe6f182fd1634f0f9b0054879 |
|
BLAKE2b-256 | 16c879a20b28c7b849e320102f9ed3bd0a5e2125585f434c00ffe49789e4414a |
Hashes for stim-1.12.dev1686512864-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e55ff4f1be4b8be17bb0591a658c4731a15abf072019b63fffd17f4b47b2296 |
|
MD5 | ba50eea0e2a96c2ff59a06e299bd2daf |
|
BLAKE2b-256 | d9f7421a7fee4d854c7acb207a8b3b2868db86a0951480e656fc3201b268397f |
Hashes for stim-1.12.dev1686512864-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e37bdf9883c49f38f5eee96fa425ead02e141598aa05a1c95081b44409c48ff |
|
MD5 | 5f73c93d47f06cda583f8865051ae18f |
|
BLAKE2b-256 | 2b24f890070ba1b373ef8c4d678c8ce82a0e4b56da37c7f32939686a857c6b06 |
Hashes for stim-1.12.dev1686512864-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 436ac0d6867a7980c7d1923da3381fec9f4bb599757c5e3d3e88eb0195dd448a |
|
MD5 | a0df693fb4aef1bf0028965be92ad95a |
|
BLAKE2b-256 | 55415d78d12622954f16f7204a0319621df3132642b5bc86bec8694ecfd59297 |
Hashes for stim-1.12.dev1686512864-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46744268e7b3751adf3801d8c26feb79adcbf80d66380bb2b2acaf4c56ee321d |
|
MD5 | df09ee8b60b2def21c3b3f2a54f866a4 |
|
BLAKE2b-256 | 1caf2289236e55b5ddf454cd5288dd5592f3a55929e8de7b5f91b786ad71e9a3 |
Hashes for stim-1.12.dev1686512864-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef80975e87754c1f100ce19539b313c167e4b96ec98d6fc69389ec7a38f6fcbd |
|
MD5 | 9ff4b4130997c80936bb3ea86d2da155 |
|
BLAKE2b-256 | 4f01b9367f85814c8831fdb60542cd112b89614845a8bf6bc1f1cea4d033c87c |
Hashes for stim-1.12.dev1686512864-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f79d749f150d67bcb3d0ac9e072d36e8b4e819d820448d440c72117447861e23 |
|
MD5 | ac31ef021217effc65002acb9a694277 |
|
BLAKE2b-256 | ec59a0a48556555359fc6ee5366bc312a3c276f3511d42efd348aefb0b8994e1 |
Hashes for stim-1.12.dev1686512864-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2999432428c9dec762c9933fbea2d0e6a417d620665142aa6e7e97ad6c9be9fc |
|
MD5 | d48a324a48e36ff63ecf17f7b1d554ed |
|
BLAKE2b-256 | 0f5bf1fcb34519ade31afc548be20e6fe6ec3ad50b9fd420152433f3a4d10dee |
Hashes for stim-1.12.dev1686512864-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a7144640631043e827fe053fdecf9a8d820d67146875e1735869296f978c1b |
|
MD5 | 0ee8456ac9044ca0d5302af8eb79e381 |
|
BLAKE2b-256 | 6644806f2dc857868d5c86e414ed9574a95c9fcf8c7d70720c9b86490831ba9f |
Hashes for stim-1.12.dev1686512864-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 679316bd4fa0130b060be4a9813e699144c05b4a05f4d13c463601c499794532 |
|
MD5 | bc2682e560e7f3e24e5dcbde130614b0 |
|
BLAKE2b-256 | 4d9c46cfa23e3a27dba1a0c374014fbf0579fee5dc381975e5178b146db2fe13 |
Hashes for stim-1.12.dev1686512864-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2183a31de75ccea67fe370664ff5af5e892bfbe98c3a71911a4aad38e23991f0 |
|
MD5 | 85e7dcb81c10e87b419af6d830d9c380 |
|
BLAKE2b-256 | 59f10b0874a4bcdea7d644f371465f2078e91c913532f7cacd7f1f6bb9245a10 |
Hashes for stim-1.12.dev1686512864-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168e1d24c929ab09accffbcdca8a3fb64d0899f35cf06941853df7b1a2a156a8 |
|
MD5 | 51d7232cd959c74f32f29fa74401b111 |
|
BLAKE2b-256 | 64b84729c20451203e271b54ddcaac5564571f7b0494354e0de723e36a60d901 |
Hashes for stim-1.12.dev1686512864-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9113b5132f7dcaeecfe8055711983e4f5735afacdd977f9506e27a3bcd3c2afc |
|
MD5 | 413dd18a454b48778eed1c11fc203eb0 |
|
BLAKE2b-256 | f7a8afbbc55439fa857bbc92575e65bd73908560c10ec724ec328fdddfc79235 |
Hashes for stim-1.12.dev1686512864-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7157bede11824b70c0c2136e174142d94daa6bc7e7a447635f00d762a2da86c5 |
|
MD5 | b84bd9d50189ef1373f9e36c8ff84e1e |
|
BLAKE2b-256 | ed16030f39d45821bafb3bcab2a2ec98ac7fc69a01a67bb525ae64f8585151b8 |