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.dev1694742489-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 066e5af8673216729fc01808d57c9b73ee06d6e2d6f8edd3ca766254027dfc89 |
|
MD5 | 51399c4b6a58751b466793c38e9d6eb2 |
|
BLAKE2b-256 | d69c414086d083c0cf4702fe4e33709df876c5044e771a14d9e82d427207a656 |
Hashes for stim-1.13.dev1694742489-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 115bca4377ebbd95cebf80336c16c6132304876028ef0442d85d96b31401ecf9 |
|
MD5 | f11b089232d76dd75f5c6a955d525939 |
|
BLAKE2b-256 | 35aefd941f35dde1ad7c585523e711d3e06b6495007d1cd0069fdf749cde1da4 |
Hashes for stim-1.13.dev1694742489-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2a5a4d67208d09676f47aca5ee71276b8ae9a3cb3989b840d822e36dab012f8 |
|
MD5 | bf17c316a3279bdfcba302ce009fa7f4 |
|
BLAKE2b-256 | f7bfaffd3f39939e490d7bb185896374362df92ecb540211e1fe4b78e53819f7 |
Hashes for stim-1.13.dev1694742489-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0765f365f9be6339a83ca57dd2713619e765bddf4ecf520161199e7cd3cc6c32 |
|
MD5 | 01fc3cf221e7a8ccb32568490ac0b64c |
|
BLAKE2b-256 | 550c35bd97a9f8d4467ae7edde976c9d57183e7c3371462abe14aa652e22c702 |
Hashes for stim-1.13.dev1694742489-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fb1fa7d80b9a6566545c4424b4739c8b171347d1d813ec453b70572ac3c7fce |
|
MD5 | fbc06c442f3c15ee6e6897cdadff4b68 |
|
BLAKE2b-256 | 68d2c225496395cfb393fe664b59990859b3293fb53c7a287f2fb3de7185440c |
Hashes for stim-1.13.dev1694742489-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dca2359cc8f476a4863ea25ab849279305f426b869a1a10de547d175f1336f3 |
|
MD5 | ae9a7059249b3fd7773c131a09f7ec5d |
|
BLAKE2b-256 | fda2908c3135f693f64d6e133c0b78358ec1323f9a78980ff37a7fde3eb6160c |
Hashes for stim-1.13.dev1694742489-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f8903f24ef405b04b75f28c8ce8e9ec97eb2a91b55b561fe00526a5eeeac0e |
|
MD5 | 8ce5aec160f82c8b0f7959c8097e0d9c |
|
BLAKE2b-256 | 9fce00c80829839d2a59fa4c3b644b7824065a9dd0a86732df358fdff4299e14 |
Hashes for stim-1.13.dev1694742489-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c97c79d66199581aa2e1a3af4328ee2f91f1dabf2acba29b5eb0a618f8c4bc0 |
|
MD5 | 42b21c8dd25e94a56e608f5c85bb7ddf |
|
BLAKE2b-256 | b25bef8de17a10b8db13c1d31a86f8ed86bdfe90fd26cc08bbb9c134669ef9b0 |
Hashes for stim-1.13.dev1694742489-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d100173afdf8a4f089cf4159972e1c8061b3bd2d602f8ed7018e73781a86717a |
|
MD5 | ac659d841ca18252e63466d43c210d1b |
|
BLAKE2b-256 | 30fa8db0c47515fc8fc2709d5ec1264b473b61d591332464b1fe6ed1f6ba88e3 |
Hashes for stim-1.13.dev1694742489-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01699e9cb253d6c12b6d0cffe8e9b02831afefbf0b3824bc4feb2c271c4809ac |
|
MD5 | 0bea3bcf582650df95010e08934df3ff |
|
BLAKE2b-256 | 3453c4b0dac8f0d751b29e42a087cb22b0ebd52066f20fb6f970c79d3cd6f5d2 |
Hashes for stim-1.13.dev1694742489-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9fb5c2b0ed2dbd39bfeb21dd8554fcb6b81cc1898a922c9fc956ed80eed61df |
|
MD5 | 5c9e92b6d6d6748eb885b18d0da237f3 |
|
BLAKE2b-256 | ba886bdfd2b353e14a2221b8251df2ddf9c40f6c5fcfe217e9cda4333ab3ba33 |
Hashes for stim-1.13.dev1694742489-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebdfb7b1c1f47938ed502d9d98c075ba221f5aebbca28e1bc7ca1d80703c0d6a |
|
MD5 | f42f04b474f28b40c403b20b66013a7d |
|
BLAKE2b-256 | c30179b4e75acffc39c6bfd3d2ea84b89eba552303681f9f497d8645d17d9557 |
Hashes for stim-1.13.dev1694742489-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b98e38b0db1f0713a6c5f4ea376b7988269f39e1881906af8828e1c2e92e6a |
|
MD5 | 3a88b3ca97a2c4b5564800160182bb75 |
|
BLAKE2b-256 | 16b0914bf766c896546036f867e4b90d35eb05b74387bfbc8afcc3f89890a4d0 |
Hashes for stim-1.13.dev1694742489-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f65fb36ee191752c8fa6a63c72cbb7b93f43ceadb9af720883a14fa4e1c6f72 |
|
MD5 | f304bca1c8ec5e8041e4edebaa12164b |
|
BLAKE2b-256 | ea809572ca0ac9d5682f8db8f916937aaaa1818d36bd2461b815f55f12eaa49b |
Hashes for stim-1.13.dev1694742489-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f04ef27cd38a76761890ef6d6a6765d8b11beeeebdb8da53fc1f0c4e67c0426 |
|
MD5 | 049174e0522ec2a77aa4c2add0564ff6 |
|
BLAKE2b-256 | 445d4417318f1960cbb249c6fcdea58fbf5f2a3db15be9bfd7482dc60d61e3dd |
Hashes for stim-1.13.dev1694742489-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8b3f4272dc4f72f12380a2e971529c979779d945448f3566f5362ad94eb50d |
|
MD5 | e938a45422c5605b6b1f473007311381 |
|
BLAKE2b-256 | 11b82a47abcc42a107650a59a4cc6f4495f8ba06e564b6440ac716264a0f5b70 |
Hashes for stim-1.13.dev1694742489-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 935cfd3929c745ee8b50b887072ac04634ba3e2396be9ee185f8bb9e927553e9 |
|
MD5 | e6779d3970a192184f5f2939a333a718 |
|
BLAKE2b-256 | 9c3b6ab79c9c84276df28be1a89ed42eadc1d791312c62c191ee51b629f52fc1 |
Hashes for stim-1.13.dev1694742489-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac24d6a22363b4f89aea8a1a607901501a538b988210bdec91e3674d1712171 |
|
MD5 | cfe0f1c8a22dd6ad8c62909b42a57fe6 |
|
BLAKE2b-256 | c3c478c8c745f310809043205ab9087f40bccb92fd0f7489cb0e50e4ebac72e9 |
Hashes for stim-1.13.dev1694742489-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c55c1f13276665d292e841d9c80511a3d9735bbc57aedd5db414269916b4aeda |
|
MD5 | 3367a10f1842238e2e3dc6fd019c6d86 |
|
BLAKE2b-256 | 64dbfaa3930dbd8d6455ff23bcb490dc824c0215fa1cc101b2f9401b15dd0163 |
Hashes for stim-1.13.dev1694742489-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca077bc89652569a4901437eae0eac74c2768eb6c43434bc3739bac70eb5007 |
|
MD5 | 15f9fb10b34e23f368b18621c140b658 |
|
BLAKE2b-256 | e621858670114a8fb562749bfa6a2235c48135cec9f7a3a734553d82b5ec94cf |
Hashes for stim-1.13.dev1694742489-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7239ca4fbb3fabb45105c88229d27682b079e9c7d98b7404dc1ced6faa07052 |
|
MD5 | 3383304b627a7279390234c3193724e7 |
|
BLAKE2b-256 | 9f7473597f3e162d93f8ce2c64c8c9a6233d0341e3a5c95734f87f9cd9c55377 |
Hashes for stim-1.13.dev1694742489-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd4837264a346741e2074cc30580fed4954b06280cfc791739b235cfb2315c02 |
|
MD5 | 257d23a0fa0ee377e592ccaa7b83c082 |
|
BLAKE2b-256 | c43ff56ff021f744b6cbe5545d76ff31d7ffe194443e12f70f11350ae012c313 |
Hashes for stim-1.13.dev1694742489-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a03d46d0bd79e985812f3551ec6914a1a2de827ea1243f3df9221730ac21080 |
|
MD5 | 8912d21b81af46f4200cc9d3c08097f7 |
|
BLAKE2b-256 | 82f4d529210634c342995842873baa3728203e7bb9334854e75cde21581c3a37 |
Hashes for stim-1.13.dev1694742489-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41bacd2f751bee5a3b0b78099f4a811fb1765e5af414ea19527a5e5738590d4b |
|
MD5 | 25405d309a94157db6c5d5947c363400 |
|
BLAKE2b-256 | 25abae3d316ac98def28d9ea328cee2087e9a9cbfebad739b00b6cd1549ecc0f |
Hashes for stim-1.13.dev1694742489-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a405a7844aced9e70aee1e522efb1328ebe62ea7a1a8a4d1f3fad8cee605409 |
|
MD5 | 47fb5f0499023d160688e1092e84756a |
|
BLAKE2b-256 | 113988726cb1a4906dcc17d7335a50586d211625e531980a2a6c4b4ecfa05edc |
Hashes for stim-1.13.dev1694742489-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9139ce649fb3b2a773f3090295c45d96033eafa213771bc324b65853e9394114 |
|
MD5 | 692645e560a7b92ec803a2fe0879efab |
|
BLAKE2b-256 | b26a26581d3872efbc8d2478c8227ef5a1a2aaf5bdabf62e0a6bb5ba09e60263 |