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.dev1688897006-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 394c8a26266dd425e9ca893751b26e5b8478e10caeda36395f137adb455ea531 |
|
MD5 | 80061391bc17d3cf0015c59bec10983b |
|
BLAKE2b-256 | 28206d63dd2df60f679318c0384af6bd3d87ea859069ad3d62b81d65712337eb |
Hashes for stim-1.12.dev1688897006-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ebad70c760afd1b3905a40f428997c2e8befe5be9f577ad46055c50d315ca41 |
|
MD5 | 9b96ec7bf6377dd4742c3d339a1feca2 |
|
BLAKE2b-256 | 21575fed111a9d6c83355344503dad1e887bdce71c7f9e80db8eb984c7aa19ef |
Hashes for stim-1.12.dev1688897006-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 618b510c9a9c307f93c45e8181c94d84eb89cccd1873255af68863eeb712d2c7 |
|
MD5 | d4ca08138dd7704711ef528359f2a899 |
|
BLAKE2b-256 | e83cd5781e698aaf3eb330514d393129b0514cf4ee7517df3ba79960ad21a8d2 |
Hashes for stim-1.12.dev1688897006-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e544e8d38ca07be17af1dce49eb816918d95f3a1f526b34ac4faf29128a02f54 |
|
MD5 | 59b00c9fe91a4a775ae14d56a27e60ba |
|
BLAKE2b-256 | 5ed180ed1c6d5aec8dbbd8a9d4418e682ed1b7eb743efd1b4eedb6f0e984090b |
Hashes for stim-1.12.dev1688897006-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3dc2eb41bb2a1e38bd45d5a5b7a068ea2431cda5b05819a7611c90b41128f1e |
|
MD5 | 5559d58591678feec9a9b9986b0974a5 |
|
BLAKE2b-256 | 99af3bb2df37a21bf453b30f8721406e072028648e88231713f24070d72220ac |
Hashes for stim-1.12.dev1688897006-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5e32b2a7f3ddd30b0ca2a8807a68731ad58f9d72da4a39dd75a60b21ca113e |
|
MD5 | 86a02d1fc6a1db38e7292c81c0692143 |
|
BLAKE2b-256 | 31f28fa44534d66dacab0de404d2464707aed29c3650223645f56e13adfa72a3 |
Hashes for stim-1.12.dev1688897006-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32211fac166200d08834c433fbbfb1d1645d39978821972ad66f7f6221733a96 |
|
MD5 | 8305bccabf49884117c854c608aa7c6d |
|
BLAKE2b-256 | 21febd8ffc435efebe96cd23e7cebee42c5eb4fb3ea8f5d4986e505c417f5b9e |
Hashes for stim-1.12.dev1688897006-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f4e1feeb1cf04a5093441f76dd2e39588b05566fd091793b3c6771c78ef41c9 |
|
MD5 | f7baaad241f65b9b7d1093918a5edc33 |
|
BLAKE2b-256 | 7b2ccaa6072804ec2402cc9d53507746c7a7c4efb0c3f32faa2c3dc789f73d34 |
Hashes for stim-1.12.dev1688897006-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0334cb52999867f5a4625260d22aa10ea21f8932da37c99138af56a24a440a8c |
|
MD5 | 5da668aec36774dd2edaa2ced9fd6fb7 |
|
BLAKE2b-256 | 21277e6d24e90e0474d71c015561b432c832e0baa4fe6e18f5a0aa1e18f6278f |
Hashes for stim-1.12.dev1688897006-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ad86235a0223c16b307be52cef5bc6c5cfa169969aa1f73635219316ddf356 |
|
MD5 | c5d404b77c7a779b18b6d09045afbaaa |
|
BLAKE2b-256 | 63cef8730c7f1fb7fa2c3bc9b49f7545f0432887a087deb85e76ff736e81de1b |
Hashes for stim-1.12.dev1688897006-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c61cd2a7182d2a35cbe416b2ea873e29f4d704d64d484dcdedb1f5899fd68b2 |
|
MD5 | d802070fa688111a6d2973371c4dee49 |
|
BLAKE2b-256 | 9b60e9c2415bdb1ef30bc8e30b9b4054514c166c6feb47d2bc2e495abc85b86b |
Hashes for stim-1.12.dev1688897006-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e3572f45c367e1a10b747f51a18b6a9e4e287c19b758ee607399dcdb05de3a |
|
MD5 | 4f1cee8d4c92415b74c034fc235307fa |
|
BLAKE2b-256 | cfb078cd1e2a97431fa18ab7718baece88e82be1e0677e5464e0c62856f5ec23 |
Hashes for stim-1.12.dev1688897006-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb38a43bcd1602889d486336c2c8803f86ab3d43414a32f26de75b45ee1883f |
|
MD5 | 2506c24c568bb05b4e42990bea450593 |
|
BLAKE2b-256 | 3bb56dc87e8a509c436c19ca3d7d240367ef8d964b6647a5fd3b29c512b1ec88 |
Hashes for stim-1.12.dev1688897006-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca0dee44677c249f84d361fb990ea9e99e8a178538153f677ec9a64166bce97 |
|
MD5 | 47843af78071c396e7457f7034732028 |
|
BLAKE2b-256 | 179f78aa46480d5289dfe4124c0758d844b89200aa9f6eca66492952e8d0560f |
Hashes for stim-1.12.dev1688897006-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcdfe881fc2b469475ed71c92f60a26e1a76fc433222735811780c0d460dd1dc |
|
MD5 | 3c13faff41d1eb63796efb2cbe5943d2 |
|
BLAKE2b-256 | ac744225e2688966ccde555ccc70b777b5a84000d4c7588f3be5bd2d6c843bc4 |
Hashes for stim-1.12.dev1688897006-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f105e56d743339fabbe4f1f91d9d0e75553b14f37a32d2a6df13c7de10af0f90 |
|
MD5 | 0e8f9d3bc8f9fd2b7315388af827188a |
|
BLAKE2b-256 | b10720f6578a7c1dfcbf3f814b4a2da6ad808e0edfa086a999b2722ad4a44dfa |
Hashes for stim-1.12.dev1688897006-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409ea1b847638d5447458c8662337f3782f941d5fdba8e39aa077f3494e57628 |
|
MD5 | d7997bc43b42baece37a765e3d88abd0 |
|
BLAKE2b-256 | 43b3a4a11789da26dcdabeb7789cb9f1905ceb75cf69be9cd317f1e5e12696f3 |
Hashes for stim-1.12.dev1688897006-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 543ae26fee0fce4387208c9aa6dacc814f22db34b7954e078ced37b26d1445bc |
|
MD5 | 7ed92cd0a406bf040f047d66f94e88bf |
|
BLAKE2b-256 | 87c41ab04ed650da3295442fb51809d7c2834a850a1e6143f070e427b58b5dbe |
Hashes for stim-1.12.dev1688897006-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f472e5384c5b17fbe9caaf770fb800e5d4f623b61b0b69d6a9f05871bdf496a |
|
MD5 | bcb125be95130bf5002b7f84f4509975 |
|
BLAKE2b-256 | 713509277df876f1a12fb513b98277f7b127df150c277bae968b33efa4692508 |
Hashes for stim-1.12.dev1688897006-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e478e342bdffa3953821c36c10ee9c66e0e2d040b879f22967b3a453089cf8cc |
|
MD5 | e3de1079e9f95c4101761e767b18f677 |
|
BLAKE2b-256 | d4aeeaf3969eaa41acce35416adb127c9e9c4a9f1af38e9e43b498abe7abe76c |
Hashes for stim-1.12.dev1688897006-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a97ec6b907b4b90306ec9587b763b62b7c9760b212caff41987e5339bb896ec1 |
|
MD5 | 339743bc2167139828e82ef0ea7a6ffd |
|
BLAKE2b-256 | 051c1901b21503b1deea4d269ca91c6064061a88dbcb46f1df392b7d7891f9dc |
Hashes for stim-1.12.dev1688897006-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2a799acd86d69a7f57fbeed96356a1244fb44dc651fdf369019e9fab6bc1aa |
|
MD5 | 31a64d21f71df944317d425f3d17bbd8 |
|
BLAKE2b-256 | e3e6458df8607384b5047eeecc783ccd77b6015516404b66156ae673139cfbad |
Hashes for stim-1.12.dev1688897006-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d097796ca5b130155b9964cc90ce874b5d450668132cbb8ac1bc4274f484edd7 |
|
MD5 | 609017fec0464678b2bcfad327319f99 |
|
BLAKE2b-256 | 6cc49e75f4d83de5b614f017500244b7a98f221a7b2e574178205892eb6a508c |
Hashes for stim-1.12.dev1688897006-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e71c161e436436b4297adddfd6fdd02feee7e81ce291af1de66f8f900ba8de2 |
|
MD5 | 40ac3b3c75e2efab29aa3af44cdd8649 |
|
BLAKE2b-256 | 341e6defab79bd4fb53fb9d966cd1ee8faf427a4b63ff985c6fb116de0005de0 |
Hashes for stim-1.12.dev1688897006-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ad9d34ac26bef2bb0f5c57379f703ceb27b101dc58caf4ecedb36fd116058e0 |
|
MD5 | 6d26e0af217438e294cec51c1d5a2b99 |
|
BLAKE2b-256 | 5e41e800ad182baf228f9e244abc2a3c36fefe76bf6b8390b0e2fb4027e6c20c |
Hashes for stim-1.12.dev1688897006-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0622e4247551807581d9b8b542507e2471aa4506ac1d0f4dc332c9ae7e0350d5 |
|
MD5 | e921ee6321bd2056df55d6db98a43a76 |
|
BLAKE2b-256 | 49062b4b91600ffdcd796d6e8b40933dfd11c33cb12c82cdb80f8fc78d74ac06 |