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.dev1708139192-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b3c23a2cee3a875a258eb07d18daaf50a1999351cb45c513cf3b6c4cf8005e |
|
MD5 | a0d80e4ddcaff22fa6cc5866761a7b71 |
|
BLAKE2b-256 | 42d6ae08e02896b1406cfa8945aed0d00d3e5daad9b52d9682d04a044bec6e70 |
Hashes for stim-1.13.dev1708139192-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6676c2a47bbedfde309b699af0b0c559636bf66d200112b2a63ba69fa41e1a3 |
|
MD5 | b83dff23776e0b560446c158e831eb4d |
|
BLAKE2b-256 | db0fbd8f6aea694d67a8fb52a8aedbd4a86e2c8bdadc03c4c4def5165d724de7 |
Hashes for stim-1.13.dev1708139192-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38cdc6c423c593e7c03b42dadd38f9c42becb06941ae0b889a051aeb248cc2fb |
|
MD5 | ac299f7c2712337ddc823e67e70fb9e4 |
|
BLAKE2b-256 | 777c00347109df269c1f5ed5632ce9432ab4391e9ce1edd5bcf5a89d7085bf9c |
Hashes for stim-1.13.dev1708139192-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40bf53f7ec874259d5f645c96310ad818365cd2c08bdd2e28b61d272d4e2d857 |
|
MD5 | 480dce03383ea930b3257764a482cd5e |
|
BLAKE2b-256 | 17582a70e2e1425123a5caf7d3a833af5d6e4ddd2cfe616179ec857ba62b556d |
Hashes for stim-1.13.dev1708139192-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74d8c5e920009769aaf3433417ab0847c181863d45510ad987997b9302680572 |
|
MD5 | 7853e81c4f1130659c9113b9dc86b914 |
|
BLAKE2b-256 | 801bc09efbb1a5307e5565e0368f0441ec536897b474714e150cd0ce21374b0c |
Hashes for stim-1.13.dev1708139192-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 715397bea05dc33800a2fe90713c850b991a8e7d758923f2dee54b006cae9a79 |
|
MD5 | e3197b527b2aec1b21399fdcbcafb4b6 |
|
BLAKE2b-256 | 936704c2f274baefec2351675f6ced30e90d2de78d561c9b561ad87dc431a909 |
Hashes for stim-1.13.dev1708139192-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d939a09ce6ad0a26550f160d95f7e489dd006ce573865d4117319f949e84a3cf |
|
MD5 | 2e3eb547f774f552ad70ebdb0a9ee652 |
|
BLAKE2b-256 | 59ad07ff8e5ed2f45c2cfa068781f674119cbadc7bc0ae9d385bfbb07e23317f |
Hashes for stim-1.13.dev1708139192-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85d641ef8e521f07007a207881f81c74d527e6f5796a304bda9dbb22f19e2216 |
|
MD5 | 951d32f6a098c0e9271d794cfad91885 |
|
BLAKE2b-256 | cdc4347f90100c74254ae5fd9b2321f49de804fa820a5bfb62eb01a0b602e0ab |
Hashes for stim-1.13.dev1708139192-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 891d1ccd39df1b9ee7b3053d6109b3a03827c309c357ced004a781f2d1d77083 |
|
MD5 | a5a132f9cb07d9b8f8749c2cedd3ee55 |
|
BLAKE2b-256 | c1294cbd3f5315358eb843d9c22a0e2bb869b324fbd83be3fa60160829b432c3 |
Hashes for stim-1.13.dev1708139192-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d87929318774964b519f7e8fa4bc162f8834eef6b553872c9289cd39925e73db |
|
MD5 | bb36c33e188914e2d032961eeb09adba |
|
BLAKE2b-256 | 6987d103c7ced4207ccb5b6f9a5e49a55f07b51991a578fc887867efce49869a |
Hashes for stim-1.13.dev1708139192-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4921f5eb71b5fea3089488bef2e7732bd23f86064d92a2697c1bb8aa0efcc2c |
|
MD5 | 966b9e090078023415fefc6dbf44e8e2 |
|
BLAKE2b-256 | 5ab6a986ebedf8645cbbdf44e468597ac2367d11edb2120b921df1c2b3aa4225 |
Hashes for stim-1.13.dev1708139192-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d99cd6a7203cd41e4ad4baaa76c833540a3ea847cafabaa81944fcf044de26a3 |
|
MD5 | f45484d3fbeabc73a3696c96aa0c034a |
|
BLAKE2b-256 | 28edae66a25e67c034a873a627d2986d32c0b1bbd6e145e4dace2c45e2f54bbc |
Hashes for stim-1.13.dev1708139192-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b26bc57599797aecab1cd4db7839e20348ffa755b65d175012bf75b3c4d39674 |
|
MD5 | fd5c8bf348dab48fe49f9687e177f11a |
|
BLAKE2b-256 | 6be668e2b9844a78105cdeae4473b720200b484b0b581740f523a78c6804fe8c |
Hashes for stim-1.13.dev1708139192-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f49d9dc8e0ad01c1782c1730804fe37ecb39d8f1ead061e056f7df07d1e3cf5 |
|
MD5 | 04e36d51c7074e9483a00711130905e0 |
|
BLAKE2b-256 | 7cab7acf4c668412b6588b00880270bd971b4d39a0c8312c1e9de464f1b195dc |
Hashes for stim-1.13.dev1708139192-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf51a56f0bd8d775a63d58dbfb81884510bf8f2e610061d7b3dec2248a669f43 |
|
MD5 | aabca73ae8583b035459a297d6faa413 |
|
BLAKE2b-256 | ff26d8fa546d65151fb07b23bc6db1246d3cddf1661810a1027aa9f4bb8bbbe2 |
Hashes for stim-1.13.dev1708139192-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5b247b75bb7126aa552a86c22d91e93ea857c12cdba4728fd6492d672744cb6 |
|
MD5 | 39a9cd4d5e7c2b242f9e6d3f911d6c42 |
|
BLAKE2b-256 | bc30969c6417f862bac2cd793b4e3d4926c2c9cfb2a6000a544882ce1eac0dac |
Hashes for stim-1.13.dev1708139192-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 934bb4102fb09610e1186715bca90d00370091303f1aa1e2e6b4f3e0b93cc703 |
|
MD5 | a4e26bea42784a0f4abfa9c40500fc83 |
|
BLAKE2b-256 | 934ab682f127c69a6084a429b97a953e37d2d41651c2ac2bcaba04b1b37331ea |
Hashes for stim-1.13.dev1708139192-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26a27e4751fa913a84095a03e062f601ccd0c7fce48e06f7635f47339af55d02 |
|
MD5 | 453033deb5f792e36cad9f1eb87b66f3 |
|
BLAKE2b-256 | b0e3fe0a4b8def2eb83b78e285f109ca9d5707983fc84f0a09f76b062ea7fb78 |
Hashes for stim-1.13.dev1708139192-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0203f440697ae284f9427df57c0ce7a3cedad7ceaa129583f979ef94c6b8efd |
|
MD5 | f563b5b4b3fdadfe9f82827d30837569 |
|
BLAKE2b-256 | 25f96412edf167dc56b20bdfc1258dd4d5de1ded2a72926a5f18abc1947194c8 |
Hashes for stim-1.13.dev1708139192-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1adf4efdb72a6d58e3335840983b2a2b9c9c5d9fe91db9a66be4663c5ef2526 |
|
MD5 | 24d2488e97a72d0901451d1af4ae4901 |
|
BLAKE2b-256 | ad045a641965af89149cb3a540f40e440502e1173ccb250a9a96642f6f0c4954 |
Hashes for stim-1.13.dev1708139192-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65e072d717cf480f87e113a6dd2b6609cf7655eac0d778c66599710b0a6e1a39 |
|
MD5 | edb483406d5b10e656683b7fc3633581 |
|
BLAKE2b-256 | a090789cefa051297c057a7c5c81ce0f36ae55907b03b9f9a9727ecbf0fe6dd6 |
Hashes for stim-1.13.dev1708139192-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d4e0440c47ff9a2801f564f0ff39dd4ac4d40ee0aab710a83dfc04105e66ac4 |
|
MD5 | 8dae0ffbf1effa724b9ab20c34250205 |
|
BLAKE2b-256 | b6e9d029a67e2b0c6f5543786e00c94fcd17ae418abb5ce51a4038533af75b9d |
Hashes for stim-1.13.dev1708139192-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6905376cfd50ebbcffd0deec26b12eaa7011ee6b7fd87829f7b1310ae97437a7 |
|
MD5 | 091df43da137646f388ee5849d9f113e |
|
BLAKE2b-256 | a36073876ee4ef141302fb9ceab55bb672b24f19614a6888c3c01aba61478973 |
Hashes for stim-1.13.dev1708139192-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51e51f6766f29bb345fbabca792fe02609a7e62d16421885f57e5901a6a35a4f |
|
MD5 | 6a8ba53c01e8ce370ab17e56cf5f8413 |
|
BLAKE2b-256 | 84d234564b63de8d88969e4b6aa4fc8c5eb36e8bd13a5b47d461056eb7f72467 |
Hashes for stim-1.13.dev1708139192-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afd7f014ab29c061fd2c90ed138c5ad1b12a0ad25fddecbfdfe3267ff6542423 |
|
MD5 | a2ea6b8d7c4a3f3dee8bebb98faa094a |
|
BLAKE2b-256 | 3582cd63337de3a45436bff14c3709bc60e92e540d8cca05b673f0923d057c04 |
Hashes for stim-1.13.dev1708139192-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f91321e958fc750e184bfde665bf65ad84e6db5d12a4d9d08e0405d6f3e926b |
|
MD5 | 45364701fd7f53dabea588b2004477fd |
|
BLAKE2b-256 | eede0ab677951d6045db83afd316f1bbb9c7f00b83f77160270b96fc8ab03ea9 |
Hashes for stim-1.13.dev1708139192-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29192f6fb69eab94091650a3109b1177f8fb6dd4d367c0c44e28e06528d18afb |
|
MD5 | 0251ca00d6e5818934c94fcc288030e2 |
|
BLAKE2b-256 | 6e1c08a9b8cd413d2050dad58a9dce06d55d7a860754bab73907e833e5fb841e |
Hashes for stim-1.13.dev1708139192-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1338730037813e63f68c5a44b3d95a5a8a68997cae193f760f9370a3f3ef8df7 |
|
MD5 | 9282a04640a49e9316ee8833aea959cd |
|
BLAKE2b-256 | 9362854707deaf2feda077eee1dec98ed25490374bbffef1c39c0b4f8b08ed4b |
Hashes for stim-1.13.dev1708139192-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80286a859c22029d84565e6b6274f4b0e412f1bf2d21d4e318aca6786a60c84f |
|
MD5 | 0d33d9ad372189f2b51cf3165b05b267 |
|
BLAKE2b-256 | 84244ac520b9dc5f05a050d5b9e1a98f3032100a2b706220f95d32c7c45952ab |
Hashes for stim-1.13.dev1708139192-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 614d38c9888c0deb0dffef6f056b3f984273d2711acd63012d3fb9707e6fd19b |
|
MD5 | 89620871729ced80afb7620a136cb992 |
|
BLAKE2b-256 | 5299d9d369947699cc57271cd65ccb5710471c4fdf2a931c79d33adad96b2e9a |