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.dev1692654474-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 678e616c5db57aff059ac9be068ac4a3166842f4658163fb6017a109d02872ae |
|
MD5 | 24401b0ba8fc9828ceede34c4f4c8fea |
|
BLAKE2b-256 | ce1e7063651ef9cf93959950ffc63ba94dba130c12edde3c042260c4dcad0132 |
Hashes for stim-1.12.dev1692654474-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef98007ae85ba45da0df5b76eb57e426eaf434ab0c32f346557b6994b8cf38f0 |
|
MD5 | 6336c920d2b602639c3d3469541082ad |
|
BLAKE2b-256 | a7e7340452f8ccc02b91cb26fc686636fb3f2733044d070a2972279a79d4de5a |
Hashes for stim-1.12.dev1692654474-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aaa35aa0a3382b7446cfe8c8bdd4c6fac43453c239e66f611f33e2e851c55a8 |
|
MD5 | c74e786626d21a626380485e1de9f0dd |
|
BLAKE2b-256 | 2912552ed34bd48f8976fea192ea3d5138a4b4178b1afec8b789acc0714d0732 |
Hashes for stim-1.12.dev1692654474-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22d9ab2cdb0aad8597185b4ccce181f1503c13d0c16092068269386eb9eaa036 |
|
MD5 | 069867b0c201640dedaa0c288870a517 |
|
BLAKE2b-256 | 60ad324fcf9e9e3e04c0cce63748b11dd1df4b4e5af6fa3c360670770ea0aaf9 |
Hashes for stim-1.12.dev1692654474-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a482e1791c219a73bf6643df7fa43fbfe9f6cb96251980f88524b86a6572de9d |
|
MD5 | a00fe2be3e8242d41a76be268d2899f6 |
|
BLAKE2b-256 | cc22785eaf48664adf09057ed885c47fc7efc41f6340a33268ecaf630a680b2d |
Hashes for stim-1.12.dev1692654474-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0050785a49665eee626b305393d3984e890bcf7c75b84ce67393fa100edd3743 |
|
MD5 | ebb35db2c4ff62c9fe60aa8c6f578b62 |
|
BLAKE2b-256 | e5fb0ae742f141bc6d89395fad2fc5637eea0907f46f1be2c3c32b3359148a20 |
Hashes for stim-1.12.dev1692654474-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fee61874528ea4641d157b2ee73d3b6ab39d1a255033e971cb3cab6b307dfde |
|
MD5 | feef47191305584e748e467aed330dfd |
|
BLAKE2b-256 | 71c10281e970a31260ebcb1092c3805eaa726be55a2a38e0b219409d0db8dcc7 |
Hashes for stim-1.12.dev1692654474-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbfa5da6b7ab42998ca191f6b0f1f24622b98ae2cb067e61b3bda264f322d126 |
|
MD5 | 5a071b50fa5db3e4fc76d551ba2e8790 |
|
BLAKE2b-256 | dc268933c85e58a7f3f39fad27fde8fb0804a93ab7e29331feeb159c35fb8248 |
Hashes for stim-1.12.dev1692654474-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99ec1c8845f8f07de9e10c5917b6154bbcf867a4e33eb82ce6400872fd545b0e |
|
MD5 | 2c618ea073f184d732736f486f5a6f6f |
|
BLAKE2b-256 | f40744e83f19b5f4fbd123ff827243b372db9d4c4fbe60549656daa44b3cf33d |
Hashes for stim-1.12.dev1692654474-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5317459c2cdfac37db5d783e04c7728871c53d1c913b39a943d26155ba82f8ac |
|
MD5 | d306285e5deb598277d8a1b72f0e2c84 |
|
BLAKE2b-256 | a4b5b81c6cc9ee6796854b3c453fc3c97a4de3a206a032d310797b2a068f7311 |
Hashes for stim-1.12.dev1692654474-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca9ae6a011fac4643f0b46c7017b45168c15b42d3dee1021f2e9c7019585ef50 |
|
MD5 | 93e3fc40177403db07f6d2f11ce005d5 |
|
BLAKE2b-256 | 6d8a87ffda282268de42c0d05ea98dff167410bea43f4b9d888fe3d45fe82d47 |
Hashes for stim-1.12.dev1692654474-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dc3fd620334d60ff26a0fc86dce06b090d42b911b0e4977286bf079cd5a93f2 |
|
MD5 | 5256b2f385789afa3d067ac3362239ca |
|
BLAKE2b-256 | dcba762a7e1c18dfb70e050e177dfec71acb5b23c538bd0e3c8d5e9549a4395a |
Hashes for stim-1.12.dev1692654474-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aec71d2e61939e5aa81e5cf6d41765a042bd7fa6e7be6d7f8542f9a8738d3119 |
|
MD5 | 65c814d1fcf343ed55b64618cd3ae25d |
|
BLAKE2b-256 | f8ed62048a9574436c4cf1ff58cfe5b25054859fd61188f01fd5705188cbd1db |
Hashes for stim-1.12.dev1692654474-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3057166c752b2f2834c32541b641798ba8c56d4c1ae055c2546560416dcf180 |
|
MD5 | b07f84ceae485c0cdd5043b773c5ef52 |
|
BLAKE2b-256 | 1d57a6ac5bc97aa42769f4c4fd26a39d20c20efb2903b179ebf197fac55ca470 |
Hashes for stim-1.12.dev1692654474-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ccc4f5d0780a2948292e120d2db19a7e9508aa02390745666679cc4a42f1980 |
|
MD5 | d949969467f2c987d611b624644ca58c |
|
BLAKE2b-256 | 90cb0faa9e82d11738fd334d540b10187b5de3f8b889126742db0a55a40e216e |
Hashes for stim-1.12.dev1692654474-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2df7f990f18a1273e54439c9a90a36cf7b49eb9ed544ee06d153ee3a8c832d41 |
|
MD5 | a7e3410ad25b3b5358dfa69224f2eccb |
|
BLAKE2b-256 | 179c4928095ef25dc13e4a2fc66803fd34012108f9839a367391885e3c108cee |
Hashes for stim-1.12.dev1692654474-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bee0375cf2aa954a48a55fcc24a5606591a69aa9d097cbabee7280eb81b4192 |
|
MD5 | b6f22f4ace87321990599c80d909c78f |
|
BLAKE2b-256 | 7d8cd9d048d47ec5a0f464aeffd9a833e1459861d156516c065c67797ef5f44c |
Hashes for stim-1.12.dev1692654474-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80b26b97d0a611a67c63a51c73a826a12bfd7651a5f3e0bc99c64d25439baf40 |
|
MD5 | 4d01a5ef3cc097082d6ec0443f136984 |
|
BLAKE2b-256 | 2a42c7e46bed19a73800e95b991826276aa53cb254f38ef1e7236ba97e5ef8d9 |
Hashes for stim-1.12.dev1692654474-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a2a09c33a885e29abfb954515fff788d4e42b2cf39a5fc35b1a3f224ddb3a9e |
|
MD5 | da2d570105204fd5873482c648dbe817 |
|
BLAKE2b-256 | c6e2eed01b2d0c857dac4ff949931ba3f0d9658a3314bf195e2981db884323e2 |
Hashes for stim-1.12.dev1692654474-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 413a54e04f6bd822442f43d2d5002065f70ef037f93642f4358dedc72221ce4a |
|
MD5 | 861bbe8105a5cb6cb74cc08ce64784a5 |
|
BLAKE2b-256 | 43b06539e1d0819b36f93176e1a032c68890b3cb53263980172fa9d0cbd10756 |
Hashes for stim-1.12.dev1692654474-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0efbeb5252a27314053d23b8e8ab749faaf224f7c1ffafe85ee9fa8f9914521d |
|
MD5 | a57251b873b965463db7513ce4e15e63 |
|
BLAKE2b-256 | 4d8f88d9a7d0d1d38e8d928f10c8d1d7b90758b799f65adfb1d1587d051da896 |
Hashes for stim-1.12.dev1692654474-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e45b9032d43119d998ed6557fa06942e51026c69876900bb373a7b9f36e99a2e |
|
MD5 | 2991bd68577c0bf2b4628f27d93d7b51 |
|
BLAKE2b-256 | bdf1685902a03d4771f27b991b0ed3c98d78de6cf587f45ed6bc3a6c74e798c6 |
Hashes for stim-1.12.dev1692654474-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aabd6d0e909bada4e443d5bc31de06503d4116c27e17199c5b972d71be36b5f |
|
MD5 | c286f37f58e02770c014786944146622 |
|
BLAKE2b-256 | 1260aa2778ddbd8a2303937020204d9aabefe3e38320d9fdcaa106d31c14f5b0 |
Hashes for stim-1.12.dev1692654474-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cfe8ab8ffb159aa5760620006aa555832902969fa246a7437c503cad1ea19ba |
|
MD5 | 852795b0b9fca6dd7bca3292a1375cb2 |
|
BLAKE2b-256 | e849954cec27904fb55ab87040bf5c322116b841a164dfd612417645952dba2a |
Hashes for stim-1.12.dev1692654474-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 333a460c9069925851930abee59af5086697728b8c15e64fd47f3f0faf7912d4 |
|
MD5 | a8da420f4197fa6fbfd396fb1d4d60d6 |
|
BLAKE2b-256 | 53b26447432f030e67e766cb6bdc7cbc1889da544759e5bb78ff072f0762603b |
Hashes for stim-1.12.dev1692654474-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d646647f8864b9148ffc5920f179918f2cbe6d2189d94e12333814169722122f |
|
MD5 | 83f132732cea1a25ebf931df09c88373 |
|
BLAKE2b-256 | 24e14c26ccda91166f14b9c0e2360f08bf8d5d5861ea4b4923489e316dd8865c |