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.12.dev1692690908-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 390fb6b2e1a7137abf91b5abab6df2284b6a76a1d8f7866242b9d396ea32f466 |
|
MD5 | db128c42d0a5e0d1c75be70375ee256c |
|
BLAKE2b-256 | 641287bb56090388de3b10320694c57d4b628f7949ac0347191dff49cb50b117 |
Hashes for stim-1.12.dev1692690908-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b55355dc5faf1e425fb30548e4be3c78d13d4f6b64ce8a6c569b48366833baa |
|
MD5 | 46b45795a832f099ebdb22dd0eecc9be |
|
BLAKE2b-256 | 7731780f74559982447ad1bc4e5b9d72fc91c586f403513764ba5329d3365c11 |
Hashes for stim-1.12.dev1692690908-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34f3fb60551b866bb2c6d4030d5373fd2e35db427a2c4c4317fd305ce86b5d0 |
|
MD5 | 140f57bb172fb104122501137a375658 |
|
BLAKE2b-256 | af435e3ac6def7f9bdd8b826c8d6d8919f6f861a1870241a94e31be992c2340e |
Hashes for stim-1.12.dev1692690908-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb74a150042a5e017df678e55acb05dba9e405145392aef5f12341cad1c78e09 |
|
MD5 | 5c83403d35a2b5c2b91e8ea2db1d91f0 |
|
BLAKE2b-256 | 300564f2806f806168ddeaf143997be67ddee2ee1d7210fc531603f2c6280d2b |
Hashes for stim-1.12.dev1692690908-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0209f30c304e6934ee7d6ce7b479d5eb68b917fcd3b143755b5a5c38a873cab |
|
MD5 | f768d8a88e83d339d796b3e696beac02 |
|
BLAKE2b-256 | 155dca8a9bf36b596d3a69c19bf5e1229272a630e0529bdab3a3d001fc126023 |
Hashes for stim-1.12.dev1692690908-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7cd88abef165423c6ffdc279abd594d1f3dfbed028dfa242f9831893f933b90 |
|
MD5 | 6a3e33ff32c7d5d4bfa57b340000e62f |
|
BLAKE2b-256 | 3fefb383783e21cb150f4123a753d624e66b466a83b516229567fbadce531027 |
Hashes for stim-1.12.dev1692690908-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e50da4f486477c49a15df22e05bcb4609f301326e432beffa6fd44a205d629 |
|
MD5 | 40a5e7d4cf5eddc7419f804ac877baa7 |
|
BLAKE2b-256 | 7b1bbbf8c0b32f0ac646db9c23edc4af52918c05a4675379734bafc62c87e046 |
Hashes for stim-1.12.dev1692690908-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 414f761340c002aad196c503633e1007747eca10f64f34988a939acd08930836 |
|
MD5 | c1220175ca8c54a22c51aed7d8b87eeb |
|
BLAKE2b-256 | 244810ca394ecc66b69ad5419ea3ad70f09e366828d3a5729f8d80359d4ab3ce |
Hashes for stim-1.12.dev1692690908-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ce96b99fa9db29bd6a1a1942fa8ba33cc988a6770a9e7257f45f0cd5e73c770 |
|
MD5 | e8dbed548569a641c5654470b2de1c6d |
|
BLAKE2b-256 | e09f7e0302af5da93dfa7f5dcf91b96c41bd23eb91217acc3aaf86ece948d36d |
Hashes for stim-1.12.dev1692690908-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1280e48f555930daebc2524a3991b05d8fb1703808c1aeced3f4752faf44a244 |
|
MD5 | 57ed1aba30c366e4abf8272a73f8ee8f |
|
BLAKE2b-256 | 16c18fe71e553ec6bc5bbac9cf64ea961760207a38d16421cca1d3a1108618a7 |
Hashes for stim-1.12.dev1692690908-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61760212d7730996809ca1bed091a63317e288b745965b0c142347b6712a1cd0 |
|
MD5 | 3c23b3740ffede9055240089348fd47f |
|
BLAKE2b-256 | a300db5b2ae32e56ef731c6eeddffa2daa456f8db86299201426011f15301f6a |
Hashes for stim-1.12.dev1692690908-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9a0fbcfe513f168992498a024a8ddc0a9b2963fa4864108c05c73820ba45b86 |
|
MD5 | 9a9c3d54c415f956ba237883149e7098 |
|
BLAKE2b-256 | 0be55e0cc1874686d1bc9a0890e9ebeae378287d51452dee8722c100368b291e |
Hashes for stim-1.12.dev1692690908-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685cfc1fa02206e9a7f26e66fbba00c9446c7b7e133b0a25b7e77977415ae2f7 |
|
MD5 | fe00c8590781cbc4298cbc538da4bcf5 |
|
BLAKE2b-256 | 216c5d809a40e8da6d80610f085688cf05c564613665f321a3cf1482a9aa1db4 |
Hashes for stim-1.12.dev1692690908-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b95e953f6f7006f38dcff971ef365726e008bc716521c952389c246dbecbe7 |
|
MD5 | 96a524acf869b704fe8657597b973015 |
|
BLAKE2b-256 | 679f3e5b1101e9e14bc2b6b821bf299560c10a33568cc6bc2831e1c04d47bbbf |
Hashes for stim-1.12.dev1692690908-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1193f5fc149ec26102de8417beed20790fbbbf1ecbe97f87b6cb3bb9525fad87 |
|
MD5 | 7431376492d4c2bcd6c120a8361d347a |
|
BLAKE2b-256 | 3786e79026f9d71aaede6a53744e00b30338edb9f846840ff874f306e1d3df65 |
Hashes for stim-1.12.dev1692690908-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68dd54dd2eef18d2f58e2dd4701fdc330c416a20e3ca14ca0468ee1ae348af2 |
|
MD5 | aac48d2a3e1cb945d73d3c584f55def0 |
|
BLAKE2b-256 | f4aa87c94abb09c7f6229c9a4bc709906f72d103762581ca41c96a01ee2125aa |
Hashes for stim-1.12.dev1692690908-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1740cea55f672b859627d36c95bd7313ef59e0b90d270bb4eb60be6ca486511a |
|
MD5 | 70f8106e3eefa9820a9143cacab24dc1 |
|
BLAKE2b-256 | fedf7095895960ba683f0fa9b15cb467f6a6a42ffe863a4b382862a9e0f2eab9 |
Hashes for stim-1.12.dev1692690908-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce666dee7ec544c3ff0c31dd8275f08e772d3485a86bb7fbc02d9005716a82f4 |
|
MD5 | b07c909a24c838ae2b45371d0d60d604 |
|
BLAKE2b-256 | 00b951104bddd0399b807ac569e048214eba275ce3dae0a568c78937c4a23450 |
Hashes for stim-1.12.dev1692690908-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56aebd8109c8a7e950f5470d58800620789a05ead237d3e68836919c457e6430 |
|
MD5 | 3e1389514b6c9922b92369bb805bd4d5 |
|
BLAKE2b-256 | b5e21a224c7c976e4d9edc3ef120149c53f8fe908c7ba5abbc8fe4603f192d30 |
Hashes for stim-1.12.dev1692690908-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acd3ae3356754cd02158ef64de39e2ec24712052b42816cbc5bd9dfbddb002bc |
|
MD5 | 11f11cb7b922147ae9a96b5a661d3bcf |
|
BLAKE2b-256 | 56d7ecc2d632039c04d90419cdcc9f7247dacb2202343230a0e4cec19a2416da |
Hashes for stim-1.12.dev1692690908-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a26b7a7e418f717a20a4d4c3d57739a18bb89f11c932df0f5e54b38b81c741e1 |
|
MD5 | a86121f56ec80e0765a1252639f4e8fd |
|
BLAKE2b-256 | 2d7872f7bf4501ee125608029223b78e69efbcaab96505f5c4acd8374fc744d6 |
Hashes for stim-1.12.dev1692690908-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62d836521ba1b8c373a4904be039110d90ec654739cd6ada80ce65343387efe6 |
|
MD5 | 19a8ec29b4b404618ff2cdca0f6d512b |
|
BLAKE2b-256 | c5f4a175e3233561d8d3a75ed3b30e0059423189dc33c96e5fe369ac985273a2 |
Hashes for stim-1.12.dev1692690908-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ee269a8941f90e76017049c78ab430bf1f498841b9a1c1a906896a2691da66 |
|
MD5 | 1b699b3e3e70fd017f586c1ca77ebdb8 |
|
BLAKE2b-256 | 1b1ec64b06a11e388e2c28021fc7dfbc13e1df5910655fbb9d7c16e401e2d634 |
Hashes for stim-1.12.dev1692690908-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1183ab5f345f32b09775e75dd866390730c0933406cc6ee7b143fe48a7cc00f5 |
|
MD5 | 876f33694b1e8d3c1306b7eaa66fdd79 |
|
BLAKE2b-256 | 285653cc2924664364ab68557d884356c0dbf14c0520928bbe254a57a892e5f3 |
Hashes for stim-1.12.dev1692690908-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fdcaf64c43b0e40468dba43ed3aaf6e4db25ca614cf22aa647cbdca96e7776f |
|
MD5 | 829baf02422915884fc39af43b7f3420 |
|
BLAKE2b-256 | 54876b0d93307f9e578444dfc50ea8e5fbef6880144090fc13fc203e3f1ea3b0 |
Hashes for stim-1.12.dev1692690908-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef010ebc5c71cafa9cb8ebe8cdef697d58750d3d7797270a50750a1a46393be1 |
|
MD5 | 4032ab784b2f7b08fa1e43e4a0ac1a39 |
|
BLAKE2b-256 | 7a5a532deb96e7aa1ff9c458fd7025746c63c86d9c7da1c541a72820d2a449ab |