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.dev1779429497.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.dev1779429497-cp314-cp314-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.14Windows x86-64

stim-1.17.dev1779429497-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.dev1779429497-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

stim-1.17.dev1779429497-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.dev1779429497-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

stim-1.17.dev1779429497-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

stim-1.17.dev1779429497-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.dev1779429497-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

stim-1.17.dev1779429497-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.dev1779429497-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

stim-1.17.dev1779429497-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.dev1779429497-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

stim-1.17.dev1779429497-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.dev1779429497.tar.gz.

File metadata

  • Download URL: stim-1.17.dev1779429497.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.dev1779429497.tar.gz
Algorithm Hash digest
SHA256 ca86764bd0a19d9f0175f8f0b7e599f817fd03b326ad2daea9110f6e7c97ae7c
MD5 f5c59d975aa3049eab4f2d2b2bb7664f
BLAKE2b-256 0bce499836f9ca759106bf4f28f716a20cb6bbb091cdfd4a7734f91c8d1a7d6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a525aae14e50ba419cc238a680f1759259345aadeb047a2056a014f6a9f88383
MD5 98167559462e8151195b8f7d5c1dcc72
BLAKE2b-256 52ce3a699006b39878f094381495860866b6e82f8bb9ae2ca7f95b82c16d4530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73219bb739b64bff732eec384f3d501ce436ef192158afc20943675df88a26dd
MD5 31742e510218b3a31a23c7e3863380ff
BLAKE2b-256 f70477e8b94306dc364364b50a465a4381c35e5e7706fbdb3101faf5dde85e1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a739464e7b4c2167b6c187c0c2c3a48de89ac17503d0f5b0251742016722348
MD5 5413550ad70fd82cc50105fd74060385
BLAKE2b-256 5af1a70983ab6c3b2f6f2c44a29a747f59624112e7c29fa0aa985a187c652fe6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5a2bc9a43fde631fdb7d6b3bf8027ec0594decc3915aba2c057f9d7121c44f15
MD5 29213f6cc403b0d66dc3b03d5eb26986
BLAKE2b-256 27c11c947099c2b5ff4beacf407ad09d0684caab28346c777ec39cfd3d1a9e6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6367e6243a46edd767387d135853c373c97878d26590ca2acba501744d5ed78c
MD5 45cdf9e54a6c40f3c0d4631abede2b3d
BLAKE2b-256 d49d74c941a93e89622724888fa7d33f0ec34f2040ac152b2a06df622ac036d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b5cd1c5436c2b9650633f9079f446b3e9c8f4b68ecc027d4d7d26034ac55d18
MD5 ea8b4bdba07e67973887f64d376753e9
BLAKE2b-256 cdd8d6e5bd86dcbe4c4f2a269ca0f674127fc523fe66e7797416b1b86d2cda27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d3deeb17fe894cce61c84086bd52a428f74074dd19d5630563c389b9235bda2
MD5 032b63b17983b04b37aabd0b2f6f59e9
BLAKE2b-256 2ae5a892921081f4de0bbb42157fac6c177198ca9aae25835089d0e708d3cdf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 67b6dd434d02e8434f25cb1bf39d6383a27ed3941274775fe274d2a1391f3b7f
MD5 6f2e5a4b6ab059890e5f1f9215ccf7dd
BLAKE2b-256 213faef7bba0a24bda79b9f60977454bf9a5c0ea7498ca9684578b26a070ab10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 873ed6c18d9e35f8fa2282f33e2a80ae77042902898b2f27a8982783d30c62a9
MD5 d6e24e63583ee96c6b6821f43cd765f2
BLAKE2b-256 edf1479febcfd8621c76ce733ae80f07368d6834eecfca0b7cd302754cbdb0de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 77268ee8ddd15b338826260a4a23b2c019c3ee4f34739671fa175d0c9c564ef0
MD5 70704eba513322045aca67f164007779
BLAKE2b-256 a21ae4a72aa75be3d90630aefacb4b45b87dbe459205d6463233c0b43a425a3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 911e2870d8a0d169d34db05d59a892f66c2a8631ffa7a50f799cffe4602b86ca
MD5 c55ea2bb8f525667bec2dbcdb7a44f74
BLAKE2b-256 c0d92a56216cd1135af0c413c8ca82379456bc0c3a756eed636409c0d01696b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4399791e4478ad1a4462adedada89be8812d72b139419238ecda1b64728b0384
MD5 b696c0e4a24406f0515a6d2394920556
BLAKE2b-256 62c7f709a3caed21ab6fbd3ffcd63a58b5800d7da770d887890b41ddb0614845

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fadf087818f36e670cc9ac3d7211ebe93bddd33f3009ae6247185b8d517aedf6
MD5 e2d1d9d4ecbec331d66b48b9e81ef009
BLAKE2b-256 bdf36e4958ccf3b3211e1a414d6d55d4da3603bba8eaf32d2282482ffbffc18c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 198c127c5289f5f180ed0357e14e2c91685304ac615c7d7e108d98ba05284fce
MD5 31cc3d229f1a16d13e6d4e1c60aea456
BLAKE2b-256 852dab78c5d81753ddb167988e3b7a6d785baa40d90ac56c4df0a9621decbcbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 15cc5276679d9425469b7de4496eb8ae50ba569df85548604faf3b4d7d20422e
MD5 15dead5660b2a89e2d71b6a553910b81
BLAKE2b-256 784807ddea811f7fc637ca0dac4d4d91f271e8f4302dbea4c41deef492ee188a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f7eefb043ca437b25d216424b9231952089e77f526b03c0b394f3fadef994ae3
MD5 97670a045d1068971a2e9befea29959a
BLAKE2b-256 74f4721f0abfa884e2b654267f9fae4da1861197c8d30c0647d465e0a04dcc5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8f7be382f2a1c93002ccb5cc83dbd437b84a5f62b6e97ea5209be06cbd3c5086
MD5 7d7b6e33b991e103c0feb09b23221621
BLAKE2b-256 e588ba2d27fe3ddcb856e7db4a17d3c5d726afdc466d78e79ba613dc8150de51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a70344a4ff8e28ad19c127e3cb98aebb164bdd3261e43f023da74e52dd113d3
MD5 95bc0c1949da17253856406dda2abf35
BLAKE2b-256 e02d07b14d80437e36cbdac9e1699ecf5ac80b24c83bc1ceda57a6fe28638313

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c53aabe649b0f27fbfa7b14fe68184fc60cc467538884f620cfe81356da4a1a
MD5 16ffea269f29f42a67cc23313aa8be55
BLAKE2b-256 0efc3bd09a28f46d89e60a9e1c8c9c9a92f7f68009533cdccce85fe532a97af9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1779429497-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ef7995ccab09d60a4f9b4241565a925dc73089dfc9de53c9fb42b4d7c3643f67
MD5 8e1c4af6c6c8b6799600cb8b89ee9784
BLAKE2b-256 4c2a97ab2d5d81b2f3f351115175ecd1dcea1a247435b75ad52ba210b336d056

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