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.dev1699910914-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa1092f9d2e602ab7c9dfa0685aaa1bf9d9dc7b01e4d75b879b66d0d6b8f0504 |
|
MD5 | 3fc2792064fcd308274531097d6a0e25 |
|
BLAKE2b-256 | d863db454b193bcf5e976e9c7087177ec998c594f8ecaa9fff108c5604433056 |
Hashes for stim-1.13.dev1699910914-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4974caccbea6135a2fefccfcb8123f11bd5456e22d76ea3f9c509b218466996f |
|
MD5 | 0e57e5b4e38018807239b1c0e9b61873 |
|
BLAKE2b-256 | c9e15a640ec16eab569dd9a74ae466d4582bdaa51297a6365a07ab1015bbb0a0 |
Hashes for stim-1.13.dev1699910914-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51262b88d8c45643e603180cf5069c8e30f4949cfe130bf046fbd83ecf51af38 |
|
MD5 | a5982aa6b1cccb5f2f27c50fa39a9ba4 |
|
BLAKE2b-256 | 59429e49217b296d3bb08b9b79bcdede21b2c8325368c6f35c587459561a4be3 |
Hashes for stim-1.13.dev1699910914-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e93dc69f0695b5e564bdb9d5c6b023299ffdde0c71d197d7e1b772aaf93902d9 |
|
MD5 | 660d0c417854fb481fc2da63c000a070 |
|
BLAKE2b-256 | 653b8b4c6f9fd7f09cef10af62303ca574d62c54a7dda31c36cf932bc3f08df3 |
Hashes for stim-1.13.dev1699910914-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fce22fa80e8ad3ae1e869319430005e24d5a8b7a6aa4eb3feccefb0f4750a7b |
|
MD5 | 145cbeeeade75ea876143fc3e14a6c67 |
|
BLAKE2b-256 | c7ad3211cb6837ef544611f3b94ddf3002a827055fbd551ef024f7ccac235953 |
Hashes for stim-1.13.dev1699910914-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e414593f1f2cedcf551c2e14db05b192b3b1597f0ef06f9eb733bda642a6ae81 |
|
MD5 | 3ed147d2c2b789df886876cd62714008 |
|
BLAKE2b-256 | acc4a610c178a04ba70458bb44a68184a2d69002e59703c1a424dba9328c2ce1 |
Hashes for stim-1.13.dev1699910914-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bc9fff440d5c79562df3775720793e18f4ddb80daa0075564e428b3b64c1210 |
|
MD5 | 14af9bbf326e8d5a99a6961f19d54220 |
|
BLAKE2b-256 | 8f609dd4636b655dce589c00e26ccdf929c416d9981524ee27a8e7b415022e64 |
Hashes for stim-1.13.dev1699910914-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecd12ea0f91fa8974cf009d6696c28b612b0461a658fd2f0ebbedab502de8f22 |
|
MD5 | 4448617ac81931ca7e2cec3be198be96 |
|
BLAKE2b-256 | 1be4667390487aa4015f53401dbfe33723adf1fe6a2d557cc370f844ed5108b2 |
Hashes for stim-1.13.dev1699910914-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6aa5f65e8712cf19e3fd3c4f3ffbb06eb4ab4e2e07a3506fddfb62f195d2660 |
|
MD5 | 4d91d16bdb27fbfa5cd043a750f98c4f |
|
BLAKE2b-256 | 307c8f9e5c591c999f7f7ca8a5a376719e218add66e55742041fb6821fdac194 |
Hashes for stim-1.13.dev1699910914-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66ee21b9ca9fe397544acd92848b2fcd65e1671ba7a6c9b05d0e1f55b630d2fe |
|
MD5 | 8b66a5d59689eb39471f1c494dd68de9 |
|
BLAKE2b-256 | 63e2855d4eb2673f70b3b341beb22e1ea2181d6f7f148ddae56a301a7a211f03 |
Hashes for stim-1.13.dev1699910914-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47b808d2ba6d45a1464ef5a21c422a9bc062199ace5767c6ee5a4fe5b4a11c94 |
|
MD5 | fa4d3dbc9924e8746f226aac73c8fb0c |
|
BLAKE2b-256 | 7ac0173ba40be9f2ecbb57d90154125ec111756a0e59741c205e77c43f3dbf1a |
Hashes for stim-1.13.dev1699910914-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81be1bb33cb068359e9d9f0bf38c8121be179586cf121e904fbe2bf6686b55f7 |
|
MD5 | d06ded1605b210b95378a6b050980073 |
|
BLAKE2b-256 | a9227601106351a65e5a8a78d5c3315904c2a6dfc76874c90d6e1d4e1099850f |
Hashes for stim-1.13.dev1699910914-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99f59ef4c473549497fc0fc4cfc1e6244d49dd40791386fc5057822e374af6eb |
|
MD5 | ae2af8b4645e2e3bd28454b812bbd6a0 |
|
BLAKE2b-256 | 9e8d7c441817d97e5d2820c48f7858a8f0fe36e18528fce66429eed4310f782f |
Hashes for stim-1.13.dev1699910914-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350e1bde2bab482d0bdd7d12523d53c12a32b2dd494ae5f1b7f12555b507eb71 |
|
MD5 | b160ff491327008acf4fc82e6141148e |
|
BLAKE2b-256 | 105e57860445c857c52232a79542af5e78f2936ba00eee2efdfcfb0e00b5fae0 |
Hashes for stim-1.13.dev1699910914-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b9081cdf61bba59cb15ab9d5ca4bc62afe0df6daa87187d672bfb3c2c8383d9 |
|
MD5 | ff490b494e993ed6d993760d34b97d41 |
|
BLAKE2b-256 | 4dba9ab0de655ea11a1cae3aca1909138a787e8bc1824aa4b851c3ebd35f8937 |
Hashes for stim-1.13.dev1699910914-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da5a6c7833ed7fccee597f225d8765b03706c8965f3ab1d650384c99fc6d6f0 |
|
MD5 | a3033bd338760e50778b29f660747adc |
|
BLAKE2b-256 | 9df7a2c9220b9388a946bd6e63ea6ae85da9cb29cba0e375275aaeb1ee7070ba |
Hashes for stim-1.13.dev1699910914-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7de1b7c182e6322cb6d716e5a1a98719bb91cc6d36081e15aa0d0aa9ba0d136 |
|
MD5 | 5d904c82f62996ebd2243537c5a07ee9 |
|
BLAKE2b-256 | f009bf53c1f9974e14a3d98a6045ee485d0153aff68628fa6861abbed459069f |
Hashes for stim-1.13.dev1699910914-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4f2bf2a3de995a6eea27951b60273681a3010b47944e3f36370d3e476935eec |
|
MD5 | 5901dd11b9b7403991f85812a14165c0 |
|
BLAKE2b-256 | 66d8f2f06fc9d31abf9d542a858048a7df1a5c8494c696dd1cb5d8a758453c75 |
Hashes for stim-1.13.dev1699910914-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0de171e8f2760fea7c2ea9279b959ef5d47ac4950e504727b9618a9be236626 |
|
MD5 | 420ca2f4678b09a9a7ade22304b0fc3c |
|
BLAKE2b-256 | 2984795f18ec43114465b50025946b829bb0c5944574c9e35a0f8e9ddfdd83c2 |
Hashes for stim-1.13.dev1699910914-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceb22f1e881f32c585358c4ebae92f7452f349ee7d90774df654d37b680f8301 |
|
MD5 | a7b2045b83c6bdec42bfdf8706007616 |
|
BLAKE2b-256 | 94c086e82b420570aca9b22e1f4e88c5f34b6c0a7c43f3e5c9f5b60f503a45f7 |
Hashes for stim-1.13.dev1699910914-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47b46254dea9329eee0fedb11d2bc500a9ebc908fe28ee85c0bc9265d0ba4289 |
|
MD5 | 22d03dadecfa92bf51c9cad1edc0ab47 |
|
BLAKE2b-256 | 9fb6efc763138e25bb35d7471ad66635b43822dd94b26f13712b2f7ce3a002ee |
Hashes for stim-1.13.dev1699910914-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bf7a631ac280b45243e921f81eb40c3c855699beed7d107b35d4c5fa6634f75 |
|
MD5 | 9840a5c97bba612ca85002733573e7ec |
|
BLAKE2b-256 | c9f5d608720625978014c2cf3a64cf14215337e77db5fe7a80589d955fdcbfc2 |
Hashes for stim-1.13.dev1699910914-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b7eab5aa900b85d74f02564552a004df6e3573186a32a1c5941b266070741b |
|
MD5 | cd1e1ff6958597841a9e36989cc25cee |
|
BLAKE2b-256 | c13074c9b89425afda796a17858b691eb937e2aad1af5c4fb9f8543586f6ee0f |
Hashes for stim-1.13.dev1699910914-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71c14e83be5a954235aeb8ec05d03c164264d3a60686d613efdd808fcafe45fb |
|
MD5 | 22d6f13f28fd92918bf888ba22224af9 |
|
BLAKE2b-256 | 7f95957268ea91bd3d5e4f6f1efecc83de9cb52d33dd2a43077dcea4b7f68ba3 |
Hashes for stim-1.13.dev1699910914-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db4413818bf02cc500ea4c487d209b974f238af4dc29225565a5161192f49b85 |
|
MD5 | ebef34123110edabf55a6cbe57e9aa4f |
|
BLAKE2b-256 | 9f0eb296fdad03ec421cbca9966591a5075919ab7bfba90ce12fc468f014631c |
Hashes for stim-1.13.dev1699910914-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79927635d563f0b745f97869d24f74da11919e90333ff9c41490726b0be9a85b |
|
MD5 | da17e6b8ea576538baf5e66f00992f10 |
|
BLAKE2b-256 | c4cdbcb2fc4f3e2b8829d09344f5b7885fc1576285fa89123e5b4727d5075db2 |
Hashes for stim-1.13.dev1699910914-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f77f06a30b39ac811af2f1630f332eed71ddedda0bd70730b2860bb6a3f1362a |
|
MD5 | 61277b12cf1783ebf3b04ceef1cfb7e4 |
|
BLAKE2b-256 | 012e9779566c56d06c4e0dd286d7f43f9a83734a1f67de2ce048e4fda798448b |
Hashes for stim-1.13.dev1699910914-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a098b1e2feade9ff667e657003b0c1b00bdf963b2d5d31ca2706053059ba743c |
|
MD5 | 1d326f71db6df150493cb7bb2765e1fb |
|
BLAKE2b-256 | de67583a8a3274b23f80490d5306641b8ac23b49bfbac0ebb0060cf750b9f319 |
Hashes for stim-1.13.dev1699910914-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8da9c39e2f8987f17dd89236eb818b60f63dabc521330e567f1c73b2e1280567 |
|
MD5 | 4aab57df0c752de501f7116a9cea1037 |
|
BLAKE2b-256 | 860410de271f5e849bbedcb621e271a58c2274c11143e46087cdb0680c1727f6 |
Hashes for stim-1.13.dev1699910914-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46623bf7ce908555f5cb3086e40cb4c1bffe62816510d641129999cd103e0913 |
|
MD5 | da4ee10aa6f7fde39367665e1885eb68 |
|
BLAKE2b-256 | a212dfc2c065605cadf6b47d505eb5cd9ce32c8d3cf5d2fd64ef39541cdf4030 |