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.dev1700086664-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42539504cc02b8df8b7cb3b17ccf32c4baef6d94baedad0d8763e1cad3616817 |
|
MD5 | 1482c97bf3168cd3f1c4517e6841a903 |
|
BLAKE2b-256 | 326cbc2ca0f8f08c529a8f654d1a1efbbf3636b18e6e481f25d9570ad56f4322 |
Hashes for stim-1.13.dev1700086664-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 963ca4b4a17ee805a0e7a918353759fb513401058fb927fbe2daae23232d0569 |
|
MD5 | 5002b674f2bb51e885235a20bad4d42c |
|
BLAKE2b-256 | d181a95d9883a76e683183824abe3cc691b6ee1cc3bd9e869513173d57d1e744 |
Hashes for stim-1.13.dev1700086664-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9089fc63996abd80d1191db586b4edbf2949c06065d7dec3489f7ee8b3d344a6 |
|
MD5 | 94e9073b183e4cfe4a2256538a01e893 |
|
BLAKE2b-256 | 4ba9f7b6ccd758458d6c3490452e23be4a193e0346e0d5d5354d01982b187b09 |
Hashes for stim-1.13.dev1700086664-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13e91cbc62c3389a5b9c12c85de1bcb1619553ac3239d9d3049ee6bf36b4b485 |
|
MD5 | 1d38a74d800c94cd1c77280ef942d7ad |
|
BLAKE2b-256 | cb7354744b99137106635d04380befe3de2dc753be84bfb72f8db188516ee02b |
Hashes for stim-1.13.dev1700086664-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae9a1b3a5d989e1a912f8b2338ccbc9b8a5b7c814e395eefc3ddae1f070ceeb |
|
MD5 | 82b91680f399bdf568fad89d6c0fd57e |
|
BLAKE2b-256 | e361d340cc6fb5e02440d50000f2d3ad2f39318cc70c906b57c02c0e4b6aceec |
Hashes for stim-1.13.dev1700086664-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a1ce68165202ee77072b970055a01b2d3722077bcb57e1b6d547b5a7912be2 |
|
MD5 | 7aa5227273398e53fdd5e398200b2824 |
|
BLAKE2b-256 | 4c44ebeaad4d55ecf95303d1962dc110f2ee5885ec725a097ec939deb91a9a1d |
Hashes for stim-1.13.dev1700086664-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba76b04fb4fc7d3d10c0cb7075693f7f46d6f749756dee8f8961211835684d8a |
|
MD5 | 3476a1513849cd5ad9e902071e2db4e4 |
|
BLAKE2b-256 | 459befcc8bd90eb743f24d40a2626b77e0824c5a509e1aecb47b7be00f1989d2 |
Hashes for stim-1.13.dev1700086664-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6c1e0fbf073ce606640f8f3868313bed10688dce35960ae00c31a8da35fea84 |
|
MD5 | ae4b5ad7ec4199d935c5e217dea12023 |
|
BLAKE2b-256 | d33c8f18a5a41de4ca36879a8fbb8915f4d04a89d53fcd4473af65031209a546 |
Hashes for stim-1.13.dev1700086664-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b7eef54e2064c7906b9f43f1ffdebeb33bbe0abba9bf57c30690da062903645 |
|
MD5 | f37a51e0439b7fa6cd98bba0a5ee695a |
|
BLAKE2b-256 | 19bda37ca96f4f79b11b39ce9135e539411b1c946094c8747fd198ca2f61fad5 |
Hashes for stim-1.13.dev1700086664-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 740fea42c85543411d4d9bb364ac59d6d8cd804c9b1ab45791e4490acd30dd05 |
|
MD5 | ee0b1197633470b316dcfc2f06538644 |
|
BLAKE2b-256 | 353cefea3bd831f5975fa195687555ec9f6a7de4f7673186f6dcff01fd407285 |
Hashes for stim-1.13.dev1700086664-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30d6fbe9dad71eb98a21926d496e2a6fbec282883cf6d41673964d0679f26307 |
|
MD5 | b59f8d8de17ddffc9879ec91fab8e483 |
|
BLAKE2b-256 | f87fb1ace59f2f302a3b85f72a8233bd66577bc433b5cec262ef895044a9c103 |
Hashes for stim-1.13.dev1700086664-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d91c1ff152f76606555b06f1a92f2f7deeb8df7a51596b140d987582f8fdca6 |
|
MD5 | 3d9fa6a5c9a9ada09f9e582aa9578444 |
|
BLAKE2b-256 | 774a0447f0cd86da376a85d49a5cd970465420c40779f73a6dd6a68f7f014ed2 |
Hashes for stim-1.13.dev1700086664-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623ef7bc914095903229531f3f06411dedb5563650551052fb8c6a3394ffdcd5 |
|
MD5 | f5df8c967f01c113d62efc09be341d8c |
|
BLAKE2b-256 | 877c0a4ddff061c1260cc53240a301d897233af813f0a49e975eac42aa8f8503 |
Hashes for stim-1.13.dev1700086664-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c2fe96000e82804b622f4de7f677ee8fb2e35884e08146304ec74a129ce9dfc |
|
MD5 | 0ac97e70030cbec3ed95118b237764cb |
|
BLAKE2b-256 | 5104a6045199ac9cfaa86c36374bcf65779036c4533eecf33f74835c742616ff |
Hashes for stim-1.13.dev1700086664-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f3f37f635c1e89fe77ebccc8d49d1e9a5e8b3fbebc48542edef3f32808832e |
|
MD5 | 1d400006ddaf0d7f2887bb781bc8ce86 |
|
BLAKE2b-256 | 61048813f54b6dbaa2264e7394530fa6d870d7d02201471a2da51945662610e6 |
Hashes for stim-1.13.dev1700086664-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eb4b72e2825470ea33eaa9f880e96435a1458896502cd7fa8396e5f102cdc32 |
|
MD5 | bcfc92650c6f5349fd0470f211c80d7c |
|
BLAKE2b-256 | 37ba6074fbc9924054cce4e635754b73dcc1a2424403937b27b8dc6ca9d087d1 |
Hashes for stim-1.13.dev1700086664-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068f548686b7c37a5e8cca7ade4801000c4cf8faa288a1790db563d0210d285a |
|
MD5 | cce5aedcc521f7f1afa96e6d6c608412 |
|
BLAKE2b-256 | 85e3acda806a4b5cbf6af4c0eacaa53f7414e1f7df9a879a7506aeb19b5dea71 |
Hashes for stim-1.13.dev1700086664-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db364c19486dc5daf2c70cd6ad13b7db96cae82c983ac9611d8fd2b76c75298c |
|
MD5 | 844d9d996cfde5767a3251a0ae6713d4 |
|
BLAKE2b-256 | 4548edcf25c1f226795c254a01f0193e61f9428ab89b7bc95652fe2548833cdf |
Hashes for stim-1.13.dev1700086664-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9da1f6740d984d189a6dfae76693497b47e8318988cace730bb30b904aec437 |
|
MD5 | 52bfad9d61134f48858961216c3e2eb4 |
|
BLAKE2b-256 | 7dc79167b9cc56ef68b62690b8153dd4d2b87f1f8d69118133796926b41fe4fa |
Hashes for stim-1.13.dev1700086664-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b07b192f4a2e475072fc48dcb04ef45ba202220cfc1408837887aef5cfba231c |
|
MD5 | 74093a288a7170e2ab394857b2a79281 |
|
BLAKE2b-256 | a0efc802321007c88b7aa337c8cfc894d9c7cd2c5a94aaf1f3d88c2a652e7927 |
Hashes for stim-1.13.dev1700086664-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7f4819c1737535a70b6f393d7034729483ce44c05c5048bca7a4c80537f5d49 |
|
MD5 | 9c7110a2021cef57861e276085d7229a |
|
BLAKE2b-256 | 2e99975bc2718ded41f1f0a6f172992568572b62b7c4b451977211da6d9e6330 |
Hashes for stim-1.13.dev1700086664-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d346bb3b2de44b5c2b3437f0a2b6c3eac081a063e22db075bf0fc0db55cee837 |
|
MD5 | a89d3f79d83a9ffbfb1a27a47afadea4 |
|
BLAKE2b-256 | 0321d2f3a87a8f2955b3b6ac8c91b3883bd3a9fb8c577332119734c5c575bd0d |
Hashes for stim-1.13.dev1700086664-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a721461006bab71d0b5e2b202548d1b0f01aa9bf1aea1c61772c66bf91240e5 |
|
MD5 | c9e17ffdd5ab4c12cff815deb09ae72a |
|
BLAKE2b-256 | a930e35ca52584ade14baf25c7feedd1cb724f3a50e2444d2c79a434be9136f5 |
Hashes for stim-1.13.dev1700086664-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fca4c7cf3676277fc60c7e466e2ce9bb45e091408b132f6f1e74863bed722db9 |
|
MD5 | 7c4091ca04b38891ea703997badfac7b |
|
BLAKE2b-256 | 5d2b428ece5d88a99fbba81f2904015d3117b8b0cf7dac62b2514b4ec68f136b |
Hashes for stim-1.13.dev1700086664-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e7d8ae704698592ab5058ff1c906fce3c3b4292a6fcde0db31917442418aa8 |
|
MD5 | 3d8dcd6c4b8946cefe11672e751e22da |
|
BLAKE2b-256 | 3e2a953b3fdc11caa2bb4575c5e52307c0435e65e027a82c1a48b96017b2ef64 |
Hashes for stim-1.13.dev1700086664-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9962dda5ce6ed43617d3c47c8eae29f9dbdb8c7a7cdea4917e2b76098b01addb |
|
MD5 | 3e29d9212a565da420e2b2126c8a41f4 |
|
BLAKE2b-256 | 22f503671e06efaf5fd6902c454c39046b5e5293f0c700c269a7555619df81b7 |
Hashes for stim-1.13.dev1700086664-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d052e539a34718bda76249c18bc672ff280e65a52b697f434785a51f0138a6a |
|
MD5 | 91e54281b144879a019d2b01af391b4d |
|
BLAKE2b-256 | 9fe9f33fd46d83e2344322ea4faef9d593d52d10afda1a0ecf50b113788a0dc6 |
Hashes for stim-1.13.dev1700086664-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b782780c03d22ae393e30061389003daa9dbddd9a7ab4768f216a7c7349ea03e |
|
MD5 | 7625e47298eb51f361e623465f207d7f |
|
BLAKE2b-256 | b87586416b32c6b0a958da2ef5bb39fe2f206616fd352d0229ed17e84944d847 |
Hashes for stim-1.13.dev1700086664-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ea1aefede2bfc7f8235608eaf36f414d24af653d4c5689b2baf198ebc0ea3d8 |
|
MD5 | 53f37e08c853e9b79c58af88c27c7ebc |
|
BLAKE2b-256 | 66d055ac5de830b82c37014f6dd3b61a34fb4fffe261a0ef2ba99503058d0aba |
Hashes for stim-1.13.dev1700086664-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fc092943e3fa14a2da0f9d3fcb64e1e0d6ab27f78230961a1ebae6bea8fa1ae |
|
MD5 | 2fe0953639dfab445b6aef371e6bb1d5 |
|
BLAKE2b-256 | e2264ec5d64f98cae1d87bbcf1b174ec6058ba4929a179de5efaef986af75c51 |