Hands-On: IonQ
Run on an IonQ trapped-ion system (Aria / Forte) with all-to-all connectivity — reachable directly or through Braket / Azure.
1 · Credentials
Get an API key from the IonQ cloud and export it: export QALGORA_IONQ_API_KEY="..."
(or use AWS / Azure credentials if going through a broker).
2 · Validate locally, then submit (adapter workflow · planned)
import qalgora
@qalgora.kernel
def ghz(n: int):
q = qalgora.qvector(n)
h(q[0])
for i in range(1, n):
x.ctrl(q[0], q[i])
mz(q)
qalgora.set_target("qpp-cpu") # reference implementation, local validation
print(qalgora.sample(ghz, 4, shots_count=1000))
# qalgora.set_target("ionq", machine="forte") # planned adapter — needs vendor SDK + credentials
# job = qalgora.sample_async(ghz, 4, shots_count=1000)
# print(job.get()) # adapter future; blocks until the remote job finishesjob.get()3 · Less routing — but still gate-set translation
Because every ion couples to every other, all-to-all connectivity reduces SWAP networks, so circuits stay shallow. Your two-qubit gates are still realized by compiling to IonQ's native gate set (the adapter handles gate-set translation, shots, cost, queue, and SDK auth). A GHZ chain that needs routing on a grid chip maps more directly here.
4 · Error mitigation
IonQ supports debiasing/symmetrization to average out coherent errors; request mitigation through the resilience level when computing expectation values:
e = qalgora.observe(ansatz, hamiltonian, theta, resilience_level=2).expectation()
qpp-cpu first — trapped-ion shots
are slower than superconducting ones.
实操:IonQ
在 IonQ 离子阱系统(Aria / Forte)上运行电路,支持全连接拓扑 —— 可直接访问,也可通过 Braket / Azure 接入。
1 · 凭据配置
从 IonQ 云端获取 API 令牌并导出:export QALGORA_IONQ_API_KEY="..."
(若通过中间平台接入,也可使用 AWS / Azure 凭据)。
2 · 本地验证,然后提交(适配器工作流·规划中)
import qalgora
@qalgora.kernel
def ghz(n: int):
q = qalgora.qvector(n)
h(q[0])
for i in range(1, n):
x.ctrl(q[0], q[i])
mz(q)
qalgora.set_target("qpp-cpu") # 参考实现本地验证
print(qalgora.sample(ghz, 4, shots_count=1000))
# qalgora.set_target("ionq", machine="forte") # 规划中 / 适配示意:需厂商 SDK 与凭据
# job = qalgora.sample_async(ghz, 4, shots_count=1000)
# print(job.get()) # 适配器 future;阻塞直到远程任务完成job.get()3 · 更少布线——但仍需门集编译
由于每个离子与其他所有离子都相互耦合,全连接拓扑可减少 SWAP 网络,电路深度保持浅层。你的双比特门仍需通过编译到 IonQ 原生门集来实现(适配器负责门集编译、采样次数、费用、排队与 SDK 鉴权)。在网格芯片上需要布线的 GHZ 链,在这里映射更直接。
4 · 纠错缓解
IonQ 支持去偏与对称化,以平均消除相干误差;在计算期望值时,通过韧性等级请求纠错缓解:
e = qalgora.observe(ansatz, hamiltonian, theta, resilience_level=2).expectation()
qpp-cpu 上验证 —— 离子阱的采样速度比超导慢。