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.12.dev1686536079-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f5a050981db9b1eaa0ce88caddfaf4e4b45b7dd2e3e7c43645f581c3fb0def0 |
|
MD5 | 4d57f36b145bff087f035867a6055b07 |
|
BLAKE2b-256 | d3f54ff3057ea71946529738bbaefab353ae52178b41cedd8a115c58aaca427e |
Hashes for stim-1.12.dev1686536079-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dcd03b9691e252adfbc874a89c057e70837dab6947e23727a0b948c4a5f9917 |
|
MD5 | e210cb5657b0a938fbb19a02b36ec579 |
|
BLAKE2b-256 | 6d996ad09431622ca9c3f970499ba3a9cd7602f0df95234d46999b8e3c48152b |
Hashes for stim-1.12.dev1686536079-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8421fcd4e428c011b910b613a6246df0b13b385fc764182f80f69eebf42ca4a8 |
|
MD5 | 95019abee999e404da3087ad6ca1d13c |
|
BLAKE2b-256 | e82bdf520022b2a55e4bada7dac4b7c82c433ec5c439268aa0f1a5178356c387 |
Hashes for stim-1.12.dev1686536079-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aed4f6600a22282719a70bcb83043b284a831744c306d58f6ebe9bde399cc418 |
|
MD5 | 01ee5e37239186bc23e775150ec7175b |
|
BLAKE2b-256 | 7fc9c5eac9574a87ecec32ca136f3996b50c6eca61e999a88b1fd3b9e61dc4b5 |
Hashes for stim-1.12.dev1686536079-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec4898a019b8ce03bffc7b5e141b88b3a0fddc344a0a0be3dbeac77928ef1eb5 |
|
MD5 | 065b48cd8ff69ccaa9bb3691b022965a |
|
BLAKE2b-256 | 110b55dc9539129eff6cc6970d543f2d686a8ab5682b8b3d1e1b02dbd192fcd0 |
Hashes for stim-1.12.dev1686536079-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e9993f0ae3ea922101ed72f156ae1c09ed9c4c62dfcab37de3e24fd2720436c |
|
MD5 | 02690baa454cce1cc76caa7f5e760066 |
|
BLAKE2b-256 | 24cbbf7a20990bac8a2a50b1c23e451c8f3f2525a0968cd7c779e04a2ee6ef68 |
Hashes for stim-1.12.dev1686536079-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b55dae539b2a0230c692717a16e01f74e859a712ac88138fa2fcd83ea182b707 |
|
MD5 | b1cb1a034d8c9faac55e9e00fbdaba73 |
|
BLAKE2b-256 | 174673ef616e0bd30da433039219db7d46ef249f8bd1aa3417f41d87b503f1b9 |
Hashes for stim-1.12.dev1686536079-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d54b2b4d6ef4a645fefe76c4e9fb82e2cde733f99fc1d9dda7c8e23bb83efd |
|
MD5 | a7e28949ca2637c9f6f8a8c67f4f6504 |
|
BLAKE2b-256 | 7e33e166a85c7e65c9f9b90f23fb763bd13947e885266820cec07fe82b5647f4 |
Hashes for stim-1.12.dev1686536079-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291c72ec650ee0882fc164b98b287902b1a00ac9f794252869bd15f81203b713 |
|
MD5 | b8c23d9ac12d257dfd2d5c795956c2a7 |
|
BLAKE2b-256 | 3d0b7142ba740dabc02bd8c93d4799b9dee932ecc2dbfeeb299f91bd72d52993 |
Hashes for stim-1.12.dev1686536079-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29aa22f90c443ba92e0272183a9c8949794e71286c1f5fbebe65aca883f75b59 |
|
MD5 | 8412f3a6d9f0fe3202ad0717e250f1ac |
|
BLAKE2b-256 | 47fd37bdd0c40f84def89f225b5bef18bc38820cf10c018aff5e8ecda037a476 |
Hashes for stim-1.12.dev1686536079-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8909b4cfeac095b4cff06736e2ce807df08391985e3ba05299701676983aa06f |
|
MD5 | a749d2aa9a847f294cc58e2d124fdeb3 |
|
BLAKE2b-256 | cc5c5819335e264e784f7bc98c3e93c7239d89c7eebcc71b82b73ab55ca57e18 |
Hashes for stim-1.12.dev1686536079-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca0371ddbf8747bab5fa0eb1134994bf849402e8f85db240a4c3fa4a49f7e577 |
|
MD5 | fa0235c219c1dec10c656c0a3610396d |
|
BLAKE2b-256 | 908b390c1362f55f65d6b4e5a8a6f376634640a93ce46d75ab3e204f729c69db |
Hashes for stim-1.12.dev1686536079-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c51dccca4a8071338c605be47df7f96cb3bc8e09af12136a3d6d2f3060ffc1ee |
|
MD5 | dae6fa23b0ff8427a03b058dce1f641e |
|
BLAKE2b-256 | 59274ce243fa9491179aa8706ae31f3637d07f17ad7f48e0c36f5fe430940e14 |
Hashes for stim-1.12.dev1686536079-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0430f6895f217a741d916f6298f3161c86ffe17e1916f2d5820d4b2eb8fb9868 |
|
MD5 | 951b4f84e1107d1fd7fc72edd67ee79f |
|
BLAKE2b-256 | b58c420146940945085def9e84b5185ac7ae2ff78ea4ce7b70175961e9a7e1f7 |
Hashes for stim-1.12.dev1686536079-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66f1bd13ac9c397186e5d8161490936d77dba1283895404679c9a4b3f2ba58e3 |
|
MD5 | 40ff32ba23ee3a5462177792968b3ddc |
|
BLAKE2b-256 | 718454fb64bd1b7f4ac9a870cbb184fac132737eb2173eb042af9447b3d1ebad |
Hashes for stim-1.12.dev1686536079-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b67912f9e5c67000027a846e276a69534542f282cd38606e536bb85d52f524 |
|
MD5 | bc3e2bdde72b7165969f8f5f33d48715 |
|
BLAKE2b-256 | c46fea99a9bfc4fc874fc1154a638ccb4bf5600772521af5384e83af5de939d3 |
Hashes for stim-1.12.dev1686536079-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1c133da782f163815af4fb0a49dadfd0e65915352bf6891170edf501e324547 |
|
MD5 | 5736e489d8f682f06df0818122c56963 |
|
BLAKE2b-256 | ef51aa7ef4534d71eb8cdbcbc79fd1aedf0e48fd62727a2de8e744b528a5ac21 |
Hashes for stim-1.12.dev1686536079-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a08a0703eb1dbf6b689884c3bbf4a2c338dc700494f8ded93e78b119ec9a7d1 |
|
MD5 | 33e6945d2fd598ff3819190da9a793a6 |
|
BLAKE2b-256 | 77172c3188fac5dac33dc01b5007fb3cde061a227f4e91dfb13e3924c52f8da7 |
Hashes for stim-1.12.dev1686536079-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1f388519008269d9e9305bba4d1ffd1b3008a5ae2604526b14d2603835515d7 |
|
MD5 | ac3d3b54e381c08951a71971fa71e2b8 |
|
BLAKE2b-256 | df942e7a93edc5d216bab81aaea7ee8b3a46448dee7c4f1a256f622ebb616224 |
Hashes for stim-1.12.dev1686536079-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03b4a5e0d22d23e6e1981bf62a7a050a6d4840e50105cab60f5577a9dd65c23d |
|
MD5 | 764c3ce3a2a0c52932fb1746aec74ab8 |
|
BLAKE2b-256 | b236ab2637dd7c1704310f65099dd4457e44aa9107fd0bf8dc1fe4fa2f9451eb |
Hashes for stim-1.12.dev1686536079-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f127ebcc12537a59d9b17d7e5d17638fec6758a870bf694d674b34a699b296f0 |
|
MD5 | a32c894021e2043ff28e92ad3c401948 |
|
BLAKE2b-256 | 37978091fef2862691e782431db513b52f84c6e5b1766dbdce92716c0fcf6b66 |
Hashes for stim-1.12.dev1686536079-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63499e25a5cd975384d74e80e41c04ff5d76af7f820e650cae526e607b142c35 |
|
MD5 | beeb1986ca597262b4806f56b58ee336 |
|
BLAKE2b-256 | 4541907804d12bf98e552853b84b0083f7cab6f154f2cb3d4e6f49f3ce8ebab4 |
Hashes for stim-1.12.dev1686536079-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5dfbcdecb41f33b77fce2a692517a41934edb8ae902883b63926e4d3411b364 |
|
MD5 | 8241551e6f017232f3a791dc1b681073 |
|
BLAKE2b-256 | 97271819be9d0dcf602e112938d13744fa7bd315a11a163783f9080eccea89a7 |
Hashes for stim-1.12.dev1686536079-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 039d066cf92506dc39faac48c72472b0ee7babeedbf7fe0ba50b82b79834011d |
|
MD5 | eec2c6a4192ed37931cb81a1d3d0925f |
|
BLAKE2b-256 | 704c3f4bc8bc18adcad664ddb8f23b265e1518ffccc8b61ae1814bb0c0aa5fda |
Hashes for stim-1.12.dev1686536079-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975441170176d4131a0674bf7a2197c53cd180e26e9c7e7959cbd6796e093713 |
|
MD5 | 4905f266e6d6c5d15e7fdac1f6fd3f49 |
|
BLAKE2b-256 | bf7959630b70c73ff7aca18cd82a0b5c6c7c709050ce62e2ba22ba81a1590bcd |
Hashes for stim-1.12.dev1686536079-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c5dc0429b52b56f4e926183c2c8b6e37a13ed6ce88c97b8ed4f55fd4cac338f |
|
MD5 | 31dd71f6bf2ea44abafc668666411c26 |
|
BLAKE2b-256 | 9186ff87196ec29e5b2d1711d2b5d468c6802b1328d69b8e15956e2792fa9ba2 |