IonQ后端Qiskit提供者
项目描述
Qiskit IonQ 提供者
Qiskit 是一个开源SDK,用于在电路、算法和应用模块级别与量子计算机交互。
该项目包含一个提供者,允许访问 IonQ 离子阱量子系统。
示例python笔记本(在 /example
中)应有助于您理解基本用法。
API访问
IonQ提供者使用IonQ的REST API,使用提供者需要IonQ的API访问令牌。如果您想将IonQ用作Qiskit提供者,请访问 https://cloud.ionq.com/settings/keys 生成IonQ API密钥。
安装
您可以使用pip安装提供者
pip install qiskit-ionq
提供者设置
要实例化提供者,请确保您有访问令牌,然后创建提供者
from qiskit_ionq import IonQProvider
provider = IonQProvider("token")
凭证环境变量
或者,IonQ提供者可以从环境变量中查找您的访问令牌
export IONQ_API_TOKEN="token"
然后不带任何参数调用实例化提供者
from qiskit_ionq import IonQProvider, ErrorMitigation
provider = IonQProvider()
一旦实例化提供者,就可以用它来访问支持的后端。
# Show all current supported backends:
print(provider.backends())
# Get IonQ's simulator backend:
simulator_backend = provider.get_backend("ionq_simulator")
提交电路
一旦指定了后端,就可以用它来提交电路。例如,运行贝尔态。
from qiskit import QuantumCircuit
# Create a basic Bell State circuit:
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Run the circuit on IonQ's platform with error mitigation:
job = simulator_backend.run(qc, error_mitigation=ErrorMitigation.DEBIASING)
# Print the results.
print(job.result().get_counts())
# Get results with a different aggregation method when debiasing
# is applied as an error mitigation strategy
print(job.result(sharpen=True).get_counts())
# The simulator specifically provides the the ideal probabilities and creates
# counts by sampling from these probabilities. The raw probabilities are also accessible:
print(job.result().get_probabilities())
基本门和编译器转换
IonQ 提供者提供了对完整的 IonQ Cloud 后端的访问,包括其自身的编译器转换和编译流程。因此,IonQ 提供者后端接受广泛的“基本门”——实际上是 IonQ API 所接受的任何内容。当前支持的门可以在我们的文档网站上找到。[链接](https://docs.ionq.com/#tag/quantum_programs)
如果您想运行在其他 IonQ 后端上(例如使用此 (u
或 iswap
)之外的门)的电路,您可能需要手动重写电路以仅使用上述列表,或者按照以下示例使用 Qiskit 编译器转换。请注意,并非所有电路都可以自动转换。
如果您想获得更底层的访问权限——即用本地门编程并跳过我们的编译器/编译器转换流程——请联系您的 IonQ 联系人以获取更多信息。
from qiskit import QuantumCircuit, transpile
from math import pi
qc2 = QuantumCircuit(1, 1)
qc2.u(pi, pi/2, pi/4, 0)
qc2.measure(0,0)
transpiled_circuit = transpile(qc2, simulator_backend)
贡献
如果您想为 IonQ 提供者做出贡献,请查看[贡献指南](CONTRIBUTING.md)。此项目遵守 Qiskit 社区行为准则。通过参与,您同意遵守此准则。
如果您有增强请求或错误报告,我们鼓励您在本项目的[问题跟踪器](https://github.com/qiskit-partners/qiskit-ionq/issues)中打开一个问题。如果您有支持问题或一般讨论主题,我们建议您在[Qiskit 社区 Slack](https://qiskit.slack.com/)(您可以使用[此链接](https://ibm.co/joinqiskitslack)加入)或[Quantum Computing StackExchange](https://quantumcomputing.stackexchange.com/questions/tagged/qiskit)上提问。
运行测试
此包使用pytest测试运行器和其他用于模拟交互、报告覆盖率等的包。这些可以通过运行pip install -r requirements-test.txt
来安装。
要直接使用 pytest,只需运行
pytest [pytest-args]
或者,您可以通过运行 setup.py
通过 setuptools 集成来运行测试,例如
python setup.py test --addopts="[pytest-args]"
设置
全局 pytest 设置文件可以在顶层test/conftest.py
文件中找到。
SSL 证书问题
如果您收到错误SSLError(SSLCertVerificationError)
或无法成功连接,以下是一些可能的解决方案
- 尝试在您的浏览器中访问https://api.ionq.co/v0.3/health;如果这没有加载,您需要联系 IT 管理员以允许访问 IonQ API。
pip install pip_system_certs
指示 Python 使用与您本地浏览器相同的证书根信任 - 如果第一步成功但 qiskit-ionq 仍然存在问题,请安装此内容。- 您可以通过运行
res = requests.get('https://api.ionq.co/v0.3/health', timeout=30)
并检查res
来进一步调试,您应该收到一个包含内容{"status": "pass"}
的 200 响应。如果您看到企业或 ISP 登录页面,您需要联系本地 IT 管理员以进一步调试。
文档
要构建 API 参考和快速入门文档,请运行
pip install -r requirements-docs.txt
make html
open build/html/index.html
许可协议
IonQ 标志和 Q 标志为 IonQ,Inc. 版权所有。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。