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.dev1700898803-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee79cfbdf14e28dc5973ae82f48c90ace898c2297dd16d4739a3cc4ca4178327 |
|
MD5 | 0b6faf88820b8046cd1c86922641deb6 |
|
BLAKE2b-256 | c25473221feff96d5dd8bac6bdf4d861f1f7c02bc1414607d7d67b40460c039c |
Hashes for stim-1.13.dev1700898803-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2546ebf0013b838e23509def9d052848830356e842b4838a5674fd7df8e9861b |
|
MD5 | 0a21fba22b227f703ce5ace6e30cd76b |
|
BLAKE2b-256 | dcf9365cbd23eb54a2ceea5b339bb274a260cfd339f38f28b215bd1727cb51be |
Hashes for stim-1.13.dev1700898803-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c25fbc646b9a8df39fad937a03a4d840644a86791a03199047c84bd05993902e |
|
MD5 | e39608704d13904ba84fed9248972a1b |
|
BLAKE2b-256 | 76f9a1808c4b6f6463d796ca6ca1c63b6d2b029288efe81e5b7917b4e68ef357 |
Hashes for stim-1.13.dev1700898803-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6409a4314b029341ad5f3eb882c5487e0d21098fff6b81c1a00a5bd01ea601cc |
|
MD5 | 86ae068c8de1f9e90067bec702b8341b |
|
BLAKE2b-256 | bf2bc951c1379deb936b2108ddb5d035627707b639302212b7097dae9759078e |
Hashes for stim-1.13.dev1700898803-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 472686541316080f647f3f7492d241660adf4788fd8d4ade743c2ea36f7c4997 |
|
MD5 | ebbc781479642a0799dfb11a832226b4 |
|
BLAKE2b-256 | 71fd494d2454d345bddf35d44e54262d4014d17b0a13d6d7c95235bb8663f265 |
Hashes for stim-1.13.dev1700898803-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d92d058d59068ba76d70028db1bdc726a08d0ff69de17704a77c8bc24e646af |
|
MD5 | 7e16123ca226c8ea56989fe783ae2c66 |
|
BLAKE2b-256 | eaef4132273729fad323be7a4b9ec79d685a2c9aa8d9ad48bbf88b3b6091d785 |
Hashes for stim-1.13.dev1700898803-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db0e42b88afa7824aa2b88f1eacbf8bd4b6cd63081d385a2294b85b6c651ad48 |
|
MD5 | a461e3a925dc197948cd2e5228237f02 |
|
BLAKE2b-256 | 314eaa11ad76de643b9ea85893d02d85d66843cc957378aa41acb9fa82ae6c09 |
Hashes for stim-1.13.dev1700898803-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b74ff3556be65a4345b221f2b43e584d0cb7998c2c4fe9c97ba2240f21efb0a8 |
|
MD5 | 618f51d563a77bb19f7228df19389c7f |
|
BLAKE2b-256 | 10d2fade2cf6867c2f077940190ab12f830c47b90d015f7934cd18d0f4937c8d |
Hashes for stim-1.13.dev1700898803-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f9e9f7399180733d2e2b5cef66da7418d5b9f6156921e9f66639b2f0f9a7a83 |
|
MD5 | 63fa8ea10aae1f6bf351fe388680a84e |
|
BLAKE2b-256 | a0dda8253a10d469e26bec3aa1644ee0d8e402705074c1d5d7ceb4f8862c7aac |
Hashes for stim-1.13.dev1700898803-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50ea9757cc63ccb1aa13b43f3831a7efb9d781d4cff6fc3f053369d11000ab50 |
|
MD5 | 55cccf18b2c4852388cef56e5dc7fdd9 |
|
BLAKE2b-256 | a25f38c977d73aeb4ef7d1dae7157b4e0be98b35f5814d71f3f3d4ec5be0335d |
Hashes for stim-1.13.dev1700898803-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8aeb6e95dfa55b04ee1b7368b9eea167f4510729dbc61d3c766cccb54dc8610 |
|
MD5 | 14f362d38090173c0f55c246de84aeb3 |
|
BLAKE2b-256 | d0624fe5042d43c40bf2c2130c2fe1ae71fdef8c74cdba973bb404bb2e208186 |
Hashes for stim-1.13.dev1700898803-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41365428534e715dfb840545754c682272065c194322a9000d3db08629f8580 |
|
MD5 | a7da76a5fe62f60695b692522e732057 |
|
BLAKE2b-256 | c36bdd4aa20e0dd976dce5ffa90d3db03d3a2279fc80b6c19cf77d03966bf45c |
Hashes for stim-1.13.dev1700898803-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e58a9f1c3f8c636a74546174a4b34d106c4b153ab51d6506c5fa723c8c8bd390 |
|
MD5 | 125b9ce32f09d48b55467c1da2c45fbf |
|
BLAKE2b-256 | 9c3fe4bb8139d2fe1602c9de6f3f3d8d7a7afee91c0d121907b7499f1639c40d |
Hashes for stim-1.13.dev1700898803-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e899dda9df08a20379c61c5f1dd2fbfd94380c9e1b99a660134ecec109ce469 |
|
MD5 | 65478b67fc159c4960cfbcf9638a42ab |
|
BLAKE2b-256 | a645a5e9682f688b91f3e648c4e004d1b6056d7c687e8ce424f7bbc69a23c3ea |
Hashes for stim-1.13.dev1700898803-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3587c0ca2f825d7dd2c74e2dbb7646f73df84b48f73180daea14e0e39f085cf0 |
|
MD5 | 50d010fbe6644035889d789578ef5a65 |
|
BLAKE2b-256 | 5879bb09fce3e754d473be3334b9a6228df08cef973d444e8536bce200e969ab |
Hashes for stim-1.13.dev1700898803-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba86804b7c37c74cc09d147bed1a2a4951a604e0d7c36e32bed85179a9af4b0e |
|
MD5 | 3ccfc9836143c96630c4f464cef771ea |
|
BLAKE2b-256 | 2881b02ae871c5ff2c2dd8f1a8108a1d9db6a1e0af4f8fc9fac6da73299edc90 |
Hashes for stim-1.13.dev1700898803-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a73478b00a59f19eeb762bd11f3d5a87798be4d1ded6ac83e0457a5859f51fe |
|
MD5 | 2f6003894d0300fc6242f96d51b593a2 |
|
BLAKE2b-256 | 72f6691ac193a9b4bd4fbd817622543b67436ff29eb8d3e5df27f860804f0f3b |
Hashes for stim-1.13.dev1700898803-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55de9a5893361bdd9342e392b6365611ac6b8801dad87153c2c0db4b70a53196 |
|
MD5 | 34f5bf057aaf367ad3586cc9a769785b |
|
BLAKE2b-256 | 6ec327d5f580c7e8cf61fd13f1465416158d91fcda2d83532130edfd951b596a |
Hashes for stim-1.13.dev1700898803-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 313e040d55b2eb5cedfe17f531bb04f509de9eec8a87b4c46a0ec458dc20de79 |
|
MD5 | d9e65b269d6edcda7b65676d8e8b3c87 |
|
BLAKE2b-256 | bf40d72c4c262468290a70570b9c1cc9a913b3c0ad22caba084ffd6ef2a7d065 |
Hashes for stim-1.13.dev1700898803-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc9d53299aacca588d19f50dcdc3475b617a7f61da888861fafdf4800c8a8cff |
|
MD5 | 10266428731e385c76f910388627ee48 |
|
BLAKE2b-256 | b647d0c1870df676c5cfe8a01f5ca016e27599c0e00a3773480fb6eca63370f5 |
Hashes for stim-1.13.dev1700898803-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5dcf279dadcfbee25196546bbd2ec005df7e01d08b49e9b2cda0bcf4fb751e6 |
|
MD5 | a04c43b99cb35af0b5be909bcdc0cb85 |
|
BLAKE2b-256 | be37d3869202ea6f486f15178c45259aaa4b02894e1a9baea54c0ee98226527d |
Hashes for stim-1.13.dev1700898803-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1923d2e3421fda50b63f6ae33446feaf07da8574fcab1ca6e5adf9b19014f444 |
|
MD5 | 3e63ef631a6313a259368e900e32c998 |
|
BLAKE2b-256 | eaa41bda92ee7bf83b066a3c541eec62a414b76190e9082e1e42f7bb69731600 |
Hashes for stim-1.13.dev1700898803-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69f266a9cdb1ce484c5ce2391d10549cf0a92b00dd6d027310fc23161d02db83 |
|
MD5 | 66356201d04321a766201673cf02e374 |
|
BLAKE2b-256 | 32fdb14ea44e112a7c82c5cefed8ca07d465a8bf5b761f30038449e7ee52c231 |
Hashes for stim-1.13.dev1700898803-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71e951b2362ef7a0cdba9b2730e2853e165cb0baeabacfe0810a957c4360812c |
|
MD5 | 39789e921ed1e06fc421bb6c15f0216e |
|
BLAKE2b-256 | eb5d3d53301a489cb0e5a5de0fcd0bfe1b18ecb97ba68058ff1b06a97760f54e |
Hashes for stim-1.13.dev1700898803-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 667eb784c8e939890581afc90bb758e70c4a50ab120faa5f31dca41819a430a5 |
|
MD5 | 9534d7560dfa30d855e25b9297b9dd60 |
|
BLAKE2b-256 | 2f5ab7d98a757d91c3645d66fc6dd12fa91fbda4e8b49f41e6e297cf9648f4a6 |
Hashes for stim-1.13.dev1700898803-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5310ec0170dbe4988eeb6bc02b308886c1a4b771b0e91d89fca0c32c5cd766a8 |
|
MD5 | a9500198fc55e4e383c13b44046114b2 |
|
BLAKE2b-256 | df790104bf0dd6329f1c7ce054d0ae1fa9816c22ac76e2f31a7fcd7bd4aea7a1 |
Hashes for stim-1.13.dev1700898803-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a66031c62985b5a078e7245f516e56943c867bc0b2b5f3b2554298f9055a5b64 |
|
MD5 | 0b4cbf837c357d3085751d426c7a1dbe |
|
BLAKE2b-256 | 3844593e4578a03f80d1c004b9bf09e9c2c44581c5f8c96444ae28289846acfe |
Hashes for stim-1.13.dev1700898803-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b161a463af82d5ff317f300f87abd50dba4e061deaeb55c2efa95f1b072443a |
|
MD5 | 82b763f2cdc6910d55e8b477e3571b93 |
|
BLAKE2b-256 | a1ee7e08b381ab588f0e7813cea87a03a7dfb951a64ddef877bba28a2af325ae |
Hashes for stim-1.13.dev1700898803-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb61fdc8e3c52f37bd3958fc5167fa67c23c1ae964a4f5640c50ae813eba3239 |
|
MD5 | 5b04aac206a677be18b0eaaa533a245b |
|
BLAKE2b-256 | f15d8017fe7470b9cc5f482421706a877789e1534ecda9230bd3e37911976b80 |
Hashes for stim-1.13.dev1700898803-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3773df61d52a1d7fbbcd744b1b575c1d0243962c31dd90f38480d239140bfa8c |
|
MD5 | 8915cbdb64e4ce8bafbeef8b4eb1588f |
|
BLAKE2b-256 | 4ed546e5738e88d6f3af4a7cfb96c906c15d7ecba3068c7c29b0b7edbfe12a30 |