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.dev1726900525-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 604f135f0e2eb50bbc26f354d5f703932effa9877fd52d431e4943a2ce699e48 |
|
MD5 | 5cbb10db8b581527091c773d90107df7 |
|
BLAKE2b-256 | 0b7b856920dbd5f505f59e59a0ea25c6c8d8a971fe70227b7770c9d3a613dd89 |
Hashes for stim-1.14.dev1726900525-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bcf4d6b728eadb1b0182e55fe85657f0f0ec000e55a890b5617917305672fa7 |
|
MD5 | 69f457c801d7080594363905abe677f5 |
|
BLAKE2b-256 | f40e5da31364e1bb457da5ef40ac77dbcebc019174a467f0b35c22c06f7df92b |
Hashes for stim-1.14.dev1726900525-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35a3afd6f124264bd3b79f3496052b34bff752638e00c67fcc20487bf1462c2b |
|
MD5 | 90a2f83626bf76d4bb8bc5e6229c4b86 |
|
BLAKE2b-256 | 902cd27bf2e3e1176618cf684a6253f60d72c95cd04634eac67178a1939d11ad |
Hashes for stim-1.14.dev1726900525-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eaf56bd1a052dd2ad67294b55ba163f113693d62c978628e337e4f5deee1969 |
|
MD5 | 97ea9a603de222d84b0371cb91183b06 |
|
BLAKE2b-256 | 96c51a8bb3878f538bad5d78a4da46db7356caf5a5db2b20efb1f9c093b659dd |
Hashes for stim-1.14.dev1726900525-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9565c4b0aa9887093bf05fdbc6ce1768222c34c3518700aa25a4d69da178cce2 |
|
MD5 | 493fddcc08885e62aedaedc13ed205f4 |
|
BLAKE2b-256 | 013f9c1fcaee1cd165b24c0903983d71ec704f66a4b5a1da6617d26e10772621 |
Hashes for stim-1.14.dev1726900525-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ea80844a8793340475883aa1327145fb16b2456b36ae84bd322f15a8dae0ca7 |
|
MD5 | 5e13143f199485a3cb621e2bbfec4da3 |
|
BLAKE2b-256 | 438f64271e2afcc5eaf9c84d06b0a40ed6ec81a2766b8aba1ba999633c420736 |
Hashes for stim-1.14.dev1726900525-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02056535e8156f7a36f184b1ff5b25ca491d13f42f72d41fbef9ff2a768db3b2 |
|
MD5 | d0111c175b101a25600d78da66356e90 |
|
BLAKE2b-256 | 24e04bc1c99120dc24ae13f3f3973245165bf5e5b4c63e5b438c23f5280cff60 |
Hashes for stim-1.14.dev1726900525-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82548472bbe45103e3d3364cab2a54e8a14903515f979b53c68c77b61eeb38d |
|
MD5 | d2a0cdf9efc50dc848e2006bc72e6fd2 |
|
BLAKE2b-256 | 6af67489d223489511ef8243af66f923636069db52bd60ca869d6452885a3b0f |
Hashes for stim-1.14.dev1726900525-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61c1f38ea54e890308d4ea6d1179566207b53ffbf1f34560149a289547db6fb7 |
|
MD5 | 4fe11b807e55c3c7ff78d7a617b904c4 |
|
BLAKE2b-256 | e694dfd269e3a349886cc18cfb3b07c90abb4b0668188faf04c1c40b5316eb48 |
Hashes for stim-1.14.dev1726900525-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86f4757fd19865559f5471bff2499afad1c506bbecfdb327d030c4eed288a6c5 |
|
MD5 | 44f6fa072acf081a0a463c199273f8fc |
|
BLAKE2b-256 | b9322fc58c1de3a074dce118eded4a411ec813331ef4cae160dc35077aa9a617 |
Hashes for stim-1.14.dev1726900525-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 119336d236eb1f459728319d1c38ab1754b0afdbb44245b38bd7d99c22e04d3e |
|
MD5 | a3f1efce7b19e76c57c99c20799393cd |
|
BLAKE2b-256 | 9ef2a3d979892bb0aef9a53af134304df0af687edbf6a3cc0d8844e246ab40f2 |
Hashes for stim-1.14.dev1726900525-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c94be9e8d9be3528d07f1e22bea0be772bca15813545dab460e22cc35217f492 |
|
MD5 | f9b7e5d6384e6959d6a33345908ec446 |
|
BLAKE2b-256 | a31b16bd95b5c0af869e63f36afe084eabb3bc8289c0140f7e6a2bcf5150fa41 |
Hashes for stim-1.14.dev1726900525-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6cd655a72ad01a262a5b2e3d1a2fdade09da756a22879feb6751082f2ed4d92 |
|
MD5 | a8b35d87ff6fbaee11aca6d735213d1a |
|
BLAKE2b-256 | a0890b000084111be52e53879a331cd87b2ee6fdb5f29e85ee65f882528c0297 |
Hashes for stim-1.14.dev1726900525-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145041dcf3c37b7fc868855479bf81f079c089e238e42cd2c275cbdebaf1ccbe |
|
MD5 | 62d96ce26f5ef1b4d603e64ad3780992 |
|
BLAKE2b-256 | accdb2483886399ffb78a62a486aa3c62f5f09bce32cbd4565638a88199e9af6 |
Hashes for stim-1.14.dev1726900525-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7715ce937c3e274dfc81c7d7bc3dff85e80c779bc6b82e946d118cf0b2115613 |
|
MD5 | f5a039dab3d0a6a48f224951be379529 |
|
BLAKE2b-256 | 4adcf0206a4e2cbaad74c0b3736ce7efe90094361730200299af792cb3c177d4 |
Hashes for stim-1.14.dev1726900525-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f796b8dab2a08858659b57de2c066ea044ff5382737dbd8bc5f64b4cb94ed16 |
|
MD5 | 67ef92aa322afbd65ca98b67f8fc0b5c |
|
BLAKE2b-256 | 2660a0a7b8542ddb5eb653a7af11162b7a9576d8d7bb59b511f559ef17363255 |
Hashes for stim-1.14.dev1726900525-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a992dd567f3f28b862e7cfcf4087ff78fb8f708aa21d5e11127bedf5e378eb09 |
|
MD5 | 835bbba06fa34bd7681e346cdef6b0bb |
|
BLAKE2b-256 | 18c650a55e8ba57ad2a2bf5e4e63ddf715dbcf8019f9b66f0e3b95d406f1c6a6 |
Hashes for stim-1.14.dev1726900525-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 573c6a7b74e14807c949b1e464a2b59fbe458fe1cb81206b7124a1ccbef937f0 |
|
MD5 | 5724a11ef36dd01ffdb2479b6c19945b |
|
BLAKE2b-256 | 453b77bcc0cc33e2887e483581c488bcc5f66c4c9e4e93a28e20738a7d7aaf4e |
Hashes for stim-1.14.dev1726900525-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8b1a55dddba2a7d3039f588b10112454d23e1d24cab9b801b0db18391dd0bef |
|
MD5 | 70bbad033facd04e9806fc46c4ca643a |
|
BLAKE2b-256 | a15b82caca427e37c1ed0a0ee59cf43edc84ec90c4d7526a6bc401c5a6ce34c1 |
Hashes for stim-1.14.dev1726900525-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee2ddd1c2828a5ea72a9d284c01ac8b16ec901856bfebd4b9ee153646aca00d |
|
MD5 | e6f658afd530a01c5796a7a2ee1a6403 |
|
BLAKE2b-256 | afde64eda7c08606c047674b54950b1fc7590bff856a2a854b0eb970dd69d813 |
Hashes for stim-1.14.dev1726900525-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a253902f74eb1853d6f092ae8166b4794e9f5fa95559f3289ba050728002db68 |
|
MD5 | abbfdb3c2a71858b3460fe7daaea2603 |
|
BLAKE2b-256 | 5ccd04d11f22eec12593423f5510cd90d1b5d3ae67dfc9ca81adb4cb968f32bb |
Hashes for stim-1.14.dev1726900525-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de68dfd9399c1d3f5ad2d822caa1751c5fd373ea4a46c7811ca30ad20d489d0a |
|
MD5 | 035f5acbe7d86c346553a60106f07fb2 |
|
BLAKE2b-256 | 2f9972a288c7eaf80b95f00c0e445dc10088cce7f6a995e879929244e2697dac |
Hashes for stim-1.14.dev1726900525-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f1704fbfc813efa0aadec71c673f20d5d1916398e9b1a31b7616e385e44839 |
|
MD5 | 16080845b3e02d39cf525b4989b21037 |
|
BLAKE2b-256 | 90fa0b81405e3b2d6ff0ad55d3db11fa56429eb4326a80adf7d96041928800e1 |
Hashes for stim-1.14.dev1726900525-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c074c45116bdd551034771aaf739a4d5a98f21b670ad30b78194fe66a8f73dc |
|
MD5 | 50fa30e28b311dca844b9dc1164d3707 |
|
BLAKE2b-256 | 38394f9cf54ec3ecdc863685306fb171ebcf6272073e8aed8d43257b532cdaf6 |
Hashes for stim-1.14.dev1726900525-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3006f5e73c652c82b5ad3ebbbdfb36e26cf4f906f2d73f4aa16e49110bb27174 |
|
MD5 | 48c0ac280614a627d9fe614455d72afc |
|
BLAKE2b-256 | 64d472795c5090ea97bceac6b9e1534ac19db9f89dd9927e6c78b0fbe25d4438 |
Hashes for stim-1.14.dev1726900525-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf962657cf3249f5da34c4b4f06cdcf5da430d6db437446e6a0c61776a21ba4d |
|
MD5 | 38261927dcc84d98e9caaf47e60ba590 |
|
BLAKE2b-256 | 2ddabf6d0a49b4cc176fe4dba5bde8c1f759b74ba8cd1d771ae6bc8f43534f49 |
Hashes for stim-1.14.dev1726900525-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c8a76e39e3943d05bdae511c9cf429fea44fa1e2a18555a72b9d7dcc1e9716 |
|
MD5 | 66d964b4501cb2a1ded522fdbc86ed74 |
|
BLAKE2b-256 | a8d0530dc26691a1c0dfbf0696c8c421bffa0a4d802a15b07563acb82ecc293f |
Hashes for stim-1.14.dev1726900525-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4220c3ec9058eaedb61c605356f588752774d03956215810e790afaebe4cc672 |
|
MD5 | 15b360de8fa93ea1ad2e879e69f7ab20 |
|
BLAKE2b-256 | 923af55f4f9d044ce741bbe4730f6b1fcbadda1f2e8e73e21420dd2082e97ce6 |
Hashes for stim-1.14.dev1726900525-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9e5440eaa2847e545a16b2299dfb944b5efea79a90f9970cc260109bbd6f357 |
|
MD5 | 41a3b1473dd3e750679764b8a3b7d4ff |
|
BLAKE2b-256 | 40339703ae6a59d831f26b6b72df5b21ea867fa5e9187dc459e9ba3aa054b5de |
Hashes for stim-1.14.dev1726900525-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1152ef73cbc5a5e85ff06c05605d108c6a5d31bbb6b7faee0eae0b489cfb735 |
|
MD5 | f9cf22018d235e4c307e8d4335b6ffba |
|
BLAKE2b-256 | 8499b31dbd7a66a50ab2727df36de94dec12eefa2df96765d04f127d61fbdf56 |