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.dev1693008283-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69c595a0e6ef9322853db53742dddd63acaff0c1ba8ed0332f4c66bf12c25fe6 |
|
MD5 | a53558bb66fe1bde5c49b3d3a7180177 |
|
BLAKE2b-256 | c1e78a778533784f159d150fb7953cab9c2adb304b922dc443c176bc878c2709 |
Hashes for stim-1.13.dev1693008283-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a68f014ab5fd6b088996ee13b948b47b8352f589ef4b913dcc916de9a849287 |
|
MD5 | 4dec12d55e680e353fd0471b6b9e62fd |
|
BLAKE2b-256 | fed7ff7b9a441080b94d90a8c7ff00552fea7db7227b66795f8094541a08272f |
Hashes for stim-1.13.dev1693008283-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5daf077b9977b0f787d2ce78f9e1fc6c2a37989d08ad4699bc9a9324b88a4dee |
|
MD5 | 6b9b4ab5663ea0b6a110f3fe5e283184 |
|
BLAKE2b-256 | 4bf0d32127ad13484382f1a054b5882f2f3c645a65762d1facc9ffb1deafac5f |
Hashes for stim-1.13.dev1693008283-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d14ef85aa346b70de0902e7ef5fd661c996e3d35860394436a2e90fe142ed4ec |
|
MD5 | 4d01af73a23e9164aad7f35deabedb31 |
|
BLAKE2b-256 | 736fe4efc04c8514fe3cd0ef5f4db09e8c3ed619e2979fc51106d40451d445b3 |
Hashes for stim-1.13.dev1693008283-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82fdf0ad3a9ca20ab75cdc09a799a9402a5fea0d95edd6aa76906a520659e67d |
|
MD5 | d221de2dce3ba295441425e1141c17c7 |
|
BLAKE2b-256 | a66cb23ffeeef96376ca18525322784acc8f5657c37c6fb694933a572263952b |
Hashes for stim-1.13.dev1693008283-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31c074a65077c7e5b8d942c4374e1c3e4c4de7073d2ebc35765f0167e9ebc0b |
|
MD5 | f5abef2a6332a748497494911a16ab7f |
|
BLAKE2b-256 | f1702775a232c3f08b34e880be3203f56a6d25206f36f7d21719487e95febb87 |
Hashes for stim-1.13.dev1693008283-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4954d665229186892899615db76280a49358095b4cc290e76440d55673b27bc0 |
|
MD5 | 6f811bfeb84304f749ea10a8467314ff |
|
BLAKE2b-256 | 12890766f11a13544d3fae97ca0dfc22e129c717a62082400efec3fc5b595f7b |
Hashes for stim-1.13.dev1693008283-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e971fd0ec75ef40fe259c22ed714f4d7995a73a3c5a42fd8aaf78c5605bb2aa0 |
|
MD5 | 4684850f8001930cbdad577a18a23446 |
|
BLAKE2b-256 | f9d4259eb4f3728fe7a2920c451de51b19e0a0c84851a4efe6c214df016105f3 |
Hashes for stim-1.13.dev1693008283-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76852d1c6abf48b4a1ab1966aef1fc1c0b701753b3a518c29c9ba35f93c95288 |
|
MD5 | 91a62b04b5034b8f53878a814fec1f07 |
|
BLAKE2b-256 | d8e5a35a6de673bbdd2d64d73333ac30e1440f2ab06e946187148510aefa0775 |
Hashes for stim-1.13.dev1693008283-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 683f9e31c169b8266bff0bee1f0f076ef8b35f4b2701eded2564aef3b26a1cbd |
|
MD5 | 96afdbab70ca54011fadd4f81e0a1661 |
|
BLAKE2b-256 | 40d9c6a136d02ee303f9154d0946b5985d8445045d7cca2b8d8c1371b37f1ebc |
Hashes for stim-1.13.dev1693008283-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2f31769390b0a74d1829c16d2eaa4d8969923e2e8f347585531a25d974e6dab |
|
MD5 | db691f35d13e80cbf2fe24d499712a8d |
|
BLAKE2b-256 | 4fc5cc1b1d91a3492ff3abbbb0317a71abda8b4a7ea279a77b2f274e9bb5bae3 |
Hashes for stim-1.13.dev1693008283-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e20b47ced614dbbc9f545df525f5cff9c2a29ee23ed62be2d96197ab2c71d588 |
|
MD5 | 5a9da5c9b50781404a36c572460807ed |
|
BLAKE2b-256 | 0934c72ca8390fdd2e57e8c185993041aabd9620d73a613212644c4de42a1989 |
Hashes for stim-1.13.dev1693008283-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90780de0fd3b2c873e7bc72c370be2309b5b32f2270821442412cf012054d083 |
|
MD5 | c440957f0ec7fe66ba4c92a4da445a1a |
|
BLAKE2b-256 | e23a9e9f0e380e2dd5209cc70b30b034f9bae3d2a294054855246bd4fdfe98ef |
Hashes for stim-1.13.dev1693008283-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8366dcca6ff05b5dbebdc87e25ac00347eefd0add4c4c7d3aaf6931030bfe5a5 |
|
MD5 | 7d56782e74cc04490f6b9336b19eab74 |
|
BLAKE2b-256 | 8055c82d3e49bab89153cdef610bc7478c542c09fb657b1f68f30c82b7437c89 |
Hashes for stim-1.13.dev1693008283-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f709025422df7476ee6645dc8c65baaee95e57e6d55416ea463f0cf5fb8a3b5 |
|
MD5 | 1543e03c6a4ccaa5d23d6ea8734a34ed |
|
BLAKE2b-256 | eb28efac9deecbfeb0987995d9b047293e1c2ba5d6c33c0b51309ecd93a8c354 |
Hashes for stim-1.13.dev1693008283-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3b0be033bd47149edd9ec94db4b14c113bb99d0dfcd49fbf3aa4d000a2ac418 |
|
MD5 | f96bd52bb20222266ba09715aef95f60 |
|
BLAKE2b-256 | ff156c2d3904b2c2b6f10931b2b929fd1a92b556ce6b5ba763924d2f1dab475b |
Hashes for stim-1.13.dev1693008283-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77e796ae267274ca36313bc90b606bc06371c25aa325a82e179403985462ee37 |
|
MD5 | 683d14bb1dc42b84679739be99bdf7fb |
|
BLAKE2b-256 | 354c0019424dfdb51d2e428448f59f377414ae04f4c6f9c8f2149bf6df4897a6 |
Hashes for stim-1.13.dev1693008283-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 974397b55f58e18b192d8a64c8b6d357b186317c2b86e5c52e92d135830603e4 |
|
MD5 | 69e84bbbc958e9de4dfae4055dc93b85 |
|
BLAKE2b-256 | 64845c248a3ad088dceff350f9acd4c9d9261b7210239f19e791a5469f31ae0a |
Hashes for stim-1.13.dev1693008283-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec61d86095f64a12d0ab5d1baab9cf9ee99488c7718f5b8426b04d585258f506 |
|
MD5 | 633798f2f0e18b673d7387cf7d3e43b7 |
|
BLAKE2b-256 | dd814e7e601671708e8d4d851532177754a73b85840d8c8f527d8ac14801cb2b |
Hashes for stim-1.13.dev1693008283-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b44df42afa94f7783fed40bd4b9469d27b4b983586c82f937cf6fa6f575db5c7 |
|
MD5 | c4fd50c88fe041684bb3723e5d327e6a |
|
BLAKE2b-256 | a035179b3e5ec99915e0dd6efbc1b4467a2c9fb16c83cc2982ac98e796c8d2b0 |
Hashes for stim-1.13.dev1693008283-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc02290538aa4e20b5c1102d1deb71ef709b69d20b75d4b71ddd963f22df7eaa |
|
MD5 | 5a7839349c19053d89f3f47a30554f5d |
|
BLAKE2b-256 | 54217815af062736b2e151c5fde4f29c56dbf020b9b07245b74c6abbf6de0251 |
Hashes for stim-1.13.dev1693008283-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9df2ec9178bdb0d1b13c9781e1a6b2344aff8bb940638a2cbb89ae5bbe96dcfd |
|
MD5 | 82dbf62065a064a226b0010b24b87685 |
|
BLAKE2b-256 | 117e080b7f3b92719dec25cf06682037a3803e7be8fe74a3c3fda366f8f4ce21 |
Hashes for stim-1.13.dev1693008283-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebdf81738da7223c6ba469d6f9716ff1ebb685d4d7f08ed8e9b47ad8e6fbf14 |
|
MD5 | 1de54deb6f516eff459f2af11fe0de71 |
|
BLAKE2b-256 | d790a5a1466faf4345378479a7a59b582304552fa85f1de05626c66bcd92754c |
Hashes for stim-1.13.dev1693008283-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cb9dd6e52def68b450ded8e9fa5ea333edef06c2dd205bc9860454ae2ca1bdd |
|
MD5 | dac75e44b45a1cb42268d8094d6f0947 |
|
BLAKE2b-256 | 2ff079b289cd52a2e5e015dd0c05cfb7ae2c1debc8081a14e50723a29a2b17c3 |
Hashes for stim-1.13.dev1693008283-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97b64a408b95f10ab30583be456fc79985473194001ccbeaf5df026b0db76200 |
|
MD5 | 420128d2f497479f2eb1a06a1cbd708f |
|
BLAKE2b-256 | 6d81242b534398dfaa8c7e95ec40febaca5e14aa8201088fc09815e0b34b008f |
Hashes for stim-1.13.dev1693008283-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd4bad859e142cbd7b1975c38526858a8550afb9eeab71c00e3b4572a68316e0 |
|
MD5 | 0595f41ac876b6fde2ee06f87ed35ed1 |
|
BLAKE2b-256 | 900c3059fd62b869aed9b2fbea4213a927cfb46390f8552a7cfec176f057c103 |