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.dev1782535097.tar.gz (882.8 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.dev1782535097-cp314-cp314-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

stim-1.17.dev1782535097-cp313-cp313-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

stim-1.17.dev1782535097-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

stim-1.17.dev1782535097-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

stim-1.17.dev1782535097-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.17.dev1782535097.tar.gz
  • Upload date:
  • Size: 882.8 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.dev1782535097.tar.gz
Algorithm Hash digest
SHA256 083acd4bc193ba836ab8aca3c4b175fcdbf5755e06f73585fdf622cc7f87fc41
MD5 b76771b8621ba955fab45c4fd2fcac0a
BLAKE2b-256 6a7c8dda5a9326f1a17d7bab233c408d0ba1abdafb4f8b452915829c12187638

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8c08cfdc44759b33a9fbf1926d7cade2ab4ee689991b0063b27c8c161954e6b1
MD5 ae3bee4d0971e2fcfbff771bc03531d2
BLAKE2b-256 f7c4802b130b2134ba3deaad9b4ee758d0393029e0968cb9da7109067ba84117

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a67c434264a60dee1a3198615b0a1a2ccdcb23c01ac07e4c0d508832ed274a5
MD5 174514e40499a41b75c9215dd5a2e310
BLAKE2b-256 e3ed3aabd1a30e6fc4093bf759278a653672ef0f94e3d405ceb768bd233320ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f273ccf77617b358d85e17c056e9aea3abf687f310a7171930b9de8a194947b1
MD5 a3fae212cf1c15117e6b4c49d80a0365
BLAKE2b-256 5ebf98932fe6bed3e7d0be6d30f64b9d31227ebd5ad3d66a7052f15554a12861

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8ff07584831f393b8858503637eb9987e701985f2a83d2886be4351fdf164f85
MD5 d1ecddb7e74c52e8a28866ac406ea5fb
BLAKE2b-256 91a92a7cb83fcbd5c2eef2dae026ed08f699f076d91081bbcc6bca27717decfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cb03110fe26151b14ef6653dc7f5e6f1bc7c59b274426ae50aebf21ca8bbfe93
MD5 aa0c115ff446683ab513c33507b314fc
BLAKE2b-256 48e2f853aa158c9b227ae89ae3dbd2eab9fa6c0db38e3b6ed1b6c1c7adc8d740

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 506c47bc34c0e0a510377c73657b4cbaf62bf45e08f4f0d402099df85bf0fb30
MD5 e4e1ada7aad5f0a8f76c543f4e734626
BLAKE2b-256 0c207ea12dcf240aee886634a706e684655726d56bc37b17e5be7a811361b5af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c21a8650330abd88caf8e6925241dbd03f5f5f7388e0b7fd1419b9abc346c802
MD5 d0975642d7cde2c9f51732b39e2883f7
BLAKE2b-256 a07960fd37d6f5dad357e6666598bdb9ae4a251705fc32b5432831726f47ab1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3c15a609d38d529499bf8bcbc6095611b4c7de2d5e36b421fdc102fe78e6a9b1
MD5 c2ff00f412001f88471c7bbb410d0ce5
BLAKE2b-256 7c260da6f1f1139ba3cf812c9327ca692085dca2ba0e7dc9a0025d01c5bcfcc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b2b540f4932931640c52cc4eef7f6ca44500e416e1341086dfa40a61c7ba192b
MD5 d5becee4f0a20c456447ea0b632ae62d
BLAKE2b-256 f8bac22f93b1dc0ea8e102d7eaaafcb99b1b515610c87dc5bb2033e24bd50d50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef90cfca7b3d3fa4c393371815428c0e43257f62fbc4098f8277b1ab9abec3c3
MD5 534770e6ed373bba0684c56205084df0
BLAKE2b-256 289c9ba30618008aaae8fde8e3f5ce6c894374860fbde88545d1fd3a40b2534b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af671974ff15f909566f273d0cacc7b559a8e72d428bba4684e7745af6595e7c
MD5 755048f7a60f1ddead0c6e23831476d9
BLAKE2b-256 21857069edbe6243f4e5a98aaad8b910bfeda4cb0c31dbd87bf4e6e790ab8db9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 03b3bc5383aaea4b0ee689e9f648c172d79a202d647d4e586863c181da93d5c9
MD5 7f8a543da5481da5a1622d05fc212617
BLAKE2b-256 8501f6b7840f3b096e12b71ab62e3f60e28499f0319b66281da642d0337ac3aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1fdc3eb27718f55376d98ee5c8cae9f0dcc99196cb866fb437c08a18a2862d6e
MD5 b533c5e37b1c134d70ae6104e115a125
BLAKE2b-256 b1bf6188ea2e3c18e1669b1820c038a46da4018a663ddc7f55221d62036b05b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bfa9148728328de2dcb77b7b604dd51f0ade4ecbef69ee4867b4351e2a9e56ff
MD5 17e338276323275fd7117ebc111b2737
BLAKE2b-256 e5e1c92968924e6776c3c5705ff74e6d6f9edd175555887c62a6c607a6c45dae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae5820633804a8eb844453e57e79fa875a6539894783495472e25ff2a43fa759
MD5 c1466210d98724416d6e045406ed02b9
BLAKE2b-256 06e972849b4af5cfcaecf1acca93003aeaa1a903eae20d59bca74665db0e0a6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6aa108d3384b8722ae33cfbcc8a0afc17c83e1c81512bd8b444f5c246647c058
MD5 f72da0c8d8b63d70048c306e43ee5e25
BLAKE2b-256 2defcf5a8983862958594b699fb21934a8392f0ff865fdf7ac7db4a2ca86d787

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 77b9f98aacf7c7899ca1127af8df7baf704b62a512b448d2e3f9401038638fe0
MD5 488f12edfdd64562744fa182b16fd186
BLAKE2b-256 e55bc67b1293119bfc7a5b0ad13a335505005aba3e457bca6be8d079ac1f72f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a74653f6b0cdc103d4791b06cc3f010dfe75e55bf1fe4c3a49b04b087dcc54b8
MD5 a1e0c72417ebe815df2c6fb17bba5c1e
BLAKE2b-256 6ede1c33c3f0a3b2e9aab3382e35c36fe1342bfcf2df52fc39c25f06549d2c16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d91c11d38df31b5174edad520d0d3f8df86c245a593a129c6db7dac6f3fde361
MD5 c173585027cfc9d3bf4f4ce7dfa5a871
BLAKE2b-256 f3175bd60f8bece15dd17dfbf6183c57052be8b73f4163d9fd86985164667772

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782535097-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 65fc4f1a7c0a481b427ced91f758a7086b0ad3c0deb6f5eb6de708363c949ca6
MD5 0641160bff05234417086c78cd911e64
BLAKE2b-256 2c6a31aedae15c959b102bbe6fa7f7aa7ba347d844971410f1bbf65f80a78b8e

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