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.dev1722042181-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6c4950d2ba35ac8570d98fa58956bffe02f25910f8c201b45e9c3d8983eef1 |
|
MD5 | d5f23a5220aaf9c6332c6fbf6c0f2927 |
|
BLAKE2b-256 | 10b579e894cfa192469a20ed1ddf136a757ac84be1cfacec3204da3d221e479b |
Hashes for stim-1.14.dev1722042181-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb5cb64eb02b3e696509c4b7423301089c3afd3bd8861b7b3e15ebe46055e3fa |
|
MD5 | bbb19987927383edb075e3bdf11c1c35 |
|
BLAKE2b-256 | 87db65b331a941273209a029282cd0c7e55c3d05c3fc1fd282cc8598a69f3917 |
Hashes for stim-1.14.dev1722042181-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e3c5f085fbd859d84e403fc371c90d3825ba2a3968a802bcb1d065eb2a5f8de |
|
MD5 | 7ecaed2c6240f691e19243bc1bc4a6ec |
|
BLAKE2b-256 | 3a7e7de3a2f6ebdabfc1ee71aab7c7885ba8fcd969c308074a45c4fbf5add1de |
Hashes for stim-1.14.dev1722042181-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86847d43ecbcee02519bba36e89a11927f02e3a56a07742bdba7369c3d1606d5 |
|
MD5 | 57cc33c7085b33b21d1239321d1c1fbd |
|
BLAKE2b-256 | 7160c89a6eeb09350e6b96ea93e054684dc13358a4220db821e848dc7f949dbe |
Hashes for stim-1.14.dev1722042181-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | becec1ed2c657f243bafcfcb14a1b7a1317c80312170ef4154a42981746f16b4 |
|
MD5 | 9c02fa8f49ac72898911788c19f2df20 |
|
BLAKE2b-256 | 1b9162fdb61ae2b9dc041fcea8cf722082707d16eba5a7493fb0f80f451988ea |
Hashes for stim-1.14.dev1722042181-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 356b502bde99a8b7c25ae2e235cd5a5f5dcca21d7cf4cfc3ae8daa9ef4438cd8 |
|
MD5 | a06f6582d87a973479d8120c7ae9badb |
|
BLAKE2b-256 | 0a014b77dbca6c1dfbbf0732e7a3663a207826f90f0e77c9c4df6b2a42116938 |
Hashes for stim-1.14.dev1722042181-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b351c97b4b19aa6fcf20dee6b6cbd14d025d095622a2cd2b4e1cf2f418851967 |
|
MD5 | 9b55c4202a9e65705ffd704d5bf35595 |
|
BLAKE2b-256 | 5920a213f28dbbe9b4cf2b1825731df61063156d038553e74734de1a4f8d5091 |
Hashes for stim-1.14.dev1722042181-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d0c85da4e2124f06503ee31fa0446c1a3e2b3fa99d807ca3a7a86555f995399 |
|
MD5 | 4f34908f6ea0ac28ed2198cecc60930f |
|
BLAKE2b-256 | 65ba621d97ed32a3776a004f91597e436aba51c733a3038d600b6d7efff05607 |
Hashes for stim-1.14.dev1722042181-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 374a5d04aec6dc882f6fa05004b984f113fbeacacd5e6e8d7412dba55cff04ee |
|
MD5 | bab44683b08bed547c609d5fb1c0a248 |
|
BLAKE2b-256 | 000d7e81ef01b7b8bdc8071f16dde9bae21f1ee05e463c23972dd4b1d8bf1855 |
Hashes for stim-1.14.dev1722042181-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f291539e686aedbf71bc42e1af4ebab7fa3b17140b0123b5796cb2b44590f009 |
|
MD5 | d16778fbb4fc9710d913b28d36882898 |
|
BLAKE2b-256 | c6683bbed0018197cc9d744e51653444b21b4d28802f69ebb83889a57d439092 |
Hashes for stim-1.14.dev1722042181-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4568867710107ca618b0e1494828b5ee097a8ce420bd8ddf0924b7bd00d2637 |
|
MD5 | b6a1aa97164aa6bcdff4b9f07c60ac13 |
|
BLAKE2b-256 | a4c075892712e0dc9f111476df0b71572f1b14708e9fac1d435c4b80a51b42f2 |
Hashes for stim-1.14.dev1722042181-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce9a4ee1630e96d7fdf0b9e9f4468f8919ca34aba0aabf0b1cb97ee5ee602c70 |
|
MD5 | be4ebecab0a4985acf11e2b51dc6dfc5 |
|
BLAKE2b-256 | 813af248fab077993ee177816ed6a0bc58eb3578adabe21f02b4097eb2fdd685 |
Hashes for stim-1.14.dev1722042181-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d6cd9ef64aff1b3fe6fcc77f3b7ba87192ef699ddab06ccfb630a24c30bb292 |
|
MD5 | 32e66e7b4a8f3cf7b0356dd9f80e3800 |
|
BLAKE2b-256 | d0ca550174ab761053b05aaa956adbfd324aabacc4eb0e6e4f9ce98b56018a5e |
Hashes for stim-1.14.dev1722042181-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37c52081789254cd8e032f8f73f9d2ba8431d1c1efdb03c4efa0734a9b510b05 |
|
MD5 | 56cb3719cb026c3076daa43d86bcb008 |
|
BLAKE2b-256 | c84067427ecab080c37dccfde7c75edba539d0b8dd6b447f9b665c7960148dcb |
Hashes for stim-1.14.dev1722042181-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45bd69969fceed14aaf12f12970440077fafcfd04696d7d091d3c044214671f |
|
MD5 | c469accdc3badcf9d54413310200a4c1 |
|
BLAKE2b-256 | 2c8b4dcc8c91691f9406e6c3dcddcaf6b14e54fbce160598da16760d4af0e78e |
Hashes for stim-1.14.dev1722042181-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f29866dcfb610c222d05b6cacfc53704be0829c7d8f93a08128d60a9917a99d7 |
|
MD5 | 68f93a61cab6deb718f5ca79ef7ad4cd |
|
BLAKE2b-256 | 2259f12b6a6a23c83a7762e14566acf705f8949ef0bd97e62354416ba27769b3 |
Hashes for stim-1.14.dev1722042181-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47df30222eb049c88f433f106e1423261a3a57e1ef0dbcd7a664d08d1012ef18 |
|
MD5 | 3f0a23ab31469f2a43e54a85e8b0c59d |
|
BLAKE2b-256 | b748d6019521d9ff50758fee9e0002272acd10ab411ec420090f556ef5d9fc86 |
Hashes for stim-1.14.dev1722042181-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 100ae68568f2873f1e91c875ad5ce41ffc190a14713c74b9bb510fa3e71392b5 |
|
MD5 | 3a42dac846cf5e968e4cfdd8ed72e836 |
|
BLAKE2b-256 | d9066d56191a67b43dbb84d65ec355f45f0bdd9c24bd6fb58085cba438fd5a04 |
Hashes for stim-1.14.dev1722042181-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78611cb82ad6a269347f501d90ff797c655c273d5a78d1dedfc1bf7878294d96 |
|
MD5 | 94f8eb0f382999b815d808fe54c74aa0 |
|
BLAKE2b-256 | d55763f3516c8f7998af0a68befbee2dfef29204e40f452bc783674633164c5c |
Hashes for stim-1.14.dev1722042181-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57e460e773bdcac7ceec7973f1f2e5027f568e8ab98c2dd31687552b47bb6895 |
|
MD5 | 76d71b61ff34b69b1791873746f6d382 |
|
BLAKE2b-256 | 897a6777303db9e9c0b28da808881f4878505ac40d0ba32801c00654c134ecdd |
Hashes for stim-1.14.dev1722042181-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a7142efa01d1a6c34af62479f10bf1d6189cb8218a944d9ffa5cef2eb578f56 |
|
MD5 | 4c19bfd7a020ef78c75b985c4d3ab13f |
|
BLAKE2b-256 | c56880d39a594554a0639f8b6e36aafe7e3bb8ecefd23b4a71e4f21934882e7d |
Hashes for stim-1.14.dev1722042181-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 931ca2b1a92f6f60d7541930b4bde866dcf6f3f79ddc897b02dd5fb5d07b4be3 |
|
MD5 | 7f9602a422fe2010dbc9173e68871936 |
|
BLAKE2b-256 | 86725a52d4a007cf5d6db67e068185914f9a221844e48767f70fa1dfd441eba6 |
Hashes for stim-1.14.dev1722042181-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b9abc540093fb9b0ce25bc398db12539d071500f69859c7c5bde20a04d7ca3 |
|
MD5 | d2b0a01a5e3eaceb4a2e784f09a0a2c0 |
|
BLAKE2b-256 | 5735204fea2f7d3e254f3c462fe16f07b2fa6115d175c5cac2e0960b3b6f850f |
Hashes for stim-1.14.dev1722042181-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 804dcd33b2a88874e1447e209593926dc28365140ce64b1fcc45983322acb7da |
|
MD5 | 001c5c81f7ce49623d65590926c58e66 |
|
BLAKE2b-256 | af8bec470ce97e681622311669247537d4ec27e1d80c58a99da3d76a329270b6 |
Hashes for stim-1.14.dev1722042181-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685cae664888f067515980657721eb4e1dfdd8b5fa09b8511551b6e76c9f6bd1 |
|
MD5 | f3b2242e81ca2247def7b43e6f442f00 |
|
BLAKE2b-256 | 07b30d8d439b8d9da3c68b5169c9f30b63035ebcb9eb540bfe4c2be5ec3a6e81 |
Hashes for stim-1.14.dev1722042181-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b9039b4ebdb9bf6f499a7250423a774b6e393784f55946bcf3f717bb6057dd |
|
MD5 | ba392267ee2b7ae92383cb8fcf072c1e |
|
BLAKE2b-256 | d44b3550eb87f41adf85b5101fc7e13129db79ccb0f9865b9071c7463ae9c26d |
Hashes for stim-1.14.dev1722042181-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 118497cd01c7a84f9c898f824fec2edafd1ca6ac80f1fb129b4120d937fbb6af |
|
MD5 | f217dbdc7230b82b0cc73174d4322cb5 |
|
BLAKE2b-256 | 8bee683b63ab06e0d759c740bb59ccf3be8ffd060855f5cb5e47fccbc0287ac6 |
Hashes for stim-1.14.dev1722042181-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b99789b7edda17e3bfa153bdbc16e9cd5eefa1955b4b45b94679eb9e5639981 |
|
MD5 | 32b323086a9cbf393e67b03d37fb2a36 |
|
BLAKE2b-256 | 7f97722016d01b13e11f779a0ff8fbaabd855a21eaf7c1960dd6a3e32443da22 |
Hashes for stim-1.14.dev1722042181-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b0878abf960f157dd631cda45e80c6ff20d1d00a2b9f84dffb4c0ffd40b65a2 |
|
MD5 | 7bc55d5f669b8c25881311f9d862c91f |
|
BLAKE2b-256 | 55b5e1ff944c4dc8c151bb3b45cf1f04808f6385a62df2a49201805148cb675b |
Hashes for stim-1.14.dev1722042181-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e17d2acf6dac5bbfd5493c45aee1961843d8bfd870d9b5d1ff30ac8c1cd3283 |
|
MD5 | 4e60e82a012e2d837ec63f75f299db0a |
|
BLAKE2b-256 | c04a3a1f0c7558fe36e26755b5e78b7f6e7e350e76c3afc8546d613ee9e6e969 |