有效模拟量子稳定器电路的aaronson等人的chp模拟器的参考实现。
chp-sim的Python项目详细描述
python chp稳定器模拟器
scott aaronson和daniel gottesman的chp模拟器的简单参考python实现 定义见 their 2004 paper “Improved Simulation of Stabilizer Circuits”。 该模拟器能够在多项式时间和空间上模拟量子稳定器电路。 具体来说,它使用O(q^2*m + q*c)时间和O(q^2)空间,其中 q是量子位的数目, m是度量值的数目, c是hadamard/cnot/相位门的数目。
安装
pypi上提供了chp_sim包,可以使用pip:
python -m pip install chp_sim
或者,您可以复制粘贴github的chp_sim目录 将存储库放入项目中。 唯一的运行时依赖项是numpy。
用法
下面是一个模拟的例子 a circuit:
importchp_simsim=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 measurementsv0=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.assertnotv0.determinedassertnotv1.determinedassertv2.determinedassertbool(v0)^bool(v1)^bool(v2)
包装
(自我介绍如何发布新版本。)
根据需要编辑源代码并运行测试。
pytest
制造轮子。
python3 setup.py -q bdist_wheel ls dist
上传到测试pypi。
twine upload dist/*.whl --repository-url=https://test.pypi.org/legacy/ --username="${TEST_TWINE_USERNAME}" --password="${TEST_TWINE_PASSWORD}"
验证测试包是否正常工作。
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))"
上传到prod pypi。
twine upload dist/*.whl --username="${PROD_TWINE_USERNAME}" --password="${PROD_TWINE_PASSWORD}"
验证产品包是否正常工作。
mkvirtualenv test --python=/usr/bin/python3 pip install chp_sim python -c "import chp_sim; print(chp_sim.__version__); print(chp_sim.ChpSimulator(4))"