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.dev1689798521-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb0b8aad41dc309ddeceb60d7e886a7e380209cb8f584f500c4b401c85d78b02 |
|
MD5 | 46277172f29bd22327999b624c83d5c3 |
|
BLAKE2b-256 | 92974c2b138fa100e9fd880855e520b7cfd2c1740c53ee6c21d917882bd15923 |
Hashes for stim-1.12.dev1689798521-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e0f1d8f47cf6c3dc4ab2ee4952290ce713a44836be94b489c42cb3152aa01f3 |
|
MD5 | 5e6db197d36335fbd4529af45f9591ad |
|
BLAKE2b-256 | 526ce70b231d2d10ba4d7ecbb2149533024b93b043a6b8255b539426f08974d9 |
Hashes for stim-1.12.dev1689798521-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b31c0feff4f366515b8e5ad4d61decdee4e90b5a2bda38d103dacc05f006eac9 |
|
MD5 | 0a41c6970e7598ad993d172ac93790fc |
|
BLAKE2b-256 | c80125d74c360600ae682e4ea66544800a982db60dfe41d77daa1b5f3f8474a0 |
Hashes for stim-1.12.dev1689798521-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc6ccf69f81af7f0a8b54a9c4fbae43e413df8c1ca190696a253f67539512fa |
|
MD5 | b6b924e6403a97a9a4e8386c1ecf1cdb |
|
BLAKE2b-256 | 7d6ff47a1b475141a702c9c4af5b37579e61a2d7cd7cf545ae3f76b4aeed98e5 |
Hashes for stim-1.12.dev1689798521-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 260532eb05c79f452324a0eaba8cb920f5816123a8682f7a78d9ab392f7bbe4b |
|
MD5 | fc4294a31dc08fc0aad87f492bd73292 |
|
BLAKE2b-256 | e2d533550d1dbc683ac59ea35627cd4689f7dd4d13896940e7ac16122b857ba9 |
Hashes for stim-1.12.dev1689798521-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096b7386adb979ac4bc50ad8bf54cc006edf0b39e2e8a1d4d8151995d06fe10f |
|
MD5 | 14ac8db771f815c67e539deb705f3826 |
|
BLAKE2b-256 | 4346bb7933ba52836ef9c3ced7ea44bd27170b26442bb6234c753ab7ef4360df |
Hashes for stim-1.12.dev1689798521-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58c07fd16763e63a63b83aba597fe87be2244b02b94a9516cb4557aff7d9ebba |
|
MD5 | 08a1eb3da1fb3b787edc80d40fe98dc4 |
|
BLAKE2b-256 | 81eb9d991a3099b55dc989f16fbb32aefe32879a572bedf7da3cb523d13aef94 |
Hashes for stim-1.12.dev1689798521-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eac06d749d6feaf04b6f24dbdf3439d6b6fc87c8448760422d3a461ffe88b0a |
|
MD5 | d81012eab4bf100effe984c5d498c5ed |
|
BLAKE2b-256 | e6b504d099fe1bbd2d0a4a03f7db0c8a3609990bd47a8b1e1dd46966ea59c941 |
Hashes for stim-1.12.dev1689798521-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3e7a04bb9bbccd5b2a0afa1626997b331d73e56764ae68733eca954526f9d2 |
|
MD5 | 05a905055ae58c88750497de4bddbce4 |
|
BLAKE2b-256 | 7e3ed31cbc7b48693cb1636f55049d0c04187ec088159fb98f71f2f136c11ff9 |
Hashes for stim-1.12.dev1689798521-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a610b1a277943ff6c6323e663070083269914499fe98daaaabf82ec6953a72 |
|
MD5 | f9edb89bdc117a82dd8083bb62de1e87 |
|
BLAKE2b-256 | 9f389d5c4a53a1ba71442a24a28ecf8cdb1f79bc0efddad9364c715cfdb62e4d |
Hashes for stim-1.12.dev1689798521-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ce909e4bc552a02b2c43afe8edf6676882d2093c8641f904360ca93719ead14 |
|
MD5 | bc0075d3fd0582f9d6a6011786ef81b6 |
|
BLAKE2b-256 | 2caf7df1f98a1d8a9252f6ec42be07847f60ef46df1c61bc89fe03f1ad390e90 |
Hashes for stim-1.12.dev1689798521-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02febece44b7155ff91b74f5c6d0043c97c94d6cfeca6c91ddd2dadde5ce359f |
|
MD5 | c3ed7dc52a8bf63904c8c327b02f77b5 |
|
BLAKE2b-256 | 38197f4f945d6fedb7da1dd550df092a3ed7894608a72dcd593d8875ceee28f1 |
Hashes for stim-1.12.dev1689798521-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb5dbffcdfdea688875694e8c80e97c677e7dbbf34d9bf872e10388741c68706 |
|
MD5 | bcafee0f4536ab0bf1162f88f2fc4fb6 |
|
BLAKE2b-256 | 4537de261dc08011056f8c885a1400815c364a4411a8836974aa99fba665f51e |
Hashes for stim-1.12.dev1689798521-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72d69dd670bca4f8581ae0b6bb88e657ba80bcdd618d9db51378d1d38842235f |
|
MD5 | be28f7d0291068b2d95afcf0675b7eec |
|
BLAKE2b-256 | 9b35d132a34af98a0490f12b773d137889b3dc35d6edb82698bc565a589a9fc8 |
Hashes for stim-1.12.dev1689798521-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a9e708004d1eb7edbcd5fe66680daa007907281a2f7cfd22d7fe1d89bb5fb20 |
|
MD5 | fccf79ed2bb40118be6f7288c2f15862 |
|
BLAKE2b-256 | cdd0a6f50f7123262e73bd31a206648607136abec740340412f616ad5f8ca2a6 |
Hashes for stim-1.12.dev1689798521-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7cb38118990eb2475a0ae28170818b8de84a77fb921b99a26acd5cc05f5128 |
|
MD5 | 367b7265eb0bb3f0e60a95f84b73b560 |
|
BLAKE2b-256 | 15c287d25cb3a7984efff8ad40bd77172d760d062932aa892b30a0a3478b2eb2 |
Hashes for stim-1.12.dev1689798521-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1198a50fda78d40ba1e2dd449e99c3114979d10b85fb0c15787b0a2be0cd54bb |
|
MD5 | 9509a6c91ce42fa3399dede84cd8b4de |
|
BLAKE2b-256 | e695708f1912aeb0a4a748b7ea77887576a5d10274cab3ab675f5550b558c883 |
Hashes for stim-1.12.dev1689798521-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e5762eb2d74fe2b3f45ee81b440d8b10d9265712176cd9f27128cb7f3e53704 |
|
MD5 | e21963ad1f2a28a18603ddb6f23a3fbb |
|
BLAKE2b-256 | b2c6afcf11fcad48858d1616cf83308c3f3258a8c333189037aef1922c7d25fc |
Hashes for stim-1.12.dev1689798521-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a334496bbc1725f397a7937cd5da22be89c2e252e47653c3f150ef1e762d7d0f |
|
MD5 | 8b183b0a2aee7bd866343aeb6cddd228 |
|
BLAKE2b-256 | 1a5958d84e293a128cc4741e16708949bd25c0a3644b4ae1a03d339b56cb3c57 |
Hashes for stim-1.12.dev1689798521-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6d6831c4c4ed07e1dae8227298e8710d503d42bf7f47036730b014a9e134c63 |
|
MD5 | b8d5512596f51f48fb16ac3c7bafbc76 |
|
BLAKE2b-256 | 840718addafb5581b9ba7a612bec2b55ba0683c5ab241a4facd395c751308f3a |
Hashes for stim-1.12.dev1689798521-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c93fcf7304362d4c4c458c0308f8e78ab73e3b16e64baddec95b81ee71233f82 |
|
MD5 | 57e33492f3e04f255f5e5fa6ed74e22f |
|
BLAKE2b-256 | e8f7babaaed68fbc3cf306155c403cf0ad7a8c25ea51d7aba2a75dff81df6cb6 |
Hashes for stim-1.12.dev1689798521-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cd4b608fc6c97b7cd25d402f86c6419c69c6126f40e88f83418416b76edc318 |
|
MD5 | 9a17d2432f362a5f4015f21fa2230f76 |
|
BLAKE2b-256 | ade5f183768057ec2162ddeebe3f4e2c1510863591945f2890cff01a89983ab1 |
Hashes for stim-1.12.dev1689798521-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1022f35842a547a4f13e2568f7f8b0348094afa6621fb8852adb128a0cba6daa |
|
MD5 | e803cf4a9275fba74f2b596a21dc71f1 |
|
BLAKE2b-256 | 306b176ca9d3b0f5e8c1de7950ad9b084b1529d95b77aecae568da733d96b58e |
Hashes for stim-1.12.dev1689798521-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c0a2b1435c04699f68dfb4cbf96132d52b01b24d5281069080932402c357dd |
|
MD5 | 5e640982cddbf5a10e01f1d18de52a0c |
|
BLAKE2b-256 | af0575cb194332e9ec5a86cea25c5054a9e0018fc6196536a5f4262524cdadfe |
Hashes for stim-1.12.dev1689798521-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd227bb7959a975904e8fd51522fb0333bf4dc26c3906d16f2f63c5281b2173 |
|
MD5 | 19e07df72cc5800164b97767c157081a |
|
BLAKE2b-256 | 7fd3a9c0e508689ffcf8758f876821e02669349b515242ea2854b1d06fe1b88b |
Hashes for stim-1.12.dev1689798521-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc2b73efa3de17b72dfadaae7acfe5ef6716dbd29a67cfe84810b8d3513c2418 |
|
MD5 | b72f35389c4ddbd7ec278d167e77260f |
|
BLAKE2b-256 | b878f6496ea2111f0cc0f8129318a61503a2ebc1cfc73f15e75803f18e0a3b80 |