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.dev1701334149-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96522b119a22f277b1eda3e3fa5a7787bc2431dcb7226d028c3c7b240da26b0c |
|
MD5 | d06eb9303aaf82d854d22c4d10a0c130 |
|
BLAKE2b-256 | 5e2921626df5f0c82ac53349ceed2f42b1deca354ec9a4ffd8161374a94eb13b |
Hashes for stim-1.13.dev1701334149-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e1c21469c06af96791258398588cc4804779b2d91ee76ce8f8ce5410ab2b34d |
|
MD5 | 4592335fb2b564fb67246110ab1d9190 |
|
BLAKE2b-256 | a37886cc516b6624c2b95fe54ee0771283deb7ef4fd35cdc0ee12b591bda2cf3 |
Hashes for stim-1.13.dev1701334149-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 090af3b8d9cd73c3c72a5772b3ef080e34df9eda72c9e285dc5e70214e9def12 |
|
MD5 | aeb13146cdf81f8d24bfd0516c530ce7 |
|
BLAKE2b-256 | e8dc9827f9326fb8278a2b413b2e9b0011ec1c9c2ecfe31d4fdee87900a74d55 |
Hashes for stim-1.13.dev1701334149-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e4f7ebfb345158cb7670500b414df04ed7d4aac4444474bed2982ff62e8cdaa |
|
MD5 | 7e77517a1460fa695ae189b219923fa7 |
|
BLAKE2b-256 | d9e12b33a5aaf8d64dd1279bc2bf30b9d0d24fffac4aee50272851b2876de004 |
Hashes for stim-1.13.dev1701334149-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2235e0d920c4bd8e0c6aaf902b3c2d2d6d8edbc12264f236a29860f09ae37f6c |
|
MD5 | 93a4a7423b8f72daab62e9b0e1c38ad5 |
|
BLAKE2b-256 | 63bd16fd9a5be1a646371f4d5307f34606379cec0957ab6f1451bb729015efa1 |
Hashes for stim-1.13.dev1701334149-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6673b09085bf15e6d8de743827ce19ac868560b4970404545b6eed7860515bf |
|
MD5 | 906ac244b11f2cf14e4a4c44a25d825a |
|
BLAKE2b-256 | 7a292d4936cb3a82c373a1208d9ba02aaeafa2bdf8c961828a5dfed778b26ffa |
Hashes for stim-1.13.dev1701334149-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74f4d27bc8e8a8dd4f9a821a12f7f64107263d2b8b0b50675306455475981f3 |
|
MD5 | 1c0008c8eecf6354723bca457736f327 |
|
BLAKE2b-256 | 2839a66806f72a094daa62d26110afd38e65736e57137acf180715e351fe904f |
Hashes for stim-1.13.dev1701334149-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bb5cb3d438a54b8c4a4e264682e3908c9d3dd72b9fed5e681ee0929dc4e275b |
|
MD5 | 3d22e2808fa4243307a05c23be29c3df |
|
BLAKE2b-256 | 4dc61507a7eb4f7b3181ff03e6bd72e8e37433be13fb7d7f055d03640ce60ce1 |
Hashes for stim-1.13.dev1701334149-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed51e4c1306b3b90e9ef6f1f83c619e6b7d716e0e29482364deedfb1d68c8782 |
|
MD5 | b91d6ee7d1dde6be9b23803b6a330e19 |
|
BLAKE2b-256 | 4ddfabd924b1852781222e56c2b5b6364d59457a73d0dda791330a86783bfc58 |
Hashes for stim-1.13.dev1701334149-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1114d241e7a691537d31122059d1adf19542f39c665408a8a87d5ff75ddb0bf2 |
|
MD5 | bba19c324a99a9a6b2367f2ea4e369a4 |
|
BLAKE2b-256 | db131c6abf61180c24559d4dcc483a1fd7b209c6d9ad493c20beb772676a1f0d |
Hashes for stim-1.13.dev1701334149-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1cf44ab6edf1f7481ae3ecf5b6dbae457ee83d2af7a596fd6123846022f1efc |
|
MD5 | 939543dd2387a1305d2d5f44fc9c67f4 |
|
BLAKE2b-256 | 9566eb2f66dbc14b78d5a00d22e17ba3d95f811a04356d54413ac45d6992876b |
Hashes for stim-1.13.dev1701334149-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 570a94921baef7eef18cc0a0f42f3df9ec13e13ce31cb5e47c750c27f280d3fc |
|
MD5 | 155710ed36520942ce08bd3c10934d97 |
|
BLAKE2b-256 | 4681fc099a579244ed11ed5fb93114885815e68abcb15bbd0d174d1c4b3ac559 |
Hashes for stim-1.13.dev1701334149-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3a8286deb0aaa7710b7a43111fe8bedb161e89714d8305b3c97c063301cd4b |
|
MD5 | ba612dc9abaf9a9224175ed211d4956a |
|
BLAKE2b-256 | e744d761eba5e35d301127c62fabb0972c5b948a5da39089744495f79b699f89 |
Hashes for stim-1.13.dev1701334149-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15728a3a2916d33e44d68cc257a5ce666b163cf4f2749af876f2564415106a30 |
|
MD5 | 7f067ed867b64acecda7dc816e2e571a |
|
BLAKE2b-256 | 3a8d3ee892149dd8edcbe527b32140289a52c3c1f77417a3f5c3b7e7bcb7c0ce |
Hashes for stim-1.13.dev1701334149-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3774b4da7e400a770c013c11c0b81f7f8e96c6c8b33d6ae873822c2a8cf7c6b3 |
|
MD5 | bef107e165a53f02550f6f1926299eb4 |
|
BLAKE2b-256 | cf5686570792eb6406995496388aaf4ec1f4f53cbd09924a68024f7f0fcb1ed6 |
Hashes for stim-1.13.dev1701334149-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df48aea98d5e82c20cf9634036f66275615435f8d7ecbb4ca4aaab7b75ea2d41 |
|
MD5 | 8925ca0899c80ceea5b29c372662d18e |
|
BLAKE2b-256 | c2e3c3cc85e7a1ddb9f6578c6751d41c29466a93f5567ca58509ca53eb017f20 |
Hashes for stim-1.13.dev1701334149-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed4b09198849bd8ce0c64cf4ed64c46f85c44f73561e450cf35c35f036146f16 |
|
MD5 | a974eb44207dae84068d8b47e7ac14f4 |
|
BLAKE2b-256 | 5b84397bacc6188a619b671e15a815e9502064de613b16868af1810cb6f70748 |
Hashes for stim-1.13.dev1701334149-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f16d0a97a415f315856a3541cf01c9f845956fec8d7f4769a1d9537361b99b89 |
|
MD5 | e0bb372d00971d03690b38bb231ebb83 |
|
BLAKE2b-256 | 617b03ff1963f3ca0d69f624b1e19c5340cc3cd623f6179581dfbdfc268223cc |
Hashes for stim-1.13.dev1701334149-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcc40a9a56d86322fb8d8da187bc1e2561a65a907f95a1fcc8342f24838806c3 |
|
MD5 | 63cd1ed9ae1e0cde91a5b2a3ddbdeda1 |
|
BLAKE2b-256 | 797f6847d99a527713a8629619a22e0e471c8eeb1516bfd89b9e7496698ddcfa |
Hashes for stim-1.13.dev1701334149-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ed2a6af033b6d165ebda43dda3fbf833977ce84ffa6b060248c082aa3e5b30 |
|
MD5 | c10647ba2e96a491dccd50a6630e3929 |
|
BLAKE2b-256 | 1ef6916cd2e5c1d5dd71ed2eff5788058e19a89c7ea4d68ab375fca35b28db0d |
Hashes for stim-1.13.dev1701334149-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0254e3637f6abc7bd32eccb5993e6fb4a55a3828e9bac5aaa5baf2bc28793c30 |
|
MD5 | 335ec403c2168ec305690047b14b3ed2 |
|
BLAKE2b-256 | 518db2fbb1728a25c7cd2ce78128e6b64fd922657065c710d49156956c96961f |
Hashes for stim-1.13.dev1701334149-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 361019e67d056c771130ac46af420fbe92ffbf8de8557c68ef70d18b85a48d6c |
|
MD5 | 52ee5ee14152ff8c795f72c7c79ed440 |
|
BLAKE2b-256 | 98877ae9dd2ec3d32a925c88e1b42b528130cca062e25cf93c059f0650d94370 |
Hashes for stim-1.13.dev1701334149-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b41a2f5aea4a5d7b3cfcd3e87151e78bd93d6e99eefed52e32b63d84bf350a96 |
|
MD5 | ed2a6bc51d7dd2c5a0cc6e54992830e6 |
|
BLAKE2b-256 | 152708d0dc2b4a5d80803d9af89e102f8ab60d806e44883513bafdff8f49e478 |
Hashes for stim-1.13.dev1701334149-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e257d0b3c8fa5696ca628d1abed796d3f52c645e5b8a93513ee694d62e093e |
|
MD5 | 4da23278221a63f4fd0715b592259057 |
|
BLAKE2b-256 | 9fb090f72a4ae9107cc53dd63b6aa265fe213ed3adfac7439439bfc46d9eafb5 |
Hashes for stim-1.13.dev1701334149-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e35d8cceafae0e0bef6955c0555b98258ff335cdf06607d8c8f4f438306d9f1 |
|
MD5 | 4990a6a965a76e12e52538b3b9931c9f |
|
BLAKE2b-256 | c55af263a018a905a32889501fb2a8ad4a7e2a42db01922680e8c9a3f722a191 |
Hashes for stim-1.13.dev1701334149-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e0e8e533e0c65458ea491510d2a7f8d8fe022fca2580c09686e2458e17c932 |
|
MD5 | 86d2cb92ba85dd34ade1c999fd846975 |
|
BLAKE2b-256 | 003cca6b5dd8e50eaa1f5fa21b2876bb7ec3a00c5bf4ea69edb22a3e56c5c857 |
Hashes for stim-1.13.dev1701334149-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac14bc6e11aae43645903f5923412287b353af393b243d493907677183a8c03 |
|
MD5 | c3c8dd9cb2e89e6675275d971ae8b86f |
|
BLAKE2b-256 | c99d8334aada16bc2ebda7a101098b06273bb3277eb13c766b58729a42754115 |
Hashes for stim-1.13.dev1701334149-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 224b41d5274c98c2aae04c1350a2efd61b91a46375737821d7d5281e92bcfc29 |
|
MD5 | 480298ce40733457d248d462de7e3ca2 |
|
BLAKE2b-256 | 50f1d8e399757e2507aaaeb3ae5d698f8cd10114a207f5e6cf3ddab0fb720f1c |
Hashes for stim-1.13.dev1701334149-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb9b836c8ff9dc6eaebb8a57d42c115619a61a7b610acc4ac40c00518ce7e74 |
|
MD5 | 06152739eb81ecf33afaec6646b219ee |
|
BLAKE2b-256 | 25fd945b0e6255734ac48ee45316600e3bf19816062583de950e141b522b8322 |
Hashes for stim-1.13.dev1701334149-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea82037b35210e63ade78545dfd75b9fc586a33ae108063afb52796cbdc68f60 |
|
MD5 | 689ca0ce2869713f8ee658fe1c7a5355 |
|
BLAKE2b-256 | be9ba508d020add38204283d2912c8ef9e8e93fcda5599528eda2e451c5f1791 |