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.dev1692228133-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5781051b14482c13f08cb54d6456a87c2b71a479fcdd9068e5737fb04f8b44ee |
|
MD5 | 498fb4b8f3f863610d4bfeed87c77f98 |
|
BLAKE2b-256 | e283e6f2206ac6fb0f5de46b3cb721b048418de4020cb8b168597ea1932d9df2 |
Hashes for stim-1.12.dev1692228133-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57f9b95d87e515b32938cee45615ce2f8b94715fe1354753aae0a22e664c4eb1 |
|
MD5 | 5a1833517f33b47a30daeff8b1e9bb60 |
|
BLAKE2b-256 | d1d56c5759835c7b94129722ca12fc6ba99c51fb499ad1383b5bee6ec43df23d |
Hashes for stim-1.12.dev1692228133-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67df2b97fa9b3eac586ccfcd0951edc2cc6e89143b6f1edba14b205ef2a7270c |
|
MD5 | 26da975840e8f6a6f9f6d3e79c231110 |
|
BLAKE2b-256 | a86ae968a48b9b9f5219964224a6b861af5e6cc9ddb88c1758c844bf64bb044c |
Hashes for stim-1.12.dev1692228133-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c70d7090023485a8aa1fc14d0269f116f4520b2bb6f2fbcc7008bd6906f632 |
|
MD5 | 7e89583a9679ed776b11bb48771e1a86 |
|
BLAKE2b-256 | 4951b7a21857349abd5ae07c2f22485e625dc7eed7ad19035911f1a48a83d38e |
Hashes for stim-1.12.dev1692228133-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 071b9fc43bf0389cbb1ce026cdf6bef927df0b2a26c2912c4231038e62e7648a |
|
MD5 | 072042e93ee6f9b63126d3995eb57528 |
|
BLAKE2b-256 | 47cffd997da04ebdd2b4d4c0b6d0ab284bed35044393eee469637957bfd9823f |
Hashes for stim-1.12.dev1692228133-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 264a09dc7da385567345de80a22822e4b6b83e9341217323452714cf2fc6fb7b |
|
MD5 | fc5c640778025eb313771b6eabcc274c |
|
BLAKE2b-256 | e070a6f9054a7b2f51a83d6f121dd61f1cc5a4e1991fb0f0b42386918da5d0f5 |
Hashes for stim-1.12.dev1692228133-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a7005d91c9f31b3d04a39994f84331520c847035fe0c6ebfe38a6ee71302f26 |
|
MD5 | 4d55300163adb02305ccdca0347967cd |
|
BLAKE2b-256 | 3acfa90b1e63e12b1c38f829e72b74a64a1ed170f3eafb4531b7c97358db353f |
Hashes for stim-1.12.dev1692228133-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab055728d9d5c7b123e3279ba75eafd52471a40c0dcb044a7724c81eb0da1ad |
|
MD5 | 1435a84fafa96ca7e1236858fec478fc |
|
BLAKE2b-256 | 294f53a8af7cb0a33d6e1435a50e0880856a3771ae06a8b377f80dfa468c87d6 |
Hashes for stim-1.12.dev1692228133-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24d2874911549f9067b874c31b11d3f18d2c87e17869b1ec005fed1c64803487 |
|
MD5 | 2e7621accf57cad79c3512e299b7a129 |
|
BLAKE2b-256 | f1138b429a59fe1128a1005c7b066876685711b628a90c60b25c800a620131bc |
Hashes for stim-1.12.dev1692228133-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8942c0ad3c03c6ee642d31c7523af83310ffb8cb75326c585b2b5fbd8ff1cecc |
|
MD5 | 21244ae62a8364b6524dd25ba70deb51 |
|
BLAKE2b-256 | de7fd27bdf146e7c73bceb6d89e8a99ebd9baa650755159afba3a12a4ae9aa49 |
Hashes for stim-1.12.dev1692228133-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57888b3ecd9b2f99ef24bdf08abaa7e968435611387596a6809d549baad31301 |
|
MD5 | c6f9bcf7aa35124ac536ed0bb1697849 |
|
BLAKE2b-256 | 1b0d144bcaa5616eed15a6767d9fe922f1c618fea443f951edd8b3acd9ceeaa7 |
Hashes for stim-1.12.dev1692228133-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19d181d8dc17f0178e619bb251ce80d604ffdb928df8cacb84ade45e0f3b0104 |
|
MD5 | 435b1cc2c16246911f68d62047627dee |
|
BLAKE2b-256 | 4d2f352ed5945a0fab80eccffd41e3349b0f77da866e17b4d4e3d83435716714 |
Hashes for stim-1.12.dev1692228133-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 216aaafdac9c55a207b37bfe8d9735721808e85c8de9138aed8303e55c5d51b8 |
|
MD5 | b61db6e4e19d94ff86283a3b5d20a17a |
|
BLAKE2b-256 | 3e6b603e116fc39fefdcc81d35dcf8e7e632410c205d204aa797a6760bfac4cf |
Hashes for stim-1.12.dev1692228133-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09fea918646dceaa0aa7c1e12fad2dd019739748700f99fa66ba442eabc8ba3c |
|
MD5 | 8769472e58c69b2c984300250db3f6b7 |
|
BLAKE2b-256 | 0521993a37cd2bda049d200465d1b22fabd974f77b6a3e06e1ec78171d224f51 |
Hashes for stim-1.12.dev1692228133-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d62deb16e62d0f25f2d35df623c02b151c3c69724632942ca7c2e156f5ba53 |
|
MD5 | 15fc50a3c488da62c43d36430582d799 |
|
BLAKE2b-256 | d61ca7ae7b5f1a6da669509ecc7a883aa0e5e41b3573015c1ff276200ef1f8a4 |
Hashes for stim-1.12.dev1692228133-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a7387a771e2eda4c5084684226c5c5999fc27c4e9fcce7f849ce31bccd514f |
|
MD5 | 79a3392ccf15382042969be9ef4783f2 |
|
BLAKE2b-256 | 43f542a99ccdd0b1c9517afceff592875b4d4c47e1160dbe7058a7dd91afe548 |
Hashes for stim-1.12.dev1692228133-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef95cac690fc21c7d33c33306d9580fcfe5c88df6e490712889f5019dccf0cf |
|
MD5 | 794855febe73687e1e2755996515ed58 |
|
BLAKE2b-256 | dbc4654977ba3ba197bb143f651f9fde7da4a647df4d08c794cca9498a04bf7c |
Hashes for stim-1.12.dev1692228133-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ba5660cdf2dfe305d0eb8676dd6db06fe30dcf9a927a7419d591a086658d1b |
|
MD5 | 2c64eff7b49f53d2bb57422d708d65f2 |
|
BLAKE2b-256 | 3b4e7f1dbc78c6f570c8d617e12a919b8f13499c03cdbf8e45c7d51c4abce4de |
Hashes for stim-1.12.dev1692228133-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719cae32a3e71e2d2d1bc175cd485a6c4928276f0dd2da6b617f78160c654131 |
|
MD5 | 7016e1069bc64abea4a108194dba9727 |
|
BLAKE2b-256 | ee2f2e7b74ea9f4beee87fbe50590ced7f39623f1bdb5812d83f467078d3bea8 |
Hashes for stim-1.12.dev1692228133-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14e26283a69b9300dd072eb33029a46d4fd3354593e7ba12d4ec55f2eb17a4aa |
|
MD5 | 5190b73b29b23ef896eda0b3cef75e1a |
|
BLAKE2b-256 | b4464eac03c313dffee8bbc85bac3746deb50637977f9f4066ec761ad295089e |
Hashes for stim-1.12.dev1692228133-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbf169edaaa4a5ea7489358d75ce482373660f01689fa3c9551f47029a85a6dc |
|
MD5 | 798fad4691eb05bec6026dae10d2546c |
|
BLAKE2b-256 | bd214ca32f407e17fc4afcbb327cc9ad3786fa417412c32ddcde5dbdbde737a4 |
Hashes for stim-1.12.dev1692228133-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cc7e35ffe39d0d9833f36a0a28e3c61608b3f6049d0dae557a16c5c53b0b27b |
|
MD5 | 97fac4d84ffa9825fa2b38b67128ad3a |
|
BLAKE2b-256 | 6d631f8b2c26e6514e1980c2d537c7922f63d2b10b60c2153f41f62cace43a0b |
Hashes for stim-1.12.dev1692228133-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d456985d0127f57941b1d93955ebf4928ef1a6e7716779add56530078ad2958 |
|
MD5 | 0e2c77fe8b68618cee9fa66285b97a8f |
|
BLAKE2b-256 | be10293a34a5f0f3a154e919200a255feed59de7b747b40936e98c705cd99072 |
Hashes for stim-1.12.dev1692228133-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beb75fcc830b468d2e624ddbd7f3f74f6f79f38a48e3d8c22618bceb44e9f8d2 |
|
MD5 | 974a7feeeaed2ff10c4636bc3427925b |
|
BLAKE2b-256 | cf271b94d8dbe4e5ef2063cf1ba530ce32d492b4176ea9788e2c73e85fea14da |
Hashes for stim-1.12.dev1692228133-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 937b36f11ab5b4340ef8c09a9c0dafbdf48fcbbcd6cb42a33afacc0086aecefa |
|
MD5 | 9ae40c42732f8334bc8b5dde2b20c464 |
|
BLAKE2b-256 | 7fd5bdbd990bbf5f5ab643ebb2909b822dcc682ccfd89b4865f2e4c4f2f1cdc0 |
Hashes for stim-1.12.dev1692228133-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed97cb416e26d902a20cfe46bbe968fa1738d2ad728e3553bebad8ca78d5590b |
|
MD5 | 5c9af36c173f1b43edafeba924dc4400 |
|
BLAKE2b-256 | f98c2f621b3251efa7668594fc9883e2d202bd9ee14f7383874fcef3db318017 |