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.dev1711001478-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0995995f1ff788f3bcff3dac45f06473d028b1e6bf347650759e3f980ade398 |
|
MD5 | b5282b93cb6ea5da4a5caf18aaf3988e |
|
BLAKE2b-256 | a68914fb8efe4fb94743d39d9f1059992b6b7293a0930bdb5e264f5dc580d7a6 |
Hashes for stim-1.14.dev1711001478-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c9935add910e78b71b19bba69f90c4878925e92f2030a4d511e7bcea76c0c8c |
|
MD5 | 51759e807386069dca6656284a394c03 |
|
BLAKE2b-256 | 9cf0a50cf4214b8b5643f83dd217cba80cd54488062c22e04ec75a229a382124 |
Hashes for stim-1.14.dev1711001478-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a969350ad990c89cc669c912b92f16e9df32652b422259a02534892684a4dd |
|
MD5 | 658ea7fb22e46389c60280cbbe844b31 |
|
BLAKE2b-256 | 9b3d6690baa5225ff53da7d497cdeed3d3e0cdfaccfaea33150b3d73197dc70f |
Hashes for stim-1.14.dev1711001478-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c346d1f418ad2ced567eef53a46b483ea96345406960180072e8efdb2bf869b2 |
|
MD5 | c2c328bbe6c45d511c23279b4cee6664 |
|
BLAKE2b-256 | 40dead8e760d5e96f45a412083b308239e2348ffb92057d3a231f3f96b3b9dae |
Hashes for stim-1.14.dev1711001478-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd78455719aea644d52bba2a87776f634a2c376964a9b44699231c9c57cfa2c7 |
|
MD5 | 1ef8d7dcfa69f2dbe85e667567ff46d3 |
|
BLAKE2b-256 | 99f16120b3019383a6ff6bf7f2bf9d7a3e94f120150aaa90b1d2791b56637e02 |
Hashes for stim-1.14.dev1711001478-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb4f721e38ae5d789e687bf94bb2a5c9892a9d003f4096f59a56f700dc4532f |
|
MD5 | ba0851e98775fd8928c07a5818a217f1 |
|
BLAKE2b-256 | bfc5d8878511ad5257204e6291228762007887fccc21a6be1a99e65af75b55df |
Hashes for stim-1.14.dev1711001478-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3f11aaffc2aab45a2de0be11c66cb2c6fdbe86cc4664c3c601385f0566bfc7 |
|
MD5 | 971f20b2255f4eb3cdfdaa99ca9da1e3 |
|
BLAKE2b-256 | 53873ce705793d05f825c517873c797d289e98ce46bd19650f7f9406e277fa87 |
Hashes for stim-1.14.dev1711001478-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0047ebe66a1bb7302ab154f20875c9015397adb2c1886bc5921aa158607e538a |
|
MD5 | 0eb10de20816f6741270baf9512be579 |
|
BLAKE2b-256 | 2a188a3a2959c9ab084df843c9005bbcdaad2834675678a2fdf74965da24e1de |
Hashes for stim-1.14.dev1711001478-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cc66c3e875acc19a7b621602c82e9488b6bc4de95329f26fa7506cda9dbedac |
|
MD5 | 592163267c9ca215a40ab01d2c07efbf |
|
BLAKE2b-256 | 860b370497577fc349bcba75ca5f29201c058a1c36b437a6cbef4fdb22412ff3 |
Hashes for stim-1.14.dev1711001478-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32799d8ad333cff2a79fc381d9f3ee1f97978197ec214a3b5a091e9c3a56e44b |
|
MD5 | 8ae7005e457d0f255b42b2c6fd132eff |
|
BLAKE2b-256 | f0c43382231a9ae2951371c745a32fbf116662e7a105f4910f5ac6e9323642b1 |
Hashes for stim-1.14.dev1711001478-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dfe1afef308471193e8efe3645bd66c6bce10ac64f779826500c9fd78f97074 |
|
MD5 | 395a9118ca054c77ca5611940d34c16e |
|
BLAKE2b-256 | f129dc33b40f6d10df990ee4d7dd5a98314e28e5305d0717f20b5bb36b20c9c2 |
Hashes for stim-1.14.dev1711001478-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4451675ae9c5a89e7d722d6d026743104e35235ab6be7b5c97fdde533e1a45df |
|
MD5 | 1e467df5e77f3732a0e50e396edf5cd1 |
|
BLAKE2b-256 | eea23e54f2c75d0a7f30a2c125c2757c0740e646dc2ba4da70101309c276a99f |
Hashes for stim-1.14.dev1711001478-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fa2d0cfc6f870ffed64348df72dfae4cf7fad7c3223c886a314893053131a58 |
|
MD5 | 54163f460f1cc079caa67d0b3669c427 |
|
BLAKE2b-256 | 2bf7fa1904daed02b66f2ad427afda92508c620582d24cf60bd050d8eea26468 |
Hashes for stim-1.14.dev1711001478-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec73beae1d8317e894666ee6eb0ed2c5f5a0368c1713761ab87b477f3200b988 |
|
MD5 | 15fa0442688e235a5bf86d732e9da6cf |
|
BLAKE2b-256 | 3d7ad98b028826e2195ba2e689db71b0bef98a7e89914cfa4a8beeb1b5670492 |
Hashes for stim-1.14.dev1711001478-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89473748371098748a65029ac1a57d0f2575dfbdcbb99b42e549c008999f875c |
|
MD5 | c80ec4d3784b5c13f0e840bd37d67284 |
|
BLAKE2b-256 | bc5fa2164302210d14a6a7adc66eb0741d41edc70bf97016367f87027b995b39 |
Hashes for stim-1.14.dev1711001478-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64dded2b5d8aa9579a52709db1637b816ee9abbaccad4e93f7b28c28dc27811b |
|
MD5 | 652d94238b3a8d0c37b43880a2347946 |
|
BLAKE2b-256 | bd0bea8b1603f5692999fc70fad23bb4272482ddd6bc94819756f57599ff0fda |
Hashes for stim-1.14.dev1711001478-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a377c416ae6cb498e70ea94414c04ab33649af1458840d0a49a64ebfd1712c3 |
|
MD5 | 2bd834b5f1ad23f894dfc567182c93c6 |
|
BLAKE2b-256 | a7a7c14b698b97973549ad7fdaa51a3e0e8ce887673532ca6ef03eb88ef30caf |
Hashes for stim-1.14.dev1711001478-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a10fa5fced2062acc3bd0dd205d9ffa81c84e01680d40d5b333defb10772eb39 |
|
MD5 | e936ed9f197d21b856a33005993572a5 |
|
BLAKE2b-256 | ceb9d8ec01fd26a8991e51d378f23ea609b805671c8dcd90fe5f06804928b231 |
Hashes for stim-1.14.dev1711001478-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a5859dd7d0bcd4e62ba948a1e90dd9866ef2c877a41127165d1b0e740ea876 |
|
MD5 | 09f479e82d603dafc789fd3528563c9d |
|
BLAKE2b-256 | db176b42bfcf51ff20069abc5dcba6c81ea275cc9f0a87874825b1c47b1bad71 |
Hashes for stim-1.14.dev1711001478-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b269481d1f1ec7d0ce01c0c7908b7f4272e4852871ee01c1e1954b4370097418 |
|
MD5 | eb9de50c746960386b10950975013765 |
|
BLAKE2b-256 | 8f9da7b03fff47b94030fb2fae6a3ba6fd322988c2644d71ce1526147779fd26 |
Hashes for stim-1.14.dev1711001478-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad0c0e366e247e438b1973a1ef9365b9778c597f769c52a653a9d7b97b3de43e |
|
MD5 | 7edfb4633513ae1432045bad84b3c656 |
|
BLAKE2b-256 | 0e198f7f3353e714e3eef660e1199328f02591644507e8295632737732d80990 |
Hashes for stim-1.14.dev1711001478-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a15733d2dea01c1b1630183483f676acd195af4bd341a49cdbed0d47440beb4 |
|
MD5 | 47d8d330d0076c70e7dfcd17bf431e2f |
|
BLAKE2b-256 | 9e1efac87d8f74294be095d336cb9909f14db12604e68cd6ab6e73019c58ac67 |
Hashes for stim-1.14.dev1711001478-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32529f5729e9a1f402f50e8db54c2848a898afd9d597642fb260cbbb5347f26e |
|
MD5 | f8e3fc8bebd932b592ab10ca15053757 |
|
BLAKE2b-256 | 832f73bfc2455780348acca85f86644f1a6ba299cfa1ddb57115c6daa6b47b14 |
Hashes for stim-1.14.dev1711001478-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6e00f977ecebf81b085b8e2a7c60fee1b0a9bc8e03339586cd0119202bede10 |
|
MD5 | 393ae8efd6db2f789f9dfcb8f8b690c6 |
|
BLAKE2b-256 | 4834f57c448b9ad694ba27efafb720c47b341f3d6fa5e2d9dc652573b0a73812 |
Hashes for stim-1.14.dev1711001478-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18ea620826afc5fe200ff3586f4e83688b8c561b66a228fb06452c3aefdd76c5 |
|
MD5 | 857e8995629e76d77c542c0441b025ad |
|
BLAKE2b-256 | 0a168b17cf1e8c9bf84613e54dbe238c942db6c9344a43003a80b9a72c56a9c2 |
Hashes for stim-1.14.dev1711001478-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8c246a7ef9895fb7317a27f31caf71f9e9d894e911a645c42dc1ef667cfdc12 |
|
MD5 | 1f7d52b47b7519d9c91d3ef5b335a8d8 |
|
BLAKE2b-256 | e169c9ee31abdbda1e9c2a54cd8926664f1f07fab3332fc71262c241f63a5928 |
Hashes for stim-1.14.dev1711001478-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a65c81ded8b56002513d30fccd4f4e40c7bc4b8bf114ea0268d174b69a400de |
|
MD5 | 7d9a83653ec83e766316cddb52a9bc8b |
|
BLAKE2b-256 | c8cfa18d74b18ceeb4abb1305fc9b3a34bd40e0386e0e76d2af597e8dc8fdce1 |
Hashes for stim-1.14.dev1711001478-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84a355b244e81fff16995449dcae5e0d7ca7713c0bd77731817d18dffa3164e2 |
|
MD5 | af0eb299bd08e556618c8c0737d67cab |
|
BLAKE2b-256 | 52a3a69cfa4863fd6aac0f57051c8a830ede92b3420959f071f3ddccb02bfbc1 |
Hashes for stim-1.14.dev1711001478-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 996866d9162acad08255e43fed2c2ef3afd32023958614ce05d2fcfa6e55d9dc |
|
MD5 | 64b8646eb152df88571012ae672d2b4a |
|
BLAKE2b-256 | c1e3cb5fb9aa2c150653ce832554a0c527208e3938b1e8009047f75b0e26de45 |
Hashes for stim-1.14.dev1711001478-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3423e9a1893ab7a526088ea623c8faaa3e53067df0f00d3f0ecd6beb9b56101d |
|
MD5 | fc4ac52610484985f0e7fecfa87bd5af |
|
BLAKE2b-256 | 9201451b8ecb5bcf2c316dc837543edb5f16d4bec75842a9bd3da4888e0724f4 |