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.dev1701144542-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7002fa46d07d93ba713291404c33ef0be9304a151078767320d038175b1f2557 |
|
MD5 | f978e9bafeefb690a68f3d1c4b93742d |
|
BLAKE2b-256 | e6d4defa31361aebf63f441b2a0e9b656261cfedb2ad2887d9ae6b16cbf1c4f2 |
Hashes for stim-1.13.dev1701144542-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be5eeb3e3bffac48751b981369e79b4e3948d1b7cfe2eb988dafda7aae21505d |
|
MD5 | 6795afcfeb88fc8afecc140383f0c240 |
|
BLAKE2b-256 | 33cb6c023b90c187d08dda60345f598590ddb424863723824b76f1cc05c6ae28 |
Hashes for stim-1.13.dev1701144542-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 504a618ebd3451f3e9cbbf0a99d2a1fc634deb61faee2ba29bb7dd81ead82453 |
|
MD5 | 88af589eee4096f8dc88263e09baef1a |
|
BLAKE2b-256 | 5e458a12ea8af5bdc3f0ab4e7c5786f00525e0f213c55a8188e3805fa3ad8497 |
Hashes for stim-1.13.dev1701144542-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4152210a4bdf1e8a7689fd7fc8082a404d8b5ddf80f1222cb2897073fe11507 |
|
MD5 | f3dcb892e541ab61318b75ffb5a389b1 |
|
BLAKE2b-256 | d4473c865e2427ef9ea8af1fe06992c4d7d99fb5dce1ce4b6b24700e9a93b9b5 |
Hashes for stim-1.13.dev1701144542-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88764c4f1d2fbb0939ec5ba05ae0e028acda6b6c91a0826505d3eca5038ac3a1 |
|
MD5 | 7e5a91460df16926577046acc6c806e0 |
|
BLAKE2b-256 | a22bfaffe95e4d14fafa925201a672ff0ddc89d36047490c365fa690aa7ed9c4 |
Hashes for stim-1.13.dev1701144542-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83378fc3e617ca6f1fc071c6abe57ea1b659580eecc6fc9667811129502ff0e3 |
|
MD5 | 7a20e9198d2ed96a3a510ad9dbf30be8 |
|
BLAKE2b-256 | 3faaa13ee21d1f9d813ae9609c9e8b32145c5a20b462cfd8726659938f3833e4 |
Hashes for stim-1.13.dev1701144542-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b237fa7c971cb8df0ebca5a7a6d190caf7ac58ed9526cfe95d8bf629513379b |
|
MD5 | 95a31dc15d656b61e271e365575e4a35 |
|
BLAKE2b-256 | 8019a77e79cb2215c9428866aef402706fb115776e8211f8373f65e7bdf2cf7e |
Hashes for stim-1.13.dev1701144542-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a4ea86e6a29801303b4fc41ad239774cb4fe04aee0187a4ea65e2b080d2cfe4 |
|
MD5 | 8e59fc3c7d01638afeb6411b680eb595 |
|
BLAKE2b-256 | 5760469d2a3ea8e44db258ca30b5f6abbbedd70b9552dc25f180050083ffdebd |
Hashes for stim-1.13.dev1701144542-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61476f6b79026dc2c78109ba4a763e8296916583b427e9f753b591014d5b298c |
|
MD5 | adf7a1dd82ada27906f2d3e3211ec5fd |
|
BLAKE2b-256 | 03503d683488dcf4710bfa58d7d2d08d56c1b41e71651426c8e91e7aaa45e061 |
Hashes for stim-1.13.dev1701144542-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 154467dcd206203d9b32ddba44ead4e4c5ca74537031d7c95a7b0b71929944a7 |
|
MD5 | 7e17799e0c89334ac209272240cbe12e |
|
BLAKE2b-256 | 755d9dd4240bcdf4bb5859c0a7ea57fcf534f623ea804454bada2837a929e2a2 |
Hashes for stim-1.13.dev1701144542-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2368b16f4af1a9a0a0925b90f0cab06de62b755e11229313e4b11b18369f1700 |
|
MD5 | 11722fd5603830f3f65d12d5a9f00c5b |
|
BLAKE2b-256 | ad9f5532f3c48d1e8dc463e66b6d4c31cbe1da93aa49ab6be398d037c2cb2f98 |
Hashes for stim-1.13.dev1701144542-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c374c846d0a1c9b9e43737be0e2b5bf6ea3c2288622b4eb3817525954d89905 |
|
MD5 | 6ed89900099c44ddd0306097622267b8 |
|
BLAKE2b-256 | f66f0a3806fa3e99ed3aea12ce5a4ca561629b6ee40fb37a97c02be621eb3e9d |
Hashes for stim-1.13.dev1701144542-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a03b8610ffdbc55eba60e9fcae50fca4c00ed76a4fe44586cc922c20126b4a4 |
|
MD5 | 0ae9dee76ecada7066d32e95178d9dae |
|
BLAKE2b-256 | 13752960aa3a2589edaddf77003b829dfc587e6f95a13d57d19ab43ec86c0bc3 |
Hashes for stim-1.13.dev1701144542-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3e823c552425fafad53806e49182ee015a294223ddddca78741268028140f0a |
|
MD5 | 61417bd9e9651d2cedece25ccd56024a |
|
BLAKE2b-256 | 0a5f60d186755fa148b37aa23e660fd5f6c13fab33d9bcd0ca1ed5f8e9670f78 |
Hashes for stim-1.13.dev1701144542-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df30c28ad49e0efdf42f1d52b2c533f887c19e63a94805ce21a2d75588167bd8 |
|
MD5 | fa2b0d80a900bc0b7bc161f265fb98d9 |
|
BLAKE2b-256 | ffa4c1f5c3809eb4b391f7945b43aa78bae6eeed6b1cf01f8b35563945e9027c |
Hashes for stim-1.13.dev1701144542-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6f68ef8b07bd6ca09daa8b1f3df12325822663762aa90c9b982cd6cc5cb19c8 |
|
MD5 | 8b488ffdbea395a6a9ec2fe178193e9f |
|
BLAKE2b-256 | 3cdbd53653b0fdf186fe8dcc792418e4f520f830e60784ff76043b414162dfc5 |
Hashes for stim-1.13.dev1701144542-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aefa8fcdb57a366d0fdfcfcdfa9737861bc4ab586445c131db9780a6e558af8 |
|
MD5 | 655fddee1b3df8eb694a8bb2ed5a93bf |
|
BLAKE2b-256 | 52014c34c459e67669fe5b6273eff17e3dfcc084640541438d538a7487917055 |
Hashes for stim-1.13.dev1701144542-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04aa2c470378ed8e8b3942d927cb3e72b41d8b79232c42c076a51bad277d51d2 |
|
MD5 | e9461043b4a5a8abfd0cb01bb9fd4d86 |
|
BLAKE2b-256 | 50eb06c7b8eb88798d1326d46246b0f9ee20791d9c91d9260d98bb12102cea29 |
Hashes for stim-1.13.dev1701144542-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 497c93ce4ab1ceff2cc92a095eddc09c97221edcbd21c083a61581abc775f68b |
|
MD5 | 15fc078e98c9cb44f10d6fc7d209c5d3 |
|
BLAKE2b-256 | e82199826937bd58a7891cdd0f1020b91deb747d750363882cc11e170fa57f6d |
Hashes for stim-1.13.dev1701144542-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | becfa68625a7c27fd470d5976ec68b0896ec242de117f7590c7f120faa707af4 |
|
MD5 | 3a08d50e989f9715455d660cf9f959e4 |
|
BLAKE2b-256 | 0a5b8e93bc875116aa3191bd445630b0abd4fa406285e1b88e86aebf639c01c6 |
Hashes for stim-1.13.dev1701144542-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7af7b11060011cf9ee010e0a2081fec8c5b1b9a6caa52f054f5f5dfba19272d |
|
MD5 | 88f4c499ad97534efe43439cd27cb0a0 |
|
BLAKE2b-256 | f63f8edd74107fc0050091820fb584e1de1b5b17694aff1eac6e9aba30b82cf4 |
Hashes for stim-1.13.dev1701144542-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5454e54676c09365ec14d00d00cc47c3bdc24b277f8b13aa724b301d7b5e912d |
|
MD5 | 6e3fd06ad4c0ac9df0e045a76073c881 |
|
BLAKE2b-256 | 4a202e24ea1ac163cbf620c4f634b0dcfb0417d7694d858987f4a6586f9e47c2 |
Hashes for stim-1.13.dev1701144542-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fde1640c6b9809ae05ab614dac57949df46b7d4d6a379d726c657d25640c7c3b |
|
MD5 | 038997ac50b86a6473cec86951bcd472 |
|
BLAKE2b-256 | 0cb1d41aec4066b17f4d90ad5a6b4da7ef70ca6b4919f729679b9dc5b99eedda |
Hashes for stim-1.13.dev1701144542-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e35321b8136ee3fb3deeb41dfec6f2a55d26f4566cd4b7338999a6b5e95b5a3a |
|
MD5 | 5529474ff10b2ea0c8690967fb0ee702 |
|
BLAKE2b-256 | 26d49845b858d498aee291d5ad540306873d274418c472912d4e40ff9e7c63ae |
Hashes for stim-1.13.dev1701144542-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48088f314f47ea51a621fdbf60436ef4a56b1ed960999d2f63243737ce0beeb4 |
|
MD5 | 95c603cdb2992f33e84c5e1d4d9882f4 |
|
BLAKE2b-256 | 667e130aa50272d63347116ab75e1e78824277a4ca02f4580523c9adcf3b55a7 |
Hashes for stim-1.13.dev1701144542-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e17b6f485dab2464fb11cc5b6ee7ae59b1fa2d15e285664a7000bdb447e3f79d |
|
MD5 | bffea612cda6498c58f622ea147550c1 |
|
BLAKE2b-256 | 30923bbde9b04ab0955f8443f9f1bfebaec1734685f2436d514152c36c294ff5 |
Hashes for stim-1.13.dev1701144542-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4bcd2f35bad05a209d66cd654c10954c9b646b291152e5ea4c33117b23dabd5 |
|
MD5 | bf675ae3bfb2d79d2844efcb0e02fe30 |
|
BLAKE2b-256 | aa483e1afdf37bcd713738273381386e9b72f3578dafc0b7803da2dabbc7c34b |
Hashes for stim-1.13.dev1701144542-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d8f1ffbe05db06d95c87d3a26ccaf5c0611087926b849130d36370d3bbe425 |
|
MD5 | 14d47236a43d04d84b68b24e6b4ed3f9 |
|
BLAKE2b-256 | 1fc6683be50a8606a0cb1d65d2722fce21940250f7f32dea0f59a0d1c6cd9f73 |
Hashes for stim-1.13.dev1701144542-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fa7c3a7e8041e91e92861ca488e7840e49f30ed57e06fa0507887577148515c |
|
MD5 | 44489a7bc68371b5109a073b0b18345e |
|
BLAKE2b-256 | 0425dce42f37dbf68b803f5e4ac540f659bcfd87e3813de4573243540a055bc4 |
Hashes for stim-1.13.dev1701144542-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed60092d2499f5881e40fad3cea0c65d1fa1ab2c0a8d23072de976d96edf182d |
|
MD5 | 183414aaad3db10bb69bdaec2d41f2e6 |
|
BLAKE2b-256 | 71720277b9ab95f68061b6fc2d14c49a45c51cb30ea59c6dcd8e34978c6777c7 |