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.dev1686530425-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8df1eaaaffd48fb3a84b6d6c00732c35e27d3b360b11a9b72f4aded390365112 |
|
MD5 | 5fe2d5be772538d9376e91d0bdd0315f |
|
BLAKE2b-256 | 7082a8e35e0eda981fe18976fe0cfa2ecdecd535a36ef53253cf1d2e2823e0f4 |
Hashes for stim-1.12.dev1686530425-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c8bd1e29d9ce577257e58b3854530cbaaa6efe29429316f44a23e9b36a685f |
|
MD5 | ea48499669a70795a9c5c45918476811 |
|
BLAKE2b-256 | 4fef72347f022682a7d1a34fd9de8df765aa644af008948b5866842ed83731e8 |
Hashes for stim-1.12.dev1686530425-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36552b93bce653069333156e660a6d56813be681459fa463d6abb91bf12e70dd |
|
MD5 | e65fca32d4666a38e8d943ed27630392 |
|
BLAKE2b-256 | bf2b29a651f951f281e7dfc5bd1946a525feb90665be1659478941c4105ba6cc |
Hashes for stim-1.12.dev1686530425-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10884a967cec97c97ebaec9edba039e88bbc598cbe998e1a5ff7826eb6a16584 |
|
MD5 | 11ac514847028db99532aaef78ee2537 |
|
BLAKE2b-256 | 2b5ff9704b647a747d19ccf977f3141d73712f9045e70b24307c116fefa56bdf |
Hashes for stim-1.12.dev1686530425-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61ac435bd0c6d71ea5a80d543360f63fb1300ac7d612f6631ab68aba1f0474dd |
|
MD5 | 867178341bcb31b378a5f1e395fd6fa0 |
|
BLAKE2b-256 | f35d7bc856814d8efe3a10e878e7a8e49e6b4fb0cc0da4c8a9020c5d544150ec |
Hashes for stim-1.12.dev1686530425-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92d3226708ff0101856dc6a4378e85aa393be9979f6e743a4359a1afbd0b344 |
|
MD5 | 3192c624bec77958f3cce695c60a75be |
|
BLAKE2b-256 | 4d4127bcc165deae6eb68630945b7db9ff6def22bcea8d7333eb9554e0fca0d2 |
Hashes for stim-1.12.dev1686530425-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80048fd38c5426d0cfeb4fd7d8bd99def7ad687108e3c6df752d72bf25fbc718 |
|
MD5 | 5f2a0dba65167a671493ca22b245c915 |
|
BLAKE2b-256 | e430bd7e898e3fd48011b3d34b161368c095b010860a35d9d4a344675aece934 |
Hashes for stim-1.12.dev1686530425-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 807f423547aa471c7e3409342c9e4d405fef95658187c738a9a1dee9acec12ea |
|
MD5 | 9feae2a144199a8c18df159964f6f3a4 |
|
BLAKE2b-256 | 8743096e9077eab33f29e064a0f94d3b002ce54b9158253a316b99ae814e8dd5 |
Hashes for stim-1.12.dev1686530425-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a317e9473bc607895609639d9713bd06920c35b3f88f4ef97c43b719f6eed96 |
|
MD5 | 89da9856f39b6cba6db1d8ae3da92216 |
|
BLAKE2b-256 | 94973194d44be4b33991671995d2d524bf63724b7cdcee0844098bccbc5d1ed2 |
Hashes for stim-1.12.dev1686530425-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a3ea7a283ed6fda1271785f2354325fb709c489d780f97ace3f09f07c6a3d1 |
|
MD5 | efed85d8da09b40cc9bc47cf46164944 |
|
BLAKE2b-256 | 86c868831bbc7a7736abef591e8325710d6ad6379397af3d3b7912b83a3dc5b5 |
Hashes for stim-1.12.dev1686530425-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e203c5e873b3cf66914f1b2587d58fac45eab25025a2bf57557b4a417c7a9f63 |
|
MD5 | 242a17221612e404ae673e8a64195980 |
|
BLAKE2b-256 | 2a7afccbcba91a50f42a88d5520769e3f25b1122a4dd6f052a5165f6fef23333 |
Hashes for stim-1.12.dev1686530425-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c93fc7c4c1ace2ad99c75e94a2456280dab3815580a1d2c4734b3c96b18247b3 |
|
MD5 | 1a9a1a71ef1e91dae18ec1a04e91c1aa |
|
BLAKE2b-256 | 016bf374c726d60aea885a60b74a14a257a2317c55c637445dc069afc545cb3b |
Hashes for stim-1.12.dev1686530425-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e71e856c0ab71d56b18f5355dabc461e5767f57a6c1ace78037bc6e59e8bb3e |
|
MD5 | 194d8bb19c2e9df15979d978b8d1888d |
|
BLAKE2b-256 | e14e1ca6439b5971bbba2f3d6d921a9b75a300c1923e8eb3d5056f6e16b8389a |
Hashes for stim-1.12.dev1686530425-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 688c63040611f95007f2f53afc201c26d1c902db887340351ad1f89f6db415b4 |
|
MD5 | 176bc8f74edc7f2902d5a96404bf1029 |
|
BLAKE2b-256 | a7290b641e1f686d97358b8c4ca0cd27071d0cdc56a2d93f5282cd02efb8ce1f |
Hashes for stim-1.12.dev1686530425-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aacba9f52248060158093c0ad733c5da147a1f1fa69ce4e1ac93a7d5f40168da |
|
MD5 | 5fff9bf679d16f5ef1d06f0f7e0d5f2c |
|
BLAKE2b-256 | 0dd6237393aabbd9a0831e9096f7a0c53b339a9b11d955237210cffdecb0e9a2 |
Hashes for stim-1.12.dev1686530425-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3714019973adfe2e57f0147e0b33a67f8fbe2f1974e647e5dea195266b4db23c |
|
MD5 | ddff2f8a4a3a8c6b8f84a79e66961882 |
|
BLAKE2b-256 | 29da7c5af014f8b1425bd782d8f7a978a290802a87402553cca435eef6bd46ed |
Hashes for stim-1.12.dev1686530425-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe0e3e5f7c2431a3dc9efc3fb72f18d21b14e2b328df22180635952120d613eb |
|
MD5 | b631e8afac3b7a3a25a6dfc1bfa9e154 |
|
BLAKE2b-256 | e7de77176d2dab112c89b2d5a7fb2f393491dcbc9df454e1252bf8bcadae48ed |
Hashes for stim-1.12.dev1686530425-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560f8b58d2e18f440c241652ea60b5ca4bdcb2f137eef9ecd215072920ef57fb |
|
MD5 | d0d4fb88c32ca95683e34f2c0eb41119 |
|
BLAKE2b-256 | e1f740bdd9fab34cf2b72e1766251929ff35749ee0c2956b37f61b69e6d81c7e |
Hashes for stim-1.12.dev1686530425-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d63183ebfa11081776f0e86e898d85dfb1c7ca5ccd8a2491c1d3204f768e304 |
|
MD5 | d19604b88e6e83e5c0c1bc28baefd73f |
|
BLAKE2b-256 | 552f3f5dc63de96933a5305038c387cb3cb5a6d404cdb46f372ea6ab150d070a |
Hashes for stim-1.12.dev1686530425-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46e5f31ef7d9132d51467b4ab424cfb3706596b49977c94ab61ba886947f886f |
|
MD5 | 23fa29cae43e8608ee4ff87e822e146d |
|
BLAKE2b-256 | b04f76d907a43faa33c197bca02bc631516a715591829ce566c5e7adec23a4a4 |
Hashes for stim-1.12.dev1686530425-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf2bfced72a40ad572ab9b80487d0fd8021b5b25b070a50e626d27582c98b614 |
|
MD5 | 06375afd29ca0cf8b22d2f9ab5d1f5b3 |
|
BLAKE2b-256 | a38738b27c80bb8ecac3426937c40276423a4f2546ffc3dde44564dc469059ed |
Hashes for stim-1.12.dev1686530425-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcb8c751e8a8ea2d4a3e6eacbfb26b3b0094214098a58065bdba2d404bc322f7 |
|
MD5 | 3f261e578603f7ccb789dd47230bdab5 |
|
BLAKE2b-256 | c3b9247a90baa3b2ab77bc090b237dfc42b5753eb3307f4cbcbb30883a9c446d |
Hashes for stim-1.12.dev1686530425-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae93f7970dc53312b7bee3e7227d729b518f28048cd0b4dbdba5dd3c7ff8392 |
|
MD5 | 1babf2c9c64a147ed5466df577c0354f |
|
BLAKE2b-256 | 271d4b68df8b14ae3e999db9e4d708b41e674316ef1925c7f8bae09ebb30e8d3 |
Hashes for stim-1.12.dev1686530425-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9555c15fa3b25515fecf4749e879ce17e5a180af06d9a2506761d36576780040 |
|
MD5 | 0720aeea84a9468cf1f9b94a1bcd988d |
|
BLAKE2b-256 | 405040597acc7be82e782dd82980060ce32bdf7b04542eb184bde49ace5920e2 |
Hashes for stim-1.12.dev1686530425-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 274a91544ebd92ccd49f9a1d8040e2a1fce1f61eb9242736d057ee3c2de694b0 |
|
MD5 | 3f881ef0654c5f5dd176786448d6da19 |
|
BLAKE2b-256 | 2873f8d3c597c42e74df6b71ace1a416e9b2669c89da4dcf68f253f52e626cde |
Hashes for stim-1.12.dev1686530425-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a61ad210e26ab9235de119dd9dd25a6b74ca433bf07d17c482c4283e6d5ec33c |
|
MD5 | d81010b09f035ca73a1e71567895051e |
|
BLAKE2b-256 | b7344e7c86e212002248272bc54c7eaf3f47638a72190b8336e4959d3de4f111 |