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.13.dev1700354855-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd8c2dbd56e64c35863bb6face59636deff14430d0b31914fded23164a67ccd |
|
MD5 | b45d3bbe9145d5b28615322d733d478a |
|
BLAKE2b-256 | 2010f5fcdd0f07d87efd18e0bb4efca644c2d1867474292bb8c52f085c60c8de |
Hashes for stim-1.13.dev1700354855-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e90852c3cacb02e0d6a060e8cc7b41fe18d23492e94a2df4ba68eae644c975 |
|
MD5 | 6430af25a90510df44084821d43a9a89 |
|
BLAKE2b-256 | 2bdaf4d44712ef4e6659649f8b3760b66aac9979d1fe705019005ef1363ac975 |
Hashes for stim-1.13.dev1700354855-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67805a7c308fa4725228280ca3acaa1881643711e529dac8b2979a449755ab76 |
|
MD5 | 093ed997bc67c6b9157b66e850060a58 |
|
BLAKE2b-256 | d2fb15dbfccde8d70646729bfdc4d006e154495b8733aa289b482b1821be4f8d |
Hashes for stim-1.13.dev1700354855-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a532fe6797adf2097ec1aaa336c031d0a585059e2a55e217bcff5f7893c954 |
|
MD5 | 978fa505f6c8ddeb906bb2135cb51b09 |
|
BLAKE2b-256 | 0247bd13a3458add9762e9f9f841b679b4d610e48828186e8de3cb71ee40cad1 |
Hashes for stim-1.13.dev1700354855-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aba0e1cdcc438e4b65ec7e65e8120dc94ed9f9c7eb0d1f4be11aa3bc97852191 |
|
MD5 | 97c43196574ba47e34cbcffa63801145 |
|
BLAKE2b-256 | 657b2d3e2f19e7172a545847d29631193a405f99e31af0742a8116cb275b81e6 |
Hashes for stim-1.13.dev1700354855-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 559111f2badf92c1c18c403f45b9513c0f6baa59128f5cb422ccfd7cdc6987e9 |
|
MD5 | c53563ff5016cce0c34766c0af15ce9d |
|
BLAKE2b-256 | baf008fe8e86af1c8e736ffe16db5df5952c9baadee066438a3eefdfa121b617 |
Hashes for stim-1.13.dev1700354855-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c01f07d3ad6e657357e9e7739b052b62d40fd197e9fb55fb95f7ed6c58575e |
|
MD5 | b89c6d91f087bec0f6b101ed056ac22d |
|
BLAKE2b-256 | 705a3cf88ab73c5b9d84a0acb03ed2ac666a069ebd4a98ed55abd4363f85b5ad |
Hashes for stim-1.13.dev1700354855-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d4d8e8eb22d9e37f7e1d0dcf1359d2ec39534af996f0c9089a1e655687e110a |
|
MD5 | 837adcaaa21c60b7a443b33f2a1f75ae |
|
BLAKE2b-256 | fffa79965d5109faf7cd48b9f86aae0c010890ec1690ace6501b0f230ec4f79d |
Hashes for stim-1.13.dev1700354855-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81bb636ee2d000522146b343193450dedc11012d74a122de051c9349742145e4 |
|
MD5 | 76fa404f538b8f1214e75d5902100207 |
|
BLAKE2b-256 | f448af6f5d9ae5f9fc86ab2a460032d80e345b8f198df6ff8b71c15c1d2b2482 |
Hashes for stim-1.13.dev1700354855-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec7a0f59e5a7ee6bab08938cc60cf2adceda88dd519c18ae3a2a661c18e3db88 |
|
MD5 | e68d611871cd61561d33ce1ed9e2624b |
|
BLAKE2b-256 | 25cdadd565a8cc8b02f352a135bba15c1ee244d56a19efcf81c3a7ef1fd55025 |
Hashes for stim-1.13.dev1700354855-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09d309fed641c0aec1e99f0a26ad3c4300bad73d361fa8534ec1503136767d8a |
|
MD5 | 0a4b2ad45cef6bf71270d7c9a32a9bce |
|
BLAKE2b-256 | e11b03ce85528d0f108ee3876f89c3acd366fff8c77b29771fbfce96e417b3d2 |
Hashes for stim-1.13.dev1700354855-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc59fc497974fb9efd0bbc772e609751b96a5e3f49963ca913dc3dae5f89a18e |
|
MD5 | 196131ea05e85fe378901ae4820bfa96 |
|
BLAKE2b-256 | e69ab9e2907304777a303124883a5784dff143b984c85c5e8035366131a3d2d8 |
Hashes for stim-1.13.dev1700354855-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1934fa4183a324efafc94691b0b357d05a770c7c6799bd391e0d53e3a934638 |
|
MD5 | f55751880bd32aa32a65c58c0728e25a |
|
BLAKE2b-256 | e8c461f8d40b4d216d6b9bc60b9a5b093e16532d6b4ae0ffe8d2ecf90d54b4d4 |
Hashes for stim-1.13.dev1700354855-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df7d5242dd20c40ff12755f31c05e33388e61ce44898f289123f7105ddc60b69 |
|
MD5 | 0dc0bc454ca136bb71cdcd287bb478b6 |
|
BLAKE2b-256 | 5f6d0772474c0704829bf8d833380670282ad434a4cdb471fb5b49a4a7bcb31d |
Hashes for stim-1.13.dev1700354855-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83a6761eebd7bb2a5cd79221e5e01ee88e6cd083ca3212bd7b5625832b23bc3d |
|
MD5 | 35f5796e9cb45879ada2aecfdf84b083 |
|
BLAKE2b-256 | aecab758bf61b81ce7a6a813f070b80fbcd169e692cadc285f428763ffc8efe7 |
Hashes for stim-1.13.dev1700354855-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ac62fafd965cfe215734a7e1bf93dd14b507ca14cae056c574fef1386c14843 |
|
MD5 | 031b9a7dc4b6c621bc5bafb8ed78cdbc |
|
BLAKE2b-256 | 5cc5c20239e8c8801f81fe946fc8ac47a05194fef853041488f58c9f44c91c6a |
Hashes for stim-1.13.dev1700354855-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5caff661de9ff03de5080f0959c20a68d749c1a3eab9b1f8b87f4e7cf21a624 |
|
MD5 | 46768a5a80818249157ee61accafafa4 |
|
BLAKE2b-256 | ef6d4ec0cf70363f729a5559ddd9a4279b186f3cdd66e36ea55760d0b59b9ceb |
Hashes for stim-1.13.dev1700354855-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1de2ab5562195a4fbc75d3f11715c0fd2ca9262f5466a9282e25653f80b35165 |
|
MD5 | 3fe0a19954ca7d4b7e41130e222e2792 |
|
BLAKE2b-256 | 8ee7f36171717274f03ae2d89c33696a60908f3b56c645a687fb10cccdbf31e2 |
Hashes for stim-1.13.dev1700354855-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbb645d29595733e9a4d83142d13ae86e149498d411cf7b77c08c5ae2e33c941 |
|
MD5 | aabf402d3f3509874496f1526e104505 |
|
BLAKE2b-256 | 4b2707af9b176f3c94e350cfa801dd75fae5c668c16451dddef5d7115b8b549a |
Hashes for stim-1.13.dev1700354855-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7983459480290392534508eacbfa87ec4b8dbdbfa41c18118b924a3f4d80b56d |
|
MD5 | 3cc63d119352ebdcedee013a1a467b7c |
|
BLAKE2b-256 | 90964a5a1802a0058bd15a994ede1f27503ec6130cf1c355cc8372fac29581b3 |
Hashes for stim-1.13.dev1700354855-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 049b655f655dc20e91ba39c37ca04730291b8c0c674b25a899b43fec39a11326 |
|
MD5 | a5089adf40c5cdd22d194c0eba81d399 |
|
BLAKE2b-256 | 693260347d7f890dff24f8950439b9fbaac90b3183f436627fa1f027c0e7635d |
Hashes for stim-1.13.dev1700354855-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c99cc60a56c1f123fef4d09e4a2acd7aa8ab1abe5593afb27009796fb373aeb |
|
MD5 | b56a98d09a3a44d5b454d6f7bde3aee9 |
|
BLAKE2b-256 | 273039120f37b1bc3d1192850151f75b4d887c7c161d5e72e54df332ff791e51 |
Hashes for stim-1.13.dev1700354855-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c0c547e8fc231547e7d260bf20bded2d955cdf43c5ae2690fc9553ba403d69c |
|
MD5 | e218da3b48e771af126b52143e77db18 |
|
BLAKE2b-256 | d06e25d429168a76514e9b69b0dad0d28884ab60a71a1d2cdb73469ddf97f8e6 |
Hashes for stim-1.13.dev1700354855-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ef0b5abaf824e2e612bf33233eabf5bfb892bfda0fde025139a9a463ad35e2 |
|
MD5 | 0dbc4938214b7dbe2fffe7bc7746c39b |
|
BLAKE2b-256 | bbabc7e2673e8c566c72680d7048810805e200a29410799a5f0fce937f00dc3a |
Hashes for stim-1.13.dev1700354855-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f052138793119001da333db98c133fad7b87b29a6cee1bb3915e9807ccbd26b8 |
|
MD5 | ab8cb64415c23c5b17ecc381ae4d627f |
|
BLAKE2b-256 | a986855fb693ddc11c3e4e80af2570ff802e9337bfb80eb2a5daf2a57c8959f7 |
Hashes for stim-1.13.dev1700354855-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b96fd1f5895d60b63c3f47bc09dd15a62c896d51118db0ca70b299fc15081a26 |
|
MD5 | d200a84575f38a21efc5f9bf0d18ff01 |
|
BLAKE2b-256 | 15b90c8d084153f6aff3fde9857920fbbbe7f63dca7f377004de1f6f24668262 |
Hashes for stim-1.13.dev1700354855-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e52ee9a663229ec31de2f75a73db2e6b1b345309a0c42d3a378e51b1affe6b1c |
|
MD5 | b4ea261a93502ff1b36d9bd357b55fbe |
|
BLAKE2b-256 | b47e74d9ed5bb117685bf5e592d33f671d1b8e1d290de58d628a41a0e909163c |
Hashes for stim-1.13.dev1700354855-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3403df69f0525ef0d8e20708751b4344f8ebe1ca6f990b641f2fdf8d5c32414b |
|
MD5 | c88e1c5130346f26f9f79eb195642a7e |
|
BLAKE2b-256 | d0f7e1cc4e8fe4f946151c4374e73e0498a4242106c2074691e5bec4103af1b9 |
Hashes for stim-1.13.dev1700354855-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bca0deef91f8d2a6920a1010efe7529fcfc6a61e041f170be13fe0dd5f36841 |
|
MD5 | fa288630423d7416cf7222f14c596512 |
|
BLAKE2b-256 | ec7913d792a7f3e67fd6050be402f721709a042a6ad7de4cf223c17dba917b22 |
Hashes for stim-1.13.dev1700354855-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30206fbb55c3930ef35d3abcadc15e0c2880862d33bfa9a2770202bf8bf73f13 |
|
MD5 | b17a114b91b44da3e3eac4971a2eaa9f |
|
BLAKE2b-256 | d13d1a3d3f08e4e6212b87be1a85cdaf50cebe4d1da43e1b265a3bc35e2f8eaa |