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.13.dev1693009683-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21f7e90b7796691bf4026e0f76c0ee72e740dd239206069033a4a8c3b09e87a0 |
|
MD5 | c35cd61dc4aee709e1e91972c2e14ba3 |
|
BLAKE2b-256 | a06ecf8792db626fc421e9622eb0a507e12af0a4562332e2a136d743049e3033 |
Hashes for stim-1.13.dev1693009683-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8289369a30ce9b2c8450c3290b0f94879923d9696210eb38dff38155163346c0 |
|
MD5 | 464fc9129004e34f05802688ae0c7195 |
|
BLAKE2b-256 | 7d16efaf23769f99059a1b37a6a282c8cbfede2ddec2c23552daf6ddf700cc1a |
Hashes for stim-1.13.dev1693009683-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c29ce88d2770cd23ef52d4daaccf738f78d35ffedb2b1a5229f0f6e18d146e |
|
MD5 | dbe64d99b319e0e2d825a2ccbd9968fc |
|
BLAKE2b-256 | 0f99cee65d4cc2076d7d4121a27a6d7c30ab96d1ec5c4eafc4950a1fdc8e0ac8 |
Hashes for stim-1.13.dev1693009683-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c805d004c6816944b191735a2652944f4e7ac0f81a306b5697350adb05ccffb9 |
|
MD5 | 783c9dfaba273c38d89909df42c756c8 |
|
BLAKE2b-256 | 853e18c9eb6c54cc7a0f485456f11e41e054905d2760e2a13c57adab80926c41 |
Hashes for stim-1.13.dev1693009683-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76a5b40e5599d38b738f9444ca6af534c37256fed3eab9e5f628b65491ea22a3 |
|
MD5 | 02992a8cddd5064449b877d672d528cf |
|
BLAKE2b-256 | 3b2d6f9459d2c9b0305123dc98faab2f3123da246b4c4b147b6d834830425bc2 |
Hashes for stim-1.13.dev1693009683-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33664de59b0dc2915a9efa9d0e04de79e16f1cce573f946acac67530ad993119 |
|
MD5 | fbd4303ca0a783e367868a0dd78062c5 |
|
BLAKE2b-256 | 058fd1b836884de0c61b07484decb3553f007e9339a7ebfc6bf17ce850f865d6 |
Hashes for stim-1.13.dev1693009683-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0432d4da1390f5a40c6d732ad772828b3eb2d833dbfd4d2d8099a8261caea18f |
|
MD5 | 8bcd36c3e6664fe9a3c1dc9ee9bf26b0 |
|
BLAKE2b-256 | d53323fc0f3a52394e09b96c395bd1d4b22a35b4b00bb5b70983e1136a95a10d |
Hashes for stim-1.13.dev1693009683-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d20f6ce90e229149dbeb87f461835e9cb4296b59240d310ba49a7c6972ad9ee |
|
MD5 | 6b3a8fba4b40076023bc52bd58d485d0 |
|
BLAKE2b-256 | 7110f3e6b58cffbf53bd4db0855a3d739c45a5184cba681c70d61acce85ba6bc |
Hashes for stim-1.13.dev1693009683-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24a634a79d2e06a75e49a1db8954e332ed775e495a377e1441908129804c2d66 |
|
MD5 | 6d8828ee53ed0e1a2d4898c75a525802 |
|
BLAKE2b-256 | abd382cec794f63e0cd7a44703f305aeded442e81dec45e9693b64324aff0d43 |
Hashes for stim-1.13.dev1693009683-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8d439aaf3582f34b561a2cef08f63eb3610a4bff739c898481fa9c426d0479f |
|
MD5 | be3c5fa72ba3ac3e7ca20ab0b7182450 |
|
BLAKE2b-256 | 53af8f49f0393f086538968d0b8a2bb74f567983a183d65031a892eff05741a7 |
Hashes for stim-1.13.dev1693009683-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23bd6ff24238bdad841b21d0cf230fe4fd8141873a951c19fa4d25fc33f35cba |
|
MD5 | 0e0190464476c49b0e491bc6a4b2a610 |
|
BLAKE2b-256 | ddd94fed5c887e1b7effaa3b2fbcc62c855a0eda075363837c857380e672f5b2 |
Hashes for stim-1.13.dev1693009683-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80e5e3c4af1d49ac3e99202686da20ec720a3edeb036c5f8f42b0a9fb9969a8b |
|
MD5 | e9bf17fa9293ef01154cd5d6e33226c3 |
|
BLAKE2b-256 | f9f481dfdcc96bd3f6409ca9efd6694b8f656d331048797b722c9750de8cd30c |
Hashes for stim-1.13.dev1693009683-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03469ec22ba4a7238552a8b64a38d42a256f363c5771324891f17b379896f97d |
|
MD5 | dfce3017b5dd4cdc154fdaefaaef9739 |
|
BLAKE2b-256 | 198cf997a9be60f9062144064965274cfcbaf1cd1de43e8048b0149361f50fc6 |
Hashes for stim-1.13.dev1693009683-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7454f22b22be0b45b46b5d49426517d61ada4634f9216c192cf35189a78f4da1 |
|
MD5 | 5e5da3f39c4ff9764b600dc7b6000b8c |
|
BLAKE2b-256 | 5f758ba218f875850b6d32c5a81cca2955b3983c1d1c3c66144661110f219fde |
Hashes for stim-1.13.dev1693009683-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e37b1d1d975848655d806dd67611bef05f3e617af27b114d79d51fa3c9dae2ac |
|
MD5 | 710732f912aaf339fd9d3d0f165697ca |
|
BLAKE2b-256 | b96489058e1e16b95bdcf1fec11800f86a9a8460842de4f3340fd391ac019d6c |
Hashes for stim-1.13.dev1693009683-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b291aac3062c70970fdf85f4862fb795ebebfe2c7d711ac9568e9fbbeecf7126 |
|
MD5 | ab23ab0dd509d91c9b8b6f4bf3583858 |
|
BLAKE2b-256 | 3c872dcb109ea0e55b11c72e72d7aba5965e9565128ef5f60e991e65f81ca466 |
Hashes for stim-1.13.dev1693009683-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c48b0e01adfd8d351addd7cc26d3054e3edd0b62c978819677548e3356a7d63 |
|
MD5 | c1abfc77b08332e790a000c94f18c46f |
|
BLAKE2b-256 | 59f1aa5cea928817beba8490242b9d1b9c7e5be603c07569832502b01718448c |
Hashes for stim-1.13.dev1693009683-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cf82b84b218b1be6a797db10309cd0fb0dcfb73ba1433431cb4769d6981d054 |
|
MD5 | 983e4a199ada9029a7c2ed7b89165475 |
|
BLAKE2b-256 | 5962e2561049d0060aca45d01f08d269663c662417781beea0cdc1cedf52779f |
Hashes for stim-1.13.dev1693009683-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea4d49b33282e19fedd0f2f7869cc53d8298637d8a0dba60b7292d4c84a5ddd9 |
|
MD5 | 93755e066e36b8ae5c669c3d1761ae3a |
|
BLAKE2b-256 | 788280f7174dd995b238cfd1acb2cf624957e864edfc4caeda06f929b993fd62 |
Hashes for stim-1.13.dev1693009683-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48dbc57e2c12f45df282f4f932cb7199f6732d00a418d7641bdecb7f3d56f01a |
|
MD5 | cff0ef951d165610f279ac106c8a7bee |
|
BLAKE2b-256 | 85bab8ddecf2c4aebcee8972234c78ba5c0d7d7c3f54b990ab889b27651cf347 |
Hashes for stim-1.13.dev1693009683-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94210f615730503f2b77d0d4d5b18c1a1625eba0221253ef13ea06ff0bb4a084 |
|
MD5 | e98ada9f36fba2d6c8fcee771ba2ec65 |
|
BLAKE2b-256 | 432be14709799808f7f7dcbf73e8b6ec47da232b72488c1de7a44d3b0392013f |
Hashes for stim-1.13.dev1693009683-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15aa9cb9988321b24c98497e59e15e9c47f9cf22af37bdfbf374a66548ed656e |
|
MD5 | 78bfbb672856906303264267b216267a |
|
BLAKE2b-256 | 9f3329eeb450d6dae95c304748c93c8a146443f61649f8af0138279c4956e8f0 |
Hashes for stim-1.13.dev1693009683-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62ed8c4935ea643aba29ed7b6252d9205958ee3ca8829c4aba1e2debab2bcb19 |
|
MD5 | 412ff639aeb5980a165fc62e6373cfdb |
|
BLAKE2b-256 | ed3cd53a894fa68cff81ceaf7c37586d4bc7f9c2e0b887980fe791fe68406bae |
Hashes for stim-1.13.dev1693009683-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6877194cb3a4fb9b09a1210e36e40f06fc71e5c22d789bfaf08c6f843dcca66 |
|
MD5 | 65215548af77edbb22f9abb30a20879f |
|
BLAKE2b-256 | b3d9fd9cd110127c646decd98c52b4f90bb1d220a921ebbad70211020d96073f |
Hashes for stim-1.13.dev1693009683-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1de23f917b98c66503f60bfb734bc1f4778a2796b96c0debf342c42434c9f0e2 |
|
MD5 | 84a3fc1d18c1ba0a6447295b0fe000bd |
|
BLAKE2b-256 | d5b69bb24e2c51cc5e41bae8b70c3def0e5babc4f4553252a46851380c791d2d |
Hashes for stim-1.13.dev1693009683-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ec0272d1ec078bc1d685e1acc370196ba46d3eec1cbd5c8af165f782c4764b |
|
MD5 | 52765e8f7363710c2a0b1bd7315aaaea |
|
BLAKE2b-256 | e622e44bf7dce8b13f5705d1143ee7668b75569e500cf89dce9e03b8a336ce8e |