qalgora-Q Docs Hub量子文档 ✦ Ask AI✦ 问问文档

qalgora IR Specification

◐ 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.

qalgora IR is the MLIR-based intermediate representation that kernels are lowered to before targeting a simulator or QPU.

Why an IR?

  • Portability — one representation, many backends.
  • Optimization — gate fusion, cancellation, and mapping run as IR passes.
  • Verification — illegal programs are rejected at compile time.

Structure

qalgora IR is a dialect of MLIR. Quantum values flow through SSA references; operations act on qubit references and classical values, preserving the program's dataflow.

func.func @bell() {
  %q = quantum.alloc : !quantum.veq<2>
  %q0 = quantum.extract %q[0] : !quantum.ref
  %q1 = quantum.extract %q[1] : !quantum.ref
  quantum.h %q0 : !quantum.ref
  quantum.x [%q0] %q1 : !quantum.ref
  quantum.mz %q : !quantum.veq<2>
  return
}
Two dialects
A high-level dialect mirrors the source kernel; a lowered dialect is hardware-oriented. Passes translate between them and onto each target.

qalgora IR 规范

◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。

qalgora IR 是基于 MLIR 的中间表示,内核在面向模拟器或 QPU 之前会降级至此表示。

为何需要中间表示

  • 可移植性 — 单一表示,适配多种后端。
  • 优化 — 门融合、消除与映射均以 IR 遍的形式运行。
  • 校验 — 非法程序在编译期即被拒绝。

结构

qalgora IR 是 MLIR 的一种方言。量子值通过 SSA 引用流转;操作作用于量子比特引用和经典值,保留程序的数据流。

func.func @bell() {
  %q = quantum.alloc : !quantum.veq<2>
  %q0 = quantum.extract %q[0] : !quantum.ref
  %q1 = quantum.extract %q[1] : !quantum.ref
  quantum.h %q0 : !quantum.ref
  quantum.x [%q0] %q1 : !quantum.ref
  quantum.mz %q : !quantum.veq<2>
  return
}
两套方言
高层方言与源内核对应;降级方言面向硬件。各遍在两者之间以及到各目标后端之间进行转换。