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.dev1707966721-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 811409c5ea6046ac86c3fa589c1f68d144d6ffd9ec69c42f1f68071fd3ed21aa |
|
MD5 | 59ef021c13c72295f24713f8c10ac2b4 |
|
BLAKE2b-256 | 93063bc49b7b5ee50a3ecf60a60662da843d116dd298d605482f5ec664f87224 |
Hashes for stim-1.13.dev1707966721-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 106682e2fd6670198caf6a7fe01da1df38d967c9746f840a45f7cfe537ecdb0d |
|
MD5 | f8ffbd8e4e062b26aaa5b3a34a277701 |
|
BLAKE2b-256 | 5f3d8581d9f5fc3ba9efdd45e0c3709a027b52f8771aab5310152983e1fc7445 |
Hashes for stim-1.13.dev1707966721-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a9bca8ad19c1fea1b61f5dc48a19c8d75989a1f7bacf5416f36bd72e7591742 |
|
MD5 | db1e637ab530085ac3629930116cca32 |
|
BLAKE2b-256 | 0d5b1ec4019c7ce508fa75265abccdbd674d1f3a2af7ff434eee53f6d84a4af4 |
Hashes for stim-1.13.dev1707966721-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb250e8e0307a00d408cada41736815d78926aa8e116602497c30fee957fc3c8 |
|
MD5 | 11bfcd4aac05bdbdc155807662f967c2 |
|
BLAKE2b-256 | 4bcb97d760fa7b14d6348c0742da08c1a45717a4a0b2077bf94dc03ef30c0dc8 |
Hashes for stim-1.13.dev1707966721-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c52c877c2da1d1d0fc1712301faa4802fdcf16974354ae4cef305ca1b78d81 |
|
MD5 | 4a8e67b7e40250ebdd1534d43cb0135e |
|
BLAKE2b-256 | 173dc9de32da3a8e36cd66a5ca3706e4f24cb40681b0af29af7f5638d9b9e15b |
Hashes for stim-1.13.dev1707966721-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a63e19495e58a92b63ea84f7a1419264b0b7c1530125940a6c3e1d176315ba5 |
|
MD5 | 1f424d935ee67f17d2d246ed132e13d0 |
|
BLAKE2b-256 | 14fbedb8dbaf7da88293ac0e18f072fe1f1acd70d950c544ab2ff5c5d1a45593 |
Hashes for stim-1.13.dev1707966721-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9769e06ae87b87c1324d4ea67613cec0aadf5cb7f1fece7e47466402a54c4717 |
|
MD5 | 39da6cec2ca7aeadd58609c24ba45280 |
|
BLAKE2b-256 | 554f9b9bc2146e93a2c6f582126ba1ae4c28fab9a69d570bcf9bc1ffbffc728a |
Hashes for stim-1.13.dev1707966721-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19b895f05e81d0c5890cc0da2eec6911e34621be6fadcd0ae64b27902b78cd85 |
|
MD5 | 424a80125161491b8f7f8fe4077aab4e |
|
BLAKE2b-256 | 1518e46ecfd96b6813348813cb93973559d01b42c4eb83d671aaafed302dd6e2 |
Hashes for stim-1.13.dev1707966721-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b98b99af4632da37d9d7cc59bb6dce5628c66f0b3e313244e9fa787223135a2 |
|
MD5 | b355b5c911396e7bf343dcbe14f77392 |
|
BLAKE2b-256 | c0eb69fa1a87983c96a4fe7a2ac5807ea607f6bf87cd42cad3ec1843d22dea94 |
Hashes for stim-1.13.dev1707966721-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84c0bb8913cb44ef96acecce6915195f0539288df0cd175cfab33535cf21fb33 |
|
MD5 | 768f3d46c9f4bdc6494e6acbe679facc |
|
BLAKE2b-256 | e69b9245eb8a4103a760456cc1b669b48e158483016dd3018a92fe2127f76b37 |
Hashes for stim-1.13.dev1707966721-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac62d7f942c5179971e041b74fa206c449b07b13c58eab7a41a21a9b30431431 |
|
MD5 | b579d1470801ce940fa4691ce0bb34c5 |
|
BLAKE2b-256 | b088df97b289e7920c6694d051f991340b34e958d2bef14540a9112501127e69 |
Hashes for stim-1.13.dev1707966721-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 408a96e36cd0bebc98c9017a15a2912b06b9d78d66ccd23226f1f657be13498c |
|
MD5 | e310c8e5eeb170ede77dab9d97c781be |
|
BLAKE2b-256 | 42e3273c234730c314a9040b536e1fd48b39dea880dd1f437086de3e9006bccc |
Hashes for stim-1.13.dev1707966721-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4c2a4b32bf971d631967fc2709fae34dc959a65c55e5d3d999f62228b3a854 |
|
MD5 | 99167068e0af298682c52bead64a9b84 |
|
BLAKE2b-256 | d4b67d37581f86894cf595d37469aa00e334a242d1c4fce0256a5cf33aa40d27 |
Hashes for stim-1.13.dev1707966721-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a16c777293433d9d3f830f3cccab12dcb3e4cb0eac6390ba5d8e2bdb98c04362 |
|
MD5 | ed8f255d95e7b3de439ed21d589d6b43 |
|
BLAKE2b-256 | 3e67efbd01a67db8cc0f03d5365079a976b151f592d76ed84dd23bee07aac305 |
Hashes for stim-1.13.dev1707966721-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8b541ce2b92a044e7a2ff966df3e913c4f978d4c2b29eaa483079361921fd73 |
|
MD5 | 9814e94b153eb95c91683927adcf8a02 |
|
BLAKE2b-256 | dcb8971c299e9a7366baf145080ad60718f8a69f85ba0f711ccbe051366a9ac1 |
Hashes for stim-1.13.dev1707966721-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90d30959b338eaf2e6c9885f69916690fede79cdd8b9b0322121754d92a5ede9 |
|
MD5 | 92b99f0c8ff5e162063270e4ef802113 |
|
BLAKE2b-256 | cce1f6bf6eff2f388a711849e470832ab6dff8422b83be3a1e2862fd56985b9e |
Hashes for stim-1.13.dev1707966721-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ca4aecab7913ec9b9b9e05c453e3c67b2bbdf80fb25339454cf533a83d18945 |
|
MD5 | 3c930c878b06ea342a128d10178d605b |
|
BLAKE2b-256 | 60d4ddf7dd07125aaeb2304be995213b14aa3dc28ebeef9a09a68264324e6578 |
Hashes for stim-1.13.dev1707966721-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9250be063dc3d57d52efe98ade5e206c99915c2ac4b349eba97379b876e72b4 |
|
MD5 | 7b7e1701c66b20b81727826ca2120e51 |
|
BLAKE2b-256 | 0c50fda9ef62a0aa382a109c8d707e79961b4a149bcff496cec6da890a34e5d6 |
Hashes for stim-1.13.dev1707966721-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fd9047f280a96bcd1dd48d24a3636e35e8d52ee3407cb19cf450f4a7503b662 |
|
MD5 | 98c0a73fae05d2f93ea3dc3ccb73d1cd |
|
BLAKE2b-256 | a8e850db22388bf4fcefb6a8886b29a4ce9851ff8b332e78c14371322e1adc43 |
Hashes for stim-1.13.dev1707966721-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3ef804cd7c3755e89e57866ca0fc8b6f2c9969b839d0044e0184d490cd39267 |
|
MD5 | a4647bbc94985032998bd5eb98046de9 |
|
BLAKE2b-256 | c2d70657f89c21b75b88c8e138912261f4610c89561e433ad254018f83457685 |
Hashes for stim-1.13.dev1707966721-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dad66dd6abce27be2b284c5a718bd752bc0841808bb3a3faf89176c4a3c2209c |
|
MD5 | 46d64205dc470f59599e0c8947d093cc |
|
BLAKE2b-256 | 876bba82cd99236efb91c0bf0161f683d746870ab210b71fe5876f6c32463a28 |
Hashes for stim-1.13.dev1707966721-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e578f2450f9b219b0af3c6662e3ec44a697f31d280d2d590e23c0febd38023ff |
|
MD5 | 112d8fb287ec4c967c743b60e5250bb6 |
|
BLAKE2b-256 | 17ea85123b395b24d1e91d11b0ae03317ccaa3afa7328583c89a80011b96296c |
Hashes for stim-1.13.dev1707966721-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67fa6789d6a1372854fe1cf13e6d5e8be499bf67e44abc762864df0e53213f93 |
|
MD5 | e74ec1b7baf73f18bd64f69710eff8a9 |
|
BLAKE2b-256 | fa8afe8f75c1ca7daa5187c379c7ab72824b16d396b71c2108c889595283063d |
Hashes for stim-1.13.dev1707966721-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc0e5eea65ebe14350032e81b8e0f2bd183bbe4b09d932ca8ebb5956b8f8ab0 |
|
MD5 | be7252db0feb15caa50cef13ee8dd4c8 |
|
BLAKE2b-256 | 06fc6041c19c12ac38fdd002f3b7d54a54dadfec080d898ab292cc20890664f5 |
Hashes for stim-1.13.dev1707966721-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d871803284222e13ef06848bd61db91911bae0a72d83d7f13db2513d0751f475 |
|
MD5 | 1d056356f479b87b34c668274ef6e28e |
|
BLAKE2b-256 | e5e58a09236deb482e960578dc70588ffdc0d1848be070c42fb3293ed72b4d17 |
Hashes for stim-1.13.dev1707966721-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea91c592cd4cb282141fae822481839e58bb3193e9bd252967ab9a78c2d9b7a3 |
|
MD5 | e1f036690a8c22fa88779ff6410370f6 |
|
BLAKE2b-256 | 9300e7855e79e387aae7070845f50b138ba8410b3e9cd66c75c38a3a7a758d0b |
Hashes for stim-1.13.dev1707966721-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da716e47fc1684c031eb2f455617baa82397a5ae05da021a462330bb0539ce6 |
|
MD5 | 2e5513bd376468d7ec7e656ce5cf4b93 |
|
BLAKE2b-256 | 4cb82f47c2eaa1bee8839191b7bdc3fe81a3922cd67139524e891329fd1e45fc |
Hashes for stim-1.13.dev1707966721-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f7a948d1678f2eeec086963dc2e82eca0aa823f11b075ec19171de0116add39 |
|
MD5 | 0322225a08bd9a54305a49005f57be61 |
|
BLAKE2b-256 | db0f17b96a7c7b5a9f9c7657eac50fd566baf6c40f1cc1acf39ce525dfbb8e6a |
Hashes for stim-1.13.dev1707966721-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f2982e86b2ed9d9203a9eab0d04161ed7aef7736d77db3b52eac53a24781af |
|
MD5 | e7ebb65b7ce92f3bfabf7720766ae7eb |
|
BLAKE2b-256 | 2f3b80ec1823667a2b87e18671574fc1e81e6a4b8ad0455b5113ce19f607613b |
Hashes for stim-1.13.dev1707966721-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d40f0738f6eac91d5ee1604d2a6c3c4d6e51fa4fed9bdd39a321348995cc63b3 |
|
MD5 | f9736e0d46ce1b0f0e0a4c1492741c4a |
|
BLAKE2b-256 | bf9d3b3a3c8ccecdb5bc473cccb9587d69cc4e97b75a2ca907361cde6b00094e |