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.dev1700353273-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6075793dbbe662d68b056427ebb4023c55832f429bead1542b7b82fa3a786537 |
|
MD5 | 339cea3d8c174cef17cffb20dd682279 |
|
BLAKE2b-256 | bb977f4718f4654c06e933865e34a6c7e0127b9c3adcdb88c426371f68d91400 |
Hashes for stim-1.13.dev1700353273-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c9fe2ac5b0d9bbf61544e55f1a9b03c9fb5109d05dd5399400b72f74b7a3619 |
|
MD5 | 958d3bd8b343cc654f56a93f1ce4a345 |
|
BLAKE2b-256 | 209c2148e3918ed3d1ceb74d072802c75aac69668d15394bc02aaf07df9c783c |
Hashes for stim-1.13.dev1700353273-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63fc100480fba7162c71e36b1d11cdacb971cf52ffbf4078105f0ea882e02fe7 |
|
MD5 | 640d5825d808863217eb6b6604b9c720 |
|
BLAKE2b-256 | b81115e88f2e7775b29e27b0a67cd99d2706e20de424773c58502a662c1e02be |
Hashes for stim-1.13.dev1700353273-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f834c1622b50df096968d72fe71791c5e99ebcdb5e2a30b6fa33d7a1b35035ae |
|
MD5 | 7f96370e907ec03468198af7170e251e |
|
BLAKE2b-256 | 33c42e206d57266563fda60b7d6c687fbc9b59674dd025cf1252fc011db05c01 |
Hashes for stim-1.13.dev1700353273-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a35f1abf84cb1870aff5d94c792ef7ddd48a39159b18cdcff1a7e65f31ae5415 |
|
MD5 | 30f73b6976e24df407a3de9e71fa7983 |
|
BLAKE2b-256 | 605ebf6f44ba0d4e716261653357484c3e4036ce5540125388a40dfe911316c4 |
Hashes for stim-1.13.dev1700353273-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f42b8b3d0d0b11cb0689c47d94e326627ef51fa8eb7d22bf651c1ad3c316456 |
|
MD5 | ece6185aff71af5eb008c2b451754699 |
|
BLAKE2b-256 | 72ab26be994948eabb2f21a88dd298b10d9a1bc4e75ada117f8eebab52784b89 |
Hashes for stim-1.13.dev1700353273-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d4fee03b095b2b219f4555bde180e54766ddf613188c52fd930e5b8308303c9 |
|
MD5 | 598ab838a595ac8f995b62df1c33cf09 |
|
BLAKE2b-256 | a618027b62fa7dce82c27e32cccd92dceb5ee3e6c99364d933f118a0d7a94f0b |
Hashes for stim-1.13.dev1700353273-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35b4ffe4575d24c3914e0cfbf1f95a921b07b928460e8f1130a5584bb67959b6 |
|
MD5 | 0af1598367092de004d57608d59c1e4b |
|
BLAKE2b-256 | e69af8e9a3b67c3c9e4454c80c26b3df4a21a0dd67ad2b749be31c12818ce496 |
Hashes for stim-1.13.dev1700353273-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e9b609343fe8066af358242ba7a36c2f6686145300df5540c2254974019eed5 |
|
MD5 | e6e12523d57221d13aa26f85ad534fe1 |
|
BLAKE2b-256 | 72a9be5499ed106995142659f62db384fb1e5a2b08b76c72c5354780349b7095 |
Hashes for stim-1.13.dev1700353273-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e549cb52043591c88d8aa287d8ea98a6a70cb74d15254b736ff0830eac237ac |
|
MD5 | f9209e0973c51c1908a072b1e705482d |
|
BLAKE2b-256 | d4d03d9c865362242202d4f7d43ac22080c36010bffa6d93f459592085a0b4aa |
Hashes for stim-1.13.dev1700353273-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56da41412411aae8334e99b45ab9c9b1484e8fe83ce0d20ebd5d9d01f93a6a10 |
|
MD5 | 00b1de547ae9895833fa8d4d43efd779 |
|
BLAKE2b-256 | 1097eb125c648adc7df0638cd7902f06fdf2b642d37123378eba6ce6b63ba754 |
Hashes for stim-1.13.dev1700353273-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85cadd377529fe3a10293f4a725d65ec803bee5eca7bb0782a63796040a17978 |
|
MD5 | 378f3615bb6b396eaf5fc2b0c9012068 |
|
BLAKE2b-256 | 4507c37b7f4e7eed0df924ba01d76ae5b0e7ebb308c828b56c2d552dca916d7a |
Hashes for stim-1.13.dev1700353273-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0907cd7bf54e92a0108a781225e4a3542bb52e89ffbb2a165b6387c80aeaba0c |
|
MD5 | dda59a9b52fc00de66c8bcb9905dff69 |
|
BLAKE2b-256 | a67024e07ce73e1034da75317b21362ae49a04590510d0d7c479262595f5ea81 |
Hashes for stim-1.13.dev1700353273-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4af5bebac902380e58618b10ae98b3316beb0b8507081fc922e3c96c022e3cd |
|
MD5 | 36cd5ad459dbbb17726c62fbb109630c |
|
BLAKE2b-256 | c2866ac0dde1a347a22f21f30bd583787797bbb65466f5cd6cfc8a0141546491 |
Hashes for stim-1.13.dev1700353273-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f5ecf9bb3c590fdbb705434603974ddf9cf9a0146ca7b1a751163a07b46d062 |
|
MD5 | deb5b5b377795bebcf5e855b23a2872b |
|
BLAKE2b-256 | 3dc964f29426f5c62b0ba3014c8570da99b7d22dc9e40cd7f60090d287b20813 |
Hashes for stim-1.13.dev1700353273-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9a6c66b9e784cc58f2ecd8916d3f9a9282341e0caaae235b377634d2c156bc7 |
|
MD5 | f510382b896a01f1612be8567f1af408 |
|
BLAKE2b-256 | 05a8e10e7bde20b2ce83b373b3bab63b1da73b3350d06154e66dd376029474b1 |
Hashes for stim-1.13.dev1700353273-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da77d639a3bdcbb38ef718b4c76c76e0a585d7e4221351cf333cdf78f2217594 |
|
MD5 | 76f49d8c810a95448db140e9660216de |
|
BLAKE2b-256 | 12ff4f4af20a645fa0c424dbcaf34955f747facc9ffd6f2cb198475ba6ed5061 |
Hashes for stim-1.13.dev1700353273-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34e3d0ff8e03bdca96f048c5502481340d7a686c523760e48589b3345cee1c86 |
|
MD5 | a57fa29e619621a0f782b39d75b4ff63 |
|
BLAKE2b-256 | 593ad5c92309e6cdb09a6c0f6a48f7e6d24e8f3db2868e234ae6ec031b013220 |
Hashes for stim-1.13.dev1700353273-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4383ca13c41f6d7d8f634d82e1e99af986f8ab62a2a6cb8100dd86ffab68c43b |
|
MD5 | 19037d347d89937c86f05d359766ec81 |
|
BLAKE2b-256 | 09d4c43c2ae023494a9d3b6c788247d55a6c9be1901fd2d082954adedecd8449 |
Hashes for stim-1.13.dev1700353273-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a68a5e024923b570f54313596f7fa9628f673915fb043876615f8d0bb18b75e |
|
MD5 | f4129e58feb38de74c92d27649fa7fd2 |
|
BLAKE2b-256 | d7026631a466684779269c43581eaf0c7895b23313711afdecf51187aafc9c2a |
Hashes for stim-1.13.dev1700353273-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538cd7ffed977f95ee5816023e9a82e354de0000526f91f93dc9ca8f80ba2de2 |
|
MD5 | e624649d689d171dfb9da049cc783725 |
|
BLAKE2b-256 | f61476e6e2d09646b70bf070aaff12c030cf5717bf84bb33f90843845f2914a0 |
Hashes for stim-1.13.dev1700353273-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 250f6dc36f478337c7db4865e4b48cd2606db2a35d3f1b995da16a6be15d4292 |
|
MD5 | 86f640eb95df312fb1051a64a8b96f4a |
|
BLAKE2b-256 | 603525e3fe712f357a17b2b2448394936cf5fc333d18be9086f8452d7b92953f |
Hashes for stim-1.13.dev1700353273-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed309aed27cacbed59a104501b921599e6b2023a9ede2ca1e3bceb0f43c68352 |
|
MD5 | c8f2771c96018ec77ac095cc71a3bf15 |
|
BLAKE2b-256 | 8699f134da255e2d8aa0d2a52cf00671e474a8dac46e90cb3668a65acb3b21cc |
Hashes for stim-1.13.dev1700353273-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f69e1481e97939b1d27f4f62e854657106f95517dbf403dc6f862ed3f40cb619 |
|
MD5 | c7cc48958614259f023a2b94bf116812 |
|
BLAKE2b-256 | 5ab0d2188308d206cee93aa025796c32dad6576368b72c35879949c86790339e |
Hashes for stim-1.13.dev1700353273-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d0240dd0a2c57b32824541ea5468811df542330e2e4fdb631dc77ff37bc22f8 |
|
MD5 | 04e14c562169bbfeefc8512dbbdc9daa |
|
BLAKE2b-256 | e7c48fdb9960b9e22c3b5e3733efd5b0b2d5ba806e975572957c051976c35ccc |
Hashes for stim-1.13.dev1700353273-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebcffab94a1d94a72c64354ff4e568b5caa05b9c533b94ad58dd6cb13bed70d |
|
MD5 | b9ec3f191f0c3764b324dceda1667a81 |
|
BLAKE2b-256 | b6026c81798a540ad44a4b1908dfe9ed2645f9b01e78d3e9bc9282a114f4066b |
Hashes for stim-1.13.dev1700353273-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93e121dead051aea7dcd9ef0d0ab80ad8cb9e53417d15b29955e0f1fe250f55a |
|
MD5 | 122e2d26889935eb5708a9f9a0035809 |
|
BLAKE2b-256 | 9596f529929b6c4bb71d1952489f2afca66afb891fee9c4ecaf80668bcd31025 |
Hashes for stim-1.13.dev1700353273-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f331af7848d10c4a0afa55e5b3bd7c2f243158a4d26b1d1551d09803e0cd9d9 |
|
MD5 | 670081e7f9c31b54e919dd651b80cd74 |
|
BLAKE2b-256 | db927aae55a9ba74c0b7ac4e9e599199519bcf224f0c9fbb69b6a27723a8a660 |
Hashes for stim-1.13.dev1700353273-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50ebade1b0ba50cd01821319060fafeda6caac2a6a2b87f987f28f619d492a1c |
|
MD5 | ba26252e4546fa5e2942a3ce76a00f14 |
|
BLAKE2b-256 | 65ad0052545b2143c66f280eeb0e81108faa87cf40de4263be9826e2d6956ffb |
Hashes for stim-1.13.dev1700353273-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9d57a92cd39772ffb7dfde01e2b1994077d2a981d5e56e1365947989c02f3b5 |
|
MD5 | 4b59ea5b24c5307ed3060ae22a6ffd26 |
|
BLAKE2b-256 | 2909c08b1a29eab4bd9901173caabdf9f505b0c3766394722a8f2ca6e48ed0a2 |