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.dev1727163064-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6ac4d21a8259d34b7fd8336f2ec6eec740918357a273660e8fe42c48df0ea5 |
|
MD5 | 185fe30d6d870bd7838914ffbd53f665 |
|
BLAKE2b-256 | c87acb75357974779cab639c2090478aed18d95f09c1e31b609bdc2843b36af1 |
Hashes for stim-1.14.dev1727163064-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f93d64dd7430e8059da120b73182d706f43a7f195ec37c9ddc42fdc95110ac28 |
|
MD5 | 89b60697d62c57c6d97f324f93fefef6 |
|
BLAKE2b-256 | b01d555af463d0fc83e20be546106f154ca95b57d5820b9b7aa4dec95e0a1d38 |
Hashes for stim-1.14.dev1727163064-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a125bb6fa953c8e2b8442b27b73fa0cbedf8335f8b789cf5018dfebdacea8bb |
|
MD5 | d144cbc7a5d970192724ed3b70bdfdc7 |
|
BLAKE2b-256 | baee8f066fb62bb1a9f1b4698879324e8f0cc1e2b42e11ee5cde5b6524ea120f |
Hashes for stim-1.14.dev1727163064-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10cf98fa23073f0a6e6663924b8267f5e49a71db820694a590d4351fc348a16b |
|
MD5 | 05fc97bd7d1afd8019c61191d38f6302 |
|
BLAKE2b-256 | 8c142f86dd3256f6a29aa55be18f809d118fa180cc7010dea0699465ba24c025 |
Hashes for stim-1.14.dev1727163064-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d176e593184b581d0f8ee08d5a5451ee4f97b60f729101ecf0ee7f6273a8f6ec |
|
MD5 | c42c81bd655fccbda9af4b47aaf228a6 |
|
BLAKE2b-256 | 434e2a45c1469bc3419a67f4cca225d9262e17acfe653ddd94a2a84cbe8449f6 |
Hashes for stim-1.14.dev1727163064-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af1cd4b8d194211f5e169d3d0bb377a81fe8bb17f2d096579b2f26c326a4b2e |
|
MD5 | 56d6551a6f47592617f1a2d873523784 |
|
BLAKE2b-256 | 4441005b11fb5f515b6b43e6f34927ca346e79d2600c06956bb91f18a55ff3a3 |
Hashes for stim-1.14.dev1727163064-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6de16471295e99d5ced7ebc6946c55265253904063386ef83918ac3d357f8ee |
|
MD5 | d9b08416228adaebc6bc02435a32fe12 |
|
BLAKE2b-256 | 9935ee57e1a1ff1df2e355a1687856aef762a3b074170423cbef719e21ad1cd0 |
Hashes for stim-1.14.dev1727163064-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7244c181d1bc4acd4ee7706e2b1c6f0891dee13a9b19491ab869b981ab9931e9 |
|
MD5 | abc218ceb41f2ece9b006f09cdf6d34b |
|
BLAKE2b-256 | b46c7780044023a851272505a35b7d16b0c36c8600661062a9939b66cfd54de4 |
Hashes for stim-1.14.dev1727163064-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5875db0cb77cedaec7e1b958262a9d99014a9a8ff2cb663d651e367d0d212fd9 |
|
MD5 | 1fa120310191fb0819e0ae9b09363f0c |
|
BLAKE2b-256 | 4b6bbd2be426297c872e4136c326bb8009cf4d925a2b486984fff82d3f0cf1f7 |
Hashes for stim-1.14.dev1727163064-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 157d3c3586c221033cb879123ce674bdf289b14100f6321346d552265ff6c259 |
|
MD5 | 729e5d156ad25bd230a65d480b8b96db |
|
BLAKE2b-256 | d50fff056a07e9044c65a0b55ea966a786d393754098e43a22e4d30e5b063d9f |
Hashes for stim-1.14.dev1727163064-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f806572cd979f1d5c31db62976e67e7d14b320f1305e68142156de993119bd0c |
|
MD5 | 60b301b7887946464030e5d187aa52dc |
|
BLAKE2b-256 | 68225af5e8791218473ac501dc4429a12b54280d0c68867e9526f8ff19a85af9 |
Hashes for stim-1.14.dev1727163064-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e46e56329ae8acb7b76defc4879a66f6eadf363c1119cadc3efa20da8fe3855 |
|
MD5 | a71f10c5f6df99ac5fab25cc18fcee68 |
|
BLAKE2b-256 | 6b4e6e2e552bf8f1498ff7d4d53af18832bbf470171b47a9e4affa9f2d6f82e6 |
Hashes for stim-1.14.dev1727163064-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1243d16be9c05537b9605623aa12c7ebe1bb59947bebe52f0007dbd826d2bd64 |
|
MD5 | 8452d5611af3dbeca0452e049b8a447a |
|
BLAKE2b-256 | da5a41b40b0dabaecb4b4c885dbd827191d259de24ec6d302f97fb8a91eb4ed1 |
Hashes for stim-1.14.dev1727163064-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac19f2382a3cbcb9e60a24eb38c65eb7e5406c2820ac968659a5780b8e01816a |
|
MD5 | ec2c7c6548df30bdb59f11c299fedfad |
|
BLAKE2b-256 | c6b0678aa4048d1274268852d2ebd670cdff110301dc34cf362d876387247570 |
Hashes for stim-1.14.dev1727163064-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 257988ddf25dc3602419d20b92f3861e1ab0634d3ef2bbbcb7382a00a69a0a00 |
|
MD5 | c8df70b1007d3fa7129736e48528e7a8 |
|
BLAKE2b-256 | 21c74a5b987beaef643ef55fdcd757afa15cb77a13f85db6197a33fede9d1d75 |
Hashes for stim-1.14.dev1727163064-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e64cf1b9b3b2552cfc8c645a92b8bd16d119ee86581e969a7e5757219127467 |
|
MD5 | cdefd09386e6a048e26de12801429ebe |
|
BLAKE2b-256 | 93b498ec784b53e51f5c17e3ef85184405d3b076f006e2956f436a9165710a3c |
Hashes for stim-1.14.dev1727163064-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1695f96e5d2c23f65a383b30b791e05dee5b201f57b587c2c7e8607efa4949b2 |
|
MD5 | 2c51aaa20b3db089636ed232feff2f66 |
|
BLAKE2b-256 | c4c66d7b3cc11b788792d39a540d5beb9514d9465add403af918c37c9bd7c0c4 |
Hashes for stim-1.14.dev1727163064-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f8b4010e3af1c54e0153ac929c1ba02c3beea35bf7f581cdb1061eae6a6cc4c |
|
MD5 | 365ac7f0bd1b29ec44f8321c43fdaac1 |
|
BLAKE2b-256 | cb3e850f8b3df07ab7f60f453879ab2092c1d28c2f43abb9e77de6ac6b7b6709 |
Hashes for stim-1.14.dev1727163064-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a850f82569e615f661271e48e855eafda350d73f0d5bf03f4bcc19e4e33b8b9 |
|
MD5 | ae07ce3d4318f28bc1bf8f254be2de85 |
|
BLAKE2b-256 | 279462b7956ba73faa7b547ed73bb6528a68d29550f95ba3eb01d47b3ef36eb7 |
Hashes for stim-1.14.dev1727163064-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b55b9f4c1237a1094792a157ed457885b1ea1c4860b71ac85bbea1b084db30a |
|
MD5 | d2d74ae55ea6c5bf876035d06a9769f0 |
|
BLAKE2b-256 | 0d7fb60a039fc23da31b61ff845128f823bbf32b072a02a136579db83a27cccb |
Hashes for stim-1.14.dev1727163064-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7d47fd2b45acc09dfd873c42f58ee6790cde2d88cdcc3016695ae231fcb7c65 |
|
MD5 | d884985849fd175ab2f8a162b6d7044c |
|
BLAKE2b-256 | 6b71c51e9058f54358fef5b8c97ec9b460eb828f52d0fdd7ec5dcf56b66e2acc |
Hashes for stim-1.14.dev1727163064-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af123968470accfb056a15e80e05bd81c4666103309f5e3498f7b16e3147a6fd |
|
MD5 | b59af827a14993e80ca95fc984773c08 |
|
BLAKE2b-256 | 5b7858b644bf45514a59b9c06ae559acf67f058951587023bf495a403caadafc |
Hashes for stim-1.14.dev1727163064-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4899d7e1cf2a23f30c02ff44cf430316538cd6da93604d1488ec718d194e558 |
|
MD5 | 230e4d09960074767d6626700553ca2e |
|
BLAKE2b-256 | cfce937812663ae4966a1f3d7928492b25527fb72084708424d81ffa6a2e312f |
Hashes for stim-1.14.dev1727163064-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d59e5674b3bd5054f9c92eaaf68d0428a6276127be54b4f36c65a46992bc70f3 |
|
MD5 | 0c1036d60ea8f15f82ca6dcc64bf772c |
|
BLAKE2b-256 | be4dbc9ffd613ac975efdb5e54207461d48f81f9bdc2f220319a3c0f11d535b4 |
Hashes for stim-1.14.dev1727163064-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbaa88d20bf4640a9a87040d373f7334a0cb0a1568521117f5232de094ddcd2 |
|
MD5 | 5b8b5a4b3aa457b2a33ae4d471246303 |
|
BLAKE2b-256 | 386c58e66e321e0ac9498ed49e23e5ceab3f86b58ae1d0b640d7fac2d10c798b |
Hashes for stim-1.14.dev1727163064-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1bab1780ffc9426938d9231549de57f51727bf313741e8639eefa48b43cb6d2 |
|
MD5 | a9cfefed43f5be772c5cce1922003f47 |
|
BLAKE2b-256 | df0ab5aec537a186e5840cb4edc87959a54150939307aa52bb81fbd03ee3881c |
Hashes for stim-1.14.dev1727163064-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd4bf5158f8f1a3c52759857c65cf716cf2d8c33a247698475248d99d0d172c |
|
MD5 | 3491fcd22f96069bb2357beb73749813 |
|
BLAKE2b-256 | ff5debd14400fcdb7713affc0717a9af8a247b1556db5c2d0bf1b4005cf76ae8 |
Hashes for stim-1.14.dev1727163064-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c35f0ce4fa92a8e4dad89e5d7a04a9bad639ca40aa691e06a1708a78192d6fb |
|
MD5 | fa861a46391cbd55cd95b6b9d36bb70b |
|
BLAKE2b-256 | f43567df41357e74550aeb504f62e354e875c196f5d884f5e656f62d2d822ed5 |
Hashes for stim-1.14.dev1727163064-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06fcc9a227d95151acbee845df4a558722a828452aaff705ea00928dbb72775c |
|
MD5 | 51db01feafdc0d95181b9c7a27ed7e3f |
|
BLAKE2b-256 | 54c6bd0aab340942c3fc3818a2da44f42395e1b182461520a1894d9c6203913b |
Hashes for stim-1.14.dev1727163064-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 769535fff12f481777e0aab3c4308b915a56b06eaf5e080538266a2434a7421e |
|
MD5 | 03a367579473395736d79673bb4a9bd6 |
|
BLAKE2b-256 | 6ab16274a4879bcc82e8619fdb84cddf18826025503b73be2d0cfa340cfa44c2 |