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.dev1712801263-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162fe8343e8b903e5130cb7501e2b20307d4247c1ffde4bc4cef639e84eff807 |
|
MD5 | b638492d31a3883377b538510823e346 |
|
BLAKE2b-256 | 2f33fe1465444a4caa26c60969e3d3b128aa4dd8f06b26ac4e48fd6db8400834 |
Hashes for stim-1.14.dev1712801263-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10ee71a43c549c24cdce991659cc4d94175c4b6b638f00f5bfddfe3f555134f2 |
|
MD5 | 5742648213a399631b8265d788dc93d0 |
|
BLAKE2b-256 | 033305074ed5f3af16e40a512f945b886d5d80e1818677e5bd404915503e68fa |
Hashes for stim-1.14.dev1712801263-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6841201e597ccb4a792ecdfbba7bea8c5bd3d8e2fb7ea7bc8b8b1b05969b906e |
|
MD5 | 93b20f05146522aa304aa7ad5f336c8a |
|
BLAKE2b-256 | 20673c8f46ed1b09a32c83af1a2491ab475b16c9a16ab06d0e876545484b1c46 |
Hashes for stim-1.14.dev1712801263-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56eaba3e2949e30c3a1078421f0c7023aca1c2e280b5c946180bc65477927c67 |
|
MD5 | 80d75fc9889330f1edc53e3f270c9ca8 |
|
BLAKE2b-256 | 07136032513de6a321ef223aaf75cfb207ac6feb5db8e54078b9dc25c33258ed |
Hashes for stim-1.14.dev1712801263-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93a2a1267654a8f43b5ddb42690fd669dd0c3aa54f8ca99b9da5e37ffa565d79 |
|
MD5 | 29a7fb87e09f5bf2b8d7e71021f6d914 |
|
BLAKE2b-256 | eca14908af84bd9ea2d67433eb3d6381b3949acd83cbcc9aaa27d58c812920bb |
Hashes for stim-1.14.dev1712801263-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43a68f99d6f95a6f4a5d412f02771279ce7cb3dff53c4bb6b6d61fa3a27831a5 |
|
MD5 | d0c2225ab19a90a216dceb8971af5710 |
|
BLAKE2b-256 | 8e4904b1c4640bf7d7fb3cf0f26c9f19183a01d3b498b3833b5f04b22b4a9c83 |
Hashes for stim-1.14.dev1712801263-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 874a2c7d53e89659ba30ad4ad6406ecc06fcc9c0214cc7b5f511ebfd529a636d |
|
MD5 | 4a9ecacae7a58142cc6bc27b77c8ccd2 |
|
BLAKE2b-256 | 280fde4b7f0ef8596a7e04a7f4e25af2842d99eac182246fbeab4a450c98bf78 |
Hashes for stim-1.14.dev1712801263-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b84fa018023e41595555ae1c10d1dcec9b15a344535cf659ac455708170da83 |
|
MD5 | 14d9e0643765513995303a7304cb4ecb |
|
BLAKE2b-256 | 589106ea7ff32dc4c3eac1e09c686b83a034386121049daffb33430b16b0a897 |
Hashes for stim-1.14.dev1712801263-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 994a31a7b93c2baeba29bdc8dbdd85a8a2cdf81615418c4879235515227f35c4 |
|
MD5 | 6f213a1ea4a9aaf77c29fdc78910be1e |
|
BLAKE2b-256 | 19aba9304d1537ec2fed776352264fa62081fc1ba150c763fe7c9bc719b08987 |
Hashes for stim-1.14.dev1712801263-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ced109bd064b904007aa087df8f90ce9e4a462a0edf87106b5439976541c343 |
|
MD5 | 3a39d95e97c77a10f63da60090d36bf0 |
|
BLAKE2b-256 | 33523b9f19aa22385d49eca118fc8a50225b9e46f6efb1af6b0e02e9691ecb95 |
Hashes for stim-1.14.dev1712801263-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91f84fbad6f76058687babd8157b8dc11c58181d2cf31708359ea0bcedb8e681 |
|
MD5 | 988d925628b2c4e9ccd31b9994a38dec |
|
BLAKE2b-256 | 0a9b916b2e1803e7fbff15b1a00030f6dc5da5863985e786e30bf296ec6fb718 |
Hashes for stim-1.14.dev1712801263-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e3975d95da581601854f6379213fccec37faa95324d9b552bcc287fdb89723f |
|
MD5 | 21182ec386ab7a83dae712ae65812e94 |
|
BLAKE2b-256 | e9a8537abce1427c188b7365dad5a9fa29fb509fa9db43d563aa6e2cb49dd099 |
Hashes for stim-1.14.dev1712801263-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25ed115fe654785b0ba859bf5a61fa66788c8d22163054c463ac83f246cbbfe8 |
|
MD5 | 2cb83e6830d3b85c40cb423e23ef38b3 |
|
BLAKE2b-256 | 168d09a668fdfbb3e936f7e37859eafbacf65c9f0582da413b870f147f8fc900 |
Hashes for stim-1.14.dev1712801263-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d08359725d1669e4978de8c02b470f7d3fc337254e9d0090e46458de5d8c93ed |
|
MD5 | b9e82b8615ba0d5086f46fd7d67811f4 |
|
BLAKE2b-256 | c336bb62839630e832415b842154b236270bfd6e5b04e5f52f2d55c16d0735a1 |
Hashes for stim-1.14.dev1712801263-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f1d8fb1b6340906f5b7fc17efac76c75148e4aedca9a37e72757f867374acea |
|
MD5 | 8ff8c130e74698587129188d328df1d2 |
|
BLAKE2b-256 | 4dc314aba1ae5e3159e858b231782d721433f79e053221738923637b93108a46 |
Hashes for stim-1.14.dev1712801263-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b33617f01591b03f5101aa303fc49b293187c38b57b872f52613d28fe1c213 |
|
MD5 | 34216c71d23d434030fcc8e0f41f8731 |
|
BLAKE2b-256 | a7eeaede409b36d6a2dbf33e22be85c65f0db1f8bc75fb38dacf79736066426e |
Hashes for stim-1.14.dev1712801263-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26da81a2b007144df95b63f90c57b5c5d732bc1bacdbaf1afeb25a4b29ae8c51 |
|
MD5 | ff5a141547a354e3b3f081ad209ef0de |
|
BLAKE2b-256 | 4e3a4fc4290060c392bd5671428d9dbaa5e078a16e294c37884e25381613901c |
Hashes for stim-1.14.dev1712801263-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b63706409272f9ee5d32f14e5b165686a6d8691d7799f54627e016ed3897721d |
|
MD5 | ca65c8da753012d0681249fcf3a87079 |
|
BLAKE2b-256 | 50714a3dbc8438517ecb8c5bb5276d72cc566711fa01b877adbfb23567593471 |
Hashes for stim-1.14.dev1712801263-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0215fbfa0769f1ae39b1a53c976123f1a83025963a63455f2a9f559a9b6689af |
|
MD5 | 9daf354d173816732b858b032c3119d4 |
|
BLAKE2b-256 | 80e7aff2b152ce5ffd8ea7dde23c0f57e4ee7649c2419176e163bfae96c55862 |
Hashes for stim-1.14.dev1712801263-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 662767b15e7445a6cc5b107eb45919d4703df252ec8aafd7535185a738d31356 |
|
MD5 | c4df7a963ecb8eb7db1cfc227e45b1b7 |
|
BLAKE2b-256 | d92224779c924061c85724b21e8670d15ed5e14d089ad95291eab59edc12fa5c |
Hashes for stim-1.14.dev1712801263-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2cbbb7ce5d43c31005f58bbd9db6f9e764b279bff4ef21ee0c09e69b41165d8 |
|
MD5 | 14dd935023747026fe894b6ef644315c |
|
BLAKE2b-256 | 3cdbf0336c4851101722d69b0aaccb7ee20e8f1afcd6c9e3b27619eeb7f7ed80 |
Hashes for stim-1.14.dev1712801263-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85b1db346e2009f0bd951245b565a3c8614f4672f00e34642f2240c0e4669904 |
|
MD5 | 757a9212bf7c4dd7c68d814786568886 |
|
BLAKE2b-256 | 66305bfce74cd164517d4a82e52f27fffe35b2292dd9e99a4b6837dc6a6d9d33 |
Hashes for stim-1.14.dev1712801263-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff3d41c4fb61fa29ea01a64dd7f707bb1f90c473e6f2a914abd63bdce1d3136a |
|
MD5 | 86d789b6fd2bf18ada428bb5312a2a8c |
|
BLAKE2b-256 | ec92c38c79597cdff649dd56b383cd8ab8926ff5f38444662baa6fc5e3770b7f |
Hashes for stim-1.14.dev1712801263-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75a1875bf600a5a61aebf1d2c5fef66fd7e5419b0398547a6fe23e912a6024c1 |
|
MD5 | 00923c5277967c85cbe73318676445ac |
|
BLAKE2b-256 | 058460c0f724be1fdddc8574c56416cb19cacffd8a2817abd9531bcdc41150bf |
Hashes for stim-1.14.dev1712801263-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8180f0afcfdaa6697d4de1aa7d5d1427669c69bc69622c7faa4e7964d3edfeda |
|
MD5 | 102bdf60cd054341263dddb4b0a51891 |
|
BLAKE2b-256 | bbd35177bc4fe25933b0d0152d383cd4505d957bcab74d361e5c91cfa8129ddc |
Hashes for stim-1.14.dev1712801263-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c0bcf514a9023787908e6b67d9ddbdb0374ea5eb36c40b9c663e52a0a9bffe |
|
MD5 | e4f39121dfb781bd4691f20de9954e22 |
|
BLAKE2b-256 | aa20096f24f2690d8b36787e9bee9667a4abdfac8f40dca9769596dcfc3f3888 |
Hashes for stim-1.14.dev1712801263-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3654936c7d2d8ea699f8a3907534ba063391da0e2dd4ee870066cbe9d56b81a4 |
|
MD5 | 0440b9c756aa15fadd1da9d499dd1781 |
|
BLAKE2b-256 | a4858541033064661b7e90031f38cf98fac97abfcd4f737841bcc7f7910f2e0e |
Hashes for stim-1.14.dev1712801263-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3957db46ac9a6b602686ae5616ce5bedf84d6aca9e15ecafaefe4075ed2ccbc3 |
|
MD5 | 69b8935423550374a3d9f9d6a8047f71 |
|
BLAKE2b-256 | 4f11e69a9866283e73252218d19f29eacf7d37776a0ca7a8576f2f6e8009cee7 |
Hashes for stim-1.14.dev1712801263-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d35609803cb3106b77200ebb1830da30d1bde758c50d40aaa01f3a8ba77b1f |
|
MD5 | d7b329823d876ade5bbbdc1a315163bc |
|
BLAKE2b-256 | 33099d8e9228bbd72aa26536d2454275556b3e0c193e4f2ff4afb53818b444ab |
Hashes for stim-1.14.dev1712801263-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0f2e3e829ad6bc599966d02b87ae2be9db32a6133dedd056ab4a70d3ecaf1ea |
|
MD5 | ca37cd463ea0d4fd6a155a89fc102f63 |
|
BLAKE2b-256 | 33e289a0c36cbfede0389898674c2c519d346f64624049d7f9be95cdc229adcb |