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.dev1710483042-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1caa023377d5a301680a54e20dbdfd159d8dcdf1b52d1c920d2b067808de4860 |
|
MD5 | 882cbfbdef9111a7aa74d42286ff44b4 |
|
BLAKE2b-256 | 08d3cb0431e99b3c709984d51af09cf840b89e0bf9c2663f94a1edf540ef69e3 |
Hashes for stim-1.13.dev1710483042-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82ed1bd99ef6be1efefe0063b8b7578fce34a9bd0b4d2303c9ccb0253ba1b671 |
|
MD5 | fea221c14398bb1f5067db7946f5f151 |
|
BLAKE2b-256 | d960bb826aa24ca9e860c6aef828c99d613772fcb4dfe443f28591fdb28658e7 |
Hashes for stim-1.13.dev1710483042-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a77a91663deb4d7dd33a41c6641c676bd93b346295f7a0bbc11e2f9ba2eb1770 |
|
MD5 | 7f7d413140f88554d6ad4b8401c171fd |
|
BLAKE2b-256 | 679e44dcbbd99c5b441ae0185d052a3bcd33cf591d0b112440ac796f294db775 |
Hashes for stim-1.13.dev1710483042-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd637b246c8ab53e6bd0448a5dec381041fc67fc67bccf5b72256101d2f7c22a |
|
MD5 | 467f3d762b9b700fecebb709b2e6cae5 |
|
BLAKE2b-256 | de76d404ed38b207a59c66d8cfcd59527f68654c2038c55abba34786164a5233 |
Hashes for stim-1.13.dev1710483042-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab050252cc6a58ee7df8011ecf449417e63b546a6d6164f54d51e5256b28575e |
|
MD5 | 68df9a79354623c809b7734d28b7595e |
|
BLAKE2b-256 | 2e40b539336c6b9a02667d2d32d8b6aa2787e59e3acdbcbb475aa8dc353c780f |
Hashes for stim-1.13.dev1710483042-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae24d49945a0bb0461531d8890ea1226159ac7021db653a70ebffb32af88ac7 |
|
MD5 | d5a2442525941bb784d519cdc48cd33f |
|
BLAKE2b-256 | e61f3db4ff4aab56a057ba05fd81c07741b27c3478ced58295b761d8dd268a1a |
Hashes for stim-1.13.dev1710483042-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18d959f67ccee7fbaba16cdcfd876daa10f12b5fe38213fdfeaf567c48703a1f |
|
MD5 | 84291dc808efc349b09743aa5d8120c3 |
|
BLAKE2b-256 | 0f7f7643f3edc33d19f03fcaa87a41b127413fb88f39ae4e4e42ff5c3eb1e3f9 |
Hashes for stim-1.13.dev1710483042-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1044a1ef6148ea4e306d35a406c390cbd75827aaa48bf16febf7e6af4e6eb4c |
|
MD5 | 069df426cd52546c19965452d9adeb3d |
|
BLAKE2b-256 | a20b5e63a8d6bec4c73fc1b9b8d1b9a682b91844a322b728b9c089330fcc36dc |
Hashes for stim-1.13.dev1710483042-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dbb14dd959c69ec991b2593e63429ac0ca02914abf530ee6360134c8615e77b |
|
MD5 | 8317c3de2b158fd9091a5aad67788571 |
|
BLAKE2b-256 | 6b4bb840b3f9a6afc86851ff89d0f35f06098f53cc7046175fccf73b8b840744 |
Hashes for stim-1.13.dev1710483042-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c097fe4ce9fb6f98761d1b046f215c6e97d5c811d5f366ab8ad2202ae3de7f0 |
|
MD5 | cc285117aaf69b8664c5ba97c42375f3 |
|
BLAKE2b-256 | 30d19d36a2e0444b2afae9c504850f5dd135b4b0ba91ab4dddd788b47fff2375 |
Hashes for stim-1.13.dev1710483042-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3078f0ea5caa504a2656fd3209a552e62b35f8bfc7a8e81f5d4b31c7cedf025 |
|
MD5 | 1a9a86dbbc896c7ec4021fe433c5fa2a |
|
BLAKE2b-256 | 5a4a6353c2be143745952a1e29fc92821f05b6e22f6e4549944a0501ae510462 |
Hashes for stim-1.13.dev1710483042-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b7c95b4275d0fca6e42c0442d3ea6e137c5a7bfeb80e000dd5e5e4d4d5536d |
|
MD5 | 81f5514a1a447667e30532617b7f50d7 |
|
BLAKE2b-256 | f25a2381b7a9d3650d1590217e52b15b2d9ef6bcf189ddf5e7014809ae7d4057 |
Hashes for stim-1.13.dev1710483042-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06f81b61e3cd22524d53da6c220fa31dbe3284f3d2335e52fc868e3cbf55182a |
|
MD5 | 530f84253740e5fc5c7ec2bd079aa835 |
|
BLAKE2b-256 | 94ca488eb9d3dc2096c0143764f03af182e99457bea4cb1525d9e14ccdab05c2 |
Hashes for stim-1.13.dev1710483042-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f046ea16fe13a4f70b31e0b58ef980958cfdfb5e0d587a60e6d6d2e11ca91b |
|
MD5 | 5aea4dcb8afcdd09527cdaea37b6fea5 |
|
BLAKE2b-256 | acefe9ae34b1c0ad9758716d3208f38a46101d33dc2f378793de270d1a7d5cf5 |
Hashes for stim-1.13.dev1710483042-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21950be9bc2b1d8623da2526b08310a5c6bebabd0e4b7ee7ab26e7e3e2d89c14 |
|
MD5 | 8ad505a17d27df66e44dc6bb3bdf7407 |
|
BLAKE2b-256 | dffb7008c3dbe3fc50d0c7dca004ca4aa02a40c8807a9efbb33dba6483010f9c |
Hashes for stim-1.13.dev1710483042-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f90c06509920384890f5708e85ce9e3e4c6a1341160d392a0323b4179592781 |
|
MD5 | a8cb9f4f9fccc2d050604f6c59c9f835 |
|
BLAKE2b-256 | b8b556520520c28e59ce76a1a16383b283efcede9aaf4cc5de136bc951d4af89 |
Hashes for stim-1.13.dev1710483042-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4ee5917bf22d12e1cb497aa7c567f971d2620ffe2d015f81dc495b7cb747593 |
|
MD5 | 1a6382480a8ce3bcea44f7f970667bed |
|
BLAKE2b-256 | 932e8e46b849a742377497ce2cefbac92afa16725e73f96e10366e87b70642fd |
Hashes for stim-1.13.dev1710483042-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8240fbc6571984b7c66aecc20c76307fb92db9f358c6a9f8155fa1cad2d7cba |
|
MD5 | 099c2159983d058b3345e96b56ecfa4e |
|
BLAKE2b-256 | 099939c60fb15ee57b06a6eb2de2dd0c4439d7a89a26e31f80998c312b6634dd |
Hashes for stim-1.13.dev1710483042-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f053813390dd263b5270127649210da744639e493621365f18cede113af5955 |
|
MD5 | b1718ce11b33384b2189bf2cdeb1dda0 |
|
BLAKE2b-256 | 1249f7da8440441e82b936dbb5c5b52a21f60b61e2625ac7560a948f85409b04 |
Hashes for stim-1.13.dev1710483042-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92fd0123edc22259f1f05b8c508e5be9b0ea5ced075dcb008ac9bc9f186dd713 |
|
MD5 | e0a43fdb88fb84d59155bd4c80d6c923 |
|
BLAKE2b-256 | 32b4b6e88d5e160d85742cf9c63ceaec0e3b1c21e81250f9ec918c86bcbfe725 |
Hashes for stim-1.13.dev1710483042-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56bc332723659b8d2dbd69298b14fa487246843061b4d12e9a8c9d8d5c08c993 |
|
MD5 | b47d15932e2fb067a073ccd2a7c6c321 |
|
BLAKE2b-256 | b2487f8a9c2394998295d6fcebb0eee9e7cac18cd363f14be3d63b4ee1783a0c |
Hashes for stim-1.13.dev1710483042-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c266179fbcea920c1a7b007d58a5ab9ddcf8177b3cece11f3a1ffb677addac5a |
|
MD5 | bb55aa913eebc41e8ca27ab8b9f5b04d |
|
BLAKE2b-256 | 4d8af585a20ccc4dd2758d65424e694a8405f33bb660a3d78578af09e5af1b1b |
Hashes for stim-1.13.dev1710483042-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a198a0cb24356c4980b6cf4699e4eeea603a65850d1e6b95258c2ac13741ae6 |
|
MD5 | 985602b1af82f1255d9762332639e63d |
|
BLAKE2b-256 | e383bc236b687455b9c39e3787b27227ce07ccb8338f4b2f371ab9db3d7c2ae9 |
Hashes for stim-1.13.dev1710483042-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 111e1bbf1f582449c6c8ebed0674557ae3275ae1501003ce974ebbc114e2bed3 |
|
MD5 | 604cec895007bf72f9135ce5071ce627 |
|
BLAKE2b-256 | 530d7048e652d0cf44e94449e04e9fe4da82cf207d224cf598ef839911b7c77c |
Hashes for stim-1.13.dev1710483042-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a15648dd93ac25a0aaa0ed349ce9d1b9e90ea04927f250562a254a54961cdfe |
|
MD5 | 1501a9aa0b37ce9f67bcd3ea3c11c918 |
|
BLAKE2b-256 | fff5f3842f09a59432d41f2822a94007be31a49bf4bf2fc2edd080c19d9f430d |
Hashes for stim-1.13.dev1710483042-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74211ce15283a34d4163dc10ef8c5f391128beaa30f340f4ad7559896db2ee0b |
|
MD5 | b78cece91518025871405baa943b55d9 |
|
BLAKE2b-256 | c98414614757dac38fbacf18fcea73385e54e80bd4a8da3fdc33b045d1599f36 |
Hashes for stim-1.13.dev1710483042-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7234a79e4d1042a2893b46f742e38844c837f8f7a73ffe851a63e26bb8c8c54c |
|
MD5 | 01915039ba24fb6feb0ab9952b5bf6c7 |
|
BLAKE2b-256 | d4853059f56cd2afbe5cd5af814a25f60a30b63a071d3997cbca83e58cad63ea |
Hashes for stim-1.13.dev1710483042-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a60dae1c7c4c722572643523a9080367b6790116d312d682f79c172159242990 |
|
MD5 | f6adf0dca94ddc9531456cd71afeabf8 |
|
BLAKE2b-256 | 4a42ace883b300739f97d66a7656c697fed0cc7320d2d67fab882ab85e86f3e4 |
Hashes for stim-1.13.dev1710483042-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 190a4ed4105e40d3e532225b56089293ffb777b41e5aa127c0c99be8a4af334f |
|
MD5 | c325ead6c22f59a59c358b0a4cb779eb |
|
BLAKE2b-256 | f5452f7e5e86eb3c39319318bb706eb8a5a056c40a93f64279f3b595f395abca |
Hashes for stim-1.13.dev1710483042-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66f922df193a954887723968c81f2d4ca4052cefa8242981ff31530d74bd302a |
|
MD5 | 3c3ec324a2004fa51402e33c52064628 |
|
BLAKE2b-256 | 955804216b121344e8f9c84a9fc2fd6c6b7a0784d8e0f376e717ff837cb0db70 |