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.14.dev1712659430-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80afeb3e998e6979e495f863560a81725b87a9d95860c0ca9f464572cf1270f9 |
|
MD5 | 602f1df667caf866a1bd9bd10c4f2779 |
|
BLAKE2b-256 | d7182fa823ee000ec1315738b1e47196fa5446566a1ff5c3af711c6a2b59ec72 |
Hashes for stim-1.14.dev1712659430-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805fb411da615317ec9446906b7983a5e803fe6ead31cf04e2e6a1fa81726f0b |
|
MD5 | dd9eae43ff45ea7e5c12c12dce97342e |
|
BLAKE2b-256 | c67c6ffec7590ada1fb167aae462d8ae672b246cd1c9d74ad32c9499109df550 |
Hashes for stim-1.14.dev1712659430-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddcde868c72387e8da6cbeee3a6b360a8a4f0d752aaaf84d9673aa3158e28403 |
|
MD5 | 6baa0ab797a730d367151f3e88219b90 |
|
BLAKE2b-256 | bb40312f4ca4c2718a413136acc3cb010cbae910a241be6ca6b7b97ebb24dd38 |
Hashes for stim-1.14.dev1712659430-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39c079d9f53fe9616cb9965e8376f95d4505ccbded7712b4262c711cd97361b6 |
|
MD5 | fc895c4d6402914266237969eeb29ee6 |
|
BLAKE2b-256 | 500c37e202b7a0bc9cbd0a6991b58456d83a6ac81b1706365cbc387c7c9f20a0 |
Hashes for stim-1.14.dev1712659430-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e28c887ee3ddd22f040b473fb283eb05db6b7bec2e564270353eaf163b9ce3bc |
|
MD5 | 02306f8d7c8de983c95bbf2663b142e2 |
|
BLAKE2b-256 | 1839877a9b751aaae157aba291359ee9d8fcc33fca57562ef4dbbb9c5766913e |
Hashes for stim-1.14.dev1712659430-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec57b65486c05cdca04daa819d8fb5ee82cd9b09e30784760d373342cc4fe88c |
|
MD5 | a169e71995576d15dea1e4ce552e5fc7 |
|
BLAKE2b-256 | c934c96faae4d9044e3d1df454a00794d2d41e362e772b5c8b19e5e9ba896af5 |
Hashes for stim-1.14.dev1712659430-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27605a9078606c3a56a5876e4e187e3a380415df6cd63388b589c54b658d5998 |
|
MD5 | 6f2159edbc52d985ab290eb2a55dc8e8 |
|
BLAKE2b-256 | 7b909cc94618ddb7563401e98ea71bc7f4fbdb980313f39b737de9b9ffe31211 |
Hashes for stim-1.14.dev1712659430-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ffdf8ea6a76ba35a5fbc52aafe7a84838a842c4fcc9cf2d94b9f701bdbbf20a |
|
MD5 | 9569e4643d84c1832e43dd2d258c45d1 |
|
BLAKE2b-256 | b624fe7f80f72f9028e81ec4e50203abec2455f2a34868b5a51e0a5910ae5324 |
Hashes for stim-1.14.dev1712659430-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fbf9ddd0e77945d201d096aac34287fddc2964276b2d6f420be70a48aa70113 |
|
MD5 | cf1b3914618b0f766b76aa0d449fea23 |
|
BLAKE2b-256 | 50550f4746551afba4bedd75086b2091ad53b9231046f0eac6d5582aeae86c7f |
Hashes for stim-1.14.dev1712659430-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b013a14ac2f6302391b444ca85637701b1efe262eba33eb53b4d77f48092f93 |
|
MD5 | 94013877303684e29410535f4333aa43 |
|
BLAKE2b-256 | 045389256d26339dbeed84e8d8dc456bcdb761a4ad215623e36557fcf8d57bc0 |
Hashes for stim-1.14.dev1712659430-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f116836766ec0db11fc9211c4bbfd4c059d59642273adc7d08c0105f611b5879 |
|
MD5 | 3c9745241f0e1d88fd77971ad1c8a51f |
|
BLAKE2b-256 | 10dda90579101266b87b67f33788a68bc89fa0a2ceba82b02387f9dcf19f7fb1 |
Hashes for stim-1.14.dev1712659430-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b883220c7ad5075ce2cab431ccdfe96275c72464cdf93d979d31eb48ad365fd |
|
MD5 | 980b94dad5b1d3c4878c293c3d4002e5 |
|
BLAKE2b-256 | 0f733c6e8b787b884adf3de455116f97d5b4cf35350d8eea04fa8a227d338a3f |
Hashes for stim-1.14.dev1712659430-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d6144b8b288dc268e1ab8a66cae8ec3926ca5962c3f31abe29b895719878e3 |
|
MD5 | aba013a970c5ebe175f237beed209458 |
|
BLAKE2b-256 | d09b9ae08e94095f375a381dbad2e45a351d3bee04b5627c942c80eb6a9bc6bb |
Hashes for stim-1.14.dev1712659430-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea1498d904519ab46e01568f488032ccddc5c28431939501b7096d9383a8126c |
|
MD5 | 572c8b9cb6457b283f600cb628421880 |
|
BLAKE2b-256 | 223fc4cfc10632aa1e23d834c69b1c07b472cccde839cba8f62606a4aeabcc15 |
Hashes for stim-1.14.dev1712659430-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 757bc2a7f835e2a43cdbdd848008693a8bb72da568b2e59f3a65d8f77847f4be |
|
MD5 | 2c10a9f17480d49f4e2533da982a380b |
|
BLAKE2b-256 | d0d074fff97d13b25e182aa0504db35c2ca0f0f724c89336f93a27e1e06d15df |
Hashes for stim-1.14.dev1712659430-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aac2477da352b2840387ee8d17b1b307e92bbe1645865cce4d477295c97fe70e |
|
MD5 | f3b5095bee2b40f658c9131cc71034be |
|
BLAKE2b-256 | cb7ccda6fba668649642844a7e7a4ec52eacee55f4b0a86e0f45bd91e22ea958 |
Hashes for stim-1.14.dev1712659430-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e663790e7672423bbe4df368aadeeb97ab8485efd94f0d2e6b4d3cc82031325 |
|
MD5 | 607b7f7233570401408952e4e3c77226 |
|
BLAKE2b-256 | 8b01e9b96896e7426f8e1f5462f2dabc21c9eb28d041cf3bf6023535a2134f62 |
Hashes for stim-1.14.dev1712659430-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3320c3a422e7c7bff824a1f01c813dbdb28fcbee8c070da352cdbeadd1e646c |
|
MD5 | 5fbc1bcf0046abc74a6d3f8c5ed69a28 |
|
BLAKE2b-256 | 879504026c3587fd1abb02b55a06694212758d3d1284817bd6b1b29394ea762c |
Hashes for stim-1.14.dev1712659430-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 421aea80d5ee6b78058b4ab79182dfaaa11bdd2687b2d892a8c1cb505f58e753 |
|
MD5 | ca58a7f2c3caa7b47e505a60a28bf246 |
|
BLAKE2b-256 | ced75a0aecb98e4b1d6ff4acecaffb24ad2b4b71367c0c934c6e91b924125835 |
Hashes for stim-1.14.dev1712659430-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1c02dc8bd3ee8e3ffe088ea43f0635e8b05eac22f39f7ad56f645f19b822b8 |
|
MD5 | ff212b6209e92054b7f2abe0e827dd07 |
|
BLAKE2b-256 | ab0d4252d144c39615002a73a0e1a26cc4c88b40ca39988c740eb76e7953d178 |
Hashes for stim-1.14.dev1712659430-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7631874fd12dcf23b91be0cb7c7d0d797225e923bb9df58b0c3280239af9e53 |
|
MD5 | 9f26e43ca83418126b704002e134e401 |
|
BLAKE2b-256 | 4116bab9fb239f9e541a58bbd5116f9c41a72638005da73a6ce2e488451319ce |
Hashes for stim-1.14.dev1712659430-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a470476b8aa11b3770905314d4662a6581c52241299f47d852753c7011e84a8a |
|
MD5 | abe385dfe913f8b989578c2c746367d9 |
|
BLAKE2b-256 | 64f3595764596356ed0c5969252f8a000d4930950f4b7134a9ea71ea9a55fa5c |
Hashes for stim-1.14.dev1712659430-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 102a7fdeb1965e6ada9e1fcd3c20b7a68b20b404a8c8134c1274c72aca9d7027 |
|
MD5 | ee4b6bd31b1755db8706285877b3ee2b |
|
BLAKE2b-256 | 784a3823af5027ab9f460f4d46ddbbc45cb65d70c95975b31b728428cba77d60 |
Hashes for stim-1.14.dev1712659430-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bab40a189eb13c5a7db2f3f62f0e824dafc32553c3d6a98fa0a516b73bef8a5b |
|
MD5 | 291eabb86813bd8f531e6442926c04c4 |
|
BLAKE2b-256 | 13ac1aa6bf6837abb2ccd28b6e15ebb16538a7606833df57cb81a7fcf398cc46 |
Hashes for stim-1.14.dev1712659430-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795c56c9c706b69c73ef891adc13329e755019073fc6f75e14ed36b51024e53c |
|
MD5 | 18d2842f426000d1cacfba622ed3fe1c |
|
BLAKE2b-256 | bbaa81cac99f1e9b372f5f6496a6fd4521dadc1bc036cd3301448e6d63151c23 |
Hashes for stim-1.14.dev1712659430-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ffc86d325f82ad2aa322072a0b49f79227eea448b9fee0ab95f70d29beaad1b |
|
MD5 | 3bf100bdd5c22a78055d2df9e7eb0ec5 |
|
BLAKE2b-256 | 4a0690f9ef7064588e385572919dbcf2f17cc00df5d2b0b1befb4a59a20e91e3 |
Hashes for stim-1.14.dev1712659430-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e0c0b2faaf88dc2e921d094c7fec9fc9bab1fc0e4ecc5f60096aa5b14238ec |
|
MD5 | 7db2a31bf5050d9d9fb49a9a4a1a7320 |
|
BLAKE2b-256 | bf2675172cacb498165d7c7289419055eb12816efbd2fc6efc3c31ef6ba705e3 |
Hashes for stim-1.14.dev1712659430-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 322cb3e3e395ef65305a4f9637ec87d9d6a80fdc46e2187da1ccb4225f989e99 |
|
MD5 | fdbf0081b9eb8e83f2c5284664a65579 |
|
BLAKE2b-256 | 46a163142402a7bf2d521d9e2c86be8601a23a0ba3cb792b587f4231cd274cc4 |
Hashes for stim-1.14.dev1712659430-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 325dcb14063a68e69f141ea6dc9244f95707e0e20ca4808e7c3e2f28a6d5dfb7 |
|
MD5 | 2740260eb69f779ac23d250343ba4c1c |
|
BLAKE2b-256 | 4888495d7786360ca7ffcefc83c4d9f77fd42f9e8b7612b3a74060bd490345fb |
Hashes for stim-1.14.dev1712659430-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b32dd6e6c49c60383ded91949832461b6442045c6245a724ed31ce5050e949f5 |
|
MD5 | b2b84aff65101ee7fc1d3fd482af2316 |
|
BLAKE2b-256 | 6d4bebed3d3c0ac1d48b67eba201e039da3b594e181d9be9f9c7eab00d43f42c |