A fast quantum stabilizer circuit simulator.
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_operation("H", [0])
for k in range(1, 30):
c.append_operation("CNOT", [0, k])
c.append_operation("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.7.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dd2f9542d2b432e89cfa190668cc4db08a4ad05c8c45a280f9a936aafc1e1d1 |
|
MD5 | 7a709c5f5026a09a89184d34d5b50398 |
|
BLAKE2b-256 | e1114d9498347252403cd6188a8260aff481b9ee87022335110a2cfd5fc99fdc |
Hashes for stim-1.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa64c4426e72f29b63998b4f09c162a5d52abdb8754620d59945b92dcdf376d3 |
|
MD5 | 368efcb71599de6ef6230ed395a017b4 |
|
BLAKE2b-256 | c109780d35fa2050397622619a30a7aa934fe4dc70091a7fabfd0e305f4959ca |
Hashes for stim-1.7.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c3d66cfa63680d377786c00ca4e3cf00afa2af6e8805ceb86751f58236daa1 |
|
MD5 | f8839dd32c4326adcef72c386d8f7ada |
|
BLAKE2b-256 | 480bb1639b913924fdd42fa115b71cede6646b7d7e38698d7f19f20eb41598a6 |
Hashes for stim-1.7.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e826ef734801a766ae0d1a73f0c8bdadb2c4868b0163334553353a0cc2a18d67 |
|
MD5 | b35bb3f3132cd8738dfa33ee1d6a5b56 |
|
BLAKE2b-256 | a9899ff2ab7c5c1c9925c8e9db295bd5da58441d331820bc9dad0867b4367b3e |
Hashes for stim-1.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77cffe58fa6e46e2cfa6a6258aa5fa86ae689282d66c5b19d4bd1f390c738b16 |
|
MD5 | 9748e62b295fe202ffd015c9f949665b |
|
BLAKE2b-256 | 54d7fde03453d3334eadf54ee81b5a99d061b111935766c1b3bb7434f049786a |
Hashes for stim-1.7.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29385ec3ba321e9230624649e7af7885fd5a291019b8c9b1512685ebd51298b4 |
|
MD5 | f817fc338dcff74d43dd6e279212d96d |
|
BLAKE2b-256 | b0763fa74875a00c4047c7c7837f247c1552e409ecc9e1f094c98a1063298225 |
Hashes for stim-1.7.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05446ab3ac17f17e2f93a0ee18730fa13a6fbcc9c343ee6b475732eeb23776e5 |
|
MD5 | 0424feb175fd40be29d73539713e641b |
|
BLAKE2b-256 | 41367e0608fee68047e88e93f31f193dbd115936c58eb2a9224353ea48bae1ca |
Hashes for stim-1.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e04370856710502a9ffaeeab4164b2af17d128596d3abf80884f0089bdfb5ab2 |
|
MD5 | 0d875f664cdd32e10e382c9fd0820a54 |
|
BLAKE2b-256 | 706b34edcc6ecc5fa36df25e10b478afa4a64db11184db34ec231be2a4a3d40f |
Hashes for stim-1.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172f062f597aba070b11831ee514cb784e5fd3244475a471b95b93fea795730f |
|
MD5 | 0308e71ad3b7d1437496bd6505a29b93 |
|
BLAKE2b-256 | e1de10e9eb369f15de0d30e3d9931c0a9016b2b7f49950554040665c9f384e3a |
Hashes for stim-1.7.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8a3e4057f2f169ea4d3ccc003fca217a41e1a070986229c700ed93c3f916a13 |
|
MD5 | 5ebb84c8d29391d9ad2110b6f02a62f6 |
|
BLAKE2b-256 | 5ab2ca2134e7b48acafc3a013ed9ea7698a2bb582be5ca6df5edcbecc677fda0 |
Hashes for stim-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd781c7b6079e5b851be4267cf9e87edb41108a9a25214fd66fb5795f18365e6 |
|
MD5 | 3c212928864d653b3a40050052344b7c |
|
BLAKE2b-256 | 338241d16b3f881d5b84e2e6a8c1e4330204cf49854cee50255e87f8e4113a7b |
Hashes for stim-1.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13ba2d9095a0e80b73b76c8650bf6f391a7a5c64b5d09d908b2021055c5eb93 |
|
MD5 | 4a45e294440f26c343f899f04463cdb7 |
|
BLAKE2b-256 | c83d37a67c5e7aeb9414e9031ddd94db2609ab7836da330e60ec0b23182eca10 |
Hashes for stim-1.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b58174094e859a02ddc907ad9922a45a03d7554550969a1b799bff7ed789461e |
|
MD5 | 6f965f9a512e695a7977dac67f590787 |
|
BLAKE2b-256 | 6b554ce03bc4687350430662ab159368ce91c6f1f22eca60055526f02ae71c63 |
Hashes for stim-1.7.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 059343a892f2fc5fa24b60a55439cd92f40a3695f2f8dd728b6279045f078dad |
|
MD5 | aa9680b59c173820b8e18617ffca1b74 |
|
BLAKE2b-256 | fd2ae667e7cb14db36331bf21da8e26e2acf82e2a25767a45a183e33d6c2dfe4 |
Hashes for stim-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 769e6d60a6342e134c946f9196b4ebeaf3494d851a6ebcd8e89f75f9768bdec5 |
|
MD5 | 24a9622f75499a7745b294721352915c |
|
BLAKE2b-256 | ea16e0f060d826697dd8d87abf05cd65341211edc8433959da8167ac6eda4ca4 |
Hashes for stim-1.7.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 057e66886a874d19b1021582d19d5de5dd5f54c518a86c3c83d9f5aa6e5a6045 |
|
MD5 | a185e6e6cab0d26b2368eca689637b32 |
|
BLAKE2b-256 | fea322238f0d86e1fca7301c2f0b72e3f710ef5e1f27d82a6361e247562805d3 |
Hashes for stim-1.7.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38071176f9cea2572e2d380b58bba3ac8cb8174599efc92493ec31c0158c5bdc |
|
MD5 | b8223fb5cc9c328c49716b35a49e9077 |
|
BLAKE2b-256 | 7d2a9a8da2d82d0ceb6ca3a428bc7afe2491d30026fc25b3898aae3b9cc5fc3b |
Hashes for stim-1.7.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e5c100b9fe244b93a0bc7815daab2acbabe5740843f6738605ace2ca35ed5ed |
|
MD5 | 625533f7917c2887d0f6597e9fc9e680 |
|
BLAKE2b-256 | 4340f54e24d76c0d540d1cf604db24e0599797e7a3942d1d3483c4487805c606 |
Hashes for stim-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73573b70ee0e2206982ad10490781d48e5378b81a2efaff0d36e324ee4191c9a |
|
MD5 | fdd7bcffbaf44a48dc0c0b99ea2b8503 |
|
BLAKE2b-256 | 90a71999ca28b9426cdefcb275fbeaf7ad515df64742554cc860d877e60b2465 |