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:
- Interactive simulation with
stim.TableauSimulator
. - High speed sampling with samplers compiled from
stim.Circuit
. - Independent exploration using
stim.Tableau
andstim.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
Built Distributions
Hashes for stim-1.13.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5b39e305c7bbe05b0595345823f188bac5137c6ec73efc95cc98cbdcbe0c7f |
|
MD5 | b35502fad872c73d502d0ef527349578 |
|
BLAKE2b-256 | eec750b66009a751f68408fc543543b02ea05bad5e1a7a227e88002e0e5c65f3 |
Hashes for stim-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb9d6465ecfcc869e76353e1e81d574854f17ab901bbbb844d99c1290cb6edb |
|
MD5 | 8efdf4d3d87acaf84b9b59f84b7fdba8 |
|
BLAKE2b-256 | 82621ad3fffeb20d2d864c3e4fc9b4da0defbf167a81bbb12272460a3df96463 |
Hashes for stim-1.13.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e5cc5fdc44fcd081c5b2357a5fc2b662fabea05c4c9bfffbfec97ddb8b4b85 |
|
MD5 | 66fd3bbe41da808dc90acfbfe3836c3d |
|
BLAKE2b-256 | 27d014d434abaed39034905d3e9595dca71f6d0c1540f184ba118ab77e47b3dc |
Hashes for stim-1.13.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2ec3a91c4cbe9cdb4b3c8cf621c1d45ad2d784b4fbdb702ed507e482bd4261b |
|
MD5 | baf4d44bc41d62888bbeeaeb80557cd2 |
|
BLAKE2b-256 | b8189cad59fb536bbbbdfcdedc7f6103217d4dbacedf737d5920b42e55f0a286 |
Hashes for stim-1.13.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3375e247c618fd2cabb0717911d0aea691d6dcbce59daab3ad7b451051943daa |
|
MD5 | 2f9d4c64d5236fe3bbf2695bd580792f |
|
BLAKE2b-256 | f6850a578d477744c48e7775a216264b6d314a0faebce2adda78fb2b7ece880c |
Hashes for stim-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05572d3c4d594811b9c2ce3c3d595ad29834625cf674ad85682a7839af055996 |
|
MD5 | f0e9ddb82a455565e594e8f016c82b01 |
|
BLAKE2b-256 | ae7b56c877c1eb608d14255f6e35a7e12494bafe0fc5173e3de303cd01299644 |
Hashes for stim-1.13.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6f7f444aea04d98a63e14403c25b853766ad205aecb712148167c597d1cfc35 |
|
MD5 | 0c03b370e05bb4192aed23e8ef3baa7e |
|
BLAKE2b-256 | 94bd68a191fe44bbf825196bbb90f1b4da226f7a382fd859d67cc52cfc6e121d |
Hashes for stim-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 880c8e4afbf332d878b0e2270c26151f22168cc1241a12f03676ccd87b93b2bf |
|
MD5 | acc49fd07c1fa5a8188a5c5492df704b |
|
BLAKE2b-256 | 6ebdf7895083e5caca58556c7808c0294a01310b6ee81966cc60a8d6ba5131e2 |
Hashes for stim-1.13.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8055ae3acef59f482e2aa57894151c9f66926842373628a356d3492cca6df8d1 |
|
MD5 | 0a01b8e42e2c7e342575456798c13bc1 |
|
BLAKE2b-256 | 8a47a4bbb17bb3bf21777e61bfc3b6ad321c85d45c737983446d7f23eb750b4b |
Hashes for stim-1.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 710995a99162bb79d40f155a5c57d0a2576c4463d2ce52c62134eea450492d08 |
|
MD5 | 39aba973b39fe8b68c77fd3309d78e21 |
|
BLAKE2b-256 | fe5b10c8e56568462bba26718d0902856d6b815b0afc422d2703abd1b3d66d8b |
Hashes for stim-1.13.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d890bd26e8b6b69754c67a33f87f620112f533ed939bdc42eae260f78443d7 |
|
MD5 | d6ba8f786ad3fd86519945a4689efb7f |
|
BLAKE2b-256 | 6ac67eb63618e8e60f2f9cfcd0b3ab244307e5c488059477f854d84b041dfe49 |
Hashes for stim-1.13.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cf48c0354ffff024009616dd659a872a39045ce481d360d90b3cecacf1e0e8f |
|
MD5 | 97e4fe6da669da00674b0c9843623ec6 |
|
BLAKE2b-256 | 940ad7cb6eaa6e5b368a34cfab8a9f599bd310d878560f95b1b64f99a12e04f0 |
Hashes for stim-1.13.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71d43995030f53d358f911247815e8de30d6f1ba504cdf2c3577cab64f9e42b8 |
|
MD5 | 8015a580220c4bf4d21e1c38e4b65a35 |
|
BLAKE2b-256 | 108b66e36f73c9a3fcda00365b78e2f4f8ccdac2f8199f129213ed3af41b5cc1 |
Hashes for stim-1.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a6ec4469d31873c9b790944e742bf87fbabb716b660983e92845c4f378846cd |
|
MD5 | d2cab693c7602a4e715ff907aa0c442d |
|
BLAKE2b-256 | 98aa8f15451927b7c483f0e3f11d40642bc014762bf9dc9e8b593f6a1df64544 |
Hashes for stim-1.13.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a70f18b7bbe36be5843bb96034a8604d2fbad006a60657a4f73d209b06210d9 |
|
MD5 | c495a0be35ff1258e5cf97a3cca7d7c5 |
|
BLAKE2b-256 | 6073eb8da545c149e68aa773b30e0e907458aadc227319e4311ad569c4c31fd9 |
Hashes for stim-1.13.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29832a0429148447c8557fedfa7bd68a393244542b4d7c4a6636654e0050e824 |
|
MD5 | 9fa4e234d91c59e4f5eb6e17e4055334 |
|
BLAKE2b-256 | 31d72fffc520a3c3483451b6dfaa4bd1f0bd272f53f9afd53d4bbdd51f79059b |
Hashes for stim-1.13.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6c1917650706cfaf97524d7cd06da2d411a1ac72f989771fa25e3264eb6ac43 |
|
MD5 | 0a56940a229c48698989c9a69f3d2de9 |
|
BLAKE2b-256 | 9b92e5bf8d2ed433294b0e6f465384377e804116b8632e1c9e8d7d6dfb90939e |
Hashes for stim-1.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ca7261e0825f053c49561e70ae35687983575ad50aee2af16cd25dcb40bae6 |
|
MD5 | 2769714d5037af9da10815d206a89c9c |
|
BLAKE2b-256 | ed68d17b00eb44714d14f35b52ee334d7307bac0c995806077cb0872ca135340 |
Hashes for stim-1.13.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecedfd5755324b7a44e8309a1c0ba6a4ad2448fcb069e3e703826fb9bed88709 |
|
MD5 | 77ce927feaaf0ca63a95fe67db01c0d1 |
|
BLAKE2b-256 | a70e566cec01997079b1e443ea4e0e6f42f4eb7608b8bb6218856c12c12916f8 |
Hashes for stim-1.13.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0dffd23dee4d9c77a357eb606de77f9a9072465cad73509240da22417eb6b56 |
|
MD5 | 2253fcad4873a82215ec437428becf78 |
|
BLAKE2b-256 | 46e5db9fd29c52e0ac7539364c0261dd65d0e537b5b97b6e7886d8380bb97b3a |
Hashes for stim-1.13.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05670eed32671a96e5f688d33a0269f6928a489c8a3135515f70e22e25692317 |
|
MD5 | cff08af09dffdaea45e2bc73468e9925 |
|
BLAKE2b-256 | 53274f3fc6df2b21050bc2bdf9266c60a6b2934b5b4efdb04c2ca79c8a52c401 |
Hashes for stim-1.13.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2afc76a5dc5a81fa4cd8b916ff78a5cb042d8ecfb147b2095f474f5cfc427a9d |
|
MD5 | c5eefaaea895b753b818e0e7176f6e14 |
|
BLAKE2b-256 | 9b376c84261a39cc2dc1911ae18cb1adde8f9172c1a62b774f36c8dcbd5cce3e |
Hashes for stim-1.13.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f586f0563f151942b895038e561fab84bbc074ebbfa4965ee6fb3d1297d1f6a2 |
|
MD5 | ba2e808fb5346b2897f606c25b7f6511 |
|
BLAKE2b-256 | 520430321c9b80129c0363e9fd2585cc005b99c60879b0c21d3c168de027d350 |
Hashes for stim-1.13.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a3927cc72d39b3115dfbea7f5b29f12f1baeb85236e9655c7d1cac1f98e3779 |
|
MD5 | 1c05cb2bfcb50ac242cc5bca8c296fb6 |
|
BLAKE2b-256 | 1040865bb05d7f6fd6795d6764460be3c15c67fec9e2f120590266b1a27f1b31 |
Hashes for stim-1.13.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 927f32f64e78f1dc21e3f8d46cba05b2ee6f9cb74438898a18ae6212ca47549b |
|
MD5 | a87654b95d3657d6ac6fae2cfa1cb4dc |
|
BLAKE2b-256 | 0f780a2727284b4d1d90e7699162b950799867fab9a6995d714aab7179f72d6e |
Hashes for stim-1.13.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fa2448d8801125f1d9d01ace2a911affd95db7d8ac912062403250e9a5d6998 |
|
MD5 | 71b36a92021c1df026b0984142964218 |
|
BLAKE2b-256 | 989d8bb4014666d34265dd765793efb75f7df1cb3927eb09212d7416c361adbc |
Hashes for stim-1.13.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4127e32cb6603496eab703047da2b05aa42a9fd57a925e45c0aaa38ef840ceb7 |
|
MD5 | 49dea735c93808c436647ab82faceaf1 |
|
BLAKE2b-256 | d8a1ebf4ac87c076b9df202226d77bce9c631c78e0c2c3ee642fefb4a804add3 |
Hashes for stim-1.13.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad10a8cce01def490116260fc4ef8c82b87a428fdc557187d88d282bdf1ee846 |
|
MD5 | 8b24f25210dd9767fa3df15a8492765b |
|
BLAKE2b-256 | bfb4ab6d6a5066254648c46b2850056f624092860637a6edb338eebc76d66935 |
Hashes for stim-1.13.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f032bf2a3b3b1bd6a3a0a6b10ad623bf91b7fb40712f8777c49fc61ae1bc0c4f |
|
MD5 | 4c8d7e7761f4d5a1864c7d25540ea206 |
|
BLAKE2b-256 | 04ea7fffdb248e316ad28a633c07b60561c9ca83e5ced5066065ac828a7d759f |
Hashes for stim-1.13.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8224092c38a7f401d935194c7dee64d34c55b9073ecf2f39d5d4c1cc7775d101 |
|
MD5 | 6f0dc61afa4581ddef048da8d4a19263 |
|
BLAKE2b-256 | cb0faf365c6112dd6fe19c5be1ae24bd68089e5a82c50a464a3b7e007de89b80 |