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.13.dev1710209153-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3d84c307f94d7082fdc42dab0fdc0cb0d2a52c77c1c0d0c89277224b809ea41 |
|
MD5 | 18fb2d139d20255a080fe45cd1c14ed0 |
|
BLAKE2b-256 | 4a0c11099d980b26c0e3070f54c08d44decc96f32a14d9bbf30ed900e9cc3142 |
Hashes for stim-1.13.dev1710209153-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5649dfdc11bbab754f62d588e77aba3f191d34d72bd89750a95ba389fd902b97 |
|
MD5 | 2a0527a738665b0babdeedb71114aa89 |
|
BLAKE2b-256 | d784f62052f23586ba0b72bd3919a01b2673cec55734d35e1122f9411c44fb5a |
Hashes for stim-1.13.dev1710209153-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29d03b2f00445c275cd4e7fadbd73a99a23a72d79bc8a1ede6ecda06475c9c86 |
|
MD5 | 5bf50a726c9f4d196992a188a20b66e7 |
|
BLAKE2b-256 | 683f1855297542f39786d1274eb56629dd4b54bd932ba8f6325a80fa1a925d16 |
Hashes for stim-1.13.dev1710209153-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 032eb6159ef6a6f2ed2177119b0c09de1dba43a4b9df48924c48ae9d39b967ad |
|
MD5 | 772355ea9c29f006937db2158255797e |
|
BLAKE2b-256 | eef899fce19b42c16f0a127834c1b38ad1873b9c3e2f0fd52770daa0f8ee1a52 |
Hashes for stim-1.13.dev1710209153-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d4b4d72ee41e471a56fc4695aea62e0fa50be49f7aa5f51c40e85da8c913511 |
|
MD5 | 6dc10c241069591c4395c3931d6b7a86 |
|
BLAKE2b-256 | 046e15fea33f1d1fa68434431310a778953d8fa4e3100c228c52eedf36ad3d54 |
Hashes for stim-1.13.dev1710209153-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a37f994150ca1da86c55f9cd705439cfacda7e8c2cc017112991e99be33577fe |
|
MD5 | 30bb58e01c5b1589074065d38268ff16 |
|
BLAKE2b-256 | b503f718f9d4f6e640e2c3d7939f434a791fc1e7d164ba89013f80660127c849 |
Hashes for stim-1.13.dev1710209153-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7819d7445ecba0611bd8f974c52e9db89078e2881aab9536beabf57921112216 |
|
MD5 | b7bc1552d2189f6282b6528c67795f21 |
|
BLAKE2b-256 | a0b359f7f10ffba25f4901ea836c76113b546a3f3adb6a61cab69c3a30d2aea4 |
Hashes for stim-1.13.dev1710209153-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05db6324288239d931c4b78cd88df514a6379289bda2f4dada44e8333892ab19 |
|
MD5 | 41dbf9a1748190e1010180270edd0557 |
|
BLAKE2b-256 | c1fdb2f8c756790d4c8795eac4258bd06cf2d4a633f9a59c82557a160e79f3fe |
Hashes for stim-1.13.dev1710209153-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deb694aa34fd855942f02e5b28f27e5eac129360efbd26bdf9eedc60507ad510 |
|
MD5 | 0d8fd715a18c0426189a3c5f60e83b13 |
|
BLAKE2b-256 | 0eedef42d2c20fdfdde2bbff7cde0d784a31921a75b8c44d70cb2588a2391206 |
Hashes for stim-1.13.dev1710209153-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c491759359d16f7b9b63e77a18063f1daf7a74596b0cf7450600f9412a721124 |
|
MD5 | 42efaac56b339293cd256b8d64dd41cc |
|
BLAKE2b-256 | 25eeb392fefe6605eba9b4ad9af2a728cae1ca2e4b2aa22d64ff44c44a3086a2 |
Hashes for stim-1.13.dev1710209153-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c8e9d5b30d1f2e350da9a7d0e3260cc81314051d4385eef80a3fe7ed220a53e |
|
MD5 | 2c288ea95e6f834ec0dde76d53000dc1 |
|
BLAKE2b-256 | 8c205fe9cfc6510bdfdc6e918b3b41c0a6de09e1e82baa789a3c1cf1cdec5dd8 |
Hashes for stim-1.13.dev1710209153-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34db69d97e3dbe95f93d39444349694f721ba1252de250b69d6a803dd90cfb9a |
|
MD5 | 55089e1c39bb83b037909c210feeadf7 |
|
BLAKE2b-256 | 76f4b6d477919101f84254cbbd5a1901b8deb25053afa3fdeacbe15bb2b8f315 |
Hashes for stim-1.13.dev1710209153-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f090a595495523f6505b1bb9b868dd3e29cfad96b64075baa732b7cc9b0f64 |
|
MD5 | 3c40dcd52335eaeb0c86b6c52197f16f |
|
BLAKE2b-256 | 13748ebe9603a9cf674f4709264dfcfc347e47eb2fc49a86ab0e469c7d302438 |
Hashes for stim-1.13.dev1710209153-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74b3b654d4e6080a19fd441884780f311abafc57d10563fa01945b7ae7202bb |
|
MD5 | e15786e0f7036a076666ee8c563c87fa |
|
BLAKE2b-256 | 29152e2d034a5847f98c65b96baf0870b5922bf31382784dea1fa6afcf66900d |
Hashes for stim-1.13.dev1710209153-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa3309ff8da13793278d6a97fd2469e5bef5f85648f21ef3b4dd22285474b3e1 |
|
MD5 | f1f5a18ee0d44d4edea78291a8fc5146 |
|
BLAKE2b-256 | 4ef35ef75e14000116b495524c962d8bdf2235ead687c48b0eb2f42a7a2e266e |
Hashes for stim-1.13.dev1710209153-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf9db23f64fd410fc6ae7ca739f7f0bd2f9c9a3a5c35e858c64f2b81f80341e4 |
|
MD5 | 11351301d2bd89dfc07c896b2e00fd09 |
|
BLAKE2b-256 | 821cbd129ad2dbb91ce5654d1cf8231a4a6c7e01c15869918d7da7764981f0c1 |
Hashes for stim-1.13.dev1710209153-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16764d373036352a0fb4ab4ed4ab6914cc744588936fe008c161da5987c714a9 |
|
MD5 | a04e1f335a227549f9d2d0d1fe70f3e5 |
|
BLAKE2b-256 | 662767a515933c62fa1bd816a3e1cadcb3926f76c557666469428c34892cfb5a |
Hashes for stim-1.13.dev1710209153-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f918801e124bf6bd701114b53faf5896786d19fb6fd3f94c0acc53bd54569bf8 |
|
MD5 | 35423469973fb40d97ee04f59807595d |
|
BLAKE2b-256 | 6c453af21924e457d554ea84fd001c67a91b4d3666e67fc488da90cc3561b168 |
Hashes for stim-1.13.dev1710209153-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0b5eedb41e7712c8a3f9a8da051afd28525611c0e238011824643ee82150285 |
|
MD5 | a24708f166935740be7222271ba5bf93 |
|
BLAKE2b-256 | 87efbbc5922eb3e65f5fbc4c55c9bc6c7076d036f27af7c14abbdfc3f79f8c52 |
Hashes for stim-1.13.dev1710209153-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcc8ea0842d5595cd744178c7302f4c624e0b8688ddec46f1137809638ec96cb |
|
MD5 | 753f5b3b26b681049c0ef4fcb401c879 |
|
BLAKE2b-256 | 12d5e2a547951449dbd70a1ea68f405199d6267a0db98b9e8255d377752e2334 |
Hashes for stim-1.13.dev1710209153-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 565961c32537b927d50d2aed0038089497ef8d253b37ab3c78eedcb43ff798f7 |
|
MD5 | 314487abfa5e23f26addb33629e1c2ed |
|
BLAKE2b-256 | 774de36f2d3e2ead3dcda9bce51991a4a76d1a8f653ac2332b4b66c74d93f2e4 |
Hashes for stim-1.13.dev1710209153-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef5bc8bc40e42d92bdd258a4135fb90a9fd09f9dfdac56cb67ca52141040c0a |
|
MD5 | aca7244d7b3a82bfccde79818a93dcd1 |
|
BLAKE2b-256 | 737b563fce9df465f364482ff65ba4b7649e4b6208a93c38e2d4b8e2755a0e56 |
Hashes for stim-1.13.dev1710209153-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69d665fa12937ec789789e0c91e47b1ff9b001f08c0b5474c0eb37251c4fb6f2 |
|
MD5 | 7923f41de1b4ae2f5d7e865a96871016 |
|
BLAKE2b-256 | 7927f32a0a217e788c36c4b1d367f29bc1a1292092a308a3581b8008050826b8 |
Hashes for stim-1.13.dev1710209153-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c590c3c347527f571a47636a07b452cf6a2133a005faedfa1353a45317de9ef |
|
MD5 | 9bb62815ed782bb12a8a1f3f626f5dea |
|
BLAKE2b-256 | 1fb05e81daa8a4412a9b0b456828ab86fc2fb0b4f592a63176cb188e15e2bc3d |
Hashes for stim-1.13.dev1710209153-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd39a554460b46bdbde0d829fa86afeda21a0fcc0b170ee67d47f6b263792de7 |
|
MD5 | df5db9878c26caa22e9bc7993b13a140 |
|
BLAKE2b-256 | 5d0078a46c557dc6c99e1924360f138826e93cf65eb14a33f4172dc34e149944 |
Hashes for stim-1.13.dev1710209153-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a208e04c301626303e4e3cd9d2b730f75de17a60b1036fe2c83e32343004bc53 |
|
MD5 | 21e087165b7beeb7edca97e5fa976be0 |
|
BLAKE2b-256 | 39a3c47db941172f5eb8437d61a6f1468fa6309b5df2ff04130ae93c9ead0ee4 |
Hashes for stim-1.13.dev1710209153-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04fad6df89440d6ae21857a19e24d62e78e22e5d9504f567158bfb276ef7c456 |
|
MD5 | d64b46120e4e0d603b531f0cb1dbd111 |
|
BLAKE2b-256 | e0905b3a831e45fb1645faafa60b47c3cf74d8ddc4096a886bfc0cfd48dede17 |
Hashes for stim-1.13.dev1710209153-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a17db4a046805db121f7d55db30558430c75ee8896dfad80e260f813b7c2e14 |
|
MD5 | 276333aafcede1732b151051b1be7ab3 |
|
BLAKE2b-256 | 14198c5508ad7bd85ddb8c352a107a7f1b03fab8ba13d38b3a7d1dd14800adea |
Hashes for stim-1.13.dev1710209153-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb835241eec57bb51b96a425abac3bf95ff3fa53bc1a726f20dd360a592a4a5b |
|
MD5 | d5fdf540b56cb35767ed5ac4207789df |
|
BLAKE2b-256 | b7df018f2f05f7c00ce651839b71e115ee31324ecac2beee33382f079ee26e4f |
Hashes for stim-1.13.dev1710209153-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310b5984aa9c1d570700930ff9292e1f37decf432a2239798c086a4613aee7e6 |
|
MD5 | 3b87bb6a546a812eafe133be60350e11 |
|
BLAKE2b-256 | 4396660325e42df4b623eee3dca32b79a0532d7483ae6aa3758f426008e5c393 |