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.12.dev1688877722-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b73ca8d36c30b2ae3d6a99ee6c8f20c46042561a7b4d02f22b787d796ebd3ef |
|
MD5 | 650a0d4a9190afedf07e5f938ce9e5c5 |
|
BLAKE2b-256 | ae2d09f7d22b9daef4a51084d0cd37f481e0aa110f6b0b393b80b382775263ac |
Hashes for stim-1.12.dev1688877722-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1be0ba7bd215da6d0d7d6bb3761b3e944bd87fccaeefc3a0b21fc6501e939ddb |
|
MD5 | 7b79a8e7b294c4e4fdf8027b7f120450 |
|
BLAKE2b-256 | c020e02ace3c713e41d2f0a28d3c4260640d53459bc17ddad4285f53d3030a0c |
Hashes for stim-1.12.dev1688877722-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e791553d4e689cab911f2781dfed0848aeb7436b731bd54371cc5c3a9ac87c |
|
MD5 | 5f9fada05194024e8311b99e3f6d1beb |
|
BLAKE2b-256 | b760d7938bad43050dabcad1ecb4a004476a162497d80c6beb1f3267346bb569 |
Hashes for stim-1.12.dev1688877722-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b830d766639cebe0af8a68b58a1bafc4de9a6629005e1b5b3b9d7a07e053db |
|
MD5 | 4571dafffe1cada9ac1f926c266d960c |
|
BLAKE2b-256 | adbf0b466df9f11ef2be42e07cb1b5f7ca39a9e8e1053dac37507d94436be876 |
Hashes for stim-1.12.dev1688877722-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8339c884bbfb3ce55af6adb0d896e47eafa73a2b5fe1df95806a6f4b4fd0478 |
|
MD5 | ca535776bbe3360f35672a1a53043b89 |
|
BLAKE2b-256 | ee18c2875caad4801fc0b936ba4a1a07a30cbd8d682cc73b7b650a972fdca347 |
Hashes for stim-1.12.dev1688877722-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7586dc95a760ba7272d55c5b5a86608fa18e5c280dc1a53c20253823e8301bd |
|
MD5 | 95988de3f65f10137da92c50680cc070 |
|
BLAKE2b-256 | e7c6f17e178c8e47a3c2c8694c2bdaa638872ae2f458969d33200259bd613318 |
Hashes for stim-1.12.dev1688877722-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f854746e9d5db9408b29359310f7a5aa46b9ceb95d58b2fa2e28d73d58d80ce8 |
|
MD5 | 1eadc86f4771407e3576c239f4e48281 |
|
BLAKE2b-256 | b3db6f1f7aaf05ba6f5acf884f065990ba20da9a4276e828552ed83dd5650ced |
Hashes for stim-1.12.dev1688877722-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e699235971cf46a41c88bbb48029118fc39d25629a9a0461013f90642486a79 |
|
MD5 | 3396b204461343d954b027c34d60a00b |
|
BLAKE2b-256 | 7ef613af960c11c23084071fd1572c486b3897e63647eb75491414acf2d458ba |
Hashes for stim-1.12.dev1688877722-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2a0999117ae2ae71cfa04327943575277f3fe482bb7218e482c6e826e2e8e17 |
|
MD5 | 3adda9ce3514931c8252ca2b219a9685 |
|
BLAKE2b-256 | df21f55efa63be6f9bc470d51677d94e014b9ea726c34c51092b4b7c639d31c8 |
Hashes for stim-1.12.dev1688877722-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07f072d21c09a54cea61b920a39c8faa969d5b21d561191186cd31a1cd72e49d |
|
MD5 | 65fa495faae79f78414ed541943aa516 |
|
BLAKE2b-256 | 3132c0380527f1452eb2b1cbddcde08f3b7ba0cdbbd0a4448ed44d587c0009b3 |
Hashes for stim-1.12.dev1688877722-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1860ef120611d80542dcc764d569eb6fa2684064e34dbd24d5814cde8199e0b |
|
MD5 | c11f864eb06662710e5b5e4b8bf8f072 |
|
BLAKE2b-256 | 913011b1a8fefd183db505057bd3f8cf34532fba143972bbd286b789cda0714f |
Hashes for stim-1.12.dev1688877722-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8407990c9259858ac9826e69a5bf03cac8247d47f5b072f34ec278095f6b500b |
|
MD5 | 4453f4898cb01e5cf5afc98f43795b25 |
|
BLAKE2b-256 | 75c2c2bdc0aa97a5d744945c5551a53a41418cae5dcef059946c7b76286c3bff |
Hashes for stim-1.12.dev1688877722-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6213c054c935ca85219a31ae77641723ae75fa91cdc4f4dd7c30a7f343e01ab1 |
|
MD5 | 2e36bc88527da976db0e06dc68d74058 |
|
BLAKE2b-256 | 20324b9482cd01d174a1e171d7cd247ebe9b8fc66ee3d3b95cdbc6f03f94fc3e |
Hashes for stim-1.12.dev1688877722-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b59c5ebbe990180b5c74418b7e25425ef144f821d0cfedde3157ef4df82ff27 |
|
MD5 | 4d09ade51c7027667fe0e3ed6f6b1136 |
|
BLAKE2b-256 | 3760645e82861181ae96e09bfcc7f9389bd1f701376ff1b400c98e18cd86fb0c |
Hashes for stim-1.12.dev1688877722-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b30c73e9a85cfc2553d80f30782ee4c042d6485e3b7912538cdd18d1448bbed0 |
|
MD5 | dac57c2850afe2ee083fb2f77accfa9d |
|
BLAKE2b-256 | 48b1a0eb0fb0cba9bb13b40ac06b7e02eb1176a0740e34ca44aa23adb34d0842 |
Hashes for stim-1.12.dev1688877722-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c3f48becff55a3bd3f1523cc9a80a3d4c5bd606305a9a4acf5365eb12de3e5 |
|
MD5 | 54df0cd154361b4fc2ff928fa2fa5da5 |
|
BLAKE2b-256 | d0e51d42f292558f7c329c1ff96c3fd81b3ce6e9ef77aa8e495492726d6ae75f |
Hashes for stim-1.12.dev1688877722-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 241c318f5837c6b32c775eb1a24ce716c36f098147c175b552c31ddeb3fa8159 |
|
MD5 | 5fb9dba2055762d7b18c13d39bcf9ce4 |
|
BLAKE2b-256 | b9e744186b30766aae9ca45ae3ce19f5ed846705a5684399e47cba57681f9b44 |
Hashes for stim-1.12.dev1688877722-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e9ce16aa5e0fcf76b1bd86107a1142a92e4f761f6429906946ebebb527ae2bd |
|
MD5 | 623bc3ccba5e56cf28e99266e09c736c |
|
BLAKE2b-256 | 2e34944efab48ea0da559c1138deb75f737729485982ff6fb8d6f7bdf38af9d9 |
Hashes for stim-1.12.dev1688877722-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d67352fbebbf02af3d17cf99aeefc7ea43559bf6c8f0fa328ad38f4e25e4e26f |
|
MD5 | 57de89f22ab59ac0138157801dc1bbdc |
|
BLAKE2b-256 | ea3ed157ae78d2b39b7cf5ac31158847068d2459ff356ecd53472f9cc3887d08 |
Hashes for stim-1.12.dev1688877722-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7613b53463fa2e2cff2f91024a479e4f07bae8f2662d0dbcbdca8902f6f31c88 |
|
MD5 | 539cdbcc2b769936678855877c59ec9b |
|
BLAKE2b-256 | fa06fba651ec046c0038a2ee2f6a3dcb66b13da9a95051028a637f8dd69c6821 |
Hashes for stim-1.12.dev1688877722-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634be7aadb3bfe4f754ef35559e7fb349c528d881cda8c8034cbbd6b87329765 |
|
MD5 | e67c8d164acdda2da05f17c3e53ca333 |
|
BLAKE2b-256 | 488d7bbfd746d0bcdb9734e9f3122beefa1f131de72e5acbc712fc1fe036ef68 |
Hashes for stim-1.12.dev1688877722-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32c321125e10b6e74c0093343ee9484d70fde7a9c48358395c841a656459015c |
|
MD5 | dba962c5e7b5df1740f3b96be9496dcf |
|
BLAKE2b-256 | 529b476da39533febed14e8b228298300b176e645b10e06dc1847fde92ce42fe |
Hashes for stim-1.12.dev1688877722-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 496ecc45c88d74f5405c657f683c55a03e4ecff621cae1c236515a4477d5bf92 |
|
MD5 | 13dc24aadc2bc187454abfe6a3e75a67 |
|
BLAKE2b-256 | 7e9efe7a57956767045160adaf795ff7881214ea1f024f19ad62fb10ce4ff131 |
Hashes for stim-1.12.dev1688877722-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b11c4f02d261ca4c8f1813fe09e3a0573f6641d7526d1fb7cf70aecadb3aa8e7 |
|
MD5 | 873e33a7f3564383b614e95914ab82c7 |
|
BLAKE2b-256 | c3cc417eafb65dfd9dc3b627cc7b99e5ed7ebc6c4b45f56dd6402fa93c5e5e53 |
Hashes for stim-1.12.dev1688877722-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68174b25d6774241c6ee78f45e8cbd5216de199287a1f81ebb3f4f7d47eececb |
|
MD5 | a8071a51316574eef6c6ca400f54794d |
|
BLAKE2b-256 | 9dcebcab48532e4d1db66659c4f519a72e8d92ab4217301c5340b56e9ccfe6a7 |
Hashes for stim-1.12.dev1688877722-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ca7fd89c590712f7e1f4b16764316bcb2e2ab7f30360e48fe29776a49746b0 |
|
MD5 | d61066f7689b2d1eb80a13731e67ebce |
|
BLAKE2b-256 | 63f4876ad6f11c9c5d80196f2b28e784bf2e0573db5d5c09da2821f752c5cfb6 |