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.dev1719957432-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 883741dc94f352580d72c54ac3eae8e82dd69e91367ae6726069e5c9b9230431 |
|
MD5 | 036b8e2ddbca31dbe288801698fe743a |
|
BLAKE2b-256 | 6e402c46ffa64e87b4086b9db3afadfc2d47303292cf21c980b20238306e12ac |
Hashes for stim-1.14.dev1719957432-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be2541d63643a38c51ee1913004c2f07074c08264743b558bf6815c7db84173c |
|
MD5 | 9007e7a871b85bcab433de796552f95a |
|
BLAKE2b-256 | 3bcc8b2a2b354619f3e0f8a762cfa43068cf98e7d66e9fe270d800a0d707fddd |
Hashes for stim-1.14.dev1719957432-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bfe7e87876fea60e402660491fa026ed59698236b715d90ef4b07e91c93a3c0 |
|
MD5 | 5a78e78122f22a5f6e98cca8559a267b |
|
BLAKE2b-256 | 54f72a2ab9dfeda98415bc02e61363f92a9a5a95f5d86dacc090c8962006ed5a |
Hashes for stim-1.14.dev1719957432-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52cc1fe88cbc8c59663330887c725b7034d40645bb0702556402c6499a0f2da6 |
|
MD5 | 10ee7403ed805b6a0677433502962749 |
|
BLAKE2b-256 | 8b8255ba46df0e4ebfb63722da12d0a0b5859547291ff63d1bc2296af8e6a3d0 |
Hashes for stim-1.14.dev1719957432-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc60104272cc384617127a0950942287661400f392b81f34cf386ba186bf58e4 |
|
MD5 | 3038799e12fd2fab1e35ef60651d819d |
|
BLAKE2b-256 | b29f76515db903ed045a48c9ba32d340783f638f63fc6a3c8336cb33a3cf8082 |
Hashes for stim-1.14.dev1719957432-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef14abe63c5436ff51f84e901c748280eeb93ebf9bb97e92b7c046c7424bd08b |
|
MD5 | 9e57f45c9dc347d12ed4810522212f0b |
|
BLAKE2b-256 | b9544d732b826bced97ed3e8fc2cd7d676fb08c61a35687a86fc0aec7bc2ac84 |
Hashes for stim-1.14.dev1719957432-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fbe7af5f202e83d6988b6ac1ff025ef1525e1aa7cb97edec9f0debb1d778743 |
|
MD5 | 9879a8d6cd9ec9d2a2c1decd59812c51 |
|
BLAKE2b-256 | db903752961c00db6f4eb05efcf56cab2f05b68b70811c109af8a0283f676035 |
Hashes for stim-1.14.dev1719957432-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0352b704d1ffb2512597acd3bcf3105616db215a60c487d995479d001e242884 |
|
MD5 | a4711612b7df577e53ba4603e220eb49 |
|
BLAKE2b-256 | 7d50c8849e923df043643c57d4df782c5f78f9fb5491f0ee8c0d7ddf3cb78dcd |
Hashes for stim-1.14.dev1719957432-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c40ec80e5165800278f2180ffe4a022aa1adc8491a368b874df1c0d7ff96cccb |
|
MD5 | cd8a521d07e73947504983c2a1fe06de |
|
BLAKE2b-256 | 356d0080d5f927176ecf5b840a64135fe3fe393655a0c9fded68cb68828cf4a3 |
Hashes for stim-1.14.dev1719957432-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44e7694f1d0d304fcc036bd76e4dba1b6aabaa61dbbfe9766aefd98b4eb2a1c4 |
|
MD5 | 1a51988e8f5505a95327517a4f236123 |
|
BLAKE2b-256 | cb3475c8abed0e5272321ff914077e0aff6443b065839c61c934c9b3f73203b5 |
Hashes for stim-1.14.dev1719957432-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc2fa1fe0f20233b760b8e02d2faa10586594423f0f2011d92c090d852d1160b |
|
MD5 | 50a8634f4776c78500efba885dbb6ed3 |
|
BLAKE2b-256 | 22af1dca47e79bc9a7c3e3dcd692fc7cce5430db5bdbb82afe9417092ad7f6f8 |
Hashes for stim-1.14.dev1719957432-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09412c387d9b3fe7b0ec845b93e116488a8bbf7393a8d882c2f04c510ce2d4d3 |
|
MD5 | 0907c66499b573d8b43bba2e750389de |
|
BLAKE2b-256 | a7779bfcd38a9f930483fcb28abf8e53fab0cb300f3181c644ef2d7cc5f35204 |
Hashes for stim-1.14.dev1719957432-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eca7560046b7e0305687f59c05ac4351fc18bc6ba7cedc4a18f4bb8eb4b5227 |
|
MD5 | 8de9ce820e59c6a8316358b7bb516fc3 |
|
BLAKE2b-256 | 4ee3b75a0e2912f70ddc325e2199c28bb48bd658ce8fd73b32f3e2402e507b6e |
Hashes for stim-1.14.dev1719957432-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68863e16e5a8c01f6501f1a0ced4482aad07754b0ef774e295b32fa8ebaf12e |
|
MD5 | 11b2a965e4c0da67e12758f6ce714a3a |
|
BLAKE2b-256 | 263866a8f68e78206d86c45edc1bef9225f3693de78e847b9666cabf7b8a5656 |
Hashes for stim-1.14.dev1719957432-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aa158331e802f19fa45e42f9594669dff44b759d98065b582917b0139dbd4d8 |
|
MD5 | 2e8b29024f6acdd6594fc6c54963abed |
|
BLAKE2b-256 | b16436c4723592a92997714054a0cbb3b8e78d397650e37d7457bc337a961217 |
Hashes for stim-1.14.dev1719957432-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f99c1d5c68e3b34a9c36e04b27562810701e02b3d2bc58f6aca117020a704e0 |
|
MD5 | 2c20c58c06384515666345446960716f |
|
BLAKE2b-256 | 3da45c0dd1ecfbdda2d4d5fc346547124d7216afe6ee4ea4229cbdc8a8f209eb |
Hashes for stim-1.14.dev1719957432-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a225cf6b4a5edfb02e4f0ab907e6bda25ea58a4e53d0c998c9280738bb916ed6 |
|
MD5 | d0c4428a8c8be991add47259162915e2 |
|
BLAKE2b-256 | a7ab4f1adcfdd17f012c757c236d792c1794d328e7f52e268e59769e4ebfe140 |
Hashes for stim-1.14.dev1719957432-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a24bbe56d89b8c690250cc811fb13f106a500b9841d39d4027e6bb9ffd5ba4 |
|
MD5 | cf6c6f70bcd2292a876787cef3c6bba6 |
|
BLAKE2b-256 | 59c3b0f7683f9fda09342d6e1315593d0e7bfa159f093a905c8222d28dca8911 |
Hashes for stim-1.14.dev1719957432-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08d2b277534059c4969fd08ecc7f0755651e9394aa6956efed31498e43e53fb2 |
|
MD5 | b850c0dde0e1fea62dc89c044f867319 |
|
BLAKE2b-256 | eee51fc63e846b04fbafe60347aadb53aef47e9ba3ce056fdc66ab0e9fe4a882 |
Hashes for stim-1.14.dev1719957432-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c5b13d6714104244436e3c8f6cced6b7adefd419c23e23a87c736846797f7ea |
|
MD5 | ead0229e0bd4387c91cf0a13003ce140 |
|
BLAKE2b-256 | c32c747cd1e4e2b3d1e134b65985199e301f5fa0a950f476adf8dc90e9d207c7 |
Hashes for stim-1.14.dev1719957432-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4597701915935eafa149e923cbd7eb21d22023e812d252231747dbf182646e49 |
|
MD5 | 24614d4d54a147958781b96274412521 |
|
BLAKE2b-256 | 9fac6f41f68bb50b2e05621a0612495da90586be9832309cfb49e7be2ad1bfea |
Hashes for stim-1.14.dev1719957432-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3365a85020bebc9cf7266f0a292c5aad3abeca812d80901b2a0ca29c89fda20 |
|
MD5 | a19c6514325eb8a60d41081b0b3a65a0 |
|
BLAKE2b-256 | e380b74af9614b342c40095ff792b47dfd0ec5cdc59d108bcdf4d1abd49ad240 |
Hashes for stim-1.14.dev1719957432-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5b43b8c3c6da0a8ddd6b9e836d5f19423555df1a7c2b6f6258b692a4bdba150 |
|
MD5 | 8d1951b6ce6500f05cd2713e7f4e3884 |
|
BLAKE2b-256 | 37f7e29df0f8b25fb211bf5094a11dcb001477417ea877516817b8a2eef97cbe |
Hashes for stim-1.14.dev1719957432-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03a7ec75d1e3a2e74f7b8279b59d221f4a177965fa758ba7635b02d678398106 |
|
MD5 | eb92e4021a4c7a532e6342efd0fdc692 |
|
BLAKE2b-256 | 257d56b62eb1fc13b28c21f2fa03c1c410d7e56c92e6ca84bb027cc6f66d07a6 |
Hashes for stim-1.14.dev1719957432-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 003000360cbb2afb52ce895a2669087599f310243e322b71872523722e192627 |
|
MD5 | 6ab492ae40871d8238ac89ed186b078e |
|
BLAKE2b-256 | 70207ea453baf7620f8dad56ca6324a46e671b51c5a088ea5a00b0c11d433608 |
Hashes for stim-1.14.dev1719957432-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea042369810a9bd171ebff3116b6199a84f00af7e02c0c88710a138f1e631a1 |
|
MD5 | 0e98e5935ebc5e95ee7e23e875364400 |
|
BLAKE2b-256 | 3861d6ac44bf5a5b3093d0de8f36d637162a02cc6c221e07f3c1c1b633fa1cf9 |
Hashes for stim-1.14.dev1719957432-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | effd49ad582a39956c08bc800b550978d47157c6396b75e8cce34eb48815ef68 |
|
MD5 | 91e4368d04882395eeca1a03a4fcd749 |
|
BLAKE2b-256 | bf93dc0ba876552bd39124c88e7840e8d4e70c69d22f0dce3913fc5ce8ef12f6 |
Hashes for stim-1.14.dev1719957432-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3204fadf918454dea4b2418d9d65812839aebcbb8d9545cd57d4ae03cdd8dfc5 |
|
MD5 | d4ae68b1602ea18db453d9f779fce0de |
|
BLAKE2b-256 | bd3076857311fe6bd6c8e53add8f38462fd664835d7a2f2d92703cdfbe78ecd3 |
Hashes for stim-1.14.dev1719957432-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d5b3847c51696451859b7fd5340dfca336a2d913842d78c58dbba697d930822 |
|
MD5 | 3c0f2a01d192baef588bf8f7c1b7fec0 |
|
BLAKE2b-256 | ea8a9eae471e7c127d93b84b99770125b83533756af6bd72cec74308e387795f |
Hashes for stim-1.14.dev1719957432-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 782b8e799c50c4de203adf1893bd44c14e6c4eedaf10c58d67b2d4c9a675cb40 |
|
MD5 | 1938a8ee11327495ed3e25f0fc9dd0d9 |
|
BLAKE2b-256 | cee7873b9aa67ecd24a18c01084fea045c808b7c9d444175f53ffca63a5f0ebe |