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.dev1722293989-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb1092f3d880d7d17e9666548b94ee782e84189ee19d3e69f0334fc6f75ecf95 |
|
MD5 | 547d39d31589611de396dc5f0a293312 |
|
BLAKE2b-256 | 94dd72e2fe87b993c2cabc5308b8b7f5d73392c9eb1091d7f77db6c9471c422a |
Hashes for stim-1.14.dev1722293989-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a907cf3cea7e823fd5d58a48160580ea38c750ac85ebd82ed04eb3ed2d0257d6 |
|
MD5 | 6b5927e2792a5627fd6f4d56c02c7bf0 |
|
BLAKE2b-256 | 8e7067f7e7bdee073dcd301846bea53d8775b52ce5f5be1f2ac6a719d9949b0b |
Hashes for stim-1.14.dev1722293989-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9931dcf05e99cc78a8c264f3fff6f38b027aab2ab2c62f7d1b9d7b56021e1d0e |
|
MD5 | ffd3cf1a4ad156e3a6280662adca531a |
|
BLAKE2b-256 | 7568b79fe6f1fc817972ebc2319e3592224147fb4c9131cba96de9172f6611da |
Hashes for stim-1.14.dev1722293989-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6fcdf006920029e920bd87cc5511862331ee0587cf93cddc170f1527c6849b9 |
|
MD5 | 64bb287f5d21bf5a0d37d745a0f6c074 |
|
BLAKE2b-256 | 3d93b128a50a6d6c888233c56715da48a9fe3912d3197d873381ccb388f03445 |
Hashes for stim-1.14.dev1722293989-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffbff8501629ee1286ff7c86b608e45c41100687ea776644ad30f16d711c57b3 |
|
MD5 | 7d748f7676f9b763a1156e04d68e548e |
|
BLAKE2b-256 | 03b91ed37a205163c71d76633312804f0fa410a04269015579a812409abec9d2 |
Hashes for stim-1.14.dev1722293989-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 528bbc069954e1b8fd69a18a9a80d40e7db9d1ceaa8bbc9c21a0a7b1cd3f277f |
|
MD5 | bf15a983944b440d688c441875028ccf |
|
BLAKE2b-256 | 6d4a56363ab9593b2cdc3a144f63519b07dbe1d1887771a0cb0235fa4c10b56a |
Hashes for stim-1.14.dev1722293989-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 911838c316a9fc2f3a1c90d6ffc4c832117a9344f65a6873a1dc1b7e88a2aefd |
|
MD5 | f4a0a6ebd0735ff148b8e62f8d71ca58 |
|
BLAKE2b-256 | 9b2ee250421ace9e9e9ff0193a04ecdfd1d4b39a34f6eecec9806a93092e0862 |
Hashes for stim-1.14.dev1722293989-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b39cd5899d6be66988659b9c2c338ad4868d1bce9ef7f392b03578ced6b3998 |
|
MD5 | 2b44c413df6c057074f1b44a92024ba9 |
|
BLAKE2b-256 | c649c2542209c0db1c9484522be244b1445b13dceda2675bab2467e6a2a877c6 |
Hashes for stim-1.14.dev1722293989-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28490e5309825e4411325fda7900a1d762818c0ed089c01684f89f944af81126 |
|
MD5 | a0bdaf130be96713277ba912af9c354c |
|
BLAKE2b-256 | 04d9a1b7fbba1ba6222864d37d787b099662dbc2f06d66afa68b83427c34238c |
Hashes for stim-1.14.dev1722293989-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b4695067b0fda7f8692154c314ef03c18fc9acfdecf21a0a860fda56b360c68 |
|
MD5 | cf7d01d7c02354e2af7012f196337043 |
|
BLAKE2b-256 | 5e2762582d9a795af9bbd62f8819716bdd3296eafe78155ea563cbf774e6f7d1 |
Hashes for stim-1.14.dev1722293989-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e2fd8e23cabcd47a581ef14cfc16ee8f04c0635a82e005ec857731a5c61a9a1 |
|
MD5 | 65910e082b28cbfb3f6b86728f627944 |
|
BLAKE2b-256 | 38fb2161469cd642d38b928240ec9e8fd209037a523256ad47e7eea59db65f5b |
Hashes for stim-1.14.dev1722293989-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae1494a08e8fe6f5fbffe456e92b84b32710b2203c579027c587feb1b529788 |
|
MD5 | d189bc40da035a383efe47a219dacf88 |
|
BLAKE2b-256 | 6bde0e9cc2fa7977af1e9450c3bd3d3ef6fe4802deaf420441d7444a71df8f44 |
Hashes for stim-1.14.dev1722293989-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ddaf9ec846b94185cbf7621ad3ea118d8d4cbaa6df9dd1adda976c2b5c2c21d |
|
MD5 | 81f0f182ff0b33845496433cb6bf256d |
|
BLAKE2b-256 | 9f1dedd8bd1b9687e36720fa28b3b26efbca1acbce5c3608845aa99002ecf6f1 |
Hashes for stim-1.14.dev1722293989-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ef3ffcec4b92790c164adca52cc0d09ddb23da417f15385cf6e2cd8fe746489 |
|
MD5 | 1d8946749bf579ef858ad1c98bd95c00 |
|
BLAKE2b-256 | 54982aca6b36886677ab0dbb239774a1333154cf23ce1b2f58a870738ca6bfe4 |
Hashes for stim-1.14.dev1722293989-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e36ce4f2fca6583ff6ce3de930cbddb3e7a1c5dfbb3fa986ed30bdb3bfef303e |
|
MD5 | fa380d1fdc43d93d8bbbb4a0d1b9f515 |
|
BLAKE2b-256 | 2896419e098b20e7de8d2f18c74a2cd9b4127b36ae34ffab15928b1b7139dccf |
Hashes for stim-1.14.dev1722293989-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d514d20faa7ada39cea8e8f5a0ea300f37d1288c2d8f420c869b772b9e80cb0b |
|
MD5 | 3cf35814c6fe584775efbc313b3a23c3 |
|
BLAKE2b-256 | e38dd608d62e6cf247e6b3367d8e1039fdd08aa7c85058fcbc434f3c02edd9ad |
Hashes for stim-1.14.dev1722293989-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55d0f29ed2e2768bc8424008328be8a96fb385ab228665264158f3a0fc8090cd |
|
MD5 | 4d2dbf3d743e1d4ccc9200ebd78cc9d4 |
|
BLAKE2b-256 | 9ab6d9e2efb1f0e0527c96ebf79d21282126236adb31a616dea542323d0dbbaf |
Hashes for stim-1.14.dev1722293989-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6548f2c4cabfdad4ea9c87ceb1dbcf82980092859a8db62635d6d5cc34d19d3e |
|
MD5 | aecc68297fc7b17ada74db58d799b10b |
|
BLAKE2b-256 | 5e145a787f3171c2741a8047f87bae27fa1610dd93ad615a023978aebfb60238 |
Hashes for stim-1.14.dev1722293989-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e41ee396c5e43c6a1ce6d7a0e3d8270846f618e6c56687f3c43ac9ba6715efee |
|
MD5 | 05cf952f3a3790bad3d118623b390ec4 |
|
BLAKE2b-256 | a8c02e21cdc65ba0cc00297e1660bea8c6ff5b2be2fb6b0a003bb6e135d2b661 |
Hashes for stim-1.14.dev1722293989-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac8fadc653b1cae42c2b28908b716db468de22cf3d5e1f8bbceab22d329594db |
|
MD5 | b2b8223d26588ee02661652a003cddb7 |
|
BLAKE2b-256 | 0aea08372d792e7a5596a8777dc9efef742960cbb9178febb5053654d8631d4d |
Hashes for stim-1.14.dev1722293989-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1deccf5a1e12fc54f66c60a036f709a8974ab686c1a42437e62ceabcd9c3e8a |
|
MD5 | d7a6d0b918630e37ec98339fd87860a3 |
|
BLAKE2b-256 | b5981888e2a82fba9016ff505f8ae8a2c9f255f45ed386aa76529fabe9750ef1 |
Hashes for stim-1.14.dev1722293989-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36d3884c127acac2b51c63902d50c9c1d3b6e038c354c3a5d2a7ee3d798b56e7 |
|
MD5 | a5bf3e7d8fde2e94b9ec1bb6de09bd50 |
|
BLAKE2b-256 | 8f9fd491a8d3468d97e7b3792cc4225a459727ed19763da58779d2696bd0dcb3 |
Hashes for stim-1.14.dev1722293989-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a96c5902eba9e1204642fe737e2e92a6aa195231ab564950365468ba38eedb52 |
|
MD5 | 58698c3f1ec897d469a4c7c00ef549e1 |
|
BLAKE2b-256 | 5dbbd88faef37891fe947644a5bf43751c9eabbf0bfc4338905897e267746919 |
Hashes for stim-1.14.dev1722293989-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f21db15639d1a9be88c7bb4613504399f015a581ddcdae79becc6a3fc7c57ca |
|
MD5 | 7ad2862b4bdd0536ed984009779a3aa3 |
|
BLAKE2b-256 | 4dbb821493d13385ee3623b0aca2512cc41f7007e84ab4810f81ce42428ae2e1 |
Hashes for stim-1.14.dev1722293989-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef47b329ea1e96d912bac49db8d77559fd23b022b573e5cdba14f68c20281b2 |
|
MD5 | dcfdabf57b10128b115df50695e34d7a |
|
BLAKE2b-256 | e43ce4becd5b15cef1ea3a51fceb4aa4e192d4b383acd65bbce93d4b9571e1c6 |
Hashes for stim-1.14.dev1722293989-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0c96132913a78509a7045e0cde6666e3dd122e861b72479ce00b5d8f24980d1 |
|
MD5 | e1eec7acc7f7b32e22f4c6dddf7617ca |
|
BLAKE2b-256 | 88a5d636d4d4bcfac8fda570fcae9592af19c58d80175eb5ab2619ebb78fd094 |
Hashes for stim-1.14.dev1722293989-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 235489f59c07a01edd46477bcfa2641ca9c376aed1aee0dc27afbb0c0acb8002 |
|
MD5 | 247df56bf53b2024a97613e843fca602 |
|
BLAKE2b-256 | 16758937f798d16f03b5316c2fd03006051a86d7c8b8feaba68e3e76046f78e3 |
Hashes for stim-1.14.dev1722293989-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d25648687cf5711e00f1ca9c5fe2f841bc62595650bf97f167f057bb5e25a3 |
|
MD5 | 376ffe57fb3fb75fbca978832ac34fab |
|
BLAKE2b-256 | f8d368f8ea6dc6c7a535b3742d2b92e61683e77920fb63f6498587dda4755150 |
Hashes for stim-1.14.dev1722293989-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db047f1387c347b2a685859c44e122a3f283cfd4a08ba0c536875058bddcf63 |
|
MD5 | 33fb9a453823abb53d85580a71451fc1 |
|
BLAKE2b-256 | 262cb9216d96e9477a88f4c67b7092c40fecc4c6b38130336da79757827d65c3 |
Hashes for stim-1.14.dev1722293989-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 457f76dff8255948016414d32daf853ed7dc70dbc71e374acdec0cf7ffa428d8 |
|
MD5 | 146f8ce2dbad75ab6d01bb33ba17bdc9 |
|
BLAKE2b-256 | a1b7df9e8be605cc0fbf7383703df5d8f114f089012ba46280f7cf4bfdf685d4 |