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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

stim-1.16.dev1779425858-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.16.dev1779425858.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.dev1779425858.tar.gz
Algorithm Hash digest
SHA256 bc15b5e7b5f6304f725455da998eed8a6d6f4dfbf1879ba7932228c3c5056edb
MD5 4436e070441d4d68c114d735724e7dc2
BLAKE2b-256 f79522e1ec0367dd140b2408a4124957e189653d445de4da809d15c5a300ff75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ff221848278e382ab07d8cb825a30c7317120ceff21ec3b0fec3493f18222c52
MD5 70e4132e252a7ed48e24dfd0d81f4179
BLAKE2b-256 6a7edf7efd435fe908c90d7efac1ec5129aa6d4fec00db678ec517276c3491a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c10db86d434b9056cf5c2763ed2f16e49961834d16172548c73bba9247573950
MD5 9c5846394e90a270febf17e01f48ca86
BLAKE2b-256 245844371c02e312bce19cdc2225a25850d2e17f772ec8c2da33d32db1a0b992

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27f12310723029995445d86d7389139189e6e1dd40bdf45457bad2d5ac55fa5c
MD5 5e7b108399957c10e7e78e6eaf65c05a
BLAKE2b-256 ce929cc264046330127b6f6c315e18b57a5ebbe257725a6d96783624fd7343c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 906c580b57f8c66b689777746b65a6f455ca0c392a78d6868e4c9c7bcd22b6e3
MD5 56a4871f8e56e862ac4c5caac9cb5335
BLAKE2b-256 a1b7378ae5743efb6abe55320d64e4de13804898968af08769914c91c5dcb793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d0a9aebb73b673edd66783d44a5ff9b35426b54d0cea0b700dc8060a368e0163
MD5 f6ad2c04ba7794cb0743197e812fcf3a
BLAKE2b-256 ff03f154c3e68270073266573849edac4a41a43b5c9b740ff3c49d6bfe216ecf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 46b5b27a73efe022d16a5afe9f70624978dc2248d742801d5b0b50d0ee1b5616
MD5 d8b24c726a5e58927df79341f7dca35e
BLAKE2b-256 7d375b9ff8e3c07dff49bfb2ddd2fbb775fc7164fbcd4e8659a46dafa56812a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 08563eb819af3ccef4431c00fb85b87feaeb94b5d407e4e6ef5bf3aa5a41444b
MD5 6ba064afad1159a622662b3dff40ff50
BLAKE2b-256 3b944a4713c13e9f0d306817168c856f59cae75e374c7ff0bf40b8eac4b95a6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 eb62efada5f75dae31e7d4cba57ffba9418ca8214c9ace519f4cf9ace104434b
MD5 6219f06ff23ba1a27a388b794630fe7c
BLAKE2b-256 7b31d66a1712340bee30d24cbb630f6db04da94c390437b32d71c7f117241b40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0d4e8aa411404a8f2678320b4acd1961782bf6c972979a36c7285d579a62a9c4
MD5 7d618736c84e7e435889ebd1eabfabd0
BLAKE2b-256 026e32f0ea382cd49ced05ea5ce8326f6017eebf1b0238e566c7c955404c161d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5e7b8ef30151c79716e773f8f1df4df83681bfdf895011d2426f27337a256646
MD5 eb1a5a4ee0d53dab68e03d8acf8c812d
BLAKE2b-256 33acd6c47afb604283083c70a7dc06ab0580781079ae90b01db9f194f9bfd34a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c127487ec5acbe1a9dd86433c1f0bbe237dd852b3ea06e7736d38dce2b1f902
MD5 29030c86bd0f04e940782a1cb6552106
BLAKE2b-256 771a8375937a02f73bb0971b03583ee7524432433c41b960a4e11746d54e6f81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d59412ccd39275ea85121d1bfc27bc8291fa5506fe4cb31bce439997ee462d9b
MD5 c72756f4890b385cf9659b5aecf3cf6c
BLAKE2b-256 ecac62e95b67463d12688ef8eaa5c52401e3ac26052d9641749bd422f373d4d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2f83be727f9e12629bfb64d9d3d4cebb56534326561b2e90ae063b2d8c8ce047
MD5 15e640186bac63b3c841ed7995260b46
BLAKE2b-256 0f7a561776cb5abd707568dffdbbcafab69f140db7ed1b8b1aeb1b19f693573d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2052eb88c837687ce96607495f6d267cf93f22b3198dfc9ec5644e70ae7f2130
MD5 1c5f63d22aaa134022d000b95d5eaaad
BLAKE2b-256 5ef7656f063d9f188df7a20957e69e984305d966c0984c979984760f8ff616ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7523206fd3d508722176b1a20dcdc84d7d00a4efee1f78368907190992386714
MD5 e6060152f8df146a55f507c933870fc0
BLAKE2b-256 28abcfba6df8e8af5178aa728f7ed503fcd321f237b292d017113e91d8a280a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c22febb1f52c3a633ea11695e28d7bc206072b1de5f0846180c75c2df58e02f6
MD5 bbd34870843b82f94dd2b4699df0a85f
BLAKE2b-256 8ba6937ba2efb5fb39def7833925111e13772a1ae95284ab0601a5d6bb3adc8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ee603239fa7297eda9e392406bdf976488cc908b7586b8e281e41813f6cef2b1
MD5 4c9e91a79fb74eafef9ec179244131ed
BLAKE2b-256 dd671f4a1aabf3bfd26a0e0e0bbb3db704945f0fe7a962bcec7a5277b98470ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5558d3584573f77d0530fd94cf49d1079402693edb74632c670322dc72f3a9b7
MD5 1f664c59c4a60d022049137c60b7c829
BLAKE2b-256 3e44af1981fde45fa84b35cce5e53984ceb2236fd6289cd7af07a139d986eba6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6910202a01182faf76298bffe59dd1ce4a82388d3a748c8bf10fc7b7584972b2
MD5 08aeabe789e6d1632feda4c1a1da3cdd
BLAKE2b-256 6650f2384a4f586729ff7c3c5b2e2239be9ce7c588589f74a6a45f4de30a707b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.16.dev1779425858-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 332f80a98fbbc67cfb85ef1e66faf65e10dd95cf6abd72e6cf83225db17dbc2e
MD5 518d4870235f5ab7637bca00ffcb0f5e
BLAKE2b-256 3b4e2a25abd63da335e6be92d3fb19e662da5b2d35b821d4a1a0174986679f05

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