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.12.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14a31fe3e7d10c4a504b1a64321cc425a4051369734bc34b031e083a890bb354 |
|
MD5 | 8c2ca234fedccbfa85acaed3d297ef44 |
|
BLAKE2b-256 | 31f53bdb6c9d91b5596a089a5162ad2e4cfbda668e5fe13fb174fd3f4f36dcb1 |
Hashes for stim-1.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51331413966d9d4dc77bfc48601627b1291057afdc45b83efa7490f5566ff281 |
|
MD5 | 7373fa5af0aacb7a53287706e8ead362 |
|
BLAKE2b-256 | 32f3f87a13acf31b1c01b760fedf931db1dbffcfa592773036c5581f6f93fa5d |
Hashes for stim-1.12.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dc91a5b7a28cd05d6323ab6d504b6fa5b7723fbc643b170c70a15a75d933a89 |
|
MD5 | 0db67843a8063a189aa0b09f0478ab51 |
|
BLAKE2b-256 | 7487c9ee85bd669f2c008c02ec574734da2a31480db2206693ed0f795516771c |
Hashes for stim-1.12.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 540ba971aa84f858db1c2523122d1df1c7ae16958aca28c9dc3fe01c0554270f |
|
MD5 | e81bfa7fce774264f080cd9df9fba684 |
|
BLAKE2b-256 | 3c0d60ca662ae9fd50fcab9336d7beb476722bc677c4a4bbcd8a216092347425 |
Hashes for stim-1.12.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a42d12abde4820fa6549674a19b101e1633627e457437e85fc272a5e525df00 |
|
MD5 | 24c47df92ac1e3c59a89d554e748c459 |
|
BLAKE2b-256 | eb8b514fd62e5b1dd32689d4ab5a516e935699ffcc73ad93f41155b6abd2eb05 |
Hashes for stim-1.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6472646f683d5a2cc631bfde4e549b12082a2d46fa87abe3ab622dc4b2d2c43a |
|
MD5 | 467e5c8b066c2b225f959a66d4d0f147 |
|
BLAKE2b-256 | 98de7489e915b5eb0a6a4ae771ff8765b8a746a668a52370ad000c1b6d234990 |
Hashes for stim-1.12.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b63c6f67ab3020b1e301e8e70b8a467b73577b52cf1fa4f9647de3cea06df765 |
|
MD5 | 3f856a1f6937a8704a0907fe1ee54438 |
|
BLAKE2b-256 | bfd9a8d0a90c0ee6bbf426168be95d99b5a4ca2da613a694573382ae1dc0ad0a |
Hashes for stim-1.12.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f5e4ba177a49bc82b830879132466d15c34158147f43a407a3e22c30af67453 |
|
MD5 | 0c03b1309569ef22f7f1a9cd928f64de |
|
BLAKE2b-256 | 406ee9a188727b552032e9174b8abf85a5878e005065b88389a5f759810534c5 |
Hashes for stim-1.12.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae1a9f547a6605583a9c2bb5736f81f685ee65c5ec8836e019fddf2f5ae067db |
|
MD5 | 432d7da7c2c6a360391103df480737e1 |
|
BLAKE2b-256 | 4a089fc978a68e8774b6083ce1388d35e1bbe9f77fda42efd4d9006869cdb47c |
Hashes for stim-1.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c2dfbeb2308e024541c324f576b49ac973720a5c32d123b33097904dbf2457 |
|
MD5 | 2f5bc875e7ad97477c405da7e6631293 |
|
BLAKE2b-256 | c68d4d65b6d5d789727c57aaae26a2a7dc934c3b27a98761073bf73cd58b72ca |
Hashes for stim-1.12.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4132bf637525eb06bb43cf368e9cc44a1216a4e8f127c9c4fc368aa4de8f68fd |
|
MD5 | 4de0d87cdb3fb9c3812119b11d5b8635 |
|
BLAKE2b-256 | 1329149701a943f7867986fdfee4af7552bf1da4c8571997faf52e97c2708fa9 |
Hashes for stim-1.12.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb119716130d880a2b9e37ddaf4cb20aac7d23af6c08e2251629dee336b46406 |
|
MD5 | 6725b063a7ad0d8e12c93fee14566663 |
|
BLAKE2b-256 | 136330bd04a25793a725fd71e7b19a11f1c10244ef460db4b1b4c73953bb4700 |
Hashes for stim-1.12.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17888c85de6fee6a64d65a41097030e95454a3433cb2cb88429d65ad0ab69da9 |
|
MD5 | c2420522edbd691beeb962a9d16e2ef7 |
|
BLAKE2b-256 | 69bbe4bc049568e248567d5868e0490c8bca5017e2e368bfd1cb00702b2857d0 |
Hashes for stim-1.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8832b18f00d93e0e2a404b6597f73150fc2c94e6d0f770ca951cf09aab95af18 |
|
MD5 | dcaa2d4df35ae2bbb83aa022ed9ed277 |
|
BLAKE2b-256 | 81cadeeea9c6e46fca1b655d143b977464f2229d09a14aaa0c1359ba2a9bac76 |
Hashes for stim-1.12.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 126cfcc3dea688f686493c3c4faac2747aef62aa84d9ee8769c9c9746dc894ea |
|
MD5 | 36d932102eb5fd931afb08653f59edbe |
|
BLAKE2b-256 | cd3bb06a1f461b70744692a1acfbf7c0c2fd1fd2a679f26285b0b756b7c11c81 |
Hashes for stim-1.12.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a9302b9cab631d8f031ddb894e3432748fdd3a5e53454fe6909cd0c14535729 |
|
MD5 | 4b1ad9da49a6c428bdabd2ae945b7501 |
|
BLAKE2b-256 | 7a39569585e8fca9d7669ecc245c4a71f0225a46bf96acff1c20a1703cfc5e79 |
Hashes for stim-1.12.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5433995f19daa5ba8d3062a373b164c0d38a79e287d43b7053b2bfaa43ac90d |
|
MD5 | c173953461eec1b597d1a3a10943c31d |
|
BLAKE2b-256 | 06deaf18466e8d768b847e191a74cb0d70bba43b31f840d48e97ec0b9920863d |
Hashes for stim-1.12.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56c98f0582967367fd1873a12d04798b0e0afebfcd772b7534f024ffc2e760d6 |
|
MD5 | b801b8e4e6bb8e9a6c3da3313a626641 |
|
BLAKE2b-256 | dd79e7d50f096a61ecb97b7c86eb501bb1092c923cb024ecda5db06237eb8281 |
Hashes for stim-1.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d5eaa85b14faf1dedb19eafca8d184f202f90dfec25f69c540c26a624cb1b75 |
|
MD5 | 7289dc4135e5964362776195857fbb14 |
|
BLAKE2b-256 | 52e1456edffcf940e593c8e17fcf4d8889c363f42b40e20f3a68037b0160a37b |
Hashes for stim-1.12.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee395cf492536f5f9f1bf7cd8f300b2731ec6ad383f114f1b49033288df5bc35 |
|
MD5 | f97badae35333cc2cb3b924af418dec6 |
|
BLAKE2b-256 | 55aaa3876d040969b42bc4d31f6b083e73d65a4572da6e110c1ddcea2f28cddf |
Hashes for stim-1.12.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08a035c72671517f0809a3ed0c450e72fe699312f9ff08f3e95cd5348aad6883 |
|
MD5 | 9f4c552636f1aad2cdb6ea6a6ed41554 |
|
BLAKE2b-256 | 5d7b54d09b38fd973c6371c10a3d7558f1ab735f118a82580b4e26a709819c01 |
Hashes for stim-1.12.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06aec33c164be406185a2a1c11dd319267ad2f019648482de71f0c42e026564 |
|
MD5 | 553766a4f3d15ec54919d234b81a4e88 |
|
BLAKE2b-256 | ae05beda59a2e8ad8d5878d61b023c6a31f0bfee416cab71e8fbf83e6eec8a0a |
Hashes for stim-1.12.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f21fe42f2ba800a1f895fd2e4307a7fd04f153a360899d2c6e8f012a6576bb74 |
|
MD5 | d754611d5a9652ebd4cdaf1c33781075 |
|
BLAKE2b-256 | 56f32eb83be6368ccf55d1df9ca711062ea8d09831a17a915756fefcd3e291e0 |
Hashes for stim-1.12.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 547b597fab87ed8e5eec1af5242e36040128f459dfde17aa120695d10125b4df |
|
MD5 | 0cb67d2ff4ca08e013dff17e644d1943 |
|
BLAKE2b-256 | e2197070a1e60d6dde44d7914ac06d616b5e0d8bf5a8b930b5d6cdaa525d994a |
Hashes for stim-1.12.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a19571de45cea54d76efd8d2acff7050fbb651e3372fa1bbbd1b04ccf5d29854 |
|
MD5 | 7e4b0aa0af8dbd4eaf0cdf9f1e3ff213 |
|
BLAKE2b-256 | 4f7ec056ff427b2972b9f2eb64cdefe837a74ba4dc5a3df003368ce32b80a41c |
Hashes for stim-1.12.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb45e0ac4e94e52d4e546f13673db59de77fb78d97a7775063ccd60378feddb |
|
MD5 | 3012899b28dccef27349d8d7251e8b2c |
|
BLAKE2b-256 | cae750632f8a3024113e4d1c0b4bdc9af5475fa45a5fcd419de7bca92cf11b1e |