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.14.dev1717459827-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e288219ec2d929eb784447f6b9183ce2d4ad54060c93c36a21d720b74cfdde3 |
|
MD5 | 0d2458b6a979c60b96709ab4aea54df9 |
|
BLAKE2b-256 | 9e64df4c510c5eb134c5907c5a935f2f601f82b68ee534cc1063c26c03ac9831 |
Hashes for stim-1.14.dev1717459827-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 511394334a5c82f8e2fbc0b19d41b181f5a7a443206aef8e6ddc132b4625833d |
|
MD5 | 839e966c2dee82619037a2b90de57c3e |
|
BLAKE2b-256 | 7588b04f5bca1fdc2cd4bc1cb921af11a0f51099d64e44a1415c37e2d0cc80de |
Hashes for stim-1.14.dev1717459827-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa14ac5ae85c2af5719fc4a01b2512a6646af9103bfdbfed99c882af3747c9c3 |
|
MD5 | efa67b1114c9135ca0dd4ef5fa3f9d56 |
|
BLAKE2b-256 | 3278eb9f59d3f410c4069adda6a45d72ea75b697af8b0e4e153bdc6aef5c6f1f |
Hashes for stim-1.14.dev1717459827-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db9323177d41ea6f24c56f7051a300bd7bf7ba1daeedda2c8cf13fde1bebe08e |
|
MD5 | 0d316c2f436aaf02f3df6d0be2b5b1e4 |
|
BLAKE2b-256 | e41710975e40f837bb5c57f2f1c60b5c0d86d8d73088deb78bb39509889042ef |
Hashes for stim-1.14.dev1717459827-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d6520cfbc53440e728c206f577becb1294447141fe22faacfd16acd9ff07207 |
|
MD5 | fcc9f746326b21cdc31e56105323b3c2 |
|
BLAKE2b-256 | f7ad3d622102e38389cfd16c6bde03e82ff339bac90f2c484f2343a8d3cd5f60 |
Hashes for stim-1.14.dev1717459827-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c4f7080eca4cf0cfa9f04ef7de480210b3a6d1d64df0c9175ffb0c458312c34 |
|
MD5 | 1182d11499724ce718cc010632515326 |
|
BLAKE2b-256 | 023af0e3a18e51cfc9f8cd8b2fab0e638db249348cb5c3b585a3b3410135808b |
Hashes for stim-1.14.dev1717459827-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c70fa7750454d5a3bad2add70621c83e56f31b2734a217127f9a3e8e24b74724 |
|
MD5 | f7f93d702de3079bcafb1ccdf4296f3f |
|
BLAKE2b-256 | 7ee7ce494c3ba1953d21c462ec9cf7e6f14809dbc7e5e1c80bfad94bb2d091e9 |
Hashes for stim-1.14.dev1717459827-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eefa2fa9284a4de75b326c4d7eae72e7de1d905bb31350a15ab32d7fa9ab4cff |
|
MD5 | 4ac894cc7e3bb15f337a8bd4c325342c |
|
BLAKE2b-256 | 03a2043d760fa4948cecfadd5674a3d37da082c350968cf3a119be391241b6d9 |
Hashes for stim-1.14.dev1717459827-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 610b48629c7fdc338c82b158546cbde3e1c994453716a1b564db51d4bd415355 |
|
MD5 | c9eef57a5e7476b5f4dbeaae36a1db92 |
|
BLAKE2b-256 | b20ff21bfb90213025a04764b1d5630b0dfc0d3a8b04e5bbd6603a9a31028d1a |
Hashes for stim-1.14.dev1717459827-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde120ed785bec5d85baa5e99fd5ca3d33f36bdceaaaa09885c6f7b528e2fd1b |
|
MD5 | beb8f270ce8bcd86b509bd51e0cb1c91 |
|
BLAKE2b-256 | d3c5f0304734d910f0bbeefbb9405ae6cc0e909d48d498b0af046dba96292069 |
Hashes for stim-1.14.dev1717459827-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 701bd7c3dbf6d17a0ab49c43383bf583df9f6ad13c9ac6fb42d7df6ab23a61d8 |
|
MD5 | b2256e37ed3eda1b388db3f38e2d0e0f |
|
BLAKE2b-256 | 9a555900be5d60b3357fb8bc009a54fc4b4656f443ab9654247f770e5dbdf55d |
Hashes for stim-1.14.dev1717459827-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a82b38330e0fc79d236a3c98655cc2350b41ef8380373e4d02c9b64cc98a05e5 |
|
MD5 | 676ec18e86a8add1e705183326104548 |
|
BLAKE2b-256 | 9bb99f702b9b73c99d4620faf1ba8dc681ecb20793e043c9ac20999dd16a8561 |
Hashes for stim-1.14.dev1717459827-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb8fb6314b751a18b071ad0e0d75636ff304b793017874322f70caf5419a53f8 |
|
MD5 | 1a8a793a74275f8f852df554d8cfce31 |
|
BLAKE2b-256 | e4998a76e271c6d08a24b39d33b860d32dff6d7c3953859585c71eb3c443df5f |
Hashes for stim-1.14.dev1717459827-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5339ff3800a9ffe6eee18459b99311c491e096fd213c8c94a9fee055cd3891f7 |
|
MD5 | 72048deac40b6c27a25930ca27069d7b |
|
BLAKE2b-256 | 844229760fc59fd2919e6733b5b7cbe1be4e9d49ae6aab35522b90f8ce94034e |
Hashes for stim-1.14.dev1717459827-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de9588cc61f23504fdbd0670b0cf4b7fac02f4c3a20718be30d1c009b7582ec |
|
MD5 | de96922103f4476bd44d173547d9998a |
|
BLAKE2b-256 | d80a5746701ea11ebdc8d6021087bdf74ab1b3b589b58628034cbe6eff0fccd6 |
Hashes for stim-1.14.dev1717459827-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c3419e1194610672d8bee6f5778dc3aa61c285e0ac9102de2a80830180f3e52 |
|
MD5 | 67ba14f7b467a489cbb54b19536c180e |
|
BLAKE2b-256 | 47ee19cc12ba8180364d8699a11508c2bc21ed0bd57c2c2e75aeb59c495c827e |
Hashes for stim-1.14.dev1717459827-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f86d0937275ca74df0aca55c386b6060d02a92e53f65812432217a6a8346889b |
|
MD5 | c307d98f82ccce2b1d72a5b1e0c11782 |
|
BLAKE2b-256 | 086823e9dbde210ab6d36609812d8990f58c332b14d082a21bc2b99f3e83e4b7 |
Hashes for stim-1.14.dev1717459827-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e547f165d7bfc92cd97f28dbd4d6f29dc3d10c3fdc3625fb855a1ba71d28a031 |
|
MD5 | 0e46b36a182090773a9d426437d5dc33 |
|
BLAKE2b-256 | 3d78dbb1a6ec5b1b19e888a81c8d923259e5fa0a0587a88c3d426010f4a08b4d |
Hashes for stim-1.14.dev1717459827-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaaccba40be22424d290dc03e6f958c88c268127a23db68e645ff7b40dfa5dc8 |
|
MD5 | e71da6203aa7e9f8d0f201cbdfba4713 |
|
BLAKE2b-256 | b8191bb4c5fbc462ea428d1df2e96d586cbdfe07b8c4a26093255b2e4580d745 |
Hashes for stim-1.14.dev1717459827-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f063c8141fc2bbed265b914fecac20a3ac4bb0c2481a3cf0689e806337caf16 |
|
MD5 | 54f99e0c436d8a5be7253a86bdadf572 |
|
BLAKE2b-256 | 0c287829692828aeebbf84d8d8d6c7f37b641a4c04a92854bfcc4ac3beca0515 |
Hashes for stim-1.14.dev1717459827-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97cd23381cb2c014a9ef97240dbe919624118d27cffd1cb9b23365f003861855 |
|
MD5 | ab02fccb36783d4a257798762d081cb4 |
|
BLAKE2b-256 | c5643d6c8913e16a88433254d015354d3362208e034b0fe6fcff6302db048760 |
Hashes for stim-1.14.dev1717459827-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 923b9dcb5d3861b381089f1c464d6817d2dee348ad18409b35714505696f9978 |
|
MD5 | 5873c07aecad3b50c6233c755d9b24c0 |
|
BLAKE2b-256 | 17884fe9ca6c19a63318b51d286f7773a2b69bca37d448090031aaa39831e346 |
Hashes for stim-1.14.dev1717459827-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddc99f29a738a3bba7a95dc1d507da307ac637843584bb5320664068f367751b |
|
MD5 | 45a6931fa39266fd7ee6d08b7fd654be |
|
BLAKE2b-256 | a9c2c707bcb4ca4225b21cf1661805594593e38aeb009040a939ca4811787371 |
Hashes for stim-1.14.dev1717459827-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db407129c5bb0258a6a4bd9f3016c245a4ed96dee4416d7f040e8a93bebc3a9 |
|
MD5 | a81b2913ed8ad5e2d0a06d6004840eed |
|
BLAKE2b-256 | a80c892640916602aa5baba191e5615a1d656faf82468905115b4a201a1f7c74 |
Hashes for stim-1.14.dev1717459827-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9973bcde7891d51276dc9bab734d8e99fb0179ef0da9a36b41298e64835f15fd |
|
MD5 | 89d6446067caddd52eedb11433a0f264 |
|
BLAKE2b-256 | 034637bcadb57e4fcc79c58de6adf029636ab5c25cd82d0e5b57a9dd145a1977 |
Hashes for stim-1.14.dev1717459827-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac65d597d8cb8ba70fcf2b57e4e33df00c363d5099b609f90d618f3147549a13 |
|
MD5 | 18a6e37eebd47a15e32fdfcf4e4459f1 |
|
BLAKE2b-256 | 04fb929c4bc85061c13bdfee9cd114102430a967a086e593554d1d10a6e59fc6 |
Hashes for stim-1.14.dev1717459827-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b89fa2eafaf67ba101820da32b13baa444d53250a9cddc472e2db19499a569 |
|
MD5 | 27498c946f96a30dfc64024a7a115104 |
|
BLAKE2b-256 | 56dfcfad294bdc2da90e5b6ff1633f1eb79cb5aca4b9b718943684fe5ae610b3 |
Hashes for stim-1.14.dev1717459827-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6c86b28c97f950936905eafa6e4b3bd078fef8278eb42371ae4775c187eb9c2 |
|
MD5 | 0f4fd8f35cb1bc5a1d3eee665b004617 |
|
BLAKE2b-256 | 5092a1676502b0210240e24fd9e167838815ecca7dc9b3c7fb6bc445c229d8ae |
Hashes for stim-1.14.dev1717459827-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2292396aef1c035b04b0d5bd2d2872c1fdbf837109579970a1816aae37dad0b |
|
MD5 | f167844efe2e734627515a9a2b3c9130 |
|
BLAKE2b-256 | 012c70c65c0ee974d87264b4300b0687a156cb06599218045a5624216f189d0e |
Hashes for stim-1.14.dev1717459827-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 017565bc2e13c5a8021ef654e5d3fb3395b33f5afacac539f31fd36d639c9cff |
|
MD5 | 1fb0da65a6b4f526f07fc05d74baae1f |
|
BLAKE2b-256 | bee3c47d6600b825dc145cf450b70915d9cb6aff82557e9b9468dbac46192224 |