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.dev1719955661-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd4b4873ac4f5046c3faa559b5a6e67cfcefb3f6910135480eb3ef258de2a342 |
|
MD5 | 514a9e18f66d9c70f6d967a37826479b |
|
BLAKE2b-256 | ce3d033ca33fbc8c89b339a099f343c2ab6aa732bec9b16d3612a3652923c2f6 |
Hashes for stim-1.14.dev1719955661-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dc70dbfe3c191c52532558aa864c628ff1186413c1bff653cdb84e891e79324 |
|
MD5 | c1a72a5f2f82646713ff1decb090c214 |
|
BLAKE2b-256 | 99be11113ab6ce37b9b28105a156aa1268e38c45d5fbfe83fb3967773a4c9357 |
Hashes for stim-1.14.dev1719955661-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e573107804d97f1b266b274f1e2d5d51191b82b36c9da42e2df1c80f2a0164b7 |
|
MD5 | 72ae223752fe536d2b4c04df076b9963 |
|
BLAKE2b-256 | fa9cb9c004d5313b98d756dc3bd88b111f5663cc05f2c8bfa22ce322447e24a5 |
Hashes for stim-1.14.dev1719955661-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75c20e99dba24d43feda0b8fd49e3b91abb24a0d72bb9dbabfa4e3eea575842a |
|
MD5 | ef5b01a6591cd602f62fabb73096a2b6 |
|
BLAKE2b-256 | 00671bee953c06ce6c8f3a103080ad3a5e4e620352d9573661080173fafb1fbd |
Hashes for stim-1.14.dev1719955661-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27e065d8f35e048c12eab91b724e22af05bd08a5e891bd6b382b31aba75aa4ba |
|
MD5 | 3054eaf17f02e4ebd5f3f40d2561d4ac |
|
BLAKE2b-256 | d498e414e2b21b1dac5e84b640feec5784ea25fa42ebaec27bb7dbc3e54f5b41 |
Hashes for stim-1.14.dev1719955661-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b97b5256c8a41308c39d53411a0c84ea86edd997aa29b320160934411583906 |
|
MD5 | 545b654a101c176df17a71c558242f60 |
|
BLAKE2b-256 | 51ed9cb47a54842b2c2426861d90c08f49088a6df6b535cae5dadfe0789873be |
Hashes for stim-1.14.dev1719955661-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8801f6695cec88a0f97fc650905aa1ac6b8a3b10ff664932797aaeb68cb061fd |
|
MD5 | 53b6bf2b303f980763bf5775076cd095 |
|
BLAKE2b-256 | 7ab72944bf27feda761ba6529f696501b5d831357a7a0d53589ee789aceb3849 |
Hashes for stim-1.14.dev1719955661-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b979a92220fe7ccd9bba4036eefbcdd7e1f96f2db7753ec8b69c6d202d742ba |
|
MD5 | 51002bf6e452e5ea99b472440603444c |
|
BLAKE2b-256 | bd7c542d2c1a94a414bc550e9d5f66b9b4c73e9c7728e52a7880ded08dfd850f |
Hashes for stim-1.14.dev1719955661-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6425573c894382bff3cede4f3c6b38861b719f2d35b51247a546990e69edf6fd |
|
MD5 | 2b978b15052612812450cc0273439a62 |
|
BLAKE2b-256 | 9ad2009a34769429f0451132876d409bad264ba72ddf0d91930990c53a04f3aa |
Hashes for stim-1.14.dev1719955661-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b2baa063e2e533375990388d89f666e2f61ae5bca67d55fc1c85aac4c3ecb6 |
|
MD5 | 1e9de1617c1fa3952f8d3b5ead985ffe |
|
BLAKE2b-256 | f808407953e1d54a14726eea39a6ba5fffd39bd8176f7f9b86691d03cf8bd5cf |
Hashes for stim-1.14.dev1719955661-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14e0bca6ff48a40697b538156cab905de10affd858348ce422a137906109f9a0 |
|
MD5 | 5084b81249f639b8ca326fa67dc44bea |
|
BLAKE2b-256 | a4e652941032c81b5e3d68996c0037d142c2a2e3ae1eb36d388c0c54dae11b31 |
Hashes for stim-1.14.dev1719955661-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f2b55801d4b1ce2bce3420b5ee836d328c5b4c2491abb84748a77929eba624f |
|
MD5 | 5ebfd4bcb175b5aaa15a4733f15786b2 |
|
BLAKE2b-256 | 5716f4f4041be8c4e3e370195a810595df6be3c4f7be1231c0f5926ed4dc5f8f |
Hashes for stim-1.14.dev1719955661-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8109b0df821875314964328a08e304ca704b71f6f4a3c3bfa9c975af34a985b |
|
MD5 | d4b395c72dfa3b30de4b1f4ffddd0447 |
|
BLAKE2b-256 | 590479e3539e85eb4f82ab858facd37500807963029321963f2cae9c5dad921b |
Hashes for stim-1.14.dev1719955661-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85fb7d09bc9279f25fb6e4bbcb0a162f3bc246219609cd1549fcb69a6b96f4b |
|
MD5 | ebe8d3c9372311b09270fbb00707befa |
|
BLAKE2b-256 | d28dcb3aeffad921250d84d571a0042312366ce92206f6efb435d1cba63ca750 |
Hashes for stim-1.14.dev1719955661-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4ccd80693a7e822bd9e75a67d082c9f33dce330b1ebaa5afc640be30d694b7b |
|
MD5 | 58f5d66e9247f2c96e5e50c3dcc0c31e |
|
BLAKE2b-256 | d9bfbe39720d5f4b2a28c2ef19fd50a08c52930175c9b7b31f6b478d8e53192c |
Hashes for stim-1.14.dev1719955661-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6230718c5f4a5473c9d4c9153f5b75c90801402177cff0d437dbc6fae69bd329 |
|
MD5 | 88fcc3d380b7641a5003be07868dd299 |
|
BLAKE2b-256 | 6e08a4d7cd5767a94974c1024d603e63c34460a60f1cac837f1f6d9489088e7d |
Hashes for stim-1.14.dev1719955661-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d86edb383bb41cc2da1e3e9c62b155df36825440deabe32195f2c6c6fe5cb7 |
|
MD5 | 5654f1da7f6863460bbbccf0d65751b3 |
|
BLAKE2b-256 | 4433b6987ca32bf0ee1b3897cdf727e311498d6c98047fbd0c2cb8a8a1ec1d29 |
Hashes for stim-1.14.dev1719955661-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb37d471bfc8c33db608fb4bbc8ae769ee03f36644a8b0a1cca30d58918f2511 |
|
MD5 | b2539625c6d5ad0026f587c66f0d2cb3 |
|
BLAKE2b-256 | 899bd686f5f2582af979bd762e3d12364cb4498658a3c2a6e68c5247dd3ca51e |
Hashes for stim-1.14.dev1719955661-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beda32720e1e70f385e0779cfa7e17826fc5c9b7ee3ba5c790fb02fde2beff8b |
|
MD5 | 75167ad494f1f2554b9dcdc8d4c6fb94 |
|
BLAKE2b-256 | 433ecfde93103670337decaf02921a0c5d2beb0eb938daaa0e07298a755f5096 |
Hashes for stim-1.14.dev1719955661-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30f2c2de2fc42e4e9b89ca5d959d00d0e1f0b1566f2ef73911e5a3d216d31931 |
|
MD5 | f5f48bde08604dfe40bdb6c32ccf129e |
|
BLAKE2b-256 | 756e07f096ea7ffd09430e13676bc5399370a267f44ef841a8a1f9743612ac44 |
Hashes for stim-1.14.dev1719955661-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cd6a5eb388944ef8a3c2919aa2b737f125647652d94db4bb84a265632b5f8dd |
|
MD5 | 2116c39bd325be32d085f26f76480cca |
|
BLAKE2b-256 | d1754851edb1f70d2b5da024e36315904c3df5cf2dadb42c6171f27fba36859b |
Hashes for stim-1.14.dev1719955661-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8219625edbe1ce44af869775ba0179cb09931b0f68f09b594e44c02bd760c465 |
|
MD5 | f1cb3a541be6a1f9cd5b428cce9b6e6c |
|
BLAKE2b-256 | b65fa0bd464faa115b4b854672ab3c15227a66068e22f820046287816b36876d |
Hashes for stim-1.14.dev1719955661-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f7280db5f29ee09c1a6a203e2dfbd965b1e7d662cf8c9cad97f0083b96a54d6 |
|
MD5 | 3e6956d1c620461117a0b1133af6c08e |
|
BLAKE2b-256 | 601c2e82fedc07e51f0573821ffbddd09ab79a0733d8d12eb6fd16020ecfab68 |
Hashes for stim-1.14.dev1719955661-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a4decdf35d3fbb6ad11a354703754a5a1430be0c13055c20bedfb225faa6a9e |
|
MD5 | 1eeebc559e1e6c8ff16c4f2fabbe5b73 |
|
BLAKE2b-256 | 5bdcb8fb948aa5d73e0c27ebef1974419312c69b2f3283e9036300103ebbf016 |
Hashes for stim-1.14.dev1719955661-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58d062273ac384f171568d222e6794063b21b33fa66ea7b4be1f920853efed7 |
|
MD5 | 37fe75c814ede90b267e6556183848ce |
|
BLAKE2b-256 | 4d6cb450d32ec15400afa9a111b403ddb93c96eeaf3d1c59c3f3b93445760371 |
Hashes for stim-1.14.dev1719955661-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78db4eb106eb589c102fb36ad751697f44207eeb4bdc5fe729da6c0a97bd12f5 |
|
MD5 | 75494d50fbfe437448fc746069dbf46b |
|
BLAKE2b-256 | e239f87d6b020e5f90f7eccfe17320a3e2fdc9a4c554f694af372b69883b2f66 |
Hashes for stim-1.14.dev1719955661-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14eb58c3186a113714e424f28a02fb23e26111e37c3d8ae890e32d30a80216ad |
|
MD5 | 14448438c663115c2747e0c38d70acd6 |
|
BLAKE2b-256 | 93784316194dadc0ab8440b99cbd9353bf886cb81c9f19e117f5274aa572fa65 |
Hashes for stim-1.14.dev1719955661-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19b2bd1b4d20596ad3494c6420a6826c315c7ab6d16257f2d6424d273ab4651f |
|
MD5 | 727b8d873a1a985ae62fb46cb30d2a28 |
|
BLAKE2b-256 | 7ac71eaa294a6b1b948007525738ad8f74dc2361e29631267c417f668b5bac7a |
Hashes for stim-1.14.dev1719955661-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb16be917025fa007b21c00ffbd0e1c9800102fb4b95ae60b6a0c0bb743d3f84 |
|
MD5 | 9cffffdb100f8c43f29e679a3a9c67cf |
|
BLAKE2b-256 | 684674a598d9edc486682ff6a6d37f776b21216401babdbe68ff8556dbe6b96f |
Hashes for stim-1.14.dev1719955661-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c8ae553866999fba838e4971eb7add78b9ef057a5cafd26019dbacb6eb6e145 |
|
MD5 | 42337477b1220f1836e5f29647968a90 |
|
BLAKE2b-256 | 8cfc4444a33e0a2a75c438f51a3d64d073f53f6ac8331ab5ee3174330e4933e0 |