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.dev1721777478-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e472a7e7459c7b8266f93e3ae3fc9a9bda614d80cf4cb5a7630bea444e9e9ef |
|
MD5 | c33ac10e8a80ac093b5014faeed5753d |
|
BLAKE2b-256 | 1cb0b43fedd1c7263a2e218bc381f57b1aa394dcac37bf6082646d9865fd09a3 |
Hashes for stim-1.14.dev1721777478-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97820a0d1626a5f98683903fc176899ca816237ba0297de6d15e4a41a32c3814 |
|
MD5 | a6399bed79d45862eabe02ee6718ae77 |
|
BLAKE2b-256 | b1e000503feb7e73e4dbcff90e13a8b04841154dc8d2b207f1e4eb28ce02cc13 |
Hashes for stim-1.14.dev1721777478-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc418c4db0bd16bf645e411ab0ce927e55f8a8fa5cd96c55157d4eb50957119f |
|
MD5 | 7240cf4f76764376cb6e5d3e6e79b112 |
|
BLAKE2b-256 | 8d3dc0770991a19ec6d749696ac8055c7b63edae1fbb550454752b6a05981f45 |
Hashes for stim-1.14.dev1721777478-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f8e266df51a09d7f6d5575b257f911a1e4ef7dfd056a59db06bf5662383b7fe |
|
MD5 | 4b2e43ae3eb7ec714bd07379103ce787 |
|
BLAKE2b-256 | ca3f3e3bcc58b1acf7bb3df1a470c9075c60bfa7450059d746ba0f3632d0b2ae |
Hashes for stim-1.14.dev1721777478-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79e16d3460e22dcc93fad52e39058b4a3b1ccc7135be041a429f680da11004d0 |
|
MD5 | e1925126710dd1a25a653d2454875df4 |
|
BLAKE2b-256 | 78254bda016b0aa517c9c09ea9cedf1592c207272e7e1768cc0388ae3fdf0e3b |
Hashes for stim-1.14.dev1721777478-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66127f5507b71382dedd120961b5769c243c2741749dd179aa5066c29c0ba01c |
|
MD5 | 08db66e37b8ee16ce7c1cdb036bbe1d0 |
|
BLAKE2b-256 | d03cf1c4c274af467a65f6897c1b25ea0e59366c54be1705b1138ef97229ac0d |
Hashes for stim-1.14.dev1721777478-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a18cff8b5bfec5161b36790e81de6dc1e1f37ddcb07d26ad43c42507180e6e70 |
|
MD5 | 87329004054c675441a072a9f2c914e1 |
|
BLAKE2b-256 | 64073dd4ad9985c285e27b47f19933cc110c907cbe5ca241e5ea2c89c80ccd4c |
Hashes for stim-1.14.dev1721777478-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 338cbf21c6d831a9d069c1de75f1ebfd6cbe784e4ab2bc5cd16c7e9f02f29c9d |
|
MD5 | a253cff9270d410033827264b5221cc8 |
|
BLAKE2b-256 | 9d08bfd75e290e7cad80f5919e104e85f9e943b51bbe93f0a95b006e5b566eb2 |
Hashes for stim-1.14.dev1721777478-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c828a923fca98464d4381eda4baea29fcd6705fbf5918c1f3cafb36dc9d6123b |
|
MD5 | 7e38659382ef05dbb7690860422e7665 |
|
BLAKE2b-256 | 1166577b64ab068b2c5f9047995c7b010c8b1a7322c561c5b191a3f8d894fb3e |
Hashes for stim-1.14.dev1721777478-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c89df9dc00395e53465589ad4512238b22bb11a8b2afcce345dd25de8700217 |
|
MD5 | 73424664f06abcbc9d5ab091ba2ea90d |
|
BLAKE2b-256 | 5a129d8f2208ed730a9c459a7a9f93334ab48637f9cf8a8eeb2fb123586f5f9f |
Hashes for stim-1.14.dev1721777478-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3755ba7af9a316d40fe39475075f4a44638fc60836028b7f8283f73e3b002045 |
|
MD5 | 31dd50fe22b323974f94f8d5df5e9003 |
|
BLAKE2b-256 | 93b5623dcbe39fe4b337d426774a4643cf9aeb81ea582b853ea135cfc783aa04 |
Hashes for stim-1.14.dev1721777478-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b8b3b989587cb04f60b496735977b2fe725eb633299ce611e1f851b63fc1c68 |
|
MD5 | 02bd0c8337bf60be3af2bbf072e5c96b |
|
BLAKE2b-256 | cf6a823a58613ffbf095774ae33600451f553b075bb86157b8893e36855f435d |
Hashes for stim-1.14.dev1721777478-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc3280856e11c641f550b34b03fe3696821ca962145d911d59e91ae94dcbd83d |
|
MD5 | 6f2846e20bdd3381672938ea9493ab01 |
|
BLAKE2b-256 | 853c884ce3a03c6ae4aeb6e05f3e768958efa51ffa76ed700e3892223dd55960 |
Hashes for stim-1.14.dev1721777478-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4a2d872d052160936026bbd156f3eaac289e2487db961252f00680ecaab0003 |
|
MD5 | 1cc3acb0d46b55bc1173fe39e460757e |
|
BLAKE2b-256 | 46a5ebf4560b0923789586bb9ac4a580f99ceff65389b5ba683bb2a9aa67ff6f |
Hashes for stim-1.14.dev1721777478-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9183b1aa5fb044cf1c6b510067de27916810c67dd0b2fcafe7d13e1f0eb8896 |
|
MD5 | 65bd295c87ebc38e36c9682aa87aac85 |
|
BLAKE2b-256 | 2055eba826734709538be8bde84126db71e0a3b46f6bc4b11067012006169183 |
Hashes for stim-1.14.dev1721777478-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85633b00c652c9ac0750d59060c0a971a0b1bf44ade45b5e1237129a45241d1e |
|
MD5 | 47e141b88231622d672486e281f27844 |
|
BLAKE2b-256 | fd1c62d7c0f9e1784e9e92f81e1dab9ee6e1c064c5f3c7b602b18750746fa391 |
Hashes for stim-1.14.dev1721777478-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 843277012868458b2ef75d2b93d055c7a955d929509597e5c686dd19b409e923 |
|
MD5 | 6e52700f8eb8bd08eceac434fb0a16fe |
|
BLAKE2b-256 | 17df189e1c8961e0be8dfccba5a226870d1ce84b9f0d10e1af88c3fb1145bbb9 |
Hashes for stim-1.14.dev1721777478-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fff416dd6bafd7476edf9c54d5d9c5246aec3ff3c3ac96ab90f1f4e3a3d0f565 |
|
MD5 | dbf7e507251f425b20a1cb34b3b305d1 |
|
BLAKE2b-256 | 3f0c8aa09d083285aa108871d014d0c932b8f981a78308a7f56fe41dc49a1de9 |
Hashes for stim-1.14.dev1721777478-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb1e0c3fc96b6f20024c9346e35219644f6096b1641ab3abf92e8b0233404d5 |
|
MD5 | 1060b3c7ed5a12b0e5fa1e3cdc90b419 |
|
BLAKE2b-256 | a3601b5deb2fc867a687b486e6a592e8109bd72528611dfa3968686bf219b04f |
Hashes for stim-1.14.dev1721777478-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b1b5f195cac60ae7f43f949ae4b59e3ea6ef5aff605439fe00ca0e136f8bcb |
|
MD5 | b7000064c3e7367a4b8b89d032b97ba2 |
|
BLAKE2b-256 | b712db67ff1fe9abeb3e03b25b71af70594b43929669d3f56158d1680cadaf1b |
Hashes for stim-1.14.dev1721777478-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d97f909f618aa2bdc85755c3eb3cb662b72391a7930ea1542ae0e977fe730171 |
|
MD5 | 266b8987aeb3ede25a7225d5eecd9bc8 |
|
BLAKE2b-256 | d89222035ecbcb62b2dea2c6d47ebb593c26708752d5465f7768d9e85ed704b6 |
Hashes for stim-1.14.dev1721777478-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e466e38c781024ee6de67434d91043dd74229aea4cd7b383e1bc2b32487c9f75 |
|
MD5 | 830178bbf7294b12f8f5250f21cae0e9 |
|
BLAKE2b-256 | 793fd77438264b83f8c447bac6361a6e49b587b2a65900bf52b42827afb634ea |
Hashes for stim-1.14.dev1721777478-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a81636d3a079a920058e82ebbf6f9a8ba90d24fabee5d89d5ca0e61c2411378f |
|
MD5 | 3d3e269bc67e186b30c1a2a827cbada6 |
|
BLAKE2b-256 | eab02bb2d5dbb64742f6e0c315aff3eba7615c26eba9ca16749a8896495bef34 |
Hashes for stim-1.14.dev1721777478-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0fcf1c39062d328eaa4e12c16c7b62d1c0765560b39b31e7927f4b643390b56 |
|
MD5 | dc17bd8b26127f1c488bd99af84f79bb |
|
BLAKE2b-256 | 079ffc869a4f8a74ffed386d514e286f24893590bca5f033ca055470fa91394c |
Hashes for stim-1.14.dev1721777478-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c59de733e60cd3483f64143593d2c9843aa202afd0b19b76d35fc71a15fcda55 |
|
MD5 | f233d0fee04eca3d3adb79081c9e1c9f |
|
BLAKE2b-256 | d7606ae1ebb5df610b95851d690d05b2b39caf9d5da78783045faa3ee3d3017a |
Hashes for stim-1.14.dev1721777478-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f736f7c02b9187dd3f055e606740d7740a02220d4dabf6802982110004e22f9 |
|
MD5 | a0d9513080f9668fb23db0c066ec9b67 |
|
BLAKE2b-256 | 453bf6d06653761aef64e200112aef75412939abe47b76ac32c0d114e391addb |
Hashes for stim-1.14.dev1721777478-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7fbea90b8697f998da3f99eeac1ae5a39cf254ec5a9df09e3ced249348bc8da |
|
MD5 | dcca123ddabf6cb0e5ddc07e16997ec7 |
|
BLAKE2b-256 | b3dfbd2c8a6e8db1750faf2ba0d4b8469862a754e9ae80c3d0ef3727c91a627a |
Hashes for stim-1.14.dev1721777478-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aba8f60d57fcf99034505a3df2dc0c2234b5cd6fd23d1f6c4f555fd4ee9667a |
|
MD5 | 432fc21e35c2f23ab81e32645cc878f6 |
|
BLAKE2b-256 | f8624460c2d0cb2328d2580f8b85b175ae1d6e8b69ccd45a55dceb206226e1ef |
Hashes for stim-1.14.dev1721777478-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ba0f1b481f17a12c522786c942d219c9445efef1162f4c1fa3308245f2eb37e |
|
MD5 | 5d139af102e7f4528b0be9e69ca587ac |
|
BLAKE2b-256 | 8cbaa56d4bf76fa1d3271934a4aa3ae07ed2b68903d4b912dbaebde47328ae42 |
Hashes for stim-1.14.dev1721777478-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ff60b04619280c8ea6b431d90d211bc6cb1226f07bb9cb9b8af5c1dc6939cdd |
|
MD5 | 10432fcd254ed4b7b8534f664cb3fce5 |
|
BLAKE2b-256 | 23c543b43c98a18c55be2a6b3fa0cab085f517ce8d19818dd55a901eb8912db9 |