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.dev1711670133-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15c87e06449d86261a50af10bf0a741118af94049837bf6f8863e566c3ed63a2 |
|
MD5 | 2e0c033a6ced99ba7fce114a3e4f2be7 |
|
BLAKE2b-256 | 7ccf519c4bd4d14500a669b25beebeb1ea5cc924daf992bcedfe10982b91276c |
Hashes for stim-1.14.dev1711670133-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131aa9f536648ad04ef4d12df8fc192ffe113666f9535e3273b296d1c04cfdd0 |
|
MD5 | e1a10679c8a1d5a596ddb81a97e7e292 |
|
BLAKE2b-256 | 5c13da22717bb60cf23dac4b24fea05a75be59d527089acc87a353897aa96256 |
Hashes for stim-1.14.dev1711670133-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50736298c62c4eedf83d00edc35f7e60462c89862dc5326c83f03ad9b1e5719 |
|
MD5 | 480607fa10eed19fd15d699fda2066da |
|
BLAKE2b-256 | 74f17f5a294de5fd9f40e937af5dcb622e9d26f1a93948850b9e48a7e3d0c2ed |
Hashes for stim-1.14.dev1711670133-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae529a47df4f6ba0413e333ac0201c3bdd54116fad280690a59dc2b88994a3b3 |
|
MD5 | b3e0180b244391c1938f2c9e1e1c35ae |
|
BLAKE2b-256 | 683211c21bd7d3b06d13fd5cb3cbf59286b594718d88d62a7d9e27d87d4c4242 |
Hashes for stim-1.14.dev1711670133-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2921e44f7b602284b01f098932f07a1c9fa303ea2edbc6dc3389c894a311ec01 |
|
MD5 | de9fa2dbe9d522df9a03a7582506559e |
|
BLAKE2b-256 | 6b558d08baf2c7352c870c445c4b1a93f9e501ac710e4f5b1b48935051139d88 |
Hashes for stim-1.14.dev1711670133-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11aa3b657a24291b61677efd17c14d9d1526488f23e38af04fd593f0d02e5f20 |
|
MD5 | f337a944743962766553459a047acc7c |
|
BLAKE2b-256 | c90f611b4f17c62f16b9422d848f1360f3a6657b70ed68ba9849fe36006c39c7 |
Hashes for stim-1.14.dev1711670133-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33a642049e58563d58aba3e3cfa8585bed522e1c381a5d9c49a2ce8a2efcf779 |
|
MD5 | ee5aff1f82b2fa6160a9f7331571a38d |
|
BLAKE2b-256 | 1213ce9ce80d7799d92ac6e0f8a6ea53f978cd154d9a71d9fc9597f280a62fd7 |
Hashes for stim-1.14.dev1711670133-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f8c7965597f71fb6cec829cea9c7a0c382cc3390ec6c8adc5931f95ec77bc07 |
|
MD5 | 9cf9ddd5b0704ad8defd1908ba83914b |
|
BLAKE2b-256 | c0a3107cc6bce6687a3e31cc05a493392b0bbaee413bfbb53c45cc5f32751b99 |
Hashes for stim-1.14.dev1711670133-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b254340c3d4c3f93b6c66bb7cf43d8bbd2e30ee279e4c98ba13e41bd35f4fa |
|
MD5 | c3544e8b87437ad096e651198c3c9f18 |
|
BLAKE2b-256 | ddf8775776d2cf72bed770d07f433faea053e9d2471470c9eb904b5104d773db |
Hashes for stim-1.14.dev1711670133-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e596448ee8e0a92b9977b6ede150bd7bf57f86fecaee192720c9e726b4d9514 |
|
MD5 | 4d83e7a764ed6f5268a8a9eecbb5ce49 |
|
BLAKE2b-256 | 8d69203f231583b74483079b81cf61d36a371abbf25e5578ba23394892fcc742 |
Hashes for stim-1.14.dev1711670133-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e46051cc74f17684cadd2018737852af88e26a371be5752e70ff6ec885db122 |
|
MD5 | 4f7674fcbad1d24b933842c481701add |
|
BLAKE2b-256 | 5f14a140d2e1a10ca72ab01c2e4fff686ffec7a7c18164af13720a10a99656b7 |
Hashes for stim-1.14.dev1711670133-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6caeb15bc9829a1d2e798f2f920edfc3c325e68e2733f9bb8507bc14a244be8 |
|
MD5 | b6dab41286e3a21bc854b369aedaa1b8 |
|
BLAKE2b-256 | 0ec98afe6ff145a8ca011fe393509479c6c5b7b9070e2c899b34e2cc1bac5a0e |
Hashes for stim-1.14.dev1711670133-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c322b5f85e9785e35f356d2190c0b115e205c7684d44d22106c3a087701afbc |
|
MD5 | 2c861d0cf17187c0a0fb9d68a88462e1 |
|
BLAKE2b-256 | 8b10259bfb7623525fa98149c8245739f86343c4839c4c1e14ddcc7916785c30 |
Hashes for stim-1.14.dev1711670133-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cba427179ff507aefc11b85c45a282418458214aee5e7cbe375ac5db41d4c14 |
|
MD5 | fb4801bb4812a4a7951bfd252c158826 |
|
BLAKE2b-256 | 9f50a4428b905dc987e6c0947b221724d5972cb3d09eaf64894e9c151a842f37 |
Hashes for stim-1.14.dev1711670133-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5a5c5474d62d49fff88ddbaa02649004813c4326c146456e3be1dcf2f53ea5a |
|
MD5 | 8b01665fcf1b4bfe434f7bcaf7c7e1d6 |
|
BLAKE2b-256 | 1bc811a08e0eebbb325ee7d4ff11f1af02561e611d5053c1a89dfc340aaa1dfc |
Hashes for stim-1.14.dev1711670133-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e4b55143b71f6a99eabfbb74e375794312077596e0ca80714a0a0333a24c6c1 |
|
MD5 | abcb09cdac7bd526d9ffcdf1c5150bbe |
|
BLAKE2b-256 | 9bb9b18dc3b69a044db63338bb4566f357a58416c81e7d21b15d429977582597 |
Hashes for stim-1.14.dev1711670133-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c09e18a828ff69d645644a58e949ff2979eed86e656b12b6b893bac6b9fabfb5 |
|
MD5 | 9ba40f4e6541cbeb43e322d731871289 |
|
BLAKE2b-256 | 36a6a56d9ced9ece26bc78452ab6592edf6339f3412f60e4c4629dc9617d0f62 |
Hashes for stim-1.14.dev1711670133-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad059964f5b0ce91b3471ee79b1b6ef6d569ef870731c5371f55831b53f77404 |
|
MD5 | 30c23bb898f982e7282ffb58b31c17e6 |
|
BLAKE2b-256 | f370cae21e21b495a8288d80803711219e8531fc432ec708272d00557804cf77 |
Hashes for stim-1.14.dev1711670133-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2941ebfc3d62e31b119dc8e7a56a5cbd6d3cd01e5c3021e0218016af54258456 |
|
MD5 | aaab834c93f84d775966c746b0b33e64 |
|
BLAKE2b-256 | 71e20cb38d11b810966e4269971615ba70337f9484a00f55a95131e9857a89db |
Hashes for stim-1.14.dev1711670133-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3acf059dd7f0b33978cbfb664126a87d457cb8a162c8f8c774bdf2065c3ab48 |
|
MD5 | a6882e8ef7a8ab3e9d2a71948a66acd4 |
|
BLAKE2b-256 | 7ef146f0b84e1e313c2e6e86e5b87271844d2e57e9b20245cee9e10353ae4ece |
Hashes for stim-1.14.dev1711670133-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b9409ac96568b5a979dd85ebe067ca597a66ca2eb71c91cf1ae81eceae85659 |
|
MD5 | 3df4d171fcd893b87af9a2ed1389bf8f |
|
BLAKE2b-256 | 5c61dabb66a2884b270fa76d3dc7435f66c8b77643a5c5f4902ea5b7c8a183d5 |
Hashes for stim-1.14.dev1711670133-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2832d9ec42f205fb9cce8b4296e75c1fd74589ef90676ff589d712a052ac59b7 |
|
MD5 | c0e79360cd07f6892170092007d5f593 |
|
BLAKE2b-256 | 41d6b97f8f1c0d41366c8f26ab07c201e3450dc3f6b8122c7091dd537bf73a34 |
Hashes for stim-1.14.dev1711670133-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89854166e52b45fbbee4d8fa7893efd1a5470ab4d03ae3f46b983289aa5c4d1 |
|
MD5 | 89b0dcb732ad29f06e812d503db613b9 |
|
BLAKE2b-256 | 9dbe84c44b9c37f9951720cd409e35d29b0a501bf26ffae33e72fcb5a18a640f |
Hashes for stim-1.14.dev1711670133-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9009fcfd8bbc7d52bb65e0731a80f2aab59027a99b2165c305a935ad9e22b2f2 |
|
MD5 | f437043badc1c3a37175fd29e07c517f |
|
BLAKE2b-256 | 1eb32b95f129c3d61d8cd0cad75f5d2174763cf3873c13dfa862610d69ab687c |
Hashes for stim-1.14.dev1711670133-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d4d0d6751e11355a2bbeb37eb4a2087a40b0fab4921817a5ef065a324cf6782 |
|
MD5 | 9cb68b7ab380c05c2785a9e48d089503 |
|
BLAKE2b-256 | 97a033ee8549ad6a2452428e96584069a390849e69b7640745bc2f73d2940619 |
Hashes for stim-1.14.dev1711670133-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 233f7cef094c7b26bfd47d647c81f40b05756b41800c4c8f950abc38d4981d09 |
|
MD5 | 618c52b062e2ca578ff9494ecf1eda69 |
|
BLAKE2b-256 | 5993b29040359b994eb1e3474572061e63250fae7cf78e699f32d6735fdcd644 |
Hashes for stim-1.14.dev1711670133-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9492bc4168c10d4cf50cbbe5ca15e0496eeb8e067da78b4e4ae7e9c27bdfc48 |
|
MD5 | 1709d0ae22a7f98a25c4938ae3f5022a |
|
BLAKE2b-256 | ddd33daa9e862e4329a7a739fb7caf2bafe239748865c0b8816ee32503d8b1f5 |
Hashes for stim-1.14.dev1711670133-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6f84fb7475361be1e2430b070c991aa78bcfdfda73fab5aed33ef3cf348378f |
|
MD5 | 8b68fe9c1e0b4e44873d4c2448bb3904 |
|
BLAKE2b-256 | f97e19587aec3526412ab6ad1abc61d0c15f4ce6480685e62dca11666dd46843 |
Hashes for stim-1.14.dev1711670133-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f3d79cae67613892363d4a3f5b0546320c10ae44ab7e64e5aae277a147b2d69 |
|
MD5 | 96a4ac4f897deca7d6e8e0dac46beda7 |
|
BLAKE2b-256 | d703dc2604b46d0f0fecd98cd69c62464372e363ba5a23b664938c0522b00ae1 |
Hashes for stim-1.14.dev1711670133-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1d496d73ed33e6427664bdd97cd417de233b42247ef0379d9c872c721b86a76 |
|
MD5 | 523678e21409dc81735f63dc98138512 |
|
BLAKE2b-256 | 69cbcf0f770564549197d584b8a2347807ae49e509d6e0d8ec068e5c0da2cd87 |