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.dev1687239457-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7b4e8a8f10b4faea5a63c5c179df55253a96013c7bcbd322bb103b9513baee4 |
|
MD5 | 253cd7f1b672b18a4c45ab93d392ae4c |
|
BLAKE2b-256 | abe26e5fc73d9462438d8498d9b1e3a08dc4699189fe2262ea92bc8cc99aff4a |
Hashes for stim-1.12.dev1687239457-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ed6f39173d01d960ff6c725f15cd47ca62799a15c1575f70b17e6a0cabdee8 |
|
MD5 | 1a6294a7aebe8f1d0499d1ed38ea1156 |
|
BLAKE2b-256 | 26ab3feb3616473cd63d7914eaaded017c16388cf33a07c55a25ef1fa6411314 |
Hashes for stim-1.12.dev1687239457-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05b1a5c0b75d30d729f49b113dfb5376c9c74ea77736121a891edb968d78afb2 |
|
MD5 | 15766975149446d6d8d5b49fcd1d265c |
|
BLAKE2b-256 | 6f9c52485b3bc8257778fad626714ff8dd185e5d3bdaeb986a69f3629fe034af |
Hashes for stim-1.12.dev1687239457-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ed78d6161de141e65896a9235cb6f7362c5fdd4ec319fe26eb99887d61101be |
|
MD5 | c56b0d84d64839ed37de472ab403aef8 |
|
BLAKE2b-256 | b3f436f74c6550b47b284fcdd92091d25161aa050293f2334ad20a4cdd8e559a |
Hashes for stim-1.12.dev1687239457-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 403b2ef30890bd8e32e919ad065c7c93d050c22c93d42e28dc55232c3ecda687 |
|
MD5 | fe96805699cae39a533c55c19bcce916 |
|
BLAKE2b-256 | eee83a354bd5cfa59a86fdcf6c3a35d60bd38530ad7dfedddda52d7a63ca8e19 |
Hashes for stim-1.12.dev1687239457-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1cf0dcd8bcb68c91da68776d9801538c360194321ed4d04d6a8bc05d39f353d |
|
MD5 | af2f3291a26f9c250154a7c3cd60ee05 |
|
BLAKE2b-256 | 0858110ac42c0a5ffd7420b86ca83999ea44de92764e191f2d739bec2c311493 |
Hashes for stim-1.12.dev1687239457-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87c91a74647f46a7e4eed508f7b20711bb528972c6bfda418a2369835d6b3a87 |
|
MD5 | 27e2d74ed3d5c2b1bf23f6cb655f5d09 |
|
BLAKE2b-256 | c1a301fefd683808daa9e1af40ddbb0550448224407a2e9a9da0f10cca233005 |
Hashes for stim-1.12.dev1687239457-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2db507ac25ce89ed9c17e37e303ca6620c2aacdfebcd4be323fe4ed1d4d0c74 |
|
MD5 | 7e16629cb51b4093b5762c298df603ae |
|
BLAKE2b-256 | 31fc7ce37d95e68ca896a207d69908df3f7920e303e1acd05ef159452287c948 |
Hashes for stim-1.12.dev1687239457-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7020ac2dbcf1f060f42c7912e015c09badb2c0cbc380b4f333dd65f97a52ba65 |
|
MD5 | a2ac7a2eb6a778a9f996195cbbf07cf3 |
|
BLAKE2b-256 | 75fc2a71712df320239ade824c78be77b47650b5c65da6ce6891b14f811a9b71 |
Hashes for stim-1.12.dev1687239457-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e2802b6cf7b92fae0f68b1ff91ec49557f59a632b2f8b8d7e47f654dc935353 |
|
MD5 | 3635d28226e518673fe027e3f37e754d |
|
BLAKE2b-256 | fd3c794d0eaa30c4f361eea4160e8df1a10fbb8a5467e576a4b1c17817562a70 |
Hashes for stim-1.12.dev1687239457-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f25700d176728f628a98d174203a80b5410f0dd93cd99ecaab880445645364a6 |
|
MD5 | 222a16088f062f052f38f60826f212e9 |
|
BLAKE2b-256 | eb77e981bd1dfb10f219d4142fb8ab12edc800884705a739aaed94912cc124fc |
Hashes for stim-1.12.dev1687239457-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a043e85710049c94b728a6ae1f3dbf1e3a7e7bd3b40b42bd9bc188fcdde4931e |
|
MD5 | 3ba00ddbb2abf53bb23fbeec055406e4 |
|
BLAKE2b-256 | cf235c01b644ef7aca30e679d8412630f2b428c4931b1fd40a61c3f9af230092 |
Hashes for stim-1.12.dev1687239457-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd47d844694baaec9063c9a7f9056b75f32e670d091ca092cb92e6582a4cc53 |
|
MD5 | 34e741075d8248a8aa914bcdcbfa179d |
|
BLAKE2b-256 | 1365a609330a090684f3f7a235745978de46cfc99c651985b5b9f02b39b92b7f |
Hashes for stim-1.12.dev1687239457-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1935c2a55994625d39e9abbe4af200a33e3a6c7f165477b071acf645c9f2cd5 |
|
MD5 | e3b9bceb58cb3724582a384c355f4a7a |
|
BLAKE2b-256 | 8b5b179a0b6411ab95c16040c53e871d45468b70342732795bf5f955f7fc7865 |
Hashes for stim-1.12.dev1687239457-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 311ddeb14e4fd7d020fa15b3720070ff7137bfb037363312cd57bf904408b246 |
|
MD5 | 76a0db8f5bd0e28c9d5cdc340fd4ffe9 |
|
BLAKE2b-256 | 470959066fe629eae586ee96ebb3e312cf4c7456501fee6a75701e2f1761717d |
Hashes for stim-1.12.dev1687239457-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93816152ea7fe2b91b73494b1f2ccf3e5675f264de3dc30890826792857059ca |
|
MD5 | 9b12b13e94bf15f58a1ab0e8ef0ca702 |
|
BLAKE2b-256 | 796abf0b63ecb444e2cb877616366c98bf9ae9d4093c97ee36c92198985dd74f |
Hashes for stim-1.12.dev1687239457-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 173ee91452e68b79c1856b83aafdaa8a4fce06f7354b2483e608384225b15f7b |
|
MD5 | 661d98749fd163f4e0cf3df0b9ad5cfe |
|
BLAKE2b-256 | 1e74943e42158a0002e8ac10669a19b96bb5e17d76781b8f4dcb1a00a0e8ca25 |
Hashes for stim-1.12.dev1687239457-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e152512b59095a6bf38fdc2fb7573a900315a74510d93b058fc78842c0954fdd |
|
MD5 | 6ea8594f033c61608c5736de06364e5a |
|
BLAKE2b-256 | 57a1a80688043df6ab5e53bb52665ba728ddc131cdbd69e4a409b7d5bbb6053e |
Hashes for stim-1.12.dev1687239457-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9210ee3fde85b68feb14549cc7384de2e5dd39542abc218cffa9ecf9a00ad3c |
|
MD5 | 9341f7fd994ebf05ab8dfd7e26dcf1da |
|
BLAKE2b-256 | 0aa7d360b2a2dc278653d294196a8709e98742d12559f58b89f67d6281adae36 |
Hashes for stim-1.12.dev1687239457-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54b2b164b99287ec32dbea63976f19edd0e7035ebb0ca1f432eb8e3cc5f9a29d |
|
MD5 | 3a7dc0cbe82590f6ee8efbedac79e565 |
|
BLAKE2b-256 | d32c90518ebbe2f695016552e9545890862aaa5c2232a947687ee2f81e611538 |
Hashes for stim-1.12.dev1687239457-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 220c1dae9a41d67254a9331b2eb3e7b477a4bbc49d789556b1c8e4075b0a4a80 |
|
MD5 | cdf1d758d734c47a0569faac8f878a0c |
|
BLAKE2b-256 | 546fa2b331c2735230ce8c09e743a3d5f56b665bc5817fbf12f0d75d64887693 |
Hashes for stim-1.12.dev1687239457-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ca86dbe6cfa17ee137cb60fcf91738de873cf9763f5ac8ba79f6feb450b6f82 |
|
MD5 | 378a86d91aeb5afbb74267cf2edb9807 |
|
BLAKE2b-256 | a403e3e970f408dd403bef3546eeb42e4a57c4114de321a7d2e11002f1ffede8 |
Hashes for stim-1.12.dev1687239457-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c20fd00901c78f234ca49b44505fd0629830e23ba82366004e7ef9f9a7e99b |
|
MD5 | e83b1474632e0e158cf72543c3c6d740 |
|
BLAKE2b-256 | d998317ac498dbb04a8a4ac8e127ecfd291b6fcdfa02b15408f2de2854d98436 |
Hashes for stim-1.12.dev1687239457-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ca02913876819562f010f2adb155b08dd9f64c548b4c70edb1b495cba1993a8 |
|
MD5 | 869beb288ede64d532d8fe7a8d5d6d6c |
|
BLAKE2b-256 | b51b8f90ffa30b15030cd2d3115a074c8733059ae0581143605a70eff005ba6a |
Hashes for stim-1.12.dev1687239457-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac40aabd0d49cfdfb8e6b6992c8ae324d8e03f564e7aedad19a0020e3199c14 |
|
MD5 | 22d3a07f2243cd0a40d4239c136176e0 |
|
BLAKE2b-256 | 1f3e826cd24881c0fb03b200110db1878419a3550bcd842f952f712d95acb76f |
Hashes for stim-1.12.dev1687239457-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd9e9dd1b0ddf4b0b7b15886814c1acbfeff301118dab413abac99ffbe2a9ed9 |
|
MD5 | 20486ed9c71058c0409379f94656ca61 |
|
BLAKE2b-256 | a0077058fca9925935f2c50ec1213a40fd6e0b78000b8dc0128101e652dd570a |