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.dev1687378421-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac520cfd6d9d0d615dfee4a3297509d761a76da02ee556ee7d71fc1f9079d1cd |
|
MD5 | ef642d5c6074d804c55048c8411938ff |
|
BLAKE2b-256 | b89c55086cefab030dde7c2069ea7956d3b6310e8a249b015a6c5157ed73dcc7 |
Hashes for stim-1.12.dev1687378421-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beaea354652988b0f1787c01fe384364eb4e9effe0bb820dec0d8c90bd1d1351 |
|
MD5 | 152b133c542b566a17714232959a5560 |
|
BLAKE2b-256 | a3c34e43d5c73b453a37c83ae60a8be9866ec4915d4148e523a09cb48e980d1f |
Hashes for stim-1.12.dev1687378421-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29baf718b4d7f07f84f3ca6d858ae913b99f64e939422ebbf4a4328516e02f87 |
|
MD5 | 7103e02e7e3f8fc55e4a1a16eeae7262 |
|
BLAKE2b-256 | 91fb78fa90e2e9a0f73a5af18d0d6ebaf0ee48cd94239d1fff0a5b14247ab11a |
Hashes for stim-1.12.dev1687378421-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 335db667f6d93bc1348a590e19e89c1ea3cffa7c0d2280619820a84c7fe44ce8 |
|
MD5 | 04b254a1d636093b5c5feff15ba8b15d |
|
BLAKE2b-256 | 736c2126edeb3104f2dad02b3b2b62abed3c06ebb250fb6db24775190577fa5e |
Hashes for stim-1.12.dev1687378421-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df00e42491c760b68e70867d1eb7851fac39df1733bb77331787ca84842259e1 |
|
MD5 | 6cd21fe830148d3624b91d78d4b43e8b |
|
BLAKE2b-256 | ab145155c679f1d46b8583423940aabba22ec1c745cfb70587c549f103736973 |
Hashes for stim-1.12.dev1687378421-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d7537bed71c18617e73ad7a2fae83b075f1b0704c16b1b2e2e1f0570547538c |
|
MD5 | fb662cd1eea531294bb57ce146a44637 |
|
BLAKE2b-256 | af825238b54b93230b73531756a715bca4744475d5dc3e13d773805bc846a4df |
Hashes for stim-1.12.dev1687378421-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0803df7e1a8160102c0dfe2c7d7b0e25fe30086ea4937196667c7e7e732e0c |
|
MD5 | 59f9496fe2b6b97fd0672e5c4270b411 |
|
BLAKE2b-256 | 3542032b1e6ddcd9c27cdbc8a0a770a869c772766495a4632ac92fdf938ee887 |
Hashes for stim-1.12.dev1687378421-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aa634244dd3c17b6497b8589652fef80189a9b21afaeee233ff28309bacbc5e |
|
MD5 | bab050af3c9f131d316cfe388e809120 |
|
BLAKE2b-256 | a4d5867c4a890b837e67b93af2265392a890cabfb50205aa60f2f86b9416032c |
Hashes for stim-1.12.dev1687378421-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d41b353ecfaed7d381d1ed6e2ed4ef343a9152d2aa33aed8e4cfefc6c2f9f1 |
|
MD5 | 6598782b4ccf3e90c36bf04ecd3b0e7c |
|
BLAKE2b-256 | 891daf3c94c4bbc871c246fb89f160f90275b253e1d70ea9c0323a84971ef79c |
Hashes for stim-1.12.dev1687378421-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c6d5c94474889186ee26d57090fc5ae02c898e22cc3c0f4a9d15f18792cb172 |
|
MD5 | 308856ede7707c0d78f00eca5cba8e50 |
|
BLAKE2b-256 | e4a69d7c58e48bdce33bed7f7794c560cc35144fc4fc7d0fa47c5227ce735d98 |
Hashes for stim-1.12.dev1687378421-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f529fdd930b55e0fd26d59580439b4b85f0d03388a8505941a76c817b0e8ff6 |
|
MD5 | 8300fb251ba97b6f810fc2b8a82e1c07 |
|
BLAKE2b-256 | 4b6349911ebbb39f3685cb085e99da949b5db5fae5b93c100ab5dfad187c9a4d |
Hashes for stim-1.12.dev1687378421-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4553defcca3229aa38f8b4b10566f3a6858f4c79090d735a9a27b641d1cbf1 |
|
MD5 | e9bf94f5c9d6ecbf767070e3035c5628 |
|
BLAKE2b-256 | 1d192b6064351c6f775c3ee6eb14fffb61b8dbfb95a13bb5c74e32d7f99d4467 |
Hashes for stim-1.12.dev1687378421-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ab17e52e4b2e7aa2675380ce8b17b1d5e1edb71e5a1e457a888d6df66e4c0a2 |
|
MD5 | 3a46ad947c68891169f2fcbfe4e9aa1d |
|
BLAKE2b-256 | a332413da58a73417000243f4aeee15e5fa18325122855cca931fa77c45100ff |
Hashes for stim-1.12.dev1687378421-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d88077447d8cca88f0242b924192695df47a2775634a46eacc659628d2dabf |
|
MD5 | 40917ee90ea17f226050292269f4a15c |
|
BLAKE2b-256 | 08df21ab3dc39d694e00289505dc5d000b4a87a7a0421a90395447b544a619b2 |
Hashes for stim-1.12.dev1687378421-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9248890fd6e18b09f4a17cb41c969501a186c18a34c38dc1c48a22b57684b314 |
|
MD5 | ad286c4842a9479d38fee3a75234cffc |
|
BLAKE2b-256 | 5d696907f900228a9151c7b91220f9aa299d1135fae5ef3ad9a6dc96af758957 |
Hashes for stim-1.12.dev1687378421-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a99633857be1e8e79f7aa327d74a3e46ccebdc019cc8ca6060ec4d4243140a9 |
|
MD5 | 2c3e129a8db8a745b3d62f976383a91b |
|
BLAKE2b-256 | 7a3318d000376d55d65d540d55175194b5d86462d3dcc49d905a97daefdb536a |
Hashes for stim-1.12.dev1687378421-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff8597072fd584ef85d45f71e0988cc24f84a3f228295308ca1e1881bd0873a |
|
MD5 | dd7d64573321b9497f5f521f1e787014 |
|
BLAKE2b-256 | 647af100d7714b4e8c6896f827dcf842cb95d2e1f131a9bcd9d507e28ccc40b1 |
Hashes for stim-1.12.dev1687378421-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 543732f6eabbd08eea7655bbb1c8f0d81b4d20ea43a5dbecfe06ca39f28fc9ca |
|
MD5 | 3c834572280005075fbd35d225329778 |
|
BLAKE2b-256 | 8999ffac5ae1ca277593d1cebd2ab185ce0265ff28bcc466b90fe32d3189e77c |
Hashes for stim-1.12.dev1687378421-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 102de51c7297e153931e0a8275ba38fab19fc08a01c212a662c8ee101fb700e4 |
|
MD5 | dbbf4935f097a9919f00ca93ef7f4d71 |
|
BLAKE2b-256 | 53e85556e4cd0d85c65607a5a4cef14a8cc349dd0a6c471172790ebd093ebfc1 |
Hashes for stim-1.12.dev1687378421-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00c998a61827049cc265db8467191ac35c7d01345a9013071cb176219cbd8798 |
|
MD5 | 471413053f93f58024b8ac96481fdbe6 |
|
BLAKE2b-256 | 872d3ac9658c4b7dd7b68305fa8a3fcf77bf9e14aa7ca5296fec86ae292c53fe |
Hashes for stim-1.12.dev1687378421-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 930632173116f362567d8b768003a39264787dff97fe43371ea2183d839a8f24 |
|
MD5 | c8584e1229644534b1d18148040620b6 |
|
BLAKE2b-256 | 048f813c53e7abacd28a2a1f2f8c48a5241a17d5af637551e8b4a2f1fe05a758 |
Hashes for stim-1.12.dev1687378421-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c5fdee5847befbe97aa4acecddcd79e336ad87050afd9563a0a977cb01a1b5a |
|
MD5 | 124a6c2752923db06dc0fe5d1bdb9f40 |
|
BLAKE2b-256 | 7de4d7d0c6bbf8bac414535fd4908b729dc322911b795cf050939720c13bc903 |
Hashes for stim-1.12.dev1687378421-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5cf497b46b3339b51d3eab8e47f1679b4df4c36a1c3b72e4b47e6dfb2cc0ddf |
|
MD5 | b7742cfa33cd7c86d0b1c4fc278b7d5a |
|
BLAKE2b-256 | 901c61371c01b66ebb94a3a7d05426280f822578cc49a1fd6822c4705f27c046 |
Hashes for stim-1.12.dev1687378421-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81bdf20dbd9825676b221f906de836e47db91e9ffd5bbb0f0171fe25de05acbb |
|
MD5 | 01687d8191d4b6c1844732b2b7502e90 |
|
BLAKE2b-256 | 9fa4ab0d80c7f0cf7dd4b38823788f2590979de4191852259a7917455b570c22 |
Hashes for stim-1.12.dev1687378421-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 321ea563c3134a1a5434305942d2549012840483583847cd51bdb0a8fad4414b |
|
MD5 | d2d65a6af00112abbb44ed623de5a306 |
|
BLAKE2b-256 | 1da65efbbc5b58c4a98dd005691f43d83c5b3b6e88efd5b3542eab42e14695b1 |
Hashes for stim-1.12.dev1687378421-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b7b929d3909ea4d5fc5d00b0017e8e8911e5ccea89c4338538551d822cd0cd |
|
MD5 | 58fac9c5ee952ae4968fcfa9d0295f89 |
|
BLAKE2b-256 | 0ecfc8801bda59d3f48aa292a2ded9df3e5ec9fd2e0884dd494510cad2d2853c |