跳转到主要内容

一个用于分析量子稳定器电路的快速库。

项目描述

Stim

Stim是一个量子稳定器电路的快速模拟器。

API参考可在stim的GitHub wiki上找到:https://github.com/quantumlib/stim/wiki

Stim可以使用pip安装到Python 3环境中

pip install stim

安装Stim后,您可以使用 import stim 并使用它。有三个支持的用例

  1. 使用 stim.TableauSimulator 进行交互式模拟。
  2. 使用从 stim.Circuit 编译的采样器进行高速采样。
  3. 使用 stim.Tableaustim.PauliString 进行独立探索。

交互式模拟

使用 stim.TableauSimulator 模拟单个操作并检查结果

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]

高速采样

通过创建一个 stim.Circuit 并将其编译为采样器,可以非常快速地生成样本

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]]

这同样适用于包含噪声的电路

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]

您还可以使用 stim.Circuit.compile_detector_sampler 采样注解检测事件。

有关可以在stim.Circuit中出现的门列表,请参阅GitHub上的最新README

独立探索

Stim提供数据类型stim.PauliStringstim.Tableau,支持多种快速操作。

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)

项目详情


发布历史 发布通知 | RSS订阅

下载文件

下载您平台对应的文件。如果您不确定该选择哪个,请了解更多关于 安装包 的信息。

源分发

stim-1.14.0.tar.gz (814.0 kB 查看哈希值)

上传时间

构建分发

stim-1.14.0-cp312-cp312-win_amd64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.12 Windows x86-64

stim-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

stim-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ x86-64

stim-1.14.0-cp311-cp311-win_amd64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

stim-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

stim-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ x86-64

stim-1.14.0-cp310-cp310-win_amd64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

stim-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传于 CPython 3.10 manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp310-cp310-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

stim-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl (1.9 MB 查看哈希值)

上传时间 CPython 3.10 macOS 10.9+ x86-64

stim-1.14.0-cp39-cp39-win_amd64.whl (2.6 MB 查看哈希值)

上传时间 CPython 3.9 Windows x86-64

stim-1.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp39-cp39-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.9 macOS 11.0+ ARM64

stim-1.14.0-cp39-cp39-macosx_10_9_x86_64.whl (1.9 MB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

stim-1.14.0-cp38-cp38-win_amd64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.8 Windows x86-64

stim-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp38-cp38-macosx_11_0_arm64.whl (3.3 MB 查看哈希值)

上传时间 CPython 3.8 macOS 11.0+ ARM64

stim-1.14.0-cp38-cp38-macosx_10_9_x86_64.whl (3.6 MB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ x86-64

stim-1.14.0-cp37-cp37m-win_amd64.whl (2.5 MB 查看哈希值)

上传时间 CPython 3.7m Windows x86-64

stim-1.14.0-cp37-cp37m-win32.whl (2.2 MB 查看哈希值)

上传于 CPython 3.7m Windows x86

stim-1.14.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (5.0 MB 查看哈希值)

上传于 CPython 3.7m manylinux: glibc 2.17+ i686

stim-1.14.0-cp37-cp37m-macosx_10_9_x86_64.whl (3.6 MB 查看哈希值)

上传于 CPython 3.7m macOS 10.9+ x86-64

stim-1.14.0-cp36-cp36m-win_amd64.whl (2.5 MB 查看哈希值)

上传于 CPython 3.6m Windows x86-64

stim-1.14.0-cp36-cp36m-win32.whl (2.2 MB 查看哈希值)

上传于 CPython 3.6m Windows x86

stim-1.14.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB 查看哈希值)

上传于 CPython 3.6m manylinux: glibc 2.17+ x86-64

stim-1.14.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (5.0 MB 查看哈希值)

上传于 CPython 3.6m manylinux: glibc 2.17+ i686

stim-1.14.0-cp36-cp36m-macosx_10_9_x86_64.whl (3.6 MB 查看哈希值)

上传于 CPython 3.6m macOS 10.9+ x86-64

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面