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.dev1719295897-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb256c921adeee77f633f7b569b7614d4ba305f0af5f42e0a3fa8d5cc447fff3 |
|
MD5 | 200fbc949a8b5bd4b67c8d243e836ee7 |
|
BLAKE2b-256 | 646f147fa9b2398ab996629a8b4e95973a8973f265a937bdd3ff3bcb23274cce |
Hashes for stim-1.14.dev1719295897-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17d2b21a807f3d40260287e1f7055482a057288e5d4fd674a208964a93de0e5c |
|
MD5 | 45b69211bfbb51121d5f45053ce2f9f7 |
|
BLAKE2b-256 | ab23cc4ca18b1995f885341747971cdde007e9c43ae7b42070c790d754fb10c7 |
Hashes for stim-1.14.dev1719295897-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6d942a23adc7be7a863203bba664342536fc2215f8c5f16779058b7dc488c40 |
|
MD5 | 13d3dc57ee1581bf430573959a2426cb |
|
BLAKE2b-256 | a24182e7134be0c5542d1f7f07dbb2367c3bae60c7260f2715a52a994fb77d42 |
Hashes for stim-1.14.dev1719295897-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07050e510647ebd4f1718227cf372faa6e7971d09d40b9811f6da3555fc59924 |
|
MD5 | 23d6a57fdab694e0d98581db8025a959 |
|
BLAKE2b-256 | df728168a603e1509f89ca36c8bf5474c2b5c69aa25c7caa9eba1bd76fcdb7d6 |
Hashes for stim-1.14.dev1719295897-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf2b622fd49bd9895351f8e9d8422e5d291217f8d2c079b2a303360e01007d58 |
|
MD5 | 1a7f6b8dcdec79746ed57271fd96769c |
|
BLAKE2b-256 | 719e82bb64f9163fec6efc4e9260aeda0385ae1abcec0006fcda4bacdf0463af |
Hashes for stim-1.14.dev1719295897-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13fb7e0115fe65aed94ccb7e71ed5fe00c62b595bbc526cc0d08c60ab237481 |
|
MD5 | e8ca9aebfdf5628e6a2e3ce28459fba2 |
|
BLAKE2b-256 | 0020831066831bd7c7a4e249b9a317d5c66a03847c6019921c366ffbdb257e81 |
Hashes for stim-1.14.dev1719295897-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d00e8888676b368784493d8ea707201690a7ca4abc4492e2bab630626e415d7 |
|
MD5 | bca7103b8a144c402de54e14de365fd9 |
|
BLAKE2b-256 | 411bd0c4a985b3d8ec90833dec46a2d970f51f2600cac124dcc37ab2c66a8e5a |
Hashes for stim-1.14.dev1719295897-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f6bf3c9e6e96f8ad813181c823e3c5445aa621d8e279593e835d1333954246 |
|
MD5 | 5d8aff96c8301d82bbd4ff1444121072 |
|
BLAKE2b-256 | 9af9ad761e61b395392bfca67aaa7c5758db1b2d12b87a1df23f3b8fbf2002b6 |
Hashes for stim-1.14.dev1719295897-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11d26783945ba7285fb787a7d4f3b3048142915be8d544feec5336ad1f1a126d |
|
MD5 | 68cb57d6c5af980ff79ff8a262d85be0 |
|
BLAKE2b-256 | 8264c9cce5e08ad9ff785052401b73ccd36662df20a3c8ff341e72643976d49b |
Hashes for stim-1.14.dev1719295897-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25cfcc7832c5bf0145d843012ef7cb2ba5c2aad39b4312af95afa4ba4b1fc3be |
|
MD5 | a06899933c07a9128c546ac02ac30fac |
|
BLAKE2b-256 | 7484d89a69cb114f14b6fe52028ce337c30fac42205340692a5c0de67c063dd6 |
Hashes for stim-1.14.dev1719295897-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2a328552dade00bed048f127efb176edee17ee5fb4d756239790029c29910b7 |
|
MD5 | 7673a3a836dbc8c6704ad1de2d52ac6a |
|
BLAKE2b-256 | 030a42c49e7c51c99529647bf440eddaa763cebe36f588549102d6448b7960de |
Hashes for stim-1.14.dev1719295897-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96368df0c2c6dcbf2adf8e53dee4ce854b503faab765bed8f180094051014a89 |
|
MD5 | 440deb097562db2fe5f28b241ee49290 |
|
BLAKE2b-256 | c8dbd1fc958ee907288b44d2ec19c3243ca7ad642d4fe8754c0929f00d42521c |
Hashes for stim-1.14.dev1719295897-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f17ce7b8a34388234b3d3642d6591604375dd3b3550fe43ffe3472482ebc8a63 |
|
MD5 | 86eab61f0621c54f57c1149ef45b357d |
|
BLAKE2b-256 | c40c1ae8a1a474c8175cb720d487a2c8009bae45d8817623969af1486cb05101 |
Hashes for stim-1.14.dev1719295897-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e0f72f04d6cef8ef1224ab984c6a0ef6c9448e1b8f4e6aaca55848aae3c1d4 |
|
MD5 | f1c671fdf77fa9256e1d166a8e61a913 |
|
BLAKE2b-256 | a3de23ab04d614a3ad3a3bb3ad95e343edb3baa2a96a53515f376705110b6c56 |
Hashes for stim-1.14.dev1719295897-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54f75a5e2783ad1360c9f205e4a25350854efee0c0f5e53c722b26476f896e1d |
|
MD5 | 88fa7803d6050cb109390189c48b02cb |
|
BLAKE2b-256 | 7888d88a41d4b4d518f8fb23fcfe1293f9ae7c15623fbff2eea331f39ccb92b7 |
Hashes for stim-1.14.dev1719295897-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b51d0c2bbe5a280645f01d0b8e76b2d0d86cada955c4466208c8194f5357d1f |
|
MD5 | 4b616ccee24c8e1450ac97635335d3c2 |
|
BLAKE2b-256 | e5e5507012384fd18b47c330de69afce2e080e0319440a923d1859599d16e8b1 |
Hashes for stim-1.14.dev1719295897-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ee4f045168cc6f1f07ef54478644599b5c6c3410b20d7ec5e30fa28942234d |
|
MD5 | 651422ae44b55e578ecff3c70ac14059 |
|
BLAKE2b-256 | 1c038b8162c30e6093c9f6a236666abc77de992cf4d0769c58426f149fb08315 |
Hashes for stim-1.14.dev1719295897-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2d425293f1c3472c33e88af0791aad29e0d06b7adc181ddd2f2c45a93339639 |
|
MD5 | 33850fcaa83a31775376c305c65d1aea |
|
BLAKE2b-256 | 2387e6adc02c46342936980aad22b541dfd87e201b4c118ad83f5183f9ea68d9 |
Hashes for stim-1.14.dev1719295897-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3de97f8cad8dcaaa089ae403fa8db1861db1e16465f7f859a23b07beaec822c3 |
|
MD5 | 6c0b54780f1468868a7c99ef6f437f45 |
|
BLAKE2b-256 | 7255d4d7c99846be7cae6e564b4d0eee7eb812c85d3592e0da67bd8801420b1f |
Hashes for stim-1.14.dev1719295897-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0206df745b9fa6335784fd0855da19038253aadd335f7844b5fb49a4d69ee5b6 |
|
MD5 | 7ac3cd9d9f85c389b52abefe697605a4 |
|
BLAKE2b-256 | 2e5377c4bb5a2cc499266bf639293b806175c1d843048ba035f4b8779c7c5802 |
Hashes for stim-1.14.dev1719295897-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5270a7a7aff3730a96a816469b4fc68abb65ade1226a9c28ba0c4d0cb7e488b5 |
|
MD5 | d73105f4ec498d2fcd34c2084a2e70a9 |
|
BLAKE2b-256 | e8d337cf2b50810a38c444b598ce4ed00feb18eacac34334579135e6d74eaf7c |
Hashes for stim-1.14.dev1719295897-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1ae28859d2492580db582a17640491458d4af89c01029f6f7913d34b58e4338 |
|
MD5 | b409c028fd45361930f465c3f75b9fd1 |
|
BLAKE2b-256 | 7035e1e145e5100d9ccf0f4dec631938598745a91df7835d2e4d2ec9fabf99b8 |
Hashes for stim-1.14.dev1719295897-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10c32c6dd38b1df4b44a52742fe61d406bdc2591e95709f95242cee9853b569f |
|
MD5 | 1fb231e775cd89fa919ad477ef920c3a |
|
BLAKE2b-256 | 8cea0db43184002b97785660224f83487ed89a8aa8ca31f7dba0574d0f5e1c86 |
Hashes for stim-1.14.dev1719295897-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4a80ea09c82aae27b8f35dc1dc1811ca4fe18cc294afe264a58faede216dc1 |
|
MD5 | 69af1254f8cfe724a25ff1300161268c |
|
BLAKE2b-256 | 1526a52aa4f6ebd051ef53ce5b93dd65050533e0c8a04e6a4acc487f3cfec277 |
Hashes for stim-1.14.dev1719295897-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cd786c99caf53a2ae07d7fcf423edb3a1b2a07d193a700d7067d150a92c0349 |
|
MD5 | 3a245fa06fef0fe78830ce0e4805fd62 |
|
BLAKE2b-256 | 49f90fa4de8492f7ed9c06991f9e217be9431ea38ab1ccf77e70a6087b517fa9 |
Hashes for stim-1.14.dev1719295897-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2ce4222fd3e39ee77a7d0d80f4ad3586ab218c83564d0db72d699cfd5c1cacb |
|
MD5 | ca510c27b2194abba3e36723caeab278 |
|
BLAKE2b-256 | fae3bad51f0110b33f681de4d662bbb0bb41ef15a15dc5773c4dd98217af0efe |
Hashes for stim-1.14.dev1719295897-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 522569f2e59d51b740420aeb3859e4f9b4920ecaace045b5db8aa91737b9b4b5 |
|
MD5 | 5a11aced3e89daf583daf524306f8b5f |
|
BLAKE2b-256 | f17e8656dddae65c07bdf3714b7172489ee6616aba0fb0856896ff95229ab90c |
Hashes for stim-1.14.dev1719295897-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9ade3f5a537df9711a9be0cd59aa458ad38042fc34096dc3a0a7a219fb2c67b |
|
MD5 | 2089b0e9f6cfee896099da2eae0d802b |
|
BLAKE2b-256 | 34418e7135d59b4918ea6b79801b38562f42ac811437d4188befc54c76f6fae5 |
Hashes for stim-1.14.dev1719295897-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c8f8a36226b8de0f01c18369c04abaaccbadafde5386334109087729e9c27c1 |
|
MD5 | 16c3cb390c2dc6e4b7570230aca86184 |
|
BLAKE2b-256 | c4cb11ceadce73d02c21e1da78fe357588da71009a4b851405e5cfd8a32d6ca5 |
Hashes for stim-1.14.dev1719295897-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3de7b87a1a1d28b4db817d33e1ba5883b724a9c05fe7868d249b889521915f |
|
MD5 | fe7c9f8b711a26a664aa7eec6fb52dda |
|
BLAKE2b-256 | 770eeceee81806f55669fccaf1c2ade87effa7a1aa2106fb8cf3885bf96cf4f6 |