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.dev1684788861-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7c3e8dcdaffc0b3be5584fedd893b98c1111906bb0b08f218aa2c77fbb2a4b |
|
MD5 | 2e7c60eebefc9ed9b7334304d22ef758 |
|
BLAKE2b-256 | bc4810b95dc664e00a720a0576851653d0144ab04c4eef513f7bbbc939d01d52 |
Hashes for stim-1.12.dev1684788861-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a5c815cf7d40d1056aa2d7b401f6157e5611c8dfbc4a757cffeee3644a6b831 |
|
MD5 | 9bc55994b3d470529c87a48dde52e82a |
|
BLAKE2b-256 | bafe56e6352334aced835f6eb8383a1d2ed6c37ec96cda9c166d917350fb1728 |
Hashes for stim-1.12.dev1684788861-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 973d48a9c9f0539c2dd277ebdaa68743249f10e74a77973fdc7e712e78c80d97 |
|
MD5 | 08e9cf81a2fc19fdc2fdd22a10ff15ae |
|
BLAKE2b-256 | 0548c5229d6cc71ccbd44da3738020c221473568d0d00fb68e509c9fdfb201e1 |
Hashes for stim-1.12.dev1684788861-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9251bf443ce3ff19f9f89d6fd5147acd5eb564024f7ae5ce108b5d877bb569e |
|
MD5 | dbdc4ecee9220acaab98ae7f57370e87 |
|
BLAKE2b-256 | 9cae82320ccb0af532c02728c7cc1ed5ecb0dd30046c7e07b29cbcd5832ed5ab |
Hashes for stim-1.12.dev1684788861-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bf114dc9767b0baa04c4020273cac14495e1c9a17f5f41adf46d1c85f682ef8 |
|
MD5 | 08a635385c98ff757d575dada2e8b30a |
|
BLAKE2b-256 | 2c8abf70b0d3242fb053ae8c50656aa91dd09a596e7d956b054339579210f6b9 |
Hashes for stim-1.12.dev1684788861-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 631fed5ed66d8c5de7e30f532b81409956a5f2c465bf9e206ee4e116543d7627 |
|
MD5 | 743ca5dab2d72a32cf86af925e85a306 |
|
BLAKE2b-256 | 7aadd48bbcba080d886caa57a2cd18b646929b15faa0825928bef0f1b1291968 |
Hashes for stim-1.12.dev1684788861-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed7eb7f6e6d0a6ce5755de9a43bddecd0717f9108a929fdd98d94f73acee1269 |
|
MD5 | 536d2b90c372f862e80d522fa773ddc6 |
|
BLAKE2b-256 | 8e67f8e9d36ad45010dfffda8e93d81b8b8350e59d1408de583a2e37580e646e |
Hashes for stim-1.12.dev1684788861-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59aab042c120480869221751390c57b830a2b0d497dc4f20094206a92c123c4e |
|
MD5 | 839bb454cfa1143cbe2b035a7d823fd7 |
|
BLAKE2b-256 | c6fea48878c2b045381be0cec710b9cac99f5a3a597833f3443508f0b5d325f3 |
Hashes for stim-1.12.dev1684788861-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 065741e9752f8d4849098509e6cc7238fcc83d77f6c2b5f4cbf7f714aee66ddc |
|
MD5 | cd775e6f13da0fc9bb578c432084fc58 |
|
BLAKE2b-256 | 64a45bd29c5bc8c23fd7cc2e3007b8fbc9096b06dce0b1592b4362761a0f8e2a |
Hashes for stim-1.12.dev1684788861-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f297683ea69955a2cd941462e782ebe8b965b061df053863e23a6d3033dd060d |
|
MD5 | 19ed09ead8b0a7ce27aae08e30df92a5 |
|
BLAKE2b-256 | 702ad34b43e987685264d8d6409725755bb29733c0de4ebe0cb89266410c0231 |
Hashes for stim-1.12.dev1684788861-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c8deb1bb376091330919f4abf45ec4080d353dc02c7789198c327ed856cc01b |
|
MD5 | 9c1cdc8cb5bd8b09d6232d841e2562a6 |
|
BLAKE2b-256 | 6a05a24c198908034e134d670c2c3e953fe53ed1d89c9a0dca7c80685d0668e0 |
Hashes for stim-1.12.dev1684788861-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6569fed7318e09492d6f650b3c9d52340c630c3f8e1af25a1d101a89a50fbac3 |
|
MD5 | 94d73abd4df7084f31aff4197badaa52 |
|
BLAKE2b-256 | 40660e4f1c96af9ecdebb2fabb855dabf1769e9073456c44d6117856e9c366b9 |
Hashes for stim-1.12.dev1684788861-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d400acc7369507b9472f08f9ac4ab59bf6344a60fbc92eba354b2d8ff29e84ca |
|
MD5 | c146ab09eaf353916e73834cc65f3990 |
|
BLAKE2b-256 | be936f93875ae2a2b5f40b29c0800335b3f4c7b5f982a09130b1c58cbdf6f40b |
Hashes for stim-1.12.dev1684788861-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d520111ac80b2fd327be40240afe9c034cca447df07a8723e17cd3d3ecdc889 |
|
MD5 | 5c6e9acb4f6cffa03bad1e68863a12a2 |
|
BLAKE2b-256 | 49564fb45363d5bbda2c0ae6c7fa039437a6c3963c7819ba3f99c5e0477e5a0d |
Hashes for stim-1.12.dev1684788861-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1acab58e58ed4fc216b3d0fe3c4bb8d2b3065d570a879d1d69afd3dadcd498f5 |
|
MD5 | 535b626c19f9facf7bd2064485246f59 |
|
BLAKE2b-256 | d69f65e5c93428c3245a8e47ae184da08f9147019d507c7b8872a1b71271769d |
Hashes for stim-1.12.dev1684788861-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c99c1c669e04bca116c59e3129aead7fe380f7173d37163424be056190e723fb |
|
MD5 | 65321090bc1675d1b8ac91a34b6e928c |
|
BLAKE2b-256 | 01deb8f5fe570bffa0804761de0e0d612665550fa116795a30b6b527d574d35b |
Hashes for stim-1.12.dev1684788861-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b70401c805f2579c762e827048d88a0c3aedcee876c0d4b9e0535f00bab0749 |
|
MD5 | eb0c5f04365b40f88edc83a45a872194 |
|
BLAKE2b-256 | 251eb839cac8140962f3d77be9340806f0b3c34566492e261cd260917e7d8cdf |
Hashes for stim-1.12.dev1684788861-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 903dc00265f501998303203c6c3aea16ff69f111e02832e0c31d8ba629f944d1 |
|
MD5 | 8d116ced0db9ea37d3652d4012d06813 |
|
BLAKE2b-256 | 39aa525cafb9b1e5ee2242a5b382e9e5c3ade7c8c420b9d45a51b0f57e85dc63 |
Hashes for stim-1.12.dev1684788861-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb0dbd1c08da10a29975eb8bc9dbca0ce199a4510ab845e708624641724cd852 |
|
MD5 | 1aa3f32c2c2ae3d37d0a6b1e8e7602ed |
|
BLAKE2b-256 | 8f674c7db02610c12a6e3d5dd9f5be2be566339aa33f7a31a795d27831749e76 |
Hashes for stim-1.12.dev1684788861-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6579371c4e7ee7d1161cf19b1e0d8aea215c34873148778acbb12ec11bbcb9 |
|
MD5 | 0f0f49a025d2506f535d05785ae0884f |
|
BLAKE2b-256 | 0feb5139cce562921a7fb34e3b127248d5fce17ea075746b87db29a9f9796d15 |
Hashes for stim-1.12.dev1684788861-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2282be49ae24b45389d0dc5e8cdc170d6384415798c0c903f63d0c9392985952 |
|
MD5 | 77b6489ce6cc3a58161e32913ab6b756 |
|
BLAKE2b-256 | 065a533c22cd1fcb96676ba25eec75e60dbce98ddbd7fa31bb2a9ceb11b6757c |
Hashes for stim-1.12.dev1684788861-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02115bb7c2afb82a1d7f448dd8b3f2e6b946d5238f7ce1bf8deda3be02ea42e8 |
|
MD5 | 93c5f1865179a8d33c8c6549236ad302 |
|
BLAKE2b-256 | c538c79024b13f7e47f93e010435acdc959b708fd06e36a732605f0239906a6e |
Hashes for stim-1.12.dev1684788861-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4de53a8ff43a5024ece8631dd5aa4679d26e165d9c8d8cb35cc2e6fab1a1ba3d |
|
MD5 | 46c4738535c8bb26d8aa25c75500054a |
|
BLAKE2b-256 | fa0c32aa37da97623fabd7d6b233787f56b813ca832738580dfa9bbd36c1083a |
Hashes for stim-1.12.dev1684788861-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e241f738d501f1561679b698a6aa75f372746748c0d362a89091602846142b20 |
|
MD5 | c21ffafdd54cfb98c04203d77d75f93c |
|
BLAKE2b-256 | 342e38a5ebecc42af17acadae56d26dead298d91f8565b0569266351c176f718 |
Hashes for stim-1.12.dev1684788861-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94df6519563e3261566e61e6fe58f713b033d9f5f7b0f987a1ce1fb2b4b9ac17 |
|
MD5 | 715b98de7628125b47bac694ee21e5d4 |
|
BLAKE2b-256 | 0c3d6cfc74cbf01cb9c4df3bbaff2580a502ca285e86de15ff271322dd607fc5 |
Hashes for stim-1.12.dev1684788861-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d6af7d50014fc3670b2ecbe54cb488b2668f249fb22d3c56d00d57d671809a1 |
|
MD5 | 51e6fe21b069f9648893428f6ed0e5d6 |
|
BLAKE2b-256 | de551d35878b60eb1e1713f090b0b428cc3895546784adab4d6c5594adae0801 |