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.dev1692684897-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 980c57635d2d8e15582208ea5cb058affac1673a7227c1d8f0772c37582c948b |
|
MD5 | 9a4646b21d94dca1581ddfc55576480f |
|
BLAKE2b-256 | bf956a7f3daa61464e80598b118f4295c9702a2ff4adeab913f8c7675cbf8351 |
Hashes for stim-1.12.dev1692684897-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aba303939a5e0e131f08c9fb6fddf395dc90672e7ba28ea488977ed2756db2a9 |
|
MD5 | 508ab5c025daa6c6d1ac6a6a10764847 |
|
BLAKE2b-256 | a48672ea698a7203884776da614c9b7b5f37d84b46674956e3f4225e4f82d10e |
Hashes for stim-1.12.dev1692684897-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c93fc346ceb3fb915c347ac5e5749dea5e7c229768e0c1d8a6e920afc5614331 |
|
MD5 | 8f897452b21b1e5603bef7174fee94f4 |
|
BLAKE2b-256 | dcbb3afb88d656fec6b47e87ff26d8d255546423d6dca8d662f59216fc511a38 |
Hashes for stim-1.12.dev1692684897-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81874cea96a319fa37ae0e9daaf62c022f1294e7f1e206dbfa12db20b7cb4775 |
|
MD5 | 71af85767775d85d0e0b7003ce11ab0c |
|
BLAKE2b-256 | 07028fbafd60c4a09758b49ebeb45f38e8502a52547deb8d45a78ef15dafd52e |
Hashes for stim-1.12.dev1692684897-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d9669985f1c6ca6ed4e20840f7284fd73b2a5c4abef71cb77a0e2eb1e500f6a |
|
MD5 | 2af3b7171ff392fb035a60104244baac |
|
BLAKE2b-256 | 5770cb486a9c515234835b224e616938afb61533eafdb2dadc117e8d103f250a |
Hashes for stim-1.12.dev1692684897-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6a62bb97458575fe4cfc6a3ce780543ba75cff4635cc8a4eaf368161009a099 |
|
MD5 | 265e44a038975ac991956bbb7232cb4e |
|
BLAKE2b-256 | 165273651d552d8e5130caf2fd02f94957336e1ccc45c4b2c889119abdc7ad53 |
Hashes for stim-1.12.dev1692684897-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32e77fcc84677f77c9a1b619f548c351e5af972d87d36003782f3da0fdf18236 |
|
MD5 | ab6252683d77d101ed0d540cfa5980e6 |
|
BLAKE2b-256 | 1dd1f9c0ee17e40dc4b31a5c77fbc4b6db0be84de6f5a6f2aa1e8c0e6e2b3602 |
Hashes for stim-1.12.dev1692684897-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b875f0c082ddafe6880b837f545a020b90e99cb557ddda4d84e70e07e28d9c4 |
|
MD5 | 254382e7922c75134aad893c114b26a7 |
|
BLAKE2b-256 | 8ed5499e7bc2e0f0431a7e66e531ee9e4436e34faf7718a70011b7baf333dbe5 |
Hashes for stim-1.12.dev1692684897-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57855f01311b93082a569fff5461773e6117ad82ea394db15f554653920887cc |
|
MD5 | f3445c489ee2f2f2cd5c7f80f9b1a73a |
|
BLAKE2b-256 | 2feb66f75125b37eb8431a6d0e3e1bd3d637c942823379a3a8971aa072318b17 |
Hashes for stim-1.12.dev1692684897-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a19340f630adb19d5298c656ff23ee2047b87937ba89a29be06f2f7ed5df4eaa |
|
MD5 | 517df42c355507833d0aadd13acbdab9 |
|
BLAKE2b-256 | b3199b3c45e89fe2ebc832501da8c9c3194f07286cff29875d0d4860c7528fd7 |
Hashes for stim-1.12.dev1692684897-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4abf453f51447375b63a59a7d9660b62504e9ace4275da4e673bfecc7ec3c43 |
|
MD5 | fd4de0f995985cb70c876f6c7505dec8 |
|
BLAKE2b-256 | 366a3d348f950fcbd5555d1db987b5ddc21271ad684f79cc882a84d4ef9d387e |
Hashes for stim-1.12.dev1692684897-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e924bd79a394e739e84981aaefda9628b09d5bccf7ea904a6b0d36fa1270fa |
|
MD5 | fb39335e3154d4afe2557efe0bf20259 |
|
BLAKE2b-256 | a2e70488f0e83346968676ddefe772798d7b992e2f437e842d3c54e38e3a977b |
Hashes for stim-1.12.dev1692684897-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8002963c9c20c6e3ed8a5db57f995aa1e8d646638040aaade957d69661bd08d7 |
|
MD5 | 70467a6da4905d491ee9163adf8ccca5 |
|
BLAKE2b-256 | a22ef684500aa88eba471750e052059a2670cb503ad4aed6625ba31b21ce6986 |
Hashes for stim-1.12.dev1692684897-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9839dfc75343cc3d7ec4e752f31e457f308ba1bc891bc71cf6e61986cfca3a9 |
|
MD5 | 2ba98845efa3a17c01f5ce2f9eac5273 |
|
BLAKE2b-256 | 6d26e0821a0252d3de0460a2348ffc2959ead818ae284115e6535e0ed578a744 |
Hashes for stim-1.12.dev1692684897-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac527fcd74bb67b6cbb93c8238474dd5e7a9837b9e071c5b1e93ed7a929e6888 |
|
MD5 | e2583b4e12cd2851c019a66c2dd48a98 |
|
BLAKE2b-256 | 6777af0a83e5215f2c79b4329572f60937f2204a0f70d7208de1ca0ebffa5f05 |
Hashes for stim-1.12.dev1692684897-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2314f460af2f1cad80c86ce0834b657890c7acd594e83fc017d60b4db43936b8 |
|
MD5 | 6b751fae92fbecfdccd04a4db02eb409 |
|
BLAKE2b-256 | 21cba7348cace82a5d6a8046364dd99650cf432514c242034d8d2580c0d7b97a |
Hashes for stim-1.12.dev1692684897-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e9b35d751b1c21659b6d442db384c0fd19aa6c40ff9f964e8e228a36d8736e9 |
|
MD5 | de8ae77225f7c540069a5b9efe94a2da |
|
BLAKE2b-256 | 89c7215f2e7dc630e1e5fce279ce11545abd685fbe47a911d8e7da80494e53eb |
Hashes for stim-1.12.dev1692684897-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c29b03534e557af7b86771508990f2e4d8ab7d292e7c2cd9a9eb7cef1268010 |
|
MD5 | 205ab70ac913bad76695ad21e094f8b4 |
|
BLAKE2b-256 | 8feb79025ebdec44c5f1abd0e32401e5f7c382343e35853e4f4d29c8d77ee264 |
Hashes for stim-1.12.dev1692684897-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cdcbdde361499347a76513e96680c06db44078e37d4f786a0afcf11b98d69d8 |
|
MD5 | e829e74f69a47f1e2d3912b4d4a7c743 |
|
BLAKE2b-256 | d4a6f70d9516d874ee2971c401ebf17cd9d82045a323c12be1b7d8f0ef58a8a0 |
Hashes for stim-1.12.dev1692684897-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c389c911d50d9502812359f0031f162459ad6b4de9fe022f353941855dd0a2 |
|
MD5 | e3f02f6d4302eb63da3b213c723d6212 |
|
BLAKE2b-256 | b0f822e1439548bcab2faaf7263e09fdb081bd5d14a0f19ec280c5734821cd5d |
Hashes for stim-1.12.dev1692684897-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87384fed06e99819db910c5d6c0b9f6fc98dd12041e89bdc4b0c372a9d50f6a8 |
|
MD5 | 0d56c8d5fa26a9a5ec9d3adb7bec105f |
|
BLAKE2b-256 | 1790f6003a58e65935861cd01037533714f33a4d76be520f6d44e5846c667b27 |
Hashes for stim-1.12.dev1692684897-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7876c98f61bebf9766f1da4c1349a6555f00e01582245edfb372a7553357ae3 |
|
MD5 | 78e2f618c7d2efcfaefb211fc1d0b5ec |
|
BLAKE2b-256 | 59c3e312fda74e8a189d7041e356b7f7e95e77ccbc564a0ea99e982d2cb7afd6 |
Hashes for stim-1.12.dev1692684897-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3b6b355d2cd87db41ae4fb45f74dcec1fbc5dc7f3a4ce22a57e10c5208e9e16 |
|
MD5 | cbae97dcab55c94a6fc7d9b33768913d |
|
BLAKE2b-256 | 9a752e95e006a0634b6842391c8569797af19106c33fa39f1a67c8a7122ce84f |
Hashes for stim-1.12.dev1692684897-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e734746ed9f15b5da8ef21cc71bd14c5a7e306d0cf48c9e44168c9b752d24421 |
|
MD5 | c7e907798f02ea80f929a59639165103 |
|
BLAKE2b-256 | ddfe3673b2bdb7dddd936da7a03e36326574c81a68993ac1bb762adeb2925151 |
Hashes for stim-1.12.dev1692684897-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aeffeb53c6b63a5ff771d2eba691a91716404a29361df38b0da49597a3ce6e6 |
|
MD5 | 96b547ea85d0d9fcae0b0784340c8f38 |
|
BLAKE2b-256 | a31c990050acb8b84705ab9f0d9c7cff43b873b1c96f178354e0b87901d4aba1 |
Hashes for stim-1.12.dev1692684897-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7b4381fac593adaabd7cbc901294923b405dfd48bca9aa61f751fe43b0c47a8 |
|
MD5 | 01896fdc6d6ccdfe3c7e01b64eca074e |
|
BLAKE2b-256 | 3ae8b1b413e2dce4b442905e1a6717b0a931827e2d0edec67c493dda230770a0 |