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.dev1692747496-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03c62fa1157721d3cecf1077769cf09a54171cd5c7d735b44eec01dfc941fd88 |
|
MD5 | 4f7d14c44e443a29a21be270d20c369a |
|
BLAKE2b-256 | 70fc913042127ef1cacd57372b5bf04abfb16800712b77398db0c0334cc94759 |
Hashes for stim-1.13.dev1692747496-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7dcf5762b963d958d0e3e314c661c9abab841c1bdb9acc526f8e6511b0f882e |
|
MD5 | aa950b1ddc63a84f23221bdad8b52525 |
|
BLAKE2b-256 | fdd20ed03b0cf4f34a6349ecae9dadd97c3c2c824709a9409d1eb572b7406689 |
Hashes for stim-1.13.dev1692747496-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 922545c5d3b88140775bb494a8324021fc89894bc9d6f2ee151a7d11d2c50e48 |
|
MD5 | c2087fa70a7443589fc72b2fb2fd9b88 |
|
BLAKE2b-256 | cfd7ae0a9ed95a52c2673523166aa11f0dab02d90893a7ffaff65856789fd70e |
Hashes for stim-1.13.dev1692747496-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb58a26a60b7f3b4ec8dd5d7b8116b272c1b1a36a01f15d5581e55004f3683ae |
|
MD5 | b16d2a278f2e9a5ea66a144c5e761518 |
|
BLAKE2b-256 | 2fec843b82f8303a6090cd697fddd3bb306e4f84b2f375257ebfe1cbf5227a2c |
Hashes for stim-1.13.dev1692747496-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1577fca65a39c9d8d911a27db8ca5a0534db775b1b4f99d13fd506c80c53ed64 |
|
MD5 | acc05c9c4943427d6fea85a5f2cd809d |
|
BLAKE2b-256 | f24a91648a718283a337cadc0bbee14bad4c3772162ef98df00d988a6018d337 |
Hashes for stim-1.13.dev1692747496-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc21f0ddfb38b8aba900238ee8aa44a6365dc08d3ebcdcfca7c4dfa0b4c61af |
|
MD5 | d7a286653ce9f0875cb6f0b7313ef7cc |
|
BLAKE2b-256 | ccbfd9ecc36d0ed9ae2a1f36555af70c038ab1fe0595eefb90aa83ce05240332 |
Hashes for stim-1.13.dev1692747496-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34d95e586dc1ef799a0e565315e49a003d5cdf979a0ab7bc1e4689e8aaaa3358 |
|
MD5 | 70e33caab2841e31359150922141d1b6 |
|
BLAKE2b-256 | fa04bb6f3e87d1b716e31af1deb44ae85af40895ec2a5520e15f280965d9499a |
Hashes for stim-1.13.dev1692747496-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f3386c36448f3de7283c63f075f07327e5bb14755fe9b9ae15b3c3c8b6a466 |
|
MD5 | 635b02c37abe1dde5760bffcc4799340 |
|
BLAKE2b-256 | 16d6113ac39f193564ff1db9eb88d68a0782215a531c5284e2cb6e3f27b474cb |
Hashes for stim-1.13.dev1692747496-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 001ec7fcbc521c776be9720c5bce211edc5ac82a28bfdeb5fa60135cebbcadc0 |
|
MD5 | d323d99e71769270d01508d1051eca99 |
|
BLAKE2b-256 | f0f96d9d0da8bbbaf0e5dee886f6988581a2e06538e962b678b9a2d5efe4dd38 |
Hashes for stim-1.13.dev1692747496-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa5a6b29de5d861f5c6840ce36ffd2b17d6277f08e8ecaf3026eb879f277a6aa |
|
MD5 | bbb64ac887085a587ebcc1e35f84458a |
|
BLAKE2b-256 | 0282bfe2232762d45a8d1e6b9c56b9b6b5b7107806e2ea7fee5f3ba617f6aac0 |
Hashes for stim-1.13.dev1692747496-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6d746fedc5bd0cbcd7429ff8e2b83f7d2c1aaab3f6adeb6b9236ec68ef8569 |
|
MD5 | 0565611ef2a1b6c65b9a39a2d3a5b198 |
|
BLAKE2b-256 | 75ec469fdba6f442e1f58e5bf9e325dee961657816b69531ae47d35644d8a5cc |
Hashes for stim-1.13.dev1692747496-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a7ea4c499622d2e9f9a60fdc40339d6a8af69f1eda2c6c99f9528f40d346d15 |
|
MD5 | daebe1416e85fb7f17ae1f9498de51bb |
|
BLAKE2b-256 | 5411f850a8e67656feb448b5cec45de23cd0dc7c96e3ca06bd9c917ae1b29fa0 |
Hashes for stim-1.13.dev1692747496-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05ec7d625a07067a8a18c111d9406b108778c7d0828fbc053cf386cac9f0b009 |
|
MD5 | 9b4773c41784f2cc1544418f83c47377 |
|
BLAKE2b-256 | bfb4f27f5a8d1fc371bbf7096e7823b8f6499c7ac3353bfe8eac97e4840cc188 |
Hashes for stim-1.13.dev1692747496-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 205313eefed6d14906657618869a2892b3bfbeb41d9cb06154cadc1f091b3216 |
|
MD5 | 3e4ed5579583e59e78d10debb6419dc1 |
|
BLAKE2b-256 | a09d7abbcf92a592fc17664a9c68a5e8b577e82f6543d618e3f0babf0f54df19 |
Hashes for stim-1.13.dev1692747496-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d814bb999de2dee20c272cc68a6bb7427615f2432f83bfb9291d71eee495d92 |
|
MD5 | a9c79888b8c5ce9a761c0674a832861d |
|
BLAKE2b-256 | 60e744fd0a420fbdd0d10b91535dfc0a79e76e2925448ed0dfa17e455a690970 |
Hashes for stim-1.13.dev1692747496-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d840b7673ff4d23115d665ec8e69523b3a104bca2d79e55fcca0830703531ef8 |
|
MD5 | 62324e987aff3cb9d6c408dad8897a11 |
|
BLAKE2b-256 | 5e81d2bfeb96bca9b5d7aa8542f4da6f2ce52bd6c426f581e60144bc3963d05b |
Hashes for stim-1.13.dev1692747496-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba2fdf1f9fa1832516a034a164c5ecea8fadb0dc9365226f3da7491d5b983ffd |
|
MD5 | 7fb4abb235c0d84c199c67702539945d |
|
BLAKE2b-256 | 4bb7d73ef395a686cc00a122eacd5fb60f97801bf28eb40f5f793a29992b1ad2 |
Hashes for stim-1.13.dev1692747496-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 979f2c70a53ce20dcae5a2c6f30874ad68216df22993c6a1a71c92cc1430dcb4 |
|
MD5 | 1fe9182256f6cea8fbcbcb9e579469bc |
|
BLAKE2b-256 | 22892fe32af82be5753a116904b10de583da3a4e1b76821e2821dd32959a0ed3 |
Hashes for stim-1.13.dev1692747496-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 520f60c5ed2d43847a645e159a7c857975473397f8822816561c0e265e31d7b9 |
|
MD5 | 2c0b751d11b079d411f4a9971aed0a8b |
|
BLAKE2b-256 | b819c79fcabf42ae10ff8981d6b2838cf536fdc806c3cb1d9cf0e515a0768371 |
Hashes for stim-1.13.dev1692747496-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fc97b1f1eadcf40229f12f98244ba870dbc64dde44397fe217c6266f43d2291 |
|
MD5 | ebfffdc901bd60603c6e8a792fe8679a |
|
BLAKE2b-256 | 4e7889b1c73bb3d546024b601b6b7f8720d5e731db8dc493a07212f32772c7b6 |
Hashes for stim-1.13.dev1692747496-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8559303057cbfbab25a44d8a85a1b63718db844b11e8f38e55e009ddf33e4df8 |
|
MD5 | 1f050e328314ec54bdee123ebc5e8463 |
|
BLAKE2b-256 | 03d7f4775afdf4598bd8a14444395ece4cc1d8787a6b96c7d828ae9f040f1833 |
Hashes for stim-1.13.dev1692747496-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b61982b0ba90f9bf91919258d1ee1bf7c5aa5427986689d247fe2478302a09a |
|
MD5 | 81df606d9edb308f5d6f7d41e3ecb06e |
|
BLAKE2b-256 | 14384acde770f710c08d753d8e282acaa5d74bf94b15a77c5f1e28cf482d94ad |
Hashes for stim-1.13.dev1692747496-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9235fff19fff10f89875198f9ca12f4889d3ee2978f7856481e0840e933817c2 |
|
MD5 | 7b9ad5af9636e39b89a2d6d2132202de |
|
BLAKE2b-256 | 27c8c44ae12b28723631285a74d39949f9b3618f4c9a074f31975e5a7b6ecf7a |
Hashes for stim-1.13.dev1692747496-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4db6233effa131ecdd564d22a1b75a4029e2ffa187f987b7289378284a2e8d4 |
|
MD5 | 860986fede7e63067c8b18fc3b54e78c |
|
BLAKE2b-256 | ef0f3f2bee9c6099737183fdfbbc64da13d504b0d6bc56b845f7649141c4d2db |
Hashes for stim-1.13.dev1692747496-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36edb17f3503795da422d837b523f8045362a34496a11646d37dacf5f1c77891 |
|
MD5 | cf70930ec36589762164774063af2f2a |
|
BLAKE2b-256 | 16b47a716a9aee88dc6c82de0d0efcbc9f8687da2a5b658373e4427ff7c94c8b |
Hashes for stim-1.13.dev1692747496-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8559c97f448976c3d649fbaf77efa9c334cb74a153e386c5e91967180b6b638 |
|
MD5 | ceacb8975787cdb9e2ca1d48936d16ec |
|
BLAKE2b-256 | 62eedb196d50d52ca40cd50dbafb6b9b0ef3044e5589bd49f0d964013cfbb0a2 |