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.dev1726889409-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1d9e170e48d48556797263c6b9d441fb675176857e8b427beb0fd934c644f48 |
|
MD5 | 6aaf6dfe4624cea746e163f5f822be07 |
|
BLAKE2b-256 | cbfba5a1bf60f1020dd1ea0b5de33534e77e319ac38f601082b2f813e3a0c390 |
Hashes for stim-1.14.dev1726889409-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea36ac97c1a30e3a1c861b8f15e34dce447a5fc402bdd77c195347bf56b145c4 |
|
MD5 | 3612a1fc5f66eb6c9b9d79f9e4faf43e |
|
BLAKE2b-256 | 1aefe02cadfaf06a6c47d2d2795c967fef93ccee6647eb6d8bd6307c73e09e35 |
Hashes for stim-1.14.dev1726889409-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56fa06319f908cf9977b910f38f99dcfdd11e208180a9ec1bd111c6d433d22b |
|
MD5 | 0cd90c0dccd9f46a02d0c0ccf5dc959b |
|
BLAKE2b-256 | db06bab699534fb5aa64c1b114c1e4a0afd4d6641dc22b55647500987d0012ab |
Hashes for stim-1.14.dev1726889409-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33addc0b2c1e530f44614f67a3775c57d80744e1b1354d4617de01568c026473 |
|
MD5 | ed966f53eefac7840c03693337b09b18 |
|
BLAKE2b-256 | 931e6c36a7698233c94c6d9d4ab75167cbeb6cb3270fb126a1122d4011407791 |
Hashes for stim-1.14.dev1726889409-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ed969462399736bd92607e60e6d100a2ca50fe8ce9ff1b26c302ab16bc6243f |
|
MD5 | 46ade596367f6626898191b58cb80697 |
|
BLAKE2b-256 | 21bc53f239ff85f2db5ec9bfdd6c35dc41b05f5aa7b31b1cf093ced720934b91 |
Hashes for stim-1.14.dev1726889409-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 517f4c4be6e56fd2a3dbea91aa77bbb53a836c12dfe77e8cd8c0d6996db8a1c8 |
|
MD5 | 91524448ba0624cec413b12ebb0bf7df |
|
BLAKE2b-256 | 451a13a70c0a2b5550fa5dab73fc79352dd28b33f5f4e91b4bcf9699722699cb |
Hashes for stim-1.14.dev1726889409-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ce323e8e59f21eeafc30a6c1fca21e83bb143b1a823f625f97832c0398953da |
|
MD5 | eb7dca12cb223bbcf296aaeed6e50f65 |
|
BLAKE2b-256 | 8ec4dd419c44c166b9921855dced04a5ca98048b73429075294f039af75c9edb |
Hashes for stim-1.14.dev1726889409-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4081299c99768496dcbc7db8d1ee68e1e8227a5ab8972f5ac9e48b48a8e877ed |
|
MD5 | 355e1975cbdc701ec9ef0f2c2cb415c1 |
|
BLAKE2b-256 | 2381cda621903f3cf0d2d27cc2a8faf03a721439604baedc84bb746e8445eec1 |
Hashes for stim-1.14.dev1726889409-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58dc196781144f77d80d51b5cf2087c3634133ff097008494830cf1af2e4e629 |
|
MD5 | d61c238e6599487b77d4c5956a9fa79c |
|
BLAKE2b-256 | 8b7690578c3631b1075defc20e00ae2a78c27e846edc046d0b2d9458a8f8b2d2 |
Hashes for stim-1.14.dev1726889409-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b50a4a1ed290bfff697ee7546539739f3bd77b700caf08b2650bfa44b77dcf1 |
|
MD5 | bc5d698a5ba7924da421f56f1e77c48b |
|
BLAKE2b-256 | cd0051f3cabd4cd1093db8d074c59152ab06631e36bf43562c29e8291f58a8bf |
Hashes for stim-1.14.dev1726889409-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7a10d9a0acddfe66a261950f269a57e7ac28962834fa3bddce265f259fe62e4 |
|
MD5 | 928a7fa068cdd471f544b32c9b4c98cf |
|
BLAKE2b-256 | 7b7275949963201cc02dfb0541a244ec9b28830c0754eb63e751a72542cb8989 |
Hashes for stim-1.14.dev1726889409-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa2d23bdab5b34d1f9ce6c5f993a1c92915987ba06d5784895a335256cfba6b |
|
MD5 | 8fdf2d33cc5662c921c607636dd9d1a4 |
|
BLAKE2b-256 | e3985ddf774ff54f9478c845be75216585cc8fbf50ac2bdb50e962a7a4323d87 |
Hashes for stim-1.14.dev1726889409-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d3464cd13c300094b2527031958e7d743cc55bdee56d4020cb9990389140a7 |
|
MD5 | a102fbe2342da66ff776209615427216 |
|
BLAKE2b-256 | b468547c5deb701050ad4634b38091f37eb388e814b90191ebc79376e738250d |
Hashes for stim-1.14.dev1726889409-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8457d240bf476e86925ad0a1faddd58260320fee93f43c19b17ddc5fca21458e |
|
MD5 | 437bd1991f20341834a04602e80aa4ce |
|
BLAKE2b-256 | c1eca489ed13d15675baa3c72303479cff52029aa2978f80e8603cff1be5386c |
Hashes for stim-1.14.dev1726889409-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b284375048ab572d8808afd886358529b4922e1bfa6578c6f5795825b57bf1b8 |
|
MD5 | d98937c08eb64c8cc6f2d89c1d4a9b8e |
|
BLAKE2b-256 | d123ec14ccc542a8d047dd08224e5d75491ca117b60a2af7958ea60451a8e6c7 |
Hashes for stim-1.14.dev1726889409-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6426d734fb4cf89b0f9074aa86d41ee7c58e2474929975ea26822bed9e8e20f5 |
|
MD5 | 5c0455187938cf17dd60a230a42e1797 |
|
BLAKE2b-256 | 325121598bea1b6aa561ef707a22c808293215d62af629a49cb0407ecf4b9b38 |
Hashes for stim-1.14.dev1726889409-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b503db2bdbbcd7d94916c50c8cc1e63b15a75da0c86ba1a61ff1c738d569e29 |
|
MD5 | 76e001b7c8c2b2ca077231f60bfc6993 |
|
BLAKE2b-256 | b1f2771d53bd2dabf9bc5e60078a9ec995e846bd3fe0a8386eb1473243056ad0 |
Hashes for stim-1.14.dev1726889409-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 468f119a2b9f676617c8c0568d849bb0a2ead106ef7c490550a067fe2fb6473b |
|
MD5 | 15839d5410da1d9fab3881ea0f6f454e |
|
BLAKE2b-256 | d059fe08927e7d29bf1397a4bc525b9cd643d6349412045244edf00b6debfb31 |
Hashes for stim-1.14.dev1726889409-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd12ea4e0f6ac6ce9f11e1e3084345ed8ed59a3a529909acc5e0487280aa2afb |
|
MD5 | 52e1d73382399989864ff036642e449f |
|
BLAKE2b-256 | 28710ea3947af1603d26d76c664c79e00c56bc390ccb2d048fc1a15109278e18 |
Hashes for stim-1.14.dev1726889409-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a382acde50c63bbddc5a4e394ebf0121ad180c319d6f03ad0e83063c0eec8180 |
|
MD5 | 0430f2fd197c01c4952db9c13aa29b9a |
|
BLAKE2b-256 | a5eee31670829972aeb2bc34acfe125a32fb5e1ab8d6959a3f51738c13144843 |
Hashes for stim-1.14.dev1726889409-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eca6a536168dc53be5261d229535a43ca8a2531b2f79565fe0e2ebc14a12a59 |
|
MD5 | 56a8435e2a1f9292e167d6dba1b14df5 |
|
BLAKE2b-256 | aa092bb33e075ef4661b4fd16c461150d1b7ba7380b9ed562466c565fbeb0425 |
Hashes for stim-1.14.dev1726889409-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f95cb17b663690187945f7dc8c9dc7a8979a682a27edd639bdfb0a9dd27a0435 |
|
MD5 | ef8ab9e5f089da5b0cd951ff45d32d42 |
|
BLAKE2b-256 | 7e96df3ad66e19eebd15e67ce567285beb95dfaa1ba720d7f820d4239d528afb |
Hashes for stim-1.14.dev1726889409-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207085557c30418c43a8b30424cecb8f0b5ec3b98dcf597f87c684113b40e742 |
|
MD5 | 2ac61b8d36d541fc3136bd51e0d2757b |
|
BLAKE2b-256 | 08629854ee50daec8aa2c33f239c13b9a4433248904ec5247a7a27d33cdfff56 |
Hashes for stim-1.14.dev1726889409-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae8bd6021afa587a81dc07aac45e0b417fa9bcd0105e5d66df58d212f5225aa4 |
|
MD5 | be21749954c83d2ed5f6b86cf63f9878 |
|
BLAKE2b-256 | 07a9aa8bf2d45a1ac26bf07c18143fa312e3f93985953283cf68b183291079fc |
Hashes for stim-1.14.dev1726889409-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ea35c77df3adf106840b7bb0bf6ca412fd8c0e85e3969c430e5d7c6c84d7e4e |
|
MD5 | 983d086ae6b4b87fe0227888eb491e68 |
|
BLAKE2b-256 | 9988dc000e7a963337ab47b02af5e5b9f237b524c98d410e2f4c42f06bdc23bc |
Hashes for stim-1.14.dev1726889409-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f93b43e44f3268463f4945fb41ee509716fb56f81dbce85e7ffea15e83c99839 |
|
MD5 | a14cb6aabe0551f71cab26986ead8a65 |
|
BLAKE2b-256 | 01792100f4203d336a8a11af992de6d5bf8d2184dae7bd2d0c98c0d7bf1aee37 |
Hashes for stim-1.14.dev1726889409-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f3577b6eed083cad916c2db001e22c96186b0f97e1ffac23bcc1e4cc35f1bd9 |
|
MD5 | c657baf8a9e631d1ea6bb4cac02686d3 |
|
BLAKE2b-256 | 5a271b7ddea2a031f60367d1c577feadc7299f6eec7f854c75aadff2c95a2b23 |
Hashes for stim-1.14.dev1726889409-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64343ef3b030fb271b5be67d2fda7e2e251ad9040c1c6125de66facf14a4589 |
|
MD5 | 37da503329cbf5dc1117b305f8ee05d6 |
|
BLAKE2b-256 | 0b4dca8244e5a016c90e55d53332c1da0dbe4a9b3360492042e32dadb6f80483 |
Hashes for stim-1.14.dev1726889409-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee31e8a7b2ad66b38ef6e6ac73c02350976167820c768be0d29b6eebe66b8b8 |
|
MD5 | 57c42d473bebd32a5962ee035fe25907 |
|
BLAKE2b-256 | d6911cdad9ee5833519c1c65694b04024830427bd7618e7f04c174f80b462e67 |
Hashes for stim-1.14.dev1726889409-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e28a9d22e4fe417aed2e8fa7f2e0b8a3489286cdc55ddebab6b85a9e898ae193 |
|
MD5 | 3f2ed3f9fd181e23ca7e7bf3c41476b9 |
|
BLAKE2b-256 | 3773862220581621a7ee75b34dd782e667e628e95bd5958df2e54db3729aada2 |