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.dev1682885518-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73047cd357d2ea71d4d0144285795573f86cc57a9964e910b92369a2cf9211bc |
|
MD5 | 4d35ed3c27659cc79fdb7b0804795a9c |
|
BLAKE2b-256 | 354377b285cb3867abf5ef962ecfffcefa07f9f8a1baf5e9ba81e796202c8d85 |
Hashes for stim-1.12.dev1682885518-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3c2432caf3bdcd73c8c75ed0cbe421ad84a5898eb7a91c015b40a6a36411b61 |
|
MD5 | c72f13990ea4cec5bf16850e0a29f578 |
|
BLAKE2b-256 | c965ab60d065b4e0f3c35b67242872f4df0f69d2766cdfcb5c84addc3a516c3d |
Hashes for stim-1.12.dev1682885518-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368883028d7ba80cb24594069ab2485edd3e1904889ed0a20b6f05e7975d67af |
|
MD5 | 76bbaf9adf3a568b40a06032071d339f |
|
BLAKE2b-256 | 83267aff1334a16e522298d5e754a66817d93e085c03d64dbb55d384b82bc80c |
Hashes for stim-1.12.dev1682885518-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d5b906a40dffb73b679297c54baf54c3e1e10d35a5cfec57a8a6420d4e48294 |
|
MD5 | 2d824e36230d0f3a3c1492f1ed1aecf6 |
|
BLAKE2b-256 | 6830667f0912516317ab62e072930c9ffa749086f6323d89bb5460148d2b4088 |
Hashes for stim-1.12.dev1682885518-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ba0dba62b511547cdaa5cc1acbf81dff46b22f8e2c17bc09f7b6075292ed3c4 |
|
MD5 | 8e73a78018f8fbfcf6f0aba4d6942d2e |
|
BLAKE2b-256 | a463054b04a55126c5c88b08caeba724df0d4177350115dc33f7794b3b69e791 |
Hashes for stim-1.12.dev1682885518-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fac1b34595ef01bb9a4dd561faf9da62d57c23ebaf9bde12920088c3ca8b01c |
|
MD5 | bcb2735d80e3eaabeba8d20244125cb7 |
|
BLAKE2b-256 | 64102d9c3b4756a81b003dda0028923d6b9162926aa8b2a3e5d17bbd742abdfc |
Hashes for stim-1.12.dev1682885518-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe2668d08a1df2c6a4983d88ad129a5612260442b89d603f26b1a90b920ef32 |
|
MD5 | e27b18e6eb3b69df8c26201881decec9 |
|
BLAKE2b-256 | 4af2a38f067b03540e040f7537a74962859684a08cc90a8f9f1818205e9b8492 |
Hashes for stim-1.12.dev1682885518-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ea46c242fc626ae02f5d7a6fda9cacb6dfb607a7d6aa5aec717a6ee6b1e11be |
|
MD5 | c288141cbc071efdc0a6f38193049f4a |
|
BLAKE2b-256 | ba4d6dc834866ddc90c59951b741dd0a73ccd23e774870aee75da6c485cdfb78 |
Hashes for stim-1.12.dev1682885518-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cadcb38b8a110b49f7a1970b823e650824fd02534b6d5272e5a2ab08fca6c622 |
|
MD5 | 2001f9669003702315048a12e4a4ef41 |
|
BLAKE2b-256 | da4c56f11364fa551cc3311562dc86ea1d04bd1e5a06f1ae689c5559f0465c46 |
Hashes for stim-1.12.dev1682885518-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d69b6a830b677ab614004a2c52ef456bbccbed86785d1c24605667e8f924ba60 |
|
MD5 | df7248ca16a5659d1748bd5f85d334d8 |
|
BLAKE2b-256 | 4fa6fcc20ccaf362fafec845b6b58be92022ea3850533eb2147d081f086d6833 |
Hashes for stim-1.12.dev1682885518-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8387c8abad40b8a6be1c45bd002a0571dc1e461f90d5f154067118896c561eba |
|
MD5 | 4bc95e057c6539716be8599903e25a6a |
|
BLAKE2b-256 | 91133199a62e89b3c58b83cabd7a976b898b1b6deb91c1884fdce89b16d55cec |
Hashes for stim-1.12.dev1682885518-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af045e7588e0f0603ca974771a058b570280f0a03d98d3433357b1a82991a030 |
|
MD5 | 0849abcfdf6f2e8abe277455fc33570f |
|
BLAKE2b-256 | 7877680ccc7c69779a48cefb79d7504dbd0d059d7c298d4e427ea722d6aed4b5 |
Hashes for stim-1.12.dev1682885518-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29439cfe8b4930f93712d6e5e052e9087cf0f0b0ee700d08c704515466e13cdf |
|
MD5 | 7e22a1110ae7b09674a4db7ace164f1e |
|
BLAKE2b-256 | 20dab0e3a91971e81826c923be847d9c86a228a84c3336da9d79abd08a9105ed |
Hashes for stim-1.12.dev1682885518-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64111ad264588e0378c395a3f6cbf7781790320282d37bf39039bc691161fed0 |
|
MD5 | 74132e770ad24090dd1a8f3d296ce8b3 |
|
BLAKE2b-256 | 6581e81839bf2bd2704af8bd7dfb5c56ce3467bf5714e2b5e46974477866cb76 |
Hashes for stim-1.12.dev1682885518-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74958bb36cba011c7de3a8521894786a2ec06194c7f3a09b15da75825c21fa2b |
|
MD5 | ec75103a55b6c3237dbb85db668989da |
|
BLAKE2b-256 | e0d70dc71511f3ba3730c8277ed6eefc8f81fdc7a6766e328a4903fe219f6757 |
Hashes for stim-1.12.dev1682885518-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbb427511879c09fb6e0d76ee83b92d608686fafcf69c259f0141e2366ffb708 |
|
MD5 | 66e651db93d87e48c52fe082faf8872b |
|
BLAKE2b-256 | 90f3b5d03206a4bb9032700ee026fab3901a0a6fa9ec93a4f91842dcb8780d8a |
Hashes for stim-1.12.dev1682885518-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f17cd710862389e25ab298c25f243bf5cb7d1a0aa38c8e324fb157013a9c8dfb |
|
MD5 | 6fe2624046114420a42c523dd4927702 |
|
BLAKE2b-256 | 38ccee4bf8763a759706a6985fd1c03b6d67466176a800a78745ce545d2604fd |
Hashes for stim-1.12.dev1682885518-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82828e58878ad1b932818eacb8b0b0de85747078eb385f327936eb81f3e24a0 |
|
MD5 | a478f018f0bd0defe8d654be56485a54 |
|
BLAKE2b-256 | 664d4fa237629c25f824212ca3b4dca9097a1c057d7a4b9f1ed9b4a7471a9c5e |
Hashes for stim-1.12.dev1682885518-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f9386ffce599896cae20c3f3f54c66048b4a4ee0bca9cddbb293080affcf303 |
|
MD5 | 2827913c183d42a5271b8e8bf67475a2 |
|
BLAKE2b-256 | a6feec863984d81871f79bfc237fd58a045dabb53d3415eb2b46ddb6c48e3af6 |
Hashes for stim-1.12.dev1682885518-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b27b7c33ca301d02fdb3633de46a917828f8a7520b804f1b80b38a887d0401a |
|
MD5 | 346c01da69a0d485a8b1015ac708e774 |
|
BLAKE2b-256 | 2beb6619cd5b95d641655cfb450aff18863e34a5ec0f870a2fb960259aeef2b7 |
Hashes for stim-1.12.dev1682885518-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d61cf741da0685a90ff2b2b64dc7bd996e5d7c86715a8dbaa964473e0ea1f98 |
|
MD5 | 03355a24312fbc2125278f1fb8d90da1 |
|
BLAKE2b-256 | 84a9caae4bcb12ed65b6fd91c553f2cde94e7c6d4018b6c8ba652617c3513d5a |
Hashes for stim-1.12.dev1682885518-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d53b38db0d6b0797a1fa1ab36bcca825ee224a9cf68da91cc4c2ed838530b7 |
|
MD5 | 9f035a99f357e8aeb9c353bf8b7c73c9 |
|
BLAKE2b-256 | 4ff2cc676de8cdb6a300740d9c267b85b96bb6181e66ae4b06644ec42d0e998d |
Hashes for stim-1.12.dev1682885518-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f490e73143b17ba2dabe1c065054ac876fdd94960a793e78040570b8a143a3 |
|
MD5 | f89324ddb8723f5485c3c7dc5ecd37b9 |
|
BLAKE2b-256 | 97733e3b15587b80ececd9b3d97e5c490f0779b8f571f04ce399bfeea281fb60 |
Hashes for stim-1.12.dev1682885518-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e80e9a517bbdf16900f982195e61d9d4eab9935e815f007bafd3dec30fb250 |
|
MD5 | 66ecc5b403ea041e4c13e6060d73a0a2 |
|
BLAKE2b-256 | 46c161b01baa31edde8ca7062363c88122c9af859c784f4f0e00bd8cb01b850a |
Hashes for stim-1.12.dev1682885518-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35adb7538b806aeb2c6e226d368dda5ed14f88511d4ff8f6c89cd152ce36884a |
|
MD5 | 8302320b171d5c27969f44d0342b68d9 |
|
BLAKE2b-256 | 559c29e2bf7ac29d2c31c62f6c73d97c5192aa573245f7144498ae2efdf5cf1d |
Hashes for stim-1.12.dev1682885518-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b494d74e75d9af39cce016accc9fb493f82d5cb8d98376d0cf46446c2b9050b0 |
|
MD5 | c01bb3ce48199566ab3e9cd527870992 |
|
BLAKE2b-256 | 921d6ccfbf1cdf7dc06911d7ba0100ea56105293e0ac964a82a027783d0f2855 |