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.dev1708338768-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d01e2989a3281cff2d4a113bb4f84f6216cb773e6d07a71d1ed278462d7eb507 |
|
MD5 | e79946ac8592dae0476846abc06b36c7 |
|
BLAKE2b-256 | bb2ffe944e5c3d331cae6a2a3c7854b3b93feccfad33c8aa2806d0439778886f |
Hashes for stim-1.13.dev1708338768-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 643b93c849ec218ee2adbaadb4016a3f8532c45366881a22d1bdf265dfd9793e |
|
MD5 | 29bca14aced5ce1f4d49afe4f517a28e |
|
BLAKE2b-256 | de63d6bbc20af40746f5e6d3b1e80a70f62d84627ba6d84c80f957852dfc53f2 |
Hashes for stim-1.13.dev1708338768-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e339151374ba943e0b23f772b760a92abad14f33d0a99b85140e0f36639572d |
|
MD5 | 2d71067eed54983ca9502cb0a2f84bc5 |
|
BLAKE2b-256 | ac8d339aedd7cec91ea2438e7d1c858a0ceb95180ed23ec59983cf00e983a0c0 |
Hashes for stim-1.13.dev1708338768-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e777366c3a00fc0770e6a63fabdfc70811a8313a4dba817dcfe944aa5dba0bb4 |
|
MD5 | ea71af47763c798c19484741434af86a |
|
BLAKE2b-256 | 81a943481aab5dfaedc51223fab6db330e5bd94606472df807bf63a051a3fe8a |
Hashes for stim-1.13.dev1708338768-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a31b651977ec01cc1679e1f306e6417af9b5d6a4b2767d35523b3bda35896937 |
|
MD5 | f5c5d4fb2d8bf503da0d5acacac721e9 |
|
BLAKE2b-256 | bdf15c30922285824c13da5dea8a534b4d96a180fb8ffa1a3f200f2ccba9f768 |
Hashes for stim-1.13.dev1708338768-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2a8bf18e0bfc0f99510022aacec1bb3629cc0ea7c1f3d33f891ed5080f12cf1 |
|
MD5 | f82c6b554cb313441ede2d51de618396 |
|
BLAKE2b-256 | 45f94a5272c629ca4e647135a2247a20ef47994f2cec1179acadb6506b7fb0e2 |
Hashes for stim-1.13.dev1708338768-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12d55844cb22e92267a2da0ca814daed3ec2658ef26e87553a0c7c4bbbf230de |
|
MD5 | 3dda1ff6a8201c97de19715a153842bf |
|
BLAKE2b-256 | 1f32c885468025da3bf3771fb4bb0e42b27c9a7d858073fc7ce4aa380805651c |
Hashes for stim-1.13.dev1708338768-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a7c6c8046bb81eaa50097d866b7c9205eebf12cadd5160d76abd402d74d2a7 |
|
MD5 | 2262da96afdeb6c562fd9b654caa32f9 |
|
BLAKE2b-256 | 7edff88964373df61f1f98ec73a6c91b34772695b7678c1581e943975a0bf799 |
Hashes for stim-1.13.dev1708338768-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 900cc48e569b4cf515d658f562d3917d3792dd8fe082b5e931bcaf9027183c6a |
|
MD5 | 7376a7114f4ad8976ae1cf294f269203 |
|
BLAKE2b-256 | 520bf030cde3b1258475b3bf3ee435b5a14474fbcf26d904cdad0ef6f254535e |
Hashes for stim-1.13.dev1708338768-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29a4f60baae13c11ee7fd2feaa800a3d00f1d23f48980c0390a3e1933976026a |
|
MD5 | 9c7336d68115e40b2804e2eeded21c7c |
|
BLAKE2b-256 | c38ef295c554088109ab1b6ae45ec41328196b04bffb03c8fc6e77ef5a7b3794 |
Hashes for stim-1.13.dev1708338768-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7aebf176437721f44bf8021bb428cb85f219c167cb513382778c409cf9bc170 |
|
MD5 | fc43448e6d292e41f46af3a9eae2184c |
|
BLAKE2b-256 | e0a38415699af92dde92a0578567f601d6ef992cc3add91528ab1335293cacce |
Hashes for stim-1.13.dev1708338768-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eca593d92bea44c40d1d64e176e659d1649a98f060e88128d8506710cc444b6 |
|
MD5 | e9c1ecfe9601d07854e50d453c72673e |
|
BLAKE2b-256 | 8410d69ef36a6a01f64c5aba35cdfbfb652695f5266f1c7a5f7281b5a74b3acd |
Hashes for stim-1.13.dev1708338768-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2166b6ddbba15b773b3b6d5264d3dca1153afa5cfb45669c44a496bb5dfff978 |
|
MD5 | 8b33d220b5209a6eb845b5124f819bcf |
|
BLAKE2b-256 | 3b266fa9e62ca3311b07b6bb3636d1372f9a6dcb496ef892e25690f2a32be08b |
Hashes for stim-1.13.dev1708338768-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f49a8ae081bf4d826b57681cea7fbe0a9003c907ac4e66df5d9a43a683ff275f |
|
MD5 | 46158814fe633519bc945f4430722598 |
|
BLAKE2b-256 | 46e81ef4afa18cd62cdcf0bd139b87bdc05c1674d6e3a5cbb99ee891a5bdbe9c |
Hashes for stim-1.13.dev1708338768-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e8741eddb20acddb33801eb8ce0b99fb7ee17f4bb2b18384a6cec054d2e872 |
|
MD5 | c94b828c6512fc6cfa098ba151d6698e |
|
BLAKE2b-256 | 81bcde3f8b5c17993d488270905a95a0359162a8923fe980604bd3cd04b90e5a |
Hashes for stim-1.13.dev1708338768-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6675f97e4848aaca5db0eb446384eaec998c94dec4de84e331aadcb09f81e37b |
|
MD5 | 7cd7cd7df67d70e52f606cafb0bc4bb7 |
|
BLAKE2b-256 | 6ce17fce02cffdb08dd560794b82c08162a5a9313da96ef1c5dff09d0e4c8015 |
Hashes for stim-1.13.dev1708338768-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c27efb678295219d47921d8aed4702c0c6081d471975b7082807bd5a37d277 |
|
MD5 | 173bb69b4692e06c4cd9142b9619e26a |
|
BLAKE2b-256 | 7c6e5d4debf5f0dc7184de068739d0ed54991b1c8c24508cba60258db60e8f92 |
Hashes for stim-1.13.dev1708338768-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d9fcb759f9467713dc682d685023df59c59d69534f4348ec85bfcd2944c8b2 |
|
MD5 | 60212aeee72a1c4b8c03e1f85ec545b6 |
|
BLAKE2b-256 | 4c304ac55d7e7df845e9013531690c63349b4a563435d5f78a70b6b2d7de1139 |
Hashes for stim-1.13.dev1708338768-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 253004d59d14b93dda3740109324c4990868fd797653652a33a7e9a4fff1d397 |
|
MD5 | d01bbc618e66a8d9f602eca6255173a3 |
|
BLAKE2b-256 | d3329a9d0f67b1f5992313e54456d61295b3f6025c0bedfd421a0c3dbf0b1366 |
Hashes for stim-1.13.dev1708338768-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48007a9e0cbb373747480ff66551be0592dba105ef50ad45933a96179cf183b1 |
|
MD5 | b1067304bcdd335d28a779bcf71598f4 |
|
BLAKE2b-256 | 6f85326cf25de987c64885cb420a1fe212097907f5934c54368ccaad021e93cb |
Hashes for stim-1.13.dev1708338768-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8302ea76d426209dd44a5dfb168aa49acff176a716296d4e0e2ce3599921a3d4 |
|
MD5 | 9e96b23b21b273e3b28a6134bd73fa3d |
|
BLAKE2b-256 | d8d0fe800e5344719e5768327383bcb98fcea2e7228dfc63aa81c8aa22369374 |
Hashes for stim-1.13.dev1708338768-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f2b07d39a0db05fab09109625cd43b4d9ddbe7ac8bc9d838c162dc912a68d82 |
|
MD5 | 2ef6476fd4f00512d116605662146367 |
|
BLAKE2b-256 | fee5973f5eb7176272efb311909cc37d12c565a2e3a2fb2f1a5c2c9aef5cd42c |
Hashes for stim-1.13.dev1708338768-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13ce0b2fb7b23802afe6d73d60a1903354a0bea57d59a273448feda8edefb816 |
|
MD5 | 9cce022fec109705353aa69fab5f2e61 |
|
BLAKE2b-256 | ede18f8a2281674dbbc04d7257d4b2c54e5624e10e2a7fa6fee06430f20ab259 |
Hashes for stim-1.13.dev1708338768-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4558d912e3ae07dd0f7e73ce27b17449a0bd6ada361f4be4d8ce5bdddd2d65a6 |
|
MD5 | 2a8d71f1b60e771f4f263585f6a67740 |
|
BLAKE2b-256 | d5368951eb3ffcb89ac0848a91900ffce66d64bc229dc20a6867e8bced214f35 |
Hashes for stim-1.13.dev1708338768-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac3c4c0595149ddfe71f6eefe714c40023ea6a58a58f0a220330017bc752a4fc |
|
MD5 | 7a0a52c0b133dd70d29b933dadbccfb0 |
|
BLAKE2b-256 | 2862b2a5db301936fdc669768db3190e77f28da0da4a5c32e04210f0f0d691d8 |
Hashes for stim-1.13.dev1708338768-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b2fa5e2866d7cbaa663da646edf58a2ebace99c23d987626c201c5a3d69945f |
|
MD5 | f161fdb4c8112b7b9f3ab8757c9d938e |
|
BLAKE2b-256 | 2e8064282827d3eb903bd2d549b5ed369216ad487d2839402eb2fbd090cb8459 |
Hashes for stim-1.13.dev1708338768-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20a018b80b841eeb20e7aca163298d5c01e919ef59ca101d7d1e71f5fe7e2ee3 |
|
MD5 | e4daa93e13c674d5eee88b34aa2c06b6 |
|
BLAKE2b-256 | b4db35c707f165fc947badef0755b0facdfdcee02a87b603cd272b6045c089e6 |
Hashes for stim-1.13.dev1708338768-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca6c8cf42fa1bbb403659f7726a138c75321c1c3a38e41bc4080048fa290e83 |
|
MD5 | 7cf6e460e3a5cff9500de58d27840dab |
|
BLAKE2b-256 | b5d868c6838432b9d9210ca7a62e323cb2a81e364aa8da2a6682bc4ecfa7e3d8 |
Hashes for stim-1.13.dev1708338768-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc3150735e2d39a1c07cad97f9a53631fe946f9829f96fa18854effdd4896e7a |
|
MD5 | 14880f02c70b2a1e040fa9af663b6eaa |
|
BLAKE2b-256 | d87cd1186535b3dc951c618fda64419231ad742151f7c5dc22929e0234c291a3 |
Hashes for stim-1.13.dev1708338768-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ffa9c7c88dedbb3c9ed40375fcc3a8566ed6ff1b0737e5d0f89f680e8578b36 |
|
MD5 | 4d55b2ddfcc4eb2a9b8583c1d5939ec9 |
|
BLAKE2b-256 | 1bb7917a6ba543f829f097238bf1e97b16af89626fdc317adc898dba07113b54 |