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.dev1701045685-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9f2a75d36e3dbdca8078d8e8417774cf3c39b0ba73ed4a94002eb4d081133d4 |
|
MD5 | 3679c96b630cb6e7016e4e9c68713601 |
|
BLAKE2b-256 | fc3c258c9324de64bd3950addd8eb9d1580da9cdcfe12403ed052c1ea768984b |
Hashes for stim-1.13.dev1701045685-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6a64cafcb0dc3fdaec00ff5ce048080f4476d8647e7f33cda3b215f59b97da6 |
|
MD5 | dbd9fa136c4c162a1cf63e18b086e78b |
|
BLAKE2b-256 | 099a2d37e1a5401ac9f8594188bb97b754dc65bf98c2383cc5e04ed3b48809a3 |
Hashes for stim-1.13.dev1701045685-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6292fd29be8ec76c969fdbf7f32cb54de6e50dbcba678b7da20d80581085bbe7 |
|
MD5 | cc2fe15251789cf76a54f5f09ae1f154 |
|
BLAKE2b-256 | 5b0af1e351ed8cf4db450ad1a6a7535f2533302cee7c925aaa7c0bfb924fcf1a |
Hashes for stim-1.13.dev1701045685-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57b66922c1d5aac47fd6314f9ed57a59543d3cd86046663db64dcdc6229da1fa |
|
MD5 | 1687321275f5cc2ce8738bcdf6481d12 |
|
BLAKE2b-256 | 2948e0801c5f7a171a9b19eee848afcc8c3a92496cba162b54ee1f4ad894394c |
Hashes for stim-1.13.dev1701045685-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bfc801799cd5ef778a484f101b1e3db3ef263a0a36991056d9e3c849a51f9c3 |
|
MD5 | 3f6090cfebfe72cc2944807d57144636 |
|
BLAKE2b-256 | f38067fe4fa082185782b74385dd7780cfa6bd38c5bc7e9ca9e4c9cf0c59bc29 |
Hashes for stim-1.13.dev1701045685-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa633b55b682ed45143d9028ef9874662607436388ce049e3cc37f5f1de6f0d2 |
|
MD5 | a56fb500efa250f98b2a1bf18abb96de |
|
BLAKE2b-256 | 8b93d3e0ddc8431aa8c93417061b9a7dc67caa53b1c8deb9e56e2d95e5197d5f |
Hashes for stim-1.13.dev1701045685-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10148a93663032781bf9d8e9146c3bd222f5a3e04fb59d8ea356ad65d63c06b9 |
|
MD5 | b2cb82bec86fa186cc8b4e14fe7021af |
|
BLAKE2b-256 | 041e9a32506201e559683ca833c3aa1c606ef71aeaa812ca143b0c0700e30d95 |
Hashes for stim-1.13.dev1701045685-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b93c3699f9cbb92fbc76351f5b86f82a836e43e727b6ad8759ed4d26f008c2 |
|
MD5 | a02e8a6a48f64d02fa6df00876ae81b5 |
|
BLAKE2b-256 | a9aafa641042fcbce540e426f5dcbe2872621f15a2ae551a10dce70532a5c0ba |
Hashes for stim-1.13.dev1701045685-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e78322a8661db4378659e020e0f193645da4220bc861e65258c54e07ed4809d7 |
|
MD5 | 460e3e7e43ea8d24bca46f1938e91de4 |
|
BLAKE2b-256 | 61eafe109a4f7b2bab9abd9b44d61d46628c230c1d11d395f70ef97a5ba9515b |
Hashes for stim-1.13.dev1701045685-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0695f0170d08c7ede211bac5b5fb053e21477b52b8a827b709e56a6d37c2f6b5 |
|
MD5 | 80b0c1ac9857576c3a00fb934f8d76b0 |
|
BLAKE2b-256 | ca53a91f71c10b9b0ca649ee998e037d1d81f91e5f94cacd7f37665f2ba705f4 |
Hashes for stim-1.13.dev1701045685-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62b6154b0256429e42636976fdbe6c7402b7eeb78d150d063109f279896a2a23 |
|
MD5 | 23e48127d98c58da5183c0465db84c22 |
|
BLAKE2b-256 | 5382f058ca0e70760c66fbb410d22f9ab1a18524fae193c503a2a88e250b0df4 |
Hashes for stim-1.13.dev1701045685-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8345b591fa1ade7f2bddf1afce82bb74bd0b61fc65c41c7d2d00aa3182856ae |
|
MD5 | 0878dd8ab000e16675d5c290707e33cc |
|
BLAKE2b-256 | 2c2a4b4fe404b3d78cc6d5ebc81ffcdbf8bcbb28ac327fc81fe055e7eef730cd |
Hashes for stim-1.13.dev1701045685-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4350173d158c733d47f39484db654c557e3f585cd6bceb07f1921135de53c595 |
|
MD5 | c048d339b323756fa8f963f93e8256fa |
|
BLAKE2b-256 | 732acc39a7e3a3a0cc6a2084e5aa4de963392d7657aaab7ea287fa119d7c2a0a |
Hashes for stim-1.13.dev1701045685-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81387a1621bdc95c5dab12297fab4b2d6830fb3f2ebc126e8b49c241a3c5fd32 |
|
MD5 | 34b075a8a855200f34f4ce93ee7c2efd |
|
BLAKE2b-256 | fff88c2d3668f697a2cfe5f285781969e97c7f37a3a7695c8483a0132e65d355 |
Hashes for stim-1.13.dev1701045685-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dfe8ca5fd5b3e2da78d318820d5faf267a7e0a1ce4fc3aa47a443c454c5deda |
|
MD5 | 00e030596e609fe72c0ccda030ebce2c |
|
BLAKE2b-256 | 30c1dc91ad513adb6539805e1ef21a8bc2fcb75d15a653d1ea156e044a71edd4 |
Hashes for stim-1.13.dev1701045685-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b407b2b7cf965fdda6761517f0b52721f4c78d3203d2216b6d0f47ace2e3cd26 |
|
MD5 | 6e2f5b47f474afc60513f792520fe3f5 |
|
BLAKE2b-256 | 2579426bfc707e9d9926c053bbed012b39f3086664b6ff7efc4fd736fa426afe |
Hashes for stim-1.13.dev1701045685-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1523e2321588c748af9cf2b015777c2b42b5121f954c7c00a3d9b9c57e816c39 |
|
MD5 | b0700ae11da520b62c258c6141bca890 |
|
BLAKE2b-256 | 255be989d188137f35c49820fa83abced54b600b5b7cb3eee342a8ede3dbaec4 |
Hashes for stim-1.13.dev1701045685-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3d3c86bf32f810f121ba1c0b84adf057f3e6e2c92c0793ac6518b9b61645d28 |
|
MD5 | e01b775011c4e4d3c5661e158715d5c6 |
|
BLAKE2b-256 | fceb5326bd14ac6c5c1e048d1e05ab86735eaeb8befb394d57a2083b5d68316e |
Hashes for stim-1.13.dev1701045685-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aad61d9fa1706fba9e6f8836ca281de9d4db4089ece5ad0127bebefb1dfc285d |
|
MD5 | 97644b41c183f91aea8e0765fdef4516 |
|
BLAKE2b-256 | 37758cfea0d178a1e99d18adf226b74d539be795a59bb0db333b9568f99b1b93 |
Hashes for stim-1.13.dev1701045685-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a7d71dcaca813805a9aea652602ab06f66f5b9c05a2c1d31d0a8b1fea325f5c |
|
MD5 | b0adc5c99c58b8a9c9b77bb1ef3f795e |
|
BLAKE2b-256 | 456ee9489faf2cc85dbdcda6f2ae075355d79c0f27a8b7694dc2cb919c2c9c36 |
Hashes for stim-1.13.dev1701045685-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 289a8ff9b37ed8609acced1ea951d5fcccdc9bb3cc62d12aff30fb43b06cdb98 |
|
MD5 | ac0476d5c810f2ed7f9c57f088320fb8 |
|
BLAKE2b-256 | e524c6a6805eddc5a242b65836745685725494f0f99961e9a8ded3ac06fd415c |
Hashes for stim-1.13.dev1701045685-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78684448c0dd75f170561beb21c4e6abd2dc1d6f2e275ffaea2684f655ec45fb |
|
MD5 | 05bfdcd1c81d26e9eb1e33afebe68c42 |
|
BLAKE2b-256 | 5eab58488b81be6d131c3b787bf8d3d4d9299c2943ea338b16f1e52227202c78 |
Hashes for stim-1.13.dev1701045685-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34b31b3bca7ab0492be7737aacd98f3a126b9ee8386d6bc2a31b5288515d07ce |
|
MD5 | fbd12e01d68b627416f0924cfd8e8c49 |
|
BLAKE2b-256 | e1e60efe8e3fb402162637c7a3aff572f775bc2e2f8bd4c72d93e140d2f63920 |
Hashes for stim-1.13.dev1701045685-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50f34a4265a848643ce2148a8d3ad5d5d1b1f2f7efa9d755c731e1bac10dc7bc |
|
MD5 | 1f21054e973320daab0e22d4be312a9e |
|
BLAKE2b-256 | 7795c0f5a119c51a52d2497f4b327abaed25889df7f9666e84293a52c038025e |
Hashes for stim-1.13.dev1701045685-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0faa11bb0c109b0680a3ef176d953e64e73bae5d92599921ffbfaac6d512bf2 |
|
MD5 | dcc27bea25cf6f5b5b1abc7aba172d50 |
|
BLAKE2b-256 | e97ffca07d54bd18fd176c1c3de5cbdddb0ac5911dcd86ca3e5819df436d7ddd |
Hashes for stim-1.13.dev1701045685-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a094544f533a41d4f3c330d7f86fe501dc7c3ee26d254c261d5d7a85431393c9 |
|
MD5 | 81c12041b533e90c5b5d153e8559db16 |
|
BLAKE2b-256 | 395980a9b41820df595d95d1f5e57008db6f35842395fe3f56af9f3998a43c7e |
Hashes for stim-1.13.dev1701045685-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1604953cdf3c050080a290600a88804a382aafde0dbed1d3180a18b42741797 |
|
MD5 | 12138a5563ee7a453394fb580cc09f37 |
|
BLAKE2b-256 | aad9e8a19da31041f8fc15ce9a2fa6d0fc0cedb88844afa88193f9a7cc9c444d |
Hashes for stim-1.13.dev1701045685-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81839d88e519d1e45c71e9f0e38fe1d6999933b74820945cf8c68cf4f787f6d7 |
|
MD5 | 9e10c38401220a35b0bb4bbd2c458877 |
|
BLAKE2b-256 | eebaf81ae47f84558c7649560c5ccf5e264a0a3d688b2a0a1c70a22795f2a2fc |
Hashes for stim-1.13.dev1701045685-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3f6ee7f95603406f20633bfeb0ed7598c73017a2b13dad3c29b73d37f934df6 |
|
MD5 | cc181645b429b5ca8c9e358cfe1116a7 |
|
BLAKE2b-256 | a7c6b4338a6a616d10b611dff7e9b1467f1e3d342096fc1d12b1dd078c693b0e |
Hashes for stim-1.13.dev1701045685-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fc92d0c24311be587ad76d0b5105571e2bac6e5682182411e8b665c6167b063 |
|
MD5 | 6bc48b35fa50300e11abd551b40e38d2 |
|
BLAKE2b-256 | 8bdae0925a5bf1b258f20a1c3be74f97c0ff06514322eb1ea8f3ddcd98be566c |