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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.17.dev1782599698.tar.gz
  • Upload date:
  • Size: 882.9 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.dev1782599698.tar.gz
Algorithm Hash digest
SHA256 fb40b55f28a241f2e8087e68b44dd5995ea7cd1f61adb7b51c9512e1a76a38ce
MD5 987ed57cd5bae682b23bcd695dd404cd
BLAKE2b-256 941cf626c97912e50a516e2d807215cb6bf251e7169dad582c0db602b5391845

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c7c4d6ee63f16c623eda42d72c1f5b8d15447ccdfb26fe81431eb46cce4c385c
MD5 adb7b54880474f817015c05dd6bd46c7
BLAKE2b-256 c6a9479d722bb4c0cc41e84d53d9beb58dff4539e23c8da7c716ffe8229e079d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d7c948a953e4168e74ca76c5fe5877c6aa0ff3a3f22258cf53d00da198f80fe8
MD5 4a107eaeff0c9080f76de5670e110f5e
BLAKE2b-256 a57ef16f39f119e6174029fbc85c88ac46f21cc1e1f3f0b8f7c4217a30eadf29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2174dad555782f3ee559cb89e0bdca91570e55ba1e59a0592cc017e77f13168b
MD5 c5199a535545661daacbfd4f311a3bb9
BLAKE2b-256 59d911832a7a24d41fe57c9f2901d69c152e18963829eebfa52b48759c925a65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e5db9f042b9d9d9d127cdb8f0e634936cdd6a884129d1fe3c0c3fdad4ef1053e
MD5 dfb01cc39c47a11cd728b9b9dc45eedb
BLAKE2b-256 346eda5021ee3edc79d702a9cee415ddfbc47711d9cb92c0221164b401b5f2cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 be7bba638782b1c686f08a10e8b7e01329101f5180edf2efe7d0bc9d2c5ee702
MD5 44efa0e9960e2f8370a77dd36faf6f56
BLAKE2b-256 b85729bd4e8485289c6d05564fba8265f7bb020844676cf484a230e41eb3e431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22f451a3aa15eb39e7aa5d411ae5361ec4ef04912f683e5d0cbee076fd2896f4
MD5 e0630220e33b2a2acccdc6f7e83ec872
BLAKE2b-256 fd33dcb2f24053cf30ecf51e5c65043ddff7bc512e6464b9a7d018d29adb585d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c6b4388c6527d40c4e87761fc9b1d8b4193eae84eee1f162eb04dabed89439c
MD5 43cf904b36340d46d8a12d786dd523f5
BLAKE2b-256 c5eb73145edae303f6b68b5c8a60baab898c543ecd0ed0dcb0555d34a2d2d78e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 696f1be3d50c7d2c7d5f747d4b78bf724a861fefce1f8b8f4735277a2ea28bdc
MD5 96173a1e7bec6a6d2734f3b29f26aac8
BLAKE2b-256 2a9b17ae61b06cfdc5e53d111e11fe8e96b48b48ed2b25e4650b8fbb396686c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 31fedd201c06e80b7ae9d593df2dc94899cf82b71302c5269ef018037ae52b5e
MD5 b89eaa249fb38857b53b74068cc65a09
BLAKE2b-256 01738838fcc7eecd180dc59f18516144e2164ebea462c81f224339eb7d1fc077

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 63871e5d822654c0cbc4bc25018d1d1993997f94d33cc549abe761796135901b
MD5 465af8f9e3ffd5deaf9b78c3dc80d67f
BLAKE2b-256 39d7fd810483ac60805557c42ea64a164585c92057a2bacc8ada49bc8cc43727

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2ef0ca346a87c11f3a1de815e87f27e4f6f8abd01a9c991681a301ff3275285
MD5 27a8e7f4fde6d728a7f688e2b440b279
BLAKE2b-256 2ce9d6ed0c093ef2decc8f217461e631c1d5713b4dabe9a1d91c1b1795585121

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 0bd6cd23e2665218a9cf4e8f0e6a15be9815ca1d2ea501b7ead299da98bf2220
MD5 a0510f4d9c87ba1433385c2f2b2bbcaf
BLAKE2b-256 d41a00485b16abe35189486d361113c4a15ceb70014152970b0d72b8bf547112

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f3c048f256a856e1b84f8036364537851ec2dbb77feeae3c51d8f0b16f10989c
MD5 394dd467a1ab38855d09f84305da00d9
BLAKE2b-256 40936083b4e0b8b4432f5387d8ba8ec6e8158d31baadc0d2e14bcf42d6319830

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dc44049fcc2553f81922f154d570f6548f7a2b214fa2dc5dcda6ea54c19b17e2
MD5 9fcd3ff2f2433dd7b39330bff1dd952e
BLAKE2b-256 101accebe7773a2585815f4b9d49750b227625ba56be1d4383c8d24c05148504

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9cba5bc3d48af5d2d8ca160f739ffd269e75cac1d08e5a6b4fa00443abb1ca9d
MD5 fc13c492d9b48de3513f65644d7e8d39
BLAKE2b-256 03eb3b4a006f35ff51c7249192369b5b4ac53b61b03358cec0dcdea9057ad67b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 91150ac67c09e535a5a7301b099742df4d343cc844ad7e755ba668fa2de9431b
MD5 360b0bbb2fadfd6ce15c5eeb0afee923
BLAKE2b-256 798200ad0f7fad7f7689adb5141f7e924c6a5e0cd2a8e6e3a21588ad89e90002

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2f8ccff24f83c3af1dbb5c564b9beaaa3ad42d0f5cfe7aa5d3a91f9664b2e909
MD5 37ead8b3bd4976908f10583e772907a0
BLAKE2b-256 42497d77d3652bfc29dba2f5195a2fed05cd1e872288c16920344ed5d089d095

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d215852305caf841cf458540fee142c7ee046107a3a419252b1ed1517aca6c6
MD5 21125f794c073ec39521fa77dae7a54f
BLAKE2b-256 75ca5b8bce41dc434349c461deb2e5ead6c806332e63d52b397d22d343824569

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 204c81880b3aca4d0c6da33a595a98482303f726ee7bb4946083e6b8e343c38b
MD5 d59c65d29789d5e71b06235853b6b05a
BLAKE2b-256 e78e29b99dc31bb48622532a0d366eee993650b887b401c44db9e95a793df2ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782599698-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b8d8163d86dd49d659c373c7f73bce1796f8e5ec58279d9bb896a2338790a826
MD5 813c67a735b444824a1a5da2ad5fb718
BLAKE2b-256 e41f9479fd067388e848226492a6bdca958c1665a714e8f0b5af0056c52168ba

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