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.12.dev1682880181-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9622044087039bad73d9d078d9b349e009adec540a983857b0860995c2b6e39b |
|
MD5 | 17fdef4d07a6c563d39e55a9e3f0dd1c |
|
BLAKE2b-256 | 614a976c0c0fe95e0e9e93310543b265a2c6dec8f2c6ea15d12ce98935540f8d |
Hashes for stim-1.12.dev1682880181-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 595a0064fe92596741c413d275711c8eb7d08438a9f6b80a47475bc0bb60499c |
|
MD5 | 23c8a7a1f0c6c0a1632ebc65e7f93d48 |
|
BLAKE2b-256 | 06b21a0d58ad1a332a0bc343d99342dd3c6fd989c77806820876d0086ca4fd32 |
Hashes for stim-1.12.dev1682880181-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db74bd8fa8bb0d20b798e5ff9a3ef9974f4f7acc1b91c940b52cc515a1ca24c2 |
|
MD5 | 7cc19eacba57be87f1ea72b0ff9233a7 |
|
BLAKE2b-256 | a50c99e48f48e23f06cc65e3f124453cd1c8fee6f39a4850cfecbc12c6e338bb |
Hashes for stim-1.12.dev1682880181-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce1f5b026fb052cb145eac929ebd1966578d368341e4af6b138b7b04c5567231 |
|
MD5 | 024b3972ed9cb19911c14817dba322a6 |
|
BLAKE2b-256 | b0c8cadd6859711151d9bb4ab1325ae3af012df3cc72d58fd55b0e0ef691e9fb |
Hashes for stim-1.12.dev1682880181-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521d4dd054e5895c2d1e07a32b4231680ba35090b5b07c4aa0be4cf10ede33ff |
|
MD5 | e8a8220c5dec14a77fdc4144ecf77250 |
|
BLAKE2b-256 | 7112b953d1445f668d809456af9dd0d8289856c60755ae8cf24d394b46da2190 |
Hashes for stim-1.12.dev1682880181-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8175c3792bc795a8130cb61420bc01995318886baef21b460be1d08ea0711ba3 |
|
MD5 | b321905a0bd6bfecc0ea23d6305c7838 |
|
BLAKE2b-256 | b2dbcdbbc5a26a6b9f166d2f384c6b54bb25624350aadf734c35bdb82446084d |
Hashes for stim-1.12.dev1682880181-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bae2a530cacb382fb9fc7c7c1ad36403452c0cde521d95d20bc47324919ccc7 |
|
MD5 | aa89a560b53abf3e7d16d30eadca6e97 |
|
BLAKE2b-256 | d743f65eb0a367a7fe6b777f381432884efd16cdfc0be487005e7f04cfeca0af |
Hashes for stim-1.12.dev1682880181-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 355b7bfef9afc792a1ccca95cdb58711993cff500e0292e67055166dd1bd9806 |
|
MD5 | 6cbb473b9e4a4d9ebf7e6e66d07a1ffd |
|
BLAKE2b-256 | 67b4da717a6b41108053dcb4675b74e09e9ec6780a440eead6d808bdf0c96e0c |
Hashes for stim-1.12.dev1682880181-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e465bd2de9246486bb1646cfdbbed30bbe3f1aaaeb95a96aecfda219a8467b3 |
|
MD5 | 5771317cbcefecc1f75f4410a4e2d734 |
|
BLAKE2b-256 | ab609e965e3cc5fc93d248ae91c95a247910415dec14ed05ddca2276f43cd8da |
Hashes for stim-1.12.dev1682880181-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda7f70040d567c0abc3dffb1111d65fe66fd154aedb089ae34561b60aa8828f |
|
MD5 | 425d3a2dc4e723db48b3a10a5f9c9b32 |
|
BLAKE2b-256 | f7d36d144fa6dffaa8550569ae4b9ec6f23c1878501b0b904ef701f0e7f6fcad |
Hashes for stim-1.12.dev1682880181-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4941547ecb11f9171fb87359c6cd2e0cf886bafa5d246021ec873376d26df2d4 |
|
MD5 | a0896ecc70e48d8c4c6fc87fbb122c72 |
|
BLAKE2b-256 | 28ed855a15be48f2d19a197068857d10717da68d828c64ae6f97aeee9bf11d0c |
Hashes for stim-1.12.dev1682880181-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b2a2b96eb9645433874c2415ed7405c261237e8f5b94f7dab6761307e6398c8 |
|
MD5 | afc10810a9e9e2b7f7b476b5d47eeffd |
|
BLAKE2b-256 | 08c11c302c72800d779e75fb2173afde8baee74e08c3085d15fbf39f324dd200 |
Hashes for stim-1.12.dev1682880181-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aae40de299e416847435fef532921d9366f13d39494261a10ebe7a24df32c45 |
|
MD5 | 3d3164985b1917e0f789f34a42b9b6e3 |
|
BLAKE2b-256 | d6a2b1ccce76993d6cb900379266a33e3b79bf13a21b57e40e4c45366e70cb75 |
Hashes for stim-1.12.dev1682880181-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab1796d97e1b5c6c901ef098ca3438685bd06f39fa6f2dfdbbd0a390f86314a8 |
|
MD5 | e274d36134889be384679261d64f17e8 |
|
BLAKE2b-256 | c39e48e4f1fd39d51a0c65f4bd2e9a0f28159ff43025384f3af9092d1cb013bb |
Hashes for stim-1.12.dev1682880181-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ad8baa6ccba6369f3f164dd3e4909a342f6ef2b51d52f5cbee594c5719a4c7 |
|
MD5 | 7adc21af7b5603809e38bffb35deb412 |
|
BLAKE2b-256 | 8075af3b46acef5e1dd3d1b3144fdfded53b9ce20dbcffcc8d756bbc0b2c035f |
Hashes for stim-1.12.dev1682880181-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 746493b9eb434d1e551e1b07454d3e456f0335cf64f179d444e75f0d1e8f2a77 |
|
MD5 | 00101f73f63e50a8d7aff1db49c2538c |
|
BLAKE2b-256 | 91fbfecce9f0f653ff422f00ba0b9191977b150e0991d9e22cab92e82c96e346 |
Hashes for stim-1.12.dev1682880181-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee4a7a047df5bdfa9dcf25aa066f21344a9cc68a22231ca2ee69a6b31746134e |
|
MD5 | acc8d6b9c03f25e5b1f7c227fa0b48c0 |
|
BLAKE2b-256 | e543cb3457eec2e106f1e4d20643287fcbdd0d8488d3425510f598ee29d7d590 |
Hashes for stim-1.12.dev1682880181-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 041b16c341bfe47bcfe62bf1ab5d2a9d6cda30d7ae662a8c0feb86454e26ef97 |
|
MD5 | 577e8cda5c17c7802421912d434a0d57 |
|
BLAKE2b-256 | c5c4fb60921adbede0f60966bf64503332a65ebbe78467e3490eb8ef808f863a |
Hashes for stim-1.12.dev1682880181-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94523730337887d5353577a3ef960412b808494359928518d936519462dc9b01 |
|
MD5 | 3335961f33bc7f8f410da206b5343915 |
|
BLAKE2b-256 | 3ef1e018d56da207507394c9c7b4a72df7f2e0ae7ce29e4ecb5379a79d33409a |
Hashes for stim-1.12.dev1682880181-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3ae08fe083568f101de27136304b1d999e47f9f4f84550a3ab9b9c368b1a93 |
|
MD5 | b11a5d1ef96b9c9f78e8e3ab1fbe1805 |
|
BLAKE2b-256 | fecb1a98916c4cc2088ca65ef8946d6cbbaeb1216cb2790391e439c707bdc6f1 |
Hashes for stim-1.12.dev1682880181-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ead70e431be89c882a5ed273f6a09968440e466d7af113d0ee387053b9ff718 |
|
MD5 | d105b70319e70513fbe86b5515d1502f |
|
BLAKE2b-256 | b21f920fac0b3c13083154155d3b0f089e068560e7454fa6a8957370e4d9d5b6 |
Hashes for stim-1.12.dev1682880181-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a363b7653cf4ca3f467d911c07eb900b3582d7246007a3f11135b3f65e7fdc22 |
|
MD5 | 6e6c85cbe23b89d11f3bf1c9df9474d0 |
|
BLAKE2b-256 | 488b8748aec69ba01be63a1579addfc9f269b5bab3a677b7d0328934b10d229f |
Hashes for stim-1.12.dev1682880181-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcb0a66e2e51fe44f24b9c7897539df9ff266728488c5a8ca3a1da4a49ff008b |
|
MD5 | 76301e9470ab1b7b155640bc4c1d6fc9 |
|
BLAKE2b-256 | 151f1e0d6901946758b1d2a43b67ef499dd1d7707aae981a2cf46e6a54d63bb5 |
Hashes for stim-1.12.dev1682880181-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8eed7bf8713765361c5f469d9fa29f711462c10c5a87bd881bf918005bdbfec |
|
MD5 | 3a7f2e50da78bc0a3c63a89699058f27 |
|
BLAKE2b-256 | c14b9ca8915ed3047ed7c05ccc89683cf608029fe53f0413da5be50d0814e317 |
Hashes for stim-1.12.dev1682880181-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aef6ca45b7e4e12afd55b989a3f43dc0b952c0b43a2a6a35daac9b79abf040bf |
|
MD5 | 66f85da34b1cd64e9f52fe19e80405e2 |
|
BLAKE2b-256 | 24bd5838b4f4653d144d985c3526329ce0af1baaafd6ce99b6373cb8bc3912fa |
Hashes for stim-1.12.dev1682880181-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d055509792afd062cde2c0657e38745d2a8b0197227cc14ed7678df7eb062fe2 |
|
MD5 | e6369aae191f5c29f285ab037b705f7a |
|
BLAKE2b-256 | e92d524c4bc45fd2f6d0e72b9a1ad7d1acaaa447f869ecc9fef9027b381fbd47 |