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.dev1700871912-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a715a5c59114f847616d6f6de9ec69c510547394d235040d63b72cc9d753fa |
|
MD5 | b3e7ade30d984295eaab1c508d14c28c |
|
BLAKE2b-256 | 657e25bda9c367a4dd49606169293f3daaed295a7f9f6c9a7f4df8d67f2e4dd2 |
Hashes for stim-1.13.dev1700871912-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 487845b9922e06ab78bb0aff50e9e199d9a022ef206de0ba251162d8310c7db3 |
|
MD5 | ea0570e1dba79850d326d9fcb2d3ff9b |
|
BLAKE2b-256 | 6dbea4db799cb587852ce040767b40dd67dc3c42dd6905705b93acae1148f9f6 |
Hashes for stim-1.13.dev1700871912-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6287e2511d248b5a0a42d8730c999db93e6ed81da89ebdae6b3bc621d61c3cf2 |
|
MD5 | 30c9c8d073dfdac927307da1969f9ef4 |
|
BLAKE2b-256 | 1f6a807a1860dbe27ce06f8f643f0d4e9d69a3cc8b49ba38fcb81d2a418a5941 |
Hashes for stim-1.13.dev1700871912-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2a6b5dfa9882059d2b0559685563c137bcd23970694be05708ba05aa306434 |
|
MD5 | 3a8e0b7122ded070456a045c94d45c3c |
|
BLAKE2b-256 | e9f505051d7c3293586e1aa199883f7ffde1abbb047e4bf2a87869319791fd42 |
Hashes for stim-1.13.dev1700871912-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3ab471e41089dc6d4dbffcfdb883f62f9d547058d30e5447beed187b7d7a3ad |
|
MD5 | e6677067bdacc9318516c39c7a865fb3 |
|
BLAKE2b-256 | b192c27aa0e32f0055b5117f11aac8768caa691e353d66692beb314d72aa48cf |
Hashes for stim-1.13.dev1700871912-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b47e68e32f36d500120e3b6af27dedf6fde81971314db219fdf2712d4a190e9d |
|
MD5 | da728364da4d7982c71c058bd6e972c5 |
|
BLAKE2b-256 | e4291eea7f1780a23c7aff5e4a6e079f73f1fe61ed7e78c1da970e33436e9109 |
Hashes for stim-1.13.dev1700871912-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 479735dc475427ddc890c6be10c8d6af2d60d0079ef8a6c1b9c329a85beac4e0 |
|
MD5 | af22240747bc33d360d40ca59ca6855e |
|
BLAKE2b-256 | 118fd204fdd39d7b491b0bfd03d26c769976620cbfee53c2d05728d0d688f125 |
Hashes for stim-1.13.dev1700871912-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6c08e2814ac5422c5014bb99a2f4b48d3ede24d9cc1896999b3e59ed640f2fd |
|
MD5 | 2e5c6a5f134176e58991878357e0fdac |
|
BLAKE2b-256 | 34c73bc1d2113cea802e407d08368e6e0611a33b2837d5cc29d498ba558967ce |
Hashes for stim-1.13.dev1700871912-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17f5c0289cd370fc2c08f90ee5841221d2ae7a037cbe798f8c8191f3f0e4de80 |
|
MD5 | 68a9a0caf9096d57861d5c64a0764908 |
|
BLAKE2b-256 | 492c128b9e49eb6c655329496f808ad270d4b1045ad6b3b3d30152390b1979ad |
Hashes for stim-1.13.dev1700871912-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0667afd9c91241769c14ee6c2faa605951d070d336c93f7baa18b4f71517acad |
|
MD5 | 766ec6dc3974a3aa939fda2a60a11cbe |
|
BLAKE2b-256 | a9d3cea7f2ec43f0ef73ee545808ff25e65523a916dfc156b392b0fba5b48df3 |
Hashes for stim-1.13.dev1700871912-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0363652f4093a4e251006ec3a461ab966b689630454a6a7bb0726e5d9dc37637 |
|
MD5 | 0f896ecd468fdb4b811567248a4ced4a |
|
BLAKE2b-256 | a3c9852322753383d9b9298c11f146e2bf2511e3963d825d23b0f8569b337209 |
Hashes for stim-1.13.dev1700871912-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0416ce1c2d242b3191199b7eccedca99c16f380d17bc5375b9c8a628532d0955 |
|
MD5 | 8b954375c8b1e08bbaf11be161a29ccf |
|
BLAKE2b-256 | 495239795b8b5367f6581ea59b73ab6816b6f29fed245876779a555947e1befc |
Hashes for stim-1.13.dev1700871912-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da4a8927359fb5260f045b8d2c533116277fcc2186b980490e1c3c699a9f4d3c |
|
MD5 | eb7f71c19d4cbab79175787f2c758e73 |
|
BLAKE2b-256 | 34c067b693c47e83a817376d282b1d25d53f862d10c60ef7e2f2c005c23905e9 |
Hashes for stim-1.13.dev1700871912-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe7fca66445b830b45b585960929967a7a5257711b1ffc220b8ecddd8cadc520 |
|
MD5 | a797a58f4b0000824a9455abd7f8c4f3 |
|
BLAKE2b-256 | 3cf23288073498cbc9f4a5cd5d4251929f78c6dc754992a573ec505dc1cde2f3 |
Hashes for stim-1.13.dev1700871912-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c4a84189c611f384c8d43b19b070e9b631f7859a44e83aacd5f8d7ebe017319 |
|
MD5 | 3e677400192d49cc8acc4a2ac688e302 |
|
BLAKE2b-256 | 9dbb3f00bc4d3d5cc31cbc46217645a64b2d44e26fc9a08a5555a8717cff0da4 |
Hashes for stim-1.13.dev1700871912-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b2a5eee716d5a8de57e2bb595f0869fc5250f7b0b6bcf7cf812e2fe28a9c8d3 |
|
MD5 | 9d691f1806f1c69f82e6f561d8d912da |
|
BLAKE2b-256 | a27e0f6507014187fc5c5655063c703724c1ffe401bd0d88d34fa83af5a61ba4 |
Hashes for stim-1.13.dev1700871912-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e392860572b6b1a3b9600f2664a662977bbe0fa268e09b3792f897fbfad51ebe |
|
MD5 | 7f0d79da81fbde7e00f9b43a4780a350 |
|
BLAKE2b-256 | 364b1dea79702fe1d478b42ee1a994c048fd3c8b1cfbb9786f91495a24e04625 |
Hashes for stim-1.13.dev1700871912-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85df4b4c288a4a07ff57366abd47453e171ca69d0b482d542319378a39370c5b |
|
MD5 | 8f2f40a37b77bd89704f9a0950125950 |
|
BLAKE2b-256 | 03d7e7272dfc5f156e5a6b8d5bfed14b041f1f9eb87c80df0f61df7bd70a46a6 |
Hashes for stim-1.13.dev1700871912-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18f6de6c6d7e1feb82dd8e4b16ce6f99be355ebed657dbc94fbc19d564d4001 |
|
MD5 | e326f78b7127b92991b524b747443a34 |
|
BLAKE2b-256 | f2a75173714f64d4e8823aed22923e876c54178fe2a4c3f83b61d3de16611bf0 |
Hashes for stim-1.13.dev1700871912-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ef1fdfb8ba7e1f5636dc816c2cc450e6cd5a676735e45bbaab26aa50c78f08a |
|
MD5 | 9c4195401cc90a2b2782b08435d3abe7 |
|
BLAKE2b-256 | 26f5c1cf7bab3a4bd34fa09897eb8afcfb0fa9b0bb3ce4fc5a9d2dfc21dc6b1c |
Hashes for stim-1.13.dev1700871912-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 055bc09216dfca7a219a0cd23ddb59f350d014f0b76318d225b5ef5aefcfe6d1 |
|
MD5 | 3d3ca07adf13205e81fc270df144d980 |
|
BLAKE2b-256 | cb3b2349f8be63c544ca5b08947cf3cb31a42a09259d7bb81c50053bf8b0574d |
Hashes for stim-1.13.dev1700871912-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9be37fea05cd4bf00e5097f508b2c1af5b89653f5b9259efd24846f8045c424a |
|
MD5 | 8ed749622229cc0738d6a8c844c4739a |
|
BLAKE2b-256 | d20be2884d8b55d0efdb3a79cbe9abd15fac4d0d2ca4bb8f6a708308af8fb1dd |
Hashes for stim-1.13.dev1700871912-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26c20f095c976f81bfb0d68f97a4bd68eb39159ddcd309cd7f46b1d17e7ad5fe |
|
MD5 | 423d9bf2058da653ab7c3f00c9154322 |
|
BLAKE2b-256 | 36504524da8cd3df6ff5e936e627fb3f8804b9f6e7f12c1f09528fe8582647f2 |
Hashes for stim-1.13.dev1700871912-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a0d42a03dd01376a3811075486f33f6eeb315079ae4dc2f5179731c957375c |
|
MD5 | 0adebe9aff10617f876c9e7bcb633854 |
|
BLAKE2b-256 | 9f5e65e61cf1f96308266ed28a9c692f5e0cdbe93cdb44abcd19fed0b6bfa7e9 |
Hashes for stim-1.13.dev1700871912-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fa9a96bd668e2d6592439ee68cc8e4cec4aee61bb4da07f8b5323e3f3f3d2f2 |
|
MD5 | 361ff51488a4631fceff641c0cfc0b4b |
|
BLAKE2b-256 | ee8cc288fa9e72c571b635d0f6bc32ce4c60b7f17773c046d1fcc429d29fba0a |
Hashes for stim-1.13.dev1700871912-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 245b36c8183fc16b21d660b619ec567360c6965f24868b9abb5b8beedc22f8eb |
|
MD5 | 8942674298743316f47151b77728dd44 |
|
BLAKE2b-256 | e43d6b08ba5700776bd7b8e08f0e0f2f0dd6acfef54dda2d1bdf7b7b6ac06f2d |
Hashes for stim-1.13.dev1700871912-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4abbf4631007d1cbe6449cdf53383eb71ceb925069f6458465d7a92d43f2ec8 |
|
MD5 | 708f49cc0cd21b4fc4d27c6f899551c8 |
|
BLAKE2b-256 | c9d98112711fcc2b20015698b07aaddbcb94f00b204cb3c8dfbbb544e5542537 |
Hashes for stim-1.13.dev1700871912-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e8273aeead9e05a7f054043d5ebd15f4b9577bbe7b871d2b6460db88f55c939 |
|
MD5 | 0c240e29d3cfd3418877ae075ddb5e45 |
|
BLAKE2b-256 | 9049f73eeae564de6f189a9eeffe6d77cff96fc5a0465817fe7e5bf052efdd45 |
Hashes for stim-1.13.dev1700871912-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 053eaf52b86c15aa526d44f9d7f2a8746ce93ffaf8a9b57f4dfb0010d1f10f04 |
|
MD5 | 42cdf6714efc299d1803b3d2ee17f2de |
|
BLAKE2b-256 | 8a35fd6251b6cd67af2faf85896f0fb1c525d0bc60b1b03a862f220306accc72 |
Hashes for stim-1.13.dev1700871912-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab65262961f67d0c6c65edd3d323bf231dea35484ebe011a0becf0763d3d8773 |
|
MD5 | 56455b9c5cd32ee33b01a5fcbb088be2 |
|
BLAKE2b-256 | b01f092adcbe17c04597569f40feb1f8947ae51c8a83d418cb1665694c50cefa |