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.14.dev1711709508-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 512ed13ce8d070cd7db9eae932afe6e00dccb272053833e5366ccdb19cab8689 |
|
MD5 | ebb6f7cfd1bb010b15759410b93557ce |
|
BLAKE2b-256 | 80ee710e5555877877da871edea9092cbec20c8a7427e7cee33fa9eee3424c25 |
Hashes for stim-1.14.dev1711709508-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37841e6f36576eeb8696ac9f0620262b26f5a731ba0f304fada865fa99b18f8d |
|
MD5 | f543ec89dbe6733e8f7f042062a81d62 |
|
BLAKE2b-256 | 11e5ab313e59eb9bd808d9f9b26dd5a90a1aa507539fc627e831de49c84a6eaa |
Hashes for stim-1.14.dev1711709508-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab06d3a34df285d9de9c3e7fe65a74825b0ddcecfa6f7aedf3c82084c5fe1ca4 |
|
MD5 | 5209437cf774f740eaefb857c74196e1 |
|
BLAKE2b-256 | a482a38d14d009e87abefd8ed8848e93c0679442554e2fdd1b585dec237a93de |
Hashes for stim-1.14.dev1711709508-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e720870c277677ba589364c7d2f494ee67d46b2aa69d1c2ce76c9726cd9dc05 |
|
MD5 | 4b81e5f26502d2172a42c4b0a250c79b |
|
BLAKE2b-256 | 67d0045d0e45e56f40b7e3d0d4178e4d177ddb8e9dbd11302445c56c2cdd7f32 |
Hashes for stim-1.14.dev1711709508-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91681b963aad8ba65d3fedaf7be8c9b179a2f4caf35f1382c38adf99ec7dd7d6 |
|
MD5 | 5efe3f5847a362d179479081578255fa |
|
BLAKE2b-256 | 1469464aa9065a7d14fc2320fa5f911e807e6e59f7b1d06f16c4ebae7a2097f4 |
Hashes for stim-1.14.dev1711709508-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 739fb5c5bbef3023c0863fe43b4829da2eb1ea4af94756158a97aaf94a2bc75c |
|
MD5 | 9439194ed20a32b3847c6ae950d838c1 |
|
BLAKE2b-256 | d6f0a3ee4d73ab274eade724f290b36a2ae20fe87bedcd5c850a0a2214651c28 |
Hashes for stim-1.14.dev1711709508-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 476ae0609edf34e6a84bf2d6a4455d5311cf06d9676a533bded349a8e2079a49 |
|
MD5 | 30d8f3c7644c5e2bc3c77054916f90ac |
|
BLAKE2b-256 | 59c95572d38a0f7743901871865cb917c50449fae5cdd352ab74016cc26d7b99 |
Hashes for stim-1.14.dev1711709508-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06fde4eb9587b1933abdb8166322f76654afb962cd601550db9dfe701683b45e |
|
MD5 | 65deb62deee23c280e74ea2c4314131b |
|
BLAKE2b-256 | e8b04a2746d514a774a3c5477ed9669c3b53e426cf2447a6a472dce5d1e0b14e |
Hashes for stim-1.14.dev1711709508-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0d46123f841746fd97c85faf2601bd70dd4f33575d9f0d1bcc5a0f074a0285 |
|
MD5 | 6ece3e492b962ca196f9f2a45efc9ae8 |
|
BLAKE2b-256 | 24944c13b635f1e2ea58baf6f15d122917f8dcb34b66a5e68c12f665186b6208 |
Hashes for stim-1.14.dev1711709508-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce0275266a206413b2f1d2ffb933c9d2607c7b9d6954def2fd66f9c7e3ff659 |
|
MD5 | 5aa09fcb70c49634a58f0f4758067fb8 |
|
BLAKE2b-256 | 492b3fa9b6151673d6631215afc20ffaae2581eebaf8a54393dd315a06c054ee |
Hashes for stim-1.14.dev1711709508-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e36fa3391ab87a9bfc6176ed7a655d0edf80107f3e49bc71ef85889ece7e2cfa |
|
MD5 | 44b2dd67363b81cc2a603dd5a150d72d |
|
BLAKE2b-256 | 5024826c90330a5687cc12662ad2579b74ad15a5c4370df7abc5a20dffe71efb |
Hashes for stim-1.14.dev1711709508-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb3689c169be966f14e0a40272feba6f44025a54e7169e132a5fe0f8c71ca0a4 |
|
MD5 | 3e67bbd0b40d58b190c49f37a1bac834 |
|
BLAKE2b-256 | bff3dea194f45987bd222c5e7754d1a1122d1b91b45c340d2c450b06d10d5638 |
Hashes for stim-1.14.dev1711709508-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9681c3ab77b74d28372c9e0d033e52bfe32f9147b5f44ee8619a2c5f057a82a5 |
|
MD5 | 5e11013c4ccad89c69639588a7684c30 |
|
BLAKE2b-256 | 95fcb6dadcc32ad61fd42c5e81b033bb1377da0bc1b9ddd2ddc6de8dc7aa19a5 |
Hashes for stim-1.14.dev1711709508-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8faee58b467c6e745e19c3d3c2dc4f0a0dd01ad5ca93dccba1ae2bf7535730c7 |
|
MD5 | 8128294f8f703944f6a5a436a8f54b4a |
|
BLAKE2b-256 | ef6335480ed175d527be9648665c6c78be4288c1fbdfcff5a9b71f54bd6d8d78 |
Hashes for stim-1.14.dev1711709508-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6efca71e85e992cb235e808e5842d0f3d7db4183aa085b14dc04642de9b57460 |
|
MD5 | 1d3881a0238e828aaf1bbc9766458661 |
|
BLAKE2b-256 | 35c7d59a58d8489bd54c56b5248bbb201b562058b4e2309e1be5f65efe69a804 |
Hashes for stim-1.14.dev1711709508-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ece2b3aa09af1e90da191bf30d52bfd9930367d18d695f4a89c15f8c441b9ea |
|
MD5 | 60665a6e36258915c4c58d2c8389dc5c |
|
BLAKE2b-256 | 7e4b6acd59a7b95f604118ae3e6519a727d5c3e9726f83c2d48d7fa2acafde43 |
Hashes for stim-1.14.dev1711709508-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950973109f74bf8c3b99d9519747d444cb16bbca9d11bd120bae1e4f6ab717fd |
|
MD5 | 83b7c6f054de89f17cf9f8920a363e78 |
|
BLAKE2b-256 | 6d556bee158401bb7a4e10ec4ee9cbfe28767c2d917a668a2a9b6fc07f88931c |
Hashes for stim-1.14.dev1711709508-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 265a19d48caff71524135b7b35a4b9ce47c3c016a487d76fd34acaf218cd91b1 |
|
MD5 | e13d54fc0122098d615de82a0d4f06f8 |
|
BLAKE2b-256 | 0aad49dffe51c89fdcd459411f7d7d9f6d8be9777d58323d3d61ceb0f2c01d7a |
Hashes for stim-1.14.dev1711709508-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d52130a7c85f10eebfe7dbc591319ef26444f8b2d1f71db0d3cb976c6e35cd79 |
|
MD5 | a5901642745d25ca1a557f95cf4a853b |
|
BLAKE2b-256 | ef613ac12a2e36ff6f0634006e5caaa75c71aebb11a0821ef19ffdf4a62a238a |
Hashes for stim-1.14.dev1711709508-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d35b55683e37fc091ee46f12365f8d818a57ef40a00e2d234ee8989b4b39940 |
|
MD5 | fbc192b4be217768a867e3e52d777e5a |
|
BLAKE2b-256 | 793a5fde8be7cb51cbf2180aeb88d78c5b08ca681973057bdd17bca85721df69 |
Hashes for stim-1.14.dev1711709508-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3adc940b89686934f2263202b0dc1913e0dc8fbb424407620eab85bcb2a5488c |
|
MD5 | c350ecf72dc96d8d9c12155552159f49 |
|
BLAKE2b-256 | bb3ecc508e67813c580033e976f249a4cd9720ca1332e307c1434cb8a9d21065 |
Hashes for stim-1.14.dev1711709508-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 626547e849c8b46f005eb4f214381c19448c28e9446fe445a95380cb8f5ea067 |
|
MD5 | b66371b8ec9b2900941a8fe80857c9a7 |
|
BLAKE2b-256 | e3e85765f35ed2dcbfb7d7111b74d85d567cb7736e331080a677b3f073903f21 |
Hashes for stim-1.14.dev1711709508-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d023514a1b89f7a97e42729c63eadd33094014ff6001118187e1eaa42420601b |
|
MD5 | f42a2e693e5dfca0cb4b4d5c987b097d |
|
BLAKE2b-256 | 8a741604675acc62943f16cb91f2303eb1c257d2e92e51e506ecd70a2e45ca95 |
Hashes for stim-1.14.dev1711709508-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05b0e9b493f6588aed10cf64dd6528995e3046b292f5b99d2ef8293870678345 |
|
MD5 | 32ccbd21310e60a01a2cf6c545e7b0ff |
|
BLAKE2b-256 | fb8eb628dda5cb6556df29742931d420eee4d442963f0b51608aac00bd492e12 |
Hashes for stim-1.14.dev1711709508-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318a85c59c961e4ce20847ccb3002a67239e96c26b63cb618573c4ae3153c269 |
|
MD5 | c5f029488253ae0448324d127608a994 |
|
BLAKE2b-256 | c974f02fe831b2cb6ef52ef88496f22350f5735e003259b117ba0e7cde028509 |
Hashes for stim-1.14.dev1711709508-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a2ec0fcec83d52e0bd0ce2359ec3fe0c67420dba38fb40ae7fd68effec0b26f |
|
MD5 | 135cdfa5d45acd58cba366336ca97370 |
|
BLAKE2b-256 | f7a82dec99495484df4ef7b57eb516d4dc0b991c559b5e67beeeb1c6b5e2a4b2 |
Hashes for stim-1.14.dev1711709508-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e82e1444c0d2e7bcba6aa90394f6c8e7ae2aaa55993e2151327dbdc76e1cc44b |
|
MD5 | 33627742c5b2ec44e47311ad18145910 |
|
BLAKE2b-256 | 2f56786c1b5a1075a3563565df435b06e2d39eaf4e31040868dd905262ffc2d4 |
Hashes for stim-1.14.dev1711709508-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b1836b5a6786cf3ca4130924c7d5267fec02e3f40b17427ab7a95b164024659 |
|
MD5 | eec4a0e83dae4457bcac94e6a8716ee9 |
|
BLAKE2b-256 | 72d8f9bd5ba458717582047c0051bdd97b879692ec69a9b4d4a040df0c52a5ca |
Hashes for stim-1.14.dev1711709508-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509c50add07d986c7e3c321c2855f8bd73cb0f7edbca6c4532f07b93f57f8028 |
|
MD5 | 2e3a8467973a1af60519f743a0a06f8e |
|
BLAKE2b-256 | 9722c36138305f5f2b434efd234bc6972d234847292f264d23fad62f78411625 |
Hashes for stim-1.14.dev1711709508-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e651c1b0c6554e69f8ea18df24395f8ea4acc4f7341884836e2c57d10452f551 |
|
MD5 | 2e3ba6af377326477c25b9b9f4b4a2e0 |
|
BLAKE2b-256 | 3dd788356ced0d343d65e4a061cd89cee101e8a1396226dfb5e02b628221af1d |