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.dev1719978558-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85e066e88c723ddc86239eabfc582329b11b521028d73b12798d76a62eecac8f |
|
MD5 | 02595e85006b355342871e0eae2b2d80 |
|
BLAKE2b-256 | aa9a293a4f6bb09dc6f8e51b0f339888abba180995a63be302eefb9f547092eb |
Hashes for stim-1.14.dev1719978558-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3360a4c3ad9230b2fe0cb75301e30b3f58530a121ea49e5dc3d7417253da01e0 |
|
MD5 | 615538b1cf2b7324cd01640e3d9fa3ca |
|
BLAKE2b-256 | 279fbf860e7dac855b3eabfff139b00a16cd54e30683c9f1c4b8404e0f6d1502 |
Hashes for stim-1.14.dev1719978558-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67457d0518ee1bcad350edd1f61d72803c5844fa2d0131ad5ae1bcfb2d2b412a |
|
MD5 | c6b422e69c56912236bd957145b6dbae |
|
BLAKE2b-256 | 60e4427010be84a8ed6b7713fb7ff7995f352690316b1351e5d21c338b2dfb1d |
Hashes for stim-1.14.dev1719978558-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 592df2c5c1d5b897dc0f04db35917edcc478f3a9b17c558923b4542d904fa018 |
|
MD5 | 06e41857b6302dfa110f6b5ed5bdb619 |
|
BLAKE2b-256 | 78728fc68cd358068104d2ca254d381ebce5a4935b13a96e842c8a2cc956cf94 |
Hashes for stim-1.14.dev1719978558-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b315654513e227b8143670e0644b212a374c88d89e2cd1808c28ffbe21257728 |
|
MD5 | 6dbfefb9cc10c121edc08957b068d47d |
|
BLAKE2b-256 | 4a1e08cdb9f9b180e4703ef53bc723cec3d39f8139b097a1aa496b3571a63e4a |
Hashes for stim-1.14.dev1719978558-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be3f21851a1fcf88ce436da1927ea43c74610e890a64f31174fea7a82316c849 |
|
MD5 | 80bb0a7d41bdc5ffe7c93454f219e6b6 |
|
BLAKE2b-256 | cc954ff574518c67ee26309bc273198776c5404ce49705ead7b4b64b8ed1f847 |
Hashes for stim-1.14.dev1719978558-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f02fbaa25778a37b17ce95f5f16f2a8b81c02d79557827afd719db7001a0f7c |
|
MD5 | 4b3cc76a1d4d69b9ee3ae17ec042915a |
|
BLAKE2b-256 | ed793054a51d5ef03668f6795885e3e0d7e50d43b83b805b9c59934745641b73 |
Hashes for stim-1.14.dev1719978558-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dec543c55ece68ecea00f86362f3b267efa388ed6d686620a4d0ebfd2fb5f115 |
|
MD5 | c7a6aa70b0f5b83d22508b3b86ffd71d |
|
BLAKE2b-256 | ce91e733d4abafe4ca3fbc6bc4d2db00b20e434c0e01a489c06889f6d6e06875 |
Hashes for stim-1.14.dev1719978558-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d79268ee2ca1cd170e9cd9966d14f4dc83e3357e3bb42a820f717df65afce7d |
|
MD5 | 45cf6ffe5ec698aedfd7707da0bb924a |
|
BLAKE2b-256 | 715935da3a1b8287bcae6c282df148bca90e8eb8859b89dc774e564ad3b6bff9 |
Hashes for stim-1.14.dev1719978558-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b33c9a8f23cbdfa4802c739bab61bb55a7b44d1cacdae70320ed148b1d4572 |
|
MD5 | 486623ac88e97d85e18522397b9975f9 |
|
BLAKE2b-256 | 94607b70d5db56ba550e18f11fbe5f196c4c209992d4484d0a264ace20ddfef1 |
Hashes for stim-1.14.dev1719978558-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b03d879987a855c69ee8b8f1957e12820247897a0d78b27d6d161878daa618ea |
|
MD5 | 2331852e9a456261571227e296dd1a59 |
|
BLAKE2b-256 | a20bf50e5192f2ae1cc5fe1267112a45afaee1765bf56b69d130e40d80eaa0af |
Hashes for stim-1.14.dev1719978558-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 611a4cb9e0fe962e9b10d5c96d27852246c1f120bbf34b481a7063631d85e7ab |
|
MD5 | 74d8c0858b049eaf1f633c5422ad5671 |
|
BLAKE2b-256 | 4e4317a62ec176157f98d60bb1538774efb3a70a3b7fb93be1b2d52d27905d76 |
Hashes for stim-1.14.dev1719978558-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e9a62954ff3c48112f004058ee9ebae93142547267ee59d237281d54775cf12 |
|
MD5 | 97938231e8883d11b9cff49a90516c7d |
|
BLAKE2b-256 | 32df37b6c3c4bd141dffee5b77320ec5ab2ba11f9fbec25a4aa63f586825e3d3 |
Hashes for stim-1.14.dev1719978558-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc17a653cb6b07188ee0e61416cb95f5b4dba307a58cc527f6e22f84b7fecc2 |
|
MD5 | 1b4bc2de3d011d2ccaec65ac9bd157ad |
|
BLAKE2b-256 | dc1c49aa9caae8f559d9c7bc2896efdf29f2956902b073b9796fc317acb97994 |
Hashes for stim-1.14.dev1719978558-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a06492d6ca2681e7dee016a9b87eef67207cea812a900d371b5e71b2f4241d90 |
|
MD5 | 75e4d245c6838433ce16933333582685 |
|
BLAKE2b-256 | e4947f7691c7ad66051d41750cfa11e12c689c6970edd055fdd11b73a6c3c7ab |
Hashes for stim-1.14.dev1719978558-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd68f5f4ee2f2408ad9eb91a0a37be190d09b205f8e146ff14bdf235209db37c |
|
MD5 | a437fa0fbdc5cbf1e9001d2301ece7a1 |
|
BLAKE2b-256 | 362fb1a2ff9c035f61f4908ea74f7c7e5a708715fa4a7a5e453385873cf07f77 |
Hashes for stim-1.14.dev1719978558-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 881aee7eee750d79dd7157ab54bd0c4a3f9317122df77ce5cd397859a71aa866 |
|
MD5 | 64312f2b9ee58eac36d17cde88814c4b |
|
BLAKE2b-256 | 4a23e54c766514d79db17604c8de7edd25d46e5d014724d63d2c90a940448539 |
Hashes for stim-1.14.dev1719978558-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b633e356d4fef9e0e393379315115fa332c84d091f975ad3c02b4f518ff8b023 |
|
MD5 | 2d2298631220765cd0f3ac5f116b9257 |
|
BLAKE2b-256 | 1f75fcf7dd60bac8cdf0a9ae7e3f7282812ad706594412c4bea1d216b3bdb61b |
Hashes for stim-1.14.dev1719978558-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8740c3ad3ac125595111819fc0434c483f26dec8e11d40a5752ea0a5ff3c35e0 |
|
MD5 | 40f9cac79e5a108e8ad6d78186dc9b4d |
|
BLAKE2b-256 | a2c5c12d1ae0b585ed770329debc9a1c3391738a5026fd0424bf4d2788016685 |
Hashes for stim-1.14.dev1719978558-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ee1c09f41ae1b86510a66a5abef498b1a44aab006420a911d31a6dd10b338a5 |
|
MD5 | 4a9929bb22b5ced300f4e86c01f5ec7e |
|
BLAKE2b-256 | 9d904440654b2e420642be62d5b24558644149ce4a4e94f3a0bfe79f2458841b |
Hashes for stim-1.14.dev1719978558-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1beb72dd6b1bdf110df725da45adf185f04c7a15fdde88e7c9b6b44e6d796dc2 |
|
MD5 | 92b7347fa77776dc7123e4b1ad76f6f2 |
|
BLAKE2b-256 | d9f58acbc5cb2c9fe6990eca7c307a4e7d1a745901d061a1181d8f7a2396052f |
Hashes for stim-1.14.dev1719978558-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57b4528ff5d4e75d06a91c257aec3e6c4946d0f940c1532078f9003c9024c165 |
|
MD5 | 5c9be06e9f4af2c1d0553d7d97d3d80a |
|
BLAKE2b-256 | 29d1a3a7a37187ba95eae0e035c5fc5d10c81c94148c681cc174cd3f482a43b7 |
Hashes for stim-1.14.dev1719978558-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d97182fac61b34d63b2267e31d95be01393cec465642132ac826385465607c |
|
MD5 | 55615f8240b9e3cec799df46c0fc6d22 |
|
BLAKE2b-256 | c84bd940c4a5c2959a0d1ac35dd8f858ed16ec92a5500b0f874ae588f2902c1d |
Hashes for stim-1.14.dev1719978558-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ccaf4f8c3ea9c0b42e39279e67338d567a21190e1e8040b59c5ef1f9ce065e3 |
|
MD5 | 46ca3f1e24ca8d72e7ef81d83addd606 |
|
BLAKE2b-256 | 95a3651fc23c285beda92fe422fa2f606cdc032c013c97a0a92ece790f3b2c50 |
Hashes for stim-1.14.dev1719978558-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d2af4910e0977a5f4d57b2bb272ccc865bcdaee1d95b3717c445e8d073206bb |
|
MD5 | 9f1af13bc05dd28c7a9f9ff4eeb9a1f5 |
|
BLAKE2b-256 | b1aba1ae676590016050e65028b292e318e104e47809f117ac17f8e5fdbe0681 |
Hashes for stim-1.14.dev1719978558-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ed802d1201f5b18adbecacb406c7cbb65c24b63f557c329d5e324fa61061069 |
|
MD5 | 817b3798ced6eb4244f01baad24b31ce |
|
BLAKE2b-256 | 18a3456b2411753b80f12fb2b6a1fa2d7cd19ff7260cc6a35a74d9dc6da17481 |
Hashes for stim-1.14.dev1719978558-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85008d22366ad5665d8ada09dfb2a08077e531541e0cccc69f01918821db8b87 |
|
MD5 | 0219e0e7ae6cbe58da682b444e8b8f5f |
|
BLAKE2b-256 | 8ae936ee36406261283319cf1d089c3bc717017920d4fca3ceee188b1568a44d |
Hashes for stim-1.14.dev1719978558-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f6d7c20cbfaed1a86e45736360b575191b0045c2c5562cefb62f159a44b91c |
|
MD5 | 9a59b0220c0499298eceedcff4e87d68 |
|
BLAKE2b-256 | 21e0c4f7f8eb62c3b187c6eb8499d2156f5318dc3509f7022b01e34c1aedd2e8 |
Hashes for stim-1.14.dev1719978558-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24187a97f93937c6523eae766efc583acfbf75d55a5a1eaac9c6a686502264bb |
|
MD5 | 7954364cb8cddeb4a9faf5f6e7101196 |
|
BLAKE2b-256 | 1b9854a3d3715ec345e5329076db0e3e088f215948f2d9f9621f5e47d6cae91a |
Hashes for stim-1.14.dev1719978558-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6c0afc1fae307abcbed2ff39a858ee7652f98a3cca49d74c9c72d5fe0bc9182 |
|
MD5 | d8abe5bdd69a53edd3b3826062bd4c9c |
|
BLAKE2b-256 | 51510d451ad1f8aec35feb172d7c8215e918c975ce1e232a80fb40cbe805af0f |