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.dev1692830278-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3ff0e6fd4d67cf29197099afd745b53a4f50a8dbb0760e142ab2425d760272c |
|
MD5 | aa04f4d6cfb9a149f94243ad837cbf41 |
|
BLAKE2b-256 | b4517db9b60aab993251d81d3974bc38dd9dfbbe5c0734d64d8c060af758591c |
Hashes for stim-1.13.dev1692830278-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86d9932fba2982bfe439331092141c25ea8f41176b48c76b99031a106558cc1f |
|
MD5 | 39561115832848176d192ed2fdc79e26 |
|
BLAKE2b-256 | 53c79f8b8b8f7541c77b7c31a7f6f856ccd908bc35de918e0f3a660be47332c4 |
Hashes for stim-1.13.dev1692830278-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 826679d24f7150a05f6be112cc1c8e3d3ff606a5ed894559d29e52e21586bb04 |
|
MD5 | 6cae06fa7ac95497e503dc3e3bc16d24 |
|
BLAKE2b-256 | 4cd52374591306ca0d851e066988dc19c5687e739ecc3090709208d4e3472d7c |
Hashes for stim-1.13.dev1692830278-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 617b1cc656450a0ebc5124b9eacf7aa3b517be43b9b2a0c3d1eff40cfe7429a5 |
|
MD5 | 0a3c58d71b3e04118827a564c5e77b2a |
|
BLAKE2b-256 | 4905f5453b2f5b5a023920f8e77bd3d06d3e798ae0f36616c27925efd086f6ea |
Hashes for stim-1.13.dev1692830278-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8deb554371714a3b9c9d50e56f4bff59fb38f830231eab6e33fd7c3162832f |
|
MD5 | 6c62ef9b2f1efc34bf902e16ec7c24e5 |
|
BLAKE2b-256 | a15cac6036ec59c703c41e7226d0ccf8f4919257646e8a1cd516549ecd1eb0eb |
Hashes for stim-1.13.dev1692830278-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db9e252631047f149d99cf9b1b37af02d1d28f02cbb188f185da59544585ca6e |
|
MD5 | de1db73655c3c109ac1fb23a2ba13a11 |
|
BLAKE2b-256 | 7439938bd023b482f1d15bc6a0957008402bf678f8a28d51ae1a4efac513720d |
Hashes for stim-1.13.dev1692830278-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00ebde9d100437b93a51f47beb82a305082ffa6df0fdc1e3da5b6974bc6a0fe5 |
|
MD5 | 385d4229dbcbb81c265f6851d12aaca4 |
|
BLAKE2b-256 | b14a230c03978b98aabe5bb58c1b72dd601511572e264b80c528db3fe9d2ddf0 |
Hashes for stim-1.13.dev1692830278-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca29a492b1e65d16336d3734d768774e9d32eb9ebe855425f09237a93b097fb2 |
|
MD5 | b491266167a13c76c3bbdcff36713b2d |
|
BLAKE2b-256 | f32dfb796ff232e624b3260a774244730418e7d555c643a1b9cbc88601377db9 |
Hashes for stim-1.13.dev1692830278-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c03875e242ce8f60e882cee989743590b9af5ab9abba136360dba4b34f88365c |
|
MD5 | 3a595a5d33f5da956d8734204ecf42a3 |
|
BLAKE2b-256 | 9dd5bd9ac8818bcebe464cf9de2b05770b983a2ba622666bffff83b4cde1e583 |
Hashes for stim-1.13.dev1692830278-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9adc3756e1bd61949460e2318b0dc1c26ee747804213a72aca32977e4c68350 |
|
MD5 | d37f96a96756e6bdcd4814275627026d |
|
BLAKE2b-256 | 8fc6d8abbf35d261b40a900bf28a5424b319e47823c09574676691fe00dc44ff |
Hashes for stim-1.13.dev1692830278-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8215b3988a85e2ce23c9e4b641ebc1a3135b1c958ce6db876f3f2298d010f9 |
|
MD5 | b3c25b0e68a6ed117246af3f9108c0f6 |
|
BLAKE2b-256 | f9ec474db8febc1d2d762eaa9df9f35e6b967a8681657e195bb7f343cca638cd |
Hashes for stim-1.13.dev1692830278-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf43b830d91f1040865f78d71e367fd7c026cdc9cb287281b4168a4bf8402d35 |
|
MD5 | 7df08bd79cf3ba21765c49d7d9ef3076 |
|
BLAKE2b-256 | 23c2a4f6da6d251d3b1f8055477097a103d89a2277e67df48895abb9c9650a9f |
Hashes for stim-1.13.dev1692830278-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3fdae6f88ce38080192dc4671d49ca60b84a26d334cf9de2f1332b39784b83 |
|
MD5 | cf987cdf0274e497e7135c92946b2e51 |
|
BLAKE2b-256 | 937299f4a24eb73147dbe9e118884435020830b3bab177980395cf538baf8e11 |
Hashes for stim-1.13.dev1692830278-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d68f6a082f62c61ff885017ded6a24aee4dcdd7c443bd0569c0291bf4d29efa5 |
|
MD5 | 79eab3925f79a0008f882eda0e0376dd |
|
BLAKE2b-256 | a6bfc21903d81295791e5776c4d48da1eaa2e00a0eda143c431d21b081078b25 |
Hashes for stim-1.13.dev1692830278-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbde939a0ca2142e0ecd1f1a4d05fa37eafde4880e84a5e51666fa3498f94ff3 |
|
MD5 | e4a80f799e308003ada1c73cac4a808e |
|
BLAKE2b-256 | 6792264a46b09b465ac22b700afe57851f6470a27d44a5b6dd40ac3cf34ffbbd |
Hashes for stim-1.13.dev1692830278-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4391653f5932526f265750443e27684d93b33f9fa8db96a7b00721f3018e57b6 |
|
MD5 | 921fa96fcab3f4365744a6c36c3c2c98 |
|
BLAKE2b-256 | b677a550ac2b302e54e9fdcb059a82be029a27bc96269e6bd549de7f26e4f8fa |
Hashes for stim-1.13.dev1692830278-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5fae065d7d88b4859e071d93cbb8e88101709baf30556f072dd7a2a7441f0cc |
|
MD5 | 666921a45d4c72b8c928593afc4b4856 |
|
BLAKE2b-256 | 10dac507e77b3a0dbcf299453491933e377de836cbd280186bf1c8179a7e063f |
Hashes for stim-1.13.dev1692830278-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73aa19c341e4aa1da24f1051a6c2cb630e1b200cf3bf1d526cd02b4b03174465 |
|
MD5 | 8d51819e1c235da4a05a1c2a66ac4e5e |
|
BLAKE2b-256 | 161af47704e1690e60c01c550832811fedc344fb382df036e432430fa81a7111 |
Hashes for stim-1.13.dev1692830278-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dcdbb5b8b90dd066e0a092fca1034890f91cd1fbfd4929f5f99dfcc514a0ae2 |
|
MD5 | 4671c98c974da14d921b68b7963cca50 |
|
BLAKE2b-256 | ef9bb59959bf67ac201356748d2c9d96b6627db7817a62599234628d544c1e67 |
Hashes for stim-1.13.dev1692830278-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d6924de72ec1a24f23876c7b67fc203ec235542e7c531ad424c325523e42b8b |
|
MD5 | 525e9d1e3c8cbf52b9641055bed7500f |
|
BLAKE2b-256 | c00ffd8ece74b70fd1c6303a14c8c033f62a06c6f9d50049ff8662ea25da494e |
Hashes for stim-1.13.dev1692830278-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3edb3e368631c89275565cef8ec801f0e1afdcb343ead1954b6b0ab67f5e426a |
|
MD5 | a335c0eac15004ac33290f7a52edb954 |
|
BLAKE2b-256 | 79f815205426a5ec0da5197cfe2d3b4777145baa388afb4d921a07fc7675fb9f |
Hashes for stim-1.13.dev1692830278-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2817bec297837f6bd5afb5c0a2daac867e0ea2a2eb6ef7a607ebfda95da00431 |
|
MD5 | 07131a76a4b78d06b5928a19b0a35ef5 |
|
BLAKE2b-256 | 543d9887484310151629b5b959f8213f2fd5c79b8edd024429d29db228f0535e |
Hashes for stim-1.13.dev1692830278-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22275193a9fc5bd1eb8232024a8ce5e4715408545aa97495bac9045fb5832cec |
|
MD5 | 644bfe66d8d699918680e2c2511e2f69 |
|
BLAKE2b-256 | 8456c6d4c5ce5e8a41ae460aa984fba36c638c890861d2d2723e13f3cf6189f4 |
Hashes for stim-1.13.dev1692830278-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60203fc85c6bc084cb1ba8dee506736192aa7946d5e899b00f0934e8d7f243fe |
|
MD5 | 5a1b7ce8da42c99a3ab641f25a56757d |
|
BLAKE2b-256 | a83f13f8e4c18c3d1a6121a7ec8f88453c30d3c4e3ea25f40d9cadf28985ce93 |
Hashes for stim-1.13.dev1692830278-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7836d59dd7a549385710e70185558c1ee578da11edecd767fc19904ba76224e5 |
|
MD5 | d8a452e95a965cad9a296e2ea7c10645 |
|
BLAKE2b-256 | 98b047c19c1a7d7290cb806a48d3d89bcdcf814558577f384643d2f9c05af210 |
Hashes for stim-1.13.dev1692830278-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ac18c0342347f1ec11eb814c16b9c6cf7f06c2bb183b82ff2b4754cb3440ae6 |
|
MD5 | 20c4bc42ff2fcb600852edea533376b4 |
|
BLAKE2b-256 | 6e7345873a6f18418febdabbf486b02c1ceb4390558be0dd4c54859f8190bd71 |