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.dev1700462870-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e45b69aafd5999a82dbed2f5c3eb857b913bb7b140574107ffd6d273aec715f |
|
MD5 | e2041820d345b9d52e99cacb44fab7ee |
|
BLAKE2b-256 | f6f10a655106c29e2d2cf001a707f006e2191ea0f1be0b7ff7477075b704cbfa |
Hashes for stim-1.13.dev1700462870-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf5d3aa6214ca36c98a8b6a178ba6af674023cdb10b670e1d38b8e066443d6bf |
|
MD5 | cd97d99445781feeb1f18e39b7994bfa |
|
BLAKE2b-256 | 0e59b2b2ae3bae3153e3394e82063bedc86cabd15daaeed7d51fb270c8d88d48 |
Hashes for stim-1.13.dev1700462870-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800a931ec459dd43ab2eac75803850c6b4d119c75556c06e9b3e1eb89e87a57d |
|
MD5 | fa81e198f3d8c2824d658428e819ea0a |
|
BLAKE2b-256 | 4dbf7f8918134b1ea384ac8bcedb5d3569d6118c42e7bc286cbfa341295009f8 |
Hashes for stim-1.13.dev1700462870-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e61f795a60bb1febf061407d39082a2391719bdc37a4cbc9ade6fd672375546 |
|
MD5 | 35395d3ecd16c0fdee681854425f5cb6 |
|
BLAKE2b-256 | da2ed215963785c227894aec4bd3cb87db4687fa70b3dc5565e31d5da0d63800 |
Hashes for stim-1.13.dev1700462870-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03401d63e271f7bc9d409c575f7a4b48bfec1af9cc470dea086722a913e1d876 |
|
MD5 | 4ba112d31274290eb50c45f586217769 |
|
BLAKE2b-256 | fdf3264257f757b20b6f4cd927a2f27b7a5228be3558507bf681d3e865619c82 |
Hashes for stim-1.13.dev1700462870-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4100cd12b0378fa4a45a7f02ba4abe14585bb2e3ff5b130af0fe8316c2fb11d |
|
MD5 | e079fc330c55fe89d12288dcab000add |
|
BLAKE2b-256 | cec9dec4d7b99a2a739cd9af14449d4aa6d35d85d78ad661de82b3ead5872903 |
Hashes for stim-1.13.dev1700462870-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bc7b6f926ad40aacb18ef13bf5d8e6ea633a9fc4cce17582ec033c74f8bb95b |
|
MD5 | d158a1ef52e67bef10f64a608b8c5643 |
|
BLAKE2b-256 | 3f24c2a85c9ea3f69d9582a8bf5ca00b21d429121de38162905a79fe6f035de7 |
Hashes for stim-1.13.dev1700462870-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2445c41291f686f40f7e8709321ca9d902e27f38b317dce5e5f2ae96abf799a5 |
|
MD5 | eb799ec76dd6435c0cd875668629e466 |
|
BLAKE2b-256 | 70c74dab0c6f4bc5478552fec0e37b70e693df191971bcc2dd5ba9710656ca70 |
Hashes for stim-1.13.dev1700462870-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc7dce64a22698ec20c078536c0252dd86abc16ae1476ce46418ca6290771b6e |
|
MD5 | 5a56f109440292a23aab683fb410575d |
|
BLAKE2b-256 | 31efdbd28f98d45c3d4364c97e6dded8487433f076c638239ee8a49b42c573b3 |
Hashes for stim-1.13.dev1700462870-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eabbc3e004e9e709767d28549d0135f5f8aee1c4dd1ac8d1372f9443895a22f4 |
|
MD5 | 602b0948fd1114cc8ffc0737c660a0de |
|
BLAKE2b-256 | 24086a9371fb8f44c0fa109904bfcc8c1cee5dc3516f2cc8fbd778b704ab9c24 |
Hashes for stim-1.13.dev1700462870-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e68a8a2faf332cc16fd77439f580d0ce89ac75264c5d1c60868a9c5bc59ef3 |
|
MD5 | 9b497f0b935f2556e4c334dfcff22746 |
|
BLAKE2b-256 | 4526485b7c30d8fb2fd5a1555ba12398a83630778a7d30517693b49170295bb8 |
Hashes for stim-1.13.dev1700462870-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c937b36a1be8d3f9340c998d30ed6b2092d47f85ae71b13432bd5534381dab59 |
|
MD5 | 8d9cb18e67c3cf4cf4419a3de53d8633 |
|
BLAKE2b-256 | 3e56c4ba73502b1cf505acfd83fdf843ed050a5f8e72aeb303e142a977e5fccc |
Hashes for stim-1.13.dev1700462870-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df7e4de087917375fac73e77cafbdf8687741f22be986a5a977b3da205dd92ea |
|
MD5 | eb90fb192ad2af9a983661916b13bf1c |
|
BLAKE2b-256 | 65a43286132eec74f49c8d5158ba562f7ca9f10ec55494ee71449d6af1ef2efb |
Hashes for stim-1.13.dev1700462870-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17e85e7325944993db7438a6840218ae9f7a97761bce80636f9fea1d7e2d9faa |
|
MD5 | df2214a5da3699d4849c9f3a080414ec |
|
BLAKE2b-256 | cb5e58a97aff8120eea824e6d9975f25cf88d2a36a8fd7e1c9bbea2c3f0bed25 |
Hashes for stim-1.13.dev1700462870-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f204683d4fcc329ecb44d3e00d4e339d42dedfd191a1c2bcac7bc3cae8e93d3 |
|
MD5 | 0e937f4e040625ba0dc428069894022b |
|
BLAKE2b-256 | 862be7e8d7ca78da8422c0a8d39c06c3dafaf8cae8f7f37a7a94a5100c1209d1 |
Hashes for stim-1.13.dev1700462870-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbb4f23d913b9faed2d6933d10c1795139a19b4239f59e30e34a7ef52f9e1791 |
|
MD5 | 814c7e92d5653c410e4a00a1c6f898c3 |
|
BLAKE2b-256 | 4a9654771f3ee6df3e7293067e67d2c58e99fd2fda9a455477c93e5f4618d77b |
Hashes for stim-1.13.dev1700462870-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f841e8f35daa9e0e776d13af3bf05679f53aa5b5853caa5b5efc25e22b3d5f4 |
|
MD5 | 7bb073f875dc82171e241b3d027339ff |
|
BLAKE2b-256 | 81db154481c690e67c847db974cc0b8c796f9eef95523ee52b7e94fd81392b50 |
Hashes for stim-1.13.dev1700462870-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e41daf9d73e9bb06888da545afc89916fb905b910776bd947a5b0873aaaee23 |
|
MD5 | 63a90347ec4b8b2556c0a1996b656c1d |
|
BLAKE2b-256 | 3339f3cfe47e3ea77cb452873c1b93e32af95b442a11604c82c252e608ba1e1b |
Hashes for stim-1.13.dev1700462870-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baa8c4ea82952cdd1925ab141517d1a2a951aca31759997fe363596bb7d86ef4 |
|
MD5 | 82ad0878f8a191d2f303138d8e527451 |
|
BLAKE2b-256 | ea927898e1803d755a7a8a00069474acf65a3566ccc7affcafd1f3be400b02bf |
Hashes for stim-1.13.dev1700462870-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2276129eee916f007b47391e4b47870ba42c396ae70a8474e5f266d0b4c1f2e |
|
MD5 | 438e6569613961dd00555a3311cf86c9 |
|
BLAKE2b-256 | 80c2906417de5e3ef8e1508ef16dbcf77ac8450ea4181a38aee211994ac9185a |
Hashes for stim-1.13.dev1700462870-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e883d0600a2cb1040dc6bc76309021d568a474ee34c07c62913d6d38612b14e9 |
|
MD5 | dee83aaf4f61b9b66cdf03e7ddf61e7b |
|
BLAKE2b-256 | c26a72211cf90f5a009ed81984f709c073533a75948a61642277209028fc1269 |
Hashes for stim-1.13.dev1700462870-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02121747bde6b39e0c9feaaac85830e03347d533a72f3eb7b0c049d113b72605 |
|
MD5 | d378b5a6c0dc33710b016f664fcf62d9 |
|
BLAKE2b-256 | f3ccf57fa5db62c574ab8b9e0883880ef94e1bc710a2a54ebe51779425975e26 |
Hashes for stim-1.13.dev1700462870-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 116e80db2826624974dda8608180a1507c0028af68f71006923dd96a598e5949 |
|
MD5 | b256e6d89192db50b945054fa218eed4 |
|
BLAKE2b-256 | ddcf72b7788c7284d8522643ec928b1c1927abed0e9a6c42a9fc1cd61b42eec1 |
Hashes for stim-1.13.dev1700462870-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac2f7dc7bc8ed0f02cbaae9249b10253467e5b189a5e0e71e409c233a05dbf94 |
|
MD5 | 2fea31d29143606550c581b415ae267d |
|
BLAKE2b-256 | 9af2bdcfdd67908ae5d26f52b64c12121be778743c5e58e7499810520dce5ced |
Hashes for stim-1.13.dev1700462870-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d224778b9cfc1dd60084ba119a3049f7681111f9831b8f58e760c9e92d17c88 |
|
MD5 | 8e259e015e1d1d1003f85a238c09b989 |
|
BLAKE2b-256 | 149c903839505ce7cf862d6109d24eb8b91f12dd90963b5dbcc66866bdbf3b33 |
Hashes for stim-1.13.dev1700462870-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a3ba0daecc9902cc86412275f2b31474bd4ccfcd6dc59f5e05406e8f355e59c |
|
MD5 | 948705ba3ae3afda7adcfb180afce144 |
|
BLAKE2b-256 | 6d4c57e98f0aa6a1b19b8e2fd83cf2bdd246b644440a01e82ce00b3765765c7c |
Hashes for stim-1.13.dev1700462870-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c0cd09bd538d01cb1285938d6fc73975716b8f7b82cd7f2c65fa12f1bab3c08 |
|
MD5 | ccc9541a94d59e91fb287f1049238c56 |
|
BLAKE2b-256 | f7da398abda4720b3ac8117dbd0ec85dd5837b4f34d0e2a0c4eeba4fcc628870 |
Hashes for stim-1.13.dev1700462870-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e780027e7ad8fd3a667d09aea62905c05f285643be0c2e80ad4f6cad347afe6 |
|
MD5 | cc04122ff4c3db7fc5d3bd489af38588 |
|
BLAKE2b-256 | e4c5cb99ea54e9613ca073adbeca0edb21430a1e3d579be9d41bb7aeabe8db05 |
Hashes for stim-1.13.dev1700462870-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 300cf555ac47d0a9a505c249bd7c698ba650b0cfde6ccaf0824cee2c89c08bdf |
|
MD5 | 44d88173b4a63c9cf36d04a705fa2835 |
|
BLAKE2b-256 | 7e6be7367b21f399a82987c8ab4147a714ff54a60d542871a047d9fcdaf48c0f |
Hashes for stim-1.13.dev1700462870-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ffbaceb7874acd7b087ed9da1a05384d2c39ea355370e4f9a973f34cadc550 |
|
MD5 | 2bb60d5fdeca04bf57388f22c938634c |
|
BLAKE2b-256 | 8a7fa957622c2acbb323c7108b5f18af648d0606e547fbd3112984ed31f423c6 |