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.14.dev1712884560-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f1793045eb3ec2c1a6dee00e2912fa3a68738df0c794d574b1f41229f49872d |
|
MD5 | c725eead4618b865089257691bbcdf5d |
|
BLAKE2b-256 | 86e725319ae147e599736069abd40b989dcde283dacbd7c5e62a79030227011d |
Hashes for stim-1.14.dev1712884560-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c29b19aa288846a229f23d233759bf46b72e1beffb5f33ef0214c7ec2d9b7e3 |
|
MD5 | 7cbc2fe5f28fb40acc4277e935b4dcb1 |
|
BLAKE2b-256 | bbcbc7c2015453defa26bc521669b45e840e97c9c0df219997bda46bceaa2f01 |
Hashes for stim-1.14.dev1712884560-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2715e864152bcd636a2181b84ad0c51915d10c2f59a71c331f8d5f50d29c3a6b |
|
MD5 | 454f43f971f175a56429e0c198cbb965 |
|
BLAKE2b-256 | f15da3e56c9d50a8bf4f0a22ef11e813b427450f23a1cf8e6a85ce64c4f67821 |
Hashes for stim-1.14.dev1712884560-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75f153db1456cbd3fde4f2c4d0a98e90f3b8f61bdd13e93f152c297ee7e7bd5e |
|
MD5 | 98c69b6d51f72c53cad9c2993aa4f055 |
|
BLAKE2b-256 | 7c5738e583f7eb3815bacf9168c6f826cd5ab73efab40fd06d99cd01c5df4ada |
Hashes for stim-1.14.dev1712884560-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08288cfa5eed227e4d9de4fea9f0e75ec9f5a8770e97c1359c616b329f6baa0b |
|
MD5 | a7f594a2ce98c9f9d4270a75bb439f30 |
|
BLAKE2b-256 | 0e5e161a3b46692eb3166cb63130c36a709a75d55f99bcfdcd8a2f8a87e8cfbb |
Hashes for stim-1.14.dev1712884560-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c224e186b45572cc59bd475a351f7c9851e7bebdfe72e95417623540f48be8 |
|
MD5 | 79764b124f43490d6e9bd07cddaa3bb0 |
|
BLAKE2b-256 | 4683f096530c635f7504094e960736c0fed2fde972e03448e463312f715ec2ef |
Hashes for stim-1.14.dev1712884560-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db213e15069a09de0c28b9f8fb5115d0a4988de5af9d1cd650a0f16dd631f0b |
|
MD5 | a1c89cbabe4c4c750fa42942f2d96ed3 |
|
BLAKE2b-256 | 31c5200a930287f1fb043f2d1425f2d6b2252e9a319b43a040ef3426cc244b25 |
Hashes for stim-1.14.dev1712884560-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 107cd1d62233a49f46f77101533690bbf413c74ffc8749114d07b0480a7e495b |
|
MD5 | ee51dea29890ead8db04f53ebaefc742 |
|
BLAKE2b-256 | b54858a4dedeab9dc89c8c87c019c96e8a96d7a8f1c98c14036dcd3b1618f0af |
Hashes for stim-1.14.dev1712884560-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4dd72e5b8a8e338df25f5e46aa04d387a363acbfc1bf52b0b927b13b4535c45 |
|
MD5 | a050fa5a7f91c71196f2535b64784a18 |
|
BLAKE2b-256 | f75feed1e84f76a250eaab2eefd16b0eb0249069f9039c78a8cb1172e21e1ee4 |
Hashes for stim-1.14.dev1712884560-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e0b4ac1f005d3f6f2a9702674938faf7d4972f843303e5e33fa49df105b4832 |
|
MD5 | ffe5a219e0dd86c6c49cdcd542382881 |
|
BLAKE2b-256 | 0c7279dd853447119118134ccf055d4af0f1584e857132350f799ddf6537f586 |
Hashes for stim-1.14.dev1712884560-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc019e945737584bdee9b5aa27040ca8d9266b51ca9d012ebbfc9ac367c27573 |
|
MD5 | 8cc9741972a0c2499fc3d426fc9269fd |
|
BLAKE2b-256 | cba72a13d9573d81aaef7dea7187af6d86042dd978a64d09ead61cad3dd3435a |
Hashes for stim-1.14.dev1712884560-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8cea267431d15f3d6cf03b79addd765c1001dacc1e98c5a7b522966697ce41 |
|
MD5 | 94a356c709bc87bd92aee88689063741 |
|
BLAKE2b-256 | ad240863664cf4682c9be34510ecc525c08fc557511c8d3ec6bd5bd5604ff314 |
Hashes for stim-1.14.dev1712884560-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20a9c2f9be9794f14308f39f2577ff223d26dc2b928978b44e83f16a8c6f2e38 |
|
MD5 | 6ff92f795dbfb8538a494242a222e839 |
|
BLAKE2b-256 | 344fa74b3c5a8bb14ef934f8a7b9b93d0653c2498652730584918626ccab4ace |
Hashes for stim-1.14.dev1712884560-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73ac0828b41cb4a3cdfd5f2061429c75721eb310a5e559b7936fec5fa92c3847 |
|
MD5 | 43a72dfbfe36669d5b06acee502b7b2b |
|
BLAKE2b-256 | 0954aafb3ab34327efaaf55a66b6099cae84684d67cccaba85dbeae528aa782e |
Hashes for stim-1.14.dev1712884560-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f69432f9155d8cf58e7b56d2523a1c24df2089c5ddf006a8759db01e50c9857e |
|
MD5 | 29eb91d66a3684331fbb9fbb11c8e59c |
|
BLAKE2b-256 | 5fbdcdd832f20445e383dc1281557c3e05670d05b66ee63ff9cf8e884d5a6b44 |
Hashes for stim-1.14.dev1712884560-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1906320f7e640b1c6575d8aebb2c22abbc5f4f456dcc542fcf20c824570c40f |
|
MD5 | 2f2e3add0cba51178ea9516ed8910383 |
|
BLAKE2b-256 | 8860cd96ec5359ddb99601af61b6207a0892b74b5ff9054d1ae522e0226ac068 |
Hashes for stim-1.14.dev1712884560-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91f75ae3b5079befb1540f49793166bfb3b85ae6c6f0c42a091877e67755a944 |
|
MD5 | 66dfe38e44acba9712076ca36f510a7f |
|
BLAKE2b-256 | b50de49d1c4dd9124eab1666607ce173ccdb177d6c90bed2125621104132d8ad |
Hashes for stim-1.14.dev1712884560-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eb26c8858d4597fc0f8028ad1e1ebf2f3c34d9982a80ecfe80c6811a0c502cd |
|
MD5 | 1aca297344c9ad0a9a1c1888e232b8f6 |
|
BLAKE2b-256 | 540595e09c98cd2823f108db692bc80900b79bdb4077c8acd226cd6c8e0d0411 |
Hashes for stim-1.14.dev1712884560-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b03a22241f280202bec82a2af310708caaabfa433429f74809aad4d2ab5a46e7 |
|
MD5 | ef398aef66381b179792f5c57abe0b51 |
|
BLAKE2b-256 | 91c2512467171d109a3574a155fa2717f7eebb41b96df6698b24d208b34bddd7 |
Hashes for stim-1.14.dev1712884560-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb978ddf41e44b294df2d35e2aa08966417ebf05885dc6c7cad81023c09c4429 |
|
MD5 | a067beabd0d596daa396e40c1f496887 |
|
BLAKE2b-256 | aa2125f24d76bd829882480a15a97cc02e776d95c646cd038bd8f1013bda2aab |
Hashes for stim-1.14.dev1712884560-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff74a919ad5aba0d76fe09b090503f75d508b280cd93281f087e226a71d76938 |
|
MD5 | 9646a99e57844f72044421525ea0f242 |
|
BLAKE2b-256 | 63f05b0d2a1e663a3d82bacf649d780d0a592e1777c1624245ec7004d48a8768 |
Hashes for stim-1.14.dev1712884560-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee42a97b329ff69df29e03b3ac2e4395977b4c211bd8bdf5d68c8cf96c111ee |
|
MD5 | 1e4336fbcfaeb960945c783b993b0e2e |
|
BLAKE2b-256 | 7a0b49be760566d6edfec6a4dac6b60792a3d130f87517acd81e6128ccf501d2 |
Hashes for stim-1.14.dev1712884560-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4847a81af5d728dc75350e3a3afde5e18190138cf36d3c59d52cc25b31e6c1f |
|
MD5 | ab22484dd51cf5886776e45985cefd6f |
|
BLAKE2b-256 | eb78af75c57fbd7b0550e6c60c50e4d20c24c7cd9c7ca98c87e906852d51ab4c |
Hashes for stim-1.14.dev1712884560-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bee6652ca28fcc58fa17e929abec8a2373a7295eb5b1a8dd23c43cc011c22d5 |
|
MD5 | c411cab5ef146ce2d46a30d4369ff298 |
|
BLAKE2b-256 | 0078e5f1899ca7f85b65d3d9e69ad9ba587e61adfcfa4d7f4b941f4b8a8895a0 |
Hashes for stim-1.14.dev1712884560-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ce1068e9a912ebe8442cfbaba8e06669874cb991769e13ba58f84ec0fd8d1e8 |
|
MD5 | 0759aa9cf0894b084be753b6c127e5f2 |
|
BLAKE2b-256 | f5d72e8993bae00f5b36b9b864907c0face74ee2897e28df009b95a8a50bdbeb |
Hashes for stim-1.14.dev1712884560-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f5763dcbd43e68d7af5b691b28b9e0adb2cd6a335e2b8d74cbf16029d8f0db1 |
|
MD5 | bee8476b501ea79bea6654a72106db86 |
|
BLAKE2b-256 | 0151b23b236902faac4f5fdf40ce768e7646a5052ad3b65c29992c8693dc4a36 |
Hashes for stim-1.14.dev1712884560-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d27d7a19ee6efba8ad8d6778f8ac3d6b3a5ca76e4e3b7134b08e234107a0b100 |
|
MD5 | 671d0f94e8595dc067f10131d4107ecd |
|
BLAKE2b-256 | eacdc8bebef7545c787d40e2bb56da87a5b09cef1dcd923c926172b24186f043 |
Hashes for stim-1.14.dev1712884560-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66531dc846b7310106183b380e6f47c19f4c3df57dbc3fd2e0697fbde2e2e94a |
|
MD5 | 3b9bd21b9bd072e206014eba68113823 |
|
BLAKE2b-256 | b75147e7b9f0db1a228d84d00bd535ec707efc9f11dad61a254caaa77f0a8b0f |
Hashes for stim-1.14.dev1712884560-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f168d563f1805ca3ebe9ea5d796f0758f43c9c11228f261aac0a1036d6193a5 |
|
MD5 | 3e4f054711eab63c1c7e7f375170b811 |
|
BLAKE2b-256 | 3b9bdd78914d8597117025b77289ea4df2fd1b0ea562b438c987633813fceae5 |
Hashes for stim-1.14.dev1712884560-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79edc918023403b1a41af3827d322f5cbed8d46ab4bdbbcb0f259c64650afbc8 |
|
MD5 | f98331f4252bf0689a58da9cb9de9692 |
|
BLAKE2b-256 | b55e027c6b1c38a990aa5cf4f9958bb20281325b06b0a619389d40bc1fee9227 |