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.dev1686537725-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 997ef68902f49a3c201362054e24e49dc64378ed23e543a236863f3bf086a98b |
|
MD5 | 72176ffa3f5b8a1241f712dff44aba9d |
|
BLAKE2b-256 | 1cdb1a361be250e15b50dd709eb1d6fcb8fc8c021c073cc61b79ce8f841694b6 |
Hashes for stim-1.12.dev1686537725-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38037383777f0cf1eee5623d67400066d563791dd5f3aa26ae0d8aa963d66e66 |
|
MD5 | 9deae69d1e4da4d5890f12ea78f68844 |
|
BLAKE2b-256 | 64ae4f4e2ae04fc8e4e20c7b6f8995f0859b7f9734794941bee97dd8f4f72723 |
Hashes for stim-1.12.dev1686537725-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 819c00d9c8fb4d6e6449baf1f5723b863cdea5aab2c3c1a9c05ad6fea8d53ae4 |
|
MD5 | 261ad40b6e0ce2eeef407bbf71c0d400 |
|
BLAKE2b-256 | 738d4cea61442276ed357f38641a6791aeff417f28aabad4243daa4701f65bd5 |
Hashes for stim-1.12.dev1686537725-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9600cfa0e63b64c955d3d0d33abe45d53200ffdf9a3627871b7acff6bb1328c3 |
|
MD5 | a7a739fa6b84e4fa6af63828fd75e681 |
|
BLAKE2b-256 | e6ffbe5c3a36f548b74923628c759fb533aa729e373e758b022e8393746a4970 |
Hashes for stim-1.12.dev1686537725-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e8c5542e3377bb6f32cfcf14335ae2990938cf277de51215af6da4087a64988 |
|
MD5 | 51e85cb117500ac1138125a79be161c9 |
|
BLAKE2b-256 | 4dae861eece56a76d83ae191f8539db59b932c584cd7bbe6af950ceb5558a489 |
Hashes for stim-1.12.dev1686537725-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07db1e504ce3ccc618a01640a36205e3dfb8c28f0729a7849e6db798c8e1943b |
|
MD5 | 72a796b373337787836352e62d13410d |
|
BLAKE2b-256 | 6818f9bfe8eee84e7b0123f902e6921cca410d73e3e46994595e53056ba5adaa |
Hashes for stim-1.12.dev1686537725-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 272ae67a7cc85d1060e97dabdb4e801dec0d8513d99a62045068f171cbff4a37 |
|
MD5 | e7d4c63e35d0d112f1012d71d7b5e19c |
|
BLAKE2b-256 | add3b1d78c2a52465cde1d13fadee629abad869fe44d82324f0845db2d9e5788 |
Hashes for stim-1.12.dev1686537725-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4afbea5ca347158800523a82de678d640d52c5b7a71be5630110af96ccecb3b7 |
|
MD5 | c1e0cad8327998617ef1d884d80a1a4f |
|
BLAKE2b-256 | 5ce520382ff43ed48c142e6e0ffd447264241e299b01989eeccd696f91adf965 |
Hashes for stim-1.12.dev1686537725-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d7156aef75b1e16af603219ff243c6198e0bba12a7b3fb66b76d0bfaccaeb0f |
|
MD5 | acacce5df8c51060839488df590ab19d |
|
BLAKE2b-256 | 9c912794878f5a9d5bb7f906ee33310c46152c5e67c45ece6d98444b9eccdf47 |
Hashes for stim-1.12.dev1686537725-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c86b53f63025c7056469e1680956e67f0312a51d93b19a331016a3656b71670 |
|
MD5 | bb9d36cffe51795cb4ea358ccd4229a6 |
|
BLAKE2b-256 | 639ef7f9e473d3e6ebc3f45fac78fa7135895ff7ecc4d48a8d4155ffd6f20a9e |
Hashes for stim-1.12.dev1686537725-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4fb770482eb6d1fe2d837f47d72cbc22bce39747c21bc279cc3a6d17f22230a |
|
MD5 | 207a812bfb4738e1e07b0a4723f3e68c |
|
BLAKE2b-256 | 7261744d32f10d3c2ec5016d09c7206ff4d372a0320f3b51b3d3e8c722cd9a4c |
Hashes for stim-1.12.dev1686537725-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d8f315f86d174f6f80945e40bf3e882a00f756da6edfb2a591418a98824707c |
|
MD5 | 46bcfab6af0ca0c7d82a0af218d31b74 |
|
BLAKE2b-256 | 019167ab20e5f63f868f5a948ad8156817ea1697e7d74ef5046010fafce052f2 |
Hashes for stim-1.12.dev1686537725-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be8e2642568b1c7e30cf7a5a6938725ee061ca8088643420824e365d8727087 |
|
MD5 | 702b63d0c7a4a7c9ebeba8dc32e096cf |
|
BLAKE2b-256 | 82ea215d728bf80d58fc4708f8c27d047176970e938c52ff1eb717b54a1aa7ff |
Hashes for stim-1.12.dev1686537725-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3e7a905339bba66e3f40347dcf8fe4393f2951a4ccfead539a08b2e0c4b1758 |
|
MD5 | b6e43a1be253faf17d9f31f44d50ab98 |
|
BLAKE2b-256 | ea15179ba49bef11ad1fe731dc72b84ca2c101eb53c6650b1b648ff28bd8c66e |
Hashes for stim-1.12.dev1686537725-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b430d7fcd95a9f7b05556c911ac8e2f4ebf095d7799743ffc378d850ad3866f |
|
MD5 | 0b4dda10cb7dee7d0d188560b890216e |
|
BLAKE2b-256 | 7683e66c40fc1b7790847f49af1cf04f64a30a4a10387654fe16611ff4b3d416 |
Hashes for stim-1.12.dev1686537725-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd0d557f30ff9b5118551a250d4175ed6fb5f9d868c60315406228d3d32cc8cc |
|
MD5 | 1d94b4b3854a26a0e609e9e564d209dc |
|
BLAKE2b-256 | 37d08888520b7c0c28871d3c8d69bb06566e8b57d054eaca995cfb6478c1d9c2 |
Hashes for stim-1.12.dev1686537725-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4d9984f7af1b042d9bd4d088ec655d79f80fee37b6837e42c775b7922df057 |
|
MD5 | 1ab18c74dc4a0929d4f1a1ccec2773e4 |
|
BLAKE2b-256 | 90dd0513081cfd6b96d9bbde22558bed342eef7bf8b22b60f1cba8696c626a8c |
Hashes for stim-1.12.dev1686537725-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11655007dc7d901eb4bc53b69d01663d52a81399970a58da5ac75c2d5ee8e880 |
|
MD5 | fac98bb867c33b27a15bfa5473acff0c |
|
BLAKE2b-256 | 1e7d5562632c960cb1384faca413941ca65666bb0afc56f72a057d0ca6cd959e |
Hashes for stim-1.12.dev1686537725-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 082182bf75ee68da152380c56b814a6460407844ed7a0ab67fdc19923344f7ce |
|
MD5 | c4e1f762008ee19bee40756fc255033c |
|
BLAKE2b-256 | 38b685ac7c7ad250931a76af588db41e19d39bae71696f6abd2106177213703c |
Hashes for stim-1.12.dev1686537725-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5d32f3022cf294961655aa360ed9fe4e65197c47e9575a7b023d03cd9828275 |
|
MD5 | 6fe5a7693cd73bfca105319623b09b89 |
|
BLAKE2b-256 | 3e8d6dac887e1d2b360fb6995d1c11f506e3af27c178e8afb07e239c768b639c |
Hashes for stim-1.12.dev1686537725-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a38a666a37d9036a6d07a13d2520e5c9bd1e1e9518276a2869801502b3bfd3d7 |
|
MD5 | 99f98de89e941ec73c7aa96eeb3fb94f |
|
BLAKE2b-256 | d6ab1df9502e48801e970523d9098cf5d71b14beabcbeb00f2ce6201559e224e |
Hashes for stim-1.12.dev1686537725-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91709f8daaef2551d900ab4e7882c2c3db3c4908b57ef37ff6091608c987f626 |
|
MD5 | 7f5f25dd866d8ba2361968d82c554936 |
|
BLAKE2b-256 | be3a63cffe7aaac358adc57f189835819980c353a18364d1a6a64ce6ca83072a |
Hashes for stim-1.12.dev1686537725-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fa0166eff7b90e3b9668a0c9b1d627521c52a7039a943aa17e8e85982b37ffa |
|
MD5 | c4c48ab31721149e7de6796e934ae17c |
|
BLAKE2b-256 | deca049a8c7e6a55681b9d3ec747dddaf842d55f6f620165efac8513407fb7bc |
Hashes for stim-1.12.dev1686537725-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be309495bfe1b1cace72f71917178fca1a6a84bf40b619562da0d723c6497faa |
|
MD5 | 5516b6e0760552a4fa6dd0171160eb0e |
|
BLAKE2b-256 | 619276c5d3c02a620920cc518122113dcc6a01c58cacd7bf9a16fa00d0dbc727 |
Hashes for stim-1.12.dev1686537725-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38a2d842e740679c75507875f2d692348b056acd4250c4be950797b6b12fb81d |
|
MD5 | 551c5c80514a00131fbb7f3ac4894e9e |
|
BLAKE2b-256 | e31235e3d3675eecf55353e0e1cadbf9adb7d8aab4ddff91839fe8ba3c172fce |
Hashes for stim-1.12.dev1686537725-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867d7ef1bd7bd04005006bab43180f024bdd7ae8bd6f47c1d79837c15054d85a |
|
MD5 | 25d97f659d17226a30f9e93c598e52cd |
|
BLAKE2b-256 | c4e49c0f7994c6680815bf23bfb445333935960409ba1f8761202562b5eb1ccd |