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.dev1726430915-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5599df7db1925f1c696de3f537968f07a3c4772a82ea7b48d25a100a391ca9f |
|
MD5 | a4463dee63c7e757c635b86e6cd3f0d4 |
|
BLAKE2b-256 | 028ef4504d654ce7d3391fd9143b64b20ecfae88ee189c8804a6e6a51a1492f4 |
Hashes for stim-1.14.dev1726430915-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9debdca5104521d91facc347494c0171be25e03ac64754a2df4494f74af26b65 |
|
MD5 | 4e268c5f4f6de321ebf1a628ba2058b6 |
|
BLAKE2b-256 | 7f0a314edf9a72c17cd545cee0c3174d296ddf418641dd146763d00efc7a2ffe |
Hashes for stim-1.14.dev1726430915-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bd74157abb9c69267c05bf298be81e6e89364bc8f6f9664f0ae44c59dcd1d48 |
|
MD5 | 45c786e5af36ade5211f4f9b6c1b8fa1 |
|
BLAKE2b-256 | 2d723ccf82bec1cfabd115a03439aaa0eb5047367cc42a3930a552d9d8024800 |
Hashes for stim-1.14.dev1726430915-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7da3b42dc6a3d2b33f9112dc77a8a0dc1f50fdb536879cad4929f8fdfc0240a |
|
MD5 | 6851ad412ee50d9570fa48609047c73c |
|
BLAKE2b-256 | 05d5d4aebad44edc84f01330c534b85bd3f24555442d50e5c8e86c063d1a02ea |
Hashes for stim-1.14.dev1726430915-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82b731cc838051ea0ba3b46e2afa646a203efb1d72e8598d481b0efbb2b5381d |
|
MD5 | f99da68e8dafdca57b535d7cac30dd94 |
|
BLAKE2b-256 | 2dff54fcf1086897703185996eebcd42e8d82fa416b03268cddf34a2162e6f07 |
Hashes for stim-1.14.dev1726430915-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2169255e60d566303654080f99edd747ca3e2c3768c4a1f5081a756b36344d |
|
MD5 | 7453a74207b93d4d06b12cf27282d48f |
|
BLAKE2b-256 | 87053ccf48258dfc842e217c5b5d18450c85506dbd5073ce97e94bd70ce9cc39 |
Hashes for stim-1.14.dev1726430915-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e369073db84bb2097f36a383a041572807d7329ebfe68641528ef7bfaab6e89f |
|
MD5 | 1cecbd80f1ca9cb6b356e037b4fe6e34 |
|
BLAKE2b-256 | 4716fdbfab83841d56b27ba01974aefc53cf22d4e96b551c0b3ef3df64bc7a16 |
Hashes for stim-1.14.dev1726430915-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7887916ece1a3de9eda6941dfd01e2d134d5bc9eb395c456ea4c2f6d4a8cde35 |
|
MD5 | 9d22a996983f7e6997b9cf07dddb5922 |
|
BLAKE2b-256 | b7b69916b37404a46a5246608a7599268ecd78942cf64646c08ae5d691fcebf2 |
Hashes for stim-1.14.dev1726430915-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23cbdd002a75a7c488cbdead475f0d4a32080cee1e3a6387a95676f7bd002d9d |
|
MD5 | cd4b20fbe98359e559e0b14a7227c602 |
|
BLAKE2b-256 | faff19d026dcd37ca53fd04fca4634567f76269f59cdfb93c50a446dbc224be6 |
Hashes for stim-1.14.dev1726430915-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b7d31f1f590101c555ceb70689dd21b5c09b395312e035a685e069ef5894ccf |
|
MD5 | 0befd7d5d22dd0d19df662028d904fb8 |
|
BLAKE2b-256 | 02cd629332695825e548619e40df14e6f0379cc3485b0a84e514a59d0aad80ed |
Hashes for stim-1.14.dev1726430915-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 013fff294eca84ddcbc29143f8fe5fcb0c002a2a20d17fff91a8f0e915a902a5 |
|
MD5 | 833cfa08891e8dd9cbb80f6abddf4621 |
|
BLAKE2b-256 | bf534616ae17d3d9dbc36d27dc9b1ad0c5daa1b80307d3bdfa17cef9e95faac1 |
Hashes for stim-1.14.dev1726430915-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21fc56a85c51c9d7eee84f10f4d738db940c728ef6dfa7f690ec88147acca901 |
|
MD5 | 24b04cb0f8d40436699758216ae77ea9 |
|
BLAKE2b-256 | b8fd0d5af77ceb01ac0946c9ab2095deaa4e44e298253319c61e58f8312fd096 |
Hashes for stim-1.14.dev1726430915-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 866cf6ff3ef72c29c3ae4e0b3c866ee94f84a23d59ddf24143995051b34320a5 |
|
MD5 | 605976483f5a2e701d6bb480b6064c2a |
|
BLAKE2b-256 | a65971128770dc26c523a77396379b3df82aced5e9da0463e63186670f2b508c |
Hashes for stim-1.14.dev1726430915-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 030c093e8614dd2ea3aec008e9797deb54ea57a4b79412e6f188218dded923ba |
|
MD5 | dd75cabb4962e0026fdea815b39ec8ee |
|
BLAKE2b-256 | 9602336941bf18b744b6f32f93156febd3e29377343552f5108e3c65113b9598 |
Hashes for stim-1.14.dev1726430915-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | badea8368cc7238ec3c55804ae0601ebb2c0547131c600e29098b5ae927bdb94 |
|
MD5 | 40b42778d25f7f75aff1430e0afeca3b |
|
BLAKE2b-256 | 4b2e02841a0ebda611f34655f881ee8aeda6a3fc3ebdf1c2d2f9bf5e129ec1ff |
Hashes for stim-1.14.dev1726430915-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f93b8ec6615ae5e30b41fc07b44e7ad7eca5ba72821b97c5847a305b9104933b |
|
MD5 | 3975748a2760c599831b31d0efbd0675 |
|
BLAKE2b-256 | ad170839e5e8c938ec8175be88ee5c0dd0e403c6afbdb3614ea44a6ca6ade2dd |
Hashes for stim-1.14.dev1726430915-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291b16b57f340b721dcc2f8e33f463f5eaeaeba50a249458ab3bdd488d783094 |
|
MD5 | efb73cb11efb0c5598ffcae01ab4b951 |
|
BLAKE2b-256 | da24d3d6342ba09e71015b3b8911b3380d824590f77e8c7260a7e21a2c4f6e33 |
Hashes for stim-1.14.dev1726430915-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15bc170668eb5cd523c2d407ec729cab3cb97cfdbfae2c14f09fd297f7895a06 |
|
MD5 | 4bb0b75b1ee59a9c5628e4abf7ac116d |
|
BLAKE2b-256 | 397150bebb81a452438cea1a267bc314dde4a456265a2e23ee8ee610641e2b6a |
Hashes for stim-1.14.dev1726430915-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ee5c144da2c05a13f6d65288ec9d47a27e3b7b878bceae7c9c8cf22fd03fea |
|
MD5 | 67f06175977b5a605110f36432b3f667 |
|
BLAKE2b-256 | 5e177a602aea29d78e2dfb4197a7e299d2305c8f43c9909dc2e5410afa16b91c |
Hashes for stim-1.14.dev1726430915-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6717f0edaaf0aa23250efd86eb452b27136f395c50211e881f8e2f670caa99e3 |
|
MD5 | 6364b9026be8bf62f20db6da38b850c8 |
|
BLAKE2b-256 | 141acf6ed9872fa21b2f097e9b61fd7a9108fe34748acd2af9c2024b09857d57 |
Hashes for stim-1.14.dev1726430915-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1f28a64994f9b74e821e2940c67f5410f60e4803d3e6aa50a3e08a4300b20d5 |
|
MD5 | 3988f46c71357ce6400bdcc4953b1ba8 |
|
BLAKE2b-256 | 240082595528bfae60ac506f51ce9e0bb2fae7d0806de4fe8a7f039043313edc |
Hashes for stim-1.14.dev1726430915-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3cdb1252608862edcf298fcd6d7c18d661fbe9d25b32ccd9ab38489cf76ba4 |
|
MD5 | 7d8b0141424d51d1a447df64752cd62c |
|
BLAKE2b-256 | 3b1db1d03e102e4ff5a2c43763a3e946be088fd52d0786601df932eb19beec9e |
Hashes for stim-1.14.dev1726430915-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 210a9fb24abfc953c060e11503b37858d79bd5d3159a584acb4895a590401609 |
|
MD5 | 30c59e4440ed2a17823bdc23244b16fb |
|
BLAKE2b-256 | d7a5e895e44fa76937ea256bbcbd82fb4ee6007e84650660095bfeb992c0c8d3 |
Hashes for stim-1.14.dev1726430915-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eba7ee69a948c16087d1adfe1f61df1fbeb3596b6bae8afbc07bdc67665856b |
|
MD5 | 2954418c0d695319a7468425d4b83d11 |
|
BLAKE2b-256 | c1d55af9281b0b207d00bc1176349920174d8b33522b4e5dd56a3c1d9e4b3a39 |
Hashes for stim-1.14.dev1726430915-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be97468180dacf1854103103b25199a92e9fa9147da1100948cb74f67447533a |
|
MD5 | 96ee3987843a2f96623958b843f10e76 |
|
BLAKE2b-256 | b7a78ad21c0f8653eb5f4490435fa59bcbce08f8ca68d44d8d5e812d70ccb618 |
Hashes for stim-1.14.dev1726430915-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c77c68d789835ef92ddf6217d2d70f1922a3cbb74bc33e44a679fb8ab5856d3e |
|
MD5 | 6de5f694e2fb0ad95a1e757e8a81f464 |
|
BLAKE2b-256 | c25be7d82a224c8a7a78739d34dec3a04b358f7d58641657edb6937b407208f9 |
Hashes for stim-1.14.dev1726430915-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58286c3ea3be32281b5f88b3d535e80f51567384b3ef89283680fac0a90013fe |
|
MD5 | d8ef815d59d5e1a3bf4e1cb949366091 |
|
BLAKE2b-256 | 91a6b28aef7b5fe6c643066727e8446e8e35972598116d2539df691a3f3bc129 |
Hashes for stim-1.14.dev1726430915-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa9d6c234a7247fc52019f5068297c7c14bd1b03995ad500dab279ac0fb813fa |
|
MD5 | 5339a858cb2cf2d7e1e14ad41ce7d32f |
|
BLAKE2b-256 | abbce0bf63a11b9c65430aca3dcbed2738524a3bc8bfac3bdebd0bd9d25009f8 |
Hashes for stim-1.14.dev1726430915-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b59639a166a8d030781e7eed622c3464fcc98406a2f29d29405b519e4ce007f2 |
|
MD5 | 8c48c75d33ec2659354c4aa6d26e4720 |
|
BLAKE2b-256 | 6d52f9a903fe837caac94d174b1c59b3b65c281490f498e9bdc14bf9f3e0e28a |
Hashes for stim-1.14.dev1726430915-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 938dda3c119b41df026f7b5f3495bef1694e1bbe50dcd18f6a9623df024f9436 |
|
MD5 | 24b9381b9ed8e30b054d6fba5ba55529 |
|
BLAKE2b-256 | 646d1e9a11473fe123dca8406dc0a76377e4e144b549ef70fdf19773734fe2e1 |