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.dev1702289706-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d9b4f153376a1bfb450647ee24c39dff3a73e2b87ef837ce0897a55935bcb56 |
|
MD5 | a1ae86ea2aa9cf86cf8342d82b3dcddf |
|
BLAKE2b-256 | 49ef247d19202f48a75b5b36ed1b8b0d0f7f6f1003b4009bb9ae01826f12bacb |
Hashes for stim-1.13.dev1702289706-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fffef3f880c887a3586e5c307a03612f48f903115516dbecf631daedd99b1353 |
|
MD5 | c785abadad8db6133343a5d643f8011a |
|
BLAKE2b-256 | afb49861383e88e8acdbde3652748c638df4bf60379b11b3bb55aaa351fa5d88 |
Hashes for stim-1.13.dev1702289706-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84f41cfec89059a24f67a9768d84c2f26442683ed8d6d3259c0681441e72e207 |
|
MD5 | 4f0c16a3143c5044988d07256f64e944 |
|
BLAKE2b-256 | 561d413ca80d26f71648628d723dcdee73f00046874f2909b6936589c6db9d20 |
Hashes for stim-1.13.dev1702289706-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8123de255fe0a98bc1cb5ee8eefe31e9b079a3cab6ab93b31a7b09cb08a56aa4 |
|
MD5 | 6d3f652940de34cf6573457c720eb6ba |
|
BLAKE2b-256 | cbf1c3891af080e52e3695fb7175fda57df6cb92b582a42c7e0932adb1e3f44f |
Hashes for stim-1.13.dev1702289706-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e00aba26fb4c1fbca344451dc2931b93928decf0af3b8dc6d18e50bb3b4ebea |
|
MD5 | 300a2b7f38a637763a7b3f8e8423017a |
|
BLAKE2b-256 | 5aa3724c51f630156219af519d08d6203f44cec7a23d5ebb19ac7efd7ca692fc |
Hashes for stim-1.13.dev1702289706-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c9d7a2ea9d1db22b7f940d34748696e452ba5f096580a802b87213912e8d478 |
|
MD5 | 58260c06613defbc3e4599837caa6467 |
|
BLAKE2b-256 | 110476032cd623118301e917f32d187a53aa90ea8022c47d3ed6b2ed5a1f7004 |
Hashes for stim-1.13.dev1702289706-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db4f3dfd384002d2a61434071bb50024f6996a21f4cc60c4434d42eff391e02 |
|
MD5 | 34c728f4e6421e46633a880f30d36d45 |
|
BLAKE2b-256 | fb2de0dbf8486e9b8a3834f8eddd59ba58d187738b967d5d88a5cce67a47b59b |
Hashes for stim-1.13.dev1702289706-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c68cf660194d18f55d4041df36a986a5c0415e00a9fd9d52ef72c3430e2e6317 |
|
MD5 | 53c49bcd4935aae1956e1cf0c4bd683d |
|
BLAKE2b-256 | 767cfc2d6be0906d5f9f7aa79606c2a2f9333a5a1fa69a39d17a9d7ee3d33df2 |
Hashes for stim-1.13.dev1702289706-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5ba49e8aea0585220168e82e6f7ff990957b13b8e79585f0ccb1f47abca4f96 |
|
MD5 | 069dba60131d560f3bf9b3e10f919ad7 |
|
BLAKE2b-256 | 070eb897a157a2245cda8e05570d8595f27b80b05c9e26673ad6eb371e160188 |
Hashes for stim-1.13.dev1702289706-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d157739bac2db205efa059c7ef36f65c2847bf824f043de091ad63a09b7b2f5 |
|
MD5 | f7ee254ae450590598f9e4e030f97c32 |
|
BLAKE2b-256 | e1c5cda5417014229e706c14f785cfbce4d4de77528fdc6318a2fa3d7a115f4d |
Hashes for stim-1.13.dev1702289706-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb73be6b2d2a24328ffe94f2de5fb46b4f46008f24f0c61638173e26b19dedf8 |
|
MD5 | 63b42cc873b9c1ab8c4065cb26e17ca1 |
|
BLAKE2b-256 | 8f4e9cacd95a19e79824864699f5984c236777575709b5a899c5b21f1d78b70e |
Hashes for stim-1.13.dev1702289706-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac7c5820fccebbc4d8bf37f52ca7dbf8e1d7d927e55dbaaba2d17904774f64bf |
|
MD5 | 505e341f935a32e47470e8126af661a2 |
|
BLAKE2b-256 | 03a3086a389902c59528eb59e654de678c9d107abe03ca35bd82d024eb66eef7 |
Hashes for stim-1.13.dev1702289706-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 834296928736d83e50b867292579bbbffc287bbee5fd4d21bce009937ff6c0e0 |
|
MD5 | 6785dfeac85cc5eceb5005209a715189 |
|
BLAKE2b-256 | 2e1630c3524496f4e520b2c0089f5f8dc48fa4a5ee90fd27a532d7f015270373 |
Hashes for stim-1.13.dev1702289706-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f706a34e8b8d1338dffc4ab03a08f0aefb9e19eafcb2a469e295bc7b42069b38 |
|
MD5 | 50766bf64c2833d8b1ff5e115ef0174b |
|
BLAKE2b-256 | 87888719d505410cc65199eb300bbc7aa84d89ffcf48a5f80a63a901e24670ca |
Hashes for stim-1.13.dev1702289706-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2faf5470891931c8d9c19bbee8e253c539d8763cde3bbe9536cded2a7b796d |
|
MD5 | 160c1b9f4ed5884085b1876105369715 |
|
BLAKE2b-256 | 209686fcb1bfd4955ec049d2aca13883adc06eca568343de5ddb077b3803e6a9 |
Hashes for stim-1.13.dev1702289706-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68291fcdf66ecd32e1212ac375ca74f18d80d82936748ad1dc055652f5123167 |
|
MD5 | ee0174451a8848a77e7909336a04c8a0 |
|
BLAKE2b-256 | 18c00a38f7795150f301e3fabc3f9e533da6ffea539f722828a7df5062f4febb |
Hashes for stim-1.13.dev1702289706-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b189426e0a03cc27189838a1554fa141d7f545023819a63f17f6e88a4e31c6e |
|
MD5 | d77edd60621d04fdf61cd238964b2758 |
|
BLAKE2b-256 | c8e6c515f5e55cefcdc1f3da868077eff248e1c023726c24f67a84fe3d004e19 |
Hashes for stim-1.13.dev1702289706-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afd48b51737fa32b99d851e6c3d7dc49af218968bc14356e675d27c8d5d11d4f |
|
MD5 | 0fd96cb35e1ef812b96c287fa2d1bc01 |
|
BLAKE2b-256 | 957081b738631a36fc667a0bbf54842eba810772f7fc270f7829cb795d1c7e8f |
Hashes for stim-1.13.dev1702289706-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e25c89787d3eaa028bc6356bb717f0d839f46b5dedda73332bc3cb03e0f5ae10 |
|
MD5 | 62ac61d916cab57e6501702ae892f29f |
|
BLAKE2b-256 | 2e3d73ac080c4185c2c496b951ab50721d46706d152bf6b3d4d6e3c7256b0366 |
Hashes for stim-1.13.dev1702289706-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb3afd3189bab3a06f1d1778293752add75ee3c153907011afd8f28323ba6f1 |
|
MD5 | 8afdffd9d4d9649c783c19b5bef33658 |
|
BLAKE2b-256 | 121debecb3ce087c49ae561b701260d0519c4e511d68df0911cf7fc1a1974865 |
Hashes for stim-1.13.dev1702289706-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7724483baf6a9f7b7ab4e8791bde6bf15f148b4925c7c44c4e23b527fc6f679 |
|
MD5 | b597f6eeb4e0fa1059821f7e9c57d57e |
|
BLAKE2b-256 | 41f6696231c2cb2c60a8fa29fd60b2d4d1753e7c92074c1f133bc17f6c60fcbd |
Hashes for stim-1.13.dev1702289706-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1f82c58a5f7df45e2d5babb0ec57bf5f1f34fcf59f313a465c746af296d36af |
|
MD5 | eb8dcb3568854030a066d89f3e5e2d52 |
|
BLAKE2b-256 | af8b05c4918c4cb90f633bd3578609acec768e9ef3109bac8e089db72c75dc43 |
Hashes for stim-1.13.dev1702289706-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 106221d5ee0d31e7a6f5806919084345bb1cb21dc1579769b785f4ab1375bf02 |
|
MD5 | a4db3bc001d1cde3bc888be389212ceb |
|
BLAKE2b-256 | a804e5d6d576700ebe9b90ccf72750188efb70f849c112abeb164c22a0f914e1 |
Hashes for stim-1.13.dev1702289706-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeea02bcce22a693cdbf85dc50475f4ef03fd2ebd8da8e8b5131a879fbc42a13 |
|
MD5 | 2a6a3d3fb13c7baf13c63ba186913f43 |
|
BLAKE2b-256 | 1d7b31fcdbfe3d82b57ca9d4c299d48f969a9f527f7561d3859474674f180b84 |
Hashes for stim-1.13.dev1702289706-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3da02f616f07f2d9bb7dd84881f8095f8f491872c558b3dc7b7ec001f91ad7e |
|
MD5 | a833ddd071d3c68fb3c7124087a46d63 |
|
BLAKE2b-256 | 24c6c346d157e0a22ed01802b8e9be2ede6417482ce09f560f36874b51eae400 |
Hashes for stim-1.13.dev1702289706-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9f6064811d1f7f3c2068f3d0b94d1dd0fbf1d36b12462df6438a9122952b1c2 |
|
MD5 | 38cfb4a44231b48acbe3a04956374e96 |
|
BLAKE2b-256 | e182239341eef04c47cc280eb5571b7b54eab1446796bab70e4e2fafb15b87e9 |
Hashes for stim-1.13.dev1702289706-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 689ecbecc3b52576212935533a85d6eac0881423f017a490f18a59b91ca1ecb7 |
|
MD5 | 1a5df893934af64df2cfc1df96f460ad |
|
BLAKE2b-256 | 8a3ae7579cd1d46170c3c7294c2f795084a6fd3283ba7140f5d5c4f650130b24 |
Hashes for stim-1.13.dev1702289706-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37a154774779abaeb4c4d848ef614ece64e9f574554031e289c985ece296f256 |
|
MD5 | a6ea9051eff48acd3d7a874c86f28e4e |
|
BLAKE2b-256 | 61867c9b9d96a887ed34e5631419efd64aee6798b1318e135f1c61a06b1c8c3f |
Hashes for stim-1.13.dev1702289706-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3baf9c25f83eadc4552e6e126c2f9a5eab775d52ceee5dfa7850fbd4d6c789 |
|
MD5 | 587caafb0d9a59e7dad5e8b89b9dfe51 |
|
BLAKE2b-256 | d4459b01684320fac88daf0e4d62789a229734ea8aaa47ae9c1a66bb1178e004 |
Hashes for stim-1.13.dev1702289706-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0bad487495d4f6584af880ee05357759eb6c831a03c99ffd7a06bf6daee06b |
|
MD5 | 23fea314ea2ff31df170c0b6af8cbe2d |
|
BLAKE2b-256 | f01d86124488ce958b91d6735f9924ca53cdb75c8079217e02279f60f06a1267 |