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.dev1709227811-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a3569b1c2db9ce411d856548187f13c813d3b194cc085655b8386fe50a93afe |
|
MD5 | d77e58e86289554395535d3177ccaeca |
|
BLAKE2b-256 | 282bbab03eca887658033669649d32cbf1cd744d4d086959cb2b5f38ade6a693 |
Hashes for stim-1.13.dev1709227811-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81edb49676a82da7d947517c69175f0ffd51b6642609a248ded3208fa47a4ec3 |
|
MD5 | b6fce73e39682ac57f2421e70417d812 |
|
BLAKE2b-256 | 73971dc30d16111d1602acfe4dd9ee48be0dd502e72b33753f079cd7967314b3 |
Hashes for stim-1.13.dev1709227811-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5968f9c52ade58721e19f7d20eb35cbbe84e529c69ae22b7563a4b0cf2d7cf |
|
MD5 | 8a16f8281fb85ff3d03173322f2938aa |
|
BLAKE2b-256 | dbdca42de374eac389a92ee6348951c324dcffc62bdbbea43f1ef987ae2d49a1 |
Hashes for stim-1.13.dev1709227811-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17208031f9f279d4da9c46098f81f6d4201b82c9028980fc4ed210ca6da1a392 |
|
MD5 | 17a4957276895bd9b08e71e82e75ee34 |
|
BLAKE2b-256 | 88e4dc2e820257294c76530982848888555915a67b0d260aaea7129cad233446 |
Hashes for stim-1.13.dev1709227811-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ed46c8263e1f38c52a57beac0aa6ef51d269d840e5a8809891b0eb547ba309 |
|
MD5 | fc1c60d2392da4def3b9e2464b018548 |
|
BLAKE2b-256 | 06ace381a5c1ce0cc59ca06023bc59dcca0d6e6100ebde6d717d439a6962dab8 |
Hashes for stim-1.13.dev1709227811-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521d54ec5107f1e957a929d98d068dd9bcd1ec2105134a77142cc04ef03bd206 |
|
MD5 | e1dffa90a7ee171f7d5f7987e4510fce |
|
BLAKE2b-256 | 9cb10548f2135ca421d69f0570b016f7c7fefaea780fcb625fe7ae8a4b91070a |
Hashes for stim-1.13.dev1709227811-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 483db6a6b377f138df8c8ce2b63e8879f7e3a9c4262dfef6c80ac4f6b8d6f9ee |
|
MD5 | c5c7509a873544ea0c0577085e71e59b |
|
BLAKE2b-256 | 9969155a80f5032f37029dab3fef51fe6af9a6a8a316871be4072f63b152baeb |
Hashes for stim-1.13.dev1709227811-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e8bae92428ffc01ea3e88f37bc05b0de8393a99ef9493bbdc2d9c5d5ef5c4e |
|
MD5 | 998c652d5c32ba19073c4c8d1c40f84a |
|
BLAKE2b-256 | 8a1e867064c79e8c281da6b2acf7d712b57b0f7f45ba575a76c83469f5aad63e |
Hashes for stim-1.13.dev1709227811-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3872a5ecc656aee28138e1ae18d297555545854be31f946be06347654c401de5 |
|
MD5 | e077d57868eb66222a43c4ce028e781a |
|
BLAKE2b-256 | aac2d3af9e4c0c49d8fe46fc5d4bda9f041962d4a972c07562dee2be6e582fb6 |
Hashes for stim-1.13.dev1709227811-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aff733d39d691e36e81aba78c5f3699748c472c98fba08de0fd5c08fc9f0bec |
|
MD5 | 6d70d1326ef7d7c1b280e385c05aeba3 |
|
BLAKE2b-256 | e8b5be10a1201d6ad9e45c64ac65d55fc5348f96ad91057203890b7b573586ed |
Hashes for stim-1.13.dev1709227811-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a3f30ff9d1d51bcc5b3456d44b2d42abce9ae5731609680660201c4d34ee05 |
|
MD5 | 79a3a368e1bb67ff4f6fb6b7aa9bb964 |
|
BLAKE2b-256 | af96ad657f3b7d8d5df84586eb15df834484f3ca483624f5df035156b6bbc6e8 |
Hashes for stim-1.13.dev1709227811-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b8ee02d7ae56bfec0779f48b5910b561111704d2760cd0e82d45703ad80e1cc |
|
MD5 | 16fa5ba3542a058461aab0c7d884bc30 |
|
BLAKE2b-256 | c57414ae3f9f077e5a569d738e4dd3de544a041e105f7cd696b2407b4cf5c62c |
Hashes for stim-1.13.dev1709227811-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e262df98e70d40d32bec825dff90077cc5811a231217aeeed0ba847b0f8c6857 |
|
MD5 | 74089bae5284338c12a09ef8390bcaf8 |
|
BLAKE2b-256 | 0cf9d4a68e0b4f02e8ee80a95c5ab9e3c5088045d0409fd45a8f633b746085cf |
Hashes for stim-1.13.dev1709227811-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6491cb213101b35ac8c43fa9d81e26aa57d2a669c776a092c9446ed98018277f |
|
MD5 | 04a610eb91fb377157c3fca19ca758d9 |
|
BLAKE2b-256 | c7168d7e7cbeba7d3f7d1862fd66b0752477ad23cbe1bc9b74ebfd8b4f31fba0 |
Hashes for stim-1.13.dev1709227811-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad4a9b7fc45d3cedac6f70f26b7aff1bb87e8a10521de53300e1f1514c26799f |
|
MD5 | 00826b980ddc88fd7b1bfc1eeaf5cbad |
|
BLAKE2b-256 | 65dab599a80813d3c80d218030d5676a511f87f2d6996ce04d1a27ac965b217f |
Hashes for stim-1.13.dev1709227811-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 691d00c0e52fee9e9ca37c92e6e53314394110320ddb15bbec33cf7703e86f92 |
|
MD5 | 5f3931b803edb9ed125669ae3e258d16 |
|
BLAKE2b-256 | 9b706e2dfd1b9911137bca7bee5ee5a238b84a6f4e8e72a73a1567c351486995 |
Hashes for stim-1.13.dev1709227811-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f60497b7a419023f7f3976a42a74cc9585072c120465b9d26e6aa4f4c42681ec |
|
MD5 | d9d91555a6a8455fdb37dc2507aca17a |
|
BLAKE2b-256 | 3861b2f48783801f6b105bf117d9393a2a950826d4fd13aab1375db68ff186f5 |
Hashes for stim-1.13.dev1709227811-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc56f285fd0db6203ad7ecc734ad89858becd65be0fdd57800e0863a461c26a2 |
|
MD5 | 7496147d6f516e24cc25a0be4e30cc6c |
|
BLAKE2b-256 | bf157b0d274581792b7b3601a2e72ebf9087a93ab4d2aa7816cdf829d5c2d4dc |
Hashes for stim-1.13.dev1709227811-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d37f6052c54ee669d51888b3f4577e1b6b6dfbdcaa450011c38466fff704508 |
|
MD5 | 30922b4160e60693854cfa0f2dc4c5ce |
|
BLAKE2b-256 | 1bba5af1c584078c86db6dff421061623f58995c6f8cfaf11eb4956ed2d515da |
Hashes for stim-1.13.dev1709227811-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de6a3086424e1c5afadd81e926b2f9ad047c246ab22a44b822f9da36ede521ac |
|
MD5 | d825b487fd028892510389bf4bf4b4c6 |
|
BLAKE2b-256 | e4d7239f50485dccf299f104021fb034b198a9bc9a92f68ddc508b32eb0669e0 |
Hashes for stim-1.13.dev1709227811-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 267adf5c48305dd6a7d96b46b5767e5ef4e669a0ce24d71cab8ac8150ac26cb4 |
|
MD5 | 765202309c3d2aef2ba0c381acd7466d |
|
BLAKE2b-256 | a25359aebf8852879ab5ae03e9180d96e11cacf491947e94150c1c7f1440de81 |
Hashes for stim-1.13.dev1709227811-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6d9f6f55a6fd9cbe535bf12865ec1a8b3f25ddcbbd2fa8898b0a8f4f7585db6 |
|
MD5 | b097705b8cc89d2ad0fbd3a50911d01d |
|
BLAKE2b-256 | 171189882fd5a25f1369ad89e57e88164a625c7a4d44ea8d74e992d63bdc4204 |
Hashes for stim-1.13.dev1709227811-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950ac6ea4992f655fb67e2963d981aabff15c73d52bf621f5e3a2b7d0cfd91f3 |
|
MD5 | 334f832df28c9716585bb5f3aa435886 |
|
BLAKE2b-256 | 105c5e2f5e495381af3d265e5c0869b57559607c7801cd1f270806d49bf13f19 |
Hashes for stim-1.13.dev1709227811-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c7ce70bedc053df4f8bf8d7e2590b97d54da2d8004df2cf54630a6d97841ac3 |
|
MD5 | 89ede04ec7801d7a05d0477df206e065 |
|
BLAKE2b-256 | 428f55e2276ea16920b93d80e318b509271df9c804d79302b60a837d8b9b1c77 |
Hashes for stim-1.13.dev1709227811-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82358b5be07d54995dcab929ac89e2b3e8634e8a2209203e358dece2adc601d1 |
|
MD5 | 996721bdca49b2e9b056031da2a0a16c |
|
BLAKE2b-256 | 3ecb861dc13ce1e1881d9aaecb0b4ccba44f198c82928a7af226da61c4e44757 |
Hashes for stim-1.13.dev1709227811-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8c4b629019fedf343e94d3234e8619eca4a377ad8f79eb95abf66e876be55dd |
|
MD5 | 489347bcf8b85919f6a7e8db43cb280c |
|
BLAKE2b-256 | 1e519c2d7ed885533800008c842f481223e307a1f3a627e6fd39f521c3314019 |
Hashes for stim-1.13.dev1709227811-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b365f86749141b7d3ed5ef84633d6a683285fb7c4f7c5b47bc2e7ebbe5c7a23 |
|
MD5 | 93e84ae992032d6c9cc314e13c73a218 |
|
BLAKE2b-256 | 67722ebab3bc49057ab983a7e0fae9c0d13b6b65fdc0017336705c12dac2a8c0 |
Hashes for stim-1.13.dev1709227811-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 399ef2d7b04db3c39ef685c075e124105bf64887a413addb247e819a66a869f3 |
|
MD5 | c2763bd6239dcc055ab62d343f7974e3 |
|
BLAKE2b-256 | 4288303bc72773f6999fc53200c4b99b47ce12d7486851578bf2ae3a70dc1f8b |
Hashes for stim-1.13.dev1709227811-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f135b544c9bd086b742d47fb9899a2ca7f7ad70412dbdd657baa3ef5e200054e |
|
MD5 | 18fcdf0c97075665f166e1412f482592 |
|
BLAKE2b-256 | 6abd4e803f5b808bd289cd11d0087f31f17c16a07c7ba43051c644e700e177eb |
Hashes for stim-1.13.dev1709227811-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f798526a75bf2ab59c4486aa584c65353d1155ec41c996275a780becedbb638 |
|
MD5 | 0f92763171f8eb81b2b1faa95b942112 |
|
BLAKE2b-256 | d3c0c1b1ad34404e48ed8f61c4ef74ecd21ae33b9b4e026d955ce710cca58006 |