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.dev1692410061-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8c746b3c5bb62dbf7e61f4d016393248ccbb97751ce29f4cedc57cc3fb028b2 |
|
MD5 | 721b5e7a7e5e6aff93e82d8a6df4e9a6 |
|
BLAKE2b-256 | c6ccc38e88d91acbad5c6f5aa96ea1efbef2055fe2cefb10b2466eb75cb8b614 |
Hashes for stim-1.12.dev1692410061-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f1aad7d6e56a540decb900a4f17b3839b7f06e2134c2ddddf888ce11dbd952b |
|
MD5 | 16bce8a1406f5545ba73c171e14b7ae7 |
|
BLAKE2b-256 | cfe53ce51db91a184b4954e938a52facbf736e75180094cb5a83b7ed3aa3d214 |
Hashes for stim-1.12.dev1692410061-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31313a68884febd323520512db4732a5501142158dbd784fad442e599d0bdab |
|
MD5 | ec314d4cf90bfe3aea9bdc606f16dfef |
|
BLAKE2b-256 | f985653a357ff3f7e1448cc4f8db4a64a02f9acf0cb5e92119e3a089e051ae01 |
Hashes for stim-1.12.dev1692410061-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f08afd3ba66daf81e5aa31beaa56e9bd4a607b1a9582b3444f949e59b61edd22 |
|
MD5 | ad4633f301e098194cb30bc3c32c27fb |
|
BLAKE2b-256 | 2d9a79b5aad428e06e7f543d50d3d5553dde07406ff992675244508b5d238185 |
Hashes for stim-1.12.dev1692410061-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec3bc5f90ca643271f8761c283da1b43c11b221907a9fb56a82b5315bdeafe4 |
|
MD5 | 0a6bdc76fd5393a2eb0253799476a872 |
|
BLAKE2b-256 | 6f2304118487b4eb81a69cebf705749c29f890e950eb497cf0252cf5a38ed0f5 |
Hashes for stim-1.12.dev1692410061-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 263860171259065c6e6f759793b59041f873d702c1a0820113d52d4b43e296aa |
|
MD5 | 3329122bb8ff809dd80cdee2f1809d3c |
|
BLAKE2b-256 | 1d7ca9882f2bbc58b50e5770af8de8d6f454e66d40589135c2d20b93752bd72f |
Hashes for stim-1.12.dev1692410061-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d88e5f483c648d12c2df2e1dc20a5d9883655e3f1fb7e373c338b358c8af8420 |
|
MD5 | 64f777b50a58fbdfaec0fb595a14ca45 |
|
BLAKE2b-256 | dd2d1a70817ebaedeb4368cd3583e3470a658fa24919eb9bd267930ae66baf49 |
Hashes for stim-1.12.dev1692410061-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e4104bf6fe71824b606e07bfdcabf9e352b1131b09a036f480c0d226dd3aec |
|
MD5 | 673dbd921d6584049f1c10738ba8802e |
|
BLAKE2b-256 | 49f4ffa9cff008feeafed1b0638355d6007ee9e3ba45fe71bf8e8a42cc511ce6 |
Hashes for stim-1.12.dev1692410061-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b987ce5b24e0eb0fb445c3071292a091902082a696aeb3da6ccfe9e5fd9afeeb |
|
MD5 | 41ab25ad53c8df3d2b7fe886e1858db4 |
|
BLAKE2b-256 | b775020764fb3f93bb2f316b2fbe3bfbf5338608ed31e64aeac24e9423462d25 |
Hashes for stim-1.12.dev1692410061-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc79de546eba3615fdca0d6ca33081b183f7e06cff960a6d56a12f888b58520 |
|
MD5 | 0142a851d590816ca073a2a1cc543591 |
|
BLAKE2b-256 | 226be55a56cece79510ba4317b1011bb53eb1a75cda2b8db53a037ec2396a9bf |
Hashes for stim-1.12.dev1692410061-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58fdfc461166f098ae90fc1b508fd4c74b2f2af0ed58b6b9392f7336ddba3e7f |
|
MD5 | 45cd20a41ecd165f87281597ecf1a981 |
|
BLAKE2b-256 | 02c5a6d8b60527d6b6cc7c12e2e6a6d387d8c2e79219fb66ef776063f966b6b3 |
Hashes for stim-1.12.dev1692410061-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dff4c7479ddba379d954fc0ef3e28a5acf460e0edce267804311c867ef31a6e |
|
MD5 | 1873e87c6c3df1f1c2f2867afa693ce3 |
|
BLAKE2b-256 | 0e9155855e1100c46050843e06b2c71abdefed726c0f0fc54b45de8bffb820b8 |
Hashes for stim-1.12.dev1692410061-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b5492a718de9ef86959199d69fc1cf34e5f4e39f4b82f5d024bce34759f18c |
|
MD5 | c603017996f5d7e2f8a7c8c9996e21a1 |
|
BLAKE2b-256 | 086620101b98c88dd61913388e423bb97b8ada08b5873d6b7a560a644f8e3d82 |
Hashes for stim-1.12.dev1692410061-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fdcfe5d71e9787731b874ad1fdf36dc967e2d4be2c29801a93c8b0474b51e9c |
|
MD5 | 1623f594c2969f7a6ecf44f7ee7489a1 |
|
BLAKE2b-256 | 458c678fee1befc6a4cf57fdc168aa16a098c1b0098704eefffda407bcb7bafc |
Hashes for stim-1.12.dev1692410061-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c50679c4db671ea5ef3300ff3d3a4c354916757496bae9a1cb2c64d91577804 |
|
MD5 | 7a6e505038caa9e62acc539f8f65e6ae |
|
BLAKE2b-256 | 7ae8c20f5cf2c47f61b68cd67e96444d35ae49528291d91b5562dab3543aa338 |
Hashes for stim-1.12.dev1692410061-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56e96b21669261fb99b3d4e033bcdb7b5546635c1901fba1db7e9514728fe3b1 |
|
MD5 | f4e4483ce91dd695c6e9c3e857b9fa13 |
|
BLAKE2b-256 | 6e223248cb05a1c9a9cd45f1a1678077024dacf4a371cc5a3e5a41ec0b2930fe |
Hashes for stim-1.12.dev1692410061-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d5327d4f1a44dee594e465746d08b50f537106478227ed7c648fd77637048a9 |
|
MD5 | 4e1910c942b980fa1b3987b9b78a0aa8 |
|
BLAKE2b-256 | d4e1a05993508c78ae1a2d47a8d6b4a10f826c76d984397381fd39106fc5b1b3 |
Hashes for stim-1.12.dev1692410061-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ed6e6e07515e594b86d5a9cc5cb378c4e58bfa5955c558c74c97970322c9b93 |
|
MD5 | 3b58eb3315928b4d0f9adf8d0aac602e |
|
BLAKE2b-256 | 4580d3cc5513668fd06f8ca5fa5554d0391c8a847d08a532097e95e47d0c2517 |
Hashes for stim-1.12.dev1692410061-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df611d776747d1a303e47e90112a98e12f8812258d8228f50d5f48bc0c47791c |
|
MD5 | 723112899f08b9cdd3eb09a90ffbfd10 |
|
BLAKE2b-256 | a1c0e43b3984fad14647722f793d0cb778097b285652a1cc422745a48f3fb764 |
Hashes for stim-1.12.dev1692410061-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b334749c532d048a9d34af5fced8ca663523cacb9346a808252cdb2365f67321 |
|
MD5 | f90a7d0ad4118102d749ce525713ac8e |
|
BLAKE2b-256 | 83b3b0b16f382abc3585a148f17097a99fc5e5bdef49c5b0d100aa5aeb004aa3 |
Hashes for stim-1.12.dev1692410061-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6131fd38c409cfdb70c1407d2b0e5a76dca27ea4273e51c5c731c12a2271dfe0 |
|
MD5 | 52833dfc646dcc461418847ad2649362 |
|
BLAKE2b-256 | 998bb0d40e5382410df2ecb0eb3532a9c44fdffdaa8f91e7007bca87558cbe61 |
Hashes for stim-1.12.dev1692410061-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ad1ec457441ee59d69477a3fa0908a524980b7dc33ed367221f371fc2becfb2 |
|
MD5 | ab1573be0d32e04b09266e533928f8ce |
|
BLAKE2b-256 | 004d01df97fcb867002a88be32615418dcdcb25c6c0fe468fe5f4b1147e3f8f1 |
Hashes for stim-1.12.dev1692410061-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c21a1ed75fc05012c9c65d548b75967dd6dea75f857f1c743d46515d3dceec4 |
|
MD5 | 20905c41a465448f410d69971f323428 |
|
BLAKE2b-256 | a60957d60ac8a7ff45e350fed49030680040741b52947d9912a9db586d0f242a |
Hashes for stim-1.12.dev1692410061-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08af598ea864b1cc620b64ed33ecd76ce49d5cfafadf5b92c4a2e0dd40c25d71 |
|
MD5 | c1db9110d537b15a2ae1b7c8b2060a2c |
|
BLAKE2b-256 | 1c691fd2facbfdfd0c462485e9b5030edc9eafec9f61c1ed0f5d852ee6ff0f1e |
Hashes for stim-1.12.dev1692410061-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6c779b9df69f97495e08b7cf892f7f43e5dd912c0939d9b080b5dedfcfc8463 |
|
MD5 | 836bb39f707172ee1b78669e1abd5b6b |
|
BLAKE2b-256 | c237d0452149f32886dee830e537f60c2004f99c8bdb1b394a645a102863405c |
Hashes for stim-1.12.dev1692410061-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f411cc255fdbfb7ad2b7e4e22f93d17613cda2814c177e509b7e956119ecad2 |
|
MD5 | a2d678355111af7ccf2e9480dfd0c859 |
|
BLAKE2b-256 | ac6f869d902d0597c198fd094ad19f879c639663404eb1e9dc2ff81fecb37212 |