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.8.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97af1409c23b50f1a818c0034acf027fe47cf4e5479ae03e2c7a15770b8faf9e |
|
MD5 | 08a5e659c604b8e2966429804a837740 |
|
BLAKE2b-256 | 59bc20e88dd3e6bf697172ccd234c9d011ead71ce37d6527bf8cc5091c53e1f2 |
Hashes for stim-1.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 556a7f1da16c88dd321d1dacea6af9f48746da54427472c71af4ee6cc9c3d524 |
|
MD5 | 78bad93ff520ac5b96b407e14280df3b |
|
BLAKE2b-256 | 5d5a8c07ef7ad95928c68059f8e7e626d0db7a720781b0f398898ff805f21176 |
Hashes for stim-1.8.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e2dbf5efe27879b7ae359b68baa0b171f2927e6e9bb7bb7abe87401265a034 |
|
MD5 | 9021b864e8887d48b65b775ce67a3e89 |
|
BLAKE2b-256 | 0ad1ff059f49bf3a32f20fe002ebe15424ba1fc8bc6812246a1f0c27b47d9594 |
Hashes for stim-1.8.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ca170043ba579ea0d4c27f6e2104abe67f05baf9cb2a031d7ede7e09badcd08 |
|
MD5 | a322cec62be876448dfc451f8b16be55 |
|
BLAKE2b-256 | 77e1ddaf01b1dcb2385cfe21858a3c0dfdb91d1b00a086bd4d8d101f60d12211 |
Hashes for stim-1.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0101f9226deaba9b4046301401de76adb5b55955f08c3a7a698d489bc2bd32 |
|
MD5 | afcc6dd39c4e057cd862df4350159764 |
|
BLAKE2b-256 | a272ba9b2c50df29b1b4d339b0d6e2d4b45121b8180b4780af3e7ed0599021f0 |
Hashes for stim-1.8.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a094daea9e519de58d5dc21b56faa0e7e029abd8bfb8662c8adf23ba31d05c84 |
|
MD5 | 608c4231e532fca619d777e1471335f6 |
|
BLAKE2b-256 | fe58d9bb6528cde66cb218b689e22d8f8f8c9238cc2bab7ef03b562428dda245 |
Hashes for stim-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bce745b4fc6a5b14efc668e67223fff5cee641a41aa3a5e1c95d6c45a515979 |
|
MD5 | 35cf3e66afb5963639a8e25066edf7b6 |
|
BLAKE2b-256 | dbae00d69206b46fb068769b055e2d4e37978c1025e4dde1ae023aac84779c1a |
Hashes for stim-1.8.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40b40e9df73a9644045e433eddeeec7ee397872ee39a1ac8ccf3146498d2f00f |
|
MD5 | 294ab4183292f912336f7026b02ddfc2 |
|
BLAKE2b-256 | 34af2072f959f223271efb3c8765a24847560dedba8a84e522e4e2d54c9d655f |
Hashes for stim-1.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bba95c78ef18c5afb380bb82bf52dbdc538bd849b772de359c5e501754eb133 |
|
MD5 | 85f3109e0f068101f510c1709f526cd0 |
|
BLAKE2b-256 | 8a99a350177eb957ae5b1b237b76bce85e02b593afe894f1b0d384d7ef4ecc24 |
Hashes for stim-1.8.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c6af800a984fb6efb20175cc48e351dd670715a9583d1353b855dd7e3899012 |
|
MD5 | 2ea6feec458caf24c1a66e5c1c77a02f |
|
BLAKE2b-256 | 71a2592f6dce088519aea00219e8a438f009a8695b226105b2a58cfde8069b9f |
Hashes for stim-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f83238346dcdcb24dcc33788383293a504fc5f1bcd5b0e48efe58b58ad86cd5 |
|
MD5 | 9f9c5a5cfc15369950a7f4130de0f1e8 |
|
BLAKE2b-256 | 2de350ffabba9f1b440bda858d1eb610fd0f02fbfe5da2e021623d4a4647f9e2 |
Hashes for stim-1.8.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf1ee20e4d713d69bbb037142139b983592333852f3f817af7be2c17010e86d |
|
MD5 | 6b81194c837eb137584713086831074d |
|
BLAKE2b-256 | cf38688e82b1340239d2dcde68ef7d2ee6c65b5d4a86affe1f82ca05d4f314e0 |
Hashes for stim-1.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41f3112cb945f063299c067fe234a2337b2b579afebff59c13615bdf7edc2279 |
|
MD5 | 5e7f98dc323b17faf8cfab1f516a28cc |
|
BLAKE2b-256 | 9c1b3d8c836ca949afbd504c7641e7d9a9e380e8746f676df4eea5df3fab1325 |
Hashes for stim-1.8.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc5c756e7cfa7c5ea1b382a5a35a7dd4823b94a9bdc7b89fb08a611655bb34cb |
|
MD5 | b4d176f0136164676e2aa379c699ba9e |
|
BLAKE2b-256 | 6a44b0df2926f9115c8b9c849459cc1bc0f5b38b08efaa47b186d64849516f71 |
Hashes for stim-1.8.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b249515402542281445dfad9db692384c83adb31850e34673cbcbe21cf6bda6 |
|
MD5 | fc751f6ed5cc53f262ce26ac049a5e5b |
|
BLAKE2b-256 | 5349fdb4b207f2b22288b465d66a8ad02d6b2703eba63d0660e43218fbd04697 |
Hashes for stim-1.8.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0b4fa85e966e29185962583b4816ea0b0af77039a9e366f0e01d70f97ce43e7 |
|
MD5 | d372368208c84c3fd6abeb13e51f8ae0 |
|
BLAKE2b-256 | 3f0a8e7d7c2bf721c61b57e2cf6924ebdfe220dc882dbf2ce20bbc32a0c33166 |
Hashes for stim-1.8.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e27180f9aa2979acb4bdf457ca7610886aed97a29b0a6479f7bbbf43cd3f2622 |
|
MD5 | caf40b7bc38b957caefc5f1d648a384f |
|
BLAKE2b-256 | ba5c32e968f7d01187426e976ad259ea464342cd6e18b59a82da7a0d82b35864 |
Hashes for stim-1.8.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e34d090573f2edfd8c6b21e048c8497bdde75472241153b2efd11990291b1315 |
|
MD5 | a1a258b5c861c523d11f788cb63e7f4e |
|
BLAKE2b-256 | de4f812055d5d2a4d5c2d2b4fae241a0994e1d5c2a13a3fe0d5891c48cec7718 |
Hashes for stim-1.8.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60d71d3c14da09b57a59b3c4df9c513822525b64ab000f7de4a79e14f0e62a2d |
|
MD5 | 9cfc6323e9bc76b4d452aafbd0a3f878 |
|
BLAKE2b-256 | 433d72a8d2dfb3e9c1a1f41bcfba536c8febd7b3d14fb55f121b9add8889ff33 |