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.dev1696452052-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01d3ea5f202026c4ecaf58ae6d2b63395c1caf8213dcf88486116271ac1c8f03 |
|
MD5 | 88aca1aed1c7c2db3c5ff03ff18c92f5 |
|
BLAKE2b-256 | ecbffdbcab5d34204f1b728b23c6e6ffe56b459a8e8e394105dfe59ac4bfbd51 |
Hashes for stim-1.13.dev1696452052-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c99b9bb33e2a1d0602a35eaf85b59b98f057e96fa35da1dd1c293c91295eb6c7 |
|
MD5 | 63e7b57f03a2049bb104cb7fe17884e3 |
|
BLAKE2b-256 | 377dd8fb8fced13f6026606fa67b8f078db52cd5a56b7a987b42c286d834becd |
Hashes for stim-1.13.dev1696452052-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318525f0362fc00e97663f836e99172eb10575f393213814c06e240111de5cb3 |
|
MD5 | edb18abab16d16c49ddf5faca67e6a8f |
|
BLAKE2b-256 | 0a58d9ffff9b76e366adb207c4d45dc75a915a2ec42f322e689034f8d882e20f |
Hashes for stim-1.13.dev1696452052-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52a083630a5ff6893d2ea35ed681f4c32b1081e3680cd53dd627a685d7616300 |
|
MD5 | f9386c33657b11076704e8c94b0278cd |
|
BLAKE2b-256 | c1cac1fad9ceed77cc867f2f4f665726b48f025faabe2d53d1c12ae9fd381501 |
Hashes for stim-1.13.dev1696452052-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d7e7f1979a01f1ae5e2ea9b844ac1b43307724a6e59bef440d5b163b7484f37 |
|
MD5 | a7234dddc6e9045db612a4d74fd0df07 |
|
BLAKE2b-256 | 6dba7434941c54c5ff8f72473370c4b1e99336c4885dcc9d7ff507f4c5de35fb |
Hashes for stim-1.13.dev1696452052-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 220e3c09eb4565aaf0f5709413950b9afbbf111dcf74a8c42d1a872bacab44f4 |
|
MD5 | fdc9b405eb6debe5c56f4c7edbe3c5a5 |
|
BLAKE2b-256 | 7ee530f14f2c8aac33205322082a6c1412abcb84f5ca399705367891db2a30b1 |
Hashes for stim-1.13.dev1696452052-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9660d5eaa1707b0f38725be7148157c73392fe7610883f93c180ba14f5e2c266 |
|
MD5 | 47d730cfd7b1e31d04f579dc2e3e98e2 |
|
BLAKE2b-256 | 37b4bd3af3da7e902f2204e74670315b2ac3599a62cc733e90d0a63bad79fe6a |
Hashes for stim-1.13.dev1696452052-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c86fa6a085b3ef06bbfa7460c22ab46e511709c57b1286a4e3dac743585edbe8 |
|
MD5 | f2a06d45ce58aaf529990c94c830226d |
|
BLAKE2b-256 | f586feac3030afd440310fe95cff5a9eb787dee388e70f3d932d6a7dedf580c9 |
Hashes for stim-1.13.dev1696452052-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c09f849d54b998359003e2e25ae95c352791188becb738fece217d8f3d51588b |
|
MD5 | c0cfb8484934685883619d3798456fc8 |
|
BLAKE2b-256 | 2d9d4a3d9a364073be872ebc49b3e0b17a4dca12171a7e0ddff8fb8c6f4ed8e0 |
Hashes for stim-1.13.dev1696452052-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20a5405cc32f2d09326d1355e966533af3c6d3f11725a7508cd831ee86c31b2d |
|
MD5 | fe5f706ff6a0a8521a323c5852b848bd |
|
BLAKE2b-256 | 1e43855c96965cb7a50731f51958dcc08c9988f88ce25d521428fd7a1274e545 |
Hashes for stim-1.13.dev1696452052-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cb653e4cbd9b2b8710a86990fb6d3860c2b3d4a941018b2b6c40bc112dd7c79 |
|
MD5 | c9dbf5b4c8759032a9ed956d14141f58 |
|
BLAKE2b-256 | a68fe85027d6def2910d47a63bb00f3685afeed9227c940a25e90e2f2c282cf9 |
Hashes for stim-1.13.dev1696452052-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6eb6a7cf34e844370bc6cf0c4d454d18a5fbbc2948c6759c913ac5717846af5 |
|
MD5 | a1a0c2a223bd13c698edde6e01976c86 |
|
BLAKE2b-256 | 031512a6b9994460f4417e69c0a1a6a773c554061c5eb2c2f956388bd295fa30 |
Hashes for stim-1.13.dev1696452052-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14a5a49b399d5b236c2461de653c4ba09a9a4f0058edc633c3e068585c2f6c01 |
|
MD5 | 872f476d2ee90a0f0b581e46ee761090 |
|
BLAKE2b-256 | 4ef17bb081eb53698dd073c85c7fd01e6758ea355b856f6248f88fbbf9a8b6f7 |
Hashes for stim-1.13.dev1696452052-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a47b7d362679130679d58526b23fecabb490d5132eae84f6ca6a43b3c024ccb4 |
|
MD5 | 6f516cfd00eb36a4f96b5141032d360c |
|
BLAKE2b-256 | d400bdd321e72cbf6cc06c2eb9319c6668df39486cdbfb3caeecaa7dd0ec645f |
Hashes for stim-1.13.dev1696452052-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 708b401e07ab1a8766737d2c7566949a54c6d8946f147894abc201735bb7f2af |
|
MD5 | 0438eebf29a0048cee76d251b9489772 |
|
BLAKE2b-256 | 34ead9a8715da69c803c8ee559e618587e924fa12f51f69c73858e7b60d236b7 |
Hashes for stim-1.13.dev1696452052-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc359e360826ea066c91a2a5aed9f40193329b40231668da583743a58bbf6c9c |
|
MD5 | 81aeb9ca46d2145a2e5f79fdb5657c1a |
|
BLAKE2b-256 | a1a816de76a39db38ddb8502604bf820625a2f21be97f5946feeb7fe0403b1c8 |
Hashes for stim-1.13.dev1696452052-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ad49fbe92000186b94eb63aae71f85ea083a8ecd53ef4a418a85b0de3f322ec |
|
MD5 | f3219dae5e7178a9a02532b09a3705e0 |
|
BLAKE2b-256 | 164e76a552ca3cf8116f3f98637a5baa6728ff09e70bb621cd29929f5ac6d2d8 |
Hashes for stim-1.13.dev1696452052-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9321e09e2eb8a76cf83978bc9da6cdfb8e1bbe9d44c868d82457a4cf1aabc7fc |
|
MD5 | e3fc2d57d6e45fd3c3f0b558f0109578 |
|
BLAKE2b-256 | 6373031aaa00be0b6ef43a24360b46d1528a19e9ccd0ceed2f4139b3ad067e44 |
Hashes for stim-1.13.dev1696452052-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9307bf1a79ded0ddf59831926190c6ce2b37f5ea9a346626f3e7b3b432b58cb8 |
|
MD5 | 93b06cc7e89bd00187521033fcd47f5a |
|
BLAKE2b-256 | 257fc640c8b373c0354471df8ee24368ee62344abfd18b5b843a386c256f67a6 |
Hashes for stim-1.13.dev1696452052-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98cc97c84b0d83c1cb992d8b2431aa86741e3102c4d0ca9c7c4c52bd137b8be5 |
|
MD5 | 0c0b11380a275d722ebcc10e9f28260a |
|
BLAKE2b-256 | a54dc5916afd3ed997429f1771da57eba432e1fbef07a01bcd4eaa7cc988ac47 |
Hashes for stim-1.13.dev1696452052-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdc7580872c638cdb6d55ba933bf9b7d0ac369968756a5f6550e7b74f6ab54f3 |
|
MD5 | bc56979b89eec5a90772301504671041 |
|
BLAKE2b-256 | c34003cc7e522fafd80c5e7af6b76b359148eaebb9bd22361f1d87c84afcf7a9 |
Hashes for stim-1.13.dev1696452052-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f9d3e7771c6545e847e02581d6211eccccfd2e190bb232976391ec6998e613b |
|
MD5 | b365bd451aca233aaa2a527e7ed8c42d |
|
BLAKE2b-256 | 914e258e023fedf190f6e31005524ba81660a3d8d8380ff96ef2750796debf97 |
Hashes for stim-1.13.dev1696452052-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53febaa94c32cc5877b94618da2309ae221f808fb717831ef84f92d4c487ee61 |
|
MD5 | a1557c91b8e5b8f18cd67cca45f1f353 |
|
BLAKE2b-256 | e2330f094b63d8591d18e6818bc97a96769bd2172d1139e418f1c2320fd13ddc |
Hashes for stim-1.13.dev1696452052-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 777b4173c57c982504de0d2223beccc6af4c17f63ce376575a47ad90b4303380 |
|
MD5 | f06c87287b35c1e16f4fef3bfe0edc06 |
|
BLAKE2b-256 | 8d0bcdfe622574fe95e8c76d50e8570889c75529c7ee679ff35eb4cee64a4302 |
Hashes for stim-1.13.dev1696452052-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 842715a30e905c17a5ac3be5221ffbcaf0e77c62da170dafaaea4a1b72fdf5f0 |
|
MD5 | 2a918cb721ec47b272c9296c1bd32765 |
|
BLAKE2b-256 | 785350ae4d9839c46ddaf7b6575ffbe379db8491dd7216a9c8f0adc28c091149 |
Hashes for stim-1.13.dev1696452052-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 576d82290db9f72541f2cd32acd609a9e34854af05f167a90d1d9022e5a4f70c |
|
MD5 | 7a892284371e34dd953f4251fe82305e |
|
BLAKE2b-256 | b7e4bfa1782469a36fb8d218a4fd9d8427e138d0d0ca7a6894ad1164970667a0 |