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.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1e6927aa5d28d8fe219b50235ab966ff0c80d1b6a4e71ee0d0c2229c0c14134 |
|
MD5 | 4baa438c334a107b20f14264fb7cdf43 |
|
BLAKE2b-256 | 94a42c8296c10114d97a9dcfcd2a3ff2434d4986f88cc33e51e3f9715d993894 |
Hashes for stim-1.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78b392783975cc9567668877fd745df1d66d38f8a5414c0e21a88518d3e965ab |
|
MD5 | c6e28d0f1936a345c9e9a906e24f30c6 |
|
BLAKE2b-256 | a9aba71994baf7a94517ff16768df6728beb387f022d812bb10dc2e4024c394f |
Hashes for stim-1.7.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da3a5f892a0a06cc82af040797d8e786d331a864d4b717bffc854dce2dfd83c9 |
|
MD5 | e1ccbe01383af5acacbe44d10d6b1f66 |
|
BLAKE2b-256 | dd0097ba17d089af30c43fd66b09c305683107dc3adf077a25d437f0795becee |
Hashes for stim-1.7.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2da4f4dce3bb14598f7169abea6be4c9b9ea09434be3f9fddb9628075ca3d1e2 |
|
MD5 | 5a495093b12434c82687eef19f3cc0a5 |
|
BLAKE2b-256 | e714d1f3491c622cffa1d8bb5b039ae1284966c1304f5798123a281c23025efe |
Hashes for stim-1.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bbe2d5715242590d3412d5f9423e3f04acd45147f954881ad15bbbd6ce40c21 |
|
MD5 | ec8abb92e4252b1d7601c79088225377 |
|
BLAKE2b-256 | a7a9ac4aa985e15d1fccd04e10b04b39f278392eaec9ff82bebdf36f88270422 |
Hashes for stim-1.7.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9b471277428b6aff24bb7bc42dfad7bb968a57fbabefce789c677cbec62589f |
|
MD5 | 7ca88908054143b3eeeeb2e33eeafc19 |
|
BLAKE2b-256 | 85b04e3ab481b86e18e3bdfa16b0401505b84e0398cb55ab30c46425cdab927e |
Hashes for stim-1.7.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd4ece839c0f42e61b624a262471b2f046d24c9eb23e2e029fcf14039fc0a7c |
|
MD5 | aa71dd42ad1e28feca3d227bba4186d1 |
|
BLAKE2b-256 | b75fe4734f38a543fb30f7a3932b1c3682949a2d21eb71fd303129e79f684ae5 |
Hashes for stim-1.7.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4031f74d9f6d9d91dd0fcfa1fefc5b6d7bb27661608c4219422cfabde9f9769d |
|
MD5 | 90388955b3529004e978901ebd02707d |
|
BLAKE2b-256 | 57962d5318eac86b23a2fc2f77097e7c9bb544efe2653b70995e072bad1c7e87 |
Hashes for stim-1.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207eec3592e37be8100eadddc011b50c151a7060479f16f6cc5981d98ef6bcea |
|
MD5 | 38655013444751fe50cb4c549ff40417 |
|
BLAKE2b-256 | 08c1a657aa5ba163148f59962c5696621e494e5884be271d9fc666f7c23f27a4 |
Hashes for stim-1.7.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9df35d7441e1e7e20ea0356c21aff39c9b9256bc0bb9cff460dbb5a42bfac883 |
|
MD5 | 09a67623089f2732a27cc381928eb5cd |
|
BLAKE2b-256 | e9126d43e66cd884a4629f84049fbc91c1056c4847e08f3a6e724ec1245090b8 |
Hashes for stim-1.7.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81ff319337e1fac17bf1f9275154386d2e0875b6a1b91b7af712984bc9a049c4 |
|
MD5 | 15ac891440858d57d399ce3d919f4fb2 |
|
BLAKE2b-256 | ea7ecad3984bb2e15a27279574a3e36c8019c33a8ecd2699436ccc7e0511a6ea |
Hashes for stim-1.7.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f15ee3a1a5914468addccc90a772a9790ee246c49e6b99b05c9766636b013dd |
|
MD5 | a93b64ee3076159c27c9ba14587fc156 |
|
BLAKE2b-256 | 8be4fa53c7608a33598871f46f363a30fb323ecf97c5924084a4d6b851a65b34 |
Hashes for stim-1.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec5f98dad30faa309d3437e2fd7d88175a319f6a49a41362376d6dcabad0bdff |
|
MD5 | f2d87dce5f7cfb234db5284177bd969c |
|
BLAKE2b-256 | fd08fc54ddfc922256bc4b435948996767d9ba9809c76d26806945d748c83d53 |
Hashes for stim-1.7.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27df7edf213301c603aa04e70afd8eff3b89e0b9da7fff55436e73a9054b7b9b |
|
MD5 | c59ede1efe4469f3893faa6b7087fb57 |
|
BLAKE2b-256 | aebe19f643a280ab162768a7520b05d4e4290b387b01b8a6b75be184ffd37476 |
Hashes for stim-1.7.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2016d4b6f53247372557072bfd0d46662034cb8d6c486b16a6f3b008d2d0ac9 |
|
MD5 | 7af62a099a36ddd14202d51ee12f8c8f |
|
BLAKE2b-256 | 6a9964594e4552600e567df0022b8049c8c531e2f9359438cf4672359860456a |
Hashes for stim-1.7.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0453ce171d02411b531278a4821da9b99e181bebc2867f4cf8ee2a0df52f61d |
|
MD5 | f58888088eae1d9e6c283fa07ae1bcd2 |
|
BLAKE2b-256 | 39c59a26a9927ac2e4cd37b983aa6a2cf20e4d5279db5a34dab1ab99fc011f02 |
Hashes for stim-1.7.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 267af02ee1b1e8f19ec243c09936088c758c49839512796a9b6ab908fc3ffba6 |
|
MD5 | 0cb0c4f1cab51722acdf9c4791e19160 |
|
BLAKE2b-256 | 4b0fd1f05b3696c6864289a626c60c3d839fa72b208a37c3faeb5a38ce39d176 |
Hashes for stim-1.7.1-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f5fb534b07fbb42ada046e803447ab7cbcf931e3d4e4772c133cd493886ba4 |
|
MD5 | ceb40ff58056a2817c41203fe82918ec |
|
BLAKE2b-256 | bb351f0526dd500f015ef43ad2f356a60f26e1f1860acb4232e07e1eefb12361 |
Hashes for stim-1.7.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c67b7b303ea7b3f05a482a54fe04888e408b61fa13817fd98f47c43837f71b |
|
MD5 | 444a877fbac535f21a6c5892f6bfcbb5 |
|
BLAKE2b-256 | 855d718ad577a6ee86be0c6f49fe31b3f5ce543672d4624bc8714afbbe7f3842 |