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.dev1688842788-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e1a13e57ed2192a6839d5ee1a3a309554b9d86815c34cd27092dbe9d3cdf93 |
|
MD5 | fb8776a5adda2199941c34376072a3f6 |
|
BLAKE2b-256 | dbfb99c038e2ffe49ae72e5d9c60c3a7d6db4ae20693cd4d9631293861cfb7fb |
Hashes for stim-1.12.dev1688842788-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f533598f951cf06b9ab5c7a1eb41ed0f2810dfe39f6126ed8fcd065b05eb1070 |
|
MD5 | b192b5fd048d22642cdce00d964fc387 |
|
BLAKE2b-256 | cd8fdb78dbeafa5e9d6b0e44a1fb32f921d4a25446f7cabf19958f76462345a0 |
Hashes for stim-1.12.dev1688842788-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1557cd01eae678a932baadcd21851feef98ba3559f103c095faf9719eb5ffea6 |
|
MD5 | 4d6319dd13c73a3aa951db368fb09abe |
|
BLAKE2b-256 | e1fd113c6dc3aba0ed81a713fb4636c77840ea65822bc374d517805adb0c640b |
Hashes for stim-1.12.dev1688842788-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06c89c18f86bd524fa97deb7d4569ff4bbc864985d5eddc3ca41b36e5f2579e8 |
|
MD5 | 9a4fa373f5268d1504402c1b68c0a537 |
|
BLAKE2b-256 | ce2b5651ff67275bc5c1750e4393de45c31349580af2256c45ec9104f1674ea8 |
Hashes for stim-1.12.dev1688842788-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c01ca9cd32e34f1a4cd242c41d18bff47d21e6751c724a029a0dc7b9159b9414 |
|
MD5 | 0a8019bdb25592cb76027345b5fcd18f |
|
BLAKE2b-256 | e272954320e65eb750f88551306404d3732f195928f4303463f8dcf818f36805 |
Hashes for stim-1.12.dev1688842788-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 017fdddaa3c57d024af767e2c25baa2fc889f24fe446e94bfae40650a1f66e68 |
|
MD5 | c5b6a1d4226e48fbda7f01fc71c450aa |
|
BLAKE2b-256 | 177f0fa7a8e7a44967d069754efc8f491d54b74612c7651bf3a6642932982298 |
Hashes for stim-1.12.dev1688842788-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2228dce1a54a11ad0023e23c5e2fbbb90b1c926a441074f4ec28ad8fcab1801 |
|
MD5 | 1db637477431e7ede37264877fb3739c |
|
BLAKE2b-256 | b708612c289a21a2869f4f4a3308abc9e940693e68cc4374bbcf77837be3012b |
Hashes for stim-1.12.dev1688842788-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9399762c202e57dd6f76cf5a552a3c861381d692b3b95da1897a5c1a9cce1f0d |
|
MD5 | 4d9e0aa51241dc793a9b63ddeb640134 |
|
BLAKE2b-256 | fea4af81f870115d300e6cedd75d152d8721a75096ccef5c5c09c8b95afc0c4c |
Hashes for stim-1.12.dev1688842788-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02859c2ce1295dbf43fd97ea951b382f80b6ae3c27cd460211d44c8308e54d7a |
|
MD5 | 1e1e058c508d406765acac0d6550f607 |
|
BLAKE2b-256 | 862b1c15f720b668a32d83ab1ae8a35cfb8818aad99859381b782f3e78c759c3 |
Hashes for stim-1.12.dev1688842788-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2087637321987492bc482e2cb7886d8652f6b32056545726761791a180ab92cf |
|
MD5 | ee92dca98124b520fc8bab1dd6527390 |
|
BLAKE2b-256 | e1be35bbf98c4a9b363387108c2c4eec036aa34ccc050d62177b704f3b2ba8f8 |
Hashes for stim-1.12.dev1688842788-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bff2afa127d2b965b002660cc231cf02ba53753d4276dab98d978f96c59b2302 |
|
MD5 | 1a8bb1e849196f8871eafcdaa7089726 |
|
BLAKE2b-256 | a72a240ee4bb97d65eb174f9dd6dc67497baeaf406905ad049b523248dbfd2bb |
Hashes for stim-1.12.dev1688842788-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace7eade844e938b030c15910023d1241997547911614ebb07564c8e1a29c89c |
|
MD5 | 73ef6b28557d435a4a3687dc32d9e7f5 |
|
BLAKE2b-256 | dc0af6a398bbf8883ca884b797c9ca9f1a2fb7ac4fb88f58e510537b6dff23db |
Hashes for stim-1.12.dev1688842788-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7918f0ef9df2a51f4e67efe067785c264c7aaaf5b693bb5786bac24abb5ae5ee |
|
MD5 | 37f48bfa9e2634d2ab574e4a8b0f916a |
|
BLAKE2b-256 | 69116af0226d2d156f59ffc6a33f98b7d8b93c79746a2690d66f645689799399 |
Hashes for stim-1.12.dev1688842788-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69a77432b32ce9fe7d941e0c5661b5e8f12a10ee61b0a21eb3bef4539c681984 |
|
MD5 | 813e5af7ab75b835ee7c3d2e33653323 |
|
BLAKE2b-256 | 6f10948518ac1adcad412600f59b788b6e3cae21384de72ac781c9232c730b75 |
Hashes for stim-1.12.dev1688842788-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7f8812cd54c4c5f59371bdce140d909f0122bacffc8291783ae97911b584b8 |
|
MD5 | af73083b46501291b055d78fc89c4c23 |
|
BLAKE2b-256 | 838f68523b0ed572e2441a79a9571a6759d58acaf49f68eb74a0a6fd5a99aad7 |
Hashes for stim-1.12.dev1688842788-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d4ab53f20958bf02b474d1df08b16bb85c634e2989fd08a86eb3a774854314b |
|
MD5 | 78a3201f6f92978d0480910bdc91b545 |
|
BLAKE2b-256 | 7dab02c3426b4c72235b677f29db4368c05029cde20531d0cdf71a10e1da2d07 |
Hashes for stim-1.12.dev1688842788-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3fb0ae469d47e1f4d2808bf7313470a127a3c8fa25b1ffee8097212d4bd282c |
|
MD5 | 076f0db904664527a12891fa7e11f64b |
|
BLAKE2b-256 | 7102ca956a98ac9935ab9aebd077fcde71520ff93fab698e910594c3b14827e9 |
Hashes for stim-1.12.dev1688842788-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51268be5dc9a139856c5ca0c8cc1a8304e7fc0055f4c7cd9c020ebab638abdad |
|
MD5 | d4d83d64dd866069ed4b4a01b72516d5 |
|
BLAKE2b-256 | 9c43590d68e5b73ecf4d5e5bfc9d616a8570631974670da587fe285f88243ddf |
Hashes for stim-1.12.dev1688842788-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8d554731f1a7515bb084c0f499f486e00b4cb613c73be854b5350f30b9fa873 |
|
MD5 | b1a6ac1db98a49b136c6ef4be89a62d3 |
|
BLAKE2b-256 | e428acff7973203871b9cdba6c63777e54ef95f76c14d6d2ba824474730996f8 |
Hashes for stim-1.12.dev1688842788-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84cfb1aa8289b43bdadbbc56bd03808d306b57c060479f10fe6220384f687f67 |
|
MD5 | a26130e9f2032a4002d24bbdfab358f8 |
|
BLAKE2b-256 | 770978edd909925b326300e7426298399bc4a8b395ff86c9111978505b66d39c |
Hashes for stim-1.12.dev1688842788-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac0b144a98c8e169dea6179e28fbaf8d13eb6fd8fb6eaf1ed01793c51369167 |
|
MD5 | 8d5df6620a2a5d748a1f8d136b8258bb |
|
BLAKE2b-256 | 1fc994b24ff3141ba73362822e36425f4172398b6f7d405d444c0bdbde4bad9e |
Hashes for stim-1.12.dev1688842788-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faec2095a61022716637632877c56c750f73268c546b68527134b7acf4d0ebf1 |
|
MD5 | baec816f1b1b7769b92c0e4408be1e03 |
|
BLAKE2b-256 | 8caddf72f3f7d7be6bc20a176e848eaf105c721856a3a9e3848eb08b236805c6 |
Hashes for stim-1.12.dev1688842788-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 209fb989f4d448ae1994695c43e9ce06358bbb72fe449622282ee7a124c7b685 |
|
MD5 | b6eaebeac61e5c020ab0c129e214b0e6 |
|
BLAKE2b-256 | dec22838e01f8b1215630777cd7a6354229916e8c2074892967726af0cae6397 |
Hashes for stim-1.12.dev1688842788-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043c063e9dd234ce6fc21202fe525b420fdda3a533687761fab8ddb290b4faa6 |
|
MD5 | d4f74886be16b3b93776edf8d07143b7 |
|
BLAKE2b-256 | e4a5d3773fe69e1d238885edc035d2e062a48bd98927bee05030242a65f576a1 |
Hashes for stim-1.12.dev1688842788-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d82f3449879e553bbfd0d7f953d4f3d15439a4808aa04ba2dac44a569a95a7f5 |
|
MD5 | d8cb8a00b0c9faea2ff894791dea6776 |
|
BLAKE2b-256 | 2412daca3386dc3a4ccf4fe436e2fa31939ec1743e157c7e0db397d1785d1b41 |
Hashes for stim-1.12.dev1688842788-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63cf424f2f3b2a5461a061d663bd076f348c2a284c2ac2117f43cad413740d1c |
|
MD5 | 59bf1e673236410b4259d9c87ccc79cb |
|
BLAKE2b-256 | 535d867d648a1c8c67c41232c4865d6f05a6f5e9d4f6527d515d250c9f1db5af |