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.dev1710720884-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9acbe0a7c2645333c1c2cf2c1a4c2c7a81e23b8880b2e1f0310a552934fed42b |
|
MD5 | 5cdf6e8f5dc261725525784ae46836c4 |
|
BLAKE2b-256 | e96066749232d5f4af695b7bdc2260234c6954f179dbf51515ca64de8c5b0087 |
Hashes for stim-1.13.dev1710720884-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0501ce7739cfe3420e9ad9476a08e85d277ababfbe13753369523ba163632a6 |
|
MD5 | d710843097b7a7691909dff2109a8b98 |
|
BLAKE2b-256 | da0adf2eb43051d11d9bff8b8d860345831448897ab70fa615619f20fa4ac4a0 |
Hashes for stim-1.13.dev1710720884-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb03b049b61b4fe824b6570afcfed8d8619716356284a01086aeac8d404075b |
|
MD5 | a51ad6b3f9d3e4af3726a876ff1411a8 |
|
BLAKE2b-256 | b8e657fe9f61461a6eb5611bb31b67aa22f4f0ff36b982c8618a8a840a25a35d |
Hashes for stim-1.13.dev1710720884-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd169c5aaeedb1057a3dfc316b96c91eb527007986a0505dbd7064adb977f458 |
|
MD5 | 48de71b0d7eb7a9d4cbbf68c14ab3c23 |
|
BLAKE2b-256 | b936356487c48d29e117631aef3f6893339d0eab6195bcecfbfc844c96a53070 |
Hashes for stim-1.13.dev1710720884-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9fa7fb0926f702744efbff2b7a5975ff678572bee1c5294697cb7d89b630b0 |
|
MD5 | 304ca5b2f2369a078c41e8a74946bd9d |
|
BLAKE2b-256 | 798cc5ec944a366131a8ee53b6c833a44f21500e96f5c26d59e87ff9e4d0d223 |
Hashes for stim-1.13.dev1710720884-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90d93d62ece9c4f29b3b3fa63ee815f3486cfcc7015a6ee18d9a3fe545a3e4e6 |
|
MD5 | f9ec6089555151c50ed97fd4f05057bd |
|
BLAKE2b-256 | a10e12aeb1e7da24817ccbd954c20fedde59c0d76091497c78dbb148d7617a65 |
Hashes for stim-1.13.dev1710720884-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2339fc6e1a7667c6548ee9b0a035d00f42480c90ff385c342374e0ffa7d29fb9 |
|
MD5 | eeb12ee01eb09e3bdd5f4e7bbf4a996c |
|
BLAKE2b-256 | 68a8cfb9a2e3044de585abbb73174c2928f69882ca11bfb331dca28cdaf2364c |
Hashes for stim-1.13.dev1710720884-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8fd3d483dc8bf04bc0c7cbd35fc8d7c6cee6da88515c5a38e67a7846fc7caf4 |
|
MD5 | 825b4792fc5989858f819f6f23795ba4 |
|
BLAKE2b-256 | 53d626076d513283ecb89ec1860916f022786bd63113ccb1f90970e928ab2d07 |
Hashes for stim-1.13.dev1710720884-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c851bea59fb45317eddec52db5ba2cec407555c4517f9d75dab05b04780a1141 |
|
MD5 | c7ff8dd9da8f926a3943d7ad36cd04ea |
|
BLAKE2b-256 | 18a3011f12ea8acd0a692473bd538cd40923153af237f4b36270c4ad6566aac6 |
Hashes for stim-1.13.dev1710720884-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ce129c92ce93e0356124239b99bc2b0ef640698f601e7af51c54ca1b1fee1a |
|
MD5 | f1413b0224c10af9f5c0e7fc67204fd5 |
|
BLAKE2b-256 | 6899c135455596d89e579acdf34045a163eb747ab44f8efea7f87041ef026159 |
Hashes for stim-1.13.dev1710720884-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f764ae529f75f98932147ec9515cc8cca9be834dcec44422829ecdcdaebf8fa1 |
|
MD5 | abbf2217c0112358ace2abb7fd5d9e94 |
|
BLAKE2b-256 | 608adc404a8f092601dc8da979e4428e59880138b3cee99d076f3f256f7a1e32 |
Hashes for stim-1.13.dev1710720884-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06361d0614ff4c76549bb206356962d0cb67364344886291fdb2963a08b1f5a4 |
|
MD5 | 243929bde9e0c007b34f6444c6126f3a |
|
BLAKE2b-256 | 615a8cb4f456b7e0d2bf1014d3c9752de1898ba70a2c59d0ca2c3abb122be29e |
Hashes for stim-1.13.dev1710720884-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92bef29f084b2da119f8e69b531f15ebfd857368d305e89da719cc333fedea63 |
|
MD5 | e90d05172024ca1c83d785265473bcbb |
|
BLAKE2b-256 | 1daaa40f2910acad44226421f4845c3285771432e04de9dafc4fb41dd4d4fe32 |
Hashes for stim-1.13.dev1710720884-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36fa19662eb9e3ae5c008faf9863ac6e330c4dde2d8ea9af59dbfc3b497e126d |
|
MD5 | 594cde20850d312e600dc24528ac5fb4 |
|
BLAKE2b-256 | eacf99a2970c5c5a51ec7370b519a67a3ad45d87a8592d02b7b1582c84ff34fc |
Hashes for stim-1.13.dev1710720884-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c7fe243b08fd1746e14ea241852c90f4d29314a2e41103f3ecd3d450215e659 |
|
MD5 | a4e65e52c12b8180e783661bd5f893ac |
|
BLAKE2b-256 | 1d48a4adc50aaf6f169bfe498c5fedd682ad300185789ffbaabfde27b55ba3e6 |
Hashes for stim-1.13.dev1710720884-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d31ebaa46e6033b344d4e96c7275f2841557371a2511be2e54aa76861692cdf6 |
|
MD5 | 0c8625bb44ab62b4bfeeff67cf4610a1 |
|
BLAKE2b-256 | 6955daa63e9da1fbcb218df798d7a7f68d4810f68c9f7b9619ee2a6ee9d28d8c |
Hashes for stim-1.13.dev1710720884-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b91d10f247422c295914746c5424e01924fd22b66c0cd51b4b8c96b38a0a8106 |
|
MD5 | 845976e56318d0e4f014059f1a0c0179 |
|
BLAKE2b-256 | 8b50ebfef0b8cb3bdb61da5399ef82e5b7f0fdb40be8e9e76b7b1d5df1098b8a |
Hashes for stim-1.13.dev1710720884-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd684730bfb1953fa610d282b98295d7ee9c9be36d56f91ca603ce7f25762237 |
|
MD5 | 3ea1061dbddfa13914a8e4a1652bf455 |
|
BLAKE2b-256 | 4d744c6ba16183e12d0ca92c1c036bc626201984852bc807e94a6d57f18ac015 |
Hashes for stim-1.13.dev1710720884-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 642ba254a9776256f941a212f102b3a4eadd6feb18ce602f2b6cfbcfe9fa1ebb |
|
MD5 | 6fd81790966d813abd0bc720a08dfb30 |
|
BLAKE2b-256 | 83ca8e0b5083a23fb08dd0f4dfa6e5a9dab29ff8c74446d4cd27bb4a782e3f85 |
Hashes for stim-1.13.dev1710720884-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b189fa9dc573379508d7e885857a02e8d58f94226d6ddad19edbcd35ec854467 |
|
MD5 | f12dcb0fd6a57327c2cb1a7f01fc9188 |
|
BLAKE2b-256 | 9ea80703ac1b0b2dbb4bef4c2986eb612c51042af1fad93096fc8719fcece809 |
Hashes for stim-1.13.dev1710720884-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00005467b2f93531d8ac296075af6c2689873bc26a4f8203e0ff4efbd40e2a35 |
|
MD5 | 964e35e1812a83b5533352442fd82d67 |
|
BLAKE2b-256 | 8cb8103b7fcee3a0577763a21715d83a34bfbc6ad64f7690661765bbedaa6cf6 |
Hashes for stim-1.13.dev1710720884-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a0134bb95f245e2241e2fb6819e4f8bc9c9db70a210badf955a26b5a9d4fb7b |
|
MD5 | aa52c810ad93a7b823ceb32f0771c2a0 |
|
BLAKE2b-256 | 3a68eb39dc7c28b6eddab9ff3eefe758ee76c07a02e1f684a9b922f66e27ad99 |
Hashes for stim-1.13.dev1710720884-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b80fd0b4e8aa9b504f08112ef4e71f3205c9293e052a5ddc9555c4064ed7e5a |
|
MD5 | 5a1c09d883f7d0d6a910f86a05964e79 |
|
BLAKE2b-256 | 19ec1f1504479b7de26da07462c67aebe481db145ed3797ede2b2702bf836618 |
Hashes for stim-1.13.dev1710720884-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e11761b594c73cef16e1eaca210819690baa812910f7f5ea9fb22864aac0d624 |
|
MD5 | f1d16a8672db3439535877edf4f29c87 |
|
BLAKE2b-256 | 0abf4be37935887b7b4b16d5acef243a1cc28f3aafa39529d91255289d44d2d2 |
Hashes for stim-1.13.dev1710720884-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c88b408051fd33d39ca83a73d730512d3c0791413a002a88a552a5bcf6210689 |
|
MD5 | 760d8199c09a32f5f293dbec52dbe3c3 |
|
BLAKE2b-256 | be20dee0a598db855d621a1af28bc5d9a72f6f31b7611a6302886bd97568c823 |
Hashes for stim-1.13.dev1710720884-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69e1277d91808739de5edf61a1836c6041acb8696039b0002372f9b4e03fc8e2 |
|
MD5 | a9e1465e57f8952475b9659f7d5b64a5 |
|
BLAKE2b-256 | 7c2cf7ae7609f48c6287a4bf81d98bf9fe41bf92a19d9c75c2cb16b8fc4a324a |
Hashes for stim-1.13.dev1710720884-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 630d0ccb13bbc00169408d8360678b32b99c0ee2db092d970de0b0d6d38d2798 |
|
MD5 | b5600348dc48c2d5ff10e0cc848c2adc |
|
BLAKE2b-256 | 62dca1f51deed66abac383daeb3669aca6a25ed6ade9b953f8b43b5e7d082da0 |
Hashes for stim-1.13.dev1710720884-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0270b2f636fdad1522edd983d169ea59bef40bd7f83b87418c3ba28f68f5e9e2 |
|
MD5 | c83f72e125d639f3c46951c438a503d2 |
|
BLAKE2b-256 | 90fd895e744fa27bbd39cd114df7a775f59fefb22196d04935b2dad36901f6a3 |
Hashes for stim-1.13.dev1710720884-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97902cb6742a40c513c06f8436f197d01a78f201f9764f62f0571bf46909e853 |
|
MD5 | e0e04b75ca742c0a12613e34ded7ecc1 |
|
BLAKE2b-256 | a11310cb700a679840c15c64614dd1eea4fb2a8680476302f6d2688cb2d5b256 |
Hashes for stim-1.13.dev1710720884-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc4b70c147d0539bc845eeeb37b414e0561d29b7392a01436ee2ad397a0bc43 |
|
MD5 | 89093b0906a98593f65d1736603048a2 |
|
BLAKE2b-256 | d40ad577e1cc43114eb071a062c9c26fee3ee3227de11585c56496203c3b7790 |