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.dev1687218935-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2e6d8bba1f8e8dedc070cdaae5c57dc2631bf9f1a909f15c7760a87c787f0d0 |
|
MD5 | c355b5cf1912d074f46a1878175d3c78 |
|
BLAKE2b-256 | 0d10ade6ec02686764fc25f139944c4552a0e3769040d5d014c5dccace0028d4 |
Hashes for stim-1.12.dev1687218935-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a71bf356ebdac8c4e885ca8673ce5fea5d0f5034d14057e8da20aa7db569d40 |
|
MD5 | b56a81d58a66e9869050cb62d7cbd7eb |
|
BLAKE2b-256 | 8f46f07e37beda83a32692699eaba8d09ca8979c0500b66e2fb9e8086e4a9259 |
Hashes for stim-1.12.dev1687218935-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 213055f8aa76cb469cb422e1e14403cf7bb114bbfdce6a509dd77f095bb24d01 |
|
MD5 | 104523080b9a53d618d0377d1a08722a |
|
BLAKE2b-256 | a602ed5c4c1e040adf26099d5bcb84aa0cf20aad3885b0dc1c7522be34ebd4e8 |
Hashes for stim-1.12.dev1687218935-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9353c5099ff4dc206872c3e9460f6c6cfc1cae89d7fed001302dc20f0ea5b66f |
|
MD5 | 7412c6d998044be04083df4d24775fef |
|
BLAKE2b-256 | 6ecfd181161e3df7d9903843ebe2f2a22e66661cbd12121b04d55808161022f5 |
Hashes for stim-1.12.dev1687218935-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 961fc162cc6ced9e16c42f20140c968392f7b9e88cc6ecef93b4b1c995258dfa |
|
MD5 | a3101bb7a55bd141e89de674ebd2e57e |
|
BLAKE2b-256 | 8fd20a0086dcb959936d83b659e9e768968c405913e53bca668ff8868968a689 |
Hashes for stim-1.12.dev1687218935-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97f7c2358b9b6d7de750deff97c09bad64416ef8eeafd62813121d7e4f731f8 |
|
MD5 | aba806e743a3e840d6083fdafcbebbe1 |
|
BLAKE2b-256 | 3110010fc06428a5dcade6559245e755dcfc0767baa8e36eeb976cd9d7c730cb |
Hashes for stim-1.12.dev1687218935-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1168fe0cd87f42701c63c4beafd2538b74f8b6c89b8370466352d66f71d49192 |
|
MD5 | 0f906b6cf766ad942c4897cbc090144d |
|
BLAKE2b-256 | 087c6490d40496ac2664e2609b603fd8eeb2eb9580397e0457e4034622e0d010 |
Hashes for stim-1.12.dev1687218935-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba506dd528a2d89e7b0d2b9667a8a9683d4f7802c624a3c2d3f41dbf240fcfe5 |
|
MD5 | 804cff8e59885d49cd8db95b03ce6500 |
|
BLAKE2b-256 | 7ac6754c00f4b69a66ac0f92116e2fd6d854cb1f74926d7149298f48c3c43989 |
Hashes for stim-1.12.dev1687218935-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 403a34bb0820507ce86b6694c8721e8220d58c16163a3fae59193f3bf9e53148 |
|
MD5 | c42e0b82208e6416ed4c4ffea20d4405 |
|
BLAKE2b-256 | 0f1e88efe581335f05240198ad9429e37af8b3d0c1205bb51a1073ccfc1e4293 |
Hashes for stim-1.12.dev1687218935-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c05084df89f40bfeb799a5e042a4a20e64d3680a7440ada562f167b7c400fc |
|
MD5 | 116f585334f25aca60bc9047c78949a9 |
|
BLAKE2b-256 | 107ac308e7a1ac5704ddca5729192eb560678a99aa37ed73d3f4a97a7510bfa7 |
Hashes for stim-1.12.dev1687218935-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1264007eff1b304e5c8ea36208166eab4e612da6583d494e34847dd24443f1f2 |
|
MD5 | f68604a3cb5527cd45e7e460822a0323 |
|
BLAKE2b-256 | 9643d20b46724ec8e0357eae93cda62ce8d058019b3cc2ca1257bd9f0a706cc2 |
Hashes for stim-1.12.dev1687218935-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a945ea999c44be14b21cf39627e064ede16da2af50de134749bd804907ae456 |
|
MD5 | ae62776115659d2fd7e77c0ed35101eb |
|
BLAKE2b-256 | ff0bf1ac618649c77a9e9f5050378d25f98f6933d9b0d94f196bc7dda1c828cc |
Hashes for stim-1.12.dev1687218935-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a92546d2077701c3669bbebc57f2d6ff449696a1322706c110cacc16dae0064 |
|
MD5 | 625c609c09836cca28fadd9b046f9250 |
|
BLAKE2b-256 | f527580280a80cf02ad85e7970da0214c17ea3f7c043466b7a73155211955246 |
Hashes for stim-1.12.dev1687218935-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 694a02b2196731619e9f017cd558531c58b9b13cbb662d45c010e4fd52990b36 |
|
MD5 | f9f3d4d322a5319ef76bc014dceb11a4 |
|
BLAKE2b-256 | 1bcd5bebe06d14b552b0390e4557b2c143f8506270cc3609ccd2ef0c3999b02a |
Hashes for stim-1.12.dev1687218935-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35dd113a712a7ed1d5c292d5ea72e878131de5dffcb05b3c849bbeb6a9a4d4dc |
|
MD5 | a6efe6e1c37902c996e8841cea206cd8 |
|
BLAKE2b-256 | f132349c5f4b04d4eb361a8be73f8504e2be20a075ddf02ba12320e897de8a05 |
Hashes for stim-1.12.dev1687218935-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37042242722acc264d66e3e6ab98a4b8edd45778727d16487774fff6070dd04d |
|
MD5 | 45cea94fc2258ffafbe74d9441378f9b |
|
BLAKE2b-256 | 45a19b205e0e297e3384259fa5cd31b5fabc2c54ab7139431a1fb3f433ae9b9f |
Hashes for stim-1.12.dev1687218935-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5ac17fb636591560518e8e6b3451cad03e4c65327496fb7b0ed17f44ba85c03 |
|
MD5 | bd60dfe13464b85615dbdf8a35cc5768 |
|
BLAKE2b-256 | 5d5d8f9df5c2e3dc7ba3af3b5d17f54518e3bfa7ff711e980260023821469711 |
Hashes for stim-1.12.dev1687218935-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e85afc096e695156cb601decb74a4d6dbbd523437b1956551108d3505c92fce |
|
MD5 | bffe2582613fa24b7637a79f71ffd587 |
|
BLAKE2b-256 | f44dec0f793eec7a89739221628ed76468dfa28cc7620490dec3edfdb026fdc3 |
Hashes for stim-1.12.dev1687218935-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98c6f24d9f2e1d3bb7dde6beca4a7e52f77e28d43f73acafa7fc5c69c5b216b0 |
|
MD5 | ac670e4f57936a6af70de9e875f1d247 |
|
BLAKE2b-256 | f5004f807bc8b02f10b7ac65c8b9caf1659f22b733527339a02c6a0203697160 |
Hashes for stim-1.12.dev1687218935-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e362c2de20c86b7321cc2af9105810578c205d59fd96caad357419aeb8b89553 |
|
MD5 | d749eac4c1dc6d0991fcb24fd54ca28a |
|
BLAKE2b-256 | b2b828117ea90d0284c782293a0ec4e80dad8fbd4ab46dbeae68f5e85560960c |
Hashes for stim-1.12.dev1687218935-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d4e4a607f7473b0077240832f4e0d178803fee9f3bb7034004e1c4bf4f3fb20 |
|
MD5 | a99d9fca0e14e81cc95612d6d67549a7 |
|
BLAKE2b-256 | dafbd635794e048ee625e0a72022aca0e74ec2d7e729982bad70990d4ffcfa31 |
Hashes for stim-1.12.dev1687218935-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 064cac4c05759b7a2b48022d45d077e06b6e204587584c1f9f699e254cc0ca6c |
|
MD5 | a35618474371b8b31f24339ce0656816 |
|
BLAKE2b-256 | 1c373182f5e9f0587c0183b51fd8ffd68f07c82971cc858adb3820ebc19f6fa4 |
Hashes for stim-1.12.dev1687218935-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07825d6827807e87bfc9bb43a552f30df739f611f10ec886b302bc068e76d693 |
|
MD5 | 0744815f9d7d096bc96cc1302d4cee8c |
|
BLAKE2b-256 | 5bef5c4d216d11ef7327e749fbe489d7d58f84e84090f91c2a7b9468e4ecde33 |
Hashes for stim-1.12.dev1687218935-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 606ac0f19cc5a71498506418fbffb87e089acd051e18c46bc07753cbc8a7dab9 |
|
MD5 | d890f7c56aad1df8fc8f527cccf81754 |
|
BLAKE2b-256 | 09f75d19e691f41c1601c5124ba64580b3c370de0357e0a34d8e673933a406b1 |
Hashes for stim-1.12.dev1687218935-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e56b5a34bb5c861902d491cfcfe7f8e59c4f0ffa50ea99416450b9f7c89f971 |
|
MD5 | 8803f1ac1cb64f133cb1ea83d5d813fc |
|
BLAKE2b-256 | 7705bc21c02f7c3ae3024afc06a91abb39ff4f032e3da5bbe1aacc4d2ad6f2a8 |
Hashes for stim-1.12.dev1687218935-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dede46770c69033262361968395982ba099c11cf492bc107fca78bf5a33f679c |
|
MD5 | 553fdb084961e0d6a31d46babf169780 |
|
BLAKE2b-256 | 63c76466f6b5a4e0481cbcb2e8593251db8aed39265a367419140733027d083a |