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.dev1726091180-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42a501cc02d9c8cb0783d6feb55f591033b34a5c63832f78a7f778167bf71c43 |
|
MD5 | be21171da1d8c6d4dbdfa0d63942adf4 |
|
BLAKE2b-256 | 053bee4f53208e06029d1830df13213c6c6a625bb7dd5782694d6bd484dae3d0 |
Hashes for stim-1.14.dev1726091180-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3f7df0d02b85b90b6c1cab864dbe1f1ede10e199f4d10fbf451edf1d034eaec |
|
MD5 | e9efe3a1dcf171cb0a6f5e682edb3c8b |
|
BLAKE2b-256 | 564f1429ad14852842c145c4363e1e19888e61a8556a7b3feab2a3cb8f1e035b |
Hashes for stim-1.14.dev1726091180-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbd271ca859b59dce9cb34caff7a75fcd1e136bbbbecbee1aacad776a47a514 |
|
MD5 | 95170bd92f25f61e8015343b97e4428c |
|
BLAKE2b-256 | 4218a871495a1c91e49fbdda3870d6a72d427e72c24671abbdc7383f88936420 |
Hashes for stim-1.14.dev1726091180-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5e9581985685e30b32a8ddb65c5cc6dfe22ad390a29c0cfa3925bb274d8e54 |
|
MD5 | 378b6329984637f84fad8de06a136d9a |
|
BLAKE2b-256 | bd2759e49c51fb4e113966802622c6a2d191e5a3f249c833f55027387a843efc |
Hashes for stim-1.14.dev1726091180-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e51d58d3d35b2037d80cf854d0fafb2c667c654fdead7be6aeef57eac2af8cf |
|
MD5 | 7aec98bec1b247c99bf08f4e5baeaedd |
|
BLAKE2b-256 | d6b85ac692b936e58a4eaed78161ef7a870b3b4b7e3b8dc55e6bd3122e6b2bf4 |
Hashes for stim-1.14.dev1726091180-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eea81ae1dd5c811b7b04fc76e361f92ad6ab7c4b78b3c6132fe2ac6adc8efcc6 |
|
MD5 | 6701ad911cd8799e3df13d1fb91ef2a8 |
|
BLAKE2b-256 | de5abf4bbb60f5ef5674ac0712d96ee99cce6bcb2284158c90e261628d885fc0 |
Hashes for stim-1.14.dev1726091180-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efc754a15d3b06dc6842d776d1c8b8e8ffe8f9735b4f8ac089ec2030baaf0805 |
|
MD5 | 6baa55a0b112f237b329b5fe6e7cbd13 |
|
BLAKE2b-256 | cab3e5113f59f3cf6fef1f37d81532b4e73e907b8e1b89d16e5d5bd0aa48de19 |
Hashes for stim-1.14.dev1726091180-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa3990f749244fe2b4cd43bfe4fbc2d08d170cad9c9c5383e82788acf29b0594 |
|
MD5 | 5e9937342780cc61dcc071ca4086e15d |
|
BLAKE2b-256 | c0f7fbb2feec9a0fb0fd2462ac53fd68b1b1f7de40b61b7a2ac3686e6881ea7b |
Hashes for stim-1.14.dev1726091180-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d9af7dffa8bdf5df071cdf902c5e9f4a04978e1620a426444f00a58e09caef7 |
|
MD5 | 24af485ec0025d23a005b15097448811 |
|
BLAKE2b-256 | 7c40a48846645bd846452840b278e86bc5f1c378ac49eac64a8fede2ba7a577f |
Hashes for stim-1.14.dev1726091180-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1236844db08b7aa8072b5b22d593c8acbd7d5e7b3f5f3b0d1a87345fee23374 |
|
MD5 | 7cbf04e19703cf445ac02d8ae997da6a |
|
BLAKE2b-256 | e3e06db6655a7cb5ee2e00704450b4f112780db53c9ae424f0f233a7ab6b9169 |
Hashes for stim-1.14.dev1726091180-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49c0483e800255063af7ea80302cda714cf8ab404e1563c900d341b3716a2aa2 |
|
MD5 | 89c4ce520ab1b4f8b784cfc7a84fe0b3 |
|
BLAKE2b-256 | ba0eff4a387a6c33d3a7423349fca99e4108277843b9365e209d157a5e89de20 |
Hashes for stim-1.14.dev1726091180-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3186d33493eb43808e54a7ed59e8feb48297b8b623b45e9062bb962152d245ac |
|
MD5 | 9f4860e5c8a625211e6eb7cb1cc33f07 |
|
BLAKE2b-256 | 19bae04f47b0279c135844682ccd630153b508140086ade2c64e67a6737618d4 |
Hashes for stim-1.14.dev1726091180-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e5ba3dddc4e4084768a1748666b145367d845c79a1c1f68ff5062e2cec451b |
|
MD5 | 137533b80d884560ea92b97bd8447e34 |
|
BLAKE2b-256 | b300d5a355118e2b715e2d0e8798785e80feda79a08686cbe5f7be470f9a2729 |
Hashes for stim-1.14.dev1726091180-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae6a70b7959d4c65b90a37622a8e38fccff0b9fb07d220cb4bd64935b62d736 |
|
MD5 | 9e05d7f4e526e87fcb89bf3a0469b298 |
|
BLAKE2b-256 | 3fd625ca0fb40fbeae54fe64749dcac2d857f10d33094b0b67eb7ebcc6c5efc0 |
Hashes for stim-1.14.dev1726091180-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e4aac4f97ad644134f8d345d25428c7bbd435c210f6918558932fb3bb1d8d86 |
|
MD5 | afa0db954c08246098254cbfdd25c4a7 |
|
BLAKE2b-256 | 8d2a3658c6b9aaad4ddb30b2a3677024bdc2dbe977a81cba066c8b4d0c253eaf |
Hashes for stim-1.14.dev1726091180-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfbe245c7755927b37f28096d081803fc8b1f7b52c377a61bb1ec35537a88db7 |
|
MD5 | fae0e7da6d8092f3ffa8393c2a2f9a29 |
|
BLAKE2b-256 | 92fcdc30818929a444863e4e4040440c582a37589b4c45812981d28687c2fe98 |
Hashes for stim-1.14.dev1726091180-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f04eb767d13b272f3e43778e086c422c5d9c7136fd3fb2cd61fd956fc398c2f |
|
MD5 | 7d69558795bf5e7032a8b389cda0be72 |
|
BLAKE2b-256 | cd086e931ee27d8b007b46fe4e292f941300e55742bba2e0d87bab3743b1d7bb |
Hashes for stim-1.14.dev1726091180-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16b9d89a0820d240ca8332dad2f8e61981c08ae25e7ce310559d85130b73204f |
|
MD5 | 7790b3cd6878a076c8548c9434ad4343 |
|
BLAKE2b-256 | 90501f45cebf7855de14232f892a54b323338b04a1b20a48b598bb4650bbb704 |
Hashes for stim-1.14.dev1726091180-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1110ea99a4fab0835d354d05672398f13c354fe59782742d006ea971ae93fd2b |
|
MD5 | fd18bd929bed26754a88a4be6a62e66b |
|
BLAKE2b-256 | 74116abfdfb7618b176c1527e300bd866765222f8e39e2544f023668e7c428c1 |
Hashes for stim-1.14.dev1726091180-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5507cb8480524875cfaae878dec7753ac98c1f34208ac2fe1bae0125b768c0e1 |
|
MD5 | a96310c77ae3bd92ee9214a5159f7308 |
|
BLAKE2b-256 | 4abd3b5dbd70b43b390f031496b991ebbe311f4ea1226042628445abe72c58b3 |
Hashes for stim-1.14.dev1726091180-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b82a356a2d3698cfee9bfaa4f92790ec97f007d1019782c53b1d6baf438d51 |
|
MD5 | 062f0f105447485af9f8c3fd98cbc1ab |
|
BLAKE2b-256 | 3c70991964097dc98e05754d70e0d9dbb8cbf9ca49002877c681436053f82551 |
Hashes for stim-1.14.dev1726091180-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7426c80c6fb781a4f3861e9b25875a6f6b5693ee61178afe3a4d6a5bf8cfd93 |
|
MD5 | f2e3ec70f169494f81518705ad9c51eb |
|
BLAKE2b-256 | b6a6bc4c258203bb08b3562c9de1c6eb541d111562dd8ad8b7ba9e5958b712ad |
Hashes for stim-1.14.dev1726091180-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0213b58af5297313ac3c5775190d36ad2766367ef4cb9dd2740a2097dca0aab |
|
MD5 | e9685d6dea4c66132bd33a7c43d24b3e |
|
BLAKE2b-256 | 72f505985856291acb013f5beb0def65cb7064278465877ec38b8f0489000bcf |
Hashes for stim-1.14.dev1726091180-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5b80532d5fbf24d212b03301d9f857f130287c883406c4491a4aa62f95207b3 |
|
MD5 | 931e95a627be680f6e74ba14246cc4ce |
|
BLAKE2b-256 | d9c6c3f7a92b5462a2620672a81347ec6f37b31f944311f20fff230953f8daf2 |
Hashes for stim-1.14.dev1726091180-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e33f007da720bfa885dfe817cb0f7263a17238c9b92c67af1fa0e1188a61a9bd |
|
MD5 | 970b33c249b7128306d3a9ee20dda310 |
|
BLAKE2b-256 | 7429ea32b2a37fba163bb9ffab32861c9a9c0d3ff1f6d65b92fa73a947a0ec9a |
Hashes for stim-1.14.dev1726091180-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74eb9a9302dd501187f84aa540a4ebb6c2c2892c9a79b06a0caf8ccc4213ea94 |
|
MD5 | 53c4070085e055e66755444a88b05aee |
|
BLAKE2b-256 | ded7729bb9a48b2c9075c6056f67faa538c17519e52f7d2f6a3aecc01592c776 |
Hashes for stim-1.14.dev1726091180-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b3f44645e0caed2c6e6d1152b64b31991afb195f5bdf590ee15dff8c62278b6 |
|
MD5 | 0065be817e569180412a1d83f3dee2f9 |
|
BLAKE2b-256 | 73ee84dbc4c5dc962c186c30aa16efe6bb370fb24d52efe73b5ba58f28d8f3a6 |
Hashes for stim-1.14.dev1726091180-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25d1db4f05463255b8196e15be422376b100e97b87cea1bc1f1f430605d50b67 |
|
MD5 | 9761f802ed8d72bf0756a6a1e8aa4e6b |
|
BLAKE2b-256 | 57db0873e64db8d25b157388c1bd1caca79e30828bf5e7c6b613557686aeaf2f |
Hashes for stim-1.14.dev1726091180-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a4fe2820d2c1c274f8fda5c1fc31e9931185d53f7fc24e8b37ad899962c2090 |
|
MD5 | 9148ea727ac358191536eed28734dda5 |
|
BLAKE2b-256 | 77ceaff7e7fd9c47336dc3f9ce1d24b7cbd8d17fdfdb5ff67ce00ed93941ebcd |
Hashes for stim-1.14.dev1726091180-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccfc0d75c6abafe9c60b08ec8e567566559371a79518804f4d3708776a4ee28d |
|
MD5 | 428781a22a015286c0e3291ee5e72741 |
|
BLAKE2b-256 | 795e681aca21807941f6a342029c65b16c5729e26c40c9f56608ac7a75f4f421 |