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.12.dev1690945293-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb4e52ac83d8e64d0348e034030a22aedce33f8027de3d63e7f53182ac2c7198 |
|
MD5 | 4973870db71bcbc82b1202af6b018098 |
|
BLAKE2b-256 | 68a47cc921f2f5f355e76fdf25048ccbd9e4682a00dbd5d7b6e0b2de8a47cabf |
Hashes for stim-1.12.dev1690945293-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68038a960fc37b5bec1702b3aeed2f733418f01f3aa54b4fa0ebeadc0dc86c4a |
|
MD5 | fef5f12b048e4a9edc04b476f35044da |
|
BLAKE2b-256 | a1624f63ecf54e9db24a5be72859ef4be45e9b86547a75b77f0566db0d5558e9 |
Hashes for stim-1.12.dev1690945293-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2242f5cc4e03dd64f76b6df8c9b2d73a369c1924760a0478a1d4e81d44b6574c |
|
MD5 | 69003b2f6da0ea8a7af056954c9f3d0a |
|
BLAKE2b-256 | 0405ccac4faff1d227af5b09ff73262ebb03ae54afb5fb0c86d6cb4c15ab8643 |
Hashes for stim-1.12.dev1690945293-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1281d6dfa33b9a0b135bea89d79f2d9ac331253c496c22f3eeeba5c0145f2be |
|
MD5 | 336574b8660ec8f1455d417ec8810286 |
|
BLAKE2b-256 | abfda4f81e9de1dcf45bb7df43dc4913285b003c1e3eba5e0bb73f42eb7431cf |
Hashes for stim-1.12.dev1690945293-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 636809e89fbceed6806c736f828d79f55a39efbb9c9b1298bbb062173011fa27 |
|
MD5 | da6cdb965489d4cd71963dcd411b2258 |
|
BLAKE2b-256 | cfb79289c028211368d4c4007ce8c3643f180c4424f3a8c59ede514fd06f7520 |
Hashes for stim-1.12.dev1690945293-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32f603c72899ed8d543475cc34b49b0cb858cc4f2e5e26d723cbe15556158c7b |
|
MD5 | 6cc28c1bec9f22748cb3f36768995e66 |
|
BLAKE2b-256 | 855004f3762ba34a77a8ca4745981128d28bae9d3ba52894fe63e3597b9b5c23 |
Hashes for stim-1.12.dev1690945293-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34169d6008e3a8460dd4295bce32af6a04e6c4e3a5ff9458eac0a49e15cbd3b0 |
|
MD5 | 08f72446d13a875ac0d86c9633636cfb |
|
BLAKE2b-256 | f2849a7d0b561dee581fdcf3e986d20b1a3a7ef91176964beaa96ee1634e22a7 |
Hashes for stim-1.12.dev1690945293-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7471d6222a0263949d60928e7e0b307e42e791ffda0d28ebc673ba59755452e5 |
|
MD5 | be2bf2fc64dc8d3743118af9eb2dce4c |
|
BLAKE2b-256 | d151dd286392206fa117874eea473bfcc643c6f8b6634534856852e4d835e526 |
Hashes for stim-1.12.dev1690945293-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45b2738d002c12c50658e8fefcee366b4250be8cb4922f6fb835ade535d55f39 |
|
MD5 | a79fbe4b4534960b75d521c225155697 |
|
BLAKE2b-256 | 953eb473e6a3289834524459c9c84a70e031d4f542ad0bf1b26d2f4d59733e74 |
Hashes for stim-1.12.dev1690945293-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25462190152beaf3f0414931018343de1667e30f034af09bf962fd0fca20fc1e |
|
MD5 | 688aabbb9ed7315e9696195551fa7bed |
|
BLAKE2b-256 | 9065f4fae9ca5eb861ed5dadb30a71c66306363c3df24e11db08ae49688e3031 |
Hashes for stim-1.12.dev1690945293-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2522035f58169310642942178d2b0882bef07a600964f204f9d4dbb43ed9265 |
|
MD5 | b6306faa5de9ef5217c06de01cda29ee |
|
BLAKE2b-256 | 0f675fc24cc41ba40f9f4e7576442cd8db790ce235ddc136c211a83f3041f15e |
Hashes for stim-1.12.dev1690945293-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d1a92b47704d092641cbe79f77bf9be5bf19b84582226e309881f8609372525 |
|
MD5 | 1e6dd6b15cfddc3aa945982de131e041 |
|
BLAKE2b-256 | ebb377a94e782d5c0542b9147d59619423ec25846d0073e2999d5446a2350b6e |
Hashes for stim-1.12.dev1690945293-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7fdb95481bcace2834402a6694467b204a6587e1a20b347e914b6da44019104 |
|
MD5 | 842115b31a7d4648ac5f0573fd616741 |
|
BLAKE2b-256 | 4eeffb3c1742978df4f2178f3a2dc00da0c3c61e4f65bc156b67a3aac3a43c3b |
Hashes for stim-1.12.dev1690945293-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2213fccad5f01d989b6470ce042f1c20a069ac6727cbba3e37f21b708eb5fd7a |
|
MD5 | 4254d4a1711a12d1a6f543eca78bdf9f |
|
BLAKE2b-256 | 5dfc5e5209d0f03aa3a45cf9b3a9a8718a2bb0f877c2346db714f692aedd1d46 |
Hashes for stim-1.12.dev1690945293-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1698e403b2b8972b220fdf7f549d4ee22933936abf63d1a2bfcba1f1fc4d997 |
|
MD5 | eda3d84127071a66dc9dba9d73f5a49f |
|
BLAKE2b-256 | 1bd4a00e7cd2b0337e7a9583bdc875f1dc7be69f39f6284f2baeab54731ef362 |
Hashes for stim-1.12.dev1690945293-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d275e30a9931a645e7a893bdcd86b50df83f5fcc1c1f132ed7cb5a5d1f95e3e9 |
|
MD5 | 1e328497ec7a1b759e450fd5f4d3af75 |
|
BLAKE2b-256 | bbc2ce0ac4b017588573f86c0883c2a4df135b25378f45a69f1d79bd8a50da07 |
Hashes for stim-1.12.dev1690945293-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20fa44bcf5174fb5776d0f5cac9f1df0df2d77bb245c5be4a9540bf3a00b625d |
|
MD5 | 5c648821b4a3738868e3d4024b06c0bc |
|
BLAKE2b-256 | a1ab21e50295805c7b2c78a57bb62fe1e0f02bf458457912b5f2d687bd45e1a3 |
Hashes for stim-1.12.dev1690945293-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3981739bd9b222468d1d340dca394ab115f44e231910a68372fdebcf7b4b13d4 |
|
MD5 | e81efce206c7ecd2b497bf7b682b91ca |
|
BLAKE2b-256 | 36af1cd615c7d95bb2c68138add90e30f6cfee62b8753453df214412c3093355 |
Hashes for stim-1.12.dev1690945293-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f67eaf9d1fd59cfbce110f934178856e9b9408a01f71078f528c678a6478384 |
|
MD5 | 3ecb3a2174b80f7920dc37d8a38533f9 |
|
BLAKE2b-256 | fe936ef4970ad3b0994944e6b870a76a03220660cb481724e9c95f6f5001f68c |
Hashes for stim-1.12.dev1690945293-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f547dabe0eafb61b7515339894e05b0eeaec1eaa782e89fdf5869f664a69491 |
|
MD5 | f97e1f4a471b326dc933ea60a9edf228 |
|
BLAKE2b-256 | a143967c1cb1a8b4038bc4c9808e38cde0070d092457bb21af6147da43557c3f |
Hashes for stim-1.12.dev1690945293-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eedd43c68e27e80e44e0797c92b4ef92944761bb38ed975d891a8f8f8129ca8 |
|
MD5 | db7834d122882331c14d35b7b14892e2 |
|
BLAKE2b-256 | eff3e4f52b60146af72e756d35d06a68f73f80c67cebbc054d46f3685962cb8d |
Hashes for stim-1.12.dev1690945293-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aad6015f44136444acf21ac48107de481b1a280523e85337eeaadf88239819e |
|
MD5 | c6e5129e28ef914fb83f21e14af7257b |
|
BLAKE2b-256 | fffe1a09337c58d492a891bee3cc0d74f00b396660e34ab2652f700cef2c3bf8 |
Hashes for stim-1.12.dev1690945293-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f7c4f54e5052706c64dabd71d556b56e9103785963aa8d28f835126b97fe1c |
|
MD5 | f8d24fff8eec8b8a54a19145ab11e885 |
|
BLAKE2b-256 | 6279bdeacdfbefa1eac64550900986727d49ba5d579a485d70ab332d45cae5ad |
Hashes for stim-1.12.dev1690945293-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56f0ebf0a1cce73bbcb9ed9172b7b52b8991d7661a1e589ff5370007e6e1712b |
|
MD5 | acf29c9590b3c2b82370d47980ee15be |
|
BLAKE2b-256 | 98013b2e6629fdb1a1f8da8d83219abf73fe55af64abc9dc3ed662a245d8d41e |
Hashes for stim-1.12.dev1690945293-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989f2833661da4624a31eeba275e026dc985840d2a8b88765bf91db408c1f1bb |
|
MD5 | 548473e08d126c6f058a0b855c3fbd9b |
|
BLAKE2b-256 | 34adf3fd15d117dbff5924648944ec4cfc449d67b45efc5d2e0f91d192e3f8e9 |
Hashes for stim-1.12.dev1690945293-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61c618b65c46127d9c6e7e2587d309d2982d585b17f9679afd34582cd640c49b |
|
MD5 | 68a71a0e69c28ca6eab10d5c142b0391 |
|
BLAKE2b-256 | 7b41468f387544b065a80b21e44ec8acf63239444d851bfbe679a413610452d0 |