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.dev1714773685-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dd7d27cdfdaf44e01c57285325dac9b48cf0f02dd95cc666170cc1a49ffb58c |
|
MD5 | 634d6ebbfee729e24772fdd7ede0660d |
|
BLAKE2b-256 | 3fdc9476e465d825ddd7feefedc9475c3a686d24c69151a80024005fa988a618 |
Hashes for stim-1.14.dev1714773685-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df862ddc91353e19c68ac3249232fe6764362b3c8d56eb78baa37e8ef6cb5dd7 |
|
MD5 | 8ef08665e1fd8bef7ac56d793b3413fe |
|
BLAKE2b-256 | a3bb57af15cf7e6a4733b615e486692a64a4460f0b6d3745c761279e11999c3d |
Hashes for stim-1.14.dev1714773685-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8feaf025f66d4f105797b99197d8faac3f09341d3a16cc3caee72ac42f2e160d |
|
MD5 | ffb3b2bf02294ea1a5741d77741fe976 |
|
BLAKE2b-256 | 28674e87efacdd3c3636df41e0c9c0788ec770991f017030e0b4239944192bce |
Hashes for stim-1.14.dev1714773685-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97797380ab623875ea6fea60d3870a71fa4bb3f713c67c200ef9bdd20063914a |
|
MD5 | 9d67cf4ceba40c5d751c6c2fb3049337 |
|
BLAKE2b-256 | f10bf5076e8c5e2aeca2c79ca41ae9cb6a437ca3126d75fb20151a894535534d |
Hashes for stim-1.14.dev1714773685-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dd9df4b969485a6c6c00cb12574327e4101ee71523691b8eb3a53f7729aafca |
|
MD5 | 939e3ab7bcaea145789b575e75ff82d7 |
|
BLAKE2b-256 | aa1e73c5244608c59e1eeb3ebcfdd25849425384b15e91d930035c71ae87671e |
Hashes for stim-1.14.dev1714773685-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51ae2523539a0c4c39d54ee239c9c404e74b5e6c48d8a630e57da0c7a1beed87 |
|
MD5 | 495f4ed6ff2d1b2cd132cd9383b9ffa8 |
|
BLAKE2b-256 | 237340a4569901db431f73f2d2959cc93d7b3cf199934b67e12ffda1e1092fe0 |
Hashes for stim-1.14.dev1714773685-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66637e568efc15b0ffee5762562aafe44fd33f16f71d97b4e0388c56568de69e |
|
MD5 | fc90d4a8bf2dd6be124e6b6cee7b0b83 |
|
BLAKE2b-256 | f0afefbf72695dd921af90c5c94d3aa53e46f5f0d8ce23ede4c58a31d4e1734b |
Hashes for stim-1.14.dev1714773685-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea4c3052ebb7a2698415da8851da05551711cc2e86ee687011c1321d5b6b9e1 |
|
MD5 | b4f2f71564baddbcaded049a71ac0487 |
|
BLAKE2b-256 | adbddd4059f94c948281318747faad1f79c05519debb1a24b02a6e8a0d535fb1 |
Hashes for stim-1.14.dev1714773685-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10b45f46abdcb3461c10486d69761cd2d021513129671f0c1a7c663a8de50289 |
|
MD5 | dad756017fe7109c2071b116c8568f50 |
|
BLAKE2b-256 | ea92b67924b8444fb8a9257b568f680b0a7eaf4ca955d58084f8b298fe6e6a48 |
Hashes for stim-1.14.dev1714773685-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0befdd16bb858e6889d2301a917d2d56748e30723688c6def0967fda0f21a9ef |
|
MD5 | 66b6adc3f3b662e28f454a37299bd030 |
|
BLAKE2b-256 | 2133b036775406d588f725e9b645c1a3acffc4595c5e973c019a4405a57fb6e9 |
Hashes for stim-1.14.dev1714773685-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c06c02a2cfdf717b0325effb542e674534cf52b621c2ef710ce6130c17f88b36 |
|
MD5 | d5a33957b3282ba6ee0397ce488ec04c |
|
BLAKE2b-256 | 44bfb3b74df328462ae1949f8fe479896f9cfc421ac77d7fbc9ce4188035c6a5 |
Hashes for stim-1.14.dev1714773685-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f2c7ee74018659dac8156eb37afb7a764d21b625aca3b011bc9e67532c1542 |
|
MD5 | db67d4211ef47c30e3cb57ec1fe5dec0 |
|
BLAKE2b-256 | 1f30b6bc67a343bda03ef2e7aa8e67457057b55df80ddea8a4271049b41cb7e8 |
Hashes for stim-1.14.dev1714773685-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85468dfa5ae9d6aea05159b15a6309c0723d50931325f7468810e07ed12cf4b8 |
|
MD5 | e73f096a7521c5e8e8c0455e6b1a0f7d |
|
BLAKE2b-256 | 0fecc6a7a84a04102e2d9b479a703e6ffce6021a6d58b4bc4a5e6a81cf44996d |
Hashes for stim-1.14.dev1714773685-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d128dc3ffb13ac28ab2102438aa98fea74d4bf913d24469d7e5a5288f8d5c6b2 |
|
MD5 | c549a2795cef9ba97ea22ac8e2b0e3b3 |
|
BLAKE2b-256 | 7ca383cb9c14da54deae5ea9b86e5e6419ed0fbaaff5eb3ad94311379cc99dee |
Hashes for stim-1.14.dev1714773685-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81536286fd5b3712246cc2ff87e4d3501a0fd91651c02699f57fd12ca4f75be3 |
|
MD5 | 92a62285c92401267024efe957b11f2d |
|
BLAKE2b-256 | 159ea6b6f34a6d9198360b2d80ed76bb087928d7d4c894d0a9cbbaa5ac28295e |
Hashes for stim-1.14.dev1714773685-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc4f3e4cccc4828ee0c512884d8fe8d56bd515498110ecaf3e510d5042acbc6a |
|
MD5 | a75fb5553125a97ec459795828e67ec8 |
|
BLAKE2b-256 | 78de48def6cdb91c114e9a09594532b4d290a80ff2351b620c1b61354faea7fd |
Hashes for stim-1.14.dev1714773685-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac29f376d028b9a33e4b8bf4429330629bc205efdd5b213802c5d89b75af3a0 |
|
MD5 | cc4ac9948874f12462b573d7c7ec7eac |
|
BLAKE2b-256 | 159beb0a5e9f997d38724b1e81d0b0d2e2ea55e97f2c74e10b2d314f28861f82 |
Hashes for stim-1.14.dev1714773685-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9a2bc9b272635934e03bc6e1310cdb6f80d94ce42e57743c4e36f1bffdf29b1 |
|
MD5 | 9cf43f1571f9c6078ecb4f413c07f74c |
|
BLAKE2b-256 | 1f530522fcfb6872121d6b4111c591f90417c7fc2fe84ebeaec6e123a2efe039 |
Hashes for stim-1.14.dev1714773685-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3386cfac3b010432ba9980ed90b8ad152f8a77a79a9a5271d08c1c79d5fd37e |
|
MD5 | 10255ad3b053dd5d33f3ede6f87dc53c |
|
BLAKE2b-256 | c7f87c68a620d1d337444a8894b5b7f8d99f3cf624c165620c42aedfa51f8106 |
Hashes for stim-1.14.dev1714773685-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7962dab4ae1e94d6b4f23a4348df653d062177208f105d21804cabd56b83467 |
|
MD5 | 35299a9f4192f9feb5dfcf989ff1dc3d |
|
BLAKE2b-256 | b28240fc50bb9678bec8297db9582a19d4a23d0c0af1607811460070317670dd |
Hashes for stim-1.14.dev1714773685-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8476614efc9ba714f958c34c0ff78187b6b172cbf67562da4f4ef193528b66d |
|
MD5 | 9038fbcdc497313cba3a16b87b235baa |
|
BLAKE2b-256 | d6d4cd7b1c4a36d0593eb895d653454f643b48de209e1156a08d52d5edb62b5f |
Hashes for stim-1.14.dev1714773685-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d79aed1ab1ae67974ae3bd610a971ab787860255fc50f90c673a09b59d936ecc |
|
MD5 | fd0e748f64e05555ab7af4cd4a9ea789 |
|
BLAKE2b-256 | 984a8eed9af14b935798fdf2f17ce1f044e0a97d1530b80ed4f1f61a69bf2f53 |
Hashes for stim-1.14.dev1714773685-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ed3b0bac76009339325969200c3159e50e11ec796d87b077406392c35839c62 |
|
MD5 | c88d73e51c6c5c470a9b01d1a424bba6 |
|
BLAKE2b-256 | 409c0fbbe0af0baf4ec4eb1d89197c77f350c41f8398e9b18b84dd53bff8bbdd |
Hashes for stim-1.14.dev1714773685-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e755068d6aaa3566aa74ada0e3993ab0da72d9a6b87707dfbe3421260367c989 |
|
MD5 | aa647eeeb1c9f8832811f4239f8063cc |
|
BLAKE2b-256 | 986d1573aa74f775ccb3bfa916ec4bbdd2e297731eb72572687aa0b05f49c2a0 |
Hashes for stim-1.14.dev1714773685-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c45ab46278428e343b6fe1d7815a5f3673dea10bf3adec5da206341e9d2bc0 |
|
MD5 | e038c3193067ac693195fb90a0dfbe30 |
|
BLAKE2b-256 | ef08f9a87a9c079225f20694ee81ac6da544239b5d049496f48926429287710f |
Hashes for stim-1.14.dev1714773685-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cf59ddd772dff9bd976294a585367ead870a26b982845add923d55f9d77bdd4 |
|
MD5 | a555971a0f0097c0095f27cc46a69e43 |
|
BLAKE2b-256 | 9c6f9872b4b65f5957012fe7ff8d29573afebdb05fbad68031573c0f934e558c |
Hashes for stim-1.14.dev1714773685-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7bf6c43b60463c1e0833d05da21046a26d5373080becc3d610b08c27de5a38b |
|
MD5 | f4f050054c34849ae7d917d59b07b7a6 |
|
BLAKE2b-256 | 4759553f2ee3cfe428e4113659135f7d49a65ad92ae3c98ca89dd1665a939e8d |
Hashes for stim-1.14.dev1714773685-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7e1d2e1ed798d3435947043d78a4a7c21f4578c00952851033eaa204377e7b5 |
|
MD5 | b0b814ab00c09add65a07080e228375f |
|
BLAKE2b-256 | f92959e3669d06d41f62350150f0aa55f970967b1b9ea671ed748dc9896fae36 |
Hashes for stim-1.14.dev1714773685-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d458fc0fa03f34b9bc2704f1d29eb83987665220eb41074e52f8d9973c0f5008 |
|
MD5 | e9439512bf14515f64a5d1f24cff8329 |
|
BLAKE2b-256 | d6829f98f10055907a979e8eeccbc778228851ce3bc94be2560783d138b69ab2 |
Hashes for stim-1.14.dev1714773685-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2ab102084c2341d64ecb09c15387c14d50d604ee36701dab9e91b69cb7cb8a9 |
|
MD5 | 5afc0d4fb76dbb5c3efe15b5747c38ba |
|
BLAKE2b-256 | ca9f2e4299a8d286f52bcfe9bc57eb47bfa0fa713051a63655384b4f5ae6e84e |