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.dev1710971876-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1255680f9078d40145850c26e93cdb8146c6343b2eeaa02d23cae6771760cef3 |
|
MD5 | c1641753ff67653c1394905bb9c02551 |
|
BLAKE2b-256 | 94d4798241cb55e5944d5b070e08d809307cc2606d31571a9170bccce1d5949a |
Hashes for stim-1.14.dev1710971876-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42d6faac8930e6d0ddefa51a6f4a63a7c1a7abac02ee65a1620d3e10e13686bf |
|
MD5 | cc907827f67a9fa7ba7445ede04f9a1e |
|
BLAKE2b-256 | bc8250dfd68544b34729696b7fc417ca64b061f427da01ab8345dfbbdf0ef5a1 |
Hashes for stim-1.14.dev1710971876-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08d4a86a233af8b29700d41b4922de5e08296afb3303bdee1c10362038043a56 |
|
MD5 | 6088c1c78ed45590d128a56c3030aecc |
|
BLAKE2b-256 | 5c5b72ddc25c50bbe327a6fc9ed76286dda5b7d0b2eefc374c86b48cbfde37d8 |
Hashes for stim-1.14.dev1710971876-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | add07f3b7b652a919f3b8ba6e674baeab914eeb282715c00487da4051a7140ec |
|
MD5 | cc9ab052957d0a3581c96f562830afe9 |
|
BLAKE2b-256 | a91e104f9856d92ec902a09afa240f47aa2712e26f380c826f14aa9552629a13 |
Hashes for stim-1.14.dev1710971876-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c041536a1a6cce0a22d6ad2a156d9016100f9f1af64bb7ad0b618c73094cc411 |
|
MD5 | 32f6aa335fb542868e893dc5761c4c13 |
|
BLAKE2b-256 | 04c886588e13d340da2fdc8c4ca7edc911d8a56c35034fb611d4b4439b6d1476 |
Hashes for stim-1.14.dev1710971876-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e008bddcd170a6e1c0f50ef45763a75564c756728793ba4eef16f822aa0b8e |
|
MD5 | 2b6cd671a96103a38f2305c3c4d20ceb |
|
BLAKE2b-256 | 651162d06a4ed6795131cc36aad31ba30267ba983944004538677f9b699532e8 |
Hashes for stim-1.14.dev1710971876-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db12004217b6c28219dcd07797aac0176d9b0309589cdc7a9ed516d54fc51bd5 |
|
MD5 | fe13c9d86aa8b1e9dbbc352f93149340 |
|
BLAKE2b-256 | 696f06df8d5c2e01e64eaba6f7173b63ece926640ce6460e78a6360428e4b38d |
Hashes for stim-1.14.dev1710971876-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba069df5aaea2dca0dc3983d35e87d1b708f7d37fd177cc08b25b5990e78250e |
|
MD5 | 56440056da21c9dc0134d736ef8771d1 |
|
BLAKE2b-256 | 90c99313d52b8fdab1008d661a79f1d54f976009c90e29e89c5e6e8c4354a79f |
Hashes for stim-1.14.dev1710971876-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe64cb772a7be5f8effd4a8869fc9b04862bf53ca040cbc4d05e065f1b667bcf |
|
MD5 | a28c3a289bf8919df9785697fb61ae61 |
|
BLAKE2b-256 | 63393b69b71d10df6a43cd9ed8326b420ef95c976cd7ae2cf31fee47e74a2c86 |
Hashes for stim-1.14.dev1710971876-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad8da865e152acb95ec22be08634a3bbf35ba5137957aafbe60f08979883f892 |
|
MD5 | 83404a9cbec2f9470b9362b0592c0812 |
|
BLAKE2b-256 | 3cc78c3cd748c76f5431d00fee859a88303e3c2b280d3e7fbe5d2117c7318475 |
Hashes for stim-1.14.dev1710971876-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f4d5b111de7d5ead6b5277541bddf831f70ac424056be91fdb6a1695e06c5a5 |
|
MD5 | a65911f9f8f8dac79927d444861c0655 |
|
BLAKE2b-256 | 0877f509f5919fd1abd468acc96cb956edd7ce40da64c6f71b0f39e164366d43 |
Hashes for stim-1.14.dev1710971876-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73c04cd863b5837e24bf914887eece82b3c60189f072811713f2cfe3f1e4f272 |
|
MD5 | b7ffc0041beb90793db095c5e3796702 |
|
BLAKE2b-256 | 6b4222d799fa6683d10ac0baa6be44568a0211d45d7a79ab34b228064b9d8a0d |
Hashes for stim-1.14.dev1710971876-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f987498a96069bc422273ee70eca9725db8bb201206f0c73ca85844c18077f56 |
|
MD5 | 5a5171f6a03b39a33fc0b4c00a576f78 |
|
BLAKE2b-256 | ce735958eb3cefbfc154c3ee38ae1c4bfbc28e752b1b3458161de988f06a206d |
Hashes for stim-1.14.dev1710971876-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21a77df482f0fec9e1333b4e3d57829f78cf1f1df00e6f42a018c99029a64183 |
|
MD5 | 6983908d141e932cd2c58e8be9204ec6 |
|
BLAKE2b-256 | 36a818116eafac6ff2f4554a269a5015fc8238a9ef08ad566723b4a42d188043 |
Hashes for stim-1.14.dev1710971876-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a807ab1cef63b837f474b3ae3ff7acc6897df78dad8c15a59b4e271c2a64c25 |
|
MD5 | e2e8386138524946d5cb69839c78bf6a |
|
BLAKE2b-256 | 90c9c90819f748586a4023ded7fa412d82305e501457c7288d60f7c66d6e1fac |
Hashes for stim-1.14.dev1710971876-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61f783c97d62fce054b764a36a25e84cc5ea12f46060bc469ef8fc35d8bc93b1 |
|
MD5 | 60f3f2ecd056b0c358b31d074985b265 |
|
BLAKE2b-256 | e17da219c5bf956d0a11adcbb627b999f5b23e4b4ea81be3b775dc2e4766b19b |
Hashes for stim-1.14.dev1710971876-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cb91381e8f480a614e1aa4643254a5bee623fa58aaa90d502fd6c00cf6a2630 |
|
MD5 | d5b63c450e145d238993692e792c0897 |
|
BLAKE2b-256 | c539314522328f4ce9a772843e53fa5094f4e69636c919f75a4c8a660583665a |
Hashes for stim-1.14.dev1710971876-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86048a44f6675f42c6ffa1f6f1292ca485d309ecc043ce6f69377ee0de905e68 |
|
MD5 | 79ff95fb67da1d9ba6f44e26aa035633 |
|
BLAKE2b-256 | 516aa18fbc759192a2d96a7b1d2bc6f82167d34c9cc22a8ddd2a30db3f54c01d |
Hashes for stim-1.14.dev1710971876-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c8f17d650198604ff138e4c1cb1c4d377e8579833172956fb78fbfc2d8f739 |
|
MD5 | b799b94ffc99ed88f53a72965d335b6a |
|
BLAKE2b-256 | 38b5c1cbbb310021e217e9fde9808d66726b7753a6ac3b3dfbd313d5ecd73f18 |
Hashes for stim-1.14.dev1710971876-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eae684467a1bb271fff7db1fd9497d59ccd3520d2b4bb4d586ac68aa9d5da6d5 |
|
MD5 | 9b31182610996a973f80677379ae8c9b |
|
BLAKE2b-256 | 1cb217c0c1817f25845137481e43466cd68d49cd9a810a0cb5dd63c48d9d2919 |
Hashes for stim-1.14.dev1710971876-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 741a78dda9a8fecb1a8347881a3a6c4391e44752a938a3fcf433945d6127a151 |
|
MD5 | 3d1c432db383825341f547b97d2712df |
|
BLAKE2b-256 | cb4fed05d49fb908db33485c726f858b7c88dd9ccc47a28bf2215158b3fb3d77 |
Hashes for stim-1.14.dev1710971876-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 232b6117f25d7d56c4c2ad45f973d6c19f7f7e336efdabcf3ebc235c4695d7a9 |
|
MD5 | e8dcd7a1259a2251287c6e9d90d26d93 |
|
BLAKE2b-256 | 6225d7d1b3c4ca3d1e8093f1ee66d1b9a30c52c682a703fa6b2bca94d8e570fe |
Hashes for stim-1.14.dev1710971876-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2807ab0445bb0119228f1647cf25bf755feacde1ee881196ca378cb7279d3fd |
|
MD5 | 31fff05881d5792e277db50f5ad6808b |
|
BLAKE2b-256 | 3ea02fd85c401ab23760f1f26267f5518da3d7c1727be1ee31249cd5c7a9f0b3 |
Hashes for stim-1.14.dev1710971876-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efda4b7942f600bba75ba3e6c16327d04ffe7f610838b84a7370a4bdca029efb |
|
MD5 | 573a7441ccc2f5ef5d17451b048625e7 |
|
BLAKE2b-256 | 11cbd9cb1724afca252c4f680ff06f70b8470ce3d1b04cc8dffa6a9cab214e7c |
Hashes for stim-1.14.dev1710971876-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d015311084b6c80696efffac926817a338cbc3cef9fd05ae3b949c64527b6c7c |
|
MD5 | a04204c1b5ff9f501fd5c1c36ef96edd |
|
BLAKE2b-256 | 7d213edf59d6d99f10b4a5ec1d11c6b682cd7e0bbd987abe6a5b864d8bf72e72 |
Hashes for stim-1.14.dev1710971876-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f41fe4a047301156ab022db3945b0577104974d5bf51a0fd631462eccdd2392 |
|
MD5 | 6428ec12588fc9affdfe272d469aaad6 |
|
BLAKE2b-256 | dcba8fc8c03071812a7457c4ed2c03c1229a233a757e94de26a2c381afe42e80 |
Hashes for stim-1.14.dev1710971876-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dbb8b86f4182191dc933b2c5e524943eac8d396ed7f73030490fa0a87c5b409 |
|
MD5 | efea4a71f93f2a9839aee1226df60766 |
|
BLAKE2b-256 | 6b15cba7785d176440905af8b8e42d6d1a4f3e310bd6d9ba748e072b25d46401 |
Hashes for stim-1.14.dev1710971876-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c61b99a1643af1be8629e89223ced0172b0152fa9c5b045143e1e1d5a13ba14c |
|
MD5 | d74e0262ac374a687da0cd2ccedc590b |
|
BLAKE2b-256 | 1767df359fb56f410605f8083bbbe7c1f33a9393e336a948fa121e4c6ce8dab2 |
Hashes for stim-1.14.dev1710971876-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fca436d0590c9e6e4c39e976c22360e0098b3095b9d3741cbe69998d5c92754d |
|
MD5 | 3a05f4771afa61b602b69eeb8ffc0a8c |
|
BLAKE2b-256 | a2b381b60e591801cfc29f3b5e22be9348b744e0c052285cbb5df84810f3a033 |
Hashes for stim-1.14.dev1710971876-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3084088ec167b74603404f29defadfcffc6a778348aaab0d78c66881e93407f6 |
|
MD5 | 688f42afe97d529b975c2977ba18abee |
|
BLAKE2b-256 | 0c25bfcd3038a311415eb18f624e9d6afe304ee866a3ea95ac23326ddad72525 |