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.dev1710899196-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78aed63c27c257ce4493a931360397409cd562da82599f5e69d5dbae457544c3 |
|
MD5 | 0f3d07180c1110ccd4b3488609418b4b |
|
BLAKE2b-256 | cfa62bb8f258232ad7691453684cc20a3909fac8c461014800a050c1c5cb1ede |
Hashes for stim-1.14.dev1710899196-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c291d8175168b2bf8e59fdc8ab6b54995e32a73fc6fc3a8952f3e3987410460e |
|
MD5 | b97753dd817ebc5274573f6f2b6ffe88 |
|
BLAKE2b-256 | 6997b87ebae34c94f13ba9b902ee9d04d97fbbeef133df89b81167ff1c9699ab |
Hashes for stim-1.14.dev1710899196-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c63b5e136ffd7d725660121b13a871668bf7279082a61118173305b14c563d4 |
|
MD5 | 0f81dd439925f560372faf24c9fa5fc5 |
|
BLAKE2b-256 | e9530b1619606904fca4edb50a0d141717dafc962df843162382f469aa76b76a |
Hashes for stim-1.14.dev1710899196-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acd3cdc6ce938268d18dd8974449e6f92156b9257d81d368834894936cbf2c7b |
|
MD5 | 2df0015a4719ff81ecb4bde079d1b5ac |
|
BLAKE2b-256 | ef112e1ff27efb024437dce1c122a67c82fda06af3e7e6ba8f304b136146f39c |
Hashes for stim-1.14.dev1710899196-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d46df2ad7f64d7fb1a7618c623f601a94b3dd4fe62f12bf4b5b587be697e40f8 |
|
MD5 | 869f9aa8c738c12f758930264e93a497 |
|
BLAKE2b-256 | dabce87caf93e1de94bde44a04c643e5291bcd937c08f059f215067844bf0254 |
Hashes for stim-1.14.dev1710899196-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e626be93c5042957def1f42246244dc70c4c98c280096c5b78b654e3cc417d2 |
|
MD5 | ebd07c3a370c2f7b8445488f42ac78d7 |
|
BLAKE2b-256 | 02900729d632a30bf5ba7a8443befb7ed538880eb97596b04507899fc1d6b63d |
Hashes for stim-1.14.dev1710899196-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44ceabf81948c0d0331558dfd5209c37dcedc1b60fce21ff919276bf5ee112f5 |
|
MD5 | 26c47347ca3c4d7d54d06f589da8b2ec |
|
BLAKE2b-256 | 06f58c21bc0227fdb289ea7cbf5591405cef7b1407731f183926058d3ddc6ed5 |
Hashes for stim-1.14.dev1710899196-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7abf864747ade30cdb31ad9681db3399dfaa3c6fa62332b8b2c86fabd2bf4b02 |
|
MD5 | 27d22670a5086f332c6deef64ac109cb |
|
BLAKE2b-256 | 9f915a8903dd12a7aba251865f258f0f89a5bfac257d0ef817c25f067325eb48 |
Hashes for stim-1.14.dev1710899196-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d4d36289aadfdd81010f8796d13eb39b976ad8d7106c4eeca44f871123ab83 |
|
MD5 | 6a4cefcb28d14699f34f9c3b025a75a5 |
|
BLAKE2b-256 | f0ac796f7bc9db1de0a3cfecf6ef2f7a9e823e8116c960cb7f5efec9ad3d3ea8 |
Hashes for stim-1.14.dev1710899196-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24cb197aa0339bf533c382979e27a63f0668f5d1f73e24148789e77c12ecf5bc |
|
MD5 | 48ef1aac5c6e6f281b61478302fcd885 |
|
BLAKE2b-256 | b86c15ca6ddb236ab1eea5969b6243ac343eb322d3359b57ebae4992bf198044 |
Hashes for stim-1.14.dev1710899196-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 102fe408ebd7d23c723c753f241a6997a7b6d0be8ed24d4fb50a37adc0c83b8b |
|
MD5 | f2ebf8ac975e2ba67d37d5d31c1f441d |
|
BLAKE2b-256 | f3902830085981e15b8b6590f603303e155580c0443dd49a4632c7caaa9d4740 |
Hashes for stim-1.14.dev1710899196-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee434b40ddf00b3d7ca3cda6c57f31f0492dccf6ed8b9ae144c299a46d562ca9 |
|
MD5 | 07be1ed371c3a296bdb1148f055eb8ea |
|
BLAKE2b-256 | 777c7e561791f7732ea94f5d96bdc00b373d215f7056aa98c178dc70243096dd |
Hashes for stim-1.14.dev1710899196-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dbe7c5cafae15a0b49b6d2d4c0479a6481b8030bf4c03f54b3b078e4c206bd6 |
|
MD5 | 2799e502b9e72e966cf4657aa1947dfe |
|
BLAKE2b-256 | 50c0a69b0ee39b93adb84945f8797ebb0622d4cf92eb2153d854a4a2eb829c33 |
Hashes for stim-1.14.dev1710899196-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 302fbe839b5861bdaba4777a26e20c6983ec5805fbe1fdf5291d43916b71e3a9 |
|
MD5 | 2837c433351cb917f667329e819f7722 |
|
BLAKE2b-256 | 1391ac67a3abe31385f801db456f983dfdf68d614ba469d5e34772ac94dd0873 |
Hashes for stim-1.14.dev1710899196-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31822869a4983730e7f41fe71b1ae1aa9f3abb3c5898c576b3df47b00e3c0798 |
|
MD5 | b4c28de3b9316ff464582ab33bc2f232 |
|
BLAKE2b-256 | 834ec37d67c737beca9867a38599a4cc5f7f238b47eb9e0fff507f3db83929bc |
Hashes for stim-1.14.dev1710899196-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 061dbb1fe62e52f5f842d82e1fa35344f6e8e4124335d8f0b070eb65ce547ce0 |
|
MD5 | 7656218bd31f83428a7701282617606a |
|
BLAKE2b-256 | 180a12975044a41cfca7cb3660c82ccaac9d4a93b4756e89f630da35b5732344 |
Hashes for stim-1.14.dev1710899196-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15799d5d822ced878964fe5641396c56e463d0a7496ca888ca4a6d984e9de3bd |
|
MD5 | 11cde0f9ae49f430be73beb3193357bb |
|
BLAKE2b-256 | e0deb378c119a1337e4c3923614d1b96d8b3993e468dda8121f4a6b64b939d03 |
Hashes for stim-1.14.dev1710899196-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 015965b18e2a30d245f649f65b2310be115682ea93468f322874820618dd1083 |
|
MD5 | 4771f1eb3df42bd3b51702c1ffcb743e |
|
BLAKE2b-256 | 4302dd5d0b2b0fcc45dfc165eb7faf2edf154e8a55cd294dc23a0691e85ce481 |
Hashes for stim-1.14.dev1710899196-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e4661c22dc154f43124d5ba4688813b98a8300d7af3c8a86a640c22829222a2 |
|
MD5 | fa21ac54e9cbde464be73e591618e9b5 |
|
BLAKE2b-256 | edaf1adce273ea9dff92a78c9ea2808fcb5fdd0aefe53990ddfe06e90f08daca |
Hashes for stim-1.14.dev1710899196-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99b753ddfc30be6bbd53e2cac8a0e0ce25363d9631627b2efc8de5716a3ad05b |
|
MD5 | 4a1eb0acff11a424547c0eb2490cb94c |
|
BLAKE2b-256 | 4a2265b660d6caa5a8204ba61494ea8882fe37e5b57186800e69a5894e4ffe38 |
Hashes for stim-1.14.dev1710899196-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a3366b90658f29988a5bc6571ee34cf7f10df499d13279df989887802f6a3b2 |
|
MD5 | 8e6eb60b11d83788696f693210503b49 |
|
BLAKE2b-256 | 227d5488a6bd1ff578132bb168d544608393ac8dfaa777c25c3dbe30dd5f3b38 |
Hashes for stim-1.14.dev1710899196-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75737272bc5364ac48ab345d302bf874d6638b4d3941122271918fb59c0d3b75 |
|
MD5 | af730d46b6fd038d832fd09d42e2fbc9 |
|
BLAKE2b-256 | 88ede05d6e807149d0affbf898af3c04528fe3db7a277f5a19dcdb0a69f6b82a |
Hashes for stim-1.14.dev1710899196-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a93708300c1f1d2b7ab8b6faa1e1ee1f6cad3ee7014a84b7c9f90110817070b1 |
|
MD5 | d553e6a20dc1449d731e9faeb1b73fca |
|
BLAKE2b-256 | 5c0b245b6e77a51cf5cf6d1dcac981dc3567d59167b5fdb3c38beef1c03b2d61 |
Hashes for stim-1.14.dev1710899196-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc47fa7f96bf84eb1bdac0177c3e866c34a9b4311979a66eb3b3bedd1dc263dd |
|
MD5 | b7ec57ca9507ec3ec623ba85b9e95801 |
|
BLAKE2b-256 | d9828d4feeba0271e0ef66df321642e88b3392d228d11d7a4112bf7c38d933da |
Hashes for stim-1.14.dev1710899196-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf8b14ebee47eab0461354788695cac773a4c18187376f3ba0badeb83e3c909 |
|
MD5 | ccc0bbbe56ef46f3f3ebd5361f552d70 |
|
BLAKE2b-256 | eb94412706095b7d77969cbb0c5aede9817ddc4ed87086eee176e3305f1f5dcb |
Hashes for stim-1.14.dev1710899196-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebff43f9cf3069eecf2b37d39e0046e293bdc10b4ff1ae9af783ca2b4e076ca |
|
MD5 | 3be60952d03d1981318ca368d59503c4 |
|
BLAKE2b-256 | 0fd544fc3bed34dd5727bb2ed8a064c6c1d379cc2a312ee2eb557640be5e7f60 |
Hashes for stim-1.14.dev1710899196-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e86b7da98db781d55149135a075a465b6beab19eab4e9a084727e68539069353 |
|
MD5 | d506a3c97a9bde6398f2733f2b38a804 |
|
BLAKE2b-256 | f546c8e2721d92aacaadf50c54a79de15f73ecb9d32909aa57fd94d46346d5bf |
Hashes for stim-1.14.dev1710899196-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf5077d753b105bc87028868d42fe5a6d149a2ba274f6e5a6f61ded6a123cfde |
|
MD5 | b77703ec5dc455af7441049e269ab443 |
|
BLAKE2b-256 | 7dbb9381750019839d69f8f5079c0e41b1e8af8a15021843fdf243783c4d6981 |
Hashes for stim-1.14.dev1710899196-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c26dabb2fa36677ccbc6b96f44c3a94d5e3aad953534bd28f48aa9f226884983 |
|
MD5 | ea82cf8f12f2a4aebdd55582456b2767 |
|
BLAKE2b-256 | 9def8320eae15810d8bf62225a2259838a315d260a26b064cf4dac18cf6861c9 |
Hashes for stim-1.14.dev1710899196-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c75f04bad259ffdf8eaf63a28e305a7ce4f3a0a2e126d979c11e3272992804bd |
|
MD5 | 23ed5971b938966dc7ebf2603df6f523 |
|
BLAKE2b-256 | f9fd2b8e340657ae573fe8f32c9ea912a410d90dd97100b499921af1f3c8a01f |