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.dev1718081493-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 139ced1f4206df5e657f374698d248f27de3591927a5088438eb2729d7c9a742 |
|
MD5 | 11747d4f5cf69dce05cc2d2bf1b743ad |
|
BLAKE2b-256 | 04550b7e33759785f8d707c32eb6d2076fad16335c9c7381c512f94e9b5357d9 |
Hashes for stim-1.14.dev1718081493-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f8179cd1c60b135bd74eaca0f2f7eda0ab92b30ef61bd3255b38b9718fa97bf |
|
MD5 | 59d729cf5916dcd8639be643042d9d02 |
|
BLAKE2b-256 | ea05133eecec386a3f207c89c729f8c7412a3e2d2fb29aee0421774724a060a0 |
Hashes for stim-1.14.dev1718081493-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 627f5f548707dceee0d5818f623f1707b942a3e2ffccef862b5068e7569196ff |
|
MD5 | 9a3ec4d4c787a1ad541ef7ae55a1b272 |
|
BLAKE2b-256 | b43fb675cf399e3dd1072c5ac3cfa024618563c31c9792ef5810a344f0cf847b |
Hashes for stim-1.14.dev1718081493-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9c92280f0b5a117dee90a159e5aae1fa7dcfc4eeb9bd8f0ac7705f007b1f40c |
|
MD5 | 9e636e14e42e50836105c3e47031a6f9 |
|
BLAKE2b-256 | 48b9517ea2c146364af876eb370b9ebe9e088f391e579529feabc839de099142 |
Hashes for stim-1.14.dev1718081493-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81f85fc620d48c7df58aebd875ccfbed16049190a6fa08eb1a7d22fb66c5bf0b |
|
MD5 | 53f498969eccb77655da69fda5cffc28 |
|
BLAKE2b-256 | e9f3fa0c5ad1ce22095d7f4a38dc94b8552e9fd924a4ea68785afaab1033815a |
Hashes for stim-1.14.dev1718081493-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2c0f2f6eac3a190c05c413264ba8aafef52fd1a4285748c26da32fb5a46af2 |
|
MD5 | c36a32e4fa5f103edad0837022527b80 |
|
BLAKE2b-256 | 72778f69d56867a2b6e0ccb4e9b8b70e0f7b9afc6762590642a0a965885e4490 |
Hashes for stim-1.14.dev1718081493-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf81fee4664fbb2375c2836093be4846e3a4ebaa06e45cf85407641530817dba |
|
MD5 | 382a310707d73b3f88d747f38cefb5ff |
|
BLAKE2b-256 | 5f8d50b98384e58fe7d6bc218c4d59a230896ed082759a0a19d4673695944b73 |
Hashes for stim-1.14.dev1718081493-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b9f0a32bfda6a8d6062486a4f4b6dfb10eda4f8e33845afedb40a0e98a9da1 |
|
MD5 | e225815104b959d5253247dd7daa49f3 |
|
BLAKE2b-256 | d36a04aeaed0c07d6ecbe772b1234b772a442b3d258e7b2aa01a930785c61eec |
Hashes for stim-1.14.dev1718081493-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93e939aae389ada241c67419cbef630a5a1c1d262c99417863dc037ab3f1eded |
|
MD5 | 0f8bc8027bed014c464c036edb6bf19b |
|
BLAKE2b-256 | c1eb1e8b99d0be4d1c5d5977f9e170253b683c91d03174af381e45fcf18c7edb |
Hashes for stim-1.14.dev1718081493-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d128b866fcde6b594df638f88e9b0db348fff6165019f60f72bc990e789fcfb |
|
MD5 | 40888dc3a3201fa233612f6b1b7ea972 |
|
BLAKE2b-256 | 6f706c7efb0a35f6ee759a5eee32b92679ab2937e595adbae82d221b06511409 |
Hashes for stim-1.14.dev1718081493-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d9361260a87f395f4d3e86235f1e8704ca1ff60c386c6534704e145d09d26a9 |
|
MD5 | 97e514c2d3af6e5762e485700f71140c |
|
BLAKE2b-256 | 831f1f3ffcf983c59b3f239fc49921d215dc15ad759f03e06c2f06d144065aac |
Hashes for stim-1.14.dev1718081493-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65e89f73fe838736f371747802142556c2c54660447eeba5a3c6e109a08b9696 |
|
MD5 | 931afc588d91e3315dab042266b506d5 |
|
BLAKE2b-256 | df73b088f72b73a612103176659ba7d3236a2dc08396690045de1becf6e7e383 |
Hashes for stim-1.14.dev1718081493-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c1e0534247c40d19e7baa3aee432c0021bece753186894618f2bf69e77774af |
|
MD5 | 93271dde7fe4ef144fb816f140f3a8bb |
|
BLAKE2b-256 | 30355320f2f9fd297caa179bd627dc650f3c00bff193beb735bc2e872bddd882 |
Hashes for stim-1.14.dev1718081493-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8e3f74c460699965495c18e74e23241b44dcd7961ccf3329ea1fa3ebb18ede |
|
MD5 | 504dd9c50f2bf38c5d6ae6548cde7b0f |
|
BLAKE2b-256 | c7fe6425812850a059d6ef778aa2b96b6eb9552fbde92caad6fa85c2f45d8b85 |
Hashes for stim-1.14.dev1718081493-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d3e2e57d37becb683e0cab274908a22105724c8a8e1a4323decbe2f6fde855b |
|
MD5 | 8d8ee6c76d292f06a1253d5dbba7ca36 |
|
BLAKE2b-256 | 20d075879ae7a9203bcd261cf1b565923d078e6cc996ff4432c205018d6e6ac2 |
Hashes for stim-1.14.dev1718081493-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19bfdab32a550e9d075fa1e39e6aa3dd16fae34648f3636ef04eb6ff3430f894 |
|
MD5 | f5ec7604f5941e388bce92755af492d9 |
|
BLAKE2b-256 | 3a71fd8f8831df75ceecd5042b08d6b2d57634638320a8e8255954029be2f76b |
Hashes for stim-1.14.dev1718081493-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1507feb476062476d03857b6e9943e36fb6312fa38db3eb8f49b3e2175b3618 |
|
MD5 | 82eed38861b06a27748d9cb33777b27a |
|
BLAKE2b-256 | 214e0f25cf9389258e54813ac6bcbc325d09eec92a6bbddda03e06c9c3673e95 |
Hashes for stim-1.14.dev1718081493-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 397c3d58e744c4322ae35d100714b74dc3f092faa83bd71f83cd26c1961f94cb |
|
MD5 | 743b19296e5fd932008dc3f3d64e1753 |
|
BLAKE2b-256 | 9dfefc706ef833d5128927c922110d356cdbfaf042587278cb33962f1fe42d31 |
Hashes for stim-1.14.dev1718081493-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9120a7ae79a254203eb290128f316b578c02b9de7a3df39c38841fa9f5061c8 |
|
MD5 | 2a5b8e9898bf12cb95c46f586070213b |
|
BLAKE2b-256 | 3c7b7ce857dbe4a343ce3ce6c1c63f6391b2a2f1cf3dd1a36301f84bb95ea5d6 |
Hashes for stim-1.14.dev1718081493-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357c39d9c581c6a949676794b7153e19606380bdf0004ecfe912c2e01c5ca4f0 |
|
MD5 | dc32dab1fdadedc1166f4d2489d2cec9 |
|
BLAKE2b-256 | a008ee4be3b76737d44c86fc0e9200d056c6bbcc674ea5a5eb7a4407b4a44184 |
Hashes for stim-1.14.dev1718081493-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d75de9adf8be0fd187cb0916ae5851daada3c91d1e2cb4650e6618461cee78 |
|
MD5 | 5fd07cd5a1b28a14280837066849e029 |
|
BLAKE2b-256 | 63f2b8e76e40a264cd39876b7810139599d4f16d3a4e5676cab58af1c5c75707 |
Hashes for stim-1.14.dev1718081493-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb0261e2f7d9fae0ce2c6124a38dde9ab24326dd286b532f1253c61db22efe76 |
|
MD5 | dce40d25f757f4c5f31d1659f9a85782 |
|
BLAKE2b-256 | 35bd3286bb6320dc869ec2eca29c0e145ee7326404efbfda2112a167cc92a2e0 |
Hashes for stim-1.14.dev1718081493-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dcce18307ebe95d34bb799ef83a296327f3172e8d6c470609aa1fe4aeba7140 |
|
MD5 | 26773c798db07c60359ed04c2231bee7 |
|
BLAKE2b-256 | 7b5dd7f2706fc62d74fd8306d324cf44e01900d68933e0f87e15e6e2f39480bf |
Hashes for stim-1.14.dev1718081493-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 843b76b359189ff9db9411f962388b932bfc111bdd42cea1e1f78b7115fb979c |
|
MD5 | 1493dca9c1d1475a96431665a8d66652 |
|
BLAKE2b-256 | 50f4db6925940d3c82bec601a9202524b9f57530688e7f66b930b76c15274c2c |
Hashes for stim-1.14.dev1718081493-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec452668d4ba1af24f63dfc2ca6b83b851cd7433d8a80c11fb130f20856385ca |
|
MD5 | 638cd5d9d7fe4482186a191e3073b921 |
|
BLAKE2b-256 | 39203f21e70acb900f40efbd0c85c850b34ce9cbe6ed3a32f047ae77a9db0915 |
Hashes for stim-1.14.dev1718081493-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 369768061e04528e146dd1578b9c3ebaace7555f63c4345fcaab7e69c6944735 |
|
MD5 | b961f0cbe553c57b08aeeb51f12a555c |
|
BLAKE2b-256 | 8ce67e7a4e236069ed5fdf0e0325e161b87f5b1908bf3b5f8f9afe99faa800bd |
Hashes for stim-1.14.dev1718081493-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68d6b3597cd4832094590c62fafe7cb363f79a8cf7e19dabe49832bb763a5441 |
|
MD5 | 2d73127da177a946aea4c8ab1fb506b4 |
|
BLAKE2b-256 | 36ff22c5f534fc33ccaffc361359ebe1eca2467db7eb9d424391ab15fa376427 |
Hashes for stim-1.14.dev1718081493-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86caf6f14da67636c7fac8633851500d43d752b0e18ba38d4a260fe3fcec3f6d |
|
MD5 | a88f90d5bb93e5187477bb6cfffe8714 |
|
BLAKE2b-256 | 97b4aaf1a6ca8fe3387196a02ef436f4cf5cd2712bca7399a092d1b22ef7c44b |
Hashes for stim-1.14.dev1718081493-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2864e0a6562b8ae965fc947f8f93aa9d3d203cf391aa33dcb0b1749c6bfe2e3f |
|
MD5 | fcd2fc5ca7ae1a0ddb0a8aaf5ac456e6 |
|
BLAKE2b-256 | 2372552485afd8118b3233068e95bdc411e886089e807151fabfce741eb6c979 |
Hashes for stim-1.14.dev1718081493-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4b32a449fce01666e7093176003ce55e87679182477e815aaa5d99a49ee8a5e |
|
MD5 | aa8fc49458d59cf876826eb86634769d |
|
BLAKE2b-256 | 9adf049b8ae4014f51428a8bc74cab3fbc682eb68fb3be4d7bfdc92a3d9f2c95 |