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.dev1693376963-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82530dad9fbb7d40fcc1dc46fc1b099390e8e54cca3d489761848c6bd9d32449 |
|
MD5 | 1cf74a1ba46d0b9f6eb945e932ca49eb |
|
BLAKE2b-256 | 5f68a32eafcecd891568f50de7d3c9b379c91a7fb89307d00b98c952116e07a0 |
Hashes for stim-1.13.dev1693376963-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 177d68b45579395d0136517b43502e372cc7d39271f5bbe193fd15e06c522576 |
|
MD5 | 85d0341da19ac9f3ad67ff9595596c48 |
|
BLAKE2b-256 | 278193f5cd8266a99868960f2582af7c28e2b831d6e0e650244d2c376b80ecac |
Hashes for stim-1.13.dev1693376963-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b20d04fc9619bde8becce0752ab6d4d509c983ee69f70abe2ae61f26af495573 |
|
MD5 | 060595e2469f897cfb99f652ae075bf3 |
|
BLAKE2b-256 | a57af5a6538846709330f68c876091b12222dba54aba700fd03ea32f7ed2864f |
Hashes for stim-1.13.dev1693376963-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c43106f3dd2431ecab3da89b790c26953e43b6ec91b98354b2ad60884caa6a45 |
|
MD5 | 8c9bcc93a86960587b06dc41f3641ff0 |
|
BLAKE2b-256 | acf88af0a9b0c0b53bde336086f99b4a752a7bfe9c6bd09bd37e24dfa1bb9407 |
Hashes for stim-1.13.dev1693376963-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3360b4c1ad6c25bcd2775e3fd43bffebb3fea5bface06766577aea0dcce9a2ca |
|
MD5 | 0483919f812ce556eeefebdad330636b |
|
BLAKE2b-256 | f92ce3748aae10b48f0e98eb62b642e0344cbae24aba73150f1fac5c615b97cf |
Hashes for stim-1.13.dev1693376963-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e6a0cc56bb949c03e29fde20f26d7ea0f4249fdeb8f2becd7caee1b456940ab |
|
MD5 | 9b2235ff34980237e98761eaaba63bc7 |
|
BLAKE2b-256 | 56620b7f8641c3be4b8a392d0f6248a288a89c068a1548c6213c737c5a42eb64 |
Hashes for stim-1.13.dev1693376963-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 675b11dfb99b4729b45064b6a72595f14c01fbb7eeb9ca985c9c5cf5cb320bbc |
|
MD5 | 1313c4ddb6344288c50b3d8fc3e93403 |
|
BLAKE2b-256 | fa679ff29094d5ec8d788560afb9c600c9bda7279b116fda8a0b90421687e4b8 |
Hashes for stim-1.13.dev1693376963-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b007d53f89aa143b7df22fdda693cccc459d648db1c187b1fd23545a28fea627 |
|
MD5 | 16bd8bbf49df3d3db24139af92144b96 |
|
BLAKE2b-256 | 12fc1e0a034e6bdb3ae9416b3a4d4f7978dd53fc040bf6fb050a600a968bfaa8 |
Hashes for stim-1.13.dev1693376963-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af2d49e9312fd24ce1fb52cead18fe0f401583696f51f1852856f396cbedf6bc |
|
MD5 | 47cdc22e2758b0a615b1bffc24c225e3 |
|
BLAKE2b-256 | 212737807dd9c9a4db6324d5e2df29bbf6de898883bb3922fdf825d87bc878c2 |
Hashes for stim-1.13.dev1693376963-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d48bef35bc71a55173ec647b82b97576aeb1c419ea2460598475cb75abf32035 |
|
MD5 | cecf455145c65ad80f12ada4afee91cf |
|
BLAKE2b-256 | 95c6d306ff64b7ea6caa4957c4a65ac4fdfdb5fbbb9a2930bdddef2d2d41e632 |
Hashes for stim-1.13.dev1693376963-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f38615929bf7ea6e03c336142ce44ab0b4c1d5022e044b8edf34bd565694629 |
|
MD5 | 3ee8a79f4f6e9c0bdfbf3c3233c79d31 |
|
BLAKE2b-256 | 8c731d3af62c022a8abf55d7b45079f648a2936dcabfc8847f7d30274382d69b |
Hashes for stim-1.13.dev1693376963-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb9afef26b716e3f63f6ebab2c76b37b7902d0cca0edfee10cf9e98d9e28fa2 |
|
MD5 | e541f4a21963a74e5a2e7ead8b7d533a |
|
BLAKE2b-256 | 84d9f058a0788c4db529fb9891b6cd40b0224bc6b40837205ff502534956d3c3 |
Hashes for stim-1.13.dev1693376963-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9941561a509848e33cfed6a480e90a43093b898059e7726c6e0c95087349beeb |
|
MD5 | 619d60dd3254a460aa6b617f887a4b8d |
|
BLAKE2b-256 | 187e3415bdafa2957d5f579850572a4a7b56ba291b9ac3202ad449369c030dc7 |
Hashes for stim-1.13.dev1693376963-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4a65ba285bd9a7117275d9240e54a5dc1ca47ab1e462f3cd398d24fb5e9ce12 |
|
MD5 | 669fd4ac107a7481ecd8741fe1584b30 |
|
BLAKE2b-256 | b77dc00a095f653aceff1d8de4d8415b8134c8587e84221e1e094668105b95e8 |
Hashes for stim-1.13.dev1693376963-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dff372783db474d3c5a509470f77d31d62955e3934ffb931901c10be4e120521 |
|
MD5 | d47abf70fee2b28cc20cc2158d70caae |
|
BLAKE2b-256 | f6fb6599519162419227cf93aa295c5af90b19df88bf9c750c8b578d3193bd97 |
Hashes for stim-1.13.dev1693376963-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463885f74686f1ac76f730961f7062f5a17d0b8b7a43494bdc97fc24212618e7 |
|
MD5 | 386174eb20e22fc5571bb72367627527 |
|
BLAKE2b-256 | 37148d31a1db257936521379eb85407a21e80541a97afe07091dad98075950cf |
Hashes for stim-1.13.dev1693376963-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c954211273c4944c8170d0d6f61ae52d76bdd162b5ca3bb4b32e5f86e49f5f4 |
|
MD5 | 518c56d0864eeafa8324b30cdfc583c9 |
|
BLAKE2b-256 | 3484653c75a63d79ce71a3d0194e1ab58210ceacdaf5c907fa63496d8f8c564d |
Hashes for stim-1.13.dev1693376963-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b8286ed17d12c39a81df4946c0e0072f9fdca1d7b3fea813527ae2253436a7d |
|
MD5 | 767e6676e311172c8493e10e2bdea650 |
|
BLAKE2b-256 | f32776dfb67a6d9aca06df15402b826bb77c0ba6571f289eef26ce8d2b19d171 |
Hashes for stim-1.13.dev1693376963-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65abddec07283694d7a1c53548413691e111e838f74d615e8287fdb954ba3ee9 |
|
MD5 | 18479763de0afd075f0b470da0f46b2b |
|
BLAKE2b-256 | b2909646942369b9f25838b30fdb917c0834854d8fe7db873c990f63dba72fe8 |
Hashes for stim-1.13.dev1693376963-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29dfc40efda890b4bdee8a69283b001ab54011e16c11642386ad9b249bd9b2c0 |
|
MD5 | 9872cc41e0a33268c007856a8b011168 |
|
BLAKE2b-256 | f7bbfd23c43120b53c87efc6bfee923a701fc8dffc4b10d8504c683a9ed92654 |
Hashes for stim-1.13.dev1693376963-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 849f6a31969d3474f628f97ebe9a855b334acf6219a214566117f7327299a74a |
|
MD5 | 700aed9c805a8af0caa812de7dc51060 |
|
BLAKE2b-256 | b7dd7b288ee54dd69b278fb1bf1de6261da4e8ddcda459ca57213dfc0c7d3cda |
Hashes for stim-1.13.dev1693376963-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6ff0342eacb7bc48d2384e169487d3de1860935d339dcc944cec880e277bd01 |
|
MD5 | f6834ba5aa1ca93aa2277559ca24dac5 |
|
BLAKE2b-256 | 4e83b82c648fbf1c18640311d729bc94f6672d2ba3a60960b881ed28ffc9736d |
Hashes for stim-1.13.dev1693376963-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 288e9423c9715a02895b9af64596bb77314d84a484b27ae052bb28db01b9fc9c |
|
MD5 | 677ea555d7ea3f28ffc4ccd56c036de2 |
|
BLAKE2b-256 | b9a72c4069b9fd42b34286232bd327e8fee61fb272f475bab2a1330da74d33cd |
Hashes for stim-1.13.dev1693376963-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f994f4fcc4ca3cb41f0f35679f53d04bff3af4a774a726b78cdd0e81cd8140da |
|
MD5 | 4ab5e9d7607a7ad72cbc2516180511a4 |
|
BLAKE2b-256 | 36c4241044865568a942490995274260ca3ec688dfa5fff97c5d4f5e557497a9 |
Hashes for stim-1.13.dev1693376963-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8f7786a772d2838875c0121db05f1ae91adfd95ecf292909a8298e69faf4da |
|
MD5 | f14a4ca879496eeb3f96d82f44d10e1e |
|
BLAKE2b-256 | 1acebea08bb20313cdda3d2a1e0cb47b65ec7583d1199eb27575b4188b23c7f3 |
Hashes for stim-1.13.dev1693376963-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf3cadc050098946bc7ba5bd0abdb45b118abe1a1b8cd46993c1cf44b2d3f1b |
|
MD5 | 4194a01443986a78de782383833f26b8 |
|
BLAKE2b-256 | ab591da1181d9a01193c6b83d2c10758fe04922747cc14c59cf43d58319961e8 |