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.dev1714772198-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 203f747ec21299b423ce2534fd4cfbedf7c9c9918a6edd5b8ac0ff1ccad283a1 |
|
MD5 | e0ff60809e1737c47f6ce27559c46fca |
|
BLAKE2b-256 | a9da1f049c8a12413211943ce58efccd9d7695c8697aa6a006c0a8007737d116 |
Hashes for stim-1.14.dev1714772198-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05f597fbce09340387fdd7c26ed7c4698a8e4cb9103dadefc0187dbc68cb82db |
|
MD5 | e1e7079b8c3f0574463a58a1852c934d |
|
BLAKE2b-256 | e6b803ab2f0865a49b3b25e5ceae516c9d6fa9aedae5d375c2b32f02d1ec069e |
Hashes for stim-1.14.dev1714772198-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc655950e4099a23e68671f94b5962b22b3e6b4cc85a377802a736cf3b596440 |
|
MD5 | c8f322105bae5cd54fc7c97df232513c |
|
BLAKE2b-256 | f775262080d6a1e217461c0fb292f33668019675c239622ebe899deb7d10b602 |
Hashes for stim-1.14.dev1714772198-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa2d8a700f9ccd7f2ae3e7d0bfd4c9c295b038be057d44811fc6d8335d8d2f6d |
|
MD5 | 1d65f54e0a1366849f667b7d5ed49aa1 |
|
BLAKE2b-256 | d76f194e9c7d02c1b8c68b6dd6f30d1b3df18ee4092d9a35af66bea1800cd063 |
Hashes for stim-1.14.dev1714772198-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2193ecaf3dc30df9315b652ac424e43c8b837e62758d1de495bc3853aeefdcca |
|
MD5 | ad5765f7bb1da96e674098a968e0d8f7 |
|
BLAKE2b-256 | cb5c0ce29af92bd3511bce3bb8a05a526d05fc5d36eca7b9cb2d803911efdc0c |
Hashes for stim-1.14.dev1714772198-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a27fcee59688fa25d45273ca97915ddb2ab410f196bb07ebaaa6561890760606 |
|
MD5 | 51e2eb4b67b0c0e4524cccde849fc4d6 |
|
BLAKE2b-256 | 5d35ae0fe583420acc26d00523c6fb03d64d5265b0e3b6b4a63654009e5f2d20 |
Hashes for stim-1.14.dev1714772198-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 009a5e46a29e3f4d4bd57de214da7c1a7c64ab4e030046ee9b890ae601099742 |
|
MD5 | 1cef7cf2457e357d247c05c59c15862c |
|
BLAKE2b-256 | 4116a00ba1923b08edec9d6db730f54feb823c792f3ddc0a6347e6ae50e8a300 |
Hashes for stim-1.14.dev1714772198-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37db708842e02eee435246c6095ade1cab60ff9213faa5ed3ac4a9d797fd525d |
|
MD5 | 1842488124718b5ce1a566167c20e2b5 |
|
BLAKE2b-256 | 7ddf939ab44cb15058932ef013d77c4e85a5713286e7d3451c42f5783a7be5f1 |
Hashes for stim-1.14.dev1714772198-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae773ad33f4aec54628832092920882383bbabd4b6a6e034331a79aa97d1f43 |
|
MD5 | 481d9a00331ae7817073542eff470765 |
|
BLAKE2b-256 | 4bb817334a0ccb8adc26e3fa5819cec37acf338f2caf6bb47db0934eac1e5e90 |
Hashes for stim-1.14.dev1714772198-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee17eaa99c24245e96223b36fd9244e49a70d647831d827a08f54a62ac046fa8 |
|
MD5 | 1247a3aed3ab4f31f83b539ee1579323 |
|
BLAKE2b-256 | f1df3914bf62ae2ad70dff445a8a086199c3a68f62d32644948a75ec5ea084a3 |
Hashes for stim-1.14.dev1714772198-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffe7f4e52d7b0f6d9e8fcbddf13ef9c11768e4a0d998f22721219edd29c0144d |
|
MD5 | f4c5df600596ef507cc0da1c9e766ad7 |
|
BLAKE2b-256 | 527bd8c90d10424567e0cbb4f7f102bf83e441695562cb160979c85364455f96 |
Hashes for stim-1.14.dev1714772198-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b406c4da1df896379212e29df5f3fa9a52228a9c0d20c8f643bf1c7077931ca |
|
MD5 | a530e2dc243cb8ac5f1bdcb03c9a681e |
|
BLAKE2b-256 | 9f59cb9eccb0b718401e6854d789b1a5ae0ff66b80abc06bc54e597adcb97e11 |
Hashes for stim-1.14.dev1714772198-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b203719ef6207e37d8972aca1eee792c8d84da28503840b7d8f4e0a094700e34 |
|
MD5 | 5c0ff1c5888c688090e5f5e025265ccd |
|
BLAKE2b-256 | aa55f026f90ace837a4350ebc05a584439ae917da36218e65051a878f4a21e6c |
Hashes for stim-1.14.dev1714772198-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 529c12d91ef0ff7887ee64b85e2322ffaf85f3373ab05917ec7d7705e1d8fcc9 |
|
MD5 | a204f7220852b46dffcf54370e9b5309 |
|
BLAKE2b-256 | 336505d87b9ff290bb9548bbf4a9ad8f3c944b939c8ab627946b44e5f076e5a7 |
Hashes for stim-1.14.dev1714772198-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8a186cdcf8473d7ce434f683e039b72b908b61abb1ad4632c61e7781526c34b |
|
MD5 | 4b784b3159ae01a11b01447ebcb63940 |
|
BLAKE2b-256 | 0a1e571a4905cae67a3cc97af837d86db5a0e9a1fe55ba9e563300801d17d5ef |
Hashes for stim-1.14.dev1714772198-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc58299f55a617b976b0ae1fa4469adad383bdb0ff57cd2cc16a5daa21539217 |
|
MD5 | 0932b89bb22e4cf62cc15e046a510a8e |
|
BLAKE2b-256 | 861340ed3f13f5baea51e76b564e0b6fbbd573facfa40a223cb0bdc3504f075d |
Hashes for stim-1.14.dev1714772198-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e68b8e424001e8bc37ea83decd4420f0d7f9b828c246f12656ae30771625b902 |
|
MD5 | 817ca35974e7031a418b285eff16dfe6 |
|
BLAKE2b-256 | add148e577a35d56b15cc37fe499ee082bcd3f0b9ae2d869fe7e16efc491f773 |
Hashes for stim-1.14.dev1714772198-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c78c4d31a6e8caae11342a9ab94c6e560ed88d4310d9372f4e9fd2dcfd0e11c6 |
|
MD5 | 50ef2aa2b3d82f0030c571d5abfd88ee |
|
BLAKE2b-256 | 1324b87f8906d32c9c76a658b758166ebae336ed21e877aeb97b9147de27ca5f |
Hashes for stim-1.14.dev1714772198-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5605cda7ec3d346e440fa549effaea37b0cb17aaa262742d8cc9f0ff7834a193 |
|
MD5 | aa9bef04e3608626edd720e184d5089c |
|
BLAKE2b-256 | b8a7504355d1e2dd89539598a4af2bafbe16d334747477f5524c385dcff3e314 |
Hashes for stim-1.14.dev1714772198-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa4c3faa9dab9b98ef7c237eec738cdb679067431b2518b78cc548220c80f715 |
|
MD5 | 11f41ed108d29c3c697da08eb83ae476 |
|
BLAKE2b-256 | 9c35976858587ce78fde7b498dd1de25da6a4d48a521a28c44ac6b804bf385dc |
Hashes for stim-1.14.dev1714772198-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbf24b7ac2c5674b2c7d1b6d79fdd8929688fa91aac8acc1d0babdf7d56b1fb3 |
|
MD5 | 9fdac5be54190b2cbea3614565e01683 |
|
BLAKE2b-256 | 450a2135fdc2603433f6236a30852dc7d95584d4d01af2b4d057da89b86e35d1 |
Hashes for stim-1.14.dev1714772198-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 457d2a15920cc3533c02d881d48fc2b0cab5dfb0bbdc022b3ebc7e5d79310a96 |
|
MD5 | 170f20dbd8507c4f4dde819612559a11 |
|
BLAKE2b-256 | b9d38d5ad28105f3e4d77241c2b994f5724515d6015d923784dc16c7d04f49d5 |
Hashes for stim-1.14.dev1714772198-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 221dab160c489de0ce6d39adae0f77c92ea44f55343a7a4c1878b165691df689 |
|
MD5 | 128f29c30b8483d708e728a229ad7dc0 |
|
BLAKE2b-256 | daab1d4d9ab4043a765ccab26c7ff9e54464e9092df078dbf23cba145900f802 |
Hashes for stim-1.14.dev1714772198-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d063114753718d975b87c176f528be70abfc1b9676fdae8a2af6e27fb3d48ef |
|
MD5 | 330b7c37c402d5190e622bb965030d65 |
|
BLAKE2b-256 | ee667eb2b5c77cdffbfe6a8da6869bcc159d87f1a003be28e5c9fa9d5472cd15 |
Hashes for stim-1.14.dev1714772198-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44a68f529ad72f9873adde59310aa105e5047c797980d97fcf48bd31f715a8f |
|
MD5 | e92b71f16dbc1629eff6a099a6b6271b |
|
BLAKE2b-256 | a294ce188c8801b294975b0e909e86f7df9b6c12b52678012f020429790f57fe |
Hashes for stim-1.14.dev1714772198-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f406d2067c5c7e0f2dd3ee652e3c7157aabeea15a176547b34484d6d5e960e1 |
|
MD5 | cc5759c8eb312af01b6f488db3236362 |
|
BLAKE2b-256 | 7c49353bff4d6a8e3aac7c9af333e50465f22349bba9f25840d6af64378b3559 |
Hashes for stim-1.14.dev1714772198-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee64b92e87366ba0d401f3fbee3fd1225ea064ee5c725eb031036667284cf69f |
|
MD5 | cb9b8c1f455f226f03a987bbbd00d38a |
|
BLAKE2b-256 | 27ffb67eef0a8d48846a4569e04b865abb641d5083a5c10e1ec69ef2311a2a4f |
Hashes for stim-1.14.dev1714772198-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c65a9fe568d314a55ff0ede6225062285752d8d3ada1c4a8a14889d4016e87 |
|
MD5 | 374a81bb7dab18eace745fabb909f40c |
|
BLAKE2b-256 | a447c1e92d2ab1356d6c7253eab511f05d6352868c632a533520c6ebd87010c9 |
Hashes for stim-1.14.dev1714772198-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d64817fc20a92b6b6e86526ab9ae82c93647da4b36c684ce9bce0663aa5a5b |
|
MD5 | 51045b9164693257f6e56eb0ce0e1c46 |
|
BLAKE2b-256 | 23522cf6f1269a2cd46a4cb10a9b87f6d2b052d459cee57a1e4c6dc0dd3bfe1e |
Hashes for stim-1.14.dev1714772198-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c3b6c29a0ab46774b7436709b4d9e5089455dc263727c0b2a6109e4c4fbaf80 |
|
MD5 | 4277759ad0c3af002956c5c0dfbb7ea4 |
|
BLAKE2b-256 | 686c36bcac94be144e785196a76482250a0a6c5a1c9e4c8762f9fa384399d236 |