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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

stim-1.17.dev1780897841-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.17.dev1780897841.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.dev1780897841.tar.gz
Algorithm Hash digest
SHA256 71370a7db3144bfe047c38ac6e65506326ed8ab9de58a7240d66b4823a318c9b
MD5 03d832d304645076abcf7d3057ecee72
BLAKE2b-256 dac6ce83cac749343be8f0aeabdd262f17e3223b63fa5247bcca79c897d31bff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 120d00b01c4ba1e744c7687d6ae7fc4fa7607d7202c059c19238215410226a44
MD5 ab4c8bd4a326e958260ee75dbb0c3916
BLAKE2b-256 a15700461b241142dd5e5f69f5be29b7e5f51a099200abe0ac111c17dfad033d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5aa41211c79d0528382083f8a850b27f94c52132b82976dea0c3b6fc0039ee89
MD5 d568a71010dc94dff14c5e34b892430b
BLAKE2b-256 6d6c7a2fb3d89ac8fb0b8bcb43e530f10e302cfb2d8d6d3ecfdbefbf0bdcb608

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a19bf037d8c99e2488541f9980ede90623dd2f8ec0f72353a5eafe643d6572e
MD5 0ae7966940216b87eb2b5161bb80d28b
BLAKE2b-256 29486b8802584246896149bdc184c99385a7d5622ebef1a7d149ecfdfc102530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3060629dd7136cb3b893510ebc4730f8fb8dc1e28df943969c3826dcee883ddd
MD5 44340e9e505c17c7bc7d300b3ea4ceeb
BLAKE2b-256 66d40ffbc9408b408e1e9c640e5d6136cd06cd7d38b40a75a5fabf575b64b220

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f7313a1c174433b988d40d7dd0d3fc553f81567cc73ab76f9a9d452e29d73100
MD5 ee37e7252d17c5696e02ab29fe66f396
BLAKE2b-256 71f46aa9590b8c6426ff0340d2ff034b595ebecc3273578ac05f80f62d2eda83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a0a8d9d2563b0e97c4684652e824e851e46388400fed3092fbb8b747cb92d348
MD5 4f3b868ee125552bed840ba1f3fe499a
BLAKE2b-256 a60d8c44f44817a270e9bb118935fbfaa70edc7c626e50350077e135ae46089c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c1e7ba36deefb420d492f5ef2a7f4acc990b3b0678aae20daf2615e18f85178
MD5 94515b437fd508c5999adfbdc82506d7
BLAKE2b-256 bc5b7c81966c93ab12d3aadc448e9fd8d90f76e771e727494d38f0c3ea57b0fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8dd50859e22b28cec3e2c8b660e92547dffae0d2ded46c846dc85438b7b700bd
MD5 e8a5ae25519319deb77836de86f9ceef
BLAKE2b-256 cbb359d1a71dac4b1606b10e919eaf18c6da1f2dc05582357f2879ea47d459d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 280990f9b0a29360bc3b5b950d71b66145233c16205ec4e11abc5ff13cc01a1f
MD5 473981b388ca83e688f4ee8e1cf569f1
BLAKE2b-256 04e732ceb7933fb568d1e71f201199953bca7725dbf61b84553534ff0222001d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99c9a6e16aeb31403b0807add4cf09e5d0f23be727d4f9e484ccef1f4b77b9c8
MD5 709223bd98d98822a8ebbe0a0dff45ab
BLAKE2b-256 ed1f291c402f149111e27e79c715c471d3701f0268f08304c02ba55af346534e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3c6f259da57921fba7057477f04ce05f06647cef3a6f623a991864119215733
MD5 9c0513e257b66873cd2fb08c9c05dc12
BLAKE2b-256 8649057cc0ddf4189ef0c291dd5c1125d8f7d4ef39dac1eff59d7577cc2a3757

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 30d5ce03a733eef179e8b8b04fc6927c466288e005a5f2797fac444d381fc606
MD5 901d45afe62c7734fa390ed714288867
BLAKE2b-256 cfd9767d4e5aa486338cf90138998bc967bb1f0a2e1d28400ec978b42de6c7c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 27e21698093907bc17b3cd6dab0cf64199219617ae493356de5e232bb9ae8a2f
MD5 6a192d5605403ef658233c52ee7e155e
BLAKE2b-256 24193b12183ee13213bdac33dd78f8bb540c2f5f341643146a7aa0f75748b857

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6b4b3b8cd38622ae0009fcae71aeaafd9a8c29e826eec04edcae21014804d9f5
MD5 c260a903e89b300781e362582f0162ef
BLAKE2b-256 bccada62a2af29d95169a55fc67629a70f5036953b6304f576dddabf3d7f1f41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e33730cbf2da093b4f1c4752d31482772ddfa4b53616926beadf1d14345165b9
MD5 c11a371ac3b5334933982b4a0a88b8fd
BLAKE2b-256 6ffa572e8be45710128475f0245b3b2e17a586bfc452e77c7e043bba2ba3b554

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 052e5de87f0e7e9ee98986254063324600879db5689fab99e2f81768170c4299
MD5 d7dc3173c1822ee40bbcd28c9d94f31e
BLAKE2b-256 8d3a8253c551a652521f34bda0500c1b38bb6948128693288ecae887f626ad9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e78a11ab7871e4b09a014733c3e2172a1066a3ad13b869a921800584ac7bcbff
MD5 6fe81b924242ca52c5f21d5f8d755c1c
BLAKE2b-256 f5916294b673530fc68b160dc52058435e34347a6aeaab3b83dbe28b0ee24071

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1aab79108e7c36f4868f439a9634b1ec35cbd4fec0c4495c2fd0cefa31684b15
MD5 0bbc0fef609e4973cd666ed099eea109
BLAKE2b-256 98b816f41b1fa4c007506b1d5674c0ffe13aa040ae3467bf02939c30988118ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 510f9d70e3dc190c2d50185237c6c316ce32512efda0498c6ddf15888f96488a
MD5 ab4ba6429f35da2142699018554f8ee9
BLAKE2b-256 5d36c40b4a82ec9954afcd18f8681016ee4b6b213be1262086d280252cafb6e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780897841-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2b03e4c9779f61e6e205769841e7d23869bfeb60a8af5c6b8d51a714916ef3c7
MD5 d590a2780d74534b60c80639ac0f0bc1
BLAKE2b-256 a45c6a5f7ffe578c39aba92dc1318901e24818fda2142f211d9cd374176250bd

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