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.dev1699526789-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45821dad716475611b7239355b16960c6e377aa182f85de894f7a635646fb9f4 |
|
MD5 | 92addaa7dd072ac47e6389d0740f7ba0 |
|
BLAKE2b-256 | 4ec27a7139d71fb37366441cde6594e33f867da924688349f850905004727d2e |
Hashes for stim-1.13.dev1699526789-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb29d5f66fabe8de5a4d2c7c1d96d4b5d188fee6593b53935ab0b9ef03ed4b61 |
|
MD5 | a1d71d2f90e442dd7c7fe1a806d5675e |
|
BLAKE2b-256 | 41f1b5f2599f5b94af16d97ce447fcbaa36fb6ad99731df1703f116282436379 |
Hashes for stim-1.13.dev1699526789-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2dbff1f68bfb8f7b83ed289d03ef57ff8aa2e494d508c9771c3642a611deb87 |
|
MD5 | f9d1b09a800ff155c68d59be2180062a |
|
BLAKE2b-256 | 3702212e69e9c1a546166da8cb0918c43c73362a019083934276e234a9572d9e |
Hashes for stim-1.13.dev1699526789-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52cdd58fc386fbe196d8c4cc76dffbed0bf26d8a9ede0c19090f4aa4e5fe65f5 |
|
MD5 | 49e4e98d7d79d71b9b3896c0fefc1f84 |
|
BLAKE2b-256 | 1da93722bcc6fcc8f97a80aa4712094f2d711b0887dac40fa6a0475613d6a74f |
Hashes for stim-1.13.dev1699526789-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3ec91c085246a50774da4ed476694631cd05f6bbc2c87fb518a9093d365523f |
|
MD5 | d2c32cf7f9292058e461642ee5245ef8 |
|
BLAKE2b-256 | c9f5915ad95290259ee46de0eb115a91c372f23c9d655e73ca55621cd742e085 |
Hashes for stim-1.13.dev1699526789-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4806ac5545779847a4eee79b68bd510c80f96584f10e4b80e12358f3c0e64a54 |
|
MD5 | 436c4d5c6930bf4d62ff1cfc00f88290 |
|
BLAKE2b-256 | 9e673c994f2317bb777ea23ff39d5915289c481f1efc5cbf6db048b623d0a622 |
Hashes for stim-1.13.dev1699526789-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a17ab552e649212e52663c92d167fe521d6cf06d0ccf7f8b57f18af9261d193f |
|
MD5 | da2ad99ccf0e7a79a474c3171ce06d50 |
|
BLAKE2b-256 | 4b8a8280557e5c30755bc469bfb7f58b99c5328c6e27ba3fab95c08dd914ea1f |
Hashes for stim-1.13.dev1699526789-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ae71ce7dcc1365676c886a2afae942b80aa58772667a1f9db008e34fa5e329 |
|
MD5 | 2096c4157851e4247a0309c1fdfd493e |
|
BLAKE2b-256 | 68a1b1e092c235261400b70531cc48ba172498035db2b08ec881a9c8e1d00ea5 |
Hashes for stim-1.13.dev1699526789-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7b9e023f453175ab51f756a5cfcb49d550624dc4cee013c7b64e3c752c9f462 |
|
MD5 | f7764d554e85948ddc82cbf2b23db465 |
|
BLAKE2b-256 | f62865052806cf9261a54f150cbf464e8ea6360c908523f6f4e509723b40b69c |
Hashes for stim-1.13.dev1699526789-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23f61c69e5c071fc4d9b0aa3426109382c3790459cdebde9b9abff1f1ba4c4f |
|
MD5 | fc86ec0554315611c26c03da49d5fde4 |
|
BLAKE2b-256 | b49b946f8febb9b57cf07d890278eef84889f76b46b27f2d710a782eb22d9fba |
Hashes for stim-1.13.dev1699526789-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0b7f44c663076f22facc63329f444fd1de6ac456c10562eea19e2e5080e3ba2 |
|
MD5 | 55c00fc0c794a1df494837b28ce8094c |
|
BLAKE2b-256 | 85e834bd229cc9e8c13968ff135404bd6d80866393e35431d22c7d2993b2e016 |
Hashes for stim-1.13.dev1699526789-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78e6cd3f0b472de6ab64b07724251291b6afe6634a6ce9f264513b8266efba7a |
|
MD5 | d6a5be6a9f60cb4758b93e59ed92c4a1 |
|
BLAKE2b-256 | 9247265ea478d565a8d0f40990503e8c025a396d75d4d8a42e2406331e501808 |
Hashes for stim-1.13.dev1699526789-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22615356b40c848ab3c1de98eb45f58aff31d23262a22892d1a8f9d335228e5f |
|
MD5 | 0a93d5e318ad61ee82c5a178b01118f8 |
|
BLAKE2b-256 | 1d64b5689461e4b4bbb5843c87693aa0741a6d556b33e283874a67ae89b68051 |
Hashes for stim-1.13.dev1699526789-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2821ae973198b482267a9bf5fbd1a8ff72cac0e51f14ecc790529547935b466a |
|
MD5 | aa4a5974c092688678e4e2e28d7052ce |
|
BLAKE2b-256 | dbbf190d8a7644105c0952c5d7bd3a243de634e878ee02207c20868ffe381da1 |
Hashes for stim-1.13.dev1699526789-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ce78d1d9be98fbb1d99fc607dbacedef023f79a7ddb8aa4954632e986494cca |
|
MD5 | 17ef6bf8bae1ce55fdd98d36092398e9 |
|
BLAKE2b-256 | 4502b3a8c54de443678b505d4bb75b56f7bb4f5ba117d6c05f8681e27df3b61e |
Hashes for stim-1.13.dev1699526789-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb0aeed03d319f189ba0023942964c5ca064bcb4d75cdd30ed88c0f7e507d266 |
|
MD5 | f60a1eb8ef0b8ea5f8ffb70dd7cac7d6 |
|
BLAKE2b-256 | 21294664cdf32584248e286ea25d692080681ccff093a79fa50336d35bfa0c43 |
Hashes for stim-1.13.dev1699526789-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 312af2721eca1b5a0e609fa58c46070d094d6404c9ba9ae93780a6870a05e0ce |
|
MD5 | f0d409640ae6b460411c98298e2b9e5a |
|
BLAKE2b-256 | e0a41731a55896ae9505c2d868bb3894c972ebe4c736428fa8dd3b9e86df796b |
Hashes for stim-1.13.dev1699526789-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4546b3578545c71f7339b7d700f858fd8dbf56ee0bdf95a98ff59de6cdd0187 |
|
MD5 | 136a54ccd4b00ef6ec79b135e369cde3 |
|
BLAKE2b-256 | 1807823b5ac4afc13690fef8d91e72e032b2fced312718e04d1189090fb6c822 |
Hashes for stim-1.13.dev1699526789-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f4eea20998b88104667de09502e52867e99300443b99a4081701878c70aa722 |
|
MD5 | 86f3f89e5742b2d62d0fa504052bed5e |
|
BLAKE2b-256 | e3f40a4661660c84de40a302f2d53f64a60504c05993453f5c2407ba7f02e719 |
Hashes for stim-1.13.dev1699526789-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816d58f1c2d11fd0cae744b1837599713e2b9c7961a8c9e9b5098abf0c9ef96a |
|
MD5 | b84a368ffbd31a66301eff0c081d5dc9 |
|
BLAKE2b-256 | 07f7ae27cdefd3659a0166264e81be3314c556c467d8df1c572220940724726c |
Hashes for stim-1.13.dev1699526789-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33b55f37626d53a62c9eee68d31113f1b21127bddf1143867774e881455bc6ee |
|
MD5 | 28bb126c90c283126c00f41bf679be9c |
|
BLAKE2b-256 | 2ef0b38bd8cd91ca43ab8dcd6b402df94888dded31e1066a18810a6f9616c0f4 |
Hashes for stim-1.13.dev1699526789-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29b71ca766205a563db2007f0605aa4a8794e77a55ca2e8e660c6c7cb52e2e0f |
|
MD5 | c9f2e30290608964c4a73034df3e4cec |
|
BLAKE2b-256 | 8be357d7c1b4d1632a3229fc274280e4fb4092290486253da10b18fdf7e36af8 |
Hashes for stim-1.13.dev1699526789-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a92a70dff71b1d6ab42fe22ac74e9d57c7cbc9510faf240f4227920e116d4f |
|
MD5 | d2342b6bebbe28a7f661fc03fbca5195 |
|
BLAKE2b-256 | 9afc951129dfd47ee2a56ef4b39232a798471280f9ec26ed297dd5424be700ff |
Hashes for stim-1.13.dev1699526789-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b75b6735be67464f1592e25db59c7aa43a8b967155b10a99ec1108b122d53af3 |
|
MD5 | 22fbf91357b9196127b077f2434adf12 |
|
BLAKE2b-256 | 438ceee2e1a220d833a7ab281bfa8410be5f3c886d050689a10c440ce2ccbee0 |
Hashes for stim-1.13.dev1699526789-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c73083e930eb20d09e90458e480705ae96eb092204896d4979483d605eb8826 |
|
MD5 | 0e6cc9caf0fb31c44e8ee538492c2699 |
|
BLAKE2b-256 | 63de1d1c4f492c69cda6b1da890af9ebee67122f9eb7fc0af51ba989350013f9 |
Hashes for stim-1.13.dev1699526789-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87d0bf7c1532505d2db4d93f235001a5526d79952eda27f5fabfd5032804abc9 |
|
MD5 | 2dacf23f675d676b756bed88b23a1cce |
|
BLAKE2b-256 | 1d4682143145c8735b6b0d3d664b0e8f2a3602d0f80f2b5ff407631e8faa0069 |
Hashes for stim-1.13.dev1699526789-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30a2213fe1a4eb64b786df8c1cf4688a1abd329806285e82aec3438a602477f5 |
|
MD5 | c5d3403813496e4829986551080a1385 |
|
BLAKE2b-256 | fe7f9c57dd471146216a02a2ee3b460402c366f56c5c760546623a8a6009f49f |
Hashes for stim-1.13.dev1699526789-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ed6ac9bc525988c6587580254b1a45e638cf84d7a780c01abbc494c4a6e002 |
|
MD5 | 76d3e575ea4db1d6147f59ae408168de |
|
BLAKE2b-256 | 648cfb13e80ddb3da1765b908bc095b48c804d39a8004eba1434285bd42c1077 |
Hashes for stim-1.13.dev1699526789-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dbe8cbfa619e47364f9928c19af0f0b5ef10ca1ce35db077005a83c367d062a |
|
MD5 | e5140afd3bd9fe1bc47bb46101a376a8 |
|
BLAKE2b-256 | df51ea4f9e12139cce20988f8a5dddb0b4e5b23200dc8d7f5693011cf0ed76f6 |
Hashes for stim-1.13.dev1699526789-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f97c98956e9230f98da61e948a0d594e5b812891da7d9b87315202214cb9ca2 |
|
MD5 | 9b4e45a88704af67c030d4993129e3f8 |
|
BLAKE2b-256 | 5123fe3384cc33667a66eb345400aa6152d4e12f250dcb695de53c76b82fd7df |