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.dev1726206696-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db92323dbecae3bd538daf936cf60fb1730f089dff83638b43fff950c848833c |
|
MD5 | f56fc8a697bef6b8c0ea9ca9ec4698cd |
|
BLAKE2b-256 | 03abe5b8d8163f8dfda56f0f2ab9d61fa2772d92f3dbf45d0f5d53133303f61a |
Hashes for stim-1.14.dev1726206696-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 028293dcbbe894a635bc38bd2f7e61342b9d90969a92dfd9bdf8956ddf0b860f |
|
MD5 | f01922687082225873b300ad13024ad9 |
|
BLAKE2b-256 | c006e11f9e8da2122a69d032ba1ec6528db86499c9bb2375376e278fba0d8d07 |
Hashes for stim-1.14.dev1726206696-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67052cb1bfdf3b7b717a356d6daa9719c644aa5217693942e346a7ab563efc6a |
|
MD5 | 9abe7db992973ac5d9e2269f5bd1b043 |
|
BLAKE2b-256 | 504a58186d1d1e374ab0d088c9fb022839f0e899f445eba20795826774d10faa |
Hashes for stim-1.14.dev1726206696-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a93bc78fe7782338f1e6d9ad1953a9001a6fb64d6f9e56a7d414998c7a831f7 |
|
MD5 | 04c587ba7c9a272eaad66f89361cd735 |
|
BLAKE2b-256 | 53c786f0eb1e2479cdd0a8d553dbe77aded707429009edcc03b42af9d6f53e44 |
Hashes for stim-1.14.dev1726206696-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9100bc7b46f320d7d8a08d95a2a3eb4198d62e4afc8f6a9f665c9537ea402aa1 |
|
MD5 | a7f5fd66e5e629ce22f194ef163d3398 |
|
BLAKE2b-256 | 3208b9664a7680fd87147e4135f70b8de776fa3437eb944dafa67ad7d799fcb8 |
Hashes for stim-1.14.dev1726206696-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f1ffc411b504874995b3da86a959c6878f2bb2db36948677cff72de2c515f9 |
|
MD5 | 1c18ef69366471dda6ea711ffb7ddc7f |
|
BLAKE2b-256 | 4f8c732f09f9c760a4b6fc79545cc587580cb8c5f08222010116f4c027ae7c3c |
Hashes for stim-1.14.dev1726206696-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3ac62634e4dbd291dbc9a5256b0ddb6f8f7ea18e1fc921d519acef8918bd441 |
|
MD5 | 140b8f91e7a9630ecff5fbe5dfad6730 |
|
BLAKE2b-256 | 1ec6487faf51945ed1213e10d3043bb1dec1f3cbefbdace6fb7cdddc4cbac3b3 |
Hashes for stim-1.14.dev1726206696-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 124c84da44d43b6d8ce7df4912ea16c16e7fb8f1d0643e1ae0248876473b7eb3 |
|
MD5 | bff647c5a3a154412f02736b8c1a4d8e |
|
BLAKE2b-256 | f29b75b177ca0dcdec00486b778060e6dda9fa6f94d34c97cd3d83a442c87d3d |
Hashes for stim-1.14.dev1726206696-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29e225c8cbaa5fc9d103dafc2554a654a243fcd3907641f0ad58fc623d5eb7b |
|
MD5 | a85ca1b1a6172c78001a5c9dd7f08144 |
|
BLAKE2b-256 | 46934e11a69901b169e3b07406388d179ebeb0b400472bb0b1fffa7c856eef0f |
Hashes for stim-1.14.dev1726206696-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45101300448f6d836b28173cff2c70fcaa88b095e76be579e7d7332935ca77fc |
|
MD5 | 6e3f550ab3ab01d08896c0d199987426 |
|
BLAKE2b-256 | 6a9378a4bad51c7778c02932c1143415f94c111ba965bf2736185281fdefaf53 |
Hashes for stim-1.14.dev1726206696-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 793c65efe0de32cecf01f7738dfd39ebc3a7f2e20ce964a035ff969fd71f97a2 |
|
MD5 | 644cddf4fe4e5161f78f85027ec8a30d |
|
BLAKE2b-256 | cdc6c2ad46a3945833c4dc39a7fb46fb73c79abe918b8ce6bc59e2faa98d2df5 |
Hashes for stim-1.14.dev1726206696-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee2311219c4d4d2190a84422dc50ef0e26165250c09dcd0c28d483d004474f6 |
|
MD5 | 6b1b05d4d4f193df2f6973f49e143ced |
|
BLAKE2b-256 | 541080a6faab320d9ff218ab325987a0180f44bcd5c1251f8f671b8feb6b2008 |
Hashes for stim-1.14.dev1726206696-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67d0285a01ed75b5cdc645c86dab045423bf35c954eb2d75c2ae53c007d2a0a5 |
|
MD5 | 755454adecf73886ccdcb5b3181f8289 |
|
BLAKE2b-256 | a821bdaea9cb500c7296b7aece501caa7c918d5459b3e16a4eb90b45b913acd8 |
Hashes for stim-1.14.dev1726206696-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 334f3e735e5af8aa9077ea3f441185fc92647c3ce722fb7373e2c704af19dc18 |
|
MD5 | 226e2c52f7ba9761ac1b449db6252512 |
|
BLAKE2b-256 | 3fcf823518cc2e33d4d069e4b9fcaef2b48d1e207b7d0356da341636ff05024f |
Hashes for stim-1.14.dev1726206696-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37555cfca2620585dcdf5ba5a22b6aa0b4984a5f7435c87a636c928df7ee3729 |
|
MD5 | d5af29b2970fd5d9568daafc61c88296 |
|
BLAKE2b-256 | c14f27d0e8dfefae085a4806179e7bc8dad44af1e34493441d00d4550f1bad1a |
Hashes for stim-1.14.dev1726206696-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 659b0d9cb142e3b6a3094f4e7ef08a127043c85136a88e5bca7342ed92546005 |
|
MD5 | c6433c058ebf5425855cbbc3fe8924bc |
|
BLAKE2b-256 | 2647544f63e5ffa632bd6b0b64dca192590e0f86568b5b037fa59e0a872822ab |
Hashes for stim-1.14.dev1726206696-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2123514835ab9ab95705e53e9e6a6644677c0426662616add0da200f416c0e |
|
MD5 | b007f922df3ecd7ed3711fbf8299d99b |
|
BLAKE2b-256 | 3497103417b26ddab44a0739fb2cbe227cacf98795961240be0c7fcea30d950e |
Hashes for stim-1.14.dev1726206696-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b934d4b72127459bb74b8568dc63543afcc482f9a175cb1dc4a1465e60ee5aa |
|
MD5 | 48f324e851e3cf1bea0fc333274f36e2 |
|
BLAKE2b-256 | 6d4050bb9a051689420ea472e9708ab2abce100a4601c9c837f2e0cf8202efb7 |
Hashes for stim-1.14.dev1726206696-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dacc2f2b2e05ed68a07a33ca3b6c8c6ce82a8bcfe4efbfafea90049c7af6b68 |
|
MD5 | e1ad1ab2b33d255d470a376208db764d |
|
BLAKE2b-256 | e66d3d2c99b0da0e0c4ad8bf79530bead9fee1f0ba6acbc67c41c79708d0407d |
Hashes for stim-1.14.dev1726206696-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aa2ea26b71e4cb8c61e997552cb57ca68ab74afc2e3264541ec764bcc934c31 |
|
MD5 | e91c55cc7070c4ada62aa35b2c439e1f |
|
BLAKE2b-256 | a97d5e14e10192de1a8d8f3ad4cf9302ae0538ceebc84cd447c9b60cd6619ea7 |
Hashes for stim-1.14.dev1726206696-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ab07430a1f6212f0fa59e3071ae26646c4586980ed4a90ebb91308077f47ea5 |
|
MD5 | 8cb7ecb1ee08be2bf640a52dca8bc92b |
|
BLAKE2b-256 | f8166d5af599433ec7e85ca90d24caae8c8619031ee29b996a78e3a86ae50775 |
Hashes for stim-1.14.dev1726206696-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b7b25d2f5ad118d93d5105654144fa402c9ffd7008fcc6bdf34dd9c00a7437 |
|
MD5 | 28e4ec92e9a92a6ad7f4cf0a097d5acb |
|
BLAKE2b-256 | 42ef7b51891106268e5c3ab052d0f2c352c41b1c9f735090a08d65bc5b6f6520 |
Hashes for stim-1.14.dev1726206696-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7707b834b778db26202215882fe73632d06bdc6e2004e4734acfc150741e2e85 |
|
MD5 | ecdc5217199c0c1c00c914f4a59fcb52 |
|
BLAKE2b-256 | 8a8551a0ae6bc10c8d7184bff5ea8229f88dfc172f9e247b40946a4dd9aa8d42 |
Hashes for stim-1.14.dev1726206696-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ab6005ee74b0fb349d32ad848774f6fa94f42546ea71a36c4b72f67a9cb289 |
|
MD5 | 6c5c7f153584f38e87c9c01c1f2d842a |
|
BLAKE2b-256 | 7a2105d943792b1460ea5d9ce19b6a967f1437982e403cc85c798d9ceb58e690 |
Hashes for stim-1.14.dev1726206696-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3992a6ffd3391fbcf59ee689cce59d0120cd483272930fe6f44f3fb0b490691 |
|
MD5 | 74d4229c26d73becd00130bf14a0273f |
|
BLAKE2b-256 | e8907a486571259cf1007930d7e12b3c24b24734e7359cbbcad94873d506ae03 |
Hashes for stim-1.14.dev1726206696-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd94b5ab1f860a3db4e2435a71760faa8b68da64ca16183eeecd301293869514 |
|
MD5 | 9bbf4351c1a74184012d8234f0e52fc9 |
|
BLAKE2b-256 | 8aa0b40bb8e66beb26bb34036ee35b448dcc801bcfd3aefde65d56458d40a8a1 |
Hashes for stim-1.14.dev1726206696-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 009d1016b145d376003b970cedc43dc7da518102e2f2aefb2f8fd483d6f46d0f |
|
MD5 | 2c23af9fdfc68bb5993d6da5c7592f8b |
|
BLAKE2b-256 | 07d5f64e46e3b820823d50ec8bcf1932230be2a5c5062b30f50eb7971393ed9a |
Hashes for stim-1.14.dev1726206696-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73ea665025c852da70aa795af204cee6149601cbdcbbb6fa945f70e2532563c7 |
|
MD5 | d25de0c12dbfe9a9ff7ec209326f355c |
|
BLAKE2b-256 | e3996ccd4e1c751bba8669a98eceb720e5c753232254b491702a8f93bfe2f072 |
Hashes for stim-1.14.dev1726206696-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb5b6d5c84c780a853bb5f48b082ff617847040d18e15f3b80284e86533b0b0f |
|
MD5 | d9b96ff98b390bb504e2c63b014bcfec |
|
BLAKE2b-256 | 545315ff2c5675e550b0c7169739166deba633c805666038faece9534ef008cc |
Hashes for stim-1.14.dev1726206696-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9830d28a50b7453b750ca68ee28825ce5a5cd6833b2dd3a5d1c9f7860535d16c |
|
MD5 | a7d308992200c9086043ac8037cc436f |
|
BLAKE2b-256 | 3d2263aba5a87f5bc71ba352372a97dbd2a7654cc30d153a0ebf295155c59455 |