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_operation("H", [0])
for k in range(1, 30):
    c.append_operation("CNOT", [0, k])
c.append_operation("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.9.0.tar.gz (348.9 kB view details)

Uploaded Source

Built Distributions

stim-1.9.0-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

stim-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

stim-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

stim-1.9.0-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9 Windows x86-64

stim-1.9.0-cp39-cp39-win32.whl (1.6 MB view details)

Uploaded CPython 3.9 Windows x86

stim-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

stim-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

stim-1.9.0-cp38-cp38-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.8 Windows x86-64

stim-1.9.0-cp38-cp38-win32.whl (1.6 MB view details)

Uploaded CPython 3.8 Windows x86

stim-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

stim-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

stim-1.9.0-cp37-cp37m-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.7m Windows x86-64

stim-1.9.0-cp37-cp37m-win32.whl (1.6 MB view details)

Uploaded CPython 3.7m Windows x86

stim-1.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

stim-1.9.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (3.5 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

stim-1.9.0-cp37-cp37m-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

stim-1.9.0-cp36-cp36m-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.6m Windows x86-64

stim-1.9.0-cp36-cp36m-win32.whl (1.7 MB view details)

Uploaded CPython 3.6m Windows x86

stim-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

stim-1.9.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (3.5 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

stim-1.9.0-cp36-cp36m-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

Details for the file stim-1.9.0.tar.gz.

File metadata

  • Download URL: stim-1.9.0.tar.gz
  • Upload date:
  • Size: 348.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0.tar.gz
Algorithm Hash digest
SHA256 7d71cf4a1033de0d1932f7b7408602bd5683d28fb2b65e4b15aa67d27511659b
MD5 cb8221e5cf670b6866a041ecefc0a738
BLAKE2b-256 d4c3eba3f24b52d2c1ed2e7fd5490f31c7cafa4a0a82b9282b1ffee94eee8a4c

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: stim-1.9.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5db0d41f51e3921d4f6ea6a4c755d495f868061b4ac67cc10a3463eea7a55da6
MD5 5116500e3745332d3e0b07e330438e6b
BLAKE2b-256 bb06f8c54e2da639e7ee379b9ecfb23e1b7ea446c65190851d418545fe353d81

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf8caf5493c1629dddd888d23e824804a3f552156d0d1d5a349bf875caaee0b7
MD5 a2a38927f4138a0ebad96513cec515ea
BLAKE2b-256 cffed982574dfb0abbbffae6e99e52cfcdf8958e2443463cafe2ddea1fa32ed9

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for stim-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a8ab3fee84eff33651418ece05dea9e413a1c95fc9e2f1e73a705b8128a4d65
MD5 f742d872535292ba2944860faec6d3ba
BLAKE2b-256 322985a67b355b67ab7e2a0eb3cd3bc980aa40ec5f8fc255cc56a7cd6c4f9874

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: stim-1.9.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 bf510dc9987a4ba4bc2a5d03ecc0060d4718e57ed8700dd92b89dc2e87721abe
MD5 041d9a6a62ea6f91435c4df6aa9dc48c
BLAKE2b-256 edfabf80c9ccb6a403031abb53af05a3234983b35e32811a3e92257fa1877527

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: stim-1.9.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 e51cc1c5cbfc06ec01b4bbdbdd254f21f76f72914b0617eba136f783042aac0a
MD5 2148bf3b36f931fd592b10b063b5f0b2
BLAKE2b-256 ae3eae0dc8f3fb57d00c403ceff6140946ae15422666377c09dd26b6fe62c332

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a48eb723ba895b68f5c4b569daaae81d1c36b3250f8e0b629a6320899bf278f
MD5 e4a10e0a84608d3c48c3320aca32b8a9
BLAKE2b-256 3b5c866b8ea10abbf48e161c67a6fb70cfe809b33399557ceacd5b04ad87880a

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6c65b8b41423136d0e10b4578774b42db9ce88c79d091b8e3ccfa259f43121bd
MD5 0cfe0663896d67aa3cf1fc3c02848f72
BLAKE2b-256 ebe45b6f3b4fbb1a24e2923fb33f99284383d4bdee1c676775937647195a49b3

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: stim-1.9.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b8f28305c93d3e10f58f64c55dfd3781c3fce9aca4221746835fe71a9bd31880
MD5 b127eb3b8867fb82b002b6c583da4993
BLAKE2b-256 0a8d6958f8bff9a0521aa1d3891a86ee0d90b9ee72eaa9ae32b8b8a9e382a4cd

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: stim-1.9.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 63cb5302526fd5b0474959facf4e01df5c7aac7814d0ce662b8e772d491b173a
MD5 b8e22dd456fab3414485119b387aff07
BLAKE2b-256 5f92101ce16a8ff17549a4ed6c837c94ad6394b6ece14b278ff4dcc498933501

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c96dcc32903ea08f1429648eec36c6fb38f90f009431a234e1f99ec50dbb838
MD5 b62f32135b6add63e6271bcdd8395ff4
BLAKE2b-256 1398142a24e3c1adfa3ca4d03b489e523e421f00f336829628085258aaddfa66

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7d6cbf4c82e9217d896ef3575bf546344e989015b4070ff6a0695ae2f5915014
MD5 2d398f5a52053cb01fc077fd0496c051
BLAKE2b-256 1d3363dc137e9748a34a98e8777a417f62dd94569249669b5bfd228531411d4a

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: stim-1.9.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ccb0f20f3f1f60f2e48034cb541fcd60e46487e68a9a748f787478cc72e557e7
MD5 eb04c56f90c3eff3bc78f72f00103cd2
BLAKE2b-256 37669437bc45e1df6450793b61e8584157d460dbcbe734ed7433a0922c3f1496

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: stim-1.9.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 df20ebba508cc6b0afcba44215612ccdd7cb0b3c577c3d44cc21b4b5eb93d1ac
MD5 344640e282f483f182f1353ce2d72205
BLAKE2b-256 55a6fac15e9ce9eae9d925661e3d50f23f6613d96bdca5c367360c9ac7e650fb

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 992db292c7bfe619a0a9180b0635417ec55930e8dc9fdba695f0b13e1f26584e
MD5 feabf2b92cfbc829660ebc6e6aac6b83
BLAKE2b-256 aae17743c5ce04f97cb48dbd15a90046cf2aeff9046d077d85eb57608256eb60

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3c8c271a3b71081ca2b57d0d072ffaa319cb357801b309cf09748b984e15659b
MD5 580b3549bfffaaaff82ecd572dacf498
BLAKE2b-256 c3507a904a7342ed3d8c71f4812f0d93cb7a492a216d5db12844e478865fc8fa

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b9cb0091e10b9e247762f3ef4e8aaa8d1b899d6021bca3e9fd19f98a2ed9a158
MD5 7c3dc9222a99b0912719cfa7e669c32e
BLAKE2b-256 3af4b34fd44537e25b250de0b142aba690997e9220cc38d2f8277fce2370260b

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: stim-1.9.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 382bbd68d76049a654991d33e90723edcd7a13effe5da5dfa31a3d1e9310c74d
MD5 b64c3993cdb7d1c4a7f0d745fcd7a1eb
BLAKE2b-256 ab533a1edc2ebb313f79b3a4d79618badb6d86064fbcc9b2bd37489a64ba0d93

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: stim-1.9.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for stim-1.9.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 324c2023f5625359a34f181159e5475163f499f08826b25924df590cfd2503e8
MD5 7188899952b5535b0f6d708696d8321d
BLAKE2b-256 919ee60bd965da4bbf1373a9f2ea42f1e317bc5af91fa3a776992d200c5e3fab

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a15b3983e27c8b871c99efb94c2a3455184d1e711a1e60d9692a3fdb65494c56
MD5 eeef4f188ddf90c02a3a7d4cd0764ce5
BLAKE2b-256 229f60538d496b54d84686c0d669f5bef07ae1388068dccc9fbe1c5c62d38710

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4a671679ec84f10a95fe96494c85ccfd88a1bd3ba626a3273407918598ebcf8f
MD5 916aa2e9ef86d6274b809441da10131b
BLAKE2b-256 560621d940a0261d27ead060456a9a4ea389f94aeb94ca7d1a7f67e548d6a3ec

See more details on using hashes here.

Provenance

File details

Details for the file stim-1.9.0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for stim-1.9.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0b67f3e66aeaa3f21bb5a950718e6e87ff61c434ffdf59b0b19195dc67bbae86
MD5 090c56322b749646db477130d2a73771
BLAKE2b-256 1d374e0963b5005fbeaf85556b3fcb3f5c41d7e1db6bc74121b53b139095094e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page