Prepare Your First Vendor Hardware Workflow
◐ Design-level API
This page documents qalgora-Q API design, architecture, or adaptation workflows. Code examples illustrate intended usage and are not guaranteed to run in the current reference implementation.The workflow for preparing a qalgora-Q kernel for real vendor hardware follows the same shape on every provider: get credentials, write a kernel, transpile, and submit through the vendor's SDK to read results. The open reference build itself runs locally; this page is the universal recipe, and each provider's workflow page fills in the specifics.
The five steps
- Get access — create an account with a provider and obtain an API token.
- Set credentials — export the token as an environment variable.
- Write & validate — build a kernel and run it on the
qpp-cpuCPU statevector reference implementation first. - Submit — set the hardware target and submit through the vendor adapter (planned · not in the open reference build).
- Retrieve — poll status, then read the counts (adapter workflow).
1–3 · Write and validate locally
import qalgora
@qalgora.kernel
def bell():
q = qalgora.qvector(2)
h(q[0])
x.ctrl(q[0], q[1])
mz(q)
qalgora.set_target("qpp-cpu") # reference implementation, local validation
# qalgora.set_target("gpu") # optional: requires qalgora-gpu plugin (planned)
print(qalgora.sample(bell, shots_count=1000)) # expect ~{00, 11}
4 · Submit to hardware (adapter workflow · planned)
Specification interface / planned · not in the open reference build
Real-hardware submission is an adapter/export workflow: it requires the vendor SDK and credentials,
and is not included in the open CPU reference implementation. The lines below are commented out to
show the intended shape — substitute the real backend name for your provider.
# qalgora.set_target("ibm", machine="<ibm_backend_name>") # planned adapter — needs vendor SDK + credentials
# job = qalgora.sample_async(bell, shots_count=4000) # returns immediately (adapter future)
# print(job.id(), job.status()) # queued / running / doneReference build runs locally — not real hardware
This example targets a remote cloud/QPU, but the open reference build does not submit to a real machine — it warns and falls back to the local CPU statevector simulator, returning simulated results. Submitting to an actual device (e.g. 天衍/TianYan, IBM, IonQ, Origin) requires the vendor’s own SDK and credentials.5 · Retrieve results (adapter workflow · planned)
# counts = job.get() # blocks until the job finishes
# print(counts.most_probable(), counts.probability("11"))
On
This is the intended semantics of the adapter layer's job/future — it blocks until the remote job
finishes. The open reference implementation does not produce a real remote job.
job.get()Good habits
- Validate on a simulator before spending hardware time or money.
- Use async — hardware jobs queue; do other work while you wait.
- Mind the bitstring order and add explicit
mz. - Turn on mitigation for expectation values — see Error Mitigation.
Pick a provider
Free to start: IBM Quantum (Open plan) and
Origin Wukong (public cloud). Then
IonQ, Quantinuum, and
Amazon Braket.
准备第一个厂商硬件工作流
◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。为真实厂商硬件准备 qalgora-Q 内核的端到端流程,在每家平台上都大致相同:获取凭据、编写内核、转译,再经厂商 SDK 提交并读取结果。开源参考实现本身在本地运行;本页是通用步骤,各平台的工作流页面会补充具体细节。
五个步骤
- 获取访问权限 — 在平台注册账号并获得 API 令牌。
- 配置凭据 — 将令牌导出为环境变量。
- 编写并验证 — 构建内核,先在
qpp-cpuCPU 态矢量参考实现上运行验证。 - 提交 — 设置硬件目标,经厂商适配器提交(规划中·尚未发布,开源参考实现暂未包含)。
- 获取结果 — 轮询状态,然后读取计数(适配器工作流)。
1–3 · 本地编写并验证
import qalgora
@qalgora.kernel
def bell():
q = qalgora.qvector(2)
h(q[0])
x.ctrl(q[0], q[1])
mz(q)
qalgora.set_target("qpp-cpu") # 参考实现本地验证
# qalgora.set_target("gpu") # 可选:需 qalgora-gpu 插件(规划中)
print(qalgora.sample(bell, shots_count=1000)) # expect ~{00, 11}
4 · 提交到真机(适配器工作流·规划中)
规范接口/规划中 · 参考实现暂未包含
真机提交属于适配器/导出工作流:需厂商 SDK 与凭据,开源 CPU 参考实现暂未包含。下方代码已注释,仅示意预期形态——请把真实后端名替换为你所用平台的后端。# qalgora.set_target("ibm", machine="<ibm_backend_name>") # 规划中 / 适配示意:真实 QPU 提交需厂商 SDK 与凭据
# job = qalgora.sample_async(bell, shots_count=4000) # 立即返回(适配器 future)
# print(job.id(), job.status()) # queued / running / done参考实现仅本地运行 · 非真机
此示例虽指向远程云端/QPU,但开放参考实现不会真正提交到真机 —— 它会给出告警并回退到本地 CPU 态矢量模拟器,返回模拟结果,不会真正提交到天衍等真机。真正提交真机需使用对应厂商的 SDK 与凭证。5 · 获取结果(适配器工作流·规划中)
# counts = job.get() # blocks until the job finishes
# print(counts.most_probable(), counts.probability("11"))
关于
这是适配器层 job/future 的预期语义——它会阻塞直到远程任务完成;开放参考实现不会产生真实远程 job。job.get()好习惯
- 先在模拟器上验证,再消耗真机时间或费用。
- 使用异步方式 — 硬件任务会排队,等待期间可以做其他事情。
- 注意比特串顺序,并显式添加
mz。 - 开启纠错缓解以获取期望值 — 参见 纠错缓解。