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.dev1702511128-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8cb2d4d3f815e9c3a395902ce584425cc19ab9f68b18bf43d34bd0bf6c3ae7b |
|
MD5 | bcf586f2df7857428b00b2fe0d309945 |
|
BLAKE2b-256 | ee3d442f46918bdac1a83a41bb28e6570808b43e76fbfb287b579be4e56ef4a9 |
Hashes for stim-1.13.dev1702511128-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb66b55158cef01a329d4c9826de371dca0b2af0ab5dd72ed41086eb7c9e45a |
|
MD5 | 7c775c00fb1cdd33c8d95fdeaff24727 |
|
BLAKE2b-256 | 4980d976ad40c8f22c354b64c51b677adc3716f85531b0e4a51abc1785a3aac5 |
Hashes for stim-1.13.dev1702511128-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07329d2662fe58e2b881ed0f2bb42d9605105816a7ab21e78cf82dc5cc2bfb98 |
|
MD5 | 385d9c904c06284bc929f54cb961a39f |
|
BLAKE2b-256 | e9eebcc595dadfa781fcb31845516c09135046ae4855a0ee88d665181391bd6e |
Hashes for stim-1.13.dev1702511128-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0afe06ab8e1cc1bb341c2e5881d81cd9b0ec38c60bb9d3f2801c2fbf18fbbd4c |
|
MD5 | b3f2d2935c1c7cc657311fad412872e1 |
|
BLAKE2b-256 | 58ebc7a212dafa5b98d88a36f41c4cab7ed517d18fb59cc96d5dfc903084e169 |
Hashes for stim-1.13.dev1702511128-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f52d76938590ad3d5831341bfbf6bd93ff6fdcf53cbc7f0f3198469c62660c84 |
|
MD5 | 64064d534d5090c5e8811f3ed04eb1da |
|
BLAKE2b-256 | 65c607ca519d8afe1950a5a8d5f1ebcac52eecd63457217d2d75a03367d02a34 |
Hashes for stim-1.13.dev1702511128-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b264ff075bb713bb27d63e760fdcf2c10511806dce4ac2cb253bf285d9291d2 |
|
MD5 | ebf0c028adffabdad660782d9767a0d7 |
|
BLAKE2b-256 | 13f740aef604a26decc2d38d0784f578558a49252e37b8548d08b45b667d1043 |
Hashes for stim-1.13.dev1702511128-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f04c38ef7aade203b03186b1bc9542c8582bfa470955ac40a2716b8ec92f6f2e |
|
MD5 | adb082b7704dabc639575f179a4e5a09 |
|
BLAKE2b-256 | dbb99bce1181d9e74b15e7377dc90b9c2a55ed948b73423e44a6517215646ff7 |
Hashes for stim-1.13.dev1702511128-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff574eb058e145e35873eb1e40114875128fab3740bbff45a31bece9beb8ef52 |
|
MD5 | 37fa4254319e6b705abe5a7d99797b7d |
|
BLAKE2b-256 | 939c4cdcf81b03b80c4324effa07608b0a4ce0248634cf70700ed988566c24b1 |
Hashes for stim-1.13.dev1702511128-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 694b6ca0f1185e9a6831220916fda5edcc843fe75c3d9f991b043588dc9ef36a |
|
MD5 | 0c0af17c24a67f66caf39e8e7a8b98cc |
|
BLAKE2b-256 | b59e98fbe4283a4888abe148897479c914dd1edaf5685be1a8913990d89b352e |
Hashes for stim-1.13.dev1702511128-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1993681124d892e80ff52a966aee997e88215af0afa1cf19f588e455f57fd2d3 |
|
MD5 | 156410ddec57cd24bf86414b9aed0421 |
|
BLAKE2b-256 | d4ce8b6d638a3e997fed4909188aaf632cb7249c01cc2765fe599289bd5afdc0 |
Hashes for stim-1.13.dev1702511128-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bcdaba2894b4a262ad2de87b528017449465ed77ed2bf47a407f0fc7fcb7607 |
|
MD5 | 3d2d3c85adef8064d307b4cdea040fc1 |
|
BLAKE2b-256 | 029a887a2acfe6a36242d66b45e237196590808bfbde837f546846af718aab13 |
Hashes for stim-1.13.dev1702511128-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e857347de8fc061cdf41db1b60104cca26df485c7dab11a9c74c56c41a77a3ef |
|
MD5 | 21652777786f0d08381bc3808e9480e4 |
|
BLAKE2b-256 | 0aefb163cc59b43226cb8efedd8573ebc4335ce6a0e4d8ca2d72f557dec48539 |
Hashes for stim-1.13.dev1702511128-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b395ba7f9ed4488f5f2b2a21ca8a8f117a5de0a152833cab30662f42c5902f6 |
|
MD5 | b149e2c92e1f92ce2cafd30251ffd15a |
|
BLAKE2b-256 | f16fd4752ff0df07f5d2644e9d0a168fcaca910cf0b15695ad4daf4893ed5cba |
Hashes for stim-1.13.dev1702511128-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41e81dad2e011c97be742a006515d1d72e79de000252b79a5fc5535ecfac2ce0 |
|
MD5 | b483c04b2d810565aee8be1983ecdd4e |
|
BLAKE2b-256 | 6aa73afeddbe2b684f31a6ebf24cce639bc8f41c6b6eace31c1fcbd9af26823e |
Hashes for stim-1.13.dev1702511128-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3d745bf4ba5c10cbad9bad856047f76ed8e46093010b27dfbe64caa157fb2e5 |
|
MD5 | 697b3f1535822cd9721f5481960e0bb5 |
|
BLAKE2b-256 | f7588fca8878b084c75b188575fe92139d80d4cc8d8692cda36723fb4c6f49c4 |
Hashes for stim-1.13.dev1702511128-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e66ef2b5c39b72a966ae418679b65fb19a242541368c6e162f9c321859a29616 |
|
MD5 | 532af8fa790e2cee3d891b969ec0332e |
|
BLAKE2b-256 | 791ee2d75d2f7e3f11c6f46e0ea869a98ecc32edd6e70422fda0b5aaf9f68465 |
Hashes for stim-1.13.dev1702511128-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18aacf27e8b4eb22b4268b532e2d859d6a6d8bec47158fe2eea710cfce7d4254 |
|
MD5 | 6449949c12617a1d2e66f037a4d2689c |
|
BLAKE2b-256 | 4e81f8e05b2fde2e255887a37b7d7c4f71b2287d4c5c421c0160186714c1c10b |
Hashes for stim-1.13.dev1702511128-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43755b2bbf4eb903e73cb9bc0d2dd85c45a1e860f56c1987586e26ac150d7e02 |
|
MD5 | 3569fcf870b684be0371e677285ce786 |
|
BLAKE2b-256 | 12cf4bbe5aa28e1c33ecc408e34e94ae76d09ffc65ff2492f250a1a74932b0bc |
Hashes for stim-1.13.dev1702511128-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3c1e36ab6b23f0117d3e6616aef7d3e162aa8ab15ad76c8483ae5da00c28c1e |
|
MD5 | fe9dac6de7645c079eef8c0fa88cfc93 |
|
BLAKE2b-256 | 998609ead534e2983f4d7a9e3f006d57a8e5627b022e070275e71b16832cf32a |
Hashes for stim-1.13.dev1702511128-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ffa2570af0d17ed1c8fbd80fd04cec32825970ed77ff91d20c28e69fd4cd091 |
|
MD5 | c5356e35363d0584958d8edc26b2547c |
|
BLAKE2b-256 | de2801a81d2ebd9c4f843a0ba5ba78db5366d8ad04623699ed24938f22d56a97 |
Hashes for stim-1.13.dev1702511128-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e51533eddb09135bd35ad51867fed4ed498240be7b9b2bf9a3686bc7b1ddda0 |
|
MD5 | 117dfa0603f695eeda269ee800521672 |
|
BLAKE2b-256 | 772be8303329a4623685574e67e59bc21b34ca8fff4ac87411eec4e1c87d26d3 |
Hashes for stim-1.13.dev1702511128-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d748d4597e6830042c3dfe5a7ac07e462b9ce06b6d60e48ffd1d6f7315d12240 |
|
MD5 | ce5a8e44f55503f80a3d882c2e0d593a |
|
BLAKE2b-256 | 151dbe42b33ab0267d9cd9ef57400496eff0725f699fd01e4fcc8caf50d753a7 |
Hashes for stim-1.13.dev1702511128-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed0ae8abe748b8a0ecfd5ec74f5ea84e12c1c4899f4e2cabc763095db087deeb |
|
MD5 | e1c2aac2eeaf9bf9c42973414ba3a034 |
|
BLAKE2b-256 | 3f54a1e7ba61df2ee57dd46a10542d229f75b0ecf7749d8dd35af984ff121013 |
Hashes for stim-1.13.dev1702511128-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae4b474ef10ded43de7d1e9ba65460efc30ccba1e87bf21a70a9f0b0eb35251 |
|
MD5 | da95a36a3ae55dde5483c5e13b620be9 |
|
BLAKE2b-256 | a14170670cbced037f590186ac8cd2eecb3a35f9199ac5d0019300e6771a283c |
Hashes for stim-1.13.dev1702511128-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc2a215bfd9c041e4a4c6ff0c45f7c42bf0703d0ec25f441f6faf8d992705b5 |
|
MD5 | dd4199c6f28bc94b4f78d059ae5691bb |
|
BLAKE2b-256 | 3606ca1a0cc1ef8f9742449e84d2bf86a529a3b78e7246d654df95b0d85ad4f1 |
Hashes for stim-1.13.dev1702511128-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12c204c0cd1fd8980ea84c6498d1732c4e6c137a86bbec5b1131218df1cbb18d |
|
MD5 | 7cdc0eff0b270c9c499f3279dc887fde |
|
BLAKE2b-256 | c9c0f3d739dfebac67ae1fd27cd77f17d6c355dda83963746404210113b7897e |
Hashes for stim-1.13.dev1702511128-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f30a76db9a8b8fdcb6d832da68a9e10d2d28dca32aa905564692b3cf89e382 |
|
MD5 | 1baf4aa8729180bfbdbeb2a9465c42df |
|
BLAKE2b-256 | c339c14d92dc1d22f4d5ef2a5d8f6310c79312de2f804fb8925cfa80525665bc |
Hashes for stim-1.13.dev1702511128-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b573f4901210a8f848ecb9b21719c1fdeff9cb20c1df9fe58ca2a66769d54add |
|
MD5 | e53d4e99a1b2801e66a24392f5b8e2e5 |
|
BLAKE2b-256 | 67fb05521d57f8ae04fb37ac889768c7656523ca9b41669395a8c42756e299fd |
Hashes for stim-1.13.dev1702511128-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db87f133b51627c1ef5dbb3b1ffdaeae0889c5da09cd14ed3f67cde0c98b5652 |
|
MD5 | f9610a105180009c6dc14727fb53fb83 |
|
BLAKE2b-256 | 9c3af766f1c3342cbe4ae67d7dc262a12103b83fe510d5add2a2ca90bd054aed |
Hashes for stim-1.13.dev1702511128-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55d25a8663a68d46f21ed50c2bcd1697f0564b85bf2a4a04a53ffe4067584c1d |
|
MD5 | 088b6b6102fdc9cbb8d257ea55eb19cb |
|
BLAKE2b-256 | 90d5e480ba7fd1dbd72e9e8b77188a6a7941c998371f80708e8461700e1c175b |