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.dev1682630312-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e38e404ae84b4f5589ee166fa54eb61b952fbf49cb2e0f8cd5fa71a94f291c3c |
|
MD5 | 70838abc4629b9d0e3d43d30f645cd39 |
|
BLAKE2b-256 | 1cbc6059931526efe68b81ff29066f103b155547953d9fa9809a2c84e3b2f2c4 |
Hashes for stim-1.12.dev1682630312-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9f52620c055f719bf2b9f60178530f0fde8449ab30cca4de43eb87145f76b71 |
|
MD5 | bd800ccea097d4b4c51b9ce824893d60 |
|
BLAKE2b-256 | 2a08b02fe411c80697c0c97cd3d84061dfbcbea0af6e2939d2a5f8645fa0f786 |
Hashes for stim-1.12.dev1682630312-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57abf70ff74d7b89c2dd7edad783e78041be3ba9a32e03ec3c4510c4193d6b3f |
|
MD5 | 4b7286a17c56d1e890a2cbfbd0768ee7 |
|
BLAKE2b-256 | e560dba5fd4288772e08fe63b74079e28c2eb6f50ba2181fe0e3a410233cb4d0 |
Hashes for stim-1.12.dev1682630312-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 961eebe14fe878f2c0ce6a48a3562adc99fa3dbc8f71cf81bfbfbbae38ca65d2 |
|
MD5 | 9e015cf305e504577590948aa434cb97 |
|
BLAKE2b-256 | 75df4f8a3187280eee39e10d6e0c078e77ed1d9ccdf8079e4c9c627df3f28eaa |
Hashes for stim-1.12.dev1682630312-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e11036522fe976d3ea3505ac0eda8349aaf83bf03a62e46a4528bfdf1e8dc989 |
|
MD5 | 1242d1974828b01e565776c5266d6a73 |
|
BLAKE2b-256 | 507bc669ac5dc99df6c95926ddc64ea79782ed447a9decb600c741d54ef0385d |
Hashes for stim-1.12.dev1682630312-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867f285b9a27f44e0828b27607fe775f95f4e37844abaf1c9f84b9e4ae4fa8d3 |
|
MD5 | ab7b863d53b891c0645db9fba124b454 |
|
BLAKE2b-256 | de181b7f0039701e96f2b8244d12d6a5670f1144fa0f8263b0d44b564d3998bb |
Hashes for stim-1.12.dev1682630312-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3067022c82e2154cb26dbc5f032e9ea04e8483897483608629e319af06e344ee |
|
MD5 | 8f6917f61da00f0ec268c261489a8964 |
|
BLAKE2b-256 | 0cf17b1286ab4a341c1523cc3a49c92c7890d38ad86c2bd6a023a502631790d1 |
Hashes for stim-1.12.dev1682630312-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c8bddc4c234057918784081c3d57146a0baea2ec34a14dfbcf42f951a55c51c |
|
MD5 | b3f8b6eaf6939d6c9472d29da0bbc955 |
|
BLAKE2b-256 | 51264666aa02096b21ef895c931fad2eeca61bf8907510ecf57edf82762eb85d |
Hashes for stim-1.12.dev1682630312-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 433cc58fd255d3b12c423b4954ce0418b501546439b8bb6b41e948ceb30075a3 |
|
MD5 | 1d9b6c6a37e4ef89a16293f884da2dd3 |
|
BLAKE2b-256 | 6cdb77f704fa9f6e6a313ea64c1e4f4475882cd451a700d82b460291c4b4e9aa |
Hashes for stim-1.12.dev1682630312-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2af871cd12e7ae96b0c1b5599f159351c622c555c1748ee7cf60dfccd7ef91d |
|
MD5 | 7565748541d92ffa36ea3a46af759d52 |
|
BLAKE2b-256 | d411e938ace42ea13af6abd7cf202943cc594be7eb2fd207e59309f7fee87997 |
Hashes for stim-1.12.dev1682630312-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43708abb3eabd336fdc63c7eba2850a2ff244c4636ba77e13ecf6e3e689904a |
|
MD5 | 3bac78c243b45793ff75e21921d6b89f |
|
BLAKE2b-256 | 5c3b1acb84f618d3fedeaa22470ba7a16f7eefac887635c9725a20130fc5ca3f |
Hashes for stim-1.12.dev1682630312-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80c4a59c8002267d4f0c3fbff3cb06368f20c756a2dac251ea6e281a13f1691d |
|
MD5 | edbf541ff0ccc009411cb650bb1c9cc7 |
|
BLAKE2b-256 | df19308a57dc1c8d08b87085ffe9a33949228792a84eaa68491ea89ab9f87355 |
Hashes for stim-1.12.dev1682630312-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3964e56880f4650efe1b097cbfa6f8f72a36604d5be1cef7469df4d48bc07dff |
|
MD5 | e99c1058bee7f81c1dce982e49323a15 |
|
BLAKE2b-256 | 8cf156a3f63c2fb2f1c59075c5b9d52096685a000b5eb7ffc9e01ea94c74fddf |
Hashes for stim-1.12.dev1682630312-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7905dfa5017991da6629efa6d98e3e383b2563c5513ee8ca085b2526336ce88 |
|
MD5 | be9f126b4e49eaa3c53f7cf75dead219 |
|
BLAKE2b-256 | 27d800f2f89e1408a919fa5f4ef543ac3c606da020786a62ee6ca6be75a6d9f1 |
Hashes for stim-1.12.dev1682630312-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 926a463644055f36948751411c99b68a0236a3ecd0a1e73ef067d35c40d97bce |
|
MD5 | a8cc40bc4e2d51582531200496ddb15a |
|
BLAKE2b-256 | 0f2a9e5ff2ea24ab37588ca6d866026c27891a4685131b2bff08a1e03b449119 |
Hashes for stim-1.12.dev1682630312-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dcb8cd62f4d15d3bce2d94a592d48a932eaffd0f15972b9eb0820b671cd515d |
|
MD5 | 6f1e53ee8c35464de73c8f6d95f1f36d |
|
BLAKE2b-256 | 0dadd7ee1fc78296986620d318b7227df0e03d308b9788526a726f96dd4ba2ab |
Hashes for stim-1.12.dev1682630312-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c017849470ed79b4baf8808c0e45b3a1960f39e273ae366a76f5946b459aa990 |
|
MD5 | 2ec45ae30cf03d5298e5559a0c7c37e2 |
|
BLAKE2b-256 | 6e1579f888017f9eca98e753e0ecf3768cb9311c9a0bf45001117568f9c913e9 |
Hashes for stim-1.12.dev1682630312-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65cdf4d4377ac28a958538922b5518de740956900d481dea200df49d10e792eb |
|
MD5 | c6221304a7c129c4ec62fe505759bf12 |
|
BLAKE2b-256 | 82bf4f26974b6ea148161b90c93a5a15ab39925295310211b0dc8667d03e2a87 |
Hashes for stim-1.12.dev1682630312-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ac082bdda3b60e0992adc0c75ffd4f5069ac6e6878231f9ef922d44af01e87a |
|
MD5 | a083d2ef9a06b9cf7e01cb2c88080d99 |
|
BLAKE2b-256 | ba6d56b9c24b025a084afcfc2dfbf6c7debc98330f1d01280d922062f671e9ec |
Hashes for stim-1.12.dev1682630312-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af882b1bf22b5431ac31cc51893c9324dbd32bf7d08501bd97a462f54f1012e |
|
MD5 | 1567f3d6806515eb27caca3c561511a7 |
|
BLAKE2b-256 | f3a1028c9020803940c11362ddf2529767a8880d2494465b9fdd362edebbcadb |
Hashes for stim-1.12.dev1682630312-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f01f6285f074ae0c862f07ee2cc62e71794c5c3659bf2e825424b992b01f9cff |
|
MD5 | efdbf97e69d7c94503984b26679e1b52 |
|
BLAKE2b-256 | dc8c1db7e499835bb8d7b5921b6c9154157092b93234e44fe605afb9a4a5cac6 |
Hashes for stim-1.12.dev1682630312-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97a4b6aa4c23e09102aed2e585dda98f5e77f29c4b7df21be33c7110f6c1c1f4 |
|
MD5 | f552fef89aa497d0a8dea214df63366c |
|
BLAKE2b-256 | 5cb9efd94531d016502eca3b3f2588d6ceb06524f96fb98972f95200af4e322c |
Hashes for stim-1.12.dev1682630312-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9681ae2292bfb1b09f9dbd702d0fb5cfbcf44208c6b33f77df9df3430afeec93 |
|
MD5 | 0e2ce8174a5ad7c19b4ae05085ded09a |
|
BLAKE2b-256 | 74de9870a7cb02367fe21be268187b663327db742d13ee3a59ca46c5d88b18fa |
Hashes for stim-1.12.dev1682630312-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd943e87adfea4cf926aead2e7ad3972978602de6d9b5f299528068890022cc |
|
MD5 | 0d5909b058eeeddf9011779d59606f05 |
|
BLAKE2b-256 | b6aba6024548a0b03d3a1d09e80f18f97b8a617a63f1709b489fddef448fdbc6 |
Hashes for stim-1.12.dev1682630312-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe76aee5cacc8d3fdb9faf2f20d43ef92086e5cdb1913a42716888b33fa178aa |
|
MD5 | 9548edd963caa75531f6a9879d2d5d41 |
|
BLAKE2b-256 | 870b292db0881d3d4b71abc225fae9f73bfe7203591e237bb4aa4a41381f29e8 |
Hashes for stim-1.12.dev1682630312-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aa0843839a6f36ce31612b84a3a09680477adf293b84648b394e51c64d2cf3a |
|
MD5 | 3e03bf5bf1138b5369a362876964fcd9 |
|
BLAKE2b-256 | f36cfad3f8ac2515140b8955ffcb41bd5285d12e8678114186053d0ff02b0411 |