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.dev1710546840-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bd5dab12672e13943cafc7c6020261f14b346aaac2c0731105a1b79c6677f7a |
|
MD5 | e719942303ee25c655ea32aa12a18ad8 |
|
BLAKE2b-256 | 378c2950559254d5741efccaa6b1fc05c9c0fb46152a9eb7114bc007f7df7118 |
Hashes for stim-1.13.dev1710546840-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f359e9016160a7ff6efd9322f17fa0cc562e62dd9ae5f25d6c436c282d76acd1 |
|
MD5 | 497f2c4bfa73ab718771a40bddbea4bd |
|
BLAKE2b-256 | de6f9903da89ca1a18afe16010f5a2d9a5ee4ac932b0bea76b30caf56662bc9a |
Hashes for stim-1.13.dev1710546840-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f228932c57e094f6655fbcb7a991be0a1fae8ab3f7bd8613a6e0cfd01b06b838 |
|
MD5 | 20bb5eadc4db4016daedbd064d5bafe1 |
|
BLAKE2b-256 | 2841b2137bb95a0fd5740f1a86a0bdc52079f952ff7742b0cd69ab8cd2d4e4fa |
Hashes for stim-1.13.dev1710546840-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db6aa43309c7e806f8d1cc907c0581b61b48c1095816c131dde13b6657974676 |
|
MD5 | 68ea935301c7718d32348ae98278485c |
|
BLAKE2b-256 | 214a22baa499b9faa0cc7a426763c90857e0fed473bcff371a4549ee5c5f82d4 |
Hashes for stim-1.13.dev1710546840-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a4c6a7b2d3141841809f82b38564508c298370c2395332c1a47dcfb7daa210f |
|
MD5 | 528e905ffaa8f6b690d60cac701de526 |
|
BLAKE2b-256 | d31e8b9ee7404c5d4fc50ead6f089ba904aaec0d1bc875049f0518c84168024b |
Hashes for stim-1.13.dev1710546840-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e778771dbf02e229e0400ead11f9da171cbabe7e4ed13d71376363a447814610 |
|
MD5 | d6d8679f19fb3b48f992d9f299a70349 |
|
BLAKE2b-256 | 466bc297ff78121b7e1b7f02abc6ead6298548ba956c53a605daae8a3b9cb26c |
Hashes for stim-1.13.dev1710546840-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7beb802a78e162a96cf26d6b5b0dce59e0515e287a904751f9ed96f56c10eb97 |
|
MD5 | c1307539dc1d6a7ed55fad9324b37d6b |
|
BLAKE2b-256 | 6cee95d8d7f6cc5969b0866621efd0b75f7740009c9a1aa3c8da0bfc99a2cb21 |
Hashes for stim-1.13.dev1710546840-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5e928f6a55e5bc36cba0405bc39eb89fc29b9cccf5c274f5e0ae27ccf56402e |
|
MD5 | f547cf0b5337fc34130125a71b7a3e8d |
|
BLAKE2b-256 | 92b05910168344bc1181ed35d25ed64b6edf9af1ce057a4a2da52b271d4e8968 |
Hashes for stim-1.13.dev1710546840-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 464415dc71af3f065a34886754edcafbe463dec668c65e5608b9350b91e9b9c8 |
|
MD5 | 783c5f4b3bdf2a3a86f036b0bb2dbbba |
|
BLAKE2b-256 | ae1b66a4c326386f32ce4b652ca7504660d12abd51116f4e6b8f5a70e782695e |
Hashes for stim-1.13.dev1710546840-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fca95ae75cde1f5b0ff13a1f5d7ad576a5c6d296e566ee41784e6540a3b5f6f |
|
MD5 | 3ea39fc489a451475240ca391d0525f3 |
|
BLAKE2b-256 | b25cddd1f5ea3a7b6f4e04e915875e23f463e743c0bb76dce0874ca34dcaadfc |
Hashes for stim-1.13.dev1710546840-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83d4706d6bc6cdf2eebf4604a330a30396cd9f410b7809f7fdc12bcbe9fd0c69 |
|
MD5 | 7bab48b6a8da37677a5d7319688d7e8e |
|
BLAKE2b-256 | 30130f2f8602b76e51bdce2ae085d9850d01d6673765edac81159e91619e43fa |
Hashes for stim-1.13.dev1710546840-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2edf30435c09e6412c4b2e288fbd717581841adf699d882cff05d86d3a17975 |
|
MD5 | 0a87443fcd449edaad2d64a5c6380e68 |
|
BLAKE2b-256 | f217161cfde98ce6efa287885f1d8c17aadf30df66e534d9ff9e30a0cbd846bc |
Hashes for stim-1.13.dev1710546840-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0544fc4cc6adf56b4ebe20e769a85b9ef9486dfea337203fa4c852941986fc05 |
|
MD5 | 5fcc08ad3ec13555206c9b3f62e2c9a1 |
|
BLAKE2b-256 | 0a20181f7ec2dfb2e7e3fbd38ef281755fc3e0996b5acece2cb41d5b8c9dd39d |
Hashes for stim-1.13.dev1710546840-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce78c5f6bc1e33426b6cac423d69146ffcd35485c18d8a6627a80775d8eda124 |
|
MD5 | 848d1714459a4ecca723ab8d6713a6f4 |
|
BLAKE2b-256 | e9794dfc9dc1dd31f78275b630fb82a7ea33634eea47f0058cf0066788a80a17 |
Hashes for stim-1.13.dev1710546840-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a10e626ccd6b743eb47a03f75123f70c14fb8dbbe8e1d366d6da75e3646d8bd |
|
MD5 | 0ea094a7caab8e1db0cb9a5e982d1e1f |
|
BLAKE2b-256 | 4793bd8cc61699747a986ab88fb967ef66676447171b69b170635c4bbedad7b6 |
Hashes for stim-1.13.dev1710546840-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02cd512a69e6142de9f62fec442f1503d3387c07a2436862ba234b78dbbba15f |
|
MD5 | 03bf4457cc355fa04087f53b3aa04b9b |
|
BLAKE2b-256 | a958445e285b9737980c8e0c75f58eebc666513e0047ce29142171e69cd28323 |
Hashes for stim-1.13.dev1710546840-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12c0fd8edff4131c1b8daf940d59e13df1b0889d3d90150073eb9b2ca128138f |
|
MD5 | 691460705f150cc2c5fa28b381addacb |
|
BLAKE2b-256 | dd5d8a8b1dbedf421952c5cea305b1b1985f942a89abab78c1b9f781e60edd3c |
Hashes for stim-1.13.dev1710546840-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eeb825dd7f377e5fa4e007980e5c72a01296e2fd39e9d4b54ca1a62a52ec395 |
|
MD5 | d7a15bd8526274a769fae02192b535cc |
|
BLAKE2b-256 | 7c4e7b314acbcc0232978cc79bd4b853281cc55bbfa31b7ef20bfe233af09829 |
Hashes for stim-1.13.dev1710546840-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6665bc2828e6fa554be5d1c96289cbbc62e1268e92a845c23662c521d6304651 |
|
MD5 | 10fad17a768d5011552024119bb9a2ff |
|
BLAKE2b-256 | 9ac3aaa24b001304239be07036a46e705247b8f25d20ddcb395fa2d7a545bccf |
Hashes for stim-1.13.dev1710546840-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a1dbec313c56e0cfa7440ae6ff7ce1ac627c23fecd3266d2c0d8296eaffc0d3 |
|
MD5 | 32155fcce3fd33a08d0af853d9727d50 |
|
BLAKE2b-256 | 025f102ef3a305b62261f035673b046ffdcee201fe495bcbd0c5ebf9d48ad0e5 |
Hashes for stim-1.13.dev1710546840-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d7c216fb091787d4986a08d7cd15b52c8f7deb2c879b0dc470c2f7f1caef6d5 |
|
MD5 | 67790ef89d5f96f81b6a491cf5c788c6 |
|
BLAKE2b-256 | 1ee18a269cf207ac9073c05d4e2710f51c20da9c7933a1c4f79335a563baaeec |
Hashes for stim-1.13.dev1710546840-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f84494f4867fc9e15116be21916f1d317ba4e3b01d4d0a3b29207f7bff2f7fc |
|
MD5 | 65be6372cd7a0847bc77b2c8c168b071 |
|
BLAKE2b-256 | 69e3d7ed6486b6e0e72304391b9cd254215f36f12fe4f64bd56d59d9097ecbb5 |
Hashes for stim-1.13.dev1710546840-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2a2ee8fd46335d602ec115c19584e0d5cf8558343f455c166cc0c1307e9e44 |
|
MD5 | 133f287a287caa3cb60acd83a4a8b769 |
|
BLAKE2b-256 | 9068542b709aec9469a9132bff094feb6296d2374d6a024abc4c87809b7f7a00 |
Hashes for stim-1.13.dev1710546840-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e46b53ef982037d8231ff7e56488a5654c66e3c93439d0a0cf299f89f3dd98c5 |
|
MD5 | c4c1b805c77cbc68a85c93ed9cd8d64d |
|
BLAKE2b-256 | 4ac19775cc9b5e21f447d881bb3a14f1ca3225ec0d1d65febce40f841c811445 |
Hashes for stim-1.13.dev1710546840-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 649a9906f6a2faf218c85425251ef2f72dd95ac05c79258413a1096a1006233e |
|
MD5 | 1d899d75aae07051dcd08bc0d9e6abbd |
|
BLAKE2b-256 | ce63db256c70237bce2b72e57aef4c2f8c61ad6622002e2592fc3d23e8aefcfa |
Hashes for stim-1.13.dev1710546840-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8242b7618c88f28c638b0d4bad1743d2465bbb614955832dc37431264e073a6d |
|
MD5 | 66292446b65937aab1aada1ce3b714be |
|
BLAKE2b-256 | 1fac65cf45b2507501cbb4123b890fd466e5c65bbfbd7d3203bd3dd40997eb9b |
Hashes for stim-1.13.dev1710546840-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3fdfa75e1f916019408c11e0c0f524a5ed6bec280c8e6617588af6a1c774301 |
|
MD5 | ef0394992f630655ba281db506f873c9 |
|
BLAKE2b-256 | 78fe5c13fca600dc593421a1eabbb1312134e5683c340ed5f176e09e5315c98b |
Hashes for stim-1.13.dev1710546840-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2917e11c733709d0ee4ab3403f9430d56369744a6816d43349e1217df934b9fd |
|
MD5 | 91340e3c0ce4bbfd425b865431e1b3cc |
|
BLAKE2b-256 | 992fd1a0409c66bada4d702331aa354745b1169077df6ee9934d80fd11cc5bee |
Hashes for stim-1.13.dev1710546840-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b3377033f835115ddc6de8122982abe5983d4079aec2dfaf0574a1bf4a7940c |
|
MD5 | 9a7e9da8d52100ac3b77e48b529461b3 |
|
BLAKE2b-256 | 794451e69d0ef49d17d5f634957a2fe9c2d390cf5c85141664d94e5d02c983a1 |
Hashes for stim-1.13.dev1710546840-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cda69023d806c06c1354775ef717cd5a3b65c91df6fcbcea588de3b29db2e15 |
|
MD5 | bf8164ef355493202c9a4861e81d4d2f |
|
BLAKE2b-256 | 6051f5c1d714f9c9268043b328aefb5cc6047fd8bb433ef0cd8008dc1f466fef |