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.dev1692520989-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1216e4434c2750680a38ebf087e419b4328bedd41d57e18d298cfe5a9f87ce2 |
|
MD5 | 463cf878d72f5f640447d7b81d68f3ff |
|
BLAKE2b-256 | 9ef1e5edd3eb12e876a95ccc55c031dd6738770e01c6c81314b2381055eea8f7 |
Hashes for stim-1.12.dev1692520989-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e0470cab9d2e83800a87d21744702dd0915961e75e6e4d40144c65de329064c |
|
MD5 | a50d3518ae2b55966aeb6fa59ce384f8 |
|
BLAKE2b-256 | 0ab2102c90a0d010ead9d7d2eebd39d278359c3f6d42882a4e028513a9adb744 |
Hashes for stim-1.12.dev1692520989-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8cf9767edd247a6c742255394662f14a2a05a8b93102e58a1c2b7f8ef55fbf6 |
|
MD5 | be1c27bf8d47cf87412fd420f03af1ff |
|
BLAKE2b-256 | 13f284204f21fbb5c9aa9c142e56928fffba65165a90c5e4d85c44f899aeba85 |
Hashes for stim-1.12.dev1692520989-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9536e39da4e2767c5e218612791dcdc26a5bf60922f864a234d7cab99330d25 |
|
MD5 | d066baebe78ccbd8f73d42c6248ad763 |
|
BLAKE2b-256 | 965d0a3d8191b429719dfa64aa7f11b6edfb538e3a484d0647337576d2e88186 |
Hashes for stim-1.12.dev1692520989-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2d3b249ae439052a61440a3f40c71333ce676efb9564a5104b77644d94008b5 |
|
MD5 | 977f6c2641744a7e3a3966ea397a5372 |
|
BLAKE2b-256 | 8b96aa669c6ffa77a05b3b7d66d33f046fef8e7f7277d89d0e4ff27fb7059ba1 |
Hashes for stim-1.12.dev1692520989-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8344156368d048f5ef0b72e750d02073a1f0e89a45ae954ac100ba9a0f87d97 |
|
MD5 | b8dcfbefacdef7036ca5c991c8154f0f |
|
BLAKE2b-256 | 598c0208e8f8ad4bd3d42f6eb003741cf0bfb774c0b2f135b0a30b5acceeee7a |
Hashes for stim-1.12.dev1692520989-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c0c0d40e534cd822298fe12b5cb132c8b14390d29b41795c5f0be97605c4221 |
|
MD5 | e36c1273c72d2fc0743a24050e6a8e62 |
|
BLAKE2b-256 | 2bc9e35bec7e6976dcfec7810c470b2ab621e301be8ff0e1e184eb9bc18e11d4 |
Hashes for stim-1.12.dev1692520989-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f824553425006fb17b3e028384d7dfaf7d205c1d74181a0fd01307a451cb993a |
|
MD5 | f97d28484cda0b3a2027e59883f80571 |
|
BLAKE2b-256 | 1d02e0e5ce797f1e75f555e1b5fb75b056e6581d2c64599b27c21c68a17e11ba |
Hashes for stim-1.12.dev1692520989-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2faff32a8b0b5a035e6658eb9369d984aaf909c8fc906c0fc885099770746c6d |
|
MD5 | a653b0cf49039a341a9c898108d8bf3d |
|
BLAKE2b-256 | 66f3166733c826e509d366aa7e59d9e99f5a8b868a80db47cc88d972362e4441 |
Hashes for stim-1.12.dev1692520989-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b25351ee363a2d35b04690dbd7f30fbfee2e2ea8deb5ceac1e7e473ec6d01241 |
|
MD5 | f423f0bcaccb2948e1aec83504f65521 |
|
BLAKE2b-256 | 491f268e940af601eb16010aa30f3d915e85320cf0fc39f9fe897bf8d8108620 |
Hashes for stim-1.12.dev1692520989-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9ea8a3ec1612ea3194280e3ea38d4e721f6e203b9713c8f6dfd168e73ce763 |
|
MD5 | 6d7f37b1902e731a064441fa10f5b89a |
|
BLAKE2b-256 | df54af8dc53b1e9a174c6be1d0f55b5fc9924325497e31db57574f575d5be222 |
Hashes for stim-1.12.dev1692520989-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d877be11cff6e49c0d2f455209e2aeb444843b1d826531b2db18a87c7a74d39 |
|
MD5 | a24e7cf51938dd0605c8c54937903a06 |
|
BLAKE2b-256 | b1ce4187a69e3f29b91c9cac70396ff47f4f1ffb8357a6d59e033928c1b442ca |
Hashes for stim-1.12.dev1692520989-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a2ea3c475cfb2486b34f3c9898d84e0176587201bf0e236adad65dd7b5d8962 |
|
MD5 | 9de769e24d7362ffa0a8efd651946a59 |
|
BLAKE2b-256 | 0277f5bc60e4540bb122c0303b5353a607b667a5c40d9ac0f085dedb0d510a32 |
Hashes for stim-1.12.dev1692520989-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac617c29d8fb512260138d17de3ce91411ec8f88037478bde85180db5907bf4d |
|
MD5 | f6808fbcb7e569ee8d4306067b4a0493 |
|
BLAKE2b-256 | f977ceb0796910298f9b1038362c5c23b9d9be5f871045aa1f4383e9267d1a67 |
Hashes for stim-1.12.dev1692520989-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3086176a14a94a18fe6db1aedafde7defe68351ee18fe316d3abf18b7d8c36d3 |
|
MD5 | 276d180cbac7baca28a063fbadf3298c |
|
BLAKE2b-256 | 573bb687aea7394fd9cee3746e0f0a0b331798dd62d14995f4e6709198b8e854 |
Hashes for stim-1.12.dev1692520989-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af6ac2f4eb1a2744a24b7be59f6c70a08bd90027dd77564e636e111f4ce15d7f |
|
MD5 | b1c4e29fd4ac792077bd2c65a2dcd61f |
|
BLAKE2b-256 | b36847d404bc660df5cce162be6e5323ba22c372c1f1c1af5f93bfd98630546b |
Hashes for stim-1.12.dev1692520989-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4935e641d32477781b4093ab8f09de038b4f0ebcd9d3a8330a31c8137e464ee5 |
|
MD5 | 617a8ec9ab902fa0daff690a9343de9f |
|
BLAKE2b-256 | d559a7a12841041b61792fcd274565e20052a07a4698c973cdb7cd7e8035467b |
Hashes for stim-1.12.dev1692520989-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fa1810868c39fb7cfa526650e3f2809e574b6ff648e0a0546f5918e5336f0b |
|
MD5 | 0ce0914cba9ee69ad7ef95c33c1b131f |
|
BLAKE2b-256 | e38d08fd754656c1afa9494218c8a1ed4225662c649f00f174ceea31c57d8b10 |
Hashes for stim-1.12.dev1692520989-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d91615a914ce02104c71c21f2a53b31ae16abc21f4fc3769a67e19c43efb1703 |
|
MD5 | 8c41bc91ae2915ba4050280690c2a702 |
|
BLAKE2b-256 | a2734ffdd0b0bc33f7006fdef453af89ef5dcf91741c5fabea2c3f436d49741a |
Hashes for stim-1.12.dev1692520989-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | facc5673018bb39ea4797cf7d72a6b75860f49d220118523809261a0411a1433 |
|
MD5 | 83ae97dbac1d621093b2b12411540110 |
|
BLAKE2b-256 | 4f3b282c27f670e151990c07f8db3982fd022866347520bbebc642b3dbc47bcb |
Hashes for stim-1.12.dev1692520989-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c01745d94eebed3292691f88041835e9c40fe2199898db837f6d23eb9620ecdc |
|
MD5 | aa4ada62bdb2249892e49123842a9972 |
|
BLAKE2b-256 | 54d99bae707993f61a0ef743efa27f0172e8a9c5df981f790f847d4d8cbf304a |
Hashes for stim-1.12.dev1692520989-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57f5658aa0d4ed3ce998fc137ab86648921280982f6bcc51035c43ef9b8180ec |
|
MD5 | 46290eb1e17fccd79281d6e14d6c48df |
|
BLAKE2b-256 | 01f1a455c9620f881cdfe231e89e8b4ce90b81542898805f8efcd31afd47f08c |
Hashes for stim-1.12.dev1692520989-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6494e981176db6e65e10e542e210b7f2ec5f6d0af122e91838b2d56bc6f2e4be |
|
MD5 | 6ac45e97a5c9867370473aebb48a729b |
|
BLAKE2b-256 | 6d877595588f2d68fdd563be6f897a6555fcb884e228a224e8100147d76827ce |
Hashes for stim-1.12.dev1692520989-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d75109523ebfee89c9c7d83e8eaff8a3602ac71e7c3b74c6e1735ee42a80a1ae |
|
MD5 | ad38d90c1dfa4ef313f44b069a7c784d |
|
BLAKE2b-256 | 79505d1e6245ca0f35608d4ea75ab59b0373068bf5d4e98f41464c40a0d2c768 |
Hashes for stim-1.12.dev1692520989-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a9b06a990bd5514cc98b0c5796e5451f339487f746a2aa74bd7ab774627ba7a |
|
MD5 | babddcad95b41703f2431d4c7686b22f |
|
BLAKE2b-256 | 36ec7d37cbfa7c4f22b0cc9a2114d7cbf9185dce92dfeb51012ac58c6b037255 |
Hashes for stim-1.12.dev1692520989-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb31c51ddc88c1b4c917127b75afe9eb8b4cbe6f0e67b4455a4646725220d377 |
|
MD5 | 16502a85fd2ef5c4607e02bced77c584 |
|
BLAKE2b-256 | 2c4f7ac0240671cf9bd1440f24b0c70d156bd0be4220f68f9f04ef876d63c7d7 |