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.dev1692749085-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac209359277d573aecbf48c0d4d730fc2cdd11a316db7e137d3a3cdcae76a40a |
|
MD5 | f4608d1e6308f684572886e3a8f8a72d |
|
BLAKE2b-256 | 2f5e8916377de1ee4f639815da991c4ac57c3c59771ade019d8cc5ccd2d34234 |
Hashes for stim-1.13.dev1692749085-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 988cc8624533e75fd0ae850ac2d1583cc7a447094a1a4df13ed17ffd2b25930c |
|
MD5 | d7fc2857a971a39aee28d02371cab5f0 |
|
BLAKE2b-256 | a69947cb8871cb503bd9e32bb722bd5703ba79bbf5e5d4436cc25de2da5c5275 |
Hashes for stim-1.13.dev1692749085-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39bdf0452c973759f836a513bc87e60f430b3d94bb7ed9fae44420b0b82bf867 |
|
MD5 | caced44eb928c18b4af712b9de3b3939 |
|
BLAKE2b-256 | baffb937051936f4e126eaa30988846851160b3162bb282c74285a308a77a333 |
Hashes for stim-1.13.dev1692749085-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 605687a5ef8bf58256024090104be962b1ad725122e3f10889c936c224a1d458 |
|
MD5 | d4661f73c0cdecf50f1ec1e34c6acd2b |
|
BLAKE2b-256 | a47c11f1d5c8850cb1167bcb24a8cba9aea84858d1ee6cbc7c8e7f6b4d26850f |
Hashes for stim-1.13.dev1692749085-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d60ae5acc2db4862c7b7e673f4c20a5ce2c792c1ce2267b72163bd83916b1d07 |
|
MD5 | 2760af756f51c9b4dd34a0f58acbe83f |
|
BLAKE2b-256 | 6abc2667cd557bc8312c510f31a7ad692c71263f45761b2217ac63731a94153f |
Hashes for stim-1.13.dev1692749085-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f169a996ae942c0a315ceb70368d8da9941d09f15feaa16f983af3c47f6c6329 |
|
MD5 | 5fa9fc08badc75a6dbaeb91a7b9cc7fe |
|
BLAKE2b-256 | c124e599717d528ca97b5780fa5014da96a8856cd0d6cd0e5e05e50c0ac449bc |
Hashes for stim-1.13.dev1692749085-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90d703d42c54913eaf6585669f4f3e35474947edb22df31f3e5d73d7ff5a4513 |
|
MD5 | fea61ef5fa62becdda53aa4d1de4f705 |
|
BLAKE2b-256 | 9414718699eb610aed8c0ec7b83fe477e21ce1e59351795f366e6c3a2f48804d |
Hashes for stim-1.13.dev1692749085-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de136bc721043beb6fae49dfd67cd04573cb45a74e2d25630bd2797589cbdbb7 |
|
MD5 | efcdedc6166fc5a424b332c6d663cb05 |
|
BLAKE2b-256 | 2bc0d04ea3440e76e0e246ba733f2bf2a90214c9d9d7b87f929362380c40a7a8 |
Hashes for stim-1.13.dev1692749085-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e32cdf71dc0c4a2cc430052b8f641068342725862634440caf66055b70d1d530 |
|
MD5 | b350efbac2f92bbf1c048b088318a44d |
|
BLAKE2b-256 | 11b88e867b5b5b7e2df9e176f14e5433ba28349ee6629391390e05257292325b |
Hashes for stim-1.13.dev1692749085-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4661ee1f3c16f3a09c7adba04e911782e41c618c594f13703585d0da6488ea4 |
|
MD5 | 22bc823d79c0b412fd29230893dc2ed2 |
|
BLAKE2b-256 | c7652f97d5e458b543009101b1e728df4010234e0462e103fa3051c2c0da72e9 |
Hashes for stim-1.13.dev1692749085-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6126d0b2e184f6dad228cb9e86e190ffc045fd602fb6e8f677397069de01c395 |
|
MD5 | 889a609328bd390727f9fe43e67f65b8 |
|
BLAKE2b-256 | 7b7d416ae28254fd63621afe2a66d32705a6a7f7077e954aa85a05fe098f6ace |
Hashes for stim-1.13.dev1692749085-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 403f43b640ce812e93ee08b7d51d6f2bb2aa9c05936be174d4837e2227f34d13 |
|
MD5 | b3d2f1d0950ac30d5b7bb0b697805e98 |
|
BLAKE2b-256 | 1a39610ddfc8eb8e3270d092d5d4d78f07e931a041852fc90461fe54f8862470 |
Hashes for stim-1.13.dev1692749085-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34d9da2b848e5338a6ecc4527727c551105e0dd1b79e48cca7a28fafc456f86e |
|
MD5 | 57682ab4b8abfceeeeb943d83fa76ecc |
|
BLAKE2b-256 | 6b0de7acb332a0b88ab6e1990ec9441c88f5fc7b744ed97d300f4db951c8bfd1 |
Hashes for stim-1.13.dev1692749085-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c25f54aef402cf2d3be4dc75378fa315cdbd2524f95f2a80f934b875b043ef8 |
|
MD5 | 9e8f597ec7b0633fd7efaab03c3c9a20 |
|
BLAKE2b-256 | f1dbc51351257949c02850120304a77a7abe274d8c3bb6fc148c4136e67e4a26 |
Hashes for stim-1.13.dev1692749085-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1136d04ed40a6d4b33b68fce63b821b3ba0cd515b716e3a50cc1ac007a4080b |
|
MD5 | eb35a54c116d95500c9c16f1c351f2e1 |
|
BLAKE2b-256 | 036291d46802e4b83234c2502acc5d042a924f944fcf9b50a661730e22ee567f |
Hashes for stim-1.13.dev1692749085-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d73bc9ce8b53aefb2e39ddd2ef8b7c4249f00b7b36e01946a7099db51b4b80a0 |
|
MD5 | 28c5ecbcf2b697ae516171ead107df51 |
|
BLAKE2b-256 | 7ea5fbfffcd71d993f916ce4d129eb398b11b3fbf9ff498e70cce0ae305fdb9f |
Hashes for stim-1.13.dev1692749085-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c804513378112d4316bbbc5be3ecf695d834014abed580a80885f969a28b1c28 |
|
MD5 | 44637e487a7fd48beba859f44d0badca |
|
BLAKE2b-256 | ecaa2bcfb87f41cf673525ef9c898697812b081b6b38297c1b769c0c608a31e5 |
Hashes for stim-1.13.dev1692749085-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6357d46c96efbc51e046397211d195a6ff7eab32653396a2ddc413a5dc029619 |
|
MD5 | 040d55c46e914a21a4b5a74e44dec45c |
|
BLAKE2b-256 | 99cf44d1e4dd9fd0bd28c863044bf3df90984165be9e57b2f4869145cf970b23 |
Hashes for stim-1.13.dev1692749085-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f0062b788833e7ec0f32e329185f8ec167db2939faee6a102c9bf9afe958304 |
|
MD5 | f6be25a671e125ec4813565ea90b3875 |
|
BLAKE2b-256 | 9a7c92d5bacc0c25b3fb376b32fba6e1b624df36dceb62e9064001a48c0c4197 |
Hashes for stim-1.13.dev1692749085-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e81a3bdd7d87b0e270f75d0b8c485889db98de31f388279d75bb7723499cd8c |
|
MD5 | 2ec3d0bf792c19e8c506462052b69b47 |
|
BLAKE2b-256 | ed45a35863657abc4bb351ef0e1f051495be4e79c09ed43591caafce42f0a620 |
Hashes for stim-1.13.dev1692749085-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3944b771c02bfb04cf5b32f4873c724f87c16aa7ecf98a4263b0d14374e3febb |
|
MD5 | 16ceca2b224448c166d78be7141895b0 |
|
BLAKE2b-256 | 930d68e2250d238f45da06b1e6b3b67a269bae632c357744c03be19a2fb07d41 |
Hashes for stim-1.13.dev1692749085-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95938bff823c777823fc035e21ae44a72a083e321bb0d8d108192d53fccffe52 |
|
MD5 | 8a0ff5b6f6ea9f137b7d381bfed24d7f |
|
BLAKE2b-256 | c25e1898bc9fc4db5be9c9357815ac0a3c811ee6d59217dd09fdc8a4fdacdfda |
Hashes for stim-1.13.dev1692749085-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 793e54c24a75bb52349499aff9935bfa98078cc4a2d36dd7f2798b6cc7384c2e |
|
MD5 | ad0ee2e91c274d2769689c600567057d |
|
BLAKE2b-256 | fc8b0d79d039072a04f4d390839c0f8741dafc30252969ff2cfd25735bb659a7 |
Hashes for stim-1.13.dev1692749085-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 995b6967cb662759b75772f9f127ca97d01c09dc31a5d1dc123b91fe7d5dec25 |
|
MD5 | 55174f61e8c52c722ce26cb1f7cb6ddb |
|
BLAKE2b-256 | dcadb57ae29542e7a17b2a0e4d929a2f534a8d730f553f1b8d69312f019582ba |
Hashes for stim-1.13.dev1692749085-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e41091445c89dde0b78376ce1351f0c0aeb0fb19d6edf495fd3359e6cc5898c |
|
MD5 | d7e8edb8e90e1a55b7fc1d988e36e215 |
|
BLAKE2b-256 | 0963ff43fa9350234e47dc539bea22ae3aec9705f32e72beb6b6a5a0090cc1cb |
Hashes for stim-1.13.dev1692749085-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d883ab50b533d4920b0c0e99793ec3a4e09f700ad92af202fd1fbd7971a551d1 |
|
MD5 | 49f340abc449e1f6675d9673e4ba4a85 |
|
BLAKE2b-256 | 053e1b8884429e9199a5fd068dc0bdaa689cd3b05377c345ae0ade0b547ed0a1 |