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.dev1722650154-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 171b394ee6fd277aa0419b75362e67e2b97a90689f166eb9cd03842e2c36da44 |
|
MD5 | 94a25ce292afd36d160478ba5ee37191 |
|
BLAKE2b-256 | 2ccf62d4a7069024cfb3f75dd3410b0f1deb7c17e0910fa7069c7c37ac3d6a9f |
Hashes for stim-1.14.dev1722650154-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c6eaa5711636beb8e938954896095d6a3698eaef9fabeb58f875cefce2c6703 |
|
MD5 | 1ba7c1a68cc101dd3afa52d8f89648d3 |
|
BLAKE2b-256 | 988acb890bb891d3bda07be010d9426f9038e7b690fbd0e2d78c9078d20e732f |
Hashes for stim-1.14.dev1722650154-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70d96f81efe95abb4f6bff49d4f88f7cce66916602346b33c594cb2096ee844a |
|
MD5 | a380dfc232a0de994cc2bffbdeee0e91 |
|
BLAKE2b-256 | 14bbb87d942f3020c779616ec63eb56c92dd8ef2945b3e4ce21250f5e135a554 |
Hashes for stim-1.14.dev1722650154-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1fd9a5d36deb7a85834694ad683496ab4e739d842c651915f12f7d40fbab460 |
|
MD5 | 6349acc74232ef59f60fa7743a451afe |
|
BLAKE2b-256 | e137988d0fa71408c47a1fd251dd4639196a0b3c1af0d5ef410dcbf6d92a021b |
Hashes for stim-1.14.dev1722650154-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3298b96e3d0a337dab9526e729b99e379879bb715a5fdea31d27f4ffc770cd |
|
MD5 | 72812b9d1c17f61595f948ebe1bf1bce |
|
BLAKE2b-256 | d2cede66be010a8290a19296e1958b4eae1760ebeaa276176e928af1b84d2850 |
Hashes for stim-1.14.dev1722650154-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc2b051195ab4492abfc7951f1fdce80146eea6b16aec6605ab340a41f99cbc |
|
MD5 | eec986e0dca2d22d0fd35245e525b02b |
|
BLAKE2b-256 | b6fbefa7fbfc2793d0be65900ba4c8cce65841c5e7d0d35cf95ee46249918d01 |
Hashes for stim-1.14.dev1722650154-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46913f406d9f2a679c4ce807b123a8f1fb1eea33e599b2d4bc956f6ed09501ff |
|
MD5 | 36c5ce344aa59ace0bdd5598b63a52e7 |
|
BLAKE2b-256 | 69528bb49716f863fc809b1742dead70df43dc543597fe231a48f476e79e7905 |
Hashes for stim-1.14.dev1722650154-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f2ef3e31ba6f13081cf6ae658c489a4e20dd94fe984395e10fc62c24f400e01 |
|
MD5 | 46d5c1bc549b32e83db0249a8bec22d2 |
|
BLAKE2b-256 | 252501f9c471aac1a1c4b5d81e2cd08896e220dee87f306724a73c83dd7feedd |
Hashes for stim-1.14.dev1722650154-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ce1615ef38c832a533b32e25eb374eab17d223562ef8ae34019f6c35a993a3 |
|
MD5 | cb2d58b04628406bf73738a13790c3b9 |
|
BLAKE2b-256 | 0000f851fb9c0606e1f725cfa12e6e26e071dcf92e8a257197973c192001cb22 |
Hashes for stim-1.14.dev1722650154-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be55380a849c5cca109a2dcba849fafd3bc7de383290bcef9688aba9d2bd955b |
|
MD5 | c449d1340929bff2001a3f4915ec7e18 |
|
BLAKE2b-256 | 40beadc83389cad0f39478bac8489418643519d0c9366ae18042fefa65679b34 |
Hashes for stim-1.14.dev1722650154-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4b16599cc0c5734b1ae435cbbef944b9885694fed1eabe73e5dbf1ea210a81 |
|
MD5 | cd27ba37ef5ffb4f331d2445f3667849 |
|
BLAKE2b-256 | 14d28369a06b18c6ce07d5e608f75ae5c7b93345b84efa1a33cfc69e00be9b0b |
Hashes for stim-1.14.dev1722650154-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9ef7e6d43ac6a779e681860f33f74aa9b7d56dbd1a856e7e3104f46976b2179 |
|
MD5 | 8b76d016915a2cb275b66b1e67cf2a28 |
|
BLAKE2b-256 | b6d0b97920fe48992efae1cff8eb733742eaee45c2245d28f5251bb4e1e0c634 |
Hashes for stim-1.14.dev1722650154-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad4e0fdd10558d0fff3cb1c5e0bb8f6c57a493abbcf66cb71ff5fedfb6f9a2ca |
|
MD5 | e0dc9ba2c0e55fca832fa4fb80bf4550 |
|
BLAKE2b-256 | 67e88c85d7ee69c5897e8592aa0ff6ec0ad2a37d90e5419413d3d8b84d04d6d5 |
Hashes for stim-1.14.dev1722650154-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eca9beffb01966a4e82e4e851c55757f64568dc8e5fe23f29eb6c2ee1af6cd1 |
|
MD5 | bec8485d63959a240a7930c6dfc92a42 |
|
BLAKE2b-256 | 6f28e1fa20084497f0ee9b3a4f7bff4fad6fcf2b51677ede789281672956cd0e |
Hashes for stim-1.14.dev1722650154-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 965d94807690c45bc0e7bcf1d69e675f3eaa6b1af42609aa4e133db088bdccf3 |
|
MD5 | 70a8224924fd415538e2d0fb5bb26d08 |
|
BLAKE2b-256 | 6e62d64d4e903ec5932a99e05ed7e879ca337d9bac96e175be78b64501f26d93 |
Hashes for stim-1.14.dev1722650154-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efa535119a72e57d5fc8f1ee6e1726839deaeb3c95b20dc669176e60ae482886 |
|
MD5 | 71f09b96f60e2f0835d6b1098205720f |
|
BLAKE2b-256 | 45914d61864558ac839940bd7c975fdf7a95de04a62a09dd4c8795556ac3fe95 |
Hashes for stim-1.14.dev1722650154-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47f2315d3f53b98953798f30251a70d86fb4360964ecccc5e62a3ae30cf6125c |
|
MD5 | 635f9afcb6fef14525239c2de9e5b7aa |
|
BLAKE2b-256 | 1dfafef63cb47ea8c08c45b41a250898db8b3a103b012a1a741ebc293a441132 |
Hashes for stim-1.14.dev1722650154-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f2f37947a2e8f8b861c5175c046b87d61bfde018adf667c8e58873108aa241d |
|
MD5 | a6038d9c3096bb94fc852c28b4a8627c |
|
BLAKE2b-256 | a42ecf59444bbb40a9667b00f8d2a4dd31393fee215be116500a5c436bb6fae8 |
Hashes for stim-1.14.dev1722650154-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 720f22d792688ad6cbbdd825d9cb40b0d6f9d45f1fa15d9e8bfb663d779cbcfd |
|
MD5 | 5ce6830801d5e855708a0b8fad0e706d |
|
BLAKE2b-256 | 09a441133756c72cd00eb5769d5ac18fd531924acd5d426a0e14517ae05410c3 |
Hashes for stim-1.14.dev1722650154-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdecc9280bfdcdee1ef2bc43ecd1e32ae45b9902db5cfe53db15aab8e28d549a |
|
MD5 | 22aa3fe7634ee956166685fc02e984a5 |
|
BLAKE2b-256 | 5fd7fa6b64d085b175e884f5c24bbcf05f4ffa1e6daa8a5184d18df8078a7cca |
Hashes for stim-1.14.dev1722650154-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55499600486937be88ad33c20ffcdf0900ad0309ddc78eb358eaaa08fc10304d |
|
MD5 | f27b82be22b35eb2aeed6dc97c15fc15 |
|
BLAKE2b-256 | 2f6e99385b798e88dc3165f0c6e932d7338dac7c6bcd42d174f3f420d73e3536 |
Hashes for stim-1.14.dev1722650154-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4936d8dfabe72b86671fed66b8b1d9a66a58871b297218766564ee709136e9ba |
|
MD5 | 6798facf88af05a0f21c15577af2eca5 |
|
BLAKE2b-256 | 6eece693f1190d27d32b52fb442e06290e61a327258b4fdaebff7d78a156b859 |
Hashes for stim-1.14.dev1722650154-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bc991f7c84c7cab9393040ff8c0bc85bb7eadd1699598b565059ea61ff3e676 |
|
MD5 | dcbae77227413553c022c9f7532820a1 |
|
BLAKE2b-256 | dd92be5d5baf1c5e84ca89e2b56c14a842137e96f755c886bde867a04e2dcdc0 |
Hashes for stim-1.14.dev1722650154-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4ab2924243d82ae12237e2c14d14add661b51255b228c85798fef2172d57bed |
|
MD5 | 1906b814eff12a296e6194c1b4ee4971 |
|
BLAKE2b-256 | 2d8bb12671d6bd3f17e46f17acf20cb03c46b7ebf2e94ee6e5b2ab2b62b84216 |
Hashes for stim-1.14.dev1722650154-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f948c7a74ad1021ddc7e7f414c13f80fe3ce3971cf024dd85c8340e1458d94c1 |
|
MD5 | d9a0b22396916fa8e6a790b9c1d29a2e |
|
BLAKE2b-256 | 363a5363356271f2f9e54e2cab042c47df2c381264cecce8248427a26ff3c552 |
Hashes for stim-1.14.dev1722650154-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719c217c1d95c182946029d7f18476e1725e8ba077d3fe297c945632aea7c755 |
|
MD5 | f43ce47efec8ecbffa027fa07b543b7c |
|
BLAKE2b-256 | 28994d8ff6375c24d6d7ee57ec4fcf9c6eb4164e6a4b358aa85ebb9da92880af |
Hashes for stim-1.14.dev1722650154-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce360c2049458ec0bb236a4d0d4a3d6612772b8873d0192225cdaf6175db04e9 |
|
MD5 | 281761f546bba8eaf06ac80302f3c0b2 |
|
BLAKE2b-256 | e89f6fe8f2e9e9d54a2582d6df63483a1d1a02923e06403aadf4593c3e7ea968 |
Hashes for stim-1.14.dev1722650154-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7662d378c169bc8fe297f6db1e351f369dec0a04dc502616a6c27ac78256f063 |
|
MD5 | 4ef711223c565b0736b5b49ebe760638 |
|
BLAKE2b-256 | 91ad80bafafb582c98d0dbd51bd29b9a1f97a93dd459ba4efb9b25f6522aa70e |
Hashes for stim-1.14.dev1722650154-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1b5d7b195176bce6a22bbe46773e2d111910a0f62e4436a4f5babf42087c77c |
|
MD5 | 78db8a9a71ac58358e625b4511c56671 |
|
BLAKE2b-256 | 7fcb5226051ca3eaaacb83edb70b5c656e46da751b77bff432d62307941a62d2 |
Hashes for stim-1.14.dev1722650154-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ec624d3758ecdf32dcbd19c43badd4fafe52d77cb06ed2df834ab1958f25dad |
|
MD5 | 1ceb698afa99b09c6d7d589c56530a56 |
|
BLAKE2b-256 | 01722984667c499645cfe64ba1a78daadb923b18bb86c21e108d822b8f066be7 |