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.13.dev1693688313-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8164a08979c3aa4e43ef5f57f7faabbc364d26e587a010742ea506fd6a1396d |
|
MD5 | 7608d9537706e509b5056a062f39edd1 |
|
BLAKE2b-256 | 2b0a2a8aa82a3afa5493ffee373b20638975d4033ce1ab8138d4b51f5b822ee8 |
Hashes for stim-1.13.dev1693688313-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41669e6ee88a2f785461f943ee63a1d856cf42a3e672e8f36256464af9b748ad |
|
MD5 | c5c03fab43d4ed0827291fb47f5f1ea2 |
|
BLAKE2b-256 | f28ff6e7bac4c4fcc26e183fca3d90bac4f7d95a921e48a7af927fa0245a5a07 |
Hashes for stim-1.13.dev1693688313-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20b1c0f6dcf792026468759950d1c50e0453c5d87620b92632a0e9b280ad1681 |
|
MD5 | 64994aaeb73e6b830fe5b718ca935b3e |
|
BLAKE2b-256 | bdac808ab516c8bbc6f3b11c203a7a5ddd727cd063c4cdf898c61dc615e84d0f |
Hashes for stim-1.13.dev1693688313-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 374640a4f2b49d33086f6c6eebb308666106965ebd9a4c6e78e6ea14bd60e572 |
|
MD5 | 712e97d75d1a9464483fa53799f06789 |
|
BLAKE2b-256 | 32eab36f7813cf1c45563a4791ae002d820043ddff0d20fe2bd89087298bebd1 |
Hashes for stim-1.13.dev1693688313-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a171629886cc8348d1ea900df71d1704ab632a5e03db54c602ff787f3b19fe1 |
|
MD5 | a96502aecf79818429f80b4429b889a8 |
|
BLAKE2b-256 | 8ad0bf29160c6027871c12ddc1ef9a7e9aaffbec725ed0637cda252de892f39c |
Hashes for stim-1.13.dev1693688313-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 359580f00aca27339cbbda43ad501dd67de7ad8f6955fff733f096fe06ee3352 |
|
MD5 | 44b3986d7a0a0c95a45d5a217c5d4f51 |
|
BLAKE2b-256 | 675a6330a715cbd149e4b184c3563421ce7bc57de7e2aae450833aed85c73656 |
Hashes for stim-1.13.dev1693688313-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42d7dd8ee48de6284aae5ccd2ffdeeb6ba0bfa45bf09b65e4ceaf2ba8cd4e345 |
|
MD5 | f85f01b4b8abe37933466fb4e65564fa |
|
BLAKE2b-256 | aaf1ff32c1fc14532cfe214c5d3ed41b679e62b2e1b7ec699938f1afe44202b3 |
Hashes for stim-1.13.dev1693688313-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb70d5fa572c34306cbac4ad6646d44200c583de853828c09334daf54d5a7e0 |
|
MD5 | e4bb1e6d0732bef8c1040341c38e997a |
|
BLAKE2b-256 | 738de1d2fb23b0095b26145bb06e9e85d86e386260f8d6d235ff9e66f14c176b |
Hashes for stim-1.13.dev1693688313-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8024a7fcf30706a2cacea09656dbd62a339922d95f49e410b8dc73e5c186ac |
|
MD5 | cf1b6055e8951b8cb76f1ff9c46d5a71 |
|
BLAKE2b-256 | 2ac892b4d7704278a6c8161b67ccd96d9836ea2b3f61f3b89db28425f2877808 |
Hashes for stim-1.13.dev1693688313-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 464cfad38a4d3dde3b11845bdae6c4db5ad5b8f5d7c69cabca29c474a01c627a |
|
MD5 | 993a1de34b02e923ec3b6277727006b7 |
|
BLAKE2b-256 | d2806e9cf44c2852b659593f2d6ca4dfa4d1a824fa9dedf397b119c35e852d03 |
Hashes for stim-1.13.dev1693688313-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d202994adb577df344047b5e498d287e3ac14d2d6df6a0740bcbc72ed17ec8c |
|
MD5 | 94fda2fb711d99940f36b9f9fc04b4db |
|
BLAKE2b-256 | 1ae73011fb9a6609ad8f2313adac49600a16c7df1765180c4d59ed8bae654945 |
Hashes for stim-1.13.dev1693688313-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 671d0a2342ae6cce61c9e149a1ddfdc9ecc87587b727ebb32a0bc7597125b3b3 |
|
MD5 | 7b8f175480e91496ef0d09d7fb71ea0e |
|
BLAKE2b-256 | 4d41ba044944d2920fb6cb656829e270a2c15647de4cc3151eff5231ec4730df |
Hashes for stim-1.13.dev1693688313-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bdc428cdd00fba5d3da5ee172dba452ebb5421ae9e4078521dd9c04d816dcdd |
|
MD5 | 462458be36a745e83d3e99520dfd3825 |
|
BLAKE2b-256 | ed396604ee11133e2a8c2be1335369e089f04bf5696d778ef973f20f20b0830e |
Hashes for stim-1.13.dev1693688313-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ef9c6c51407f84fd7d644ea01b7dd44edf0623c8862b97692bfac45c88db23 |
|
MD5 | da5576cdeafb51a1c74fb18486ece576 |
|
BLAKE2b-256 | 897e4740859a205ce9eec8444a94e7358c87f5c3e3e1b0cb5b4eff01ec690ba2 |
Hashes for stim-1.13.dev1693688313-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04067de46537f1fba5fd3cd6c85ae459ab1c93eea32d1a6db085d96cdb1d7c99 |
|
MD5 | d611fcdc9c63af5ae10c444ab8abff1b |
|
BLAKE2b-256 | bc999bd5d3d21762527e4ca0c41b18a2baead74ef4a8a4e06775959ab9677d1b |
Hashes for stim-1.13.dev1693688313-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3428f861ccfbea56cd0091da0b8b98dc1d6150a0cea548ea045310424ecb3a62 |
|
MD5 | 20e74a1893deae53ea3314f9611c7d64 |
|
BLAKE2b-256 | effe5b18fcbf996e87f0db9324558d7b6c7fd76ef1afb1f4bf604bfe117e09bd |
Hashes for stim-1.13.dev1693688313-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f52978b0646086c09235b763e488d84f22bf1173c7b67074be9286d9d599e225 |
|
MD5 | 6c3d51eef04a1d93ef94225bb92309e9 |
|
BLAKE2b-256 | df459075a51df07d36d2b03a5b0e81042e0f8427b7c28c25718f59664288a5a4 |
Hashes for stim-1.13.dev1693688313-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b846271304c3660bc371c9d55ffa4fc5a5844e3845f93aab2b4f6434a878cea |
|
MD5 | 097d489f8b8a37d4bc8b142b73874e22 |
|
BLAKE2b-256 | 0dd04c26bc599914abeb8b5411c68c47be0f6048ddc587fb25e229c278300609 |
Hashes for stim-1.13.dev1693688313-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ea6295bf42945351eb39283c907e1ea38bd7326c227de9807228c967f345f28 |
|
MD5 | 125721974a1f324cd2de87e071e296a3 |
|
BLAKE2b-256 | 03cf8315f04599fd049de69c10fa85cad7cda423731b92028d2f0ef92e113c09 |
Hashes for stim-1.13.dev1693688313-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb5db2894a130566f1688f93ef76cc0854343830f53807859b3dd29d4bd19e6c |
|
MD5 | 920dece0d814795f77cfe7fec176e1f2 |
|
BLAKE2b-256 | 815fc13d618ac12229d2a818d2a2e064c584c5129752521a5152743e37495bc8 |
Hashes for stim-1.13.dev1693688313-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e787483ec26f35e22e50b9563952626a9be9c11ae4878f26ce9c4db57cfbb2ef |
|
MD5 | bab474c1d5d9d7b931cec35ce676682d |
|
BLAKE2b-256 | 0d03ddfc7cdb3626b6977abef80b729c454a366e3815a584888e133cb88074e9 |
Hashes for stim-1.13.dev1693688313-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16e9c935b645dad4cfd36209ac4e36cd0eb48274eff19451ba831bbbc27eb95d |
|
MD5 | b13d002a89bdd9497d70e7bec24141ea |
|
BLAKE2b-256 | 9ac853b7a78d67bb3ce481fd7488d93771019b7faefea6598c54ddb93d2fb08a |
Hashes for stim-1.13.dev1693688313-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65983b852d20b716db9acb1f2c800f490e047f8ec60a7dce9d3c8589293fec62 |
|
MD5 | c5a81fe67ffc1afcc230d62c5e265282 |
|
BLAKE2b-256 | cf5d59939c4b342363fb86be914476da7380a6fdb7867c4609fe74f9f2c1d4d3 |
Hashes for stim-1.13.dev1693688313-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abd4515576e81afe86a82fdce634c63fdc018a31ed8936c61fafd993457022bc |
|
MD5 | c6e1dd915b597ba89d1b92f49d60027b |
|
BLAKE2b-256 | d428a26a41e9565c93d03b9e5751df52f45045a9314c20300a06880408222aca |
Hashes for stim-1.13.dev1693688313-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae944a8488ff26431fee12919511e7ab7e65ea073cb9eaa0f9efa7cb93f33baf |
|
MD5 | 360332afd66de407fecbc6fb1a49f127 |
|
BLAKE2b-256 | c893a9ecc11434a8cf7d5f029a3b787cae56b8d252fc1d27ab50b9682888a7c4 |
Hashes for stim-1.13.dev1693688313-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a66c9ccee819599dbd53633e4c9d08fa046ba8e14be728c04db95784c3845479 |
|
MD5 | f3a0524e07f909843bad8390f05c6de2 |
|
BLAKE2b-256 | f28289117375716df35982702b6ee7e747ff45ae6156071ff0f8749cc35e0ab4 |