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.dev1707955768-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48e0b3df998a178c9c1923da859c8162e18950c38b047764445900927876e0e7 |
|
MD5 | 116cfb2b41da76b1b3430cabb24fae26 |
|
BLAKE2b-256 | 4d1968b240117472d03ab3f42617eb137b959be4ba6213f14ad8ccf2d8745056 |
Hashes for stim-1.13.dev1707955768-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6fc9a4e04dba6ad110acea1585f3e52b919f55bef3b1e69a6f93477443108ed |
|
MD5 | a57898e17dfdcac4f21358e9cbe28f01 |
|
BLAKE2b-256 | 00fae6e5035d30b3ff7785b5fcc1f3fc6c3fe09c00f86ebbd4d9d9ea079e9457 |
Hashes for stim-1.13.dev1707955768-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f5a44e5c7f7f95a3cc4f4271bfc7b66674db79d4be378b103d6b3eb0d35f0dc |
|
MD5 | 356520f5f402f9738988beff4e717cda |
|
BLAKE2b-256 | d3c5f6380bc1725dd47c6be9a6255ff8d58d84902d75812796aa24369c745fb4 |
Hashes for stim-1.13.dev1707955768-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d170ce109a5fccff8112b400a7bf445e899558b3713185b4688fbc33c2861f |
|
MD5 | 3599024eb78baa48c353439ed02ff05d |
|
BLAKE2b-256 | c9c4c09a737291dd276cd74bfb47cde0f9a5badf498965f32317d22dcb98e8e1 |
Hashes for stim-1.13.dev1707955768-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f324e67c5b113164a7ac54bd63ecd354ea6370f741a4c7f31ffa9bf603884061 |
|
MD5 | 52bae770859218593d918453f14c3bd8 |
|
BLAKE2b-256 | 1a8115a2b59216f0a18c4c33f7bdfda479ea6e1771c010f7565a46b90c646863 |
Hashes for stim-1.13.dev1707955768-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79ff5019bf9d90bb6c872472a3c4ba73bfbe67c4576e8ee2554a26d648ae4c75 |
|
MD5 | 015f0c92f607c32444141781ea5dd4b6 |
|
BLAKE2b-256 | c137b48973ac06faf66d1ad89bcf35ac690eda5ed5cf8c6dc09a0966d6b09657 |
Hashes for stim-1.13.dev1707955768-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b7dbff3e32971467e26973c5c3616744c6156658746219e3844b4d053c745ac |
|
MD5 | 0a2015373407a3ad300dd5d2e9c7febd |
|
BLAKE2b-256 | df01d30b3ad894feb36adf8beebf8d9fde2b172d80bc90c8d3a84210549f4a18 |
Hashes for stim-1.13.dev1707955768-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa10b561a046efaea72abb4d2d2852e860435ab92673895f7ad8ffc6a015938f |
|
MD5 | a9f72da6a67fe3e5cbfe8434ed79a4dc |
|
BLAKE2b-256 | 0579b9816ef8e114dba684a519f06d60fa3951dfed72dfaa2b4213294f20af8b |
Hashes for stim-1.13.dev1707955768-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eafa78fa27e13e4f56b2e2fd7449f74dc639b76bf87ac209934b21c74ef72bb3 |
|
MD5 | ff38e346feb179f986a61c7025dd67d0 |
|
BLAKE2b-256 | 949737246ce9c826f6486eef8db1f1eb974f355f10220ebc280ca6e6c523be35 |
Hashes for stim-1.13.dev1707955768-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c3fb92cf796778cb6c4506dfd0824ed1fa5e6e2ba3a7c539cd867eea72c6bb3 |
|
MD5 | 6a147590422ddafff34857a97e44bc41 |
|
BLAKE2b-256 | 5137f041c676c0745709b7cb8fa30019df775831452acf0e22258a5b92201771 |
Hashes for stim-1.13.dev1707955768-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad30b8fc664e2acef3304fb4b4f81c1b01483ff31b8d4661f5d795ab32e58b56 |
|
MD5 | ff4f699d049697e5f132f24ab0a156a1 |
|
BLAKE2b-256 | ae1ed1dfd0b6acec9ee8c17b88e4570919eb945511e369ce339bb4ef6c846ef1 |
Hashes for stim-1.13.dev1707955768-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90629a25f087dff4ca98b82970b00c3b0a97b98397a4262467c9d9694467fbe1 |
|
MD5 | 9c5feaee1b383f1ae6a62b0a7557d38c |
|
BLAKE2b-256 | a41b13ad6644f12be2ca14867e25808a58ad07c07ff2dce28a3f951bc8672a81 |
Hashes for stim-1.13.dev1707955768-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e31e3639de87728ac3f841ed46cadc0f850400cb01f38cef2f7fe3592f24654 |
|
MD5 | 188cffaba83e35d14a2d175a62553c15 |
|
BLAKE2b-256 | 3cf9f28263467b466ea7521a6d124e206823d069120a5a3e65968b444a6520ed |
Hashes for stim-1.13.dev1707955768-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3d5b9ac76510c7a76605364e411a79f5423022efee1e45d7b284f591f116108 |
|
MD5 | 7e4050e479f040082677a8512d906b92 |
|
BLAKE2b-256 | d68fb4ee1f136ba5e10ebbb410292d4bd240ed1b0e69bd252285a3818ff0e2e0 |
Hashes for stim-1.13.dev1707955768-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277901a70905be982d8734ff8c600d95600918fc3c0ea025933076b43c22255f |
|
MD5 | 91a5518865e063757f9f443e5e47f040 |
|
BLAKE2b-256 | 39fb3fbaea373d1ad5d6ebe289fe39e472379d6049c2fcb3229e1ffda7a21bc9 |
Hashes for stim-1.13.dev1707955768-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be850c2e4bd1b1e013b99349ec0a11225a12bf3faa47a6f8e00a82de14b03230 |
|
MD5 | f89f8e8337705648c0b71a0e7fefc9b8 |
|
BLAKE2b-256 | b8bd6bff969eaf24486bd86c2b7dd8c68b740cfcac90d1526839f30fbade07ad |
Hashes for stim-1.13.dev1707955768-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 741085ddabd613db19a21375cbaca0121f9c7a0578febde173576f7c513a3625 |
|
MD5 | 35b1af467bd5c5d5909ba1260c9f09be |
|
BLAKE2b-256 | 756ae35d1bd7aa808a421d8d290abe254a18befdcdf5860373cb59a6a496c338 |
Hashes for stim-1.13.dev1707955768-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5f8b8dae52df544faab2ff186a701bf9d91aa5d3a5009903fa0d6efa084db2 |
|
MD5 | e13a4b1fd830b53f9fc50b69dd5f7075 |
|
BLAKE2b-256 | 7b34dfa7ee8ee083a5c27e062ec3a8b088098d4cb1b10b4b579d94ac8045b440 |
Hashes for stim-1.13.dev1707955768-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 280e51ef061b8375a83d53991535b0a020cb5016344bd8b98e59b353958d6651 |
|
MD5 | f18c778bf81dd6b099bb6ef2c16973ea |
|
BLAKE2b-256 | 60790671f4906312168abb839c0bd841b925d3fca5f610fab846f9ab75efa10b |
Hashes for stim-1.13.dev1707955768-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 712f4f8c4b9bf5477f4f5fde91abfe50e730f5f068fe57cf0f6ee6686a088a01 |
|
MD5 | e8aeaa92e5e7483d41c5fbe1d90beef5 |
|
BLAKE2b-256 | f0d9fb10b22cdd8b20b01d031bf8745856ac7b6496679f7e8921d3a8e076f35d |
Hashes for stim-1.13.dev1707955768-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3baf29cb87c5be5897bdce69d0afd975222a5598d2f421c5689bdcef2d5b6a6 |
|
MD5 | d2f286022fa79aa8924f816ae7907f3b |
|
BLAKE2b-256 | 2863f8643b6fce62894317b5e213aa9cee514ee00d952915861f71f57b4e779a |
Hashes for stim-1.13.dev1707955768-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeea76e27b718408d3fa9fdae8881cdf964575853c014b5512a3d6588d1c3986 |
|
MD5 | 69420b58585b189eab3b8ab56594cba0 |
|
BLAKE2b-256 | a28f17b95d716ee105a4d55ed23bcd81b5541020ef2131c1f8995cdf2114d518 |
Hashes for stim-1.13.dev1707955768-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ead7006a2c0c0270779bd2b2ff13a60afd51a72744247ec0b60b09462d2527f2 |
|
MD5 | b630bb270019f74d2adfd959428ae7ba |
|
BLAKE2b-256 | f46c10e6d988a7138ee896dda6ce2794da0a421f573198bd267f1d523c54aef5 |
Hashes for stim-1.13.dev1707955768-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7631233a194fc56d7e77bc0e0ac9756c6ddb3b61b97dfc5847ff6b7e2206d0f6 |
|
MD5 | 4e98040c64f63b9567c01e2e1269fccb |
|
BLAKE2b-256 | 55164a04d6c81e9c86bb6070cf41c85cfcf2ddb54e5793afe05db498419c0f14 |
Hashes for stim-1.13.dev1707955768-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b769c8ff3f4e581beebdc1326c8bf2ae160c267d0ea1c5f5325f79375947b1f9 |
|
MD5 | cf464c1fbdad8bc8b411f10c6aeeed6c |
|
BLAKE2b-256 | 68e50a2ee0049b90a96957e898dc602317ff89329ccc8d36605175398f53e943 |
Hashes for stim-1.13.dev1707955768-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729f71121b6c9ad03da5c430ae6bf50a90edf6e9c1ed7746fc0ad2b9d0407e61 |
|
MD5 | 5a0cbdb711674d0fea70b4e9a14374d7 |
|
BLAKE2b-256 | fa7e92195f65da118de9f6f81013f7fbaf0a81034f934e2c790881271ee35a0d |
Hashes for stim-1.13.dev1707955768-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa6e82d7c060446d14898297d5d536a3f20338602223bc453ae8840d4f9d9d30 |
|
MD5 | b7c4935d42f6e7617bb160f86d697ccd |
|
BLAKE2b-256 | 78944ca12cc06bdbb27ed296a41db711aedf9c3ca96d4b0c2e7f9518b108dead |
Hashes for stim-1.13.dev1707955768-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b86cce2560ff537b6ebf03c2b592ea64c88855360dc368703290aefed9f770b |
|
MD5 | 9dc5c5bfaef0c2310752e41569eaf983 |
|
BLAKE2b-256 | 204b01fe4fd384519bea3445b73ba38ab871ed4529e88e3869a7d6cda113d9d4 |
Hashes for stim-1.13.dev1707955768-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f7071cf1d060c5f64660b9713bb3e1b5c90c1a77e4ab059cb59c01f1ef15a4 |
|
MD5 | 5956669f86ea56ba82d9458334546a2e |
|
BLAKE2b-256 | 11f04979fd3a672dd228b95830cb8c50fa485e1d8a24dbe9e6def31863e1b3bc |
Hashes for stim-1.13.dev1707955768-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca799248d05245bcd44222d6ee74cbb1f27bd54eec20c15291a556521834d18f |
|
MD5 | 5a045ecdcb473e722edd9f086f1724e2 |
|
BLAKE2b-256 | 78f4f8e1576142a341ddaa9ee1de78ca4c7527e99c3871ac01ba9fff4e7c9e75 |