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.12.dev1682406094-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8fde86bf3aaf8a6cf957a8df9c20657a19abb2059a96c10d6b4699d176a39c2 |
|
MD5 | 3fb37350c3a4bd6bdbd66e4db6bdf929 |
|
BLAKE2b-256 | fd9f8489d1f942f962c6a84841504a6eb862e4f391731231740696cb5d6238c4 |
Hashes for stim-1.12.dev1682406094-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb37d6fe9dd1e4297bd83a26fb6df6d51c53adb1d423403ea385f7324c660ba |
|
MD5 | 34c19e18e1f489c6c13bf3cd3cd84396 |
|
BLAKE2b-256 | e36602b9a3f1ee364e8fd333bff69185548c8c5dce9dd38d60af04d376c8d7eb |
Hashes for stim-1.12.dev1682406094-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e2ed5fba8e4742d761f9df7e141b29d5b77bb8afab2ea128c62891fdcf786e |
|
MD5 | de132a86221074f6628e663eb18d2784 |
|
BLAKE2b-256 | ba9baab06c81b81e5a6eb399ccafee29e3710270a1ee6e10fb47822e64dbd720 |
Hashes for stim-1.12.dev1682406094-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45b5aa564b0d07556de72bf6292038347bd2240048c4415d5e3ffd2ed4acb1bf |
|
MD5 | 384adf8e15ee8c9ced482f17973191a9 |
|
BLAKE2b-256 | 3a8c2cb4d3e1bebdfe4edfa27785683db9acc0898cfe76d8f83880e891439db4 |
Hashes for stim-1.12.dev1682406094-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 115a3306fba91f4808355980f385165bd95f9431f894e5d5ff230adc3b67c888 |
|
MD5 | a325370f43d5d2bc718a3c75c809b190 |
|
BLAKE2b-256 | 5fc99389bc42810f10724a8ce32948c82e0fddaccfb1d09e84e06c10ecba1071 |
Hashes for stim-1.12.dev1682406094-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd7b5d03ca1025c13260493eb50c1978d95ee26b24f0b970943fd92421dc2c34 |
|
MD5 | 0f7df7369e02ce7636ae010451354c5d |
|
BLAKE2b-256 | ffe55ae42a3437b47f8b45ef065c322cda2f083ea232253035d7a7b1e83a0dab |
Hashes for stim-1.12.dev1682406094-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dab920f268ecb356f5920412bab108c890e40fcd6fa696e552e1a7d561d784ba |
|
MD5 | 0a09db97047f0a54287b522b03efa31f |
|
BLAKE2b-256 | 9e7bc4abe689b1bb90e2d5edc7284177993e8da545096080e96f2a7b31042e79 |
Hashes for stim-1.12.dev1682406094-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d5c028bffc3b8d786171039159fa6ff3785071ba16190912b68ad02f10c9a3a |
|
MD5 | 2d8abfdf133e0f2f7ffc39b76ae59b0c |
|
BLAKE2b-256 | 8b43d37fc0384000ec6fcb6cfe8d342587dae109955059a658e627b5e49ef421 |
Hashes for stim-1.12.dev1682406094-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 481d0252b5e6c13cfa416b092753f153cc5eaf2891cb8c5b5eb049f116c0302c |
|
MD5 | c1a90fbb5ba93ccf6f994346f381ea41 |
|
BLAKE2b-256 | 6eade2f1a0931b33e0f1c290827686b46f0eeb5b32873c45602207a2805b1b67 |
Hashes for stim-1.12.dev1682406094-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fe42a946118e774e016794d8f579139542a7475921845309136de31bf8e4697 |
|
MD5 | 4a04e1db4928c5273a757c0d8a4774de |
|
BLAKE2b-256 | 9a3802fc30d3e928bcd9b4f306e4e0d40850afbbbbdde883e6b660622a5d5d39 |
Hashes for stim-1.12.dev1682406094-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71aa4be3d752d1f81e780c9d063d455236908efb9fb6cfb86ab5bfd0ea7f79e7 |
|
MD5 | 148d71708c76ec84fd878cf98622a410 |
|
BLAKE2b-256 | 0e192acbac3d44d6cdb2e8de8d054cae30d80c286531397d05d4a2f3039bc3a2 |
Hashes for stim-1.12.dev1682406094-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e53f05d448530599375f0b82bc0e8f6d99540755e44f626f3dfc26f8ede22e75 |
|
MD5 | 79f1815617751cf1d139ba30a83abf15 |
|
BLAKE2b-256 | 29b80cfecdfe8ea088a13238d703ced1bce0bdb501be24c91ccc6565dee13bce |
Hashes for stim-1.12.dev1682406094-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c9c2576c3e81e87c8cbd5271ae720670a5923499efbc7227c4400e1df0e140b |
|
MD5 | d51f6509b858646cb1eeb7a525f845e9 |
|
BLAKE2b-256 | 19a657245a9afa19422cb61df09f56d96fe8be44b50dd350c2a98ed83090eeb8 |
Hashes for stim-1.12.dev1682406094-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac86b562fca104d941d7ef4f794907ff47b09e832676c1bc8a99c4c447ff55f0 |
|
MD5 | b30d4146b20683c518eebfb8952312b5 |
|
BLAKE2b-256 | a5e34ecba1851f3444683b8f2fc5deeff1ebd8acc73c1b609fb1a03eeb33589a |
Hashes for stim-1.12.dev1682406094-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e5e4f192ef41c6ffd1b051af67a396abf158bd37a84d919cac45c16ef56ae59 |
|
MD5 | d3b6634658ca7fecd8d3c82c3b8fd9c3 |
|
BLAKE2b-256 | f7b4672271bc614feafeae661233e60490a9b61f26644991f4ea34534bfc1ee2 |
Hashes for stim-1.12.dev1682406094-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 588f23bca7c73e2b7641486aa771d2396cc8f7412c6e71c0a5f04ad3a4f22b4b |
|
MD5 | fae6be424d4d234eac88e2b6383130b3 |
|
BLAKE2b-256 | ecc5faa2882b9895db259b9bb77bd67fb3fc9096344cbfcdb12ffe54a67409e9 |
Hashes for stim-1.12.dev1682406094-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043d02f70c168be930c5abac0c4870866203a7993f080beea75b43b8e8f9903a |
|
MD5 | d7698c3c542f9629342349e7cab9b262 |
|
BLAKE2b-256 | 04d06bc81e420f99419c484bfe1898c69b3e739ca042b390ce5b754d0d563c9c |
Hashes for stim-1.12.dev1682406094-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d0c6ead880cf9c01845481bdab81eac6f7be0d6968bbe321b1ec1d997d594de |
|
MD5 | 7cb523d707906f699aa1686cc940a7aa |
|
BLAKE2b-256 | 726de7e08824c683bed7bb606376f266b57f4da02f46572b1ecf7df4a001a791 |
Hashes for stim-1.12.dev1682406094-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbcf158d0c4e297922095689a378da277538e880c549fe16beac627cc1b8a27c |
|
MD5 | 8fbe07ad1266fc00b8c1025c7bde5951 |
|
BLAKE2b-256 | 23bd189b6185e3886cfcb1f58e6c68f644539fb7ec660b79af6bd00938c6bcbc |
Hashes for stim-1.12.dev1682406094-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fedb5f4ba2828eebd70db3322d5b756e7cebe43a265a09c52e5bedb470812f1 |
|
MD5 | e54af6ee27b4ff16646978a4d3781ef0 |
|
BLAKE2b-256 | 3271590028d78d64a6fc2adb08f3a7e8cb837801cc758e7fc42d699cec12fdb4 |
Hashes for stim-1.12.dev1682406094-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18e524d913fc47cf5eeac0b97af2b6ae4a83db7578625969ee50e1eb6ae6b804 |
|
MD5 | 29756e0dfc0c252b5a39cc1515593735 |
|
BLAKE2b-256 | a0f0eb6035dd968838271c4922e95b922358c5279cabdbf6b1f0938da02d9c7e |
Hashes for stim-1.12.dev1682406094-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03193391b090dd8baff3eb7ad55b92b41700148e53e635f9c6a6398eec8591cc |
|
MD5 | ad572fd0c5516abb386d36afdbb51b56 |
|
BLAKE2b-256 | 57f2e7e839410a9c824a86924621c06aa8a2663428badd9819339f973663a556 |
Hashes for stim-1.12.dev1682406094-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a72073b19f8fd28f58bccdd191f53adb955d1689dc4d78d47418d1cb794e55b6 |
|
MD5 | c9a2b6010c4c1ce01dcfd75afac4bb1c |
|
BLAKE2b-256 | b3839ca441aa441aa1bf19484101796c1e17920b236c278c1f87a57e57913a26 |
Hashes for stim-1.12.dev1682406094-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8501b4fbf1874faf9d74a60e4696d24963aaef728282d47c13d55cfd042179a |
|
MD5 | 267b0e84c49b34fb983b8ffbab368d94 |
|
BLAKE2b-256 | b79906355235fedb496c83f71a43df049d553b8c670ce1113ee9ef54c1e4cba2 |
Hashes for stim-1.12.dev1682406094-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b93a3abae5d9a2632158f842ea660d8cb462ff94b834d517a62d62a00b049ea5 |
|
MD5 | dd8d2512329f311856d379e66a110a61 |
|
BLAKE2b-256 | f77da02b6234d9a6f223ecaf6bbae12c7b78625a62d090bbe731f51036c3225d |
Hashes for stim-1.12.dev1682406094-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6be8fabed0055c4cf57e39011a336d82b4cb8dade803ae3ecfe02e6c692a2c09 |
|
MD5 | 57fbac7c5dacea019c6fdbddd8922967 |
|
BLAKE2b-256 | 5303859d9e87a897c0ed81b5c1ec20141e13cdddfb837067fe1d99450862fc9b |