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.dev1708140965-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d72c95135c8552fb13280d794eed418969e88870370d0e5de793d5bdcb876805 |
|
MD5 | 2251673e23d639b9295b37018b65b2c2 |
|
BLAKE2b-256 | 6b065dc79d95467ac50c5e6c572028a6cc942e016874c3dc921640b23e886082 |
Hashes for stim-1.13.dev1708140965-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ead06a79f9f3cd2091f42553bf2c7d9eaa346cd3c4ae14537c9e65ca47b274e |
|
MD5 | 63ac40a83802d90effe3a1054cadfbb5 |
|
BLAKE2b-256 | f7b0e28c61e1110fc1797709ae33c0bc365f466c3b40fbc080e709c74c235dea |
Hashes for stim-1.13.dev1708140965-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0316a57d3d78094eed2e6ed7e93228018c7d5aed9f1e4d547dc0f9964007b546 |
|
MD5 | 117aad520127e7d28d64c26d1438a8c2 |
|
BLAKE2b-256 | 2cd8041d6d8c8ce757ba96b08fb621f9a074f34fabeb6656e516837ea3f8468e |
Hashes for stim-1.13.dev1708140965-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 306cb750578ff19c46a412f375be73113491989a8cac8d00d60bd693d6fba1e7 |
|
MD5 | a0f482f6eb04b475fe88c833fca6c7dd |
|
BLAKE2b-256 | 5b23edb4775d1e9bfb0b45399a6c687631bb1f51018a0b12894a13eb7228c8d1 |
Hashes for stim-1.13.dev1708140965-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0589e9f5f984ef7c02778581d97a168245f8797be7eea93a8a795af4b9e478bf |
|
MD5 | c118683743a977944499126c68f008e8 |
|
BLAKE2b-256 | 40ce51cdb80b53cf7ba87750d8aee606e8c8a894253a93fa597cbe656393cbc9 |
Hashes for stim-1.13.dev1708140965-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82bc9695b4dacf2852328a51602a9286835ef72c20f88138e9f8ae2442c932bc |
|
MD5 | f4c9e8f6d2216dc6cbdf309495e114af |
|
BLAKE2b-256 | a75161c49da533249c3bc36555b82810bda2f3f41e8ee22aac92854d00bb746e |
Hashes for stim-1.13.dev1708140965-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26121571f57754107a99b839afddcf022fc5e7056c63270b5f87d83c0a93b03c |
|
MD5 | ba5967afe093cd63d770bb255c937a39 |
|
BLAKE2b-256 | f43deb43bd8c11772ef3fa8044e62dc59753a44534d1baff2ffc7d7dc810b875 |
Hashes for stim-1.13.dev1708140965-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08544fc76d909773177939d422bb46e5617effeb758e1b50a4f83eefb44483ea |
|
MD5 | aa2a707c904224d180227ca68ca6f0cc |
|
BLAKE2b-256 | 487621833f4fe9bb03b211f696ff545858522411bf45071a66441c540b721f09 |
Hashes for stim-1.13.dev1708140965-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3ad4c822f53dfe329603d137c9bd7c04bb21799793b24d8564acdc52382d185 |
|
MD5 | a87237a5c20b97afab2001694b475d69 |
|
BLAKE2b-256 | c7839e72324fcf6013b3dd2fc267861292b6183064ddaee96d15ea5779a132eb |
Hashes for stim-1.13.dev1708140965-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9503249cc63ff9ab62743a1caeee26ce8c715c1b956fedefbde4a2fac283a821 |
|
MD5 | abe48d9881d4127482b7905829a2a5a3 |
|
BLAKE2b-256 | 3bbcce7ec6a96b60360d0a7ba769408a48ab71c4f5a08b5f095295449ce93795 |
Hashes for stim-1.13.dev1708140965-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7880cf04da9d69d3f9ed1eab45b05e664f519b3767809f2b1f9fd4afc4be8d07 |
|
MD5 | 0f63ad49806fa48e4cfd4678e7710018 |
|
BLAKE2b-256 | cec5f1b85c7c781e46f6fc770714d62a59f981f84854fc1af065395b0d5e7c64 |
Hashes for stim-1.13.dev1708140965-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f065e79020220ee4692b850239b658fa2df0e7ba0ede58d9ef84eea4c0657d |
|
MD5 | 3fe0b487bf27b9455c4772fa779d1ff3 |
|
BLAKE2b-256 | cd3305b1dcb971dfc3687c570c83c01067d27fd076dda49800fa767ee418d167 |
Hashes for stim-1.13.dev1708140965-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 691ddfe5a48ede70db0238092ce383a0ddbe25acb49556753104e80b57fb943e |
|
MD5 | f48bee6bbb7ffd699572e374ff8a5eba |
|
BLAKE2b-256 | 265cc3ecd5c113591eb68bb37d6fdc654a1e4667ca2843ebeb5f370cda536d57 |
Hashes for stim-1.13.dev1708140965-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ee10865c8858d47f7aa6f7e5b5885242ad4b3c8cdaad9ac01d3743fcc95d5e |
|
MD5 | 69abc3e1ea3ebc6f97f917cf216667cb |
|
BLAKE2b-256 | a4d0d613d1d85982983578f3af311b0bfbc7da47134d7c3779e12205a1eae08c |
Hashes for stim-1.13.dev1708140965-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b3a6199b9a6ed1d453a8439781a58614e1161255151071e8663f54656999304 |
|
MD5 | c19a0459cdf059b2a2a44ab485dda173 |
|
BLAKE2b-256 | 9740a97e279ffffa2172992a93c40c3e7fa67a8e350d601318c40c85a5c311af |
Hashes for stim-1.13.dev1708140965-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc9e2bd1b71300a0edf73a4bcaca4bf9ae6831cb26a847a17a7d965de6717f84 |
|
MD5 | bae0f6ada37121a3ace13697d051a8b9 |
|
BLAKE2b-256 | c684c300c72f609b0811402b82f4798eb5d7e1e79e012b915b0ab0a10f46da44 |
Hashes for stim-1.13.dev1708140965-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7192a273612039f6258d9fcaa2f4615d6e99b13a1aa095a54fd3acef509d5305 |
|
MD5 | 6b719516e2fe3e8dbb63e4ca01667d96 |
|
BLAKE2b-256 | 1868b01d3367fbd2bfb35838ff43cea84d8b26457eb69492fda262675ed78fab |
Hashes for stim-1.13.dev1708140965-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b29e9bc917ac72e52a7461717f7459664835607b327c05c35bad6e11afa012 |
|
MD5 | 9de0f3641cfeb7a6e76a5132d30992bb |
|
BLAKE2b-256 | c77f1d5b9d0912d75167d1ce187b40607a33293b21999c33e8d3876a524675a7 |
Hashes for stim-1.13.dev1708140965-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25721e388c071e84f2db76f95b911d8680d189dffeaddc3ee51a6ef0dc8e497f |
|
MD5 | ecfd8cf987000fa300de81e2cb1c4a58 |
|
BLAKE2b-256 | a05126c9923414fb8d4cb887e30ccdfd50dba89e79ff33d7295e8d712e03bc78 |
Hashes for stim-1.13.dev1708140965-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab8c7b374d9f419bd2c33b5e28167870ec53bb7e2c1c53caa1d51546af6fb4e1 |
|
MD5 | 06954e494c0c0c4df779b0453a35782d |
|
BLAKE2b-256 | 7b739933f325da9ec56ee29bdd368828dded10ebc10ee545e8104772ca9a2c0d |
Hashes for stim-1.13.dev1708140965-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 983cdb724936728a1c3c863949a2b219be7dd4d60f01803d6aea05fe86c50d05 |
|
MD5 | ae95c308218f13dd77df2baeb5e31fc8 |
|
BLAKE2b-256 | ad9e3e4184ce2025287e4eb752af9efb3c21d2bb3d010e89f56984c34b71d953 |
Hashes for stim-1.13.dev1708140965-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 452d2b0b1f084d67bb2e3d680828b3ef101a906f793c3134e4395bd71202be88 |
|
MD5 | a43e58fca31a3502f602c06c082ee1fd |
|
BLAKE2b-256 | 1067b584c2b39b86c57598e5d42924f972dae4aec7c1ef5ca0d8e28935de373a |
Hashes for stim-1.13.dev1708140965-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96cb23945e2159d8882a6f795626b4a8a27bd49b44aff30cf2ba60bf524b19a2 |
|
MD5 | 920224e33dfc1d6310f6db99cea02893 |
|
BLAKE2b-256 | 7f96613f94075d3939d8eda797a0aae75aeb771762b1950e237176d3850fb060 |
Hashes for stim-1.13.dev1708140965-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf4143afc669ec61711e6c6cf12c7177bd75a503d62820f753dbc5c4755271a |
|
MD5 | 6df92ae96c70a3620ca7af02baf2b9b8 |
|
BLAKE2b-256 | 0da3952ab4024b711cfc32689ea845fbb974daf29f23961a0c5daed0239a13b5 |
Hashes for stim-1.13.dev1708140965-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3984ac20e6bdc6d1ecf5da477ff2bf3e24cdebc77193a96a6170fb77dd8fd5d |
|
MD5 | 43a41bbe41fb5247a26481773d52dda8 |
|
BLAKE2b-256 | 894ad10defdaf90f3b2c28a2c20d92980ec6f13257973abd2f8374b2cba26933 |
Hashes for stim-1.13.dev1708140965-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd3ac68d490c79b92baffceca1a480cc28ae06df09db11deeadf7aa018985337 |
|
MD5 | 93f72e97025d1d2bfb662543c27d30fc |
|
BLAKE2b-256 | 70869d9a7568fde79d358feebce9114d42148726712dffc5d8aa3d367d7d5813 |
Hashes for stim-1.13.dev1708140965-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8493a45cbdc79f8f19d0e3d30547d4f357b451a1727fa5db958546ecddbf705a |
|
MD5 | 7423c5bdee229ed6e72b38a1ec01b638 |
|
BLAKE2b-256 | 308d9fa515c20f542221f6ae79f05597674dd78883042920d06beec87c567af6 |
Hashes for stim-1.13.dev1708140965-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2153420901b1f172d21a31e5138c019e6de39b4ff89eab5514eba4e0e8fccb06 |
|
MD5 | 6d43967f5c41ffd842dc2c30b58946c7 |
|
BLAKE2b-256 | 93a24588830a6e91e242653f1fe90f61eb3585cae8480fcdf7b2fdb33df5276c |
Hashes for stim-1.13.dev1708140965-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ede076d85365b398287019d310d451b90bfe3d4cceb95723b9347f3eecd6016 |
|
MD5 | e7b0e9854880293d6ceac495582a9e49 |
|
BLAKE2b-256 | 83164dbb23d01c2525270d0499d5a714a80e5908e491e4360ef91910adca6444 |
Hashes for stim-1.13.dev1708140965-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddca375144fce97f9079e44d337701a414d85438adac3b33fd97a86ac768654e |
|
MD5 | 30daf961c4f93b51f33f910e3955e270 |
|
BLAKE2b-256 | e7450f6aa354e63e23f693a40ae7d1d6097279bb5c3c4a3dccb7f074e0055e63 |