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.14.dev1712965049-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0629822786748732c0472c776d060c40d54f0f168dd9942812a572000162dd80 |
|
MD5 | e841b787c0d5929c730b7dda2dc1adea |
|
BLAKE2b-256 | edcf4276bbde083b10c43c055c6488c944d06c437f1a29fc904e15029daff1e5 |
Hashes for stim-1.14.dev1712965049-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd48788ba436557d95dec6a4962f903350a4d7ebb98a837d33fcb8231219c431 |
|
MD5 | c24efa0e9b10ace2394c2f3c1c782d06 |
|
BLAKE2b-256 | 09807911c1939174113446f6fa0b08816eace4126617c4f521815632bbd27d12 |
Hashes for stim-1.14.dev1712965049-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecde83e7a9678a70dd3bbcadf2535abf3115fb986ebee1a4e9822dfd0fbc67fe |
|
MD5 | 0db2dd485c4b941608917f53b778e032 |
|
BLAKE2b-256 | 78f131e4dc548a3b750290eda78ba0f5c0dd76351aa493e8ab995900ed2fd740 |
Hashes for stim-1.14.dev1712965049-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e4dec17383b85066f504de59745dd56676b537f082603dcd01b8135e8631c1a |
|
MD5 | 2f2aa406526761d516b341ca28659b55 |
|
BLAKE2b-256 | 2d5c7385b92aa2db3e8f5724127afb5edc0d7e06ba9e1e2f5805183f5222969e |
Hashes for stim-1.14.dev1712965049-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67b84e8690b1afc06e24fc67170d6728efcd77336cc039aabdefb3073deae52b |
|
MD5 | 807e4851e79d8357970ba8008519c431 |
|
BLAKE2b-256 | 626db84a5c2f152bc6fcd1759561809c7c04c576ac992a76b1e166f9ae5329fb |
Hashes for stim-1.14.dev1712965049-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0850fa625dbc5217db554a972fe3e64a34910e438a7c05450ebd9179f574a67 |
|
MD5 | 552e47960ac7ce47741c6704085e473e |
|
BLAKE2b-256 | d984e195ce7a52e7a8f25657c7f55f67b73bc31f3d5e6919cae578caee3d559d |
Hashes for stim-1.14.dev1712965049-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6999a872bc4aae42d2a3ce636aaccc9582dec8aa3b226b53233007240149c6e0 |
|
MD5 | 7c99e265f8827444458f2c943f26f1bc |
|
BLAKE2b-256 | f7fd42e15a89e614efcecc0ea4d720e4ea507f78d0d20b37a9cf096d6f996d79 |
Hashes for stim-1.14.dev1712965049-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 727e8436bf6b5e8d7e480986ea35ec49409a54162bbe72199b4b22c4f5dc43fc |
|
MD5 | efc63f2732726ba631802f06b84d373f |
|
BLAKE2b-256 | bd56cb292432925f3d96a672cada534ec1d95aa49b4e4448431909c3b04e88f6 |
Hashes for stim-1.14.dev1712965049-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53deb367aeb30f40007dd418844dda9c55b6612f686d5a479dd40e8fbd6d6eed |
|
MD5 | 351acd146b12812ea9ed74647c871c13 |
|
BLAKE2b-256 | 9ccbb46abae62ea8469e81e7d2105f8b1d102c2c4bed2846aa93118a1b7bbb69 |
Hashes for stim-1.14.dev1712965049-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a13a905e68f993351d7382c805d808ad74d64effc7fba976a3d945d66779460a |
|
MD5 | 8c6d9279f166b860ffe07d5a111c4d5a |
|
BLAKE2b-256 | e4a8ece433821296ae0d18b8fb43547561126095ec2c09d0c523f590f39e3110 |
Hashes for stim-1.14.dev1712965049-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127fd7ee6f4a5369414e3242ac94d8f4ff268f9aaaae2f0efe486af08a4677db |
|
MD5 | 6e4973604c1283879ad4971aaf8ec5b1 |
|
BLAKE2b-256 | 4060e7668362dd75ae4d4a59f8323e2879ccbddda37f1822e990c8e69ac84a3b |
Hashes for stim-1.14.dev1712965049-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d33821499fb34ed395f44483986ed28e2841194aa2bfb8e323fab3b55cd3ca5 |
|
MD5 | b7925d7af04035d8856a89c787320f84 |
|
BLAKE2b-256 | 48adeebf7dfa66e7fd0d2914b21e68157679e316fc663ba40afe1b3026674821 |
Hashes for stim-1.14.dev1712965049-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d87f4134d834ef7ee8dbda39e60f2c39dcd7b4cd8e3f5b270ff9841a659100b3 |
|
MD5 | 19853ee5488415413734a228e1645cdb |
|
BLAKE2b-256 | 0b7411d394eefd59c612df3b7f1ec82b2cd55ec7ad046b534871058d8af67e8a |
Hashes for stim-1.14.dev1712965049-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f7b1e3df057b0b2298faaa0cf15ed54bff0bce28b599fd19b1357e9bf61aaec |
|
MD5 | 66579a2e4784304bcd32fc17c34c1fa6 |
|
BLAKE2b-256 | 6c339556a658f76551ceb4710dcffe0669b185b60826e2055bf0da458006011a |
Hashes for stim-1.14.dev1712965049-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68aa544e948f7a1efa9e23fb440344e688efeed954492a6702fccce3ec73ae1 |
|
MD5 | e0d23ed9e0eaf50415315d55433add02 |
|
BLAKE2b-256 | 5a51b3bff9015071ec3c1fda76eb7b02ddf9125ee2c8a47f1d87e52d623a3cb6 |
Hashes for stim-1.14.dev1712965049-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ebcdb22c69d22c2ba602929d3d9842da16f954a6c48d42b89e20a03ef2d3f28 |
|
MD5 | 3b9581c93d7d63f411cc7abb1e6c6289 |
|
BLAKE2b-256 | f03b4f5761de3f210bb78a8f3b456fae3bdf66c855ca241c919065e04f650f41 |
Hashes for stim-1.14.dev1712965049-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1072c110d71a606908205f330bf449c03f7d1588412e382191236d71c30e3724 |
|
MD5 | 015dabccec9ebd92c897647b8cab682d |
|
BLAKE2b-256 | fb3d56590fca2fca5f4ce80b9205f5a92b455f716390cc3a23207d2bdd165c37 |
Hashes for stim-1.14.dev1712965049-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58642105334cb2cb731f8480a6d2c7c44748508f336195f0bf437cd1cd91d9a0 |
|
MD5 | 9a21cada32d6ef7a52831610431620a1 |
|
BLAKE2b-256 | 883cc0c9972121bcd250510933a8afcff9a210ed887241c97ac15056d64664d9 |
Hashes for stim-1.14.dev1712965049-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2b57b3d89e58f78936e2de3c6b32adf0903e4020184c5ba57cad4df6577bd8 |
|
MD5 | c5fbec0a43b9d6be4cd3693a9212ff54 |
|
BLAKE2b-256 | 0b1ad87ff6218d81aca69b55b5d9b56564f073f5798b5d380d3fdff5ce241e94 |
Hashes for stim-1.14.dev1712965049-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f66ff1e7f83643ccc735cbcd0cf1e572bc2f5f6bc60d578e9bd13098d8bb5d |
|
MD5 | 9ccf90ca1030333223cf61c0271d0587 |
|
BLAKE2b-256 | df3b99ddaaa58e0bdc3f16c06827b07970c48952e83269195b751cb43e57a8e4 |
Hashes for stim-1.14.dev1712965049-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0d39d608d502ee5c421cf5fc1408dff9ebd0d5df6a3854ae8db9d2f9b29f9c |
|
MD5 | a39fce9048234c8a789afa99b9635590 |
|
BLAKE2b-256 | d5f5f6c554a02ac41bb42e21c7695dc6479bf9a3c1688acccade5e639c587260 |
Hashes for stim-1.14.dev1712965049-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7394ef715f3e94a00e5904e03d0c113965391a5b3df5700ab79d663f1e2b4977 |
|
MD5 | 41314876f5de23b5a56003c9f99bf576 |
|
BLAKE2b-256 | f8ec066598daae2e90bb397a30350301d1b3174497c864d705f01dabfc56d142 |
Hashes for stim-1.14.dev1712965049-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7b014ea56a6d8536281bb364827bd3e25ffa0201d2036b49e1dc98bcd3520a8 |
|
MD5 | df653b1a29d6253eda2870e981d3bacd |
|
BLAKE2b-256 | 4c16736f601abc549c199f25f2dc4aab70d1238186cb895216cb0ac3628924f9 |
Hashes for stim-1.14.dev1712965049-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ada2d1e993f933ca3df6a65b078452fda52d1078df9ee4d722e4a560d87ab5 |
|
MD5 | c2d264a81d28ebc5766b227df5d2c30c |
|
BLAKE2b-256 | d7df2a410d121aaed8c6787f79c600d642cd44271a9d22c8518b49a2a0d7c4f7 |
Hashes for stim-1.14.dev1712965049-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60f7eb72ea0d8123cea1e10ce0642e41b21de201a083b2147c1a7a05a97bc595 |
|
MD5 | cda7dfbd06c4b6d7e0129031cdbb71a6 |
|
BLAKE2b-256 | 741087609894118a2ec4b84a3220f1e8c4df0707f95d402121a72281b134874e |
Hashes for stim-1.14.dev1712965049-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d373bc68679ea1561cd7fcb25bb80479649406f48b4ebe52de191daf6f9243c |
|
MD5 | 1f3e179d6b6e44a8418d153a91908170 |
|
BLAKE2b-256 | 56ffe30b41560e53ef7bb51e8f830b8efc3ab370c75b29b90e9e670ee6d6207e |
Hashes for stim-1.14.dev1712965049-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5cbe3f5cab1839227148efb64c076d25582819688513db42d380d654ef7343d |
|
MD5 | 0dd92f2e297b6d6c564787b34be22efc |
|
BLAKE2b-256 | 5059dc3993a5e1f04c796a05a1397bf0be8160f507ebb5f5edaf20c670b80fb7 |
Hashes for stim-1.14.dev1712965049-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec3525fd8f56eb39384b49601129db93bff31961cd06dcacdf73479911bb5cb6 |
|
MD5 | 2b07a6ef3026c49ba4903f7d9f1044bf |
|
BLAKE2b-256 | 007c19d10c135839ca2bb4275b7553c79b92fcb8b51bbd00bd646414e71fc1b1 |
Hashes for stim-1.14.dev1712965049-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 873c7656df1b2923c477d8f515dff081a56c6e20011085945789d5cff359e58b |
|
MD5 | 0d6e0c617829e67296a777047cb2dc06 |
|
BLAKE2b-256 | 9629d4939a79922c219f9f41f61427809ccdf469e146d06eaeb26d91b6fe206a |
Hashes for stim-1.14.dev1712965049-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491cf542d7439b4532d962438cc9a1b34b8b7753bcc0659c47ffec91a545ed74 |
|
MD5 | 171401b743528b527861e0a664def815 |
|
BLAKE2b-256 | a5c4e4de41514c0253418d5a601982240073e59b91ab61278fc11aec040ca9e0 |