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.13.dev1710203367-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceced694abe255065b439098f9926ac1d6becf4d63fa5aca29a29725eabcc595 |
|
MD5 | 5e02c90bbc4046749132744141c45c37 |
|
BLAKE2b-256 | b6230b7dd6d74f0887a5abe0752d9539627c2221a58eb00cc923564bca98cfd8 |
Hashes for stim-1.13.dev1710203367-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bfc41d771a748f7ec6a23320748ef91fdc56a7bf3d36df7a270046f5ff725e3 |
|
MD5 | 71cf05200d3ad0ee6222c830f5620279 |
|
BLAKE2b-256 | e034c0bc028294611fc94640197081b1defc91b46384021cab9b6c3deaf7126b |
Hashes for stim-1.13.dev1710203367-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8689628007abffcda23093f10d1fd6c667f596d9dcd8c57d5e053239c5c2ed4 |
|
MD5 | b1e1d990bc8acc005fa8f776e1b1d34c |
|
BLAKE2b-256 | ba681de714ff4c15ba859802395688a901c3b71ee4ad4b08f9bf6b784b82055e |
Hashes for stim-1.13.dev1710203367-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 605ecd662ba8518436c4e750f82b72f07843fe9b820c385068e85550515475c1 |
|
MD5 | 05907196d79118daf5f4f30825f8cead |
|
BLAKE2b-256 | 9c397dd468b3f01c8112337e4d2c50adb41188ca92546aacf4861a378a9f4e4e |
Hashes for stim-1.13.dev1710203367-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7288d5d3578386f6517b8ed49faf41ff83fc4f8ac41cac01e9442ab7fe38b4c |
|
MD5 | ef2cf322eb687f64ddd91fff1d9fed9d |
|
BLAKE2b-256 | f6986726e74099473aaa090bf32ff0a2c7acdfebe471b4455ea85d0f2f60f0ab |
Hashes for stim-1.13.dev1710203367-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22ad5e1bb0914f709cfa56767217fa73b3aae8dee10a284de3fab2978a11c055 |
|
MD5 | b4775fafd13f00b7f80205d4cbba51b8 |
|
BLAKE2b-256 | 357d35b4704dd97bace882cbab2518dcacaa8f1cf76150dbce1e142bae9be157 |
Hashes for stim-1.13.dev1710203367-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 803762064590398e3bc6763b5666cddc5c05741413bcdf4563c2093948d1cb5e |
|
MD5 | 0da0a2a6faa0bc965b4c1b1ea6badfb3 |
|
BLAKE2b-256 | 55ee89aa3296dc066e9c9664c10c2e0c63fd76b5c4ca40ef954dc64597af818d |
Hashes for stim-1.13.dev1710203367-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0eac4f2ea84146ab1fad5f20c1eeaed0f634f2e2b8dacd2494173a055aabddc9 |
|
MD5 | d9f0e4e22ca3ab2047678f85c84df570 |
|
BLAKE2b-256 | 77468f4ec8f1435e6d2d915563028a549495a70b13599db604f29dc0e9bdea00 |
Hashes for stim-1.13.dev1710203367-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2f8a2a2f489c081839178722cc69ae48f521f6ee87ad46f8f0f12ba7ae6e647 |
|
MD5 | 8cf05748765f78052764acefd7102eb4 |
|
BLAKE2b-256 | 7e7b20499987ab057b7a2dbcbbee544a84d8781b46ccd505ab6dd9dbcfb82061 |
Hashes for stim-1.13.dev1710203367-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8880df238de954ebf33d0391f446c6a4ed052faed3685a3be19de7026b101e93 |
|
MD5 | 3eab5ca23ca1969a665c0b18fd3a34f2 |
|
BLAKE2b-256 | d642eadde8b6115e970492613bd64d438e27653419cabdde688b2dc1566b0095 |
Hashes for stim-1.13.dev1710203367-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bef63308f1fb1a4834d8d95ff2b720b2065e3ce81580ad7ade704dc109f3d6f4 |
|
MD5 | 9b19d382ae7645fb04825b7711f401ad |
|
BLAKE2b-256 | 425d55241c54a8f5f0eaa395c061962970436e40148ec641eeaaab6433f00f16 |
Hashes for stim-1.13.dev1710203367-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcfb6c4c1a539e5a22b320254d734b83d7277596644b7e6d5fec5545c8fd8045 |
|
MD5 | eb697841db1a9629f00284f3dcb0f561 |
|
BLAKE2b-256 | 0546104eade3c9f06d283422647af2771bad2406aa15f31aea04b36babc3d60d |
Hashes for stim-1.13.dev1710203367-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66e4b4feac830ab4669b6dae46564b346785b3a60113940b9c60bd9477c3ce57 |
|
MD5 | db0cee3265f207c71934a95f3c4d7e34 |
|
BLAKE2b-256 | d2434777f0a01dde0ee4fe4e2b2cb329481b458bf829e6ca7d6a4e126132ef97 |
Hashes for stim-1.13.dev1710203367-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 682ce94ced910629a4af1265ee172eb1811af7e36e797b114f91105de21bfb07 |
|
MD5 | 552710d518f8351d503e0442211a6e09 |
|
BLAKE2b-256 | db97ffc42b3c3c692f39fa400b3b76c55da9f9eb71663cd9df76257ad25dd3a2 |
Hashes for stim-1.13.dev1710203367-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddef18d00d840b51cd07b1e0dbab0aae2aab8c08f7da80cd553a16ef39629d97 |
|
MD5 | c06aa68b36fbe3bb2a77802be1273367 |
|
BLAKE2b-256 | f2fcdd9d225bf3416110ff0ef451adab6cc84b7450eac956efe56de1fa8ecf1a |
Hashes for stim-1.13.dev1710203367-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f50da971755397c85b13d68c92434b394e0f581b7869654aa018020864265926 |
|
MD5 | 8be44d2ea5bebedebcc03dd30594983e |
|
BLAKE2b-256 | 22166fd83322774faa19cfdee98d0b04d770d457841a07d65b6641937af7c291 |
Hashes for stim-1.13.dev1710203367-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d64c13af46c72ee3f42a7faa5c3ad3642366aa7e8bd7a2dab9f1a10f5dc82355 |
|
MD5 | 49a167246296b02ac5c5579746ed740f |
|
BLAKE2b-256 | 6f1910416a82de4dc9779b75d914612553371ee5f5fa5fd859f7a56ab0d10de0 |
Hashes for stim-1.13.dev1710203367-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c2201db9b898523775c079041a24217aa664674779ef86d19915e22afacdd95 |
|
MD5 | 9ba43c3dccce34f21d2185c6870314a5 |
|
BLAKE2b-256 | 44b060193a106b2ff9ab9f02e62103ff555f5da83c5edcb15eff1c8bf4d4399c |
Hashes for stim-1.13.dev1710203367-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e30d7775e125cb6a15d827307b89f89462385209c9519144f9010a5376a5ddde |
|
MD5 | 61d9d9fd356b82ff5684941e3e042a4b |
|
BLAKE2b-256 | de5ba8be61d83eed8a5c65af3074432b9ab26abbcc97c2b9b50a2b0a53461892 |
Hashes for stim-1.13.dev1710203367-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cf96889e4290f048876733f3d8c1cd81d62a74201a233a8d781b6f726bb2c70 |
|
MD5 | ae3c218e028e81b110deda86e3f2989d |
|
BLAKE2b-256 | 3a25480e5ec71bc5545dd6387a364997fb4c6549bcf7ed773f27c3a4e347e50c |
Hashes for stim-1.13.dev1710203367-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3865b5bbf91ea395dc661611cca9fbefa50e05070294061bf381da9eb0779c0d |
|
MD5 | 95b7f4f8a2a8369fd6a40d719f7445e8 |
|
BLAKE2b-256 | ab1299a425bc2e3003583dd91926ac860fbd4cf8bdd4fd96da47aced7f46625d |
Hashes for stim-1.13.dev1710203367-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb6dcdd0ccae1e2f261e9d503e34aa1cb73541f78fdcfe0cbcfba47e109f2e96 |
|
MD5 | 673c4c0512bafa6b914493148b56073a |
|
BLAKE2b-256 | 53582cf0c5fb50aed8e66302f94d7b75282e4fd8a353a44c52efd03d9bc36738 |
Hashes for stim-1.13.dev1710203367-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c696c86b980f63d7cb3ba0fad4f8ee5955cfbbe5f9a80cadbc3300db414c68b6 |
|
MD5 | aaada34faae6b3a3fb2efc98f91e8856 |
|
BLAKE2b-256 | 0b9742d9545b92a298dc573eac91d82d656472247f60923f74960460f164c6da |
Hashes for stim-1.13.dev1710203367-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b1f29c5f49d01f93b7f1939bb075023c53b1728501ec1aebf41c80bca22d69a |
|
MD5 | 17f2d798ac23d6f5e13f26e70f0bba1c |
|
BLAKE2b-256 | 56bb013b03388a5039df090b3e5e749eabb08256834f718329bc409c0923b8ab |
Hashes for stim-1.13.dev1710203367-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7e10a4227cdfd6c58e7f2c3dd4a19ec0ccd99216289911f01ba166438c524d2 |
|
MD5 | c013d7fec919e35f18b1e7d262eccacb |
|
BLAKE2b-256 | 8072bdc037265f72d08495c33e7b2a375b5984efaa07509c15055182cf011f15 |
Hashes for stim-1.13.dev1710203367-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a15902f9bf3879e0318ad7a2501b2cc0283bcbb1ce1ccf11a2cce1fad6c2d09 |
|
MD5 | e8baf6cc9d164cd5a0ff3b30faa67b9e |
|
BLAKE2b-256 | 55a763c6396ababe0b5da85e8b84137a44dddbff855d86199da199d1b13e229c |
Hashes for stim-1.13.dev1710203367-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00ee219a4ad4055e4235d778fbd0cf845d59d75a73a7c0643918843faba7718a |
|
MD5 | 8da5bf5afee297e46d3c7fdffbce02dd |
|
BLAKE2b-256 | 979daa161c613ff48a91b85c500c49223aa0374896313636e54506e70959c3b0 |
Hashes for stim-1.13.dev1710203367-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5672dc2186e068d4e6452629dde666561803c1fd8ed32d82951d7c9bf9cd072f |
|
MD5 | 5fa3b665a6b202a95a890823d760bfa6 |
|
BLAKE2b-256 | 408f7a072dee4e382be1ebc046d3c35910444957208ca0a87abbab181fed40a2 |
Hashes for stim-1.13.dev1710203367-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b00ce110bea8418424768c7be66feb91806e0fa19253acbdea2fab8da963fb05 |
|
MD5 | 748c90473a8cf8201f83d526135d8541 |
|
BLAKE2b-256 | 14ec6375464355b0ccf644adb5226f34db1857d42affaa40a8fa349f582cb8d6 |
Hashes for stim-1.13.dev1710203367-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b76633b7dfdaf772cc65c3ad546fec244342e66b6f9dcc471ec099434b384b90 |
|
MD5 | 9d05d4be7d0f701352603c6bf27ebad7 |
|
BLAKE2b-256 | 100374aa7d2b0c9a220deb756976703b0b5b8b1a82b4439c959271bb986b52ee |