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.10.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93b4a4303a4bbbbd22f6392a1d53689ac1b91847b97a881683746357f265119c |
|
MD5 | e2b95a2d9839c547d0d759976a43055c |
|
BLAKE2b-256 | b9e6557270c8b020540684508b2f81c7591f9bfaf8dd6194b7fbb93ee9957b9d |
Hashes for stim-1.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 784415a54c4fef486b8462b6b02b1d0bc9be735e09b6935f493905dff7cdcdb7 |
|
MD5 | 08ccc213ea65bdd2a4f78569675d57f9 |
|
BLAKE2b-256 | 53f96d10949e86ec3b89a6cada2a182f15783525fb4fd0b8b3b02f8aecc6d22a |
Hashes for stim-1.10.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a01ec9e73334dae1f7723e5a6ba21eb66d5f2a75e9e6a212a5edee9bd440d69 |
|
MD5 | dc0e1fd867ceb751eaf7f0e3640c9931 |
|
BLAKE2b-256 | 45e6bf76e174ab77191b37588da632349c1a817a9974196e54a3176aa4765e00 |
Hashes for stim-1.10.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfece7bd787ec7d09c65e6e5c085833ea9ff4eff03c507d437e5c3e7a8d7af5e |
|
MD5 | a05b5e4fa6a8049c16211830bf548e8a |
|
BLAKE2b-256 | d43dfda50f079d275755c0945b6fa384c38be595f6f413f5ad75b3752798e623 |
Hashes for stim-1.10.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd4ebd38a1f0ae6553a3dce3103fcd4b61d7fb6872d6bb60b19780da9b852d57 |
|
MD5 | c8c00abd2a1eebacdfc9270327dda3d2 |
|
BLAKE2b-256 | 88f13f8ed88d56d1ae257cffd40d2193aff5d51d48fa738888a1b7c5a0f62899 |
Hashes for stim-1.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3681227aebaaadc3b3631320b17197db6b95cfe71c2aed244214c7281456c33 |
|
MD5 | 7f15f381766cc79609d5d855db9b8374 |
|
BLAKE2b-256 | ab86e81b0bfc3f5b199d72e9d42691d12e7a80949328eb82818bd89ad469a59a |
Hashes for stim-1.10.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f4b5913e652e4a420cb4b8f3092fb95df6d608a90559510f7235a49dfccba7 |
|
MD5 | d6186c500b9efa092cd0ebfc07bc659f |
|
BLAKE2b-256 | 72ba5bf61362d988914ede09fa45d2adf06dabe55d39f0938807ab68400f5357 |
Hashes for stim-1.10.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4dfedfbaf3ad85413d17e406dbc604b22af861b73697c0821ccf6a8500c8fec |
|
MD5 | 1df53bc0bd73e7dd93e6c174b6a4b65f |
|
BLAKE2b-256 | e1ddec8e81b4410508fb952904e54f1c4ab46f3470fc69ebf222cfede91856ee |
Hashes for stim-1.10.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c11c41a54fa646dfbe34fe00e413a2e6d292f4b31d59b037bdb0d32f55984ab5 |
|
MD5 | be2084554070f71e25bd02550f6a5a5a |
|
BLAKE2b-256 | 436c395c116d2cf4e31774746c37fafe8171e0352a2a2ce60bf1b442482eb30a |
Hashes for stim-1.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597f4afea9f35e4b9ffa579f9cb81a48529a035d41540e90648271fbc15f4bb2 |
|
MD5 | 66202124f1c59f141d31c3e88c557636 |
|
BLAKE2b-256 | 9ca9063ada9bbbd17e01d73d0a138a08dd5020175e6b82e481730b2775248ec5 |
Hashes for stim-1.10.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f860d6fd883c4aae2c5400b08c076d128495566977c204328785217f177f1481 |
|
MD5 | 6aa861d2ab31074084b40500ef06f191 |
|
BLAKE2b-256 | 97d07c42916a721e19ddf332f0812b29f28c199113a5f7d65df2c3ecf9e8ddb9 |
Hashes for stim-1.10.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd6d023339ae7075ccc9d8a280a37ae657e3e2d7b899faace390727800eb4771 |
|
MD5 | 7240c4cd5ad896e67b9be2638d8e32ff |
|
BLAKE2b-256 | 27818ed9cc874087b32b0389814be5dc92c226cd15512c4657a06d9c714a78e2 |
Hashes for stim-1.10.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2cada958d87f8f8bc51a6296c8e9a6ea559efa7bea9389e24b2074a4d9004fe |
|
MD5 | c9377b5c033d00a5a62f59184a3e9e05 |
|
BLAKE2b-256 | 31b7851400163feb9af485da2a4fd42642a1d43cd2395d628f3907fe986804fd |
Hashes for stim-1.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b9c1efe04f6a736a0d87984ea8961f2d0f6769df60ffa56bc1cc251790cd8de |
|
MD5 | 855199033ef1a6310f80c2a4c79cfdb2 |
|
BLAKE2b-256 | cd1441a088b688428a4bbe74923bbc0bf804b7ff16c0f29e4e806aa05f6d3962 |
Hashes for stim-1.10.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f942b62a0d35a8b55da450e272731b35edd3556314d441365d89573ec0331c4 |
|
MD5 | d6b8fd5473e652b9a0e8d2483f721d82 |
|
BLAKE2b-256 | 1eecc691c716cd8fb164eba7387cbe9de6ddc0d09830652ccfedaac02a7b249c |
Hashes for stim-1.10.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3d9ba3d17545887575c46a8c41038cc5bad242497b7bb2498c7f389af979165 |
|
MD5 | da22ef96998023eca1e9837814825356 |
|
BLAKE2b-256 | 870151049a2757dae53bd8cc0d1abf62d2ab8907c32bd50b2617799c1e4a3db5 |
Hashes for stim-1.10.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27b6004acff82e4a83d98be215ebc6fd533166b4f6d1e8bb80ca9c6f2589f997 |
|
MD5 | 3031013fcb3b03e488e391c62f1e8602 |
|
BLAKE2b-256 | c6897ab77cb0e07c0dce0707c766be57477a19288c564a51f3ca10a43b451354 |
Hashes for stim-1.10.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f55aacd6645d77c42cedc0f1146e8441353d10467035e44b22391d8aac7147 |
|
MD5 | 868a6ac9e196e8ab53d1fe08b1348292 |
|
BLAKE2b-256 | 0e873ab8a2b2fe84ba3d724e6575061a5abc0b72480a2e48843dc347475b8700 |
Hashes for stim-1.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa3272ca6efd77ae1a502a623fc0842d95716ad9792bb37dfa5506e74267d1a7 |
|
MD5 | 3aa983f5611c807450e2029988374b0b |
|
BLAKE2b-256 | aeb60bcd329e0deca4c22229b6f2e418efa432d631aee36dc0a233c3d97be9fc |
Hashes for stim-1.10.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 584483b4f50f1e63599fefb6b23c8e09914c2dee90c6e40f6e677e7d33ab1803 |
|
MD5 | 87ad6bc895011c6ca9bff3d8537e8e15 |
|
BLAKE2b-256 | b5fb0bf11a00a5addb31b921952a2d0e595f47bea538cc856edbf442a0d82c62 |
Hashes for stim-1.10.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29bb0836e47702e02fbf70e5ca401d79f0c8e38b6a22eeeb421ff58942d85327 |
|
MD5 | 952fee411c2018ec5d26d50e21401c05 |
|
BLAKE2b-256 | d1ea04a3acd3d5fb1f56acb2042f776a2832a122be0d1dac07e45cde1080fedc |
Hashes for stim-1.10.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 302f2684749a2772324f4eda9ac1a6c1358a1edeec26abba39db9f515918e726 |
|
MD5 | f96b6d5c0c4c9e82da9b945b55fabe7b |
|
BLAKE2b-256 | 7d5fa585dc0dd341abf6cf4fdeedeb9b26d3990e6b435171f9d12b00b29a4789 |
Hashes for stim-1.10.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f403d598127b527e5f3570f0f1404939a589013e18b66d184f4a8d5e6bd5ef6e |
|
MD5 | 2e31ddb29bcb4563a2401c8c3b45dce1 |
|
BLAKE2b-256 | 4f2e2b1978871b8e159b0f30893b3fbf43c32f0506401f3ff66d4bbe400929de |
Hashes for stim-1.10.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d561179173b3378e7a4a21e0dff4d409e533c80f1e557a5d557d2bdc4ef3cab |
|
MD5 | 81f911ddb66ae42d3a2de22063abb1ad |
|
BLAKE2b-256 | 06c0812f23bb672b4ad4e8b4525a53f109a56953c410188f4f26acf0e207466c |
Hashes for stim-1.10.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c63157aa1ae92e7c03fc0b05c57a3b7c9fe81e2c9e1d174ee09def93ecb98b5 |
|
MD5 | 748fbef60bf78d7780b3a500d20d1f58 |
|
BLAKE2b-256 | cbf7b9c2761f4c52796211bfb2fd60106eac5fec99562fbe04d15a5fa7ebdc41 |
Hashes for stim-1.10.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e54a7c1c8ab9e0df705351f93f42c09959c31b0f89d584bc93fe5d2a6f979f8 |
|
MD5 | ba6098b806073f91b09a39c7ea81c7f6 |
|
BLAKE2b-256 | fda20504fbc4a19551e6d1daf1e5ff5b3dec293e0f58d383053b3e5784c2857d |