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.dev1710743364-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffa679cabf1fc01bf119526bead565e7a7d19d84c5d2150560dd3c809ba59c5e |
|
MD5 | 6247615ac74ee6cb232561db8389bc9f |
|
BLAKE2b-256 | c8869b96c71707d492958a19ffc83adcf39b15517fac51ce2571fb1d587547a0 |
Hashes for stim-1.14.dev1710743364-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae9178fc146ff4552389e033609427d36425d7085c434edd00670c587391c65 |
|
MD5 | 676ebc2cf4933ac3689465d8d51fef1d |
|
BLAKE2b-256 | bb08db0285ebe9485eeee5d793ca7b8973040d0656f4b7b94aebe4d8156f0d9e |
Hashes for stim-1.14.dev1710743364-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f4fe9abc0c71a90d241717817ef0c5355dcf77d48566b494d0919d9a5593aae |
|
MD5 | 98e3122232882b4f9df1f79f7eacb9d0 |
|
BLAKE2b-256 | 653161dc72147df8fe8bf78d389085445b7afce245556cf5edae638f0813f517 |
Hashes for stim-1.14.dev1710743364-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3af934f3868afd8ddfc90844cc10dfebf16fe4fada712efe71b2039ce31448f |
|
MD5 | 735e401b701a64c629c465f3c59fc5bb |
|
BLAKE2b-256 | d6c8db181fcb169911b07b5021045980f94716faff2a11ce678fd9d6f34bcd89 |
Hashes for stim-1.14.dev1710743364-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aa394a4bf3a8ea714f2b56ca02dbe22eadbd59e27a2b48efaa3ae7dae5c86d2 |
|
MD5 | b8c6c4be24db38778614817708993065 |
|
BLAKE2b-256 | 64b0fdcfbd21983cc669b965864fef86f6ec58d8b7d1079ab2919cd361eb6cca |
Hashes for stim-1.14.dev1710743364-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 459ab8086289fa96a1e1b1b16523b12f9ec3ddf7203418b9a51cacb595a16d4a |
|
MD5 | 9bc14e2ba4ae512cbaff8da012e3aefd |
|
BLAKE2b-256 | 13572070a81b80436464d3fd02154c00ab3f34959c4b6e2baa2f3bdd53439a79 |
Hashes for stim-1.14.dev1710743364-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 951fe0ac582dd1a40f9dfbb24550783cd51f98fac2b62393bddde6b3e096c73b |
|
MD5 | c7f24b67ea42575160ba55be8c435c14 |
|
BLAKE2b-256 | 995a5d2c3695b470dc598e0a435247a306233259549befd5bafb3c564a8ef19e |
Hashes for stim-1.14.dev1710743364-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c248f4318133d50de11ff3716c465f34c61ba7b99e3f9a37918f94d6c5ae96 |
|
MD5 | 7a57bdb661e4e6af451dee5e42df7c93 |
|
BLAKE2b-256 | 01335587a95cc06e80e0eb7202d7b40e2ebaf4b0cf5e5d169ed20d46d7367268 |
Hashes for stim-1.14.dev1710743364-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c25b265559827f8078e575d28d98ef4645c5dca614c822b2b7755c3c139a3de2 |
|
MD5 | ae9d5a5d8758e3d3245d2dabf105c01c |
|
BLAKE2b-256 | d647a3ad1be93367952d126888bb9f60fd3b8fb658989bf7814f7c72876dc915 |
Hashes for stim-1.14.dev1710743364-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc15999f08bf71fc98959d42f75d22bfcb8ec7ea00644fe7caa4c2b1ea7add7d |
|
MD5 | 15a55be4404bffbaf25d3d3bc59b205f |
|
BLAKE2b-256 | 3ec4e1929ea35066abeec90da6ac152a9dbcb6da37a38565174175f8fb4ad482 |
Hashes for stim-1.14.dev1710743364-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f703151e0ae00f0e474253ba2629c10a596746c24c17997b53d6adeffd5173c |
|
MD5 | fad01e399d353f3d72eda7262621212e |
|
BLAKE2b-256 | ab02d8e59b80e584090bf182167a52137a9b84df9161b1717239c35547ad85d7 |
Hashes for stim-1.14.dev1710743364-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168f43ca1bd0d62a9f2cfc1bd086d4d1b32a2b31cba1eab1875d8d0a98cbc5e7 |
|
MD5 | d369d09f077a39326e3fc64172d1ca20 |
|
BLAKE2b-256 | 0799153f2a8d0abe26a089a4a0ed42bd225ceb3e54bab047882f9af72e78f7c9 |
Hashes for stim-1.14.dev1710743364-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d119e34606cae25db3677f655760c54ba90c73cad846d5f741b5e847b1b2cf5 |
|
MD5 | f84d3225fe947d3d8e57cde670850db6 |
|
BLAKE2b-256 | 10bf81059c3bfd1764a649b41b2c32249ee2a3546a96657d4349a0030cff53d2 |
Hashes for stim-1.14.dev1710743364-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abc21549152faae9c9d44a441a9464ef00134b177d99e893471d59e5c3304f44 |
|
MD5 | c4a7e5f60e0723f2ce64862e82b9d36f |
|
BLAKE2b-256 | 4111dbfd9553f55b0c59040e9b0f1ad1b2375fd6ebd3c0d371bea57d75b8173a |
Hashes for stim-1.14.dev1710743364-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b14f5c1b75a755dfa3659788f928a877c644c7171417acd0a53490b9c5cd15 |
|
MD5 | 6847584ea6715bb1bb8b497078c458ae |
|
BLAKE2b-256 | dff6a3d7dec1eb025846b99099c1ffc393cead0d3ed3526f15b2015be74cd5af |
Hashes for stim-1.14.dev1710743364-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 902d877f6af05c5dd1084c3bb41900b95b206f769b8c1f28ee1b0a170ae1c573 |
|
MD5 | d1749cb3b01b7291c80ea9121b56b69e |
|
BLAKE2b-256 | 1b99f50408558b93c22eb32ee0f4dbbcf226772ada00714550e304809c386ca8 |
Hashes for stim-1.14.dev1710743364-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e67e06e51451526811fab78b15851000b1eb4770b86d1208d95cec44a02b520 |
|
MD5 | 99e136a6c12b6a0f04e9d2b8c06a4f80 |
|
BLAKE2b-256 | 6ee2f067fb1dae602e42059eca34043356737a2d496253624f5140536abe089a |
Hashes for stim-1.14.dev1710743364-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1502e1926295a0ef21584820e77160c383f11d06f9de8cd9f0454eba4b89f03b |
|
MD5 | c3da9f84e31e8e8873d392398d63bff8 |
|
BLAKE2b-256 | 51a9fc40c95187ef34b34f55c421e43ff0cc82488bf633f633e70c38df6f978c |
Hashes for stim-1.14.dev1710743364-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0adb0e328299de4e2dff7fb750e2198070840e43203c265e03977d6808bf2be3 |
|
MD5 | f17d87bbfa0c027f30a91c82c1d5f9bc |
|
BLAKE2b-256 | d53b5195e4cc27073199a206814d90107a033b2ac704944751edf2728f0e900b |
Hashes for stim-1.14.dev1710743364-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9799caca0e278bcc55d955dab07cca78c9604c7708c3f4461339bd559781133 |
|
MD5 | 9c2841b940a8e80f254b8b63a3dd13ae |
|
BLAKE2b-256 | 130aaa06c0ec316af98807649f8ea7822c20e4e5120d9b89b2b2df23c3d97255 |
Hashes for stim-1.14.dev1710743364-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab59171bbc6814a008924c52b3017496dd93e103a4a1c0da584f208c27b51f7f |
|
MD5 | 5d606aa3ddbf4859eee0a1426d7dcceb |
|
BLAKE2b-256 | 67f9284a4de686a5c821b8445611e9f9d94237722825d187a199cfff87aac520 |
Hashes for stim-1.14.dev1710743364-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0db648a791caee06959c92680168e4960382efb140e2dfa8e91aef718e6a1dd |
|
MD5 | d3f2008d938edfcc47e4aa35849569c0 |
|
BLAKE2b-256 | cd01b531d50c01f60e4519036af7bfc6c53f3d3641a57637022cf2955b286840 |
Hashes for stim-1.14.dev1710743364-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbb2c1d6d32fda35b1790f83d12e4509bb2001ef58955ef0f896b85e25df18d8 |
|
MD5 | b98b39407eefddea52d14332ca0c108c |
|
BLAKE2b-256 | 92fd8216eef163a109d205c84cae680060bcdbb9d9e1851466a341c7b1216d40 |
Hashes for stim-1.14.dev1710743364-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7d734aaae498edf9931a700434fb8e6fcac7097520a32ab7998ff72a1bd39fd |
|
MD5 | c6ae65b411f395fdd90d8e58b0e686f1 |
|
BLAKE2b-256 | 266e2c415db8d7cbd40895b1620220e57232d4edaa6985efd5209d8fd91b68a6 |
Hashes for stim-1.14.dev1710743364-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af3cae79fc54e72cf24b1d2b0984ccc52e04b896e188e484f27ce760f671f1a |
|
MD5 | 8521e264963b63d020c47e008b8597a4 |
|
BLAKE2b-256 | 6d72beb93defd9bdcb851ce3d144682c44eaf1935123f11e79675c2a5107b360 |
Hashes for stim-1.14.dev1710743364-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dce2bbaecd13a0dfef08e190ea0aa44b87ea8281e1fa249487c3ab219445605 |
|
MD5 | 1adba527fd7ea367efcaeab51b79d502 |
|
BLAKE2b-256 | fb480bce8da7e94f23d335cee27edae02072c034b3abbd6ff00fbc8f4851360f |
Hashes for stim-1.14.dev1710743364-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 997f99ccbbb45711c7252e07580e60ac5871f603000c05336d83950af3c81d33 |
|
MD5 | 317033fcb809a3ae356d595f37e0b2d2 |
|
BLAKE2b-256 | bc7a46996c73ebc191277eb71018b0b710bdc6b5bf67b378bab51f6df463635b |
Hashes for stim-1.14.dev1710743364-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3a8e7efe4af30d9c44a82e7109619e79913a2076f93272e35322fd6359f5a7c |
|
MD5 | dfdfc90d41669b26d92ec089c6347884 |
|
BLAKE2b-256 | 9c3aa31421c311a50993c5efce4b05aa1051064c65ea7d1725e18ab6a8fd8b8e |
Hashes for stim-1.14.dev1710743364-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80cb29882dc4e36b286a221c6bea79750ddc532af62ffddd25e47892d6cd6452 |
|
MD5 | 55b783c9ddb8b0f6bf88c95cd86680c3 |
|
BLAKE2b-256 | b6cb564305fc562415dc25811e387da2fe0d1a03b91563c70f3490f24ad1dcd2 |
Hashes for stim-1.14.dev1710743364-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac1abe75df5e59c8f962ee88fa8b1f7da9757b70934f83f4e5b95ee6fed4fea |
|
MD5 | a056ebd6875ca59962d454d62adcc786 |
|
BLAKE2b-256 | e6d5533e2510fb162a1db68a667f9f40a9d4e307a34a343197e85329636b1d77 |