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.dev1710431323-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb90d3de9ae701a9bffd9bcce1c7c2cb33e08279fcac60fc8b53376b704dcae |
|
MD5 | f5a9afd0609bb29fcaf46323098ba5a2 |
|
BLAKE2b-256 | 8deade90d6d7211000daa47bb10f9e2c28ef7b8087bd447eb18b811e6ce4fdb3 |
Hashes for stim-1.13.dev1710431323-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645b0c23cc35f70acd55728aa793a919d370acab0d85af59081a4945a6a12f58 |
|
MD5 | 22ef1dd40dc771da7b29dc8d449b72a9 |
|
BLAKE2b-256 | 98e3bcd21573f699a3e1229f8d888ef16f7552833664d3b429e46c27a7f43385 |
Hashes for stim-1.13.dev1710431323-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 433d8afb3f4bec9ca598b33e90e4a5392fcfd7a1e18a133c50de34e2a8d56f4d |
|
MD5 | 1a70c3841c212311005713ca1cc68de9 |
|
BLAKE2b-256 | 537f1f3755f4af4fdf8bf872bec040677312205429428581451c7725e5041e07 |
Hashes for stim-1.13.dev1710431323-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c5fe8e61c8418138ec9c01886c3afbee312d78cbb1cd8d9af3a9bf1c9b4e417 |
|
MD5 | 4dabe3b49a2911e0ef4417f62605fda3 |
|
BLAKE2b-256 | 6ccb8f679fbc6d0aed878774f3c7e16da106aec55d6d0829f72013c1d57773b2 |
Hashes for stim-1.13.dev1710431323-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f38e496b8475ed0e014833f8598d947e6c4196d443b787d74038531a2a50762 |
|
MD5 | 59fc16c4230777e98856a42c34668fee |
|
BLAKE2b-256 | 3d7779349e2f4318850e3fa27f0b9788c6674b9e8b3b80da1405c6641db2f5c2 |
Hashes for stim-1.13.dev1710431323-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd8ccf44225463968e9bf658fd2eef3b6c5cfd8ffc43dccfb1541a113a419015 |
|
MD5 | 330d1cfba2e55f80e954c1609740d535 |
|
BLAKE2b-256 | fcefa7e23a29bf868ec62ce44516208d3b3f5016495c4db4d0c00c43b9014644 |
Hashes for stim-1.13.dev1710431323-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3dfe422e8f7614d7e4efda875437fd6dacf6ada0fa9d60241e026e0d4aa7c99 |
|
MD5 | 9301e1d44f29c895524461a4f25b3815 |
|
BLAKE2b-256 | 170a04a6157776badb5b0b0c579925377d825889612bd39663ad7f800c3464ec |
Hashes for stim-1.13.dev1710431323-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dbd547d08f038718d347a9173ced0b0252838b8695d465f5b55502853b2d80d |
|
MD5 | f016a773f9264fa16c191892d9838180 |
|
BLAKE2b-256 | 464a674658267eb4754e35784ae7ab5c19291c7782e3b9d3d9638f5ec855af97 |
Hashes for stim-1.13.dev1710431323-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9693472ac041921312502882362bd7947e42473564c8abb78fcc573445ab7a16 |
|
MD5 | da0db80ab8a14cdecc431e9bce9df3bf |
|
BLAKE2b-256 | a1db02997582f9f3a2dd9ae8f98bb6f210213c5378db53f8bb989dad5b738704 |
Hashes for stim-1.13.dev1710431323-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e037669e7a96257df14f4bde2a28596dbea3505dbe8f4dce340e400660237e54 |
|
MD5 | 5621794f48389c537e48dd455cea732d |
|
BLAKE2b-256 | f1b1f856095d82fd05a748733165f09e7b64cd5d698c7214d9848ec53506f320 |
Hashes for stim-1.13.dev1710431323-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e8fab60f35ae5a0398f213fd05269dd8db1d700b89648da167d3e7274157a4e |
|
MD5 | a5455f2bc5a0b933d1be097f82c627a1 |
|
BLAKE2b-256 | 2b7e860f7a217f3465ac66bba17cefb17987dfd84046c6408ed7d25fe1a2b21d |
Hashes for stim-1.13.dev1710431323-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f79e7a90d79260b0679539950932f6c24164cb32e6492a9c801258b2303153a |
|
MD5 | e7b3f97a9f4413438945b5d8be311119 |
|
BLAKE2b-256 | 92db5a0d1ce2aa26b2f6e72ebe6e6f708b36a4626f8d4a46b7bbee5b169f6cc5 |
Hashes for stim-1.13.dev1710431323-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba644c767293e37e9ac8b730f9ac35ed755d2eaab14ae9a1e0934985a3981747 |
|
MD5 | 5de732bb94abe482a86809e1f531470b |
|
BLAKE2b-256 | 13465698c66c883c403e5cb3ac993422503920a942b7785ffaa07579225f26a5 |
Hashes for stim-1.13.dev1710431323-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d36f0c05fae80310733f36e8a0bd52fcd25e6d478676dd51a4b26eeba1a7bc |
|
MD5 | 543b03cd514f0e9a11f733055f741280 |
|
BLAKE2b-256 | 02e995643d125b2fa3c57ad08b039667a915eeb7fd0267f89d4e79239e9488e8 |
Hashes for stim-1.13.dev1710431323-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69cdf77ee77413c2544d670cbb1a2fe2ede8afee48644c46f05e69b78f659aea |
|
MD5 | dbd42a29541c8a04dcba1f02c104a640 |
|
BLAKE2b-256 | c24c129ad4dbb9506a30519b30670cdc3a5cba954dc2d887f4b9fe6d6b2c18be |
Hashes for stim-1.13.dev1710431323-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11550cf7ff19f6b6cbc46bf04e8b85d497eb2293d64fe142ed78bdfd1863e619 |
|
MD5 | 7eb3d749a3154c7ff4d4af41f4b536a0 |
|
BLAKE2b-256 | dda93eab5a3e58cb72fa437b971101e94d10a461017a4bb70e72ef6330ee8661 |
Hashes for stim-1.13.dev1710431323-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3a43a6a0288d5b531a145fdb17bebf11edc2d33ecbfd1d17a5ba235e141ccca |
|
MD5 | 557fa11620f94d1b6d1231ef98b71934 |
|
BLAKE2b-256 | 0d61491028243c3b4554db1feccc4d9ac13507d7df9af611085ea1cab4f81179 |
Hashes for stim-1.13.dev1710431323-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4fea8edd2265e73a60ff7f3765d1645c679706962f6c843147b0b93e1aa28d |
|
MD5 | 214986347195fc3e0b790df76cdf0fa4 |
|
BLAKE2b-256 | 9e1a24067b4f065a1169b49d0f12887c1ccd50951cd6596fb51713bf667b7859 |
Hashes for stim-1.13.dev1710431323-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ec701cd45dbe771f8b1cd3b3cf6c2b6c93f9006d4fe9ce840b381ff9ed30cec |
|
MD5 | 1671f5a909b5bd8bc5e9e39672c19dda |
|
BLAKE2b-256 | ea1a0108a34414f78a9fbd4cb76f7918fd6cfae104058b5540c048a9c89b38df |
Hashes for stim-1.13.dev1710431323-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2a23f85bdd32926ecbad53603820935886358eddca879d177974a74cbffcfa3 |
|
MD5 | 362cc4e409d51af671178310921b8b9d |
|
BLAKE2b-256 | 4eb2271d9f309344d306ad8ef60fe80b5c359c96993aafb4fd02fc21575a301e |
Hashes for stim-1.13.dev1710431323-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eb4768fd8d53bd8f7353fdc518f8445a2d4fbe236330262d0e69fbaa7b7a2b0 |
|
MD5 | a66b8087635d89f41ad26af47f3452e4 |
|
BLAKE2b-256 | 5790276ede6c1a13d75e4116f481af1485b0243103b0585e67a6af72db5a0478 |
Hashes for stim-1.13.dev1710431323-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cdca060ae450f55e3dc414c3caf0f1dfa2f54c08677d5dbaebeb5c9e21c6e41 |
|
MD5 | 6050ab19718ddc607bd672dcbc2f2c9c |
|
BLAKE2b-256 | f96af2fc2c847c7ceefb834e0fea7a704fb5838e17aa7092437b123885c8708e |
Hashes for stim-1.13.dev1710431323-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81838f4c06894734e43c29a34fd9752c327ab5ebb74714e69383e2fe3e1e6572 |
|
MD5 | 6effcfbcefce8db6f3eef49f563a05cc |
|
BLAKE2b-256 | 7d5b6ae45494c7884e4301d12cab529d228bb2f5d8b19489cd6efe4654ae6182 |
Hashes for stim-1.13.dev1710431323-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6f86fe1a0edead16c61ec5761b092e56b51e51b3f8b1df5d0bded6b699534e |
|
MD5 | 6b784ab5abfbb75bddb610c9f32d6f3d |
|
BLAKE2b-256 | 0199098c2d0bdcc9fe943e7d6f120d4648b7fb722e0ea180a8f2de4b0946df8d |
Hashes for stim-1.13.dev1710431323-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05aa1d7de2bdf36307406755454a113c0289747bd9f8aa3444e4ead007b40c8c |
|
MD5 | b1269c9562fc732e59248da8e83582ca |
|
BLAKE2b-256 | a682f7ddbe60e2f05efb3c40613c522c42ab4dd64f7d04aaa299e328455aebb8 |
Hashes for stim-1.13.dev1710431323-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1900bb2e85e961626a90d8620b42eb38f6af3e078edd1682a43d867b3f743a2 |
|
MD5 | 3859a5b7176201f12291caec12431374 |
|
BLAKE2b-256 | b15809afe232ea95ffa1dc19de417f0a4c2f061a3101dc87ae9993e399f713e5 |
Hashes for stim-1.13.dev1710431323-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34239ba64b9e1a229690dae0f131aea9318707bc39609c61389e45ca9093af09 |
|
MD5 | 6e29c45c802dacb1c568cc78714bb6b6 |
|
BLAKE2b-256 | ee90fc7812f9e48317815e7a20a1d9a994b97d7b50c845403168c6fe897f81af |
Hashes for stim-1.13.dev1710431323-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 681e3eab0200a7de361df5db5ef38119aacfe31f1258500d568a9a3865ba70d4 |
|
MD5 | 54c95d31431005c43a69771a462be1d9 |
|
BLAKE2b-256 | f3b5c162bb24a5481163e007e347fd9a910938ad9a86cfc525ff6dc6fd7bc973 |
Hashes for stim-1.13.dev1710431323-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0633621f70b27bfc8abc985409dc182ae323122aaef7423ec6bdfc5b9c2dce02 |
|
MD5 | 8a5e13e794149107493f21a3a0991fc8 |
|
BLAKE2b-256 | eed91d81507165feb84b104efc0405403ccf8778ef2deb2405f6d79d16e396be |
Hashes for stim-1.13.dev1710431323-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e0f5de8cdf3bf5f70e40280fe2ec4ed25f2c05342688364b7fe526c8d9c2e4 |
|
MD5 | 2db284e4000ca0dd04537650b850a4a6 |
|
BLAKE2b-256 | 3319bf2514a9358ad5c824a989942e04dbe441fc1857188112681ff263a07ab4 |