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.dev1700351914-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7cab8857154044326948556bedba525e6c98b4a949a2344f62d85acaa41a258 |
|
MD5 | 4e33ae4e50dbb32ff7ccf2ef28069ed0 |
|
BLAKE2b-256 | 4e73ed361e23876460865fb7d724fd5baa269f765428adb3fa9dd6c21213d275 |
Hashes for stim-1.13.dev1700351914-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a76baa1da38a9880d7681c4382f1e0f8bf4210ce1502065144d5057a01d4e584 |
|
MD5 | 649949d1794d6fa169a0c5c9016a770c |
|
BLAKE2b-256 | 83fe93716d537e2f0bf8cccb383a07b096a03532becac45008a48e759de60305 |
Hashes for stim-1.13.dev1700351914-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba71d8a1e4097271a54432f67d4c3229cd01d97a98ac4fcafdc5adfafd1e71ee |
|
MD5 | 1cd8957c4dd7077a246c024a2e58ddc7 |
|
BLAKE2b-256 | 38b2ec67dbc857f0628001acc587b2cecefcdf65616fdbd40ab70d855d44e1fe |
Hashes for stim-1.13.dev1700351914-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e021d60131bc5f33631489c0274253d191f22ac64a82e5c44002144a0835ef1 |
|
MD5 | 7a6286219dbcc689a8cce211296cdb44 |
|
BLAKE2b-256 | 725540cb6a53175ba788388875e2f11b84992a4c079a11a4fea68d783546df9d |
Hashes for stim-1.13.dev1700351914-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2105280876fd2b6595e657f595d41da8f3e6cd5aa2b4a01dbe08b0313778007b |
|
MD5 | 21ce0c135d54b19e1e2cb220c158959f |
|
BLAKE2b-256 | 64db963c8d9eefa2f66627068cecbb0e9038004328476e79de7b36d809905f47 |
Hashes for stim-1.13.dev1700351914-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5cbf551767c809f4a3335bcc961e80060fcb914a3fcd8c47ab9b04b9a6125c6 |
|
MD5 | e10cb66c17d801f108112653367cc030 |
|
BLAKE2b-256 | 2e2d79a382fdd6ace23ac038805b3b80368feeef4ade70a820d19e0a8d5dde6b |
Hashes for stim-1.13.dev1700351914-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a5862b945692f4f1d6b7120997a5b81cccbd8f79329818e97f8216847ff0307 |
|
MD5 | 31cae059786f300a36b8d3dfb12c7fe6 |
|
BLAKE2b-256 | 907f68158a663ec4e0a78f242ae62c945db45c1f22ebcc5b8fe3cf4290bde60d |
Hashes for stim-1.13.dev1700351914-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb87e1c08da75de92f78b106408a6121d99f0e3802932a5f13fd5e5956e23d9 |
|
MD5 | f635bb6d3eaadf726ddfd377c9959d72 |
|
BLAKE2b-256 | c73e1c71d30db0a86b4656d87decd6da6193a85336be0a7a6d3cf4ea8bc7f779 |
Hashes for stim-1.13.dev1700351914-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15018cc000fd3495b0888abd5e4b9ceae30d9e6c666f21de3a612f6fe4acbdc5 |
|
MD5 | 3ede8805686fc463d087ed8df2446cac |
|
BLAKE2b-256 | 1668827c219bd557687e32b0b7c37222c2f6c8b30aaf821baf1d9a491f71e4d3 |
Hashes for stim-1.13.dev1700351914-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed5cb77559b5885e41948f37c345779436e31e804d06331ec90c71dd08c06327 |
|
MD5 | 3294660834e0e0700afb7a40d4123898 |
|
BLAKE2b-256 | 64ebc27ce25043f05e3f33b3e2967161830610bee4cbd5bde26c0e99aa3368c2 |
Hashes for stim-1.13.dev1700351914-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcd0a355e601b39943a654df28db4a882fdb1a71a0e23125f4ebc6734d27c355 |
|
MD5 | 108497530db19799e69d6ece0c28576a |
|
BLAKE2b-256 | 0bf36088bdf6b03995574862ba1b6aed794275131d1f2d625998e0634b23479d |
Hashes for stim-1.13.dev1700351914-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e30abb885834053d0749c3dd0062bef2c38f58e421e542bd4924fcc2b277ff3 |
|
MD5 | 39f4345d929931889f1e410a41e93559 |
|
BLAKE2b-256 | 989810ec83555379fe77cc1007a7901b1a361aeee9eb685a55234920c03a16e3 |
Hashes for stim-1.13.dev1700351914-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d09036f2369d2df49b217163aea5f3c69c32b720b87582ece99d8733c300fd |
|
MD5 | 3338581313c6fd1394f05c6ee4ce3f80 |
|
BLAKE2b-256 | f2c0d7dc37b0899cf546d491901983e7b5885d786aeb842ab61cd71fcf8f84e3 |
Hashes for stim-1.13.dev1700351914-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d73fa6fce8e2596f475ee92fe8272351d65f737869f332626a461e9e7333f1 |
|
MD5 | ffba833f01d15b0fc5a849a4a0fecab1 |
|
BLAKE2b-256 | ac3c18c700968542656b55767f61066ab3e9d533bc54292d69019878c91fc407 |
Hashes for stim-1.13.dev1700351914-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7beb425929f50f6b9c4670d73a2aaf8070ddfd034a24268893f76b897c24b6e0 |
|
MD5 | fbfb9a02e2520c13149db03aad6af5ce |
|
BLAKE2b-256 | e726d0181157aee60bc0f9efa4e4e041ed68db6621b1b6577b9e9e0873a439fb |
Hashes for stim-1.13.dev1700351914-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2545699436d043b0b074cbf385c8278a28be7c5057fc2f5e653567dc9c22cb16 |
|
MD5 | fc99a03dc7f0ff1c2567340581034609 |
|
BLAKE2b-256 | b50fed8523e0d2a97b33b0bcc0973ed23f7f90b300291270a19d2580e98a7039 |
Hashes for stim-1.13.dev1700351914-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3191d4862b0f3a3858e739c0b3124a1828ff21818435e1bfcb03424081b9e54a |
|
MD5 | e50066b08f9d8ff1d479f1dfff418316 |
|
BLAKE2b-256 | b14df1f9bc6de63b93f1fe78532587c417896c5baa8a7e80f32459e7275aa854 |
Hashes for stim-1.13.dev1700351914-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed556d52f0df419a8223751598ad55df9bf00c31e4d58c1b3424dd6271ccec5f |
|
MD5 | 7aee7be80e77d2a860c1e38dad2744d2 |
|
BLAKE2b-256 | c9093a76ede4f7a6fcea05cee07b5ed81ba0c28d601c25f0ac84acc759f6eae5 |
Hashes for stim-1.13.dev1700351914-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096873b1a3aef4d24c0146d3f5d554ee654ad052bda8f94567cf507051e41e8c |
|
MD5 | 222e508eb1844465c2ec692c5b2cc487 |
|
BLAKE2b-256 | 415eb72c59170b8747e516ea34906abe13ab1e81010c9f20cf2a0062c2ffa0c9 |
Hashes for stim-1.13.dev1700351914-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03dbf82d1b4a107913e31a0faa11cb95ca86a117a8ab2f93c069636a1edb7dc0 |
|
MD5 | 3ac166b2638258e26104036471a5b20c |
|
BLAKE2b-256 | a88b0d07b2ca575f14961e968a74b9512a293ea6a3b681ba492a5bf5cb6ec90a |
Hashes for stim-1.13.dev1700351914-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623cdcf59f682662068093e3f10005023924529d259aeab088b451b08e044b56 |
|
MD5 | e4e18725727ffc28b9767eaa18878723 |
|
BLAKE2b-256 | 8b42ffe457c53783fd4e1163f5a5b7af41c0aefc517e186df2c88137f25998e9 |
Hashes for stim-1.13.dev1700351914-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fad8980e00db3a0499031963e206f6c259c78ba41fe268aea7b10e7927b0fea |
|
MD5 | baf6ce302525864be408ed9cdf50d7b7 |
|
BLAKE2b-256 | 7660dd426e12d8d0b01d55e7169b72372d54330bae4917370681843ac126de80 |
Hashes for stim-1.13.dev1700351914-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2cb53b8fdb3f9183d8d2fd40120dbe96a7183b57859ca87427b124b522e891d |
|
MD5 | dd4faffb1b8d7f997356c3c5fb0eb4a1 |
|
BLAKE2b-256 | cbe0b8fa153f4957d944467ef0f8661d19c2b0fd7f87b1f77092250d8fb2f159 |
Hashes for stim-1.13.dev1700351914-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 828cc7cd57836c04ff55f13c842ff0fb01ac0e070c8d0e8e9f893d61d36edade |
|
MD5 | e713edb3e4ec8cafed951c2e42ae58ba |
|
BLAKE2b-256 | 2038593f008fa0881f4bc1c5613a866bddceaeb52150caa09ea3b2a8e4c16f32 |
Hashes for stim-1.13.dev1700351914-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ef9a1c1cc83d360696c697e55e4aa2c803038e9379301de797fb363d638d7f5 |
|
MD5 | c4ba21e08271c94f78eb891249399424 |
|
BLAKE2b-256 | 19a259ed74531723c5a8f8189cca1939af8e69967036855e891161ef804009ea |
Hashes for stim-1.13.dev1700351914-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f68c8ee7e1a76236f19b41d8f3b6bece8aad3bc96fce85a12720fa90a622626e |
|
MD5 | ba57adcd8a060807dd44fc5b9fcde0ae |
|
BLAKE2b-256 | fd9bc3eea010663c1b7748d16586964000802f5bd6ade463c5870e521f8a74ee |
Hashes for stim-1.13.dev1700351914-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aaf6f19f8a41b93c726ac78f77c41504af0e6884134f35ad70cd71876bcfe8c |
|
MD5 | 453b0aeb556b903cfc6a7f4819ca23e3 |
|
BLAKE2b-256 | c65e116c7b4bca6cd208d573c8a47e318a15a9746199f70a2f00e9cc0ccc542f |
Hashes for stim-1.13.dev1700351914-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8d5044abd5b3d8c3b6f91dccf504773b8bd0c41900f527d8fb82eecc103290 |
|
MD5 | c5df5bff6c1889793713db08abe84eb7 |
|
BLAKE2b-256 | 6e236dc98017aa404170bc72a2bd174bb8c1632a93cc2fdf995e28a2235e9dcf |
Hashes for stim-1.13.dev1700351914-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69f7538284fb6054ccdb5d54917f4fa0e2d7d42e6180f1b2cd0b04c7c25ff9d |
|
MD5 | f4aab1a19029c3731398bb66ef19b166 |
|
BLAKE2b-256 | cf4696fb6afc06433f49b3c1ca0c6335cfab26dfa6b87f2701a4b4496a065a36 |
Hashes for stim-1.13.dev1700351914-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e52a86e30601914ca7715648c7b3772e1a26f7c47d188f1fba8aff74f49a0988 |
|
MD5 | 5e27405967bac53a5f61846782c4557b |
|
BLAKE2b-256 | cd31fb0a180f097e128f999a3c3697037d2b86313d2d08d74c2612498eac8802 |