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.14.dev1711582216-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cdea193444a5a566f3eaa7d6b8a8ae780c37765ce778bcd7d5f70643347121b |
|
MD5 | 4d6e064b742d5b62df0cca0a26df9888 |
|
BLAKE2b-256 | 6b1e12c4d3dec4c9e7aa610d7379c7f400186342ffa14984940c890f5c753eb9 |
Hashes for stim-1.14.dev1711582216-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9539233e0e10b87be49fafa25b8ecead6788e282650e96d9c06d4a78c6a394 |
|
MD5 | f9db999938dc10652975884c2bd12f8c |
|
BLAKE2b-256 | 0cf8a98fada0870dfd9814537f737ff2b235345f4d2b2956a61250daee52b880 |
Hashes for stim-1.14.dev1711582216-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5750d33932eb8392fbc652c4db1fdffad09ba5508d0d1e188ade542454100358 |
|
MD5 | 3ef391c16b9706251edc6fff631ac141 |
|
BLAKE2b-256 | 7b46ad9e6e6883a2ca876360bbf0f0edefc60c2e73899bb1914a4f85263da8f3 |
Hashes for stim-1.14.dev1711582216-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff659f113b898481cbb4ebabc6a4995ca07bea6a0ba239dfbcf5e11b64dab39 |
|
MD5 | 2fb3bfaac80bb83621a74921f36dde45 |
|
BLAKE2b-256 | 467e116384de8ea311f695ae98859e53a4d18663f47ecd62f1c79f9422b595c2 |
Hashes for stim-1.14.dev1711582216-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57a6b5d0e2912aced79af4ae9a98e7bae35f0fec8f35ac139f73b96e72ac1423 |
|
MD5 | 999e4b59a3af62386dd246bcd0824503 |
|
BLAKE2b-256 | 17e3e060cec96130ad29ce479faa876b6e2790695cf8280ea62cda116ac838e4 |
Hashes for stim-1.14.dev1711582216-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9eb58938a4ff9b274f531200856aa4811bc79026080721e2a8c7fdcd9a25440 |
|
MD5 | e88ef58054f1f304d9439e0ea3185c73 |
|
BLAKE2b-256 | fcaadd25cf0de01ba011cc22e54f2339779dabf5846ce1d036642c10214262ef |
Hashes for stim-1.14.dev1711582216-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c214ae64df564e296a130b1f97d443f8f9f69d6eae59dc4359decc38cb6b30f3 |
|
MD5 | 1699971bc67b9fdb387fbe2dfbd9ac1f |
|
BLAKE2b-256 | 4954f50c79051b63a2b5374af3c3c67d705d7cd3e7ed2c4cd49801499ca91ed8 |
Hashes for stim-1.14.dev1711582216-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2780394b099a5e97a4730d25163eeed72f44b7118b7b7e35214d9eacc5f3ebac |
|
MD5 | 61936f9d153ab0809eafe97386850119 |
|
BLAKE2b-256 | d246610b03e42810ad2ffeba8433607c6db13398d2410509fadac11690e8d590 |
Hashes for stim-1.14.dev1711582216-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96429d5b94da1270bfefe3fd0a7e596931d493d8952d299274157aabb3a612e5 |
|
MD5 | 7d8c0be55ec67a336e56d70b0e0607b8 |
|
BLAKE2b-256 | cc1f1f66021c369d6a441dd24e8f3779a7c584db82fdcf328ab379ef3ef95088 |
Hashes for stim-1.14.dev1711582216-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa98be9ee00c24a374d9aba1542e33e839894c8b42b61c63330bb6212e61325 |
|
MD5 | b3f7a4022ac9c01d5bae0fbe70bd769d |
|
BLAKE2b-256 | 4ec110b6ad5bd1fd4bad2092cbf6e86b66a0fc95194e01162af18513e3319101 |
Hashes for stim-1.14.dev1711582216-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3948056e6f3d7a3b9d27a8ec3bdb2e416993aaaa709d0512f96f44ff8cf1973 |
|
MD5 | 3588f772ed0f5135f8d1341b83fed676 |
|
BLAKE2b-256 | a110b4ba961a7a41bc62177e8fae85cccc581cdc028f43a3587b16e388930849 |
Hashes for stim-1.14.dev1711582216-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 835909080f68f5d4d85066a94c21dfd515a132fb99a70b5620b81cb08417366e |
|
MD5 | c4038c8da74f17ddfdb93eabde91cb18 |
|
BLAKE2b-256 | 8538bd695290b5b64d8359aac5e2fc49be269c25128d8b7903fcb4de063d57d8 |
Hashes for stim-1.14.dev1711582216-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94ce214be2c5f1da83cab957d9de54297e8b278e0c42fcce7020da014c1546b5 |
|
MD5 | eb595066a5524e8c6d608a1739a08984 |
|
BLAKE2b-256 | abdb6bf7f421062578ef10dbaec8789bd53ec638a61800d6c362b117e167281f |
Hashes for stim-1.14.dev1711582216-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04c4b0a2fae8563d17ded8afe7841f5fcee7f3a819449a62f7bba2be8fe896d1 |
|
MD5 | 9fd2f097a6c59f3917d3ad5735d1c5be |
|
BLAKE2b-256 | 62ac49b4d5978ae7385dff6d15bed87042dac8008f6bd8e3e9fada2326f7f12e |
Hashes for stim-1.14.dev1711582216-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38e27daafe7e51ca5687d6f596e7f273c29cfaa4f59a1a1825383322cde8eecf |
|
MD5 | 8fa8f52cc85f7c722aa698b63b03752b |
|
BLAKE2b-256 | 3c1aaf0f7f3e076e2eb14462d9cc56d5411d17dde6552e397b333657c2de0146 |
Hashes for stim-1.14.dev1711582216-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45c3033ed944b4e4823613dbefbc57edb66ed41ac0b2fa08df622c90671b9e9d |
|
MD5 | 656724c754a98b0dc85b8122709d6846 |
|
BLAKE2b-256 | 506229065e88db7bb35c26ec35fb75a95eb7389d511534295e99d9780229e9e5 |
Hashes for stim-1.14.dev1711582216-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 761af873e7d980f9bea89ac64bc69456163d06ffd3d4380beb79ef038d72ad36 |
|
MD5 | d6a1d254813e7cb8c7b527b2b20d7aa2 |
|
BLAKE2b-256 | 43964c6b75674f1440fece901521b9f62d50326043350d70edcd0670e28a24a5 |
Hashes for stim-1.14.dev1711582216-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5d9d170a5d8a6d19b6d19871f46af159d55c2e8681752797a40c40a3f3c4c43 |
|
MD5 | 709222402d34be3567de3dff0bbcddd1 |
|
BLAKE2b-256 | ac2054858d427a913871645eabd4ee304086d9c92cc219d4e393930560119f9d |
Hashes for stim-1.14.dev1711582216-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 834d4856af30b16cf6cfb6cd13dd0e3a7dfbee239db261d0e63402e28e7438a8 |
|
MD5 | 537a842d972f3c23cad5135530cd229b |
|
BLAKE2b-256 | c4a515715a43174f1fc80842e737a822993db78dbc96abaa28574cbe76f282c7 |
Hashes for stim-1.14.dev1711582216-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b79fd6f5a72a4adb353b5b4721ff0d501871de7a2f9d146791367edf7174323 |
|
MD5 | c60c8325b73ec34e8cf4cbc982a10138 |
|
BLAKE2b-256 | 3bced56206fe63413f895088504986ffd1985e11f34002214ba54b9d9d7d9715 |
Hashes for stim-1.14.dev1711582216-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00d8676db264059530e9df03de754b929d7e93fe23be7221ab0c391f73516103 |
|
MD5 | 46bc771ce51696707c83ae4c595f58d5 |
|
BLAKE2b-256 | af29432b63be626d5fd2f8000565674afa38cbb3a7101173ebf51f7449225299 |
Hashes for stim-1.14.dev1711582216-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e99fee696dc0325a974f200dea1bb708fd4c171aab72f424c7b1589c1248458 |
|
MD5 | 8d0e718cfec0aeedb333ee917cb2e249 |
|
BLAKE2b-256 | 78b676264c8a516ba3f5fd5c05cec37d6c07e66c7f0d78f82646ce3c848561c7 |
Hashes for stim-1.14.dev1711582216-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68e34a61e6d5caeced6168a2cc8eeeb9add43fcbd59bbc96e8ee3f8705802d59 |
|
MD5 | 65ac84104a3d2c3f8a911e0cb35ffd59 |
|
BLAKE2b-256 | 0394f52ca8815e5753cf5d35756594e2f7eb351b7d63191140a68fbba75614d7 |
Hashes for stim-1.14.dev1711582216-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d245f6e1c246b4afcf4df6360041186dbafde109ad6832d663387c3b67d918cb |
|
MD5 | 4472396507a5dc99b292eb161721606e |
|
BLAKE2b-256 | e6aeede732e0978303cb0c6fef84e0c71f2d8fac1b2f1060431ffc69e243e09e |
Hashes for stim-1.14.dev1711582216-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a01dec316f5970be83ab78ff3497fc46d43cc95571ffb5b5c0fffc07ab95e6e |
|
MD5 | 6e7e4c5e75067d28609d8f7245b14698 |
|
BLAKE2b-256 | 144ade04661aa4865b98de4534c61e3f118204dc90caacbf67c981bf43fb94de |
Hashes for stim-1.14.dev1711582216-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75061d798405325ddc17c4c46f74c6567e2c41af693395f5fdf8c0efcd07fb1 |
|
MD5 | 23dd343d5538b5ef68da725c7bc12829 |
|
BLAKE2b-256 | 2fb152d5e7786cd60a2589e25f715e57b80a0f96b277952ba8fcf18b49dc9447 |
Hashes for stim-1.14.dev1711582216-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95d07186c3d7eb1f752e41b01fa3cb72ee4abad3757ab53fb14879bf5c60dff6 |
|
MD5 | 6f171d3944f5a6fc6ec8b281a556e6ea |
|
BLAKE2b-256 | 9d9b9bc509ffd41343aae4ebf2e44b3dbdba0bfadaf9871df97fb96ce5898e3c |
Hashes for stim-1.14.dev1711582216-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f0a7cfa3ed48da485dbeed933b09593b5d2ba1db97f8cc1c7d85a73d277c81e |
|
MD5 | a686e4e19a26139206cb925ae6486a8a |
|
BLAKE2b-256 | be4fb3caab19d015984c1256a5d77658379134cd7cda5208da30b86ff4d9b739 |
Hashes for stim-1.14.dev1711582216-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ec0c6b471e45c312c8c0bce52cade72e16be8f22a0f3fd4ec23e6425d7da74 |
|
MD5 | 291dc89f1a6e3e7cefa2fffce3faa5d8 |
|
BLAKE2b-256 | 97bad084cbd69b08be1049fcee05655f40a4d389980bcdf2fc618f59056218df |
Hashes for stim-1.14.dev1711582216-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01df660c124b9255de4fcfe29e74dbd4f4b5aaa16bb1210f4b040ac51f0c4cff |
|
MD5 | 8bbdab9e379e163f3ab2a98937fe2af9 |
|
BLAKE2b-256 | 1285d379e407953c997ee7d28b1ab1ed69d5fbafa51fd38f6f59802f5409ab66 |