Skip to main content

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:

  1. Interactive simulation with stim.TableauSimulator.
  2. High speed sampling with samplers compiled from stim.Circuit.
  3. Independent exploration using stim.Tableau and stim.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

stim-1.17.dev1780910265.tar.gz (882.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

stim-1.17.dev1780910265-cp314-cp314-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.14Windows x86-64

stim-1.17.dev1780910265-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stim-1.17.dev1780910265-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

stim-1.17.dev1780910265-cp314-cp314-macosx_10_15_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

stim-1.17.dev1780910265-cp313-cp313-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.13Windows x86-64

stim-1.17.dev1780910265-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stim-1.17.dev1780910265-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

stim-1.17.dev1780910265-cp313-cp313-macosx_10_13_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

stim-1.17.dev1780910265-cp312-cp312-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.12Windows x86-64

stim-1.17.dev1780910265-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stim-1.17.dev1780910265-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

stim-1.17.dev1780910265-cp312-cp312-macosx_10_13_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

stim-1.17.dev1780910265-cp311-cp311-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.11Windows x86-64

stim-1.17.dev1780910265-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stim-1.17.dev1780910265-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

stim-1.17.dev1780910265-cp311-cp311-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

stim-1.17.dev1780910265-cp310-cp310-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10Windows x86-64

stim-1.17.dev1780910265-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

stim-1.17.dev1780910265-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

stim-1.17.dev1780910265-cp310-cp310-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file stim-1.17.dev1780910265.tar.gz.

File metadata

  • Download URL: stim-1.17.dev1780910265.tar.gz
  • Upload date:
  • Size: 882.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for stim-1.17.dev1780910265.tar.gz
Algorithm Hash digest
SHA256 be2923cba01ae58ade11e5f77a6e29ad97d07eec859aa3d0ec862792f692b62f
MD5 f4f73e12a5370b011818e70bb78258be
BLAKE2b-256 f86c4c4747807e2658976aaed76d10798df94d6a7ad83f850ddd315f5cc9a307

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 57c935a4a55b93f4d0d0ae5fd8325e563d86770f311ee29d8ea0a59ca48bf4bc
MD5 18d758c723323b63b31801808946bba4
BLAKE2b-256 e37292bcc234cf1bbf35b6bd1ee5a873cfedba6b23ab8c96b5e372eb13bdfe07

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79637f3aedca65c1a74b4768a32441566282fcc5b3a4784b2102828f93504d77
MD5 fef9fb9daa34dc250a10b6bf7e020e72
BLAKE2b-256 009b2eddd7452d5b32aed61d365d6fa42509f2903b4cab003688e74cf58bbfe7

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e179422030eeba16768fb6df3427caed18cdb0819a906d0438708a6d19a0dbc7
MD5 cd8d7c8d9ef32ebbe0cb79582d291c9b
BLAKE2b-256 52a1f2d6a6d8e81dfd9852f5270f6f10bf5b2c35df3c16068f45e04719b94e24

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f835ccae1470400a87fba8ebe3d5388195e8b86ebedbbcbab3d0b18bc8a0739b
MD5 5c89531986583fa2722987ef8e4d6f26
BLAKE2b-256 e166c8767c8a4fbcbbf6019cdb32ec3c204c6285c1e64ca96b66e16e1021c5c6

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 149f0ebf94a3f618d46c47604c090e8e7725c4ffee27f65861a33d728f7c5a8c
MD5 aadb3894f2284619889a191463973a4d
BLAKE2b-256 fc629d740a1d17f54aa679586fa0fe9e4b724b343dca3d8b748894494c6a3273

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 71b36a9ad9c4459c26cf15777f39558a913dd5ff1c6716a4c7db5f14d0526e9c
MD5 a1cb8a6d03456ba32732c41bc2bcf971
BLAKE2b-256 4608ac405edc8446899bf82a1f1093da43e755e6f219184da99581a406d4477b

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ea8ab7bb036fba727ee2f226da3278346fab94a89d9c8442a099b596d21b9861
MD5 602067ef0597c0b449d65b962a2bfb10
BLAKE2b-256 3fa39bd02271c2272e75f19be56714f3a1160d3887925395ae4f0864254bc8c0

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 92236f4118a02a627a652e9cb9f590d75da89531b4a8f5e76927d6b9ea30a680
MD5 11c7f5f422cbeb0e59162123e007ca5b
BLAKE2b-256 19ffe077aae94697110c423cd2c657a1c82c520ceff4305c1d7c5e2a97c7e93a

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bf156429ebc531c563d213aea5753ffc3ab88d59aaad1ca02f49cb7038394197
MD5 e1a33ad720a4c4a3e699d56d9f6a2362
BLAKE2b-256 ce9243b3ba676c61915c59bb7e937bd678fe0e2c58b02e1e0d71449d01bf030b

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 201b6dc1ef488b79453e2a0e1fefb584d6ba0240dbc162669c5599a1f6debded
MD5 e5f3d3874409bc3dfa0921c43ba7179c
BLAKE2b-256 51c4d4cc17e1ea2d704bc791d77b611ce34b522b5294f1cd25f7a066c0f55a93

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbf68a1e905b56698ef8c97915d082f94650b6e1c2bed1cf4973a60007ec6b25
MD5 8935e9162d87bfeaf34d038d0ab4c743
BLAKE2b-256 db54a8220621502e868f3de3994f0a67fa722751781b52fe9205985dac15cf26

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 75bfb77eb8786450763ea35317a5523b845e5e46d11ed1c2ec74cc330e348ac9
MD5 ac3e84c772a90aa3559b6662823ed31d
BLAKE2b-256 7bb59223bda16ebaba9d8856165844565fbbd81a335d039a67860079f34dfbe3

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 df3ddfafa3db59d57ec88e85bad985927f2291c3d5fa95f3c12f66f67deca4d8
MD5 80af59b77dc9556fad2792da06ca5614
BLAKE2b-256 fd5c6861bb2c894614df9f3ef312f8d4b24424278ba8cfc6367372da60ce7933

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd98428bcc1f6ccc70f46374896759fe60dbc51bd7593c36a8e884d5412852ab
MD5 72d94baa2610047689e2ddcd73deb71b
BLAKE2b-256 7702c46cde7ca193f5029e34feb49ad9736a431e50cc360844deaf93b74d9e02

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c69c0465690bd8c4da430407a193296412f2c280a36fc77b26a46616c116d324
MD5 193caa92a8786ddea8fcd39c501b320f
BLAKE2b-256 4588f6898848bc3a97d51139e5da3f6916918b76ae7d5b996a5a709fcfd79db2

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cfe788d5bb6649bc13fd1f70abcabd4282f063b07efac7c6bd038def43fba2b8
MD5 0450797fe38cf62129f609faee3d256a
BLAKE2b-256 adb986215a9ab2fd9ed5fb6fa6b3344dbfb2ec8e2cc466d5b987c7b90234290c

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ca928d2969d0eabcf8d4a675ee9e101007eff2341021d3fd05ba378586cd560a
MD5 edd168a52a00314650cfde0fb79eec1a
BLAKE2b-256 488c9c38fc071a33ad0411521a147db97222753c281d3753e721b31bebf3fcaa

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb380c1f200565ad0cc8b46d43be6478e935e8def7d3a084549f45712b0ea52b
MD5 ca34907f62703a9bef1be6d4ed6ec5ca
BLAKE2b-256 30baecb2e104d26cdec5988c63428121915a0b0f4fd926bbb609aeff669adb0c

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 06f3c9ee6f5af5f3a9b4f49e64d00b3bb108f81d00c91bdf9b0ac5786c585a08
MD5 31610008712aa72bed7f5f1c9d971a2e
BLAKE2b-256 c0af97f9de09ef99e6a52a63238873dfc4f288ac93c4078ed20a98abc53e0f9a

See more details on using hashes here.

File details

Details for the file stim-1.17.dev1780910265-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.17.dev1780910265-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 63bfbbd46db186abbf93b1c4416ed61e62192add52b68af689c285c0fec1bea8
MD5 5b25e106fbf0d756c1cf9c7b3aa05989
BLAKE2b-256 6e693a211780087af427ca3e8f646e15a8d91f98fa7e2e89fcf080ec935ead44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page