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.dev1722409480-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0217bf91d82bad0b1339ed55e2e132e503b827c27b393d7ca9c4d9054352880 |
|
MD5 | 85469bf46e1cebbd68db6cb679057b1d |
|
BLAKE2b-256 | 6780db992916896590436394c237f940c2d86ea104821fe98a542912bb6bdefc |
Hashes for stim-1.14.dev1722409480-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fe11d3860cd4bb341fc408f5d6b94ebc770d987ea3409eebacf0f1e06066945 |
|
MD5 | 6f164dc3daf5b43b620268849a76a992 |
|
BLAKE2b-256 | d1efc9851bf4562ef9e3f0bb62bb7b7e6623244b1aec3ff62d0ae3ae8a620b0d |
Hashes for stim-1.14.dev1722409480-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c847eb162ae423d64612c9e7492313469dcd6a1e741693c046bafc6669d69ed |
|
MD5 | 8066ec54f238e32aab84b8535cc9c065 |
|
BLAKE2b-256 | 9b17a4e625ed106ffbd482b6a95299b9c471155317c9cbd39b60066a4d1bd0dd |
Hashes for stim-1.14.dev1722409480-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a63f59da08489c2dd3c90a0cf6e814f69f8d013d59af72f68febec687ce93a6f |
|
MD5 | dbe1d4d83b031b229a1612a3e83a02f9 |
|
BLAKE2b-256 | 9a25782cc403f9ecfa5b158ba370335e7980ded6a3c3692de42aa78509752b11 |
Hashes for stim-1.14.dev1722409480-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8090d1d049712ebe6ba07fbef1726f1740d2ea305391c58dfd63b969cbd7257d |
|
MD5 | 5edec290d27d8465a381fb107870254d |
|
BLAKE2b-256 | 6da9637b2edf6b725581ea206f7f28b1ee168e6a3f7cc45859bd2b880da7229a |
Hashes for stim-1.14.dev1722409480-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd340669b2717caa9d409e1a3df8a13f88e003ee16201bdc7a0f46f44fd0ce21 |
|
MD5 | 72faa1df2ca66ca69aaf1d16f2e24f46 |
|
BLAKE2b-256 | bf158198191508e35650f66bc008bdef398020c512d60b68f587931bc6ffcc45 |
Hashes for stim-1.14.dev1722409480-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bfb97b283af5a30e0d9a4d4a480546c168e545427ff13d6443bcfa8288ccd4a |
|
MD5 | 0b6d294b303f19f507c807055205740e |
|
BLAKE2b-256 | 0eae42e7caf4a4f9085994b8062840283b0ba361927a5bd72c9761999e5768ac |
Hashes for stim-1.14.dev1722409480-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8adbfb7006a0633c8e3cc90c71c74ef7cb16d9d7fe292967ec29a6701c9e512 |
|
MD5 | 4a7ccf5522d4822b2dccf754944fbb94 |
|
BLAKE2b-256 | 4d7895f05e697ce7f135efdb801743e9bdd79660fd693a375affa89469f019c8 |
Hashes for stim-1.14.dev1722409480-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0139dfd2d0747bed64fc783be2925b1bd2f1806ef96772c288256f9b5454bf4 |
|
MD5 | 32b08a39a83ba4c169e11f1d555c5fcc |
|
BLAKE2b-256 | d821bcdf5efd5ef6c3b5c30a955782be95e3f426b4ac40f106ba901e9be9cfed |
Hashes for stim-1.14.dev1722409480-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3480243255642b40229ecb6b0ed43c1a56c1039865307ddd1897084542926433 |
|
MD5 | e018483f8093fad4764ab2047972d85a |
|
BLAKE2b-256 | 7e610e7e1174d7458da8b51b52bdfe7a59a56d41cddf38d1826c09966eca4ec6 |
Hashes for stim-1.14.dev1722409480-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1946414b095d5f2a4457b1dc59f9eba480d2dc2fb1ba9e06f000eee56a2bc10 |
|
MD5 | f52f77bff4790fb19fe340eca4bbe426 |
|
BLAKE2b-256 | c268eeb6137e24e36aaa0b5734addee194a828662c8bf9a3d1bed1d82b02f387 |
Hashes for stim-1.14.dev1722409480-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907c41732c0f21ed40bc8141ea9ea8bafb67de393f30cdb2d65d6b9540fc466e |
|
MD5 | afebc07ded4160b7b8cf83fcbe1dfe67 |
|
BLAKE2b-256 | a226914a38feb75c8787f2fa28c2240c54f439c602306fa6877ce46059beb40f |
Hashes for stim-1.14.dev1722409480-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc56d815197f33ae21c1c41040b201727b5c91889b6d1cb0993b6f16c831c18 |
|
MD5 | 6b19c6813fb44a6005ae97f5f137f84c |
|
BLAKE2b-256 | db79c22d61d84db01c8cbe484acd6d0d484fc0766bc8c36bf9d5c84c0386be93 |
Hashes for stim-1.14.dev1722409480-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8f060788bee00bd30ab5834a72294ef4dc8a86c706881db350f3406eb513684 |
|
MD5 | ddb7b0d976ca92f5f0d9d0762034ad5c |
|
BLAKE2b-256 | 455852aba93bc401685fb6fda64d7d4073e06f98372cac208e1ede989f4d211c |
Hashes for stim-1.14.dev1722409480-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a7e5db112e0283f27385a0ad20768efe8d71628847954a28fc85a166840060 |
|
MD5 | 1f18fc5c3a7cb52308ae62300143f510 |
|
BLAKE2b-256 | ebac4cea56b1c7bbd9eba247a07145cc8bc61697287e9b0ca0219c5c66ac2a5c |
Hashes for stim-1.14.dev1722409480-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5abcfc54347720eeb7ed7ab3cd94ab3dfeeed6d7cfe9672307e7ef8e0ddb597c |
|
MD5 | 6eb22f136dff590d8e90ddb1103e3302 |
|
BLAKE2b-256 | 6da11d13e4ee1bbf1368a93af52568a8b8a4567518c1c2efb98f1be7cab27df3 |
Hashes for stim-1.14.dev1722409480-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5146c6343eb25f9b0e7df44c69ad16d78f925962ebb27c06ae2a5b8d99d7bac |
|
MD5 | 6610182a92989d79f25c83490aec4121 |
|
BLAKE2b-256 | 886ff776a78bbe3608629dca96b34e57b867cafd095471f83bddece9c15e636d |
Hashes for stim-1.14.dev1722409480-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ee2b906fd7a67bca3459e43866c5441aa913b0663b92b3c6c265992303f87b8 |
|
MD5 | aa11adb438d030e91149edcd01cc3c05 |
|
BLAKE2b-256 | 3a0f269ab78276d7cf8fc45441d902e2678afb3527c4a602fe14e1662a10d68f |
Hashes for stim-1.14.dev1722409480-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2349c2e5afeca5ecf997afc82d341e361291562221a385058eba3732b745d42 |
|
MD5 | c1d470c80bd519fad26c8982db808ae3 |
|
BLAKE2b-256 | ee585f2b229c81d2d7f98b0cc3c96136f4399ce21540a12b1b7aad3906b07645 |
Hashes for stim-1.14.dev1722409480-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbe34abc26af17a0f2a93c9788103bf8595b206f14163a5fa5bd29a41cf64fba |
|
MD5 | 85be0027509003c0df1bd105acd91922 |
|
BLAKE2b-256 | 071cfa072a431c0e92cd4d9f0bb721712dfd4354e735bd08103fb50cb337efc5 |
Hashes for stim-1.14.dev1722409480-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b248cc1b4d8895a35400fb05b5bd2c437353472056f195525800810d83a39ed3 |
|
MD5 | 42417c614bcd898087292f869c976dce |
|
BLAKE2b-256 | 49e9c0e8f7c25533d2c53049ce1bb3eb369beba53b7a94c10a929d4d3ea6bca7 |
Hashes for stim-1.14.dev1722409480-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3bf56d0183a786d9bd81ab2811ebf16cb4b2e463c90b07c061908a563e1323a |
|
MD5 | 3ddd8e5ec338e7ce710d57e38df60c4b |
|
BLAKE2b-256 | cf833a2f6168f1c501ffcd43b56230306f0286a263ec955d556c751f52d9d21b |
Hashes for stim-1.14.dev1722409480-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5e3fd9c8eed41f1e97c796cbdde3a6289a6811c9c4b5749cff57090b4251258 |
|
MD5 | 556136dc00edf75e44b055e606bb35cd |
|
BLAKE2b-256 | 6d5abc3bcf3e9756d54116ae35a3939811e488cdc883faca6ac21f04df5ec434 |
Hashes for stim-1.14.dev1722409480-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4220fe356671fd9e3964cf6c65a90ef6402fcbcf59f8bf81baff6884df0801b |
|
MD5 | 10ff970c55626ece819dfe49444cce44 |
|
BLAKE2b-256 | 3f0f68e644d5919bb14a8e7095eae1f4d80cf2f2c8798bd6da3202b8f63b0ab9 |
Hashes for stim-1.14.dev1722409480-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d871ac1ce5b06133ebc130cc56d6d042d217ae2d5ef540ecd5eac8816c5bcc3a |
|
MD5 | cabb375662636a9f5e8c2e1b3b038249 |
|
BLAKE2b-256 | cfabb5caca6b26cf76f053896056b07a410d6bae6e71c4020ed90089b301186f |
Hashes for stim-1.14.dev1722409480-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6692f0aa31550050795939d3ecf933ce862cf5d4ff1c61a70ff8983f0b88e56 |
|
MD5 | 58c1cce3dc150a29480e401b21d3778d |
|
BLAKE2b-256 | 0d7665fb02f4992de2479bca750a8fb5b5539bacde7c251269e64f6a91b8c86a |
Hashes for stim-1.14.dev1722409480-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6af30765643893c66324d58b4def901e6260117aef5a5261c58241aec86521d |
|
MD5 | cca58db101f4bc2ad1ff23d7b797031b |
|
BLAKE2b-256 | 4d4bf8bb31bf5d5a36c7687fb676a8969f872bc0b90bcddc3b965bea8d759e10 |
Hashes for stim-1.14.dev1722409480-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb9e0710ac934491398d71df3806c1f2a400a91bed0c1c9c01483e8cc8ad82a1 |
|
MD5 | 36ef818e672889fe9151e0445795d028 |
|
BLAKE2b-256 | 3f8a9e4d50ea22a28b56410faaa7425d4db9d04de71877a485eed8530fb7f95e |
Hashes for stim-1.14.dev1722409480-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c93cedf8fa3882a757d06b5c7d5681b68eb4083fde85e3d11292b0fa907657 |
|
MD5 | c092c9fea16953f7c4da2c7c40d05de2 |
|
BLAKE2b-256 | 8bf804f078062cd51087dffa134626d0e98b84697e4f016632f09a7f1836b548 |
Hashes for stim-1.14.dev1722409480-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f926828114fff304155a7ca378ac7c4f7e508c6d8e532033e9a66c22a90bdc07 |
|
MD5 | c0778ea1f2f99429a67fa3c171a36d43 |
|
BLAKE2b-256 | 71e21a8bc71808f06efeaf43ca80a680d16df7694916874d49db84a32cbaf420 |