OpenQASM Exchange
◐ 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.OpenQASM is one of the common circuit-exchange formats; real hardware usually supports only a particular version or subset, so after export a program still goes through the target SDK's parsing, transpilation, and capability checks.
Importing OpenQASM
import qalgora
qasm = """
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c[0] = measure q[0];
c[1] = measure q[1];
"""
qalgora.set_target("qpp-cpu")
# Planned adapter:
# kernel = qalgora.from_qasm(qasm)
# print(qalgora.sample(kernel, shots_count=1000))Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.Exporting OpenQASM
@qalgora.kernel
def bell():
q = qalgora.qvector(2)
h(q[0]); x.ctrl(q[0], q[1]); mz(q)
print(qalgora.to_qasm(bell)) # OpenQASM 3 text for exchangeSpecification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.Exchange format
When no direct adapter exists, OpenQASM can serve as a bridge — many quantum SDKs and hardware
providers accept some version of it, though usually only a specific version or subset.
Notes
OpenQASM 2 is not OpenQASM 3. Support for dynamic circuits, classical control flow,
extern, duration/timing, and pulse/calibration grammar is not always
complete — check what your target SDK actually parses before relying on a feature.
OpenQASM 互换
◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。OpenQASM 是常用的电路交换格式之一;实际硬件通常只支持某个版本或子集,导出后仍需经过目标 SDK 的解析、转译和能力检查。
导入 OpenQASM
import qalgora
qasm = """
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c[0] = measure q[0];
c[1] = measure q[1];
"""
qalgora.set_target("qpp-cpu")
# 规划中的适配器:
# kernel = qalgora.from_qasm(qasm)
# print(qalgora.sample(kernel, shots_count=1000))规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。导出 OpenQASM
@qalgora.kernel
def bell():
q = qalgora.qvector(2)
h(q[0]); x.ctrl(q[0], q[1]); mz(q)
print(qalgora.to_qasm(bell)) # 供交换使用的 OpenQASM 3 文本规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。交换格式
没有现成适配器时,OpenQASM 可以作为桥梁——许多量子 SDK 和硬件厂商都接受某个版本的 OpenQASM,但通常只支持某个特定版本或子集。
注意事项
OpenQASM 2 不等于 OpenQASM 3。对动态线路、经典控制流、extern、duration/时序以及脉冲/标定语法的支持并不总是完整——在依赖某项特性前,先确认目标 SDK 实际能解析哪些内容。