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.dev1710740471-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f6a845f64663678b67eae3ca642b16364c205c2530be179368d632fd8a76424 |
|
MD5 | e8279127fea4d7ed3d03fbb7d98b9686 |
|
BLAKE2b-256 | 0707c386d56576992dba959aad3fff3abf948922a1bc106fe34c6cf68869bd4e |
Hashes for stim-1.13.dev1710740471-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d991b1af36815724b1e2d6254d92933945a3fbbbec32745b99c18c916e77290 |
|
MD5 | f34359006846c8ccf95caee3ce67c45d |
|
BLAKE2b-256 | 1e74c3e1eaff1e3b92bf92303def424cbd354381ffc22052f3195a53b375e69b |
Hashes for stim-1.13.dev1710740471-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc3ed5b86f94cfecfbc63206bce189d539495f2023c982dd00f367305692c697 |
|
MD5 | 9313b681eebdcb59a8b66c8116cdfd3c |
|
BLAKE2b-256 | fd27cbae7af82f12f02883de95823666c0a5c315999276648abfae969b51399d |
Hashes for stim-1.13.dev1710740471-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 079138764ea278380d4254903fc540d63fe123af3411a0450daf95c563f051aa |
|
MD5 | 461ae81dd941fa042fefcb3a4f460ca6 |
|
BLAKE2b-256 | 79d9532bf273e2df1f6a91d9557ad645d346ee05b8e8f517af473277a68ad47e |
Hashes for stim-1.13.dev1710740471-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7092869fe8d46856803223442a5b49ac998d538aa1d495531ebca75edb9476c8 |
|
MD5 | 2a0200bae4e944ea8384d4eeda728604 |
|
BLAKE2b-256 | eff78ac1ee6fe69b960c032d32718bfcd877e7a4ee00a705f930ea484635de8e |
Hashes for stim-1.13.dev1710740471-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd313404f4a2d413c6ff36cc59779327205e72f5fcd7d5b4d478e4673056658b |
|
MD5 | 25dfebe4206fe02ee5a57ffc891492c7 |
|
BLAKE2b-256 | 9a531b9c1a2bfd785ee8592fac81effb8a639eb7d461038725f1a766eeb2e326 |
Hashes for stim-1.13.dev1710740471-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d784825983ea2560f832692fbf1bd746ccfe208fca01225ecacea0a36a69a6b1 |
|
MD5 | 5790098d1dc9bf0d4515a1ea5862c8da |
|
BLAKE2b-256 | 0c1a8075e82c090b50d14634635f9d30f2a033e77a010e1ecacf8bf3a05e31df |
Hashes for stim-1.13.dev1710740471-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 046e1bb0a7bdd4bd304b8c549571da3d7e92bec60f126d231136bf6361fb9307 |
|
MD5 | 90fa57711d4538db06ba9eb400e19fcf |
|
BLAKE2b-256 | 5427724ba83c3cbc71588361b5e5915be5639d328b3e842347f351881ae3e089 |
Hashes for stim-1.13.dev1710740471-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | feff3eeb360a244ca4556ede1976c35c093cb9bb9e430672d2f6f4c27267c384 |
|
MD5 | 1a83b77a4a55f51299c3f3a5938d6102 |
|
BLAKE2b-256 | 835214aa73d8e548ca53e674bb6534eec713b7fa391b9c04d198bcb6548ea4d2 |
Hashes for stim-1.13.dev1710740471-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72703335ada2f4da19e926a95c5d586d044d7848fcf7a37a86b0e0d4404f5a2f |
|
MD5 | 1697bb01458b8b4cc0d2ede0ab6f40f4 |
|
BLAKE2b-256 | 4b770edcf993f9a6a571a37300708316998bc1a73543018c18c25dc82ca6d584 |
Hashes for stim-1.13.dev1710740471-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe04720f7e9831b994170c80ae4002a6238987deb5de780904004b17471bc214 |
|
MD5 | a6f956ecf2c9cea386d9a6490f32f914 |
|
BLAKE2b-256 | 197fb861e0981998ee6b615c08aca2a2701e52a1f865b7f58bb8864d2ead3bce |
Hashes for stim-1.13.dev1710740471-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e17ae88a82e9b17b51c0729826953a26379ce241cc4b6bd0b9b6a0baecf0baf1 |
|
MD5 | 4e289653cfa233745979b3bda4597deb |
|
BLAKE2b-256 | de21ef795042ec12827149a55b4144a1d3ae7467c187577f88cc82fe9d52d3e8 |
Hashes for stim-1.13.dev1710740471-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca81f12d3875dbf9c5de053615620fb8061170ce0f8f7b1562d97f8a4c23184 |
|
MD5 | d3a27f13da56d3246a5254f43352a08e |
|
BLAKE2b-256 | ff9f2b5230f97029cf9b84f71dfcc176886c5f2fc0ec77bf91c18504b2e0f330 |
Hashes for stim-1.13.dev1710740471-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c7451e5332d61279ed12b533744cc6c7fa93f75b7647f387fcae9fc7669dc2b |
|
MD5 | 3dd5385e321ff3c7669602c6611cd6b3 |
|
BLAKE2b-256 | 4f1a1c86fd9dcee50dc9dcab1d8651c3782d8d6ebe15f5b58a0b9bee13f4a08d |
Hashes for stim-1.13.dev1710740471-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 523bea1c99b8fdb074a8c1d6f9d16efe0a0b04a12b0848b78a822b6a30ea9546 |
|
MD5 | f8141dfcd895172944a3fc2dde45cac3 |
|
BLAKE2b-256 | b81b2ac84f90f46e070400813d1037c3bb52c3de1419c65fea6a92db06242e6a |
Hashes for stim-1.13.dev1710740471-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40fc9e37ac264d0ba52b7dc550f352936d043e52f2688e3588f8595b7fd1f096 |
|
MD5 | 4960f4d25a09dd26cc31718c534ad224 |
|
BLAKE2b-256 | fce1dbb9f0a9b193e9c8fd237c9744a47fa424c9d7343fc7d285b2403ed92de1 |
Hashes for stim-1.13.dev1710740471-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bd2774e4f0aaeccd0b7ff66982332627d9ee0222515181c7648b98a2efbbf98 |
|
MD5 | e94bc42ad660f7a0060d53a8af92787c |
|
BLAKE2b-256 | b6b5b13d017265b066528eb1c37916b7ad13cc98faf16381bd0443daeb50788b |
Hashes for stim-1.13.dev1710740471-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 404760646f5ffe6414b96036c2f991dc615f8376be8648eb4141ec1c894365d0 |
|
MD5 | 4631768c4845ad3c65ab694b6b3ddf72 |
|
BLAKE2b-256 | ce69b971370110fcf333135bab6087fea929c8c32eb235e454ebbb146427a24a |
Hashes for stim-1.13.dev1710740471-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcf1c279dc0694d3bf89e7540773b0c011ebe306edbc7c2efae46e8d3465a547 |
|
MD5 | c07c9e332f558f655edcae3de395e35d |
|
BLAKE2b-256 | 96c46e41574d48baf848537168bb65f5e326006db3a97260a91be2538fc64c32 |
Hashes for stim-1.13.dev1710740471-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 864738c32c07b1802ef1cfd3e62a9fa9667592b68ac1eef8d099d6878b6ffe1a |
|
MD5 | 9d130f64c6ca985c01bdee10b9e4bcde |
|
BLAKE2b-256 | f35b55c3ee42c25f93d406b6620ebb92d79ca11870048617d0a660bb75993d0f |
Hashes for stim-1.13.dev1710740471-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 034f45980677f15b2d804f4007b925d7ca81f44278e3459a9fd0e4bc9f99d048 |
|
MD5 | e737eb547173a0cb8707850aebb5e32a |
|
BLAKE2b-256 | 53204afb13531f08fbb2dbd886cb9009bf6f6e90374f7e48ed9e65bb3d8847d5 |
Hashes for stim-1.13.dev1710740471-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 519bece10036dc1001fde8d2b60f255c289fe75b43696d69d0fdf8927d486d87 |
|
MD5 | a0f69bd1ac37f3d7b781514eff10a0fe |
|
BLAKE2b-256 | 0f84b914e4046685fa53ab3337eaa7bb9a134346090d2decfbdb1e2355b7704f |
Hashes for stim-1.13.dev1710740471-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9025af6e4433c48a18d28440b0f84a68cbcfd79d2d82ac580bcef83125343a6 |
|
MD5 | 87f00e5ed3c244ce926b2bf9c3663130 |
|
BLAKE2b-256 | aa52779aff624bf568a33bc817a52d1eff011b6519b7dafc757816282504fd16 |
Hashes for stim-1.13.dev1710740471-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112b3d478798dbc21389782e4f9f48d48a7119316a605831576446dfcf32ce99 |
|
MD5 | 7f7f91c181c617bf08908f935f6f8594 |
|
BLAKE2b-256 | c8d0bd830fa7459f5f3bc78e54039d6534138cba21e888c59c1ef2ce7088d80b |
Hashes for stim-1.13.dev1710740471-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6993f96bb6371a4691e11f6cec0409c6573551cecbee1760c6f4442b031ee79 |
|
MD5 | 2441f5f40c60e856f7f500ae9b498af9 |
|
BLAKE2b-256 | d33d75e73ad6d02bfed01c3f5a76a4355241823232597e2c066b493431f12679 |
Hashes for stim-1.13.dev1710740471-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2b6bb255f518662c3937cb709c033aa2f1a235590c205bd7d0199e08669663c |
|
MD5 | c827e0d0cc66e80484b43d82650b4c48 |
|
BLAKE2b-256 | 362be0a7cb2d5d82cea21568b649706301aa03ad22ddadb574909340df7ba9e7 |
Hashes for stim-1.13.dev1710740471-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ea5a562ffdc6b51257248336ffdf0c9c3418935ff6991b6cedb130637838251 |
|
MD5 | aef19a256e19f91887b1df0d0018dae5 |
|
BLAKE2b-256 | 10abbf21c09c048d6b6468392305fee64877b6b11e459bd8fadf715615eebdfe |
Hashes for stim-1.13.dev1710740471-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bfb29a9c9b3b42ee953c2cc25ff87c3393bb99ceec2d22261d845279f1e9434 |
|
MD5 | 471d8ca9b49a8591d054253f4dc36ba5 |
|
BLAKE2b-256 | 2319defec552662d330d7dbbc018136edac4cd93389d60ceab33a68f816bbb1d |
Hashes for stim-1.13.dev1710740471-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ec4c964a0f9206c0a0385bab01b6217110b0bbbb67b01911af47549d422515 |
|
MD5 | bad52caf84bc06d67d71d67f8e31891c |
|
BLAKE2b-256 | bef9f28e08d3eafe418ca86a4a01cf4a988cb12b0ce7392dc12730c9d6fe267f |
Hashes for stim-1.13.dev1710740471-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c06d96488e45274ffa343a4946d40991d0d97eb2f65568a308e002b0dac288e6 |
|
MD5 | e8081d883a42b8745bac6ab28cc9a66c |
|
BLAKE2b-256 | 7afd6b34982c264adc621310a7568c6dfe200ce9879c03174b76a2cea7985364 |