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.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39425614ad476b0f8ddf75413a0710de00d1970c2a5b90ec417e221a1412d42c |
|
MD5 | d2aeab6af017044031cc993d9ba81191 |
|
BLAKE2b-256 | 0654aa1269cab0e342de31f3122dd0c8e06be4624c1ca65bfdd09ee2ac4efb16 |
Hashes for stim-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff7f6fee2bd6e1bc718b4e57205d6d3fc6d3c292c3eafd22fdb7a8d7b010a1b |
|
MD5 | d4861e049a741ef55db69ca318111fcd |
|
BLAKE2b-256 | 1971de7c2a9e6cfe0ea078cdea34cb9d39a6898964880212254f47834e629779 |
Hashes for stim-1.14.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a86f9ccf0be4e4cab6ba246c320aec5ade9aab5c586d8afa353440b7e6372b8 |
|
MD5 | 37ecc90a1c858f1a9d4d43219f67297c |
|
BLAKE2b-256 | 022f15d0ccba620aefdeb1c064f97eca04d57525611d7bc06e7934e96f02e8ec |
Hashes for stim-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 383464d27a7f2a692fe4877607e9f894f6edaf3e7b5ed2d55d3872794e0cfd0b |
|
MD5 | d7551164d9d8fa1867e01ba15def48c8 |
|
BLAKE2b-256 | 131b9cc8cf338235a7585a11aae5d6c237bea2bbd6191063d08790bf402e5c33 |
Hashes for stim-1.14.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebe6fae7aa3b80d38deb662e4e410686d3af8c6a63eac44ae424b7d26e3726c4 |
|
MD5 | 550ce138a3fd84f88b76d4357aef716f |
|
BLAKE2b-256 | 0b55bc54681d0969f400b08f562f946e2cad4216c4d5699982f6ba9bff177b57 |
Hashes for stim-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb34d8ac0d13b604af70de0a6a58191045b4f3d09fc1ffedd91683315d1c99a6 |
|
MD5 | 6b4986e98f569c1092795f1a2729c136 |
|
BLAKE2b-256 | 30351fb567928b10a37d541bc809ac0883fdcd9f89b00b50ecf1e1761596a481 |
Hashes for stim-1.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0716c47bf5090db014373b44f471467f88b1a019698741bee189afdcb0dd3f19 |
|
MD5 | 1cca2e614e5cbb75974b0eb652ecbefd |
|
BLAKE2b-256 | 1195497325c2bf8f83782d1c5217e58cd736e67545cdadf9f909b120089a5e64 |
Hashes for stim-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea0f96c63a2d278b5eeb87ea1faea23ef5be9a7ae3bb16fcfa67cd00792471bc |
|
MD5 | 8c9e072b69e0d5c54b5a5d5b07908f3c |
|
BLAKE2b-256 | 9685c928e75b52ce91d74c409c1cf2537c8b6e91176567ae4d5283b94e421951 |
Hashes for stim-1.14.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c42ced0f4432b15954b88b93905e4f3815ee7c6b827f40917b74799b0f4fa3a7 |
|
MD5 | b93172c97b74384aba439e3cd428c56b |
|
BLAKE2b-256 | ab7db5efb84c060059ab14791a79213a38412273e81ec203dc7ec3ca528d64a9 |
Hashes for stim-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3568b4d79e90287aeb12581cb9b7a854e223427a95d19ea838d918b5d40431ea |
|
MD5 | faa3ebf96bb6d42f4c4cc7b24b279ecf |
|
BLAKE2b-256 | c9057902e01f80a6ab6a6a318d3a2942f1c31fbac5225d3021f7953150f2f0ce |
Hashes for stim-1.14.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13b1814cef65f591238f84be62c64c7cdd2494998a92911812207a69e52cbed6 |
|
MD5 | b2f07d945b948116421e1b5c26d6b0a5 |
|
BLAKE2b-256 | 0db62a745f9bdfb6bdf8aa8a3314e2a621b7dd0d482f34bc639abee5bdd1e8f3 |
Hashes for stim-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c01b47ddc708aadc36a8a4b2f4873c54836120565f24b6a6b92ad7c650b1df58 |
|
MD5 | f3589412e586fae1ecf964bce8812f0e |
|
BLAKE2b-256 | efdc90c512151ea0428f6e3e8435b964e8e09bcade78336737a4c25ae01dcdea |
Hashes for stim-1.14.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19b4aab97e347bafc03d95231025cab5abc93151611b6a811ccf4f13df86cd66 |
|
MD5 | a9b93fc06b108c1a904cfcf2822c135e |
|
BLAKE2b-256 | 0b73a0db8eb3e200a703d476a8c9091caee71b00d324d6bcdf3fe085dbfbe8ad |
Hashes for stim-1.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5344d1abe2c9a7382942c634c8c8fd77023ef1b04378c8db400bf3c02c010d10 |
|
MD5 | a550b2bf3b336cedf69124376be46e28 |
|
BLAKE2b-256 | c6a357cbc4b8e5c5b3c3361127d0ba1aa6df4a5af18cade80d82291dedd9fde5 |
Hashes for stim-1.14.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 651c72a98e24304bb36e92d79c98024628133fb7c39681dbe8704a988c930ad6 |
|
MD5 | 4019f7c3b9146b6e24bf246eb621719e |
|
BLAKE2b-256 | 056dd19eec8ab1b4790d43f7d3055bb5d1cba7c85bc16115c49da0c3dcf1eba2 |
Hashes for stim-1.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a3bee99f98f362fd9e124e5c6488fe8abc52200c2a7eab2976930c29b2fc43 |
|
MD5 | 1130d219db24bec3c3cb5fe3fc78f8af |
|
BLAKE2b-256 | cf2d1b0b0c571881161971167ffbeeed8c7459e7ee87d0a9f0aa62bd05c2458a |
Hashes for stim-1.14.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8cfa9c601329619eedadd11a33acc356899729370b96c1f423b2e22a49eb98 |
|
MD5 | 3e5b6b59ab9a28936b6ec11206a6dcaf |
|
BLAKE2b-256 | 88f542157550597978703db1ff4630ed2945b7788648d9fbab584879c51aac2d |
Hashes for stim-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04587a59bb0d9b756d3cb9367f1ebe02fb30ea8b1330da7f4f99b71cd08e3f40 |
|
MD5 | 6b7cdcb42d1d38215c3e93cfdc278cfa |
|
BLAKE2b-256 | 8eefdbd6ae3b2bf414024f736da0f7cf115011437fc8c385e979496e1a845ba9 |
Hashes for stim-1.14.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a77bf836fb5cf146befd215615c1144dc150b855c3226e39e6eb6e5d412d4f |
|
MD5 | 69429c1cb8a2dbe52e19440668f8cc17 |
|
BLAKE2b-256 | 654714a0e345a9dfdbbdd31ec526754950e9e5a47e8c0461c574ab2e8c0e9a70 |
Hashes for stim-1.14.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d685d25af2d604063d9cdda773d8f3404747cbcf9346ddac737b1ee552b25ea4 |
|
MD5 | 43412dbd544f1d571269340b480a6dad |
|
BLAKE2b-256 | e16a9167869b841bb413a6432f081629af706bbc9e2612706612900c3a936f0d |
Hashes for stim-1.14.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4269141eb824cfede171d44a74665f66d088ea227ddccc9b2bf05575948c172 |
|
MD5 | db4a9dbcddff7960df32a1820ad3ee3b |
|
BLAKE2b-256 | a380ed9b7c81932ec4fd6ba610499151263e31698e883c59a2800f151a0691b0 |
Hashes for stim-1.14.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65e0ba08440c6d871d319f9eba196ac9360c22396fb4b07732c5730c76a3d8e7 |
|
MD5 | bd944a9f4c5b903594c2c9642691b4cb |
|
BLAKE2b-256 | 7a61f28c9ef4f468e1acab91bd185c1159859fc2cbb35f8fffe14918e977299f |
Hashes for stim-1.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b61e3cc13aa8f2bdedd0194c42414b56a8f024d06f2ef4d745b77f99109cdad |
|
MD5 | 07978b971ce057cf3056ab53e6395469 |
|
BLAKE2b-256 | f483760cfb1d93a7bbb7f9f77d9ab9e3c12de654dbb314f6c779dfbc8aca37c4 |
Hashes for stim-1.14.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7855eca741b27d22d7964bf3bc7b509d381a329786f33f5f1b4656ac9968269f |
|
MD5 | 8c8d45f0d0cb73d8cc0fa2326ade4d0d |
|
BLAKE2b-256 | fd5b5d2b06b73823a30c4d6a985d3d4a70aadd381f9508639b8cd1133df71176 |
Hashes for stim-1.14.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 422a7f12a203be20364fc88c0373a0e0a8b6141762d8cb1a997e01724d8a1cb6 |
|
MD5 | 2c5e43b5d2829189c5124fff64b89058 |
|
BLAKE2b-256 | bd46217d9d24563a266e464eeb44ab6e66aa661f5e1ca4437fc9f559c5d6e1e8 |
Hashes for stim-1.14.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7492aeb319ba5d467937ef43b63e25a660891fa2b051b444e12f9dd307a26db |
|
MD5 | 373fc8a3bb0cbaf9ac2d44f44d158bb0 |
|
BLAKE2b-256 | 73da71617d51fc2a8001592a33b927a8b70f60e5f63259b51acded173f07605c |
Hashes for stim-1.14.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 861ff5c327b263f68e64e11ea00a450cedf6246645a684ebedf7168c00c606e0 |
|
MD5 | 9d5f19ee9a9a0598023c313145b1f286 |
|
BLAKE2b-256 | 6d6a18fe301c39807c755647dbcb566ba6e0d14a933d9642b3c525fd45b7d178 |
Hashes for stim-1.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b44935d177a56c5fdebf3283088f1014a7271f15cfcf8cf21ccb50604abb95e7 |
|
MD5 | e3f3178793c05de7bd23930b20249a7d |
|
BLAKE2b-256 | 487388960bb9064ad000fc9338ba022cc67865d16e1a9e513cf9ce9261280af7 |
Hashes for stim-1.14.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab583c0d935bae3dd9762c9eb92d634e1cd511fdc9b7f688158312bd24e8de1b |
|
MD5 | efa64009bc92cf1ad791fba794e4ff38 |
|
BLAKE2b-256 | b838fabf8bd067308c1caf038bdc7f3f5bc7980f0f22e7f10907eee27235871d |
Hashes for stim-1.14.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 365a0a4afb0b52653d945daec918a53de63739960409b201c25878dce665b3ab |
|
MD5 | 7e2987938f10be2ed9f2771c911d4c13 |
|
BLAKE2b-256 | 7927394fd17a4c2d3112f50e34cd12d0771d5701b920884121a095626e5ffbb5 |