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.dev1692487761-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b059f5cca9bd1cf8e07e898498dcedf6175049811299ffc4036ab85300518a88 |
|
MD5 | a3eced0a47969ce1c11ca74ed655b164 |
|
BLAKE2b-256 | 489b0ea792432baa5b4b1cccb981564c9778fbf3ac3f0bebc2a01a30cf1c9761 |
Hashes for stim-1.12.dev1692487761-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2538b3b60a829c1a183f6bbadc1396e24da65a33ab8d0a673d8a6c227abe660e |
|
MD5 | 96fa1da53a9884dc8371d8c26be8caa3 |
|
BLAKE2b-256 | cd94a2d305f6a1b391cd37bf1ee749956357e586c0a9038df4e609e00aece5e7 |
Hashes for stim-1.12.dev1692487761-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 465c6033b51603f87a45e351573415b8a9eb2158f5ca2b89903191816f968cc6 |
|
MD5 | f3100ef0072fe4b3d9e017384ccd7988 |
|
BLAKE2b-256 | eb0137d3e1c32aed3d5f6c8a83918bdaa278eb17f3bf19c383330ddbbcd01fb6 |
Hashes for stim-1.12.dev1692487761-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2388868174cf93f7d91c2a2ff6e87f064391b502c3ca9d304480f4581402222 |
|
MD5 | 681b62651ad8de8a95996a5a4e72a935 |
|
BLAKE2b-256 | 9a93a48d011b549ebfe57736e4d63e2268e868f981eb5f6c5f9a0c48ef2f7dd3 |
Hashes for stim-1.12.dev1692487761-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a52e4f00b145a3da53bb83dd8ab73ce658e07b177bd5c44f1f96730a852311e |
|
MD5 | 14aee40888253484d0518dc2d3f89c10 |
|
BLAKE2b-256 | e6c5a7667ea7042205f4758e586b3598d5a73e3602ce837ff09d74f7ea4980db |
Hashes for stim-1.12.dev1692487761-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d454aa1186faee187c3c3259a063f5d6b07176d02ba9f12710a67241bdba715e |
|
MD5 | d779be6c77d04cd6cfed3cc776f199e1 |
|
BLAKE2b-256 | a0e82e4815ee07e020955509af551f04c4aaff5df6188635b33a835fcc8c143b |
Hashes for stim-1.12.dev1692487761-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a37361f67d6fb85a02ad850a57669269c0c0688e7bf41cd752608c64d392304 |
|
MD5 | ffaa626024e28593e9e3d279bdab85e0 |
|
BLAKE2b-256 | 78c48a384d1914321417d0ea93b3da22dca4c764977992ff8ae07ecbaf1a10b7 |
Hashes for stim-1.12.dev1692487761-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2c50b6c6349c24bb8c4d8213655e3c8cded10c7dc02cc3160f111e9f3000a1b |
|
MD5 | 79a25b3ad7372a79c9789335b203ced8 |
|
BLAKE2b-256 | 24a622dc07ae2772c5437ba512f5186436e9ed48c5da0957acb7eedbbb0f43a6 |
Hashes for stim-1.12.dev1692487761-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bb292f813ce59a1bdd97b87222a1f7f1fdc7788139bdc922da32c43d1c7dd9c |
|
MD5 | f3eb5e578b22d6ec8da04a02cc9e7f78 |
|
BLAKE2b-256 | 5ddf532e0b7fc7f0478611d900311efe56e1d121210828ede1ccc4100106dc67 |
Hashes for stim-1.12.dev1692487761-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8216456b2fd622d516fb51f2690c4def3675184dd015924dd2dd0541d3e9e104 |
|
MD5 | b2528b6fe8b65c274cdea6aa61e7d678 |
|
BLAKE2b-256 | eea13c116d26fba48d0faf0de1e49d54d80488589f0a1a4b35fc3008fae38fa5 |
Hashes for stim-1.12.dev1692487761-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b54fe7e841ad0445c89ba827f1a4d85efb51df207a4473e8ac939d6e515a7406 |
|
MD5 | 61289132e334b8366c4b0cb271ff1d37 |
|
BLAKE2b-256 | 2be7b5f2de28d8ab1568c024f36b1e288fb8cf3b9ddf4ac858ff85bf64ede018 |
Hashes for stim-1.12.dev1692487761-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5441a2d48766efeee4bbb0b97a8c1055faafdf28c807bb08e7a9446b596323aa |
|
MD5 | 0e6f6a59b252dd79b2ec5e6f83801ae5 |
|
BLAKE2b-256 | e5387cc8f78df2cb85120be70102103401a8846a329a03142919cbaf22cda19f |
Hashes for stim-1.12.dev1692487761-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 108edb65f923c9e1c3b4cce97535f7b1348f9547800f8a685114346e6f7d6d1d |
|
MD5 | e587bbccb0f1869c25f0f1926003f5ac |
|
BLAKE2b-256 | 6302342bdb328558edb646638dff77c332d34356f74c5b1568182ce4cd61b528 |
Hashes for stim-1.12.dev1692487761-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc64a29579376f279fbb6725d3d7ebb22a351727e5b1f21479b2d64ee8a36b7e |
|
MD5 | 2eea8f5fc4f9194e68b897dd51bc7375 |
|
BLAKE2b-256 | 4f6e9c8e1c1d20ebf5688758898744d1ce7f79c79ff9edc6e11ce85a0d6e63fc |
Hashes for stim-1.12.dev1692487761-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3dc8662a5717f235c1c7bcbbbb841dd590b9f34dddf2c2cc7a5adeb929f99bb |
|
MD5 | fefa0a8fd2c18e6bf5ebb5c8ff8f9fe5 |
|
BLAKE2b-256 | 74c6c2ba2ce5729ef92f4473f77abd435a4eaa0ceb12414bd43f23be64596efd |
Hashes for stim-1.12.dev1692487761-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32f36f4317c4987d4a6b5415e8906c7dcd938faba668c1243251f617f255f309 |
|
MD5 | 55e55a6b669ec3d31096961e73e02eca |
|
BLAKE2b-256 | ac264c2114724f13882675ea4b961507015b4786af03653f342753a08fde9e2d |
Hashes for stim-1.12.dev1692487761-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583585d79b1e26d9fcc8e32d7cdfc3431bb4f3c7b5d3a466ef3f1c91a20b71f8 |
|
MD5 | a14cefdb3b98085db712abe24b70a3d2 |
|
BLAKE2b-256 | 5534bee34d06eea3178b396aaaef4cdb2f91f8e0b918b4b9b7e590e791a0e339 |
Hashes for stim-1.12.dev1692487761-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe618949c4280e9d3ff4e43d16409b0664f43ca96c10e8c683d0c8d8d9cf013e |
|
MD5 | a1820d70b979ab44031afc89df51e447 |
|
BLAKE2b-256 | 935f26f22a277d2b6907bcf2d54abbed6861f773f13d1d1dca48e118c7d923de |
Hashes for stim-1.12.dev1692487761-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d679dcd5df9d4b2aedd7a69e07379006ef78ec75a0e89c939987846d0e8885a |
|
MD5 | 77aaf07ce33489945c152aea2b16df85 |
|
BLAKE2b-256 | fd41bff519c19ce2881bda26169603d5f3e7969a9249496a8130963c90336358 |
Hashes for stim-1.12.dev1692487761-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d28167d97244e7480004a1bdde54d3a98577944b7ad7553052f3e9bd72e8a552 |
|
MD5 | 47d354e428baaa8cf806e74b5fa57b0a |
|
BLAKE2b-256 | 86a19e438dbd8f827f1979c58953ecda98dbbd8b186048c3b9750fe4d2a6e00c |
Hashes for stim-1.12.dev1692487761-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296bcb29dc235dc49772e7fb6ffcf153c15b03aeb303c737319e0c090101afb3 |
|
MD5 | 184c60c75eb35dfeb0f852eb66153933 |
|
BLAKE2b-256 | d86c4698c482842196dacbe63e80c12690640d182fe3e4413bde2cc0756c93d3 |
Hashes for stim-1.12.dev1692487761-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4797fc199877f00b5626bd70f9eef160f89ab2b418cc8497b9bcd79ef3f99d63 |
|
MD5 | 7b42362547e4b7697db92616d5b09cef |
|
BLAKE2b-256 | 39a4afec5778853686a4410814589942e2798b2d457352325f019cb9662c83c6 |
Hashes for stim-1.12.dev1692487761-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 587e02176f118e3bfe4456811a3dd1dc5b10fb0029e66e2ac92ce0bdefd957e0 |
|
MD5 | 354521c037e154b4356c86d6d03b8e26 |
|
BLAKE2b-256 | 2536e6ac23c9abe83ff765238266a838c9c7e81d4d1cb0a0c185e2eb1c5a9d8f |
Hashes for stim-1.12.dev1692487761-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb5edab42b670ed65f24fdbb79c5e456d3d88e5fe17a407b90fcc982b4e5d03 |
|
MD5 | cf40810a79a5da3be42d493edabf3821 |
|
BLAKE2b-256 | a0ffb7411df0906dc408534f02a389ec5619080534e943ce30ea5a4fa1fc2137 |
Hashes for stim-1.12.dev1692487761-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d281e1b0cd6fa5833836d4fbe4ca387d26a2c21a44ff196e80e64af16cf4daf |
|
MD5 | b5f9c07f035d69d78a2185f453b63485 |
|
BLAKE2b-256 | e29904ddc31b95c51698b1aef910720d561afa28412d4033191591b02f1ceedc |
Hashes for stim-1.12.dev1692487761-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a31aa45695d6fe2773ed2cd3bda35dda94906cd855ab4109e515e5991fd27702 |
|
MD5 | b5bb5f7a0c51cc419f2fc598980037ff |
|
BLAKE2b-256 | c6c596d35036b214d4e4a40138ad3eec3ece3f8ddf555427c48550ca4c552294 |