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.dev1711415157-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcdce3f3e3790c978da12844af29dbd3e76b0221a500795f890bad43fe1fa3db |
|
MD5 | 5ab84bb1837bd8503313c336ddca8d8e |
|
BLAKE2b-256 | 9376d8faeed8188056c6d7a6546e0a389b730ae38841e6abcf9764b57021b40f |
Hashes for stim-1.14.dev1711415157-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bce6d313556511d676c904b1622c39f2d04cc9985282330754424f8a86269e2 |
|
MD5 | df5dc8dd14455b50ce9f79d09dc93ecf |
|
BLAKE2b-256 | 4d4e62b62462b05701e495f2c9522962721c6d04494067e15f62ca66ed28d73d |
Hashes for stim-1.14.dev1711415157-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75557da0fe03ec7155df9082b9ea2a859bc5973b53c56779689292dea4f3d6c2 |
|
MD5 | 9ddfcb182a7a89945a70f23972cb8d1d |
|
BLAKE2b-256 | de84ccce4b8c58de6535fe541560755eada7015165e4a999aa4c4e1f46277d88 |
Hashes for stim-1.14.dev1711415157-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 847bbb02cfedb3938986dc646656081eda5e1acd4fbcb5be6aaad3e8baa47408 |
|
MD5 | c1ae1f6e80168542485e8301b45537dc |
|
BLAKE2b-256 | 9995c7053675d89c7d680416c6c493d41ef01ce9f84a60fd77e6541f4a9b8a91 |
Hashes for stim-1.14.dev1711415157-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35475ba4b56b10baf016bf6bafa4332aee83d5ba17aaee906bca03a40fd8a39a |
|
MD5 | b811c2ab02b07fc7436b47efec64858e |
|
BLAKE2b-256 | e9b76cc4af96c94bbe2eee90be9f84bfa8352da78735d942e145843eb0cf262e |
Hashes for stim-1.14.dev1711415157-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc90dca8eab5a93db69550a114abc6a190d75ca3cfaf929a83acec85a4bed6c |
|
MD5 | 5a0b019c09ed2e9f66baa24b358cc1d6 |
|
BLAKE2b-256 | 34b1d22d124d05b3057dae904894da48f0acf1cb6c84bb9f00e5f54c1ab30f16 |
Hashes for stim-1.14.dev1711415157-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc6bd1f09688889c8bca0259b93e037fb510435c10ac8a8428408ae29fa63c4 |
|
MD5 | e8614533eb87c175743d30438e92ab6b |
|
BLAKE2b-256 | 4a3b656f6c740ff96906263a44b56e853b1194335ed5b939aca1f801534ea5da |
Hashes for stim-1.14.dev1711415157-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 267e5a37222f0608bbc18a3cc01c4b4e2a157aca3042ac5c189787a765567402 |
|
MD5 | 1e4ba8254895900765770e6cd11b9b22 |
|
BLAKE2b-256 | 96fb77d347033ca64bb12f0617b59724bb3487aebc0ef52d6cc0f24f6a09c18d |
Hashes for stim-1.14.dev1711415157-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa057fab16bc9d731f2c5cb9489f771781d6e7db8d9e239c7b4818982fd9c886 |
|
MD5 | ed02a4db4ddc2d9ba92f514d839b671e |
|
BLAKE2b-256 | a07a8ad3ca6789c1bdf3d0798d109140cc08b2629ad802a02f61f73450216225 |
Hashes for stim-1.14.dev1711415157-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d689820c231044a9600635f979728d49bbbdb43962029ff6d6d12701349429e7 |
|
MD5 | 3addffb38fe59006327e1fd98bec655c |
|
BLAKE2b-256 | 592834c63f35398cbc22d04e006195d47017f14a88a5534a061bdf286eef387a |
Hashes for stim-1.14.dev1711415157-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e995c7cb78b17ad49de054d005ef4305ba2a66b638521cf8e438ca5707572f2 |
|
MD5 | bb64d40754d2d8978081decc7e104774 |
|
BLAKE2b-256 | 34cbff366f7f7dce0a8355f49014d7e32c1ec2b41848f98782e749a6f841539e |
Hashes for stim-1.14.dev1711415157-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02e7c3307010e2ada2e240ba077842397aa30c442e877ce4dbe417f2cd11173f |
|
MD5 | cefa4ff8c06e719bab1067bb323ed41f |
|
BLAKE2b-256 | 3ce1a9be9b924afdc7229c910b62db34f2c97f575cd4852b2515285b28d1d61b |
Hashes for stim-1.14.dev1711415157-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0b6a9e5b23a617581ba77338d6f8db1a1cbcf67b5ad957cf3ff40928cf9e5dc |
|
MD5 | c233deb4f7cefdd2b6283725068ed8ef |
|
BLAKE2b-256 | 168b4767e21606c00fb3c1c0565277f104d796394e94363590c5fd3688531eff |
Hashes for stim-1.14.dev1711415157-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eff423bd01b177d4197a2483b4102d87d2c823d10af44a03b4d649f92b11d7b9 |
|
MD5 | df169ec6ca829f40bfbdb2f7b2779b3d |
|
BLAKE2b-256 | b653f5d88c8904a67ac9ecb5d881693e9ac14f67829f07c2d893691e39e2f90d |
Hashes for stim-1.14.dev1711415157-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7703138eed8ef66dd4b3cb998ff5f09107c954435d0b8ac80bec728d920653b |
|
MD5 | 4f70b0c129f20571670df3c05fa5cdb3 |
|
BLAKE2b-256 | a84067788fd3b7cc6ca4824bc7c13ed19bb7cad1d6450dbff4745b1b732b7795 |
Hashes for stim-1.14.dev1711415157-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb076943d67e7c91e4c1fcac0b9e9f8680a37efdd41ee98510be097324e4a32 |
|
MD5 | 6a9891e5cfb9af9137d2fa6dd6163aa6 |
|
BLAKE2b-256 | feb1ce37599b4c07405acda4b63d5e16f3e2fb5598e707793bcec87fd88fd889 |
Hashes for stim-1.14.dev1711415157-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d9c815f800e919595a7b6ac33c0c7761a5cd6c66034e9d37433330c3d203c49 |
|
MD5 | c0ebcc67d0a4c189718e997797d15edd |
|
BLAKE2b-256 | 008a297f53ab023d2fa8d8bb9ba9cd93e8dd155e1fe2689b206cf993609b816b |
Hashes for stim-1.14.dev1711415157-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eba3354c04ae8b68d3ce27c956e8f8e12fe867ed8ea6f56ae5e78ba4ddec6c6c |
|
MD5 | 6f5eeb19971bfdcfc297ef94112657ce |
|
BLAKE2b-256 | 9fc4010b7d24b760d0351bc37498f6105a4e0da741e2934a0a5767aafc30e919 |
Hashes for stim-1.14.dev1711415157-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ceffcb50de18f6f6fbbb7f2b8497c3b2694d69b2f31ad6e3ee72c9afea2a05 |
|
MD5 | a73ccf44198deeb854dcaed0773d502f |
|
BLAKE2b-256 | d3a5c3149a6043488ff04ada280927b92fad7613a55d40027eb27cb766346b70 |
Hashes for stim-1.14.dev1711415157-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11bbc05891b7bd0f9b3191fb41b134626308ce80b3032c486f4fabdd9e1e3449 |
|
MD5 | 1ee7f66e5c5d74eee8392606f792f5c6 |
|
BLAKE2b-256 | e6c0392d9e2b86e41e712d21d345016ba490cfe857fc68abec08569f9d076656 |
Hashes for stim-1.14.dev1711415157-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d15b8f67c2d447ba40c97a8b7f01fa3cf713190ba779db25a901d610d519e8eb |
|
MD5 | 7da0bb6ea19babd5342381adbaa27585 |
|
BLAKE2b-256 | fd5e6cb47043c119441f6a4f9438482e89f5854e330eb16ef931798106061820 |
Hashes for stim-1.14.dev1711415157-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e52de8757d092c128591e45eecc2fd33256115007abb2cc305a552de208ec47 |
|
MD5 | 06e52dda40dc8ea1174b7c29d6431592 |
|
BLAKE2b-256 | e124e9dbe3371eb9bbcad12f76ebb1edee46f959bebc77aa692a4df81ad40558 |
Hashes for stim-1.14.dev1711415157-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6d57aed95929e28631e6621e120ed3c97e18a63128fb7ab1fb304b248d20f76 |
|
MD5 | b58d319a1847f3c5c2d21a0f674a99df |
|
BLAKE2b-256 | c6aa4f04682ba8e5b4143fcc5acc5a14ffff5022c256631a1563e4639392c22c |
Hashes for stim-1.14.dev1711415157-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 454f794c1603fc9ca3a196b1ca1939ef074ecec27e521325814967dd73349b53 |
|
MD5 | ef33b573cfb9d8c94da67bf60570bd84 |
|
BLAKE2b-256 | 018e100cf6f39748a0f0284d5f0955e3362d0e5f5a7eae1464d57bad6fdb9875 |
Hashes for stim-1.14.dev1711415157-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a886259fb3f460b740e2039719674a558d8b930ab3ca7d4628bb0950a8bf1e |
|
MD5 | e4c746cf6e95e65628cd42d2afed2853 |
|
BLAKE2b-256 | d82aacd081ffa5d34c7c3dc84cd80af6668c1550b44e2214f1f2fb0067f19e57 |
Hashes for stim-1.14.dev1711415157-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d15af80085230e654ff1b472629664e121b642d599a95fc20cf44674f686ff1 |
|
MD5 | dcbd6b6984d2729d1b863d7e0a6140df |
|
BLAKE2b-256 | 38fffc633a1af802a4e79c9f9343e5dd2594973db69bbb55a0555ec0becda396 |
Hashes for stim-1.14.dev1711415157-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5fb2cd7277de3f4d2307af87ae5837670b2f813145dc27a3f2d4e97420251a8 |
|
MD5 | 417dc8af5d865707792e6c58e6d7dd78 |
|
BLAKE2b-256 | 27655f7d2d3741298679e1401cd3bc040bd2189ebb03b64cd60d2867a29a0f3c |
Hashes for stim-1.14.dev1711415157-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f9be25db96e41061ed1c519de88eef6d24998d7001353b0315fe57d0e6c1046 |
|
MD5 | f6edb3bf0d615605b4b7008b6c4e1fc9 |
|
BLAKE2b-256 | abccff547af0f8663ef4392a589fa9d569895d507e8e2b37921d16c92d4f5a2f |
Hashes for stim-1.14.dev1711415157-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9104e8f3afa032b66c61011551a431b679e97f3d4865cd2b977bd55b5c1997fa |
|
MD5 | 03d02a1e414f7adeb8b29b7d5e9ac86a |
|
BLAKE2b-256 | b229cdd2cefb71da6e70efb9a47b7b52e4c1715315c29f44472b3b929eed74d0 |
Hashes for stim-1.14.dev1711415157-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 496cdfefdfcbc126188d15683968da27a2de121b2dab45e80dc14f02e6da244c |
|
MD5 | 887e7172ac1427c2b7fd04944fa733d5 |
|
BLAKE2b-256 | a32fa689ea0b027911b33b55e2a2c634d413cf0ec5f87e509c30a5a77fc718a8 |