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.dev1687325088-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b000300d7e0f521dfdfe493a069b0c698f85f1403fc7e149ea75de065a84ff4 |
|
MD5 | d821ccc3012679c36dd7fd8efec10a7d |
|
BLAKE2b-256 | cb3b0d03c9df1418fc3d32a13d33bd749c02fcc6b204cf8d34d96738030846e1 |
Hashes for stim-1.12.dev1687325088-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27614ab0d7a9102190abc0769a6f1747b02e0bbd5baa34bf826c88f5ca75bbe0 |
|
MD5 | f9ed9a0f62686a7608f4905626edbfaf |
|
BLAKE2b-256 | c1425c3fe397559bbaa86b4bc389c2c99c07614d340c170c124d989b49c6eb66 |
Hashes for stim-1.12.dev1687325088-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9ab2a49d9237bd671aa5a216eee232299eae750b62aa60bc3c663e2e3b51248 |
|
MD5 | 982ac5905a070e3a7ee04dfc63c8d547 |
|
BLAKE2b-256 | 03134e4256394e7763b0784f35543fef967d459598269ba148af1941e8cddb0d |
Hashes for stim-1.12.dev1687325088-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3897465ba208c97496ecc4fb86bb08618388b38ab147e03a53ddfec50d487662 |
|
MD5 | ff15308fdf1d44668e0d5cbb7583eb65 |
|
BLAKE2b-256 | 6d196de8728c9b2e01e95629d1dd318c7f799e5e48a5a6e8376dab3c03a719e5 |
Hashes for stim-1.12.dev1687325088-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19934e3028cb0eabd672b739009f78adfef73f66546c46087ac4e861eb02d452 |
|
MD5 | b302eb44594ae1e4f1a4aeea1b8d97ec |
|
BLAKE2b-256 | 482b302b04d37d7511d1537661c9c5b5d6d8e7ef0c0fb585f747788c1ab9b15b |
Hashes for stim-1.12.dev1687325088-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5db6beb99900ba53e89c61dc9537060d9b798212d05f28dd52dc98a273f36b33 |
|
MD5 | ff00422ce0f4f1ac92f592161ac475f4 |
|
BLAKE2b-256 | 78adc4c65d6e199283d2812fd06ec2efc776643a9689c50a6c6629ad9f9115f7 |
Hashes for stim-1.12.dev1687325088-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1290fbb571daa0aec3e5f9e4d3e2d34de98f7c6b56e7b3d30d8e22ad08a33ce |
|
MD5 | dbbe6b663f9cbed939a6854f20700a8f |
|
BLAKE2b-256 | e6775d0472918c47d5ce8388bf7da3c53fc282a30e9f6a38fd2a32a4c3263133 |
Hashes for stim-1.12.dev1687325088-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d08682e27e11a837875fecdacd3ee3c2dd5c5b83eff0c4ee7a8932f0bdfa773 |
|
MD5 | b14503276484c44db7f45c4fb6516ba6 |
|
BLAKE2b-256 | 7899ba9c02e5718968a59e49ca8bdfd914de719c2f53ad6819c24094e2af5923 |
Hashes for stim-1.12.dev1687325088-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd8120eba13ba229aa89d6ede49da16618eb92110042bd3532f7fcd83390c91e |
|
MD5 | 78d0546302a936ae511263cdc83e6b91 |
|
BLAKE2b-256 | ffdeaa0b1d6191a7f6ac046be605cc15272741b0cb786e7d6736f75072bf5837 |
Hashes for stim-1.12.dev1687325088-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40b11e7ae1310393153d2a84845fe5107dde2f40c8a6ebe4ea6bfd82c4d3ff7e |
|
MD5 | f2e3a11f7b351c17cb089495b3d76de5 |
|
BLAKE2b-256 | 6871f4926c2a5b780deb7bbb6fd7ba754aa5341e453fe0ca399fc8df56a5a28d |
Hashes for stim-1.12.dev1687325088-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d008345592401081398a7d677f225fd980806e03d439b063b5764821d210251 |
|
MD5 | 607210636470c846bd7f93a440cbd60b |
|
BLAKE2b-256 | 2d3f39e471faac69eff70263c87916f50b13ea0346fde2acbcb987ac0c28e1a4 |
Hashes for stim-1.12.dev1687325088-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa2a358ad14146eed3142b4fd89814ccec30b1cd7e490d3b173d71e1b4154dc5 |
|
MD5 | 4bf6f33a91c9ad762940e8d5c249e30e |
|
BLAKE2b-256 | 4e74844477181a23ab08c08839f2e6624183285ea0122ca16f9bee4e323c3524 |
Hashes for stim-1.12.dev1687325088-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f551bcc2bd04e035db3c5f52255d7163a3710387bef15df0bc44f43e5abc87f3 |
|
MD5 | 935e2d63096327d4fdab6152fee717d9 |
|
BLAKE2b-256 | d6a6f5ece036f77f3612237e4745c2fdf1ecca66a07fb5f629622b3d73acf0cd |
Hashes for stim-1.12.dev1687325088-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aae0afa4eeca971150bd9d932a627eafda1a368ef7f16ca2d49fd41e7c0ec40 |
|
MD5 | f381588f2fa98e5fa52c19cf6da4a213 |
|
BLAKE2b-256 | 34edd25262c92f30d4267117b6c9b3f133649d15848204dab54c2f32575f5f3d |
Hashes for stim-1.12.dev1687325088-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c8293f50ba84cf6132a46bb527984530d97ed8b0f75ea1743071946a6b4bf1a |
|
MD5 | 510100957d361c12e4a7023b9c7978df |
|
BLAKE2b-256 | 43b04239742d99b23be1c4dc335eeba6265ee06b4d82efb12f7390423a61d306 |
Hashes for stim-1.12.dev1687325088-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0126ddd2e9673704d94bfc03714618d3c6453e7e97bd274ac46b56e5b969ed62 |
|
MD5 | 6cf09b2c7a4e679d4792ddbbeae2ff38 |
|
BLAKE2b-256 | 693b904e4bdeacc65f385f69e68bff857ae1efe11780a8ac43ec102c4c7c1939 |
Hashes for stim-1.12.dev1687325088-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad020f967747dfc23e087247e5fb03e9af5f38859c2277cbe30cbf6f309c6965 |
|
MD5 | ffe886f74abdebc06390be54c9f7a367 |
|
BLAKE2b-256 | ccd43b87fa65fb2fedec5a6d836bc8db5436e4e600cfd8f004d6cb6729edd80f |
Hashes for stim-1.12.dev1687325088-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 113dbdcddbf5913d923e933408cc0edb4a8a438761bc99e6c82f3e91383efb33 |
|
MD5 | f02a23b1c6ff79db8f84ae67e5d6ff5a |
|
BLAKE2b-256 | 6876c593578bf43426f0431a696df04f761239986fcae71f1ab618b310a55cf2 |
Hashes for stim-1.12.dev1687325088-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4f41a868f40378f66b01e81784602ba3a354acedf7a0fe785682c25f308e8d |
|
MD5 | d12037ff99c59a25515c388334643866 |
|
BLAKE2b-256 | 9be2a7cafcf14d5e8b4346a940ee4efb98f8b4fd5c9147619310f8ffac96b5e5 |
Hashes for stim-1.12.dev1687325088-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd601898a764b4dcf7ca1f668de7b7f8a33a0997503a7d90efa54e407f5028f |
|
MD5 | 0a49d47ccff3aef9ba3c346281dddd8f |
|
BLAKE2b-256 | 2911c02107b49e53ae94aa515974d95845d4bbc2c5d926ac0478dc9ed437ef99 |
Hashes for stim-1.12.dev1687325088-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bd955ba5ad43cb687080a8c5a5d81d383d3ccff9367b8e6d0e4b23f83ae36cb |
|
MD5 | 4e736de1277e2cd6b0f5f3fba1597425 |
|
BLAKE2b-256 | feaa8056ff03c5ab8b8d923b16970b1df071103810ec9493ee999b3d0a5dc661 |
Hashes for stim-1.12.dev1687325088-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f46d641e51ec676c032c8921139d6bf9f1b112f41907bf5ddbb46a1bf41dc4f6 |
|
MD5 | 39d8f9aa196857b410c7453571c0ec8f |
|
BLAKE2b-256 | 659cbe268a1b416f25426b060f0de7d407e3940bd92592f1899f2093631230df |
Hashes for stim-1.12.dev1687325088-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4394856ae9275adc97df84beaf0e7708a89c4195a9a672c59dbc612463f04470 |
|
MD5 | f6aac5ce2ff6e8c38049c1ec477e5452 |
|
BLAKE2b-256 | 30bdae747a318524d6fdaf2de81ce4a44f6ed211aad8a1cd88459cfc99eafc12 |
Hashes for stim-1.12.dev1687325088-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26bed6a6888dcab93f856b13c1bd171d8aed57392bc3b23658115da08555e5f |
|
MD5 | a4da3f5148cb3c85aa389b5b7b463d6f |
|
BLAKE2b-256 | dbe5c1df1137259c4ebee6a7888153a23add3c7d05ff3df6df9eb7de4c40b3ba |
Hashes for stim-1.12.dev1687325088-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f61e81c31a0aa3328834bb40e2de463863b6671c476f462b0a7100ffcbdc1ee |
|
MD5 | 374942dcf799e41bff37e22e48c4ee40 |
|
BLAKE2b-256 | 194d31159419aa108d26100c35278f454a9a0f5688d099ac9f329302e484598c |
Hashes for stim-1.12.dev1687325088-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6a2872bff4917ce8aaa5581cfe89b506d9ff7caae07037d6da59d9aaa09f500 |
|
MD5 | 842fedc2177fba918cb8b418d42b1174 |
|
BLAKE2b-256 | 80e2801223ff5eb97033ff9bd52dd0c5bad5f44140efd0a02add7cc1ddbb67cc |