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.dev1701377008-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1279e6b1577e798fb177f7102e70b472d48be33ff0c7ac6d72bdab107d3260bf |
|
MD5 | d18bbf36650811e92305981e9a7ae77a |
|
BLAKE2b-256 | 97badaf3dd9bd509ef52cfd82d06e997edd27038bfa2110072e9a98cc3f9ad5e |
Hashes for stim-1.13.dev1701377008-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b448964937e9a5c07e0b2e91dbe3f62e06017929de85661c3cb21c88b50c2173 |
|
MD5 | 7233a2745ae49e81d7d54f5af0adf8e4 |
|
BLAKE2b-256 | e7b8d5682784f4f02e0d48a8baf8660c62bef561eaed2f1f86bb3418b5ae5f08 |
Hashes for stim-1.13.dev1701377008-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2932673feca85b5be787c9f7ee69ee7a131ecf67dcd56da5e2c4206e021fb0 |
|
MD5 | 96674661c7ca0858ddc7b5f8670a9dca |
|
BLAKE2b-256 | 24fc8f6ee516eff9bc16908b6c061fc029b712d60a3844bb900a47fd7c5153f1 |
Hashes for stim-1.13.dev1701377008-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f1cfa7ef722f6746722b2ceccda3edb2311a4b500f06d91ba1ecf99fe9df288 |
|
MD5 | 2fd5ed756a5300bc40f66891513070ce |
|
BLAKE2b-256 | dd5ef234e64b9b96da5fe6ae9fcbe549e7e88df1d35820224ed5da3b05ac13f0 |
Hashes for stim-1.13.dev1701377008-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07a0c6c68f59514318d89f4a98fa1f19a375661324cc1b469786d695f8809a72 |
|
MD5 | 29e5a95ac1868bdd9d0d927d23a4c69f |
|
BLAKE2b-256 | 5bcfdc38c78a078384ef364ef8de81d61140ee53031d5c8a05c64c0f91e5f764 |
Hashes for stim-1.13.dev1701377008-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0e8f2dc9a8d39398ad9614bb96f8dfbacbe14414bef3fbfb9e1c59af4d1dbdc |
|
MD5 | 1b406303bb63ced49bacf678337459aa |
|
BLAKE2b-256 | 7a7f46ebda02784b33f4dacbf8a2336e75e64dbe52421d3422dbda6a34686312 |
Hashes for stim-1.13.dev1701377008-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d5184aef2fc46684aed9c328f21ec752d8e7521b5a2c8a401fbc0666bb81c40 |
|
MD5 | ebc46962f61b6d91eccd8cb736ae06ba |
|
BLAKE2b-256 | f5665372a479f4a77a2b385e3ec7bbffd941434ff5b8eb53a412541da8292efb |
Hashes for stim-1.13.dev1701377008-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ead6327e6269bc5ff4a9193a76a8a2e790ab504eb930bfa66d7296363e94a730 |
|
MD5 | 0e856e51c688dbdac64e26d54ceaeeaa |
|
BLAKE2b-256 | 0afc528cc0962bd2b41ad829ee97b743438d3abed77d488ddb1bc77dcc76ef69 |
Hashes for stim-1.13.dev1701377008-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d1f773eaa9ace1d47cdf0516e1dedfb7d3e2f8242785c221cfb43c46bf1abb3 |
|
MD5 | 0e9d85e1ba22fc3c0e413f9ce4386d24 |
|
BLAKE2b-256 | 7feffb6d22cb46a0abfd9eca282a3fb659f071c46be82c1f3079f1522b7b8e08 |
Hashes for stim-1.13.dev1701377008-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11dae6de51b0aacc8c62ef0e0c21e6df0f6881708fcdd81567f9ad54a853cec8 |
|
MD5 | 93a12bd442fc9ce3e77430bd7b53aa3c |
|
BLAKE2b-256 | a6bc1a83da6fbce5eaae6fc0b365bcc0f6f75d06856978d3cda781a9f2b327a9 |
Hashes for stim-1.13.dev1701377008-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9836b924ab0045b3c088507a1b7f2cbb88c1859453b7f775368403d5d4abf10a |
|
MD5 | a3ca083037d9f1b9abebdd7c9c7c3cf3 |
|
BLAKE2b-256 | ebef83717454bd84635f81c12d7ef18d94dc8d8037a07dd4060399de420020b8 |
Hashes for stim-1.13.dev1701377008-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4170ba76734eb5b61908852b15a7f171b921c8b2fa5c439118475afcc818086 |
|
MD5 | 9a67142191c3e54c581cf594b045e12b |
|
BLAKE2b-256 | a076bef81d80c82a4eff819e1b85e1882081138af886e66e712e2b0c0551f431 |
Hashes for stim-1.13.dev1701377008-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cd33c634733ad2831f4bb9ebdebd1643895fe6f42b62a6c8cd8ff7b9cff45c7 |
|
MD5 | 95a01b08f02f7603225d452ab7930ea9 |
|
BLAKE2b-256 | dc42a48cab05030bdf81e2ff8ca3a16f79312c6a43b47eb7425cfed2e3e1a8e3 |
Hashes for stim-1.13.dev1701377008-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d4bf7a147c5e4ba8745abe0807fb57d4150ca43b8e9ce36f7c2cab83315fce |
|
MD5 | 5831615e494d481a26ab048ea76920ed |
|
BLAKE2b-256 | e2b625dc099eae2af6e56cd4fc39a04e0325218f00a88214561805f3cea9762a |
Hashes for stim-1.13.dev1701377008-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89ccea02163641c06981d89303b90905f8bd323a6c90412a4f8f99b90b0db209 |
|
MD5 | e5541a612d986ad338a25c89ed1c85d6 |
|
BLAKE2b-256 | 24c7e7d52991e8b76a260a351ff44a19bae3af28d3549b400f1881abb5ad85be |
Hashes for stim-1.13.dev1701377008-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66991e883872358f47c02970cacb49a53945a4a0040a563d2aef5cb65bf00974 |
|
MD5 | 75c38db2966ccf536d0144be5baedc2b |
|
BLAKE2b-256 | 58817f7210e271c26645c441163052ebac8ed5d8a04e056ba9c610c34d284121 |
Hashes for stim-1.13.dev1701377008-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0271bffcb9b2b8da26fc50a44d27853352ee5df4fae4dcc74a29b2c93ecf33e |
|
MD5 | f535deeaec38bb985b16e70e10fe5a03 |
|
BLAKE2b-256 | d3402c298a82217c9b7cf185eebce3e517071d259a02989940b4fcec305efb81 |
Hashes for stim-1.13.dev1701377008-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 630f1fd8c673d02c74d1045742088030b66b05e8225152bdda9e2988507c1d86 |
|
MD5 | bda17df03bb93b09c99029c8dcd6d4ef |
|
BLAKE2b-256 | 967a236364dcf3ee3caa8e7a00126b98467c2053bf4cf9f0f432dc250fd570a7 |
Hashes for stim-1.13.dev1701377008-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 170daa0d6ed853eb7efcedbea5cdef889e080c52b5704686a4a8e9ae4d2cbeb1 |
|
MD5 | d1d4338655893ff9499c8fb82d4454ab |
|
BLAKE2b-256 | 03db628efececf53c327c12d02b8b57a04e4ccccd7ab6896dce2e27f2ebb84cb |
Hashes for stim-1.13.dev1701377008-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 185a40d7b5c847d5d4a304bb4e7346dba63854f385bf3d44ed7d27c952df4035 |
|
MD5 | 982de8aa1e2d42989fa2daf8faa0d1b9 |
|
BLAKE2b-256 | 6252a4b7612a680be24c61b258b29f2ae19c7a81663516ccb60071fcbaa473ca |
Hashes for stim-1.13.dev1701377008-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816005aefe5d1fe68669fb50616ba110a1dcf68a6a7d5aaa191e3e81a510be7e |
|
MD5 | 30e93f0d0ebcf45c5549893cecb61c1b |
|
BLAKE2b-256 | 7fe29f47cb57bbc0e595e08536285d227e78e2333b5fc2cbf5057210c848bb49 |
Hashes for stim-1.13.dev1701377008-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a10b3ea47c5192353e47fd0d8c5e4bb900aece31a25f5143d8de016579077b2e |
|
MD5 | 4ffded2750d904d435f9f201da991a84 |
|
BLAKE2b-256 | 9484664420bf7ab6aef4a16dc5df5b7a768850c75537eb072ecb0429ecb998ad |
Hashes for stim-1.13.dev1701377008-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3991058e48e29c2343085f8aca68146593296d3ec3f0bd353d76105c1e845286 |
|
MD5 | 2850f99b3380d4e00c320dd3edf0afa8 |
|
BLAKE2b-256 | 33a089129e65440ae4037e1fdf2eb246b7c343d2b317c033d1e6e7ad6deb9c60 |
Hashes for stim-1.13.dev1701377008-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd9e438c1f9f9eb8759c69d1594e7c271b957adda10fe7b1db444f3cf33c133c |
|
MD5 | 62a2c88dbc1ced076b2877fcf641c2db |
|
BLAKE2b-256 | a43604bb4bdfd01cd3add455b46e585cfe70c0f7bcc7a31f17db451c7735a671 |
Hashes for stim-1.13.dev1701377008-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461d280ef415776bfde0846db50b11e7ab2dc69b7291bbdef38f039a5926a763 |
|
MD5 | 33d3007b7e00f3fc2a96757e3a4809a9 |
|
BLAKE2b-256 | 85c054d5ee12cb16a6a065684c984b915b6ada7ad7c2cf9cf4d2f2d27cd8304f |
Hashes for stim-1.13.dev1701377008-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41978d9d68797ec2e0cdd48b6d4428494f62ffda5ec013b38346833c9f80bcbc |
|
MD5 | 4236316c29014c7d4aa3bfa1167c9d24 |
|
BLAKE2b-256 | 081c89c093dc7132ebd543d4b1359fdedf828f283f1bd96b7a816b2b85c81714 |
Hashes for stim-1.13.dev1701377008-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc52f48b571a107219a5345cf43d7a9f90113b05ad20241fa7b51f513a53d9d |
|
MD5 | d3aa9f39c99159d8d4c306209bb175bb |
|
BLAKE2b-256 | f1a54990be0a742d1c3dfd4ded51c5bdf48ff1b0a4b66999e02969eb43dbd8f5 |
Hashes for stim-1.13.dev1701377008-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 907ae8efa9b73cdd4550c0024989a99e718b36374034c88dcc0c20a91d93bc11 |
|
MD5 | f75855bf614287688a42666a99dfd364 |
|
BLAKE2b-256 | 53ac418cdc1564eaf9d4a93a630e7ae98e2251b358674488974ff18de993d7d1 |
Hashes for stim-1.13.dev1701377008-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbe3f2e96fea2912fcc1a74a7425f290555142782e8db228da8ccc2fffad4ab9 |
|
MD5 | 5deaab13dbdf1eb80d74d036195e344a |
|
BLAKE2b-256 | 77c167731a5a313759d0fdcdaacc2fd0291bbeed15496be6c303444c44346b2b |
Hashes for stim-1.13.dev1701377008-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ff4d1d14fcb5adcd50309112e900aa10ca70a4495d94223b42b416a05b1ccd7 |
|
MD5 | 9af3334d5d2bacab84a8b49834190472 |
|
BLAKE2b-256 | 6242471d594cfea732cce179dd930368e2894483d0908d844733b90876e8f072 |