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_operation("H", [0])
for k in range(1, 30):
c.append_operation("CNOT", [0, k])
c.append_operation("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.9.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5db0d41f51e3921d4f6ea6a4c755d495f868061b4ac67cc10a3463eea7a55da6 |
|
MD5 | 5116500e3745332d3e0b07e330438e6b |
|
BLAKE2b-256 | bb06f8c54e2da639e7ee379b9ecfb23e1b7ea446c65190851d418545fe353d81 |
Hashes for stim-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf8caf5493c1629dddd888d23e824804a3f552156d0d1d5a349bf875caaee0b7 |
|
MD5 | a2a38927f4138a0ebad96513cec515ea |
|
BLAKE2b-256 | cffed982574dfb0abbbffae6e99e52cfcdf8958e2443463cafe2ddea1fa32ed9 |
Hashes for stim-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8ab3fee84eff33651418ece05dea9e413a1c95fc9e2f1e73a705b8128a4d65 |
|
MD5 | f742d872535292ba2944860faec6d3ba |
|
BLAKE2b-256 | 322985a67b355b67ab7e2a0eb3cd3bc980aa40ec5f8fc255cc56a7cd6c4f9874 |
Hashes for stim-1.9.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf510dc9987a4ba4bc2a5d03ecc0060d4718e57ed8700dd92b89dc2e87721abe |
|
MD5 | 041d9a6a62ea6f91435c4df6aa9dc48c |
|
BLAKE2b-256 | edfabf80c9ccb6a403031abb53af05a3234983b35e32811a3e92257fa1877527 |
Hashes for stim-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a48eb723ba895b68f5c4b569daaae81d1c36b3250f8e0b629a6320899bf278f |
|
MD5 | e4a10e0a84608d3c48c3320aca32b8a9 |
|
BLAKE2b-256 | 3b5c866b8ea10abbf48e161c67a6fb70cfe809b33399557ceacd5b04ad87880a |
Hashes for stim-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c65b8b41423136d0e10b4578774b42db9ce88c79d091b8e3ccfa259f43121bd |
|
MD5 | 0cfe0663896d67aa3cf1fc3c02848f72 |
|
BLAKE2b-256 | ebe45b6f3b4fbb1a24e2923fb33f99284383d4bdee1c676775937647195a49b3 |
Hashes for stim-1.9.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8f28305c93d3e10f58f64c55dfd3781c3fce9aca4221746835fe71a9bd31880 |
|
MD5 | b127eb3b8867fb82b002b6c583da4993 |
|
BLAKE2b-256 | 0a8d6958f8bff9a0521aa1d3891a86ee0d90b9ee72eaa9ae32b8b8a9e382a4cd |
Hashes for stim-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c96dcc32903ea08f1429648eec36c6fb38f90f009431a234e1f99ec50dbb838 |
|
MD5 | b62f32135b6add63e6271bcdd8395ff4 |
|
BLAKE2b-256 | 1398142a24e3c1adfa3ca4d03b489e523e421f00f336829628085258aaddfa66 |
Hashes for stim-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6cbf4c82e9217d896ef3575bf546344e989015b4070ff6a0695ae2f5915014 |
|
MD5 | 2d398f5a52053cb01fc077fd0496c051 |
|
BLAKE2b-256 | 1d3363dc137e9748a34a98e8777a417f62dd94569249669b5bfd228531411d4a |
Hashes for stim-1.9.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb0f20f3f1f60f2e48034cb541fcd60e46487e68a9a748f787478cc72e557e7 |
|
MD5 | eb04c56f90c3eff3bc78f72f00103cd2 |
|
BLAKE2b-256 | 37669437bc45e1df6450793b61e8584157d460dbcbe734ed7433a0922c3f1496 |
Hashes for stim-1.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 992db292c7bfe619a0a9180b0635417ec55930e8dc9fdba695f0b13e1f26584e |
|
MD5 | feabf2b92cfbc829660ebc6e6aac6b83 |
|
BLAKE2b-256 | aae17743c5ce04f97cb48dbd15a90046cf2aeff9046d077d85eb57608256eb60 |
Hashes for stim-1.9.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c8c271a3b71081ca2b57d0d072ffaa319cb357801b309cf09748b984e15659b |
|
MD5 | 580b3549bfffaaaff82ecd572dacf498 |
|
BLAKE2b-256 | c3507a904a7342ed3d8c71f4812f0d93cb7a492a216d5db12844e478865fc8fa |
Hashes for stim-1.9.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9cb0091e10b9e247762f3ef4e8aaa8d1b899d6021bca3e9fd19f98a2ed9a158 |
|
MD5 | 7c3dc9222a99b0912719cfa7e669c32e |
|
BLAKE2b-256 | 3af4b34fd44537e25b250de0b142aba690997e9220cc38d2f8277fce2370260b |
Hashes for stim-1.9.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 382bbd68d76049a654991d33e90723edcd7a13effe5da5dfa31a3d1e9310c74d |
|
MD5 | b64c3993cdb7d1c4a7f0d745fcd7a1eb |
|
BLAKE2b-256 | ab533a1edc2ebb313f79b3a4d79618badb6d86064fbcc9b2bd37489a64ba0d93 |
Hashes for stim-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15b3983e27c8b871c99efb94c2a3455184d1e711a1e60d9692a3fdb65494c56 |
|
MD5 | eeef4f188ddf90c02a3a7d4cd0764ce5 |
|
BLAKE2b-256 | 229f60538d496b54d84686c0d669f5bef07ae1388068dccc9fbe1c5c62d38710 |
Hashes for stim-1.9.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a671679ec84f10a95fe96494c85ccfd88a1bd3ba626a3273407918598ebcf8f |
|
MD5 | 916aa2e9ef86d6274b809441da10131b |
|
BLAKE2b-256 | 560621d940a0261d27ead060456a9a4ea389f94aeb94ca7d1a7f67e548d6a3ec |
Hashes for stim-1.9.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b67f3e66aeaa3f21bb5a950718e6e87ff61c434ffdf59b0b19195dc67bbae86 |
|
MD5 | 090c56322b749646db477130d2a73771 |
|
BLAKE2b-256 | 1d374e0963b5005fbeaf85556b3fcb3f5c41d7e1db6bc74121b53b139095094e |