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.dev1726187406-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d57e4b776a62ebd211ba3ae2480473e0a028422ceecdcde89d0ff8e9c520669a |
|
MD5 | c05e181b7325b402a7c5d17bea094784 |
|
BLAKE2b-256 | 617448623fb5e5ad5fb3c394652121bca2798d8d67abcac45aa307aa3adf1b61 |
Hashes for stim-1.14.dev1726187406-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cad99ada73524bb448bf8f59457bf6bbdb87c477d1f6ada3741995e27bf6534c |
|
MD5 | e44433b5917021679ed744777ca06966 |
|
BLAKE2b-256 | 26c40f54c4a125827b5623c61248cfffd0e1416252df83727610e50f6ecb4ced |
Hashes for stim-1.14.dev1726187406-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c88bd1e2d49bad37deba820f1cc34d73942720dc60b158b24596c64d6996782 |
|
MD5 | 92fe4585a2d4cdcd279f9140354dac45 |
|
BLAKE2b-256 | 3fb3f4264fa89c8cb29891e34624308f34f45ff9857de339ab40c9a2e14c809c |
Hashes for stim-1.14.dev1726187406-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42316c71f8a6c14030f794cf540e40d1df8a522f2e3a3b5e883a7df01f2169ad |
|
MD5 | 5d13c7f8891f3b234e2921b8c3b4f70d |
|
BLAKE2b-256 | 42601399df930d146c39dd4470873b3f1d22f70db77b82ca92cdd43ab181f0cc |
Hashes for stim-1.14.dev1726187406-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 789104e0319ce4b859794429a162d9d216999c8cac90807be1a419102d8d8b42 |
|
MD5 | 88027df5f9365d3a650bc6c77c816890 |
|
BLAKE2b-256 | 36f63ecf059426b2626fd809b22d8b2ccc3c4499c2157cfb028dc462e9b26d7c |
Hashes for stim-1.14.dev1726187406-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d10712ac0a7bf2256e5d10af60d1c16dc0ecf55795f8f83bfc1ff7bd9685682 |
|
MD5 | 05288faa7496b4a2a950056cc7ba2d20 |
|
BLAKE2b-256 | 9063acad824367c158c906a16a6221c2a427ebc94f4639f6a9ad15e3965e56f7 |
Hashes for stim-1.14.dev1726187406-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83491abd52d2fee3e3de6bc3d0d616866f02e49ae818331452a89d8566b6a457 |
|
MD5 | 6207617cd23b5ebf64c974ba37cdf2b6 |
|
BLAKE2b-256 | cf2c79127151d4d01116c7ddecf5809343371ee124fbd2bba1dc12b59ab37ace |
Hashes for stim-1.14.dev1726187406-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1854d02acf87163c45dc5730d9b35bcd3d56239c5404537fe3a40d2222524103 |
|
MD5 | 18a21693f267acfdb41272ff3bbb72b3 |
|
BLAKE2b-256 | c3f72181bcfb445450fd27080b14e92248a6e43a4449f90c3012e7f54a3dbdc0 |
Hashes for stim-1.14.dev1726187406-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b6505de4ec9425dd0e6132a3ad07a3fd42458ddb4e98e621ca76406cd7ba69 |
|
MD5 | 8e478de1209f464f90d1ab491942affd |
|
BLAKE2b-256 | a610190014430023cbd9818c5c5ba813814350e69f50a17a92af46b4b9af5b90 |
Hashes for stim-1.14.dev1726187406-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad994770617029f244f9c13ede74929963b13ed2481cc8d31edaae863e23fe03 |
|
MD5 | bc73d046b2fce371ee38c504462750cc |
|
BLAKE2b-256 | 98e06c360f6e0de2427967cc9b6fa0748ee0b6a1fde45409e94240a880adad02 |
Hashes for stim-1.14.dev1726187406-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3a67d1199ca52c55f6a0935d0f31253cea61e65ea860da0c5b52f92bf222a7 |
|
MD5 | 4cc1d04eab418cae963bd5cb5b5caaea |
|
BLAKE2b-256 | d40c8a78941d3191246ebc7fed9c5642cff3ee903233cacc26754f8d52129e9c |
Hashes for stim-1.14.dev1726187406-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65eaaed2ea5c44d637cf243826e35eb44e6deaee7e7bf872d5615d3cb225a52e |
|
MD5 | 4c0286d8cb3db3a2ad6313328f89d983 |
|
BLAKE2b-256 | 8ae35536226abafa8760cbf4e13d33296d654b075ab0186d2db068b9b2db0880 |
Hashes for stim-1.14.dev1726187406-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94d278d4c72a1267fd12a833e606018e82d76dba889b947b9f999c694ce2c5b9 |
|
MD5 | 60d5166d8919f79bc05535b148d02507 |
|
BLAKE2b-256 | fde7e458f63f5e7c48534ef37a0c7b1ff51c80535df1b3ce9d715f770fc9913a |
Hashes for stim-1.14.dev1726187406-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbf233b5d484139d1423452351e204b4d5bcc373c8390d9190ff0de02d8a1bcb |
|
MD5 | 176644ee2087cac5b8cce145b350d24b |
|
BLAKE2b-256 | c9f5f5ff6a375d80d5fea3da02d1aef642d18881e9f36f834dcc3e0430637aed |
Hashes for stim-1.14.dev1726187406-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45283a6b451d4ff21371c6f3373020773296878c1eddfb2cda2bd27ed1dd112b |
|
MD5 | 17813d1af9a447b16d211ed8f80b2a4a |
|
BLAKE2b-256 | 64ea688224709ec07ebb98bfeb797f590055a4d6e1c27e747fd7a0a8acc77f73 |
Hashes for stim-1.14.dev1726187406-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3267003e02deb390a2e67daa814397d7bc45f9bd0e521e467039a363788b2b4d |
|
MD5 | 54d66855b705d505d039a3df965dc3e4 |
|
BLAKE2b-256 | 137e7a4cae405df35820a3cf436639bc598f2fe9201ebdc74c7c9ec2f4a9f058 |
Hashes for stim-1.14.dev1726187406-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97e44dcb1ee6e629982ef5fc09ef9acabe0a6da1aa80aeae45edfe4a6dba72c7 |
|
MD5 | d478b9b294a1c0d7d5797c21cd044804 |
|
BLAKE2b-256 | 84414394ab2d59fa6301c582c78b2de542b5aed3913dfef61e2c5fc8e7c40293 |
Hashes for stim-1.14.dev1726187406-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d1200255a10104fb90b48954fb62849dbf7d175835d90a9849f450c6ef96b0e |
|
MD5 | 7a5d6c11165e01798314f1afd3dba6aa |
|
BLAKE2b-256 | 00706365775524937200a4cede9845f402a2a09041332ef9140596a90377e459 |
Hashes for stim-1.14.dev1726187406-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e559ce8dd28b3bf7b4e384ba43fb12f6a70d29fe647f781acd12c620d82701c |
|
MD5 | 10b89f1fddf8d20a0eb2706539034d3f |
|
BLAKE2b-256 | e8416f52daa84661c5c7f744f5fbaed1feb12c27b3c04d57dd409d5b736627e8 |
Hashes for stim-1.14.dev1726187406-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a38b6c28091170252e3e6ac188094cfadb028ef7aaea4aa5eb3aad8d66936d05 |
|
MD5 | 40399c16079174ff8bd434bd5207c75c |
|
BLAKE2b-256 | d07e6a4b1e10b155ba3698e1ca666a93556c35c8386f3300bbf897cdce564c4e |
Hashes for stim-1.14.dev1726187406-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28c20d525352d602e9c6894f8937a1e8db56ff85e55b257c383c732340a93f88 |
|
MD5 | e8a0db529150d67d6de268fbbffb8565 |
|
BLAKE2b-256 | 908b9a0f118821f535cc0972bf9f94c80e780801de1d2eba13b567e5a42fbf21 |
Hashes for stim-1.14.dev1726187406-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f25b4cb4fbca621a5b5b7fb3f83e8bfbf01dab41265af357c5b5c4d7f55b1f |
|
MD5 | 6947ab46317735c4210d13a456ce90f1 |
|
BLAKE2b-256 | 8a84aeb9f8beceba13f08ea1f6629c5b4fe7583021c6bdf1be0b55301505320a |
Hashes for stim-1.14.dev1726187406-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13dadaef20e4dbd412b3e7fa5201eb338585859b0e66fd50845522d040a2be41 |
|
MD5 | 4cfcaae9b91960e5ec016bb7b01ac6f7 |
|
BLAKE2b-256 | 9fb282bc9efd1457103ee77cbd01ea71c348fe14f35d931c12bbbd705cd02720 |
Hashes for stim-1.14.dev1726187406-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7590f7b0cffc5f1da34433f0c18d824aadd82aa90a805aec871716ef63e1126e |
|
MD5 | 84d07e8b1b84cc0020596e4e39ed9bc4 |
|
BLAKE2b-256 | 98408349e679cad6f5fb5ac5306c42f91c458364394e1ce41448dc20062f0efb |
Hashes for stim-1.14.dev1726187406-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599478a83aa3ee5224c08c6a3f959aa69fd8e7b4285a9826254967f1bda5d9f0 |
|
MD5 | 3bf67679b7b41d4d32334119ff28a80a |
|
BLAKE2b-256 | fd6eac5a80b148f83b4e98c48cb691266cf7f96dd6a0d9f1fe3a9f4ae67e955b |
Hashes for stim-1.14.dev1726187406-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4faaeeb69790c93b1117aee23b5c3b6549938b3ec812086ee5bdc6e7a2747cbd |
|
MD5 | db69abd9ea8f46800ccd728c553db4ae |
|
BLAKE2b-256 | 6a427452e9c452aa6a5d04b214e77accabd404be5acb23b6e925b9563d13b1f4 |
Hashes for stim-1.14.dev1726187406-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db1001fef9713a5cf8bc322c7fc7d91bd6c351e0544abb4ebae7d365bc53e1e1 |
|
MD5 | 33beb822c007f1c7fb8b4249e3cc098c |
|
BLAKE2b-256 | 2cfa3e0083104baed3f080679db0dd817c011cf508afdda3c54b4842527ea759 |
Hashes for stim-1.14.dev1726187406-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 533b471b143aa4cb6204084e9f8ff5bab09e4b04c3b3f2fed8bf263e711d54c9 |
|
MD5 | 6068a3df60792b59802a357236e5e36a |
|
BLAKE2b-256 | 56a7be596c6ee980bacd2cef36d0f7ea79e2ded28cfd7bc082e389f2568d6abf |
Hashes for stim-1.14.dev1726187406-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80b52b7139eebc49d749efde5afda897a69c82fd0032914b8b5eb3352c874c77 |
|
MD5 | fb180c0f64f6dbc80d34f55a866b09f4 |
|
BLAKE2b-256 | 7c33bba0c4d66492ebf2b812e351980045973e778d60efb2972292944e39e4e4 |
Hashes for stim-1.14.dev1726187406-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1054fdcc35f93f7fa3a6ed61fbf00a051cd3298bb8166028c5714cea23987326 |
|
MD5 | f53dccdb65bf588c8dd58e2c45557d1a |
|
BLAKE2b-256 | 8fcadc506fa4c91053c5bc1d782b9eaf5d021019443d4e5de2fc91db172cfe44 |