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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.15+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.13+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

stim-1.17.dev1780685949-cp310-cp310-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: stim-1.17.dev1780685949.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.dev1780685949.tar.gz
Algorithm Hash digest
SHA256 ccbb4353c70ec70a57a17fe39e93be8457f086758204ff5294decce043449298
MD5 ba66b1a96b0268ae41369f734927fa74
BLAKE2b-256 3a44db61199c0562973aa7d24157da443015a1c1be180aaafab7a774fbb06333

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2b3126df9718aad2e219bc29a3bfb3b56eaae2b0978a09aaefefe014527a581a
MD5 5e57c718dec03dede21efaed8a6c245d
BLAKE2b-256 1cb0d2d78144f65f69cb0ef5ae808b7a2316463ce5368575c2314cc5e942275d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 96142f837772baecf8f0cf15ed40e56e3107cceeff1919de6885e80e1596fad5
MD5 808f668c5ad9081c69c4faf5aaacb755
BLAKE2b-256 f7bf251f1225aa0bc76620428c7dbbbd3e422d86c205734a0eaf12cf2063a751

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79ae3ca7561181738187f22e85b35f6bfe5dbe57a69c668bb4f289b54ec5b86f
MD5 4ffc54c8b69152e1a0b601072ed9c7a9
BLAKE2b-256 6bfbe78b0b1a06e87a735fb39983a4a57b2c4d5b2633a42c04b2790b6dba9e38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp314-cp314-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0ca055489f9067837a419581d97948354f80e6ec840f78fa5169aa842c9f66c8
MD5 3e05a971554c806838987db4b9760292
BLAKE2b-256 8831f98e920b13f25222193e807dcdd3a154653c815a7eb847c4c947547812ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1fb5d937ab0ac1aa7b84901d52e79cc5a285d8e71bff3e14abda7d49e4d3b976
MD5 3327ca4d3c57192a8926de3bfcc4763c
BLAKE2b-256 299ee9bba2d929957f044e27685b9c3964c2e91ccb29d721c07d7c38e4111895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e98328749810700f03441d641fdbda89acc223bb79751bafb40f1960a06552ee
MD5 551a63d086094d751bfaf6472d72422d
BLAKE2b-256 78fcbc37e0e6e9ea5aeb40880d8338a074b2771c5967cdaeb6440911026bc0af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 138f6d6fa64b918294f22b4f1ed1b8f73ca53969e78dc849ef0eca0341cc266f
MD5 8e550d76ab5b2b5742ccb07405e6cac9
BLAKE2b-256 6797f4698c42b63f467c13f1125170226d96d514b8e746c5a80987a858b6cef5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a052e6df0fc6fe4ed87d5b4bdce6b6dad512ce98985831f93c42be0a6d8d8c64
MD5 39adab7a7f8e79226debfebb14cbd0da
BLAKE2b-256 4c4d64862689b463b38242c8fe0dba50666fa4441f0d66d0c617d2eb9cabb52e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c72ef9d64aebc79fd4fb098b7009733a24089a96afe9ae413cbd9e34203b96ff
MD5 6626f8a97f06934c4a7c3d067b6a11aa
BLAKE2b-256 08862da300aa7388018efafc14e6143b5783248d5f344a58d2542a3a5bf9ae0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f672d3983e31f85574e0890f917922fae06fd6f5a588dad15bfc7be3de5daece
MD5 3e58b68a159802dfc638c77913ff0646
BLAKE2b-256 0ccf6c3c83ec22e2b543d841809e607196b92c52d8847e72169c52053e59e4b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29e1ff9b39d2cb3ee4e97d63be2d9f73f2df882fc98c4dc4c7f68eb5445f4eb4
MD5 69d649dece4de6698007ecc9961c1cc6
BLAKE2b-256 a9095663c26d2ce998a2710f46bc984f01d0143fc1995208fb1c3918a3bb06d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 c768eaf217792256ba95e4aeeaad553c5bca516daa836c85a7520a0758d306ba
MD5 5b84d872a6a314a0ed7500c87a919631
BLAKE2b-256 fbfe5f6966fcc495d307ba47e9936d251560ea3d87dbffb4d61b3090de833fdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 89e008b4da7589634787ed5d465332197f701721c138d853bff62950b50110d2
MD5 a63f169b1230ed486b92e51886f4cadd
BLAKE2b-256 e35b79b6c06f4e6344aa1cbed084035b9b6d09e2f5054e5ab274bb21e9e14882

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 422e8d22a1788ad4035ef419f591f082ba9f7c461ad1384c586148ef06328f6b
MD5 8090b38b0f27df5a4097322bf3dc3dcf
BLAKE2b-256 33a5b0068d37a351df4724799539b1ee8b1885562e9510d06bfcbc803850869f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d0b863fd11dba04d518c82e7ffbba1c3b8c7d73b3c6fd8e500910ef75b71025
MD5 00af41c8b78a0b4accb353d540f8eeea
BLAKE2b-256 05d0ea36801fc7a66002759fa74c23eb27a91fd2bcc6572e6681c9c77a569c7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 afcd8593c5c042778194794d70f2eb79801097f959f85a2d6f72d149341a4a65
MD5 7e9bb651d873c42543e204e68ea14074
BLAKE2b-256 7d3166c24000a701be0a993f7427d77b74033d1f591951a5d9410a8327ced38e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9e7b445eb232a061f8473d86ebcf4e5ef73ffef16fef4929b7f87187cabc8210
MD5 7e7e490a996459e5887b0aa6dc57adf0
BLAKE2b-256 fe2a018bc1f20616251a1e3525df7940d145f3ba428e2b94d98df3982627d2fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecdab61a5310886537175c8ee974b55304a9c3a2f69272227057e920c5d7595a
MD5 7851bf6562099992423728597bcc9020
BLAKE2b-256 a7afd75d8f141f4613ca542e4f578f96ed6443869a2b6a607f25c9a360456690

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 141ae3432f56893d563b8e88b872e7e4c710ebb7098091dba207d85b65ebebc1
MD5 21359122bc4eacce3f7600da1a94f332
BLAKE2b-256 303531d160d0d54a2de1e6195082e289fae0d01a4226a16a9dee8aff7e8d37f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stim-1.17.dev1780685949-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d966f7d586a97b0db5f139c0ff89373b183af22ba27d05806c1cbe3dcc450590
MD5 992437a6f6058c9d4538fac56967f797
BLAKE2b-256 a03666e1b80d4898535645db9efa55b1d037d328a174455e07be3be0ce7e2fd6

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