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.dev1692338237-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c77dc5196bc9dbe32eaad50257053100715f9dcec0861274a5a6b86bf07ae7 |
|
MD5 | a59437af1a5cd7558c94ab14dfa3d465 |
|
BLAKE2b-256 | fdbb3c5eb579c55f6ab65c8035843f01e9382a0e1e70d4bd680fa3d746bfcfa6 |
Hashes for stim-1.12.dev1692338237-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da35a866692c52f1e75aa2d1c60a36b54b23c222b325c272657939cfe2c97621 |
|
MD5 | d995c9da9e5d425b3beb8a0f67dd5adc |
|
BLAKE2b-256 | e100369d9adf3fd3eb38cc91804fe8f0f502dce19fbbca0fcdb793531604d775 |
Hashes for stim-1.12.dev1692338237-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96af0e73024044063eb4d0742af6ee2336a2f963c30945542fc4bdbc2ec0fbbc |
|
MD5 | 89ec17cab3790c1436075377b26f4dea |
|
BLAKE2b-256 | ebd0e7fd26b546c2d65086ca9b5786f02928bfd3f81496de7a1fa96f57be2c06 |
Hashes for stim-1.12.dev1692338237-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48ab013fce1d3738714f26169ac8bdafa38d8f24dc08c002e56115dac80abde1 |
|
MD5 | 2f02a8f02de1d65ae76493bc0061de31 |
|
BLAKE2b-256 | 50e796398e3c173bfca14cf7dedc8c0d5f400ab87b3ff5f3f4e218c638837938 |
Hashes for stim-1.12.dev1692338237-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb7b7be578f2b06fe7e8f26f55e2e718f79c7a5104ff55b0ac0b3de32675b0a |
|
MD5 | 17806b2083df31915c52fc87005ebd36 |
|
BLAKE2b-256 | d7c29d587fc7ad677e2ea2904afbf8f0b0728bd6a349d54d8115c8848bf36ac3 |
Hashes for stim-1.12.dev1692338237-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef9fcae8b7e4bc158a361832b8d7500fbc96e482bd857b5565db6fac0d0cba15 |
|
MD5 | 6c67fa2d0ed474bdeef8394185163218 |
|
BLAKE2b-256 | b1b871bf72d7f411c5cd82dbad134878fdd09de70ee0d8e4c58cbcaac3a131fc |
Hashes for stim-1.12.dev1692338237-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25de9feb1ba1ad5b209052f829987762fc19081502603476cae0c47622ea0bf1 |
|
MD5 | 8751bb3b6489f9edfe12f157d9f4f0f2 |
|
BLAKE2b-256 | bd511de7e3d8e337896b428b5785ce1cb65029263cd153b0e3a73039da5ee441 |
Hashes for stim-1.12.dev1692338237-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef629e2b5a0490e547e8cbaada5f540ce0e05be88195c7509523734341002a90 |
|
MD5 | ada9acd57c3aa4def3ef2f158ab6e7bf |
|
BLAKE2b-256 | 44491510780f27469ae67abe04a28043c695e22d2b81aa7facd5aed8eabcdc6a |
Hashes for stim-1.12.dev1692338237-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a1834dc3ee24dc629611382d35d2ef22b64e8343087bb6a84f8347bf3f4797 |
|
MD5 | 10a5d87ef3e5f36c0fcdf6e54d3aa39e |
|
BLAKE2b-256 | 7a807ab63960fbbc187687efe761f51d80ff7b6bd56bd726c7f44dac9092aeec |
Hashes for stim-1.12.dev1692338237-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a8f557b45ee4d8fe281a7705c807259233251ff4b1522409ddef9832e95d808 |
|
MD5 | c785f33ef4c97e38441d8bae30ff0943 |
|
BLAKE2b-256 | 078f7c7f16f08b22466910aed928f644fbe6791dbb163d84ae0dd31721fe0523 |
Hashes for stim-1.12.dev1692338237-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e61f5ff5ad1a0e80121e6d39a93d475bf7a72b4d78cfc587191345ccf8fb105c |
|
MD5 | f280a79c3ec7e3fa0c7538962032c3b0 |
|
BLAKE2b-256 | 4fa70b6bb38b9bb854e84e58628409a1aa097069173f561240b68c08767e17e3 |
Hashes for stim-1.12.dev1692338237-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af710d89bfee7d3e643ad6383a600177f6121fccdb5f1283e1e80464f2ba062 |
|
MD5 | d42a5fbb7b41b1fb0fa61a81a22b0896 |
|
BLAKE2b-256 | a3ec6b2ed00bad78ec21ae5a062aa1e08b7d3398789d42728b60c293f0fe9997 |
Hashes for stim-1.12.dev1692338237-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc1aebd82732a6b980caa03f081dd9427c2eb650f85c284c5490a244a1ed6a6e |
|
MD5 | dfdb8bda81658a9c8a7047522e260b7b |
|
BLAKE2b-256 | 97a116f2200ada2a71dca6359a23eb348361617d532eb119f5deec5398056b3a |
Hashes for stim-1.12.dev1692338237-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e9c74b2fae7c82b427d4630a56b092135438a15250d151447a98c2071ef34f1 |
|
MD5 | c6fb24e396b8b83f45ebd52606a19e2f |
|
BLAKE2b-256 | a0ca738ae4b3cc7607549106703d3abfa821ea23aa24791aacbf7ff5afcba5c9 |
Hashes for stim-1.12.dev1692338237-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b5696af0f94dedf6c14c74cc5aa40f25a8e673e02bb1dde88697fbf55a7694 |
|
MD5 | 73905d8324cb087fc72fc64476f10c5c |
|
BLAKE2b-256 | caf6ff137fa193c05ebd511a042f0da68e5a4a1f5cd7986bed7731ece6f2934b |
Hashes for stim-1.12.dev1692338237-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce9c7a9b18c0e597d92b1b7a71e5ed5a0ea2209a94c1cf7738101eef6ca5c667 |
|
MD5 | fa439c59a01751c49b98381e52d746a0 |
|
BLAKE2b-256 | 6e8d66f0a588d3a6c618c8ae1a16f701722bf07198d61cfc480a9dfe7e132a1e |
Hashes for stim-1.12.dev1692338237-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db655aad7a150d720a7e0d52cd30fd499e51767a2109df8b673d66be129153c3 |
|
MD5 | cb253a52a3d1061d1da8339abaeea492 |
|
BLAKE2b-256 | 204d51582fc71544003c0156ad2bd63e2f957cf21f92a98b29d2cf61996f9d9a |
Hashes for stim-1.12.dev1692338237-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb692eebc92b9eed8f32ad7fb4653eb09ad9694b4cded30fd71c0a2539205c5 |
|
MD5 | 929b21b30e859f0f3f44f1b16fcd9e32 |
|
BLAKE2b-256 | c3821af58cb2bf54482c5908faf21e905865f592722daaee2bb14054354e2b17 |
Hashes for stim-1.12.dev1692338237-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c09b52642feba53eecbf6feb39a70ce1f0058bf421368313f6f2013c66b0f2 |
|
MD5 | 82df3b6aea3581ed465bb3433bfa04e3 |
|
BLAKE2b-256 | b4582c78f45e01c39d78704f6e79ded4a84f0d6cf00b7457f330b5d3b383a8e2 |
Hashes for stim-1.12.dev1692338237-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ef27e5292042c24e172339f99802b60bb0fb230b0d9c88b3285eb07e43bd55e |
|
MD5 | 4f23a6b642144510cc34ec7bf97c268e |
|
BLAKE2b-256 | 45a830b1508b05284246ac3ddd3ceb06ddc9fdd27d83fe27397f05d680f3873f |
Hashes for stim-1.12.dev1692338237-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b8da4574c00e96860cd6ed00c785d9ec2d23a44293b0edb1321a333da36d37c |
|
MD5 | d7db55159baa53534fdcf1b8b595703a |
|
BLAKE2b-256 | acbda4ebcd845a36b18cb7607ef784adcacffd9e72dfd75243ec15a75e7fa18e |
Hashes for stim-1.12.dev1692338237-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b7c7de0778a1f37dc1f106133bb0bfaed61790e9c03433188bdbfbc5d5e7dae |
|
MD5 | 2138bcf80afd242b7f569d801da0f855 |
|
BLAKE2b-256 | 15c0808d24773808dacbc866a1a3d25b25cf42a606c0d67e86a5931222cc84df |
Hashes for stim-1.12.dev1692338237-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eeba0cbb58ea70148439dd730b00014208e8458a2a6c21f23e87475f9e65d5a |
|
MD5 | 837916f5d15f15c0c38aa3ba9f7d5455 |
|
BLAKE2b-256 | d6496bf23ea82241234d98784a7aae86c37996c3dbd1c46bfa33ffb94a3ce108 |
Hashes for stim-1.12.dev1692338237-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f546dd142aba7d3f4661cd15aa2dd8a546c9da44b1be34bf91a6aee272b9292 |
|
MD5 | b088d783a97fde9fe811fcd2141e3219 |
|
BLAKE2b-256 | 3c07dcd25ae2b71daecdbae1cdea62401d3e6fd41bac09d9077cf3e734ff960f |
Hashes for stim-1.12.dev1692338237-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f804cd4fcb74bed9d664213c244e53ec2883958ae14795c636ddb61fdbb2385 |
|
MD5 | 8b8da7e9878797168c247f3314fcab95 |
|
BLAKE2b-256 | f5684497b914f3159a82db539089a75a936d46b6c21693f9f76a0afc5464afd2 |
Hashes for stim-1.12.dev1692338237-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5787d78547d4b85c44abf1ba41635bf5269d5e03a53c7d419e8aee3bf8596e99 |
|
MD5 | 14e140782b14df21803e911a4f06b9e1 |
|
BLAKE2b-256 | 4d4179b89d2d2b7fde6644082763eac00301a000874ab08088583b19439091e8 |