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.dev1700468449-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e712a345dd0c0f07b6ee66a67c959498035cd6e259577601453b00daf914edd |
|
MD5 | e187a19e15531dbc22f18d58ebac7d29 |
|
BLAKE2b-256 | 796c3f332cb19b73b6222566235478ab81b23c61c9cbe71a15d7c223629c7bb9 |
Hashes for stim-1.13.dev1700468449-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f5924fb666a303487a63d8ca784d1b8bd389b897bbe05d41e60fce5d6202112 |
|
MD5 | 76e60ea925481448d17cff51a41bb8cb |
|
BLAKE2b-256 | 86e6638ae266c16701a5f6d1cc6b82516c479a5861ab99127d2ba58f9ffd6df2 |
Hashes for stim-1.13.dev1700468449-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb5bdb48ce2734098d63661ba8ba57002f2db31d73939449a58bf4c4cd91702 |
|
MD5 | f90111092b1b70b9c8e894cbcf55b3af |
|
BLAKE2b-256 | d781c0542dc705f9cbbc97a2d35351ea3cca2db825dab9d42e3e2199411105e4 |
Hashes for stim-1.13.dev1700468449-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b96f7fab480c6cc00911e30f040da2c9dd9cce8a88089ddc79cfa9655106fdff |
|
MD5 | ecac9ada9ec09cf0e5ade39acbabd41d |
|
BLAKE2b-256 | b614120b3654d489d03056bcde2d80fe64bdcf404dc63a79abd85a273cbd9d87 |
Hashes for stim-1.13.dev1700468449-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 890dc3bddcf720aa5c6d2950851a63840062a944c7ffffbf94011f7dfd18faf2 |
|
MD5 | 60395cbf1cc7561d1c973b96f794714c |
|
BLAKE2b-256 | 1dad8336bb3bfbc7553a4a9949e07976bb890416016ecf048a5d567b92c17b7b |
Hashes for stim-1.13.dev1700468449-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac18ef00ae804d09ff315efcc93932d1b686b98461506aea1ff7079c62be52e |
|
MD5 | 4d5f9e143fdf50a707639ed2cfadf93f |
|
BLAKE2b-256 | 8f0ce50a229c3311a40652d9db535e2d72baf7e68acd39e5627ab2abc1f056ad |
Hashes for stim-1.13.dev1700468449-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70f9b51e4629160fd5f27558c8111fdedbab7c8f303976af12758cc47cccb2fa |
|
MD5 | e7b03853be67bf324d840a78b969c740 |
|
BLAKE2b-256 | 1bc508344e809d728e8c2be5f2f77d8439ad1596ce0e08cb9c45c220a885829a |
Hashes for stim-1.13.dev1700468449-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b22f6797a1f05448d34c7c8e75de8804a67cfd50ec356cd786680e34133a5a |
|
MD5 | 853a80ed72cd93e58bdf6872641ed635 |
|
BLAKE2b-256 | 38265b7e2c856ea995e2c83011ec666fc3b926215cfbcf695a1d5a294a54ae30 |
Hashes for stim-1.13.dev1700468449-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5135e0dab6d878bf06ff1849b48dc653dd133d8c5bd21249b1d8e83b42e21e9 |
|
MD5 | 8bc8db652018ad31c991a5ae895e1a0d |
|
BLAKE2b-256 | 19395ac7518b6d601cf2f0d321fb8a60d8576e2d0ec09de36313a1b874385be7 |
Hashes for stim-1.13.dev1700468449-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4f66efaa580637b994b6b053c04664d2ccd2cfc404e23a2c2f1da20df6ab9d7 |
|
MD5 | be21dade29669bfc3c703f2964230930 |
|
BLAKE2b-256 | dca78e383119ff1ca369152e8416b6a5eb3dbe671b2a3fb14afc4e41a0825dc3 |
Hashes for stim-1.13.dev1700468449-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca366b2eb774c6c3e9665afdb6de682496c5a1091f29bc268e464c1ddb4c740 |
|
MD5 | 95bd5455734f01594c6597151bebf910 |
|
BLAKE2b-256 | dd2f7260647cc027b7329b38fc192f679013fe54a8e1b1bf765a82665ed4da77 |
Hashes for stim-1.13.dev1700468449-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ee2024244569701a49249112447d1a35297b04a09191111e36979985a227ca |
|
MD5 | f933acb2f2775c2ded4879114b89ad4b |
|
BLAKE2b-256 | d842e7d681ecc304007beb8e912c184f6a631fa532eae60e27afef495ee70486 |
Hashes for stim-1.13.dev1700468449-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65f9dfb23de1dcd5bad941f03ee1781e44815bd226501407cc748d1d8efa8982 |
|
MD5 | 5bfe2850be2deda75f7f094c73c91c20 |
|
BLAKE2b-256 | 00e068fe0165b597dee003325f43f162405d72b4b08d1003ab35f9629c1827e6 |
Hashes for stim-1.13.dev1700468449-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee1c838a59cebb759789cee0ed7fc77060bf377b7a2a56bb04327d3dfb8a1885 |
|
MD5 | 0e146ec85120a51a25ecf9a4ad6130bd |
|
BLAKE2b-256 | 1173139c9e4aa652b0b3f13154327b16309a5ba42e8ac2e6fdc12dae75536332 |
Hashes for stim-1.13.dev1700468449-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d806ef5ef67364ae24f5407a6f43f4735788d38858927df74bb8bae58e7f5813 |
|
MD5 | 2d68b35324dae2c1698d06a4ceaa9817 |
|
BLAKE2b-256 | 9737f2a779b01839ffc096358b768af59403e965b9c80186249e17bdef19577e |
Hashes for stim-1.13.dev1700468449-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7cd1f5d89d5bda103fdacabee954b656b9bf9db32267f4a86d7185fd2af39be |
|
MD5 | 724e9a6edeee18b8e6de590031eeeba1 |
|
BLAKE2b-256 | c222b947c6e45fa546a787578c8ee152ddb488694a0841f3aaeb0caf55879e25 |
Hashes for stim-1.13.dev1700468449-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8b2037495c9baeb55565876ef2ee7b93aa63e05c269a90c294dea7d1d8a8ffa |
|
MD5 | 33bd6104e8deceac8a018a008417f604 |
|
BLAKE2b-256 | 2d7e217c03f0b9409cc161bd4a8edbb52b41886241c18ff7890156aa39fe7acc |
Hashes for stim-1.13.dev1700468449-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3804dc77e556bda8f3749e1ea9019a438f8013ce6ea015d27cbe46578e41d339 |
|
MD5 | 6d8ba1dc017efd720d190353f8c48c96 |
|
BLAKE2b-256 | 8fef3b92c0d43f9e345fff4b234c548bab41945f6f15fd4d0589811d24ed907f |
Hashes for stim-1.13.dev1700468449-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a925b94960d308390df6bf6c5dde6d40c12f0c0c6de0c996fbafb295176b5e6 |
|
MD5 | 9905ed6bbf98035c8f50f55d86044d39 |
|
BLAKE2b-256 | 39ab346cbc277e474af1b921ba38b6d9e4bde9083d49718765d6677bcb65ef6b |
Hashes for stim-1.13.dev1700468449-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62cddcc0927f8e82487f3c8a02e6fbfdbc0a5f6c39fb764ecc3066f21c712c06 |
|
MD5 | aa27bac86a93759e7e757f2ce4180125 |
|
BLAKE2b-256 | c146a02923c246beb2d1bd8a6c910c2e839d3201b9664ce64bbc035a90c8a080 |
Hashes for stim-1.13.dev1700468449-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1186d58fc7cafe27db2b4c69618309b201f8f6c2f7f111d62d9ef64a430686ee |
|
MD5 | 6c79840cfed0d83ca44fce9ff5d8141e |
|
BLAKE2b-256 | 53cef8ed42e16cceb98967831b3baa5c124740f8b617e6ad18cdc4559d33ef16 |
Hashes for stim-1.13.dev1700468449-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff24016951df657a7332024cd6f177e0047f683f87e65b669115a377f90e85f1 |
|
MD5 | 81aa33bde5f3db0c276f62f6790fcf95 |
|
BLAKE2b-256 | 8a176a05d88bdf94e6a48dc95eb6d3d3c9627df68134b04338a47da313db48c8 |
Hashes for stim-1.13.dev1700468449-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94de96537279a49c206c133cfc941f2a34dade7e8c693412519e579d5febe3f5 |
|
MD5 | c9e5cc859493a878b1069f317b592f25 |
|
BLAKE2b-256 | 0af649c62abbb96864697cddd1f631df7a14504cfd8f1ad10f2006a321fb318b |
Hashes for stim-1.13.dev1700468449-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2315d7f70b056c9a1dd6abc9ccb7b42c5116a770cd13904a074714bcca150149 |
|
MD5 | 065e4cba88e38a071b95d02ff2df68ec |
|
BLAKE2b-256 | b8d6ad76c3ff2d5253e9370b6811e6fb03f54eb69bf55d214b1bf299a710803e |
Hashes for stim-1.13.dev1700468449-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86698a7adb3fe77c4d0b7f2e6228af362ccc7225b2b0784b507f4e048643d421 |
|
MD5 | f8cf97042efd0a88b5955d032006068c |
|
BLAKE2b-256 | 7203c8f99f33707ba34f9b0e1558d2e5f51fbd06a9644a9427fd4f1d0b271750 |
Hashes for stim-1.13.dev1700468449-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df7056cb7a202ff814908a9cf8afdc7b717edfa2d1c79bdc86ff024b09df481 |
|
MD5 | 55f1cb6035025fb687a86e2733edfb38 |
|
BLAKE2b-256 | a3e73d6771568aae3e90dc776d0088f05927b389daad084ab734875aba81d0b4 |
Hashes for stim-1.13.dev1700468449-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4317efcb7ef207cd902ad627a2967488cb53690af40fa8d8c9dc3a3d41e02ded |
|
MD5 | a71cdd33b7bce9cc6fde9f2b86425b44 |
|
BLAKE2b-256 | 9494cc354ecbb20df298418c5f8de1f202153e89167b43cfb721db93ffb7109e |
Hashes for stim-1.13.dev1700468449-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 034b623373c82ea9ae7b7f5bfce892318219872b01666ecdf470b6fc4522cdba |
|
MD5 | 89c063aaafd3893acaf856eaac46447b |
|
BLAKE2b-256 | 462a8d9d8998719f6eb3963b2acac7d9227643c8ec5702c1c7238717c3efbbe0 |
Hashes for stim-1.13.dev1700468449-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a99031ba0662ae5baab0c71495978675dd30baeab476426fc30bdb692400764 |
|
MD5 | f3fc991f213be59296546d8b00dcded0 |
|
BLAKE2b-256 | 57ab4deea8ae0a7475b59bfd5b6f29948a279e52b2928f54ce8bbd31046daa7c |
Hashes for stim-1.13.dev1700468449-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8772ed32b7a82a5fd07bbbc4d6707c88a71a0a65d995535072a71b64dc9b5554 |
|
MD5 | 3ae066faaa561d1a94885200eb9150c8 |
|
BLAKE2b-256 | 58c7d927fb67607218a84b9ef64bb11b6deb99bf899e1b5d7d702d6a5ed41d41 |