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.dev1720938100-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0896734c0a1be10b593e36e4519485e568a45d11f79918b59195ed859bed00d9 |
|
MD5 | 9e1c61344777607dd823ab73e3353869 |
|
BLAKE2b-256 | 0b6bbac1dea87adfa8505c340197a6add475d92d9df01f45dce6dbebeebfd5f6 |
Hashes for stim-1.14.dev1720938100-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5e82e0fc4c6ba6537a7095343e1c6f7d7fe9d69f3f2b910d48057403d3724e |
|
MD5 | 120630fc7821d8f12ab3cffa4406ad78 |
|
BLAKE2b-256 | 0f6bbe6da74d2d4d3f97d24008f41eaca3d7a385306b8f8a455af70f358fa198 |
Hashes for stim-1.14.dev1720938100-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f30659e25ea584e78f64c6c1d879b9ab4fcef00fd9115349506c757e19aae3e |
|
MD5 | 415c80200a1275cece267eaef163eb3b |
|
BLAKE2b-256 | c8296a0af1bcffeea1ca5eff291acc28f84a3e8088ca366a88581855a675388a |
Hashes for stim-1.14.dev1720938100-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05051ea1e60dfc74f1113464ab226baa8f83fe8382b25611cd486e950c628630 |
|
MD5 | fd71a6df2816c025503aed6d2d1292d6 |
|
BLAKE2b-256 | 44c6ef5f61c553189581dbeec66e02fbcfdf5529c48cc5c1870c1edd0b5a5d0b |
Hashes for stim-1.14.dev1720938100-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d83e1e12ecb11d865dbe46021507b01c2afad38136fa94353676a8648e7a18b |
|
MD5 | f24315abb5eb5ecfd3952bc526786b7d |
|
BLAKE2b-256 | c334d9e380e4ff6da7d62574452cf614387aa1e3b4bd2f5be65c2c538e8278e9 |
Hashes for stim-1.14.dev1720938100-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9764a09da6f3b0d6282ff81cedfc058c029e55492176024dcf4fdbf468866a7e |
|
MD5 | ba6122d9b4f3143378f876a0b53688a2 |
|
BLAKE2b-256 | 86e16a788a39b2cc34a43687e95ce54223d9d4f15cbe04b52bf3a5e994321136 |
Hashes for stim-1.14.dev1720938100-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbe31b110b9e4499ccd5cfb4b35dbcb4c015860c7335842ad50e931135f28503 |
|
MD5 | e060ce0f7dee83bdf30e45705c38c18d |
|
BLAKE2b-256 | 5b75805bb96d4520e3247660d92fe425606892c249d8d2e2dc949b30416f5ca8 |
Hashes for stim-1.14.dev1720938100-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad4adf75801c129bf34d6b87286455910a33c9a10b7de7b5fb8860e2bef40f60 |
|
MD5 | 62198b3398bf1ceb47b34db0ea5d0919 |
|
BLAKE2b-256 | 4b855adef6a3637ba9f3913bae7b4e1e459dbb37d0f91a00ab296ca7ca9e3555 |
Hashes for stim-1.14.dev1720938100-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8650e8dee8c963eef5fb0f6fad8d31ecd04cbe0556e6ce7e182e6e2e4bab5b90 |
|
MD5 | 6dd4d65392f510e7068546936b62c851 |
|
BLAKE2b-256 | fd5cf416d7a5252ad568a7c76016d21e2c0d2e06706c4e2f2dc0f55a0059ac0d |
Hashes for stim-1.14.dev1720938100-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f4245b7c05372ddfc58c877797d4126375c7eb1ddd071c0a7d1c1416333deea |
|
MD5 | e28b8d9952a2f083097c734d4c7af411 |
|
BLAKE2b-256 | 53203fa56e48c3f7e374828e333767cdbc86a2ebe4e96f4cac93c359ed12b523 |
Hashes for stim-1.14.dev1720938100-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dcf96aefe88cfa296769b26b3ef0c0a6cda91df97fa14632fe52c172d81eb47 |
|
MD5 | ae76f5ed017e204eecf8c7b215fb415a |
|
BLAKE2b-256 | d5d7cf10d707cdf6474a9a50feab946ccfae13a16872b2bb7de37859dd9d5e54 |
Hashes for stim-1.14.dev1720938100-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87dd00bdcc88b408f81fa0c0436a84afd7b6c2b4e21ce7a635e95d0de4522eea |
|
MD5 | 36db5cb5e0ec668e86704f14315bac87 |
|
BLAKE2b-256 | 856ad1b4df46f6f89a9ed6f0eae641ee40786c6dd944d292102a58d7524218e3 |
Hashes for stim-1.14.dev1720938100-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf0bee6ef14be71d08ed5ac46f35d14742edd409abbc3c539d814ad9c7674a8 |
|
MD5 | 789361fc2d2627066711638f0d5a1022 |
|
BLAKE2b-256 | 341fd4858687793f22c7bc515fd10985d2910fa4c29c2e952a179db1f11b4ad2 |
Hashes for stim-1.14.dev1720938100-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2604a9217dd7479e397ffe2640b4a7e9c53e4fb48b71e68027423d0de357cb1 |
|
MD5 | f2c2de323f3f0ff636e9de3f1a620001 |
|
BLAKE2b-256 | d0a1a6f5789a368b5686b4f7c0191a7f8aa712a434935d4e24d850df5dd138ad |
Hashes for stim-1.14.dev1720938100-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d4f168c38009c371e00ade20d9a6f8add38d3a10066cce7389c4fb76efb1782 |
|
MD5 | a69c14977eaaa9432136996b25f43e53 |
|
BLAKE2b-256 | 400d63d57cb751e6d918bce6a50a84c529e20a31dc4ae907fdd7ff2e6384bd2b |
Hashes for stim-1.14.dev1720938100-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e4ad577d3e4e6704c81d1ab308325df914b2ac1095ec22ef8c59899e6db65d6 |
|
MD5 | 4fe3b5fb9e2595a8c05655f6f41de9e2 |
|
BLAKE2b-256 | 5a360ebeef7920bcf231f40e5e3fa1cd1fc5d21e3308a4de881a8a4fb2d12bb6 |
Hashes for stim-1.14.dev1720938100-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c489ecfc413d90ae0c7da16be31e8188834c917a483f2c46b7ef5b1eb82db6b |
|
MD5 | d03b71fab3de540324447d37901b67ff |
|
BLAKE2b-256 | d8ef9be4818c046a379655d48c5eb1c887dd6cacc65fea0d4cc208237e504497 |
Hashes for stim-1.14.dev1720938100-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7fa2e367bdcf955cfd2879a7f9d19a222dcd09f9fec7f0cb84ad1dc46d91db |
|
MD5 | 3671f336eaeef7a7e88d2717e738f446 |
|
BLAKE2b-256 | 6b6a52b643b0093d77dd29e8c96eb7fb4144d8393b5dffd391ce499cb7ba30fc |
Hashes for stim-1.14.dev1720938100-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abfa379f4e7a83708507caa13dcb3bd9f8c9d9229af88ed32c3b00a5334f01ae |
|
MD5 | 96e5878c3a3e811093e308e414abc84c |
|
BLAKE2b-256 | 871a501f76e554d1e0fbfea85f91e8dad595e5b526c08119a8e89bb749d16090 |
Hashes for stim-1.14.dev1720938100-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bff845c2f5de56663ac3d550762213c93fc798943fb5fe052686bd56e9fd6bd6 |
|
MD5 | d08e89b76c2d47fb566ce638aa1bb87e |
|
BLAKE2b-256 | ac9aae74bc65e3624fbd34cbfbe44d4fb4d56bea54c82aecb09459d88add86df |
Hashes for stim-1.14.dev1720938100-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7db857547e12ed8d19a59320a4d9f2a4286fb093d9cf991b349ae622be1a032 |
|
MD5 | b1492d669dd3dbf5276b6ae1f8dd0643 |
|
BLAKE2b-256 | d49f230d5bd1cf1304ccf73a07ad9662289c07b9bce8402adeb9161dc6309999 |
Hashes for stim-1.14.dev1720938100-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc8549dcc70605f543f225f3cfd718c68988563814497a951cbf3f9a3523a76 |
|
MD5 | e5497cd65f2b7e1833ea743e562578ab |
|
BLAKE2b-256 | 90c57ec28ea4190d940ec985fd7ab479ae0c7edaba01af8a7db61d576073961e |
Hashes for stim-1.14.dev1720938100-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a710b5ec1ba7f1fc640e466d64233062d0e8d465a834f0febb084414614524e8 |
|
MD5 | 2895de93801f32b29c28b30ae472b0a8 |
|
BLAKE2b-256 | dedf5f01fc0467437c6bad74ab66d8ff0d17680faed3e0249f431eaa59ef56f1 |
Hashes for stim-1.14.dev1720938100-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf79a11fb1b027f3f5fde7dfb7f55ebc4f214e60f73b16c8eb07ef3f634aefaf |
|
MD5 | 517ab7368825f1b107eb6614ff3de70b |
|
BLAKE2b-256 | 59b9637dff67f4f61bed8149203fffae7ff0ead5cb36b6dfc21fc517463addc5 |
Hashes for stim-1.14.dev1720938100-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 502adfe960d67dcb6e3440a4553f7beff887dfdb761c820534f134ce71d47e13 |
|
MD5 | 54e113f93ebb9ed6e30eaec97c8ad8a9 |
|
BLAKE2b-256 | 3074d0d51366ffe32571007319812efdc0bf47454c94bb444b120889d66cdd64 |
Hashes for stim-1.14.dev1720938100-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63bb96c7bb8189d017eebf2c221d9219157c12aacdc17408d6952f2b9fc5c30c |
|
MD5 | 83c732c89b586f2b688af2ce6f695e5b |
|
BLAKE2b-256 | e1c593a886da4b7961f1b9048aaa6160c7c0d70cf370570f76ffbcf70677bf36 |
Hashes for stim-1.14.dev1720938100-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368f34f3145c7ef85bbd128dccdf7339c71545beb0b6630aabca9f1ee6498717 |
|
MD5 | bce7ab01c0baee3c0289bfb6cdf4ce2b |
|
BLAKE2b-256 | 3765e7f11dac3cf4763c5fe0b79b2bc3697f147d1110fd61d568024e6b26eec9 |
Hashes for stim-1.14.dev1720938100-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed823a3e9bfe0546543aeb2ac9ba0cd577db00fd9a5e1c265593e44af47796a6 |
|
MD5 | 74253fc1c5bb3759f4e25dc150164908 |
|
BLAKE2b-256 | e4d449d3f4d78a0cf2946a3b2040a1ab0a61e3cef2caf9a26cefd6bb574aa6c5 |
Hashes for stim-1.14.dev1720938100-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e16cef293242cae472c4618f3e5e81769e22d52bdff6e55386f1b6bc9282fcdf |
|
MD5 | 155a73fa3003c1e42228903de83d7a03 |
|
BLAKE2b-256 | 119ed2eeff5d319eb150ce2d6d34661f90b424d21f330e8507c90aaeaecd2e13 |
Hashes for stim-1.14.dev1720938100-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7be4d8867dff46e58778143732af1cd05c1d1014e1bd9b90f48125d0194227b |
|
MD5 | 382feca2009c41b628cc79bc9b5bcfd2 |
|
BLAKE2b-256 | ca49b2a34d7dc7d0b86fe6703cc2e1f395ef43ee3da20036cd997331f9bba846 |