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.dev1686523368-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74bf7eb4950d1a02575c6a269dfbc4227360d51e110540373295d37724af7a8f |
|
MD5 | 70e97bc7a45424b3d68264f85367df55 |
|
BLAKE2b-256 | ae0f8a4646a9231f1a5129e16e31a82875f1f8366d0dbbcec7b6605e30a71bf8 |
Hashes for stim-1.12.dev1686523368-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a6c6975bd74fe18a12d3668300da147d1ca0ea304ad8483b6be9bd8fb542171 |
|
MD5 | 81183ab08c439e76f954d7a436109df4 |
|
BLAKE2b-256 | 34f5812fd69e25726ee948a7fd21c8025a32b6840b0f7783fef9fe3733b0125c |
Hashes for stim-1.12.dev1686523368-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27dc5a518465d08d7bd28996eb27c5770b8830585badf0acde7bc377f141f8ce |
|
MD5 | 600cfe4021a9ce2bf52a8fa01e49f3b2 |
|
BLAKE2b-256 | 591e66fda005fe092f31d23a041c8b680993eab048678537993755bbac587314 |
Hashes for stim-1.12.dev1686523368-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899a3c4eb619de39fa8513a2071045ba6860e3132def262a82e2a113d60bc315 |
|
MD5 | 0b52e7b92d1f540b75e1bac16f471091 |
|
BLAKE2b-256 | 33d88149a2ddb580504abad4a40f7c27a7682122a4d5ba115baf2797b2f831b5 |
Hashes for stim-1.12.dev1686523368-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0362a667efa4e9babff0d94e4ea2d891868510b92e120b49517024b67e44c6b5 |
|
MD5 | 4ea3f2be80154dc8f74a49f904cce9b8 |
|
BLAKE2b-256 | b094465f94706579d031a7b88f42be4aef1e243d575d283a9de656980aa7d8cf |
Hashes for stim-1.12.dev1686523368-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1112048c0e7b87f40428722d710ce31adc2b5c2e3f12f4eab0597e2bc37a41d7 |
|
MD5 | d17dbb33318098bfef36ce5964b80a5b |
|
BLAKE2b-256 | b6fcac945eb633727533ab54a7e8baab7e39a09c772ad856ac2eaf9e55700447 |
Hashes for stim-1.12.dev1686523368-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d9cb3b2da6467dda468f6e5c41552f4c6919b32fcf6201199ff975342ca7d8b |
|
MD5 | 95c8a1c20dad3260b0ecc2bbd26318df |
|
BLAKE2b-256 | 15c4c7915c05d888bfdb15463a878136f592267d05f0b8adcee5aed11ea1dfe7 |
Hashes for stim-1.12.dev1686523368-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72e80e044415c805be74a14fe306d1fe70c82e802bf2085f0345d389da5e61ef |
|
MD5 | ccda31740eb73b33955b2d93252cc4cc |
|
BLAKE2b-256 | 1028acbe36724863211b71db47152fb1100a0556a27985603e4c10642cd7b27e |
Hashes for stim-1.12.dev1686523368-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ad6239f08e9c59be69932f2714a851327894f71fbbcc6d786a887278f2df88 |
|
MD5 | e8425e09903bf8be880a1d2b2dbf7546 |
|
BLAKE2b-256 | adf64f3fc0b30b75a5adcf2ae56390a4966de86c1d7252d7574c54cb8c3169b4 |
Hashes for stim-1.12.dev1686523368-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 621f5620f7cf28337cd3beda68fa299346f138b222a465d4548eac560057e4a8 |
|
MD5 | c5f01e49c91608a0d1c77931fb462200 |
|
BLAKE2b-256 | efc358d41f2d361b83ae6d5ce01e17abe89b525b6c4dbbec491635e9dc36d61b |
Hashes for stim-1.12.dev1686523368-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e97aebde633b06c4d1229f0f7ff2092299cea6e904d2eba3656d941d1d15fd |
|
MD5 | 3367a67ed428b5aba0bb1d1e5adef4f8 |
|
BLAKE2b-256 | 3cb23b2ca817eb0befb4425964eff95c73ae007e5a248be247302c295db9ab6f |
Hashes for stim-1.12.dev1686523368-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 820e7ed1bee68f14a72bdb4f9cac6fb5ffc21799224e18c5c07ee3d1fa90c614 |
|
MD5 | 586adc02a2302a6da275f9bb418da08c |
|
BLAKE2b-256 | 03950735a4e9d5b0ab8789e7c85b89f6052f863f7a5722ec5554166bac0dbd15 |
Hashes for stim-1.12.dev1686523368-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddf7d07ab8d1eb3c7d22dd82600691d74db701ccb8e0be7afb362f44809ea369 |
|
MD5 | 87cb73534d2ce453851bc981c2c49773 |
|
BLAKE2b-256 | c40a6e3ca2c26f89b362871a4b93c3f313078ba95cac79937d93ec9b747f0324 |
Hashes for stim-1.12.dev1686523368-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f57df1576a2bfbf2da4e090198e756c8ca55af6445f8cb58f53a99799f85657b |
|
MD5 | fda4d91f027da167efd99d110b8c8acd |
|
BLAKE2b-256 | 1c99839d77fbc7f3412990653dd73e0178d7989ab9ce119e48855bc699f1c3b3 |
Hashes for stim-1.12.dev1686523368-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8dd374d59c2039fa5726e98fc8391e856c9f3bc7d5dfeb2007d15e432e12baa |
|
MD5 | 68a26473f5ec57c62334e313897a3a45 |
|
BLAKE2b-256 | 608b5d85a889bf0872576c945f2a4225520db9f4121f3e29707c617958cad917 |
Hashes for stim-1.12.dev1686523368-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f3f2894b539549cd421b61a91dfd380447b739fd5a281049af23cd1147770f4 |
|
MD5 | 33351024ecbf4cad441b1101be58dc21 |
|
BLAKE2b-256 | a9bc26f475c92a956e4c6c92ee090269a3c3db682b21142de8af74c84395f917 |
Hashes for stim-1.12.dev1686523368-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7498a0fdddc8a020cd497b72e8334c00df05100bf4867f58a5361c1341020490 |
|
MD5 | 8637026491096f5e5278c0596b426d81 |
|
BLAKE2b-256 | d497237d705ee306298c2ed3046051fcbdf7195d38ac8b9948151f4dbcd2961c |
Hashes for stim-1.12.dev1686523368-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3490aadf2d0a9e334c8d55c4f328435af883a3bbe1a106760db7ae785e603ca7 |
|
MD5 | 7a648d7744befc8e6856cf0278852ab6 |
|
BLAKE2b-256 | a323bba48bd8519770256589108a26e1c6ffe25f4d332f7afb327f4e3496bf2d |
Hashes for stim-1.12.dev1686523368-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11df09e7f7fc852be86d6f53683289f3bb67647ded0f39d521169f6bf8dd5c65 |
|
MD5 | c05215472dd365a28abcb70e240fb5c9 |
|
BLAKE2b-256 | a101e6f1445ac89539676d6c65b8972870499bca0c851bff19ee564f51879651 |
Hashes for stim-1.12.dev1686523368-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b690fcf0583529e4b63045eccfafac7cb0b0226f40410015bb7a95dd4ed70284 |
|
MD5 | fcce3a19d86434ed1ef1ef9118ea459b |
|
BLAKE2b-256 | 2c33b3007ce58bf10a42ca0c97e6323cd505910135a2f3873726ff5020ba0e83 |
Hashes for stim-1.12.dev1686523368-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af44d6689abb8c71f0edf43b877d16f3f33d077002bb9b053a007e234e043eb |
|
MD5 | 6bde8dde7eb6400b712464d3360dd959 |
|
BLAKE2b-256 | 759c5cf16c5a4124f751fcb8bf0fb61f57fcb8fbaf43a7d264db15f2f9a58ef0 |
Hashes for stim-1.12.dev1686523368-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e67c51c767c9e0b96139a66ffb872d2ef0c9352b5f1c4cea31091bed6b638a7 |
|
MD5 | 466973fe9efe9625759f74ad70f726aa |
|
BLAKE2b-256 | 222fec80af684de1717d17557a895450f360ffbbeb4ddb32904ab5987d26bbe7 |
Hashes for stim-1.12.dev1686523368-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc7f38537b235e08fdd0bc1fdf5cfee7ce77a6f00c8bdcffce44c6dc07f67c64 |
|
MD5 | b8de5e94e83a512a8c4a2ecfecf4257d |
|
BLAKE2b-256 | 4ca8f6e8d17c205e13617bbb22095a5a66efcfb71a155c880ba479347f844d0c |
Hashes for stim-1.12.dev1686523368-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bfb41e4707a472f3d2507a6f87c0ba08e1de26e919a6f1711d9b7d1a1bbad41 |
|
MD5 | 0d9513c1b4cff7915d5772f0d508a05f |
|
BLAKE2b-256 | 2df22daee67aaa15e47fe7236a3f1926e435d351a88737117c0a09463dabe605 |
Hashes for stim-1.12.dev1686523368-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10910ff35a8e4fb29a53b0b5afaad1c9b22d660f66e8cdad63f5dc4e40544ca5 |
|
MD5 | 1265efe2c721ca84618eba99e4cb36c2 |
|
BLAKE2b-256 | b79ab060798e43c23dc0195531e18b01c572e94f918714e9c23a3bde79350f00 |
Hashes for stim-1.12.dev1686523368-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb2a47d506253f8cf01e79ba544f19b40fb9212a751870f62fbc10aaadfee79 |
|
MD5 | 5e1ca2ac0a29ba7e730aecc66992ab19 |
|
BLAKE2b-256 | 6ae8ce951ba37b8c6d4eb6b28b039e7da760d638a6e8815c85df71a985995d99 |