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.0.tar.gz (882.5 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.0-cp314-cp314-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

stim-1.16.0-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.0.tar.gz.

File metadata

  • Download URL: stim-1.16.0.tar.gz
  • Upload date:
  • Size: 882.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0.tar.gz
Algorithm Hash digest
SHA256 9092a996429dcf616d8d4ca01fec886b7b310caf9425a39fcfe499005636bd52
MD5 c843749fab62093a9be611fed1e57953
BLAKE2b-256 77bdc0f5d6241cdb806400a63e0c7febe22982ddf1c8761142bb0ea6b51d3f50

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: stim-1.16.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ed3aa70f82690946ba6f70abb9dad448d49ab9499fa5161de5f286da87c30ab1
MD5 0eb8752e6564e337e347c8db71dcda7a
BLAKE2b-256 f585be0fe295a5c5426aec0a2f8497360d9db8083d62c04de81bf744d29a131e

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f94040cbeeff786e7fb8860249e54d9ba3f777b5b098d21f1eccd072d3a3c32a
MD5 0aa640052de1f2e9155f5b135d7ae97c
BLAKE2b-256 fcb28535802f6eb5230678b067cde35b81fc612c612698f192b31164c6a19b9f

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1fa60a13ef921d6e6aea420e2fe7551d71a4a07b513d86da89e39259dd3739f9
MD5 418ddd159dccc8708a0b39d9a6993c41
BLAKE2b-256 b2d1a898d8e587a8718daabaf886f2d0c22c126a691886765096a0776b5b463c

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp314-cp314-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1e78fe10ab4c28af9ceb57ac8ed895f3efcde9607d851ef931c53d1f6f80bc8e
MD5 18167028fe20c58f8438827e0c441674
BLAKE2b-256 5bf84266593404f455c676bfe95785f865d77e98578fc4a35af9835653a65598

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: stim-1.16.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 55231457b5897b0ef798059aae01d9e8247fc8b2089e8a27f9f4bb13b0342af2
MD5 9414e85871788e73af457ec5b7260151
BLAKE2b-256 d715db7f4b80a0903e0962f5d824ca8cb5a962836399bd45fda59961782ebb20

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f22a009bad1e7816aeb70bdeafb6789e4840710da070f69cde91e2ac6cf1e800
MD5 f76d12a07c4bea982711f94663348af4
BLAKE2b-256 ddd16a9bca80b6ffe0fc4a3b0375ac18ff9fb1e815d152691332e55d1a9e5fa2

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66dbc6532169df84d127ceede353b15445e845a94aa008c5d0a4062b51cc2b02
MD5 e70ba3944445582a663a8adb9654d6d3
BLAKE2b-256 21409499fb076b819b479bffad35afd34e84a93c86f117fb5431dab211adff4f

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 1822adb4920f4616b253792fe1893ad07a9bea8cbc45b2f4cdf7c75a8083cd00
MD5 37aea7fbebb3d735e4442ca137fc414e
BLAKE2b-256 e4cfaeb85a75eca23907ba32c09c95340489a60ff608a9a18ebd26b9ae2e2323

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: stim-1.16.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 85b9c544c65377a42c6b5c9a57616a5ed5580e1cabb286a604800a045c7a12fb
MD5 86cb7201e6ac1c8415ef019b5f6f2998
BLAKE2b-256 bb650ddfa6f76c4a137aefeee4d51a65945e0ec77cc2221322f13a5768f4c488

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 883b24c3c95fa69818e931e8b60daf4fc8195d159d321e7548d8706dbac16558
MD5 36752d8087bbfe3184a71e600fd21f7a
BLAKE2b-256 e471db565f5bd0f273414e90d85551eed1c75f7b689847bd605a7cf0c4c0386d

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8580dfbe5ff27594dd15a83b24262630b82cf089d1463d29dbee90ffbc6898b
MD5 2398f87116bf198a1bc66a9c24e6ef7f
BLAKE2b-256 51e345a8c0889f4629027cbdd8ed8e9f5824b5bd8b12b0f5d24be27ec0c2a3dc

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3e2883216fb4f57411531c99dfa1838c0d8201c619ccd01b197b9afd54d326cf
MD5 8436a2a17f0dd76733f0477caeb82751
BLAKE2b-256 20d98b70c39860e67e233178a9ef595c15a7ec718f0b88bc424ae2c6ad8f97da

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: stim-1.16.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b367f90826e796417932ea46c0e53d80e3c5bebac0c6633c0aa07a8fcaa4298b
MD5 32a1bcf850e7f69b2fbeb9318ffca6a8
BLAKE2b-256 b887a845b9d17ab5e352eee30169a58bd8213e85ff47c6340daff2f8a25ed28e

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd2d28093818f981f8dedb2be160b62d818279b81748d72dc4fca6cdd160291d
MD5 92534f88844703e18487944b44722f26
BLAKE2b-256 d4d8a84d59b49395e4f8e080991915929c69e1e6a40c411a9c0998904dbf8bef

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1890bda08adfd6daa875d1d5e41039c5ae8c58faabc7cd1813f8d8de9f1536a2
MD5 e7663b7b96ace8a00a82cd7910071d56
BLAKE2b-256 be373742215d5fd4e090ce7ae964e43d978d1ac9865b5865530a6d5f1063a124

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8d44f858f3d5d1107e674886facbb011ed85438f0888278d6aa3c1f42d9e5a5f
MD5 f2651921c336cc68593ebe0d3d6f0b61
BLAKE2b-256 3f1d3619629c01407eef4042c22299afaf8d3f5fc3b0b26c98ffb4cd86f7cc1e

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: stim-1.16.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for stim-1.16.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 609666b77197d45705e1579a9840123a53cebe614e8bf1d496c0df24f797e653
MD5 0cb30c72b8f22e445439d37ae7120c63
BLAKE2b-256 4c434e5036fdc3c8bdfb4d774a4fff0cb8a0f44609ae18aa858ae37f61649cd1

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41c02d52af847e0ab886c35751e8f7e17e2e0d055e390ece93a50a12dcf87e56
MD5 f3c383a44a0177898c7103783924eddb
BLAKE2b-256 c53090d9ed81b10c4850e108b81346c2c6e2784126945342d591272ed090e027

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84b777678cc12e808b3d6747d57e07eed951f8ec18047a936dfa25dbc950a2e2
MD5 98366e041ba4bb58c26dc287055a12c8
BLAKE2b-256 71ccf7ebbe95361ce7b5c5da47ce024543846d6aca9fbbedd6833aeb33dccf15

See more details on using hashes here.

File details

Details for the file stim-1.16.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.16.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d467b5599de7e171651a1ff7fac353dd64d78df75d9c63e7d870d576eb0fd64b
MD5 4d925333736796463135597a1f3d1f27
BLAKE2b-256 2ac4b2cb8ed667da891b4835826eba3cb582c577ccc6980f15fd0e84d5e6491e

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