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.dev1726902167-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2d044bf841328491d15ec38d7b4536cf1b0ad14d929ac91a8d2eaf07e4faf07 |
|
MD5 | ade2b40f0595df0bdf14826e40329013 |
|
BLAKE2b-256 | cbea93c56e0362521c4db7301f778767ec765cc2b4ce4d80121c080d10525d42 |
Hashes for stim-1.14.dev1726902167-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca3104af9ba8c2a25bde6098765dbb750a197a2098f0f6c98a0a99bc283219b2 |
|
MD5 | d507656dad750f9c8bcab60fa654b034 |
|
BLAKE2b-256 | 34b0af3d77ac9863852d6f418aca452f6765239763a7a45b7923f335a8265da6 |
Hashes for stim-1.14.dev1726902167-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad66897ca504c15465eab7912a9805cecdd99ae3c7c55e8311dbc35d887f1e3 |
|
MD5 | 8efa512802510ea45fb6bd0218c32cc1 |
|
BLAKE2b-256 | 3c4758ff14a8be5f4d54207ee4c9b66f5286bb7f98c204f2a850a3dc7f0befb3 |
Hashes for stim-1.14.dev1726902167-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b45ef75725f6f4d6ef3974755afd721e7b73872417f06c30130dba236d2dc0ee |
|
MD5 | 14b9172e8cd0743e7260c1536dd869a0 |
|
BLAKE2b-256 | 1b75f2a4dd45091a7b722dcc1ababac0fa0d1834c4ec31b3c28b58f7ca8848d0 |
Hashes for stim-1.14.dev1726902167-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bce0c859e38a782fda678dc6dc420a037fc5e83d1078d7a3ec3e2255de572d86 |
|
MD5 | 62e9cd7ec3cf9d9606dfee4ca401e280 |
|
BLAKE2b-256 | 6ab87a698047487b70429fb5c828d871b9cc54d3a291fee56e5829ca402d6725 |
Hashes for stim-1.14.dev1726902167-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a09653d71052a15e4d6d010a58e87dd7f4078b079be5beff2a0310cc8ddae9 |
|
MD5 | 7ff007658829762d829a94d5aba079be |
|
BLAKE2b-256 | dd6966f371d8d895d691517eadeee9ee35ac5601ca2ade0d5ce5df5b224d6c3c |
Hashes for stim-1.14.dev1726902167-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 179a0bf40a80e2bd99d2e7a3433b019ef28b8b7e109d1eb03eb9a3b1eb4ddffe |
|
MD5 | 89bb5f67b6f7ae70b4c2cad0879ca818 |
|
BLAKE2b-256 | a8c5b43ef07f7ed25a43d988c69eb13d642762a2f1e83d0df57f7779e94ed416 |
Hashes for stim-1.14.dev1726902167-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc05d50a74217882f9af7a9fff867f9797b15bd76cba5dd402ff009e72e3712 |
|
MD5 | 20b799b08544ffe9591b6a5b6efda981 |
|
BLAKE2b-256 | 71870c55c3b98c6edd77d2e6f846fb5c64ad41978201eeddf85faf1924c402bd |
Hashes for stim-1.14.dev1726902167-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69438dd9ba0eefeaa0bca6322693ee20f0fc9d337ebb66e97f0efad9e7e3c9d7 |
|
MD5 | 9a4bc1075d7f78e661addeb3fb9733dc |
|
BLAKE2b-256 | c4833dc7f6c70120dd8a74fc9b0d0bd1f9eb40aaa503aa8939cb2cd9c9e2ad4f |
Hashes for stim-1.14.dev1726902167-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87cfe798429fe578413739bcec9e164ab601819522ecc6923eb54c83d1e9e113 |
|
MD5 | bee6c7d21505755d2c98ea6483ffdf19 |
|
BLAKE2b-256 | 194339d25422157d2c9785e313033da802a4c75f19de710997ca7dffe9965882 |
Hashes for stim-1.14.dev1726902167-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09727ee079e170779558283e99c9ca3511b5ed1c1e9f707e1206d9595df9e1d6 |
|
MD5 | e4787e826d282d47fab77059da45591c |
|
BLAKE2b-256 | 02799252bb857799ea052ea7fc8562c4ab0934a08fb19c3fbab254d9462d4130 |
Hashes for stim-1.14.dev1726902167-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8c911f17ced53feb8b502b65b9f250e800d0cc420e5e78a2acaf1c6f5b54d0 |
|
MD5 | a3cb87bcfd3724345460a824d60b3290 |
|
BLAKE2b-256 | fd0ff5297718d233be6c42b46aadc8d475c2ccccda6a8df8d244eb6f616fc28e |
Hashes for stim-1.14.dev1726902167-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e13d6181eef5cc5737c0ee48d9ada6962bf8d971342972dc024d13296b9e41f7 |
|
MD5 | ef5f24cfdb1cb30fe48ea3d89a5d65a7 |
|
BLAKE2b-256 | 5b919c006d3c35ae4a36de7c367b08f625b84d0964fe8f8bd8d2f580adf83c28 |
Hashes for stim-1.14.dev1726902167-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13af02578ca248b5d511c44087ab551b4b9b0aefe481e3fbdffddc556e3cc0f |
|
MD5 | f37f63309be88959b9e0a70aa1a55841 |
|
BLAKE2b-256 | 5ede1d74f1fd5058ea22bc2ef0210b4856d4e14d2888254741fef5d4978821fa |
Hashes for stim-1.14.dev1726902167-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a96cc800e34273eaa46c257e6ae5405d2bc3cdd5bf25157ca83c36859ad060aa |
|
MD5 | 24030d45f225e10a334b8420b26add41 |
|
BLAKE2b-256 | 48e33523d722daad22f0b0eb79e98dcf63da9dd1cf289627cd8be1580db7b601 |
Hashes for stim-1.14.dev1726902167-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d77e93276639d11f41771f26a0b40fdb59bd1e3ff1fa89c1e40290b130f18e32 |
|
MD5 | 893d4bd84b51bf9cb8ace3e5aca98b6f |
|
BLAKE2b-256 | 3480d63934c8408d3be712c1d78237c1e6af8a3871eb1dc2ca62f0dc8324a988 |
Hashes for stim-1.14.dev1726902167-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d8c234613ce4ef73bd6fdcfe12fbffaa231d357a822405f90f672b93cd7b484 |
|
MD5 | eda159e17931b70ace00812d7b849089 |
|
BLAKE2b-256 | b8a1e1d8ec9eaedb78edcb7e21feaf0165e137db703a8d23143f9153ba70c17e |
Hashes for stim-1.14.dev1726902167-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 312956fbcd93e7efd72abbe502539b8af9367073b2c858f23d5b152c37bc9730 |
|
MD5 | c2cf80c196a060a177e6ebc8d6cc8a1f |
|
BLAKE2b-256 | 9d0b53166b224e3b2e0e074a2083992408dad0e378c2e40778d2a158a28c515a |
Hashes for stim-1.14.dev1726902167-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a21f05927d4f42c17c78b25acfb8a4df381f80bd5ed177cbd6f7c680cb5d5332 |
|
MD5 | 2fa94ad580f994027a9da5e561eaf36c |
|
BLAKE2b-256 | 4f42f80012d8a01caf2c2a6750d91272339e5d66b430cd154abcaeb6532df72b |
Hashes for stim-1.14.dev1726902167-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3174de2241d94ca88cdb643bf191aaa41c2263d1d957c23903d408d8481989d |
|
MD5 | ef17237004ae432ea250ff3aceb89641 |
|
BLAKE2b-256 | 6ec04e83b4fd55f58d4dd054e0663e3c44dbc821dde7afb217b0ee60b5dd1651 |
Hashes for stim-1.14.dev1726902167-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db07e59b146d26f25c2e8bfd8d20d7bdbdf7709c44fbf8f07e2b651e24b21997 |
|
MD5 | 0c36451e558dd7b0767c31407392d681 |
|
BLAKE2b-256 | bfe5913455a1b1641c006d12fd3c5e5af03f1cbf5c5f301bfddec43f407c3e6d |
Hashes for stim-1.14.dev1726902167-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b8090f00b11885949ffcbf461b9ec767e1449f6f34b5036e06177ba7d85b5a |
|
MD5 | df785b19bef509ed5c1d403cc3807afb |
|
BLAKE2b-256 | 833192e9eb19ad612190bc53f5596e812b0176cd041379b72081a349ac76aea0 |
Hashes for stim-1.14.dev1726902167-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43f7e98a5f705a2ca95cb6bb12ff74e4f52c511f8af6cdd398402d5f1fa5a0bd |
|
MD5 | 97f5cb3ec6e7d902ef2ec87b64e234ab |
|
BLAKE2b-256 | ddee205f4155dbd70a2ef681d1c96ccfa619592547f14cd47c0d11c77d37ff7a |
Hashes for stim-1.14.dev1726902167-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b84d73946aa747b23949dd30391c6a6f956721f9cab7c026ce25105a1080781 |
|
MD5 | 6383eea1b72c3669581d7278572a49f6 |
|
BLAKE2b-256 | 9cdf1687ecec4a460886b668bdc249077730e09aa850a4b2d889ca6b58ee5d4c |
Hashes for stim-1.14.dev1726902167-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9acbd73757ac5ad9ba4042ecb822b56b5a71362af7b9a55870eaecaeb29d630 |
|
MD5 | cb64ad9a9522ab5a7c81adf4429c88aa |
|
BLAKE2b-256 | 6d3f68598c9ae9dde4e30b6d1f32bc3f670f68430eba048eb73cecd1694369d8 |
Hashes for stim-1.14.dev1726902167-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c4247104965479d5f6b7279d12eb9484d32eadec1d0a02c44136646b4c5ac50 |
|
MD5 | 70d5691c8a8809ad2449bb66d20968f1 |
|
BLAKE2b-256 | b1dd33747d8228bd0fe14d828f2b1681b76ec6c09ad88fbbc96c9107fbbc24f0 |
Hashes for stim-1.14.dev1726902167-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9f15a08a4b13953d17ddcaee787a16e211602c108ef640f2607c18ab0cc021 |
|
MD5 | 52e4ed73e8c08a36f3d7c11bb40acd79 |
|
BLAKE2b-256 | ab63dac1d1aca79f2460416078eeba1cbee22fd1cccabcfdddf12b4e4b8645c5 |
Hashes for stim-1.14.dev1726902167-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5c65b8478608bcd8de711064b00ea50fbdce870d749f00bd451e524420590c1 |
|
MD5 | cc2c7a43fe7e4a1872036f8dd8215cce |
|
BLAKE2b-256 | 1d4972e6a64d0cee05a229e8013139cd152fd9f32c2099dd3a7ddf86989bbcca |
Hashes for stim-1.14.dev1726902167-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52775ba61d343abf9c34909672c8ca30de771d7b50196bef38932464e194f667 |
|
MD5 | dbbc8c2c031fcd83b19e9f9c5d63c613 |
|
BLAKE2b-256 | cf79a74078a7bba6234b400de82a43b2f1a8fcd768176636bf7397753ae1447c |
Hashes for stim-1.14.dev1726902167-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e594af3db3854a6c62ffba90647c68bb9fd908e126c19e201d0b944e23175a |
|
MD5 | f5d150d5227af7b0dd790b99b71d4dcd |
|
BLAKE2b-256 | 7b5249356dfff4973ee84e66b2c75d55373b4ce3c76967786a562a48a54d41c7 |