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.11.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b10f293ffa6f72c82c07337afbe1734e1bc1d5a50598544075785473d0086101 |
|
MD5 | a4b90e1389bfe93e0c16ec08a041d133 |
|
BLAKE2b-256 | 4094228d0549e403ab889b5ef48527f64b0c92d8686720a87121983786a55758 |
Hashes for stim-1.11.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29d97827fd0d64d7046b94e6ebe2bbf5ea2ac7dd48746574f3c0be79f88dcb7f |
|
MD5 | 5cec5f899d73e6056bea466dff094f7e |
|
BLAKE2b-256 | 158d0973ec8b89ed866c373d5dde40b84916b9a5b01827ec88d6e040e783613f |
Hashes for stim-1.11.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82146c1a46e26e98fec2615ecd9271b5bc5d0fd0aa9f5f310fe56d2073b5603b |
|
MD5 | a8d2ae13736a1015c4279ccf22a197e6 |
|
BLAKE2b-256 | 9885e6009ac55e58a99e362545ade5a869a4cc7516b3edd8bc56b65e86e8eb66 |
Hashes for stim-1.11.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c9738c78395adb27fec541908f903fd62a9b7e3b52fe36d82929f1a5e393ead |
|
MD5 | 332a1cae7620ba0cd98a0afd3fceb3fb |
|
BLAKE2b-256 | 507fa4893db12e252851bb39b15808d8fb42a96cd0bd6da291e66a257c327336 |
Hashes for stim-1.11.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5673e085d7b0c0b1f51e8dc4f93a82756183b638de8afcbbc368c161f23da543 |
|
MD5 | 978ffdcb02f077efd509428aada2489c |
|
BLAKE2b-256 | 6fb11ca1d8a72713721a62ba657b9c292d083d0c0f99fe098dfc74520a2ed3a8 |
Hashes for stim-1.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c01660da8f6538571bb44f084d5f61e764fe4cdd35304c7f16a93626f472a19 |
|
MD5 | c26adc5958869c4857db7263c66e5b42 |
|
BLAKE2b-256 | 2882a430c64fe16027798e4a947fb528ce874dbb0a5874ea41820de0d79bd9dc |
Hashes for stim-1.11.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f83924b558391da2311f54dcd56a7eb73f2afe327c4cd74a44e1351845a7f51c |
|
MD5 | 12fd74f0c4055bdd0aa7682f7101e219 |
|
BLAKE2b-256 | 69266cd649a3af2d2a62bbf988ea07f0acae04b5f2c9b344a53f1b9698c66b47 |
Hashes for stim-1.11.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade69d52685c21b87f74ff22f774e462098a80ab81104a79cc55aa8f08d34b08 |
|
MD5 | 0c1c28ea81c43fbf3a837b8cfe52efd0 |
|
BLAKE2b-256 | 90d939dd3f92268d907ce00ba6b24d21f8466fb55c8b37ed008469c9a2a4d7b8 |
Hashes for stim-1.11.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df64d65f6f347bd5f05593ac05401b568dfdf6f0d72e630488f1a942cc90181 |
|
MD5 | 906d7145e90775e71feab562c9f1990e |
|
BLAKE2b-256 | 1e3a2b5898000243bffe81f6f265109a170ee3922e7c37a51e66f7f30a5dc1a3 |
Hashes for stim-1.11.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f1a57adcd3d1d78075172ea7c3ea4bcf92627e1c16887a2cbdae2301394abbd |
|
MD5 | 91667b866bd6b480f9b0fee59646ff2e |
|
BLAKE2b-256 | 00a738d191800caa413ef00fdb1f17195620ba57f1d9a3751813526f6fcae7ae |
Hashes for stim-1.11.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ae9f835fd9f235b48e3b9e779191801b360ba47d897c60a507347cdecca5e4 |
|
MD5 | 9305a96b281848093895a01f5815176a |
|
BLAKE2b-256 | eb0061ffcc9c4a5b0fda425e330e9b252d79254c66da23b1241d54fce4b84f6c |
Hashes for stim-1.11.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 606c2f06a9b1dc518aac8981f9c6ca2fa33a8ee7f98e3c5bb53697f03048fae4 |
|
MD5 | 239d3fbdadf43b75264b7cf30dfaaf89 |
|
BLAKE2b-256 | 3b8f9c6cd54bcaa5eb18629a076a7fb0d5388aa2e10ba8f68f46efba0b9db78c |
Hashes for stim-1.11.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f4dd80d5f13496188434408d1ed72799eed962aa04fe2c37bb668be7f0c1579 |
|
MD5 | 6b8cdff9fde5ff2d9f2bf096076091e4 |
|
BLAKE2b-256 | aa5016d8e82e26a4ca3997989dfbdc36ed0923f4fab00c496be804aaf57620f4 |
Hashes for stim-1.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83618a8cf40c8aaf04d0695569c02fd012c2d1bc6e80b20cfb07adf0b3b689df |
|
MD5 | 90f0b9a95e05e28b53fc69e2ce7c31d6 |
|
BLAKE2b-256 | d0905072f6f404369bf8dc0e26c90f17b1d0d33c5941d3d6fd0ef522bba549b3 |
Hashes for stim-1.11.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d188ba069cd4b622331df1c3c6dcd783f4901cd45e1baf441be0e139fa845b9 |
|
MD5 | d585f4b294c59633da01a4da1d87d0ae |
|
BLAKE2b-256 | 6ef96b9f326a2e273c91aa60c8b4012a4b56fb047a0556222ea5e698b72af786 |
Hashes for stim-1.11.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3899438ec01c7a324d5383f0a0d9c218faf68afa48cbf327bea4a6022cb9a676 |
|
MD5 | e29af15f28caa216ff90e67ea23d0dc7 |
|
BLAKE2b-256 | 7c09fee55e07b103c7afca60529b813cff8983ed7ba23ca08c20f088ddb6ccd5 |
Hashes for stim-1.11.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed5417ac18ac9f2771978cd83e7f6df7d6630549a1b76ca57bbb8d2b716aaa5 |
|
MD5 | aa37a270d08081ac1be13fc0914b9a13 |
|
BLAKE2b-256 | 3ee73adae4f76644725d66d38a350883f6c6e98526a262af0f1f50e04acb52ce |
Hashes for stim-1.11.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c9ab225fee789b9379b9404246cf0a8bcac899e10f458f736c13f8be6d3a8c2 |
|
MD5 | 0d81af30fdf10e789edac6d55538d6da |
|
BLAKE2b-256 | d01ebb3292ef2320522e978d0e28dc9313b4b3773f01e01fe589cbfafc75e663 |
Hashes for stim-1.11.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e982880b946102198d4b7ddbb95bb29e0c92b23bc10b67ac3230c9080348f1b |
|
MD5 | 016d2790e257aa7a47a9396581b3acd1 |
|
BLAKE2b-256 | 7ad8404252a026ebae8ebdd20704753ae576cc1a72a8f6598b08852d6f474c0a |
Hashes for stim-1.11.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e34f46e164f1e374278a35cdcdb3dadb60f20443e785f099f97f2c4d46e313 |
|
MD5 | b158356d09b2ecad8094515098a8199f |
|
BLAKE2b-256 | 4908544e6f5a43ccc2e32aa5a1a946a0416531124401c7d51a4a26775f5b4176 |
Hashes for stim-1.11.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895997e4c15b0db1aaf85762e5ce49b76cdafc29207640507201d03b8853d1eb |
|
MD5 | 752383519d56dfc2499974e6b8f21937 |
|
BLAKE2b-256 | 3373be072d8c80ec51d7d30b253de8a3296a0f448a5829e6c022c6da363a59ee |
Hashes for stim-1.11.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b40646ebabd16488b9a3ebf7db1b4d218d1c76cbda8201635d2da3f580292b56 |
|
MD5 | 41d4639ca08d207ff8212348c10d4eb0 |
|
BLAKE2b-256 | ef0b142d5851b6a1a7f3bdac16df966cead774676a20f7d07be26787678bf2de |
Hashes for stim-1.11.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d6d317d7ab5c79ee84306a879b8f560452aa23fb9f3aaeb3849f145f65a604 |
|
MD5 | bba82d9284c1737e160334c35599804f |
|
BLAKE2b-256 | 4b4401d36b2dddd392ab8396597573ac719641e42e84cd7483e5e15526e429e3 |
Hashes for stim-1.11.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d093f7183c88dc056ca0d430501498420af0adc3d0a93bc66672becc763feaf |
|
MD5 | 808e9ca91512e87f2d5a6e9038049499 |
|
BLAKE2b-256 | bf3d90ce1a9803b61508a933c7b4c6b6cc5f8b17d15f35230e9635d1515415b9 |
Hashes for stim-1.11.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c661727cf040e7866bf3789b013f9c498db48e2080fd2b83403c25593a87eb41 |
|
MD5 | ef77240e6eefa934e2aa052bb01f28ed |
|
BLAKE2b-256 | faacd034b048e3e214681543e06bfa447bdd76c02da869fdb19c9c902a93e6c5 |
Hashes for stim-1.11.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4609542763be50e1218f80a8963b04fe8c98ac558b10f963adb53bc6ab8af198 |
|
MD5 | f5b06de4727f73bad6b2f9def16291ae |
|
BLAKE2b-256 | 2bd9e22f643bd65e7f375dc4ba256d4566334b8b28f46611c0943bae71e5dc3b |