什么是 IonQ SDK?
qiskit-ionq 是 IonQ 的官方 Qiskit 提供程序 —— 它让你用标准的 Qiskit 语法构建电路,并直接在 IonQ 的 Quantum Cloud 上运行,无需 AWS 或 Azure 账户。理想(无噪声)模拟器是免费的。噪声建模模拟器则模拟真实硬件的行为。真实 QPU 的运行次数按次计费。
理想模拟器
无噪声,云端托管
免费
噪声模拟器
模拟真实硬件噪声
免费
真实 QPU
Aria、Forte 硬件
按次付费
如果你已经在使用 Amazon Braket 或 Azure Quantum,也可以通过这些平台访问 IonQ 硬件。
安装与设置
terminal
pip install qiskit-ionq
# Get a free API key at cloud.ionq.com (new accounts include trial credits)
export IONQ_API_KEY=your_api_key免费云模拟器
该后端 ionq_simulator 是由 IonQ 托管的无噪声态矢量模拟器。它免费使用,只需要一个 API 密钥 —— 无需 AWS 或 Azure 账户,也无需本地算力。
ionq_simulator.py
from qiskit import QuantumCircuit
from qiskit_ionq import IonQProvider
provider = IonQProvider() # reads IONQ_API_KEY from the environment
# Free, noiseless (ideal) simulator
backend = provider.get_backend("ionq_simulator")
# Build a Bell state circuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
job = backend.run(qc, shots=1000)
print(job.get_counts()) # {'00': ~500, '11': ~500}噪声建模模拟
在真实硬件上消耗运行次数之前,先用模拟特定 IonQ 系统的噪声模型运行同一电路。它仍在免费的模拟器后端运行,因此你可以零成本验证纠错策略。
ionq_noisy_sim.py
from qiskit import QuantumCircuit
from qiskit_ionq import IonQProvider
provider = IonQProvider()
backend = provider.get_backend("ionq_simulator")
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Model the noise profile of a real IonQ system on the free simulator
job = backend.run(qc, shots=1000, noise_model="aria-1")
print(job.get_counts())真实 QPU 硬件
IonQ 的离子阱系统提供出色的门 保真度 以及全连接量子比特拓扑,因此电路所需的 SWAP 密集型路由比网格连接的硬件更少。真实 QPU 访问按次计费 —— 在提交大型任务前,请检查你的 运行次数预算 以及 IonQ 当前的定价。
ionq_hardware.py
from qiskit import QuantumCircuit
from qiskit_ionq import IonQProvider
provider = IonQProvider()
# Aria: 25 algorithmic qubits, trapped-ion, all-to-all connectivity
aria = provider.get_backend("ionq_qpu.aria-1")
# Forte: newer generation, higher fidelity
forte = provider.get_backend("ionq_qpu.forte-1")
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Check current queue and calibration data before submitting
print(aria.calibration())
# Submit (real QPU shots are billed per-shot — check cloud.ionq.com/pricing)
job = aria.run(qc, shots=100)
print(job.get_counts())Keep exploring
💡
Also available via HLQuantum
Want to run the same circuit on multiple backends without rewriting your code? HLQuantum abstracts this SDK (and 5 others) behind a single unified API.
python
import hlquantum as hlq
qc = hlq.Circuit(2)
qc.h(0).cx(0, 1).measure_all()
# One line to switch between any backend
result = hlq.run(qc, shots=1024) # auto-detect
result = hlq.run(qc, shots=1024, backend="ionq") # explicit