跳转到主要内容

Aaronson等人CHP模拟器的参考实现,用于高效模拟量子稳定器电路。

项目描述

Python CHP稳定器模拟器

Scott Aaronson和Daniel Gottesman的CHP模拟器的简单Python参考实现,如他们在2004年的论文“改进稳定器电路的模拟”中定义。此模拟器能够在多项式时间和空间内模拟量子稳定器电路。具体来说,它使用O(q^2*m + q*c)时间和O(q^2)空间,其中q是量子比特数,m是测量数,c是Hadamard/CNOT/相位门数。

安装

chp_sim软件包可在PyPI上获得,并可以使用pip进行安装

python -m pip install chp_sim

或者,您可以将GitHub仓库中的chp_sim目录直接复制粘贴到您的项目中。唯一的运行时依赖项是numpy。

使用

以下是一个模拟电路的示例

import chp_sim
sim = chp_sim.ChpSimulator(num_qubits=3)

# Desired circuit:
# 0: -------X-------S---H---M---
#           |
# 1: -------|---X---S---H---M---
#           |   |
# 2: ---H---@---@-------H---M---

sim.hadamard(2)
sim.cnot(2, 0)
sim.cnot(2, 1)
sim.phase(0)
sim.phase(1)
sim.hadamard(0)
sim.hadamard(1)
sim.hadamard(2)

# Show internal simulator state.
print(sim, '\n')
# prints:
#   -Y..
#   -.Y.
#   +..X
#   ----
#   +X.X
#   +.XX
#   +YYZ

# Perform measurements
v0 = sim.measure(0)
v1 = sim.measure(1)
v2 = sim.measure(2)
print(v0)
print(v1)
print(v2)
# prints [note: one of four possible results for this circuit]:
#   True (random)
#   False (random)
#   False (determined)

# Check pattern the outputs should satisfy.
assert not v0.determined
assert not v1.determined
assert v2.determined
assert bool(v0) ^ bool(v1) ^ bool(v2)

打包

(关于如何发布新版本的笔记。)

  1. 根据需要编辑源代码并运行测试。

    pytest
  2. 构建wheel。

    python3 setup.py -q bdist_wheel
    ls dist
  3. 上传到测试PyPI。

    twine upload dist/*.whl --repository-url=https://test.pypi.org/legacy/ --username="${TEST_TWINE_USERNAME}" --password="${TEST_TWINE_PASSWORD}"
  4. 验证测试包是否正常工作。

    mkvirtualenv test --python=/usr/bin/python3
    pip install numpy
    pip install chp_sim --index-url=https://test.pypi.org/simple/
    python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"
  5. 上传到生产PyPI。

    twine upload dist/*.whl --username="${PROD_TWINE_USERNAME}" --password="${PROD_TWINE_PASSWORD}"
  6. 验证生产包是否正常工作。

    mkvirtualenv test --python=/usr/bin/python3
    pip install chp_sim
    python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"

项目详情


下载文件

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

源代码分发

本版本没有提供源代码分发文件。请参阅有关生成分发归档的教程。

构建的分发

chp_sim-0.1.1-py3-none-any.whl (11.2 kB 查看散列值)

上传于 Python 3

由以下支持