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.dev1727164676-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00bc7f7ce4d8a243761bf148119368860634dbebc01bb788b3ab3eabcab9c4f0 |
|
MD5 | 1ab4b0aa458dc9d4e0f1ffb8bdf7b30e |
|
BLAKE2b-256 | 5a4344b2a1cc1724f5825cada273dcc95d4ead8f760da42661f7af83775b5959 |
Hashes for stim-1.14.dev1727164676-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03c372786a0986aceebb49e702ef29fcfe2d8fdb703849e59912fc1fcbb5e2fd |
|
MD5 | 98cb552f3ffd660f76d2c7db5f9e25c4 |
|
BLAKE2b-256 | e78ebed42ffe37a12f0da54529ce6dc4f8b1bea9d5d218c0aea740fae489c75e |
Hashes for stim-1.14.dev1727164676-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b75798a2adf71efd668f685304fc128683ea35b7e1b1f80ca7a4d3213761bb |
|
MD5 | d5e20f49a2af531ab26f4e1a41ea7ee7 |
|
BLAKE2b-256 | b341067fb962fb19dd6c52f57879e64919c298656d7e803454896db2ba39a9e8 |
Hashes for stim-1.14.dev1727164676-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 040dc2acf613bd99a9e1da51e9c30e4033381a3dc41e940ee4efe5630df73c3b |
|
MD5 | 9f3f37a380ff5b837e3107fcbfabe02d |
|
BLAKE2b-256 | 059a6501203a8358d10a4a9768b57997521522df7b07cb85774cb32cb18089b7 |
Hashes for stim-1.14.dev1727164676-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ddbad0d61aea9683372d94c8fddefe077cb6db0a6696fa9ef1e33cebe9b3d7d |
|
MD5 | aa6dbe96ac459356494b4f7b393a5f19 |
|
BLAKE2b-256 | 8038cdbffb2915c7b469d756be0121af97a955999141640aa8f1ebb19fc77cfe |
Hashes for stim-1.14.dev1727164676-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8f6be6384648ca9b80a4b6a98d4a18e5ce1ecdc820b7c5bc99f1334471eafe |
|
MD5 | 643b5736ed70f6b8c043f9db40fa2342 |
|
BLAKE2b-256 | 4e857caf57b5557887597fb94ca89b824a26371e61d1f6ae863fc48425f2120f |
Hashes for stim-1.14.dev1727164676-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9552100c6cd93d72a3c4b8e7f012b00d06571ab249045cd06070eae96483348 |
|
MD5 | e56dadaf81b9fb158202c2bb6bac936a |
|
BLAKE2b-256 | 35f9a507bd574f632c084034efd0094546cf36ceb68efa04b6d0160080f8cf9b |
Hashes for stim-1.14.dev1727164676-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d796d039d4bfb966f3dea3b18d99ebe1b658ecdb994fbe869d4e01e9284c635 |
|
MD5 | 850eb1cced9d0c4ba1c6337cc49582ba |
|
BLAKE2b-256 | 3d26079a769cfa976a7f85b2f03225b3b10a3b23c957dc5b45d2fe8a1db100c0 |
Hashes for stim-1.14.dev1727164676-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48a98d9f4b5eade94e521246648146dade7f7309e220d3aa88afdb14358847b3 |
|
MD5 | 6e0591bb33589c7cd9d657b2bf1e65cd |
|
BLAKE2b-256 | 0c2877b91d49642799ad71ada1edbe603093f8d9cca389e43467661997a4b342 |
Hashes for stim-1.14.dev1727164676-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc3ead8ee19d12d139bf8608d90381f9d2ab06331cdc97b38a410122d126cce2 |
|
MD5 | 0b84b6dc6ae08c945e9a604aabe86e51 |
|
BLAKE2b-256 | 93061f75cbeb6c0f93829eeca727716750597c1639240b6df33fdffcd78ffb2e |
Hashes for stim-1.14.dev1727164676-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7351cef879e66aef5351eb7b4358eee95afb009fe6eb9f7094e8d97c8dd65eb5 |
|
MD5 | 2bb460d8b46119268c77f909b3e745f3 |
|
BLAKE2b-256 | c5c8071bdf8aef4e91fb7f1c63ae277565619d4c23fe6b444cdaf236e7e8e43b |
Hashes for stim-1.14.dev1727164676-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 564de8356a07eaafbdd0fa88a1bbd2ef7d36fdb874174a86c551fa0c545405dd |
|
MD5 | 90f03a6050e643db3a8979640fc11414 |
|
BLAKE2b-256 | 07fe13a099d48ecaecea2bbd815302b7b04a12b431dc98fc5caac5143be27584 |
Hashes for stim-1.14.dev1727164676-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63626ada4e2b67169565271e1ff586fb1983dd110af65401c1f92f6597561a36 |
|
MD5 | 174c89daac0ec2594f2f902abe3f76ca |
|
BLAKE2b-256 | 24f57cfba55c78bf6b804e5b899a79aaccb93e88fae647b6bd8e86132f7320a2 |
Hashes for stim-1.14.dev1727164676-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 516ffdfff6d2bd9e35b136e8701588e3311879fba7ceba1386cdbc683fdddeee |
|
MD5 | 33846f2d6d6b3c995cddb78f7d654302 |
|
BLAKE2b-256 | 2dce97823b5778a06cd9de17cd8268e956b28b7b92f5d55467f51f5a01f741b9 |
Hashes for stim-1.14.dev1727164676-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dce61751262cd7d06e1554b4b556690e1d0a597d4cd93e4cc0b03eaee557df0 |
|
MD5 | 73a7e33d5e054996cc5a8f9bd2ca630d |
|
BLAKE2b-256 | 25afa3ab02832d750a90a3f94570f382bdd90957311e0ef0b6c69e2959081eac |
Hashes for stim-1.14.dev1727164676-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8225353f9461f586668bb0d429c82a873041b14bf21d9010357d118d99be7450 |
|
MD5 | e75b1b8c806680a30008c973d832a0bf |
|
BLAKE2b-256 | 412321516906a706393600cecce441ac0b1405a9162ce32a98742a87bf69fe48 |
Hashes for stim-1.14.dev1727164676-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f346549cbe18ade5c12b0e928fbd85b33e629a7baf4752026bbd6c50124c42d7 |
|
MD5 | f148b0c5883e9f00a87984f6f25b7d60 |
|
BLAKE2b-256 | 9d9e2033529c357704f15b25f224334870309e5460445f808f775697993516fc |
Hashes for stim-1.14.dev1727164676-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcfd8d346f20d44b4ca681e467bc5b3d57fbf5b60db71acd53e0d1c1a9394006 |
|
MD5 | 141f5e2ba109eb44d2e4dfa1d4a32c6f |
|
BLAKE2b-256 | 68daa32a43a26020f69c98c67237d8cdf84af6b15f9e09bf8fae20972ba281b1 |
Hashes for stim-1.14.dev1727164676-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3387e78af18a7818cf40fafbba54010f5609e202fbec269876cc7ae8c0676656 |
|
MD5 | 9c3adfb0f926f064a4f28e2ee71e89ea |
|
BLAKE2b-256 | a10625f8cfc59365cb4df075f6a1bedf002d6516fa0ddc281dddaee5f160f121 |
Hashes for stim-1.14.dev1727164676-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e21c0e196142779d224ea90171db62a7c544385a61337cca5d3862f340750f7a |
|
MD5 | 187d4cc59704e936426367625825859c |
|
BLAKE2b-256 | 85d0a63bb744c3ce66e90ce8cfa314a807486ba5df510f59f50fece709dae535 |
Hashes for stim-1.14.dev1727164676-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9940493ca809bb89087a29f6bdf4d0992e7f3abaa268c92208ed5e3650b0756e |
|
MD5 | a118c67937f9942d9e6af77989d02327 |
|
BLAKE2b-256 | 055186c4c8120b1885242e5a49ffcd5088ddb5275b3aaa4d7cb8350440c892d6 |
Hashes for stim-1.14.dev1727164676-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 359f791f02aa8f19a7b7122f41e94c386d3249a7be17706ef87c205c31b82e84 |
|
MD5 | 167734bdc018c6d0c31d3d2b53861aa3 |
|
BLAKE2b-256 | 69464c9d63b97e794d8f4ef3c6c64d5ed2d85f19c26282f8b91ada587235e5ee |
Hashes for stim-1.14.dev1727164676-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4623d26489df1ee905aa33dd3de4b13ce6aef30bfdc7b4ecbce81781ba8cafe8 |
|
MD5 | 6ba61b6df2e462226aa761cef336eb11 |
|
BLAKE2b-256 | 569188bf83deab22f468c18c8c13b0410f240bd4c2b64a8812aef71bcc1831ae |
Hashes for stim-1.14.dev1727164676-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51e3e13bf628dba34ef573b36c61ea31bb5fa0ff6f3025e2cbfd4500d6ec1f74 |
|
MD5 | a91143dff61673c2a420b9fc41f1c923 |
|
BLAKE2b-256 | d52e5c745538f779a4004437a2313a0b4cafb86edb77c3c91337fa18c9174f81 |
Hashes for stim-1.14.dev1727164676-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c8de2b213fa42219b41422a8cd994c80b3f1724b21334d218d314cfa8fc8f30 |
|
MD5 | e489ebb0ce6336f6e9ad618373daa425 |
|
BLAKE2b-256 | 2447467e8945e60e0cd446b9f499db43fa1bc300438b6be909648f8431232dcb |
Hashes for stim-1.14.dev1727164676-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d50205a4be6bc59e54d27c37bc5a3eedf20e4ff2354f1a2a86c05ad459216c |
|
MD5 | ddcff0c401d207ca305a99cdb83fbabb |
|
BLAKE2b-256 | 19d2234a3d4d374cbae2abaf0d0a6d0262fc77e456d1b3a1e3cb7b26668890c4 |
Hashes for stim-1.14.dev1727164676-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edac9f55bf3fa6cad327b0bbc3f3b2b8452210d98e88de3e6cd66d35f3fb6413 |
|
MD5 | 166a3cc4fa47c1255716b06f6e0ca200 |
|
BLAKE2b-256 | 5941ac4bae2bdd53344d156b442543d7d8736af23bcf93d18a05ccf9d90f3eb5 |
Hashes for stim-1.14.dev1727164676-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d1535bf59262b834b0017366390e64d2dddf6747274baadc464a75619b1c3a2 |
|
MD5 | d9aed488257d47d0b487feed9b6ed724 |
|
BLAKE2b-256 | ee6f19cb4e0928a8c49419546adac1249633b48322d957ee3f602e237fd0288d |
Hashes for stim-1.14.dev1727164676-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eadf95f12e22c3bda7319fa77c1b18f0e27c412eaa6807a5eed5a7bf351d8422 |
|
MD5 | ee6a4eed2e2a30a4f6ef7e2cff035d75 |
|
BLAKE2b-256 | 82db0e07f334534c6d8d541e6ea81a976e74362375446bcc1591b972a3746de1 |
Hashes for stim-1.14.dev1727164676-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d847021538501c5d45522921b84ed1b01528171a787d246296403c098a263e2 |
|
MD5 | cf6cf50978b978cecf6cdd3985875e07 |
|
BLAKE2b-256 | 3901a13fba8f2f0ba5189292ebb8afab62c3a1a7a90b5855601ca895a51b46ed |