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.dev1692512639-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09318d948c3d1bec1b539a0e4f359ec0f7ef4eceb34a3e13df1123ef79ad01ee |
|
MD5 | 5ebecfd5c146efd59d4fd6c670d380e9 |
|
BLAKE2b-256 | 15623c57e7b1d67f5c7b0604b32b67876dcc212a771ac04a6a6b431ed445d4fd |
Hashes for stim-1.12.dev1692512639-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d65efe9811dda709b59ab661884bacbe4c6891581ce5026a3a182b566ad4c3 |
|
MD5 | 6912c81d6b3823a87981c1cdc1fcd2ad |
|
BLAKE2b-256 | 8b2149de14c6491ba727465c300a2b73dc56d896755349bcaab280cd54ca73ae |
Hashes for stim-1.12.dev1692512639-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3a06114da923e209d82c7f10d059a387a484bb194c3cc2902be98e7a953f9b0 |
|
MD5 | 54c64a04357255e354e1f91cf15e73d1 |
|
BLAKE2b-256 | fe532f455db0eb7da04f8e4baa550e257a5f4290eea2b8603a731145de8a1594 |
Hashes for stim-1.12.dev1692512639-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b80123b538c94f149948a69bc7be4199b936d1e7a95134862c84d5efeb6a84a8 |
|
MD5 | 7764cee49b232b1763160a244d4f883a |
|
BLAKE2b-256 | 2f837dab9bf7db1f861cdcd0a2306a868539e5de62180dcc6f2a9ccbbc54094b |
Hashes for stim-1.12.dev1692512639-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e82c9b21ad948b316839f8bb4a4016f73f90d99b1cffb2e019b90430da7e4726 |
|
MD5 | 97742c23f9f17a6e26d07c831d636770 |
|
BLAKE2b-256 | 9fe22fbae58c625e1e3fe585c03d7c2100c8aa53d23fe6ff1e58c1f95be015d0 |
Hashes for stim-1.12.dev1692512639-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 759d467a16ab409c56eb2eeda341475e122e6730b5f91d7f035dd763922a76ae |
|
MD5 | 418dd6c4db13a5739e806f7efaf02b66 |
|
BLAKE2b-256 | bcf435e6bc22115f831c2dadde264d4010b61c392ec454ac1be5f0fddb91ff7d |
Hashes for stim-1.12.dev1692512639-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7699044f3b0f788a0b5cf05bf7fe3795c3c9fb2a3d1fe89abfe746fc43d069c3 |
|
MD5 | 8f9f15375825f93d781ce24d21bd6cd6 |
|
BLAKE2b-256 | 26996b8d147920dd7ace0040089eaccbee1c20c22dbcddc6e5728b4cc5568e9a |
Hashes for stim-1.12.dev1692512639-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87dad8b4e39a07d4774d63ddd9d47ba49519cba8bec32a52dc5da4739b4fcc90 |
|
MD5 | e809e24b2794afc0899109c68dcbb33a |
|
BLAKE2b-256 | 9af0a55f10e59cf702a62cba2d1106bda19500bc258e2c770d95e5569760c77c |
Hashes for stim-1.12.dev1692512639-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13b3a9c4b63d27dd0977e64c28ef385b14376a06b3adc2c956ae18e1300ba06f |
|
MD5 | fa9cd28dc39d7869d9838696ab9834be |
|
BLAKE2b-256 | e97188418c5ace53be6753aa8de775acc22ddf63e86e9754737a492d6e0ab830 |
Hashes for stim-1.12.dev1692512639-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c65e4d14225ff842b7b2917550c26bd131b9b98f8ffbeed844ad73694d3b7f7 |
|
MD5 | e40e44a3e4a7a502d2c5d1ad16e75565 |
|
BLAKE2b-256 | 512ad7e4fc4bb85b5a6316f82527ed6579d94dc7e9cc06b50a6b574b3bf85610 |
Hashes for stim-1.12.dev1692512639-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 124e7af01fcd837d94ed144bce89bc6aa25d72a3e705645358f60b9a690ebc81 |
|
MD5 | 3de847befc51e60fcca931e362b653a6 |
|
BLAKE2b-256 | a6dc5c9161b69fda1bf5de7612b535a5553f8aaa2a6f6f5a510ab2eae95fc1f7 |
Hashes for stim-1.12.dev1692512639-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d1311b1cdeef59058534bbb4515cfd9ae52e8e7d2ae22054c3666f989b0082c |
|
MD5 | 59bad07fa1afc1febbd4f85e8192bcf4 |
|
BLAKE2b-256 | a674b30edc14c2826a190ee29d00bec1869ea8f3fe5f9f2eeda50face1baccd2 |
Hashes for stim-1.12.dev1692512639-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3feb5dd97af71337e54f5da2e72bcbcc08d7a076d2c390b72d19ac567eb5f18 |
|
MD5 | fc3f4b90cdf1dbb3be408c9e901c7022 |
|
BLAKE2b-256 | f432de6590df09b2ef4baf3b994256312fa5af187a39a93f9f7aba8dd4a45f72 |
Hashes for stim-1.12.dev1692512639-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a7b269af470e0792e2bcf81235dce735b465fd74f61a83786329a21750e4074 |
|
MD5 | 6bd1ca98097d3e21254e822b16c66e84 |
|
BLAKE2b-256 | e1facc26217edf838757aea0efddc611533e9e519de0fa5971d48e13f9bae137 |
Hashes for stim-1.12.dev1692512639-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ff7e04f5a1c65996d36ae66b15469f7fc26f644475696bc0a6124eff9bcf5d2 |
|
MD5 | ca1502ac31b4716f8abdcb1a97f5366e |
|
BLAKE2b-256 | 2d94249eef6a3b95ea0c2c4d424c56608cb3c7a160c77d4d63818abc331934a0 |
Hashes for stim-1.12.dev1692512639-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b982b24ca0f89148d94212727687b21b90d47d1485f6d1033e7a8fb788c3b1b |
|
MD5 | f86787ae4e9e47a1527b0554b865ad30 |
|
BLAKE2b-256 | df1ef47b932d85fd5934cfecb80214731fbc8efd7b71e7a5fda92c03826ba297 |
Hashes for stim-1.12.dev1692512639-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9f3c84d19ac91b2515428e466446895321eec5d72c362f242af329a13e3eec0 |
|
MD5 | 055d61c4d95cd638ceb998a3f6d1aa20 |
|
BLAKE2b-256 | 7dd84a6cfac1b8181c27d5cb4e3d3742cf17bd42600a4aa3029c5650b7fdceaa |
Hashes for stim-1.12.dev1692512639-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca7838e68c44862f41bbc4b423109df175b362e3900f27205df5074ac7226225 |
|
MD5 | 92f0d764ba68383f2c36accbe882ce2c |
|
BLAKE2b-256 | 7862acefd8f1e4e917966e566cc8f61e9d2986bbb80264108542d931f06d85c5 |
Hashes for stim-1.12.dev1692512639-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f77d570d6e5d8c86ddaa0694b4c4cc97e7feff18b5e049f3ac8ab21a0635e0f |
|
MD5 | 80f2782c7bb576fe78c41139799127cb |
|
BLAKE2b-256 | 1d6e312dcc64fae5e12a6b1a37401cda33de26476a3eb9bd99ee26b93586030a |
Hashes for stim-1.12.dev1692512639-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b8250ef40592931d6b25749e005e1a292acc8c8504d4511a8d82bc8d0dc55bd |
|
MD5 | b16e7caf1c401adbcb3522b6b9111f97 |
|
BLAKE2b-256 | ad49dadc537541e34e805660e91a46e95a2dd293a2d6d3688af60509bba4a880 |
Hashes for stim-1.12.dev1692512639-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e871d80dffc840a7ae3051b14d4459edfc95a82dbdb0797cf58dab481d3c1129 |
|
MD5 | a6f1179d6c383c9b4290e31fe5ab7164 |
|
BLAKE2b-256 | 841db6362062de2ecf2a7c5c74482d4e2c70a3ecf0a0d1348d5cfebbd6480895 |
Hashes for stim-1.12.dev1692512639-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac04cc2cad58de2511936fbef863c459f0fb342397a10aa59ce60b39df840291 |
|
MD5 | 033a0f3f6c2237e04d9440d6ddc2501b |
|
BLAKE2b-256 | 52b998c79541aa4bc209b08190a2676e957f3b6a2b8e9a3c56fa64e5f751a11f |
Hashes for stim-1.12.dev1692512639-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83d68021d5e93707027c6568fee1c4437f538d14f46e06379df732ff80326a0e |
|
MD5 | 3ad12c9d45f9f78513a6a4b2c2e928aa |
|
BLAKE2b-256 | 4e7bf8c28eccf5903b55e4c149c83a948ea56b606a1834d70eb9e89a8f891e35 |
Hashes for stim-1.12.dev1692512639-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b64221a4e5e418931cc6eb2ab84e360403acfb4e19cd9fec3c3da49d490425e |
|
MD5 | 0f0092bcc174be48974be98c264207bb |
|
BLAKE2b-256 | f900f4bcec2f72b39120eba3d0adbb46acfc3430e913a3f1994ca42257b8261b |
Hashes for stim-1.12.dev1692512639-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77f1d7af06b918a536e1d6cb8a6a595ee40aab6701dbb29b2760aff8e428e38a |
|
MD5 | 2aa3773d3687c42c7d8835a3ff2b4cdc |
|
BLAKE2b-256 | 388a2d3561743252e75dab663122ce3f7a29d0d77904bf37df2f98d62516a17b |
Hashes for stim-1.12.dev1692512639-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4430d5f797407b1427102e72509c5f23804605f1989a04921d3cc0da1e14bfe9 |
|
MD5 | 3a9a3217ac496faa0a85083da37f3237 |
|
BLAKE2b-256 | e667393abef527a0deaef45c0ae46f6936231ca29aa7cb87471e6da1e1ecfdef |