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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

stim-1.17.dev1782536076-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

stim-1.17.dev1782536076-cp311-cp311-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.17.dev1782536076.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.dev1782536076.tar.gz
Algorithm Hash digest
SHA256 86d6a46227354479e5dd2b113d46554fd9eb64d25d5ff973c87a676b5a53863e
MD5 a6c45a5a9205733fb3f97af8fc8b43ed
BLAKE2b-256 14ad34d6bfbfcaba7e090591e94842f1d80d9bc3626a390f096eb7b353504b56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6cd85f1da79fe48e723026c4305370b281b7843d497f8a5624ed6451af38da57
MD5 8a304881b02b79f89e877729605d4637
BLAKE2b-256 7d288f84ac230aed34cc486e0bc7babe9c597e61fae9c436313da24f0d53df88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a2177b49db9e7c9dffdff695489926ec6aa06aa7d92605c0fe2fb89b85a2266
MD5 f427d1cc85b65817fefef923d6237324
BLAKE2b-256 8fc4a1a014c780dee3c6f3d9cea8c25873fc4b47fe66c558ae484aefdfd2ee80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85772ba26233e339764ca101993cddbf1e81a05115463ec40f4a959ef33563e5
MD5 2db35d4a8b2a23ebdcab1f0a0821aaf8
BLAKE2b-256 dbdec1cc67f955b1b94af7da36c9bf27cbae264fc16975a1725ddbe664a1230d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 10e798e8f8088366c5ba5eb80938c8685b616829b564835616865b2a6dc6d53f
MD5 0e1dd3866ec990ce838b9b2b1a57e56a
BLAKE2b-256 3615b533b84f23489d961f86b5a1ab191980518f67df5707a8c2b4fce262829e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c6e4b5af3e11997746b52b172ae9297fb67c0c9473e3d90094593ffe9d6d6054
MD5 a1512eab8c34d00d2d7fd8c88171ce3a
BLAKE2b-256 2492c460aad6ede67c29e6ae9e4a84eeb77aa9741bba73be65281b185ea92d0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75d017c3321442e328f60207f5a4cb4f541d424e7f09a913dc339919657ca8bc
MD5 1d333139b79fffa11eef593806f4a0a0
BLAKE2b-256 d8561a066593bd3505ca8f5677b9402a32dcf91c79a3c4676e8d04e6ac8924bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 341d4903798a66136612c514bacac976ee35c556b750ca1ed5e0e5c23e7d1f8c
MD5 034f56764c0346a1b45076e613dc0d9f
BLAKE2b-256 28253f4b9a5b48fc531d63fc43ef680757d1a06100e316f213e9fdae691d76c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 cfea878e06b2a8a87fc72787aa34f1cd09e858ee9497adc9e0d005f2fce9efca
MD5 f0646c30dd4c19da605b78ae7a984ed5
BLAKE2b-256 602464c2ca60416c3da4ba5f4d2c5251dc50f3881d735b634679501b037d8488

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a38a40bb2727ff1e3202fb186eebcb885de9b8bfaf491c0e7e379dc85c7bcebd
MD5 ffda054142d46df70015cc464c64dfa5
BLAKE2b-256 3304b85ef21318df01a2ee82e27e440e7c656e379209d862005050dcd490c4f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e92f07ca32ee1a2e7ea7323011f237b1e75b6da7fdee379365592a6f518b40b3
MD5 82a4398b3543432fd4717be43cac2b79
BLAKE2b-256 f349dd2b557a6e8bbcd0f55443b69f21c69fe37b4a0336ac6dc6dbfa54ab31ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2abe51a21c03f1b79f7ab87b72858c38d930515656095354b3d91b293979daf
MD5 619a977f2e5f15634ade6134646aa9e4
BLAKE2b-256 8b4776b45948225857fbba0981f10885d282ae0f794444e4700bf28ae759d691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 cb71cc68b3234fc18305acefb4aabe49f550717fe13d03236c8c41bf7ab87884
MD5 b84d038447aa528bdb7d72577cdce855
BLAKE2b-256 e739c7b2256dad0d5c5085d6da6f420f7d2d31be88fad48599eebab543bb61ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 79da027258849a18f7d9e2f24447da9539eee8a54f20d7d6356545bcf2c7ce42
MD5 065321e0e03453dd32eac1e3b8062adf
BLAKE2b-256 8f8a88c6e7a3b8a27c37f1230aab51c0aee40a138a0fedf2e79ee294286d5eaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d3eab9b1c09e74570ff702388bc19cfc2e496f6911579346f957bc5a13dacc09
MD5 27bea1eb658cf49d78b7af359e5e75e3
BLAKE2b-256 c311b42c1d8ea4673203866c118bbc489fb407db74c235f41dc0c922503122f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f578d833725a3d9693d82e57b241cd201d1bc3cf547b98e41c3213993702a78
MD5 49219e7ccf5a150b3b0b17d3d02125fe
BLAKE2b-256 108919dd4f161ea1d079e5f6961abfa3be01fd98864a05b5fdd3f62a7207f2c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a63a79cf3ccedf7e95c71ef69a2f023d6e923999cc11950678d9813bf6229600
MD5 6a07c568b1b90b4b37b3ca813850efa5
BLAKE2b-256 698bb860a53688a4bafce67dd2eba402afb0bc44a9f915214b382c1d2b1ed4d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 87a70696376d2338b44bc03e700d6b8203f13e45c31ee0bff9f18c174b74d9dc
MD5 f7b215274b94b0f83a09885bdbee127f
BLAKE2b-256 f26d9768c23ac86aa70579ea4cccfbcd0208cd71f4e2be0c78a09511de96100a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 652d37d9f29ad0742e3c6771a76d2ab6695082ec3c2bfc8f02eda304433f7005
MD5 aa8d8a364723a2b5610163393d1868b7
BLAKE2b-256 9d46af53c01fa111e8bb49f6b22f487f3448c4817176df0ece48318a7770be00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2965199cbfb325256a91efe9dacf9cb356e361dcf1d16ade9f2ba01d745fe832
MD5 3a610163d38d912eca229b71b11fbbfa
BLAKE2b-256 748c7796576217214c652e8c49291103281f4ff02784f35415434892ab62370d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1782536076-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 de0945246ef86cfe705f5526cdea5f6f9d24817e64c2322705f447f7e7ee53f1
MD5 e1ef8f6151e820425ed5967db8ed9ff6
BLAKE2b-256 2482361c5a5aaa8d161fe9235c92998d5949393d0a14cb8e3d0e0182edf839c5

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