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.dev1690946907-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae3b29d73fde01db7d83a5f1f1c9588fd0e537f5e74c1f6226a1e3fc91b9e869 |
|
MD5 | 9ed9f26f97439b212f2fcc27fabb1863 |
|
BLAKE2b-256 | e533ea3302b2b216a4f62c8d795b74f38d9fb253ec5a80b0e2067e94f6862e59 |
Hashes for stim-1.12.dev1690946907-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 564d36f012fd839b85d92d1f36657db24370e0ecefcffc52be8b604f05ccb137 |
|
MD5 | 8d4a08d963d635a56dd0476257fd05f4 |
|
BLAKE2b-256 | 9ec1e4127b29cc10b28e41dfdceb0a6ded94f1889b27d10835d841f2df369a00 |
Hashes for stim-1.12.dev1690946907-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34c0ef10a563210e997fd41cd324c3939651a56090921c4f64340707459d5660 |
|
MD5 | 89ea0870339cd34d2041d64f40784c86 |
|
BLAKE2b-256 | fe1a4a1e98efb61711d151decd0d046e66592a6cbe276e99a3b47fc0f105f677 |
Hashes for stim-1.12.dev1690946907-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cfc13d7c466a1cc02fd0dab00ece5cd1849b2b71e50caa24b8ce7a537123c0c |
|
MD5 | 5476041f9be5058af6e9f354ba1e2e4e |
|
BLAKE2b-256 | 0b91138e165a5511568215ad5a83f0d753cad6dc7821c7fa957c356c74c19dc9 |
Hashes for stim-1.12.dev1690946907-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06da2f2786dfcbce313a4243d55429e5af309f1c692576db138449791cbdf435 |
|
MD5 | eb50c14af9bc60a5d4106d474c28802d |
|
BLAKE2b-256 | 5c1bf0747f8033972e42d174c6a5bb82bb48cc02a6f34668fdf8a6357936489e |
Hashes for stim-1.12.dev1690946907-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea3e9fb079f46d56a3f241c980d044261da4f43175cc870ebf190e58fcb94d08 |
|
MD5 | cac7c34272d50e6f0bbdc961c904560c |
|
BLAKE2b-256 | deb085d244111950966d06bb3fffceca2fd94b882438bafec9a9486fadfccc6b |
Hashes for stim-1.12.dev1690946907-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d34d599fd727697cee8d0bf1b953eb4fcd4a76da2d68afd5af4df2beff13b1f2 |
|
MD5 | 6209b85fbf1d958c9eab90d2a623b7de |
|
BLAKE2b-256 | 17c4e6c879011c3ae2a16e5f322bb95cb351eba054b055fd6ae544cebca9ebdf |
Hashes for stim-1.12.dev1690946907-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c13387055b5815ceb98296129783e1c65bbbf624bcf64290c7c892b7d2f1338c |
|
MD5 | ea0dd653b1b575e4bff6f12544412a78 |
|
BLAKE2b-256 | 554281064d4050bedc58e9178c2c921c70d0daff3b83b46059ea628b26c2c3a8 |
Hashes for stim-1.12.dev1690946907-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffa1cd50b81f0f820a778722cd1a675e1cde2a3e0b969b7a3ac7deadec26d132 |
|
MD5 | d7adc9f6f837853a4c595ec6d8e5242f |
|
BLAKE2b-256 | 4cbe03c2668a5243f7f953e0a7dd7a0725c9daeaf6fc3749d09e0f32576a772e |
Hashes for stim-1.12.dev1690946907-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc50cc603206438911559b9509594b7abd0f33dcc932a936cd0c0edb60b0264 |
|
MD5 | 3d31874c44c5c6224efacebf5f5876a9 |
|
BLAKE2b-256 | f42f592d58c59e9e0b5437c76d5560bb987c5a9826ea3b8f47e54c10265e0c7d |
Hashes for stim-1.12.dev1690946907-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b403d253a1ea34069425a35249f816d88243497b563fdee4d76018041f14a15 |
|
MD5 | 8935b58b765d97f9ef5aa30b62e1d7f5 |
|
BLAKE2b-256 | d95a2e05826d2e2eb169cef58617d0d8c1cd52c7b7ee96c8df1883e4aeb9d26d |
Hashes for stim-1.12.dev1690946907-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 018ddd8be285b83abb99c6d4635acf5202ae56dbcbd067ee182712d647578864 |
|
MD5 | aab64e19dbb4ccb3d3a1c3e2338b0c67 |
|
BLAKE2b-256 | 65d8ea29d1f844b0259513978bec3d7757dafc341de86c016da8b07a1cb0ad79 |
Hashes for stim-1.12.dev1690946907-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11c2aeeb140768c0da76c0832eb61df4160ef6c085328faac740fbf5ae345d5 |
|
MD5 | 960d023f025ffdf33c3bcfea2b5db678 |
|
BLAKE2b-256 | 41bcdea3fae142981f70b6e0e9a606c51558056a8b6763af7bd2b4a99da4f945 |
Hashes for stim-1.12.dev1690946907-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 629ac1737ac49fa279adda497461f8d0f9e3f803312f9938999593ecab3757a8 |
|
MD5 | 03990d74f481e8a55046869efadc8233 |
|
BLAKE2b-256 | 7f87bf261a921203ccf24206587a80cb296c17d34cb49d46bdc64abbf778d0b1 |
Hashes for stim-1.12.dev1690946907-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da4637c1cea6f7a6f9f28bae5ca3c9a69df4fcca90490dd63776e18ed8b0e20 |
|
MD5 | bce5c0e50b8da2437cb0c8b3599864ca |
|
BLAKE2b-256 | a029dc1fd3cf2c5b67e600ffe57c5ec92cd124b64067a204def3f9e6b7b720f7 |
Hashes for stim-1.12.dev1690946907-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e47a31c4c31bd7a6d7634402bb10981eef01e36e668349a7e294e1a79c8bf1f1 |
|
MD5 | d0911f49fcf22d8c4fdb3c78a2c38019 |
|
BLAKE2b-256 | 23509b742423b5224d9a9933322b0abfd02e8430efdf7aa3b4dd02539197947d |
Hashes for stim-1.12.dev1690946907-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dad8f8c401a2eac0e51af5a48f0a6744a046d1caf411984e8f27825acde0b911 |
|
MD5 | 6a82a633413f486b0a1b0a00aa50755d |
|
BLAKE2b-256 | dde179811a5706894f99bc5016cd99dfd7f0852f7f7aba9745496a3ee45dcb7f |
Hashes for stim-1.12.dev1690946907-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d787f9b01944ca08066c50a3584e66c9a041a0ee929825b8fc9102346f9736c6 |
|
MD5 | 380ee8868aea932bb6dd43ea2808247e |
|
BLAKE2b-256 | ee523838eacfb517440a6f3cdc210418cfbcb4169d7469ba1ecb949d6624d3a7 |
Hashes for stim-1.12.dev1690946907-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d12bf6594aedaf55c06d9ebc5df4c44450bd7818b865a694efe70be72af70b2b |
|
MD5 | 6de265e12ddb5c3eade25d80902965d6 |
|
BLAKE2b-256 | 8c485859e20cc150471c4daaa0fa1201dd8a5edb66229cd45ba111c653e74b48 |
Hashes for stim-1.12.dev1690946907-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7557d92d54ea90d9f52f1ae0e3b9ab807b98687c60f4a3a6e1790ae3cf62ccc8 |
|
MD5 | 7099ddf67de0a8d8f95b7ef1a0ee3e73 |
|
BLAKE2b-256 | ce52be20c605a41d418bfd3ee0cf119c9937d32915bb0c07ff1322c4ec8331ab |
Hashes for stim-1.12.dev1690946907-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b27311a7cd7d8274d9b40ac221fe0c1a147c32620b35bed748e5cdb7833fafc |
|
MD5 | cc449660c40ea53436b08b53ec6a58a7 |
|
BLAKE2b-256 | 49fbc6a3da0eef03f0bf38399a9f7d6d41a6abfaea1006c9ef1d5b8396f04436 |
Hashes for stim-1.12.dev1690946907-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a5d41de93aec4667373ce9d785a055d5d969e751c8d80fa2d621bd01035b1db |
|
MD5 | 7878d3a9515e059d9b14e7fd0ae8747d |
|
BLAKE2b-256 | a1b9822306b1c224d9ba1a001d62dc8033458bb8af590b85e37f41a4eccb56f0 |
Hashes for stim-1.12.dev1690946907-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38a5eeebfe93d82f7a603e7955c5799985feaae9d5295822c84f2b49df240dc3 |
|
MD5 | 2eff953769674ca0792de810b7df753d |
|
BLAKE2b-256 | 7e8381d62aef328d1f70e44b25e82a72574e53dd90be69197a73aa43d7c6375a |
Hashes for stim-1.12.dev1690946907-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9bc5b32db484b2cecfe1ed54cfa083303fff60072252e0819228d260ffba203 |
|
MD5 | 4472dc1ec67f9817ebc167e668efc144 |
|
BLAKE2b-256 | cce256b97dce77aa062b8951d1ab774fa986bb06651a93d784b604258f608931 |
Hashes for stim-1.12.dev1690946907-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1d2229fea116601558def5f7b7f238b04bbe56181fc5b63bf88ff8b99974f4e |
|
MD5 | ce69703d4a7427c22dcec75916891768 |
|
BLAKE2b-256 | a7347c77c36631b545290760f0e53621c9600dfbafa797e020b00600e36d958b |
Hashes for stim-1.12.dev1690946907-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cc42a7679867cd8ccddafe7732ba8064d2919af7f5475ab31ac5b3fc14e3bd6 |
|
MD5 | 9743f3265a74d78edeeb69cde3da6be2 |
|
BLAKE2b-256 | ada4a3781736aa19cc0e4628bd1badc849f28f13bf0f070f2ebc7e569f56158e |