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

Uploaded CPython 3.14Windows x86-64

stim-1.16.dev1779421376-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.16.dev1779421376-cp314-cp314-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

stim-1.16.dev1779421376-cp314-cp314-macosx_10_15_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64

stim-1.16.dev1779421376-cp313-cp313-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.13Windows x86-64

stim-1.16.dev1779421376-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.16.dev1779421376-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

stim-1.16.dev1779421376-cp313-cp313-macosx_10_13_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

stim-1.16.dev1779421376-cp312-cp312-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.12Windows x86-64

stim-1.16.dev1779421376-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.16.dev1779421376-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

stim-1.16.dev1779421376-cp312-cp312-macosx_10_13_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

stim-1.16.dev1779421376-cp311-cp311-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.11Windows x86-64

stim-1.16.dev1779421376-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.16.dev1779421376-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

stim-1.16.dev1779421376-cp311-cp311-macosx_10_9_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

stim-1.16.dev1779421376-cp310-cp310-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10Windows x86-64

stim-1.16.dev1779421376-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.16.dev1779421376-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

stim-1.16.dev1779421376-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.16.dev1779421376.tar.gz.

File metadata

  • Download URL: stim-1.16.dev1779421376.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.16.dev1779421376.tar.gz
Algorithm Hash digest
SHA256 491f6b7de087eafe96f25b58bafc76dcfad342ed0b7d3b045f8f0bfeaf41fcbe
MD5 548b9c879cbcee2f9d0240fc68a425b4
BLAKE2b-256 1c07218d675de4603433e768d1502029dffbc97365b85c077b10e1eb5e885bc6

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 65b922b73db2208c5da5fb0329eb0dd8000d8453fe122250f4e6cf712a8d3675
MD5 84e75e13796f8b916715ed41b0f645c8
BLAKE2b-256 fa67a40852de47f11b048f9c6d6f1cd9ceb18713866a497e5eb239cf42888c5f

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 216bfbfc110f7c1a5c7193b1626c604e3a7235b5812ae97a4e00a10833d69982
MD5 79a4dd5bfcb252ce0e6e05d49b40d10b
BLAKE2b-256 a1ad0d6d037935910907e1ac310be3b4883112dbb7086217e988bd0f1c94cc4a

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 936e4b3fdc8f49d78cf912f96c69cd09b388dc688f01414b502066a816f31b35
MD5 eb0146db5ca3c8cf13764b408fea509c
BLAKE2b-256 8ae9252e9515851ddd934dd116b2d8fe5030f57fbaf5eed7a72d1420ff51b9b6

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5c0893d6ca840f156499836639621883d2b02ee266b60c5b2cada709b48ce90d
MD5 deb7a0766a487dbea684a2eb08b92737
BLAKE2b-256 3d3ced4408d1ee5715e7830b4c5b7fb0c048d0093f42e851ce9ee33ab340eeec

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 41e0c2654958d9283e9c8bcf8b177545a9d3ad0d95a669df93daea70c842dc6d
MD5 ccaccb278062d2911a5e181fb454baee
BLAKE2b-256 e9582c1ee9e5248715eccf353704a7b16bf713838e9d362071aa0e2b31409d05

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4b974c64ff37179c28c7625cd136192870527061c38ed2f6910309718e9ded8f
MD5 c5b113602ba7de6f508e5bcbcfd76be0
BLAKE2b-256 44e842a78ea2fc013ae7a02817810bdbb9bf2d6e160fc1b9d473131715806701

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d3e53cdad4362d17b50e5d979fdeef798b0712853715cfb70715c99c48e4749
MD5 19e5a0212de2a15051e1798caeba3a5e
BLAKE2b-256 75ce025855ca81054c2f3b9221491d9157ed9649de9316c6cbd99edb685fc252

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 16f678606e272cdc9b285060b8accf8a6a78e7f53314f0869e0ca0687c069bb4
MD5 66fbd9c5c3bf0118872a118b9363159d
BLAKE2b-256 4a5d0b39f48134e5feba50cc249b9aaf102300d7dfa41cda2447d0b5972e519f

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a04abe2827cc78d7642a497d479f69b3e8e1f202d7670be1b285bd970016097e
MD5 d38b32f8e784706ca2f4f1ab95d83711
BLAKE2b-256 ef72a24d66d7251f7094eaf0708fe6e1573a782bde905fa69a2366f0acc26aaf

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 853c04bf7f9188796c1dbb6efd6ef17aca605076fefbf2e14a75157fcd986b85
MD5 7bee0023940d7122464e918ac064cd73
BLAKE2b-256 7c9a58befa3f535535de74bae529835dc90e929bff721afb35039177b45d5fe6

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fc01f60a1fbd168e62d8a2fdccd21c3b7465e34d5fd374ddbf82a1c8629fd045
MD5 8f8171f358635f2b3b97676b977144cb
BLAKE2b-256 d41c68e7595592d31fb756aeae42f2dfd67364d4a19afb167e640ffb21b4c95b

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 fa0481dbb50cc15fd509e72903a682390a27ff7a2b8675ce8b178f60a8c8adf9
MD5 d938728ec016071c9146a2aa811ffdeb
BLAKE2b-256 daef53349cee52f7f265bd7d57d551750171aae0a55cdb7e54607149d86e8549

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 934069c1cc8b41b46357a6e0a54ffbfa7269c5d2799e24eca72a1422b4eb5543
MD5 067788a9122f3710ee9d3ff61d04099d
BLAKE2b-256 d2bbefac5990516ebd5e982568b2534da6b8d58bd51b551dda68688080cdc2e5

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 561355c7c5a8640db128aa43bd5240950e8df91a34ed49255e37c5dea41f26af
MD5 49484274953916847381fbf6a3d25be3
BLAKE2b-256 00a8de1848d8ca7d3ecf483f969b825fb0429c6e878a1752bace4e6f14017503

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7c0c54e91018aec05afa5b4f5fd05c033e5abc0afdcc7f8cc0c55ff56b1b2bc
MD5 2811c8d03939a7ed5e265c434e51a1e0
BLAKE2b-256 2e1d457b1c397e5e8625b675d9dd2de92267ae0111adb53a039d273048b29e4d

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 31950b53ca7e2d916ce90e60d8789b84cdeae6a462b593d249a86a10fbf32c0b
MD5 36b7f014ebd8d82c466db03222776446
BLAKE2b-256 f64fd65452e81b4eb60bdee973b9ffa81a0f62db33f23ed6d816e8dfe4dff2fb

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 299a99b0697dd0066efbf3d2e4904279d0464e074d7830176293d68d6d3bc119
MD5 62035554698cd0430d5fceb80f764e59
BLAKE2b-256 c0ac9108488eb9f785bc137fdff70d06b35e8d0b11cde7f773b214e3d2103b0a

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7c0abf3b70595bbb9c3ade9d89747f9f2745dccff9e5c0443fa4580bd7f3ceec
MD5 ddccc0169cbc9dc6d46d7dee9b53270a
BLAKE2b-256 3410e8c5eb1892542e104137a38d6641f8fd964ecab27abeed5f7ec11437ff5f

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c1d611eb374962791bbe3b434fb4465f1301f95fc58e2f9ee1078292cedb265c
MD5 17eb27f1f73e1dc27dd9111ba96ec5b5
BLAKE2b-256 4168ed134b7532dce6b15c26220c6d26f610579faa7b22ad7b4310eaac255566

See more details on using hashes here.

File details

Details for the file stim-1.16.dev1779421376-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.dev1779421376-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 31c2fab14e6f777ea86c27e645cf667ad86aec59d0494ca845ae7549b14ef81c
MD5 ce847dfbebf62313d052da4aeb27be33
BLAKE2b-256 d2ca3b147df7ffc2901694e2e330a1d8e858c04cc438ecdfc97db5da4c877fcd

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