- Python package:
quantum-runtime - CLI binary:
qrun
做一个独立于任何 coding agent 平台的量子代码运行时 CLI:
- 输入:agent 生成的自然语言意图文件 / 结构化 intent / QSpec
- 核心:自有 QSpec / Workspace / 编译与验证闭环
- 输出:Qiskit 代码、OpenQASM 3、Classiq Python SDK 代码、仿真/转译/benchmark 报告
- CLI 不是聊天机器人,而是 agent 可调用的确定性 runtime。
- 自有 IR(QSpec)是唯一真相;Qiskit / Classiq 都是 backend 或 export target。
- 状态不在 prompt 里,在 workspace 里。
- 先适配 aionrs,用 Bash + 文件方式接入,不做 aionrs 深耦合插件。
- v1 不做内置 LLM planner,由宿主 agent 负责把用户自然语言整理成
intent.md;CLI 负责解析、编译、验证、导出。 - 先做确定性能力,再做智能能力。
- 支持
intent.md -> QSpec -> Qiskit / QASM3 / 报告 - 可选支持
QSpec -> Classiq Python SDK - 支持本地仿真、Target 约束校验、资源统计、图输出
- 可被 aionrs / Codex / Claude Code 风格宿主通过 Bash 直接调用
- 不复刻 Classiq 的完整 synthesis engine
- 不实现完整 native QMOD parser
- 不做 Web Studio
- 不做硬件实际提交为默认路径
- 不把量子语义直接做成 aionrs 的 tool surface
- 宿主平台会变,但你的壁垒不应该绑在单个平台 API 上。
- aionrs 初期适合验证,因为它已经有文件读写、Bash、hooks、
CLAUDE.md注入、MCP 和 session;但你不应该把量子能力设计成 aionrs 内部专属协议。 - 真实产品边界应该是:稳定 CLI ABI + 自有 Workspace + 自有 IR + 自有验证闭环。
- tool surface 会带来上下文税。
- 量子任务天然是“多阶段流水线”,不是“单步工具调用”。
- CLI 最好的 agent 接口应该是:
- 写 intent 文件
- 执行一条命令
- 读取一个 JSON 摘要和若干产物路径
- Qiskit、Classiq 的一线 SDK 都在 Python 生态里。
- Rust 可以后面做 launcher / thin wrapper,但核心 runtime、backend driver、导出器、验证器先放 Python 更现实。
┌─────────────────────────────────────────────┐
│ Agent Host │
│ aionrs / Codex / Claude Code / IDE agent │
└─────────────────────────────────────────────┘
│
│ 写 intent.md / 调用 qrun exec
▼
┌─────────────────────────────────────────────┐
│ qrun CLI │
│ - command parser │
│ - workspace loader │
│ - intent parser │
│ - pipeline orchestrator │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Core Runtime │
│ - QSpec models │
│ - normalization │
│ - lowering │
│ - diagnostics │
│ - reporting │
└─────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Qiskit backend │ │ Classiq backend │ │ OpenQASM export │
│ emit/sim/target │ │ emit/synthesize │ │ dump/dumps │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Workspace (.quantum/) │
│ spec / artifacts / reports / figures / trace│
└─────────────────────────────────────────────┘
intent.md or qspec.json
↓
parse_intent()
↓
plan_to_qspec()
↓
normalize_qspec()
↓
emit artifacts (qiskit / qasm3 / classiq)
↓
simulate / transpile_validate / estimate / diagram
↓
write reports + manifest
↓
return compact JSON summary
quantum-runtime/
├─ pyproject.toml
├─ README.md
├─ LICENSE
├─ .gitignore
├─ src/
│ └─ quantum_runtime/
│ ├─ __init__.py
│ ├─ cli.py
│ ├─ logging.py
│ ├─ config.py
│ ├─ errors.py
│ ├─ api/
│ │ ├─ models.py
│ │ ├─ exec_result.py
│ │ └─ schemas.py
│ ├─ workspace/
│ │ ├─ manager.py
│ │ ├─ manifest.py
│ │ ├─ trace.py
│ │ └─ paths.py
│ ├─ intent/
│ │ ├─ parser.py
│ │ ├─ markdown.py
│ │ ├─ structured.py
│ │ └─ planner.py
│ ├─ qspec/
│ │ ├─ model.py
│ │ ├─ nodes.py
│ │ ├─ constraints.py
│ │ ├─ normalize.py
│ │ ├─ validate.py
│ │ └─ diff.py
│ ├─ lowering/
│ │ ├─ qiskit_emitter.py
│ │ ├─ qasm3_emitter.py
│ │ ├─ classiq_emitter.py
│ │ └─ helpers.py
│ ├─ importers/
│ │ ├─ qasm_import.py
│ │ └─ qiskit_import.py
│ ├─ backends/
│ │ ├─ base.py
│ │ ├─ qiskit_local.py
│ │ ├─ qiskit_target.py
│ │ ├─ classiq_backend.py
│ │ └─ registry.py
│ ├─ diagnostics/
│ │ ├─ simulate.py
│ │ ├─ transpile_validate.py
│ │ ├─ resources.py
│ │ ├─ diagrams.py
│ │ └─ benchmark.py
│ ├─ reporters/
│ │ ├─ writer.py
│ │ ├─ summary.py
│ │ └─ suggestions.py
│ └─ integrations/
│ └─ aionrs/
│ ├─ CLAUDE.md.example
│ ├─ hooks.example.toml
│ └─ run_quantum_task.sh
├─ tests/
│ ├─ unit/
│ ├─ integration/
│ ├─ golden/
│ └─ fixtures/
├─ examples/
│ ├─ intent-ghz.md
│ ├─ intent-maxcut-qaoa.md
│ ├─ qspec-ghz.json
│ └─ qspec-maxcut-qaoa.json
└─ docs/
├─ architecture.md
├─ qspec.md
├─ cli.md
├─ aionrs-integration.md
└─ classiq-compatibility.md
- Python: 3.11
- 包管理:
uv(首选)或pip - 测试:
pytest - 数据模型:
pydantic v2 - CLI:
typer - JSON:标准库
json+ 可选orjson
pydantic>=2typer>=0.12pyyaml>=6rich>=13networkx>=3
qiskitqiskit-aer- 可选
qiskit-ibm-runtime
classiq
pytestpytest-covruffmypytypes-PyYAML
[project]
name = "quantum-runtime"
version = "0.1.0"
description = "Agent-facing quantum runtime CLI"
requires-python = ">=3.11,<3.12"
dependencies = [
"pydantic>=2.8",
"typer>=0.12",
"pyyaml>=6.0",
"rich>=13.7",
"networkx>=3.3",
]
[project.optional-dependencies]
qiskit = [
"qiskit>=2,<3",
"qiskit-aer>=0.17",
]
ibm = [
"qiskit-ibm-runtime>=0.40",
]
classiq = [
"classiq>=1,<2",
]
dev = [
"pytest>=8",
"pytest-cov>=5",
"ruff>=0.5",
"mypy>=1.10",
]
[project.scripts]
qrun = "quantum_runtime.cli:app"说明:
requires-python固定到 3.11.x 是为了减少跨 Qiskit / Classiq / matplotlib 的轮子兼容噪音。- Qiskit major 先 pin 到
<3。 - Classiq 不锁死小版本,但 lockfile 必须锁定 tested minor。
qrun init
qrun exec
qrun inspect
qrun export
qrun bench
qrun doctor
qrun backend list
qrun version- agent-facing 主要命令只有一个:
exec - 其余命令服务于人类调试、CI、排障
初始化工作区:
qrun init --workspace .quantum行为:
- 创建
.quantum/ - 写入
workspace.json - 写入默认
qrun.toml - 建立目录骨架
qrun exec --workspace .quantum --intent-file .quantum/intents/task.md --json
qrun exec --workspace .quantum --qspec-file .quantum/specs/current.json --json
qrun exec --workspace .quantum --intent-text "生成4比特GHZ并测量" --json- 加载 workspace
- 读取 intent 或 qspec
- 生成/更新
QSpec - 输出目标 artifacts
- 执行诊断
- 写入报告
- 返回机器可读 JSON
{
"status": "ok",
"workspace": ".quantum",
"revision": "rev_000012",
"summary": "Generated a 4-qubit GHZ circuit, exported Qiskit and OpenQASM 3, and validated successfully on local simulation.",
"warnings": [],
"errors": [],
"artifacts": {
"qspec": ".quantum/specs/current.json",
"qiskit_code": ".quantum/artifacts/qiskit/main.py",
"qasm3": ".quantum/artifacts/qasm/main.qasm",
"diagram_png": ".quantum/figures/circuit.png",
"report": ".quantum/reports/latest.json"
},
"diagnostics": {
"simulation": {
"status": "ok",
"shots": 1024
},
"transpile": {
"status": "ok",
"backend": "local_target"
},
"resources": {
"qubits": 4,
"depth": 4,
"two_qubit_gates": 3
}
},
"next_actions": [
"read .quantum/reports/latest.json",
"inspect .quantum/artifacts/qiskit/main.py"
]
}0: 完全成功2: 成功但有告警 / 部分降级3: 输入非法4: backend 不支持5: 编译失败6: 仿真/转译失败7: 外部依赖缺失(如未安装 classiq)
qrun inspect --workspace .quantum
qrun inspect --workspace .quantum --json输出:
- 当前 revision
- 当前 QSpec 摘要
- 最近 artifacts
- 最近诊断
- backend 能力
qrun export --workspace .quantum --format qiskit
qrun export --workspace .quantum --format qasm3
qrun export --workspace .quantum --format classiq-pythonqrun bench --workspace .quantum --backends qiskit-local,classiq --json输出对比:
- 原始 depth
- transpiled depth
- 2Q gate 数量
- width
- backend capability notes
- 失败原因(如果某 backend 不支持)
qrun doctor --workspace .quantum
qrun doctor --workspace .quantum --fix功能:
- 检查依赖安装
- 检查 Qiskit / Aer / Classiq 是否可导入
- 检查 workspace 是否损坏
- 可选修复缺目录 / manifest 丢失
.quantum/
├─ workspace.json
├─ qrun.toml
├─ intents/
│ ├─ latest.md
│ └─ history/
├─ specs/
│ ├─ current.json
│ └─ history/
├─ artifacts/
│ ├─ qiskit/
│ │ └─ main.py
│ ├─ classiq/
│ │ └─ main.py
│ └─ qasm/
│ └─ main.qasm
├─ figures/
│ ├─ circuit.png
│ └─ circuit.txt
├─ reports/
│ ├─ latest.json
│ └─ history/
├─ trace/
│ └─ events.ndjson
└─ cache/
{
"workspace_version": "0.1",
"project_id": "proj_xxx",
"created_at": "2026-04-02T10:00:00Z",
"current_revision": "rev_000012",
"active_spec": "specs/current.json",
"active_report": "reports/latest.json",
"default_exports": ["qiskit", "qasm3"],
"history_limit": 50
}- 每次 exec 都往
trace/events.ndjson追加事件 - 事件类型:
intent_loadedqspec_createdartifact_writtensimulation_donetranspile_donebackend_failedsummary_emitted
trace 是未来训练数据资产来源。
intent 文件由宿主 agent 生成,格式允许半结构化,但必须稳定。
---
title: GHZ circuit
exports:
- qiskit
- qasm3
backend_preferences:
- qiskit-local
constraints:
max_width: 4
max_depth: 64
shots: 1024
---
# Goal
Generate a 4-qubit GHZ circuit and measure all qubits.
# Inputs
None
# Outputs
Measurement counts
# Notes
Prefer simple educational code.intent/parser.py 负责:
- 读 front matter
- 读 section blocks
- 生成
IntentModel - 缺失字段使用默认值填充
class IntentModel(BaseModel):
title: str | None = None
goal: str
exports: list[str] = ["qiskit", "qasm3"]
backend_preferences: list[str] = ["qiskit-local"]
constraints: dict[str, Any] = {}
shots: int = 1024
notes: str | None = None说明:
- v1 不做复杂 NLP 解析器。
- 宿主 agent 负责把用户自然语言整理成这个格式。
- 比 QASM 高一层,保留语义块和约束
- 比完整 Classiq/Qmod 低一层,便于快速落地
- 允许一部分高层 pattern node,而不是只允许 gate list
class QSpec(BaseModel):
version: str = "0.1"
program_id: str
title: str | None = None
goal: str
entrypoint: str = "main"
registers: list[Register]
parameters: list[Parameter] = []
body: list[Node]
observables: list[Observable] = []
constraints: Constraints = Constraints()
backend_preferences: list[str] = ["qiskit-local"]
metadata: dict[str, Any] = {}class Register(BaseModel):
kind: Literal["qubit", "cbit"]
name: str
size: intclass Parameter(BaseModel):
name: str
type: Literal["float", "int", "angle"] = "float"
default: float | int | None = None
bounds: tuple[float, float] | None = NoneAllocateNodeGateNodeMeasureNodeResetNodeBarrierNodeForNodeIfMeasureNodeBlockNode
PatternNode:ghz,bell,qft,hardware_efficient_ansatz,qaoa_ansatzWithinApplyNode:语义化 uncompute 块ObservableNode:Z / ZZ / Hamiltonian term
class PatternNode(BaseModel):
kind: Literal["pattern"] = "pattern"
pattern: Literal[
"ghz",
"bell",
"qft",
"hardware_efficient_ansatz",
"qaoa_ansatz",
]
args: dict[str, Any] = {}class GateNode(BaseModel):
kind: Literal["gate"] = "gate"
op: str
targets: list[str]
controls: list[str] = []
params: list[str | float | int] = []class Constraints(BaseModel):
max_width: int | None = None
max_depth: int | None = None
basis_gates: list[str] | None = None
connectivity_map: list[tuple[int, int]] | None = None
backend_provider: str | None = None
backend_name: str | None = None
shots: int = 1024
optimization_level: int = 2{
"version": "0.1",
"program_id": "prog_ghz_4",
"title": "4-qubit GHZ",
"goal": "Generate a 4-qubit GHZ circuit and measure all qubits.",
"entrypoint": "main",
"registers": [
{"kind": "qubit", "name": "q", "size": 4},
{"kind": "cbit", "name": "c", "size": 4}
],
"parameters": [],
"body": [
{"kind": "pattern", "pattern": "ghz", "args": {"register": "q", "size": 4}},
{"kind": "measure", "qubits": ["q[0]", "q[1]", "q[2]", "q[3]"], "cbits": ["c[0]", "c[1]", "c[2]", "c[3]"]}
],
"constraints": {"max_width": 4, "shots": 1024},
"backend_preferences": ["qiskit-local"],
"metadata": {"source": "intent"}
}PatternNode(pattern="qaoa_ansatz")args包含:- graph
- p
- mixer
- cost_hamiltonian
- parameter_names
注意:
- v1 不做通用任意优化问题 parser。
- 只支持 MaxCut / Ising 风格最小可用建模。
- 宿主 agent 写
intent.md - CLI 只做规则化解析 + 模板规划
把 IntentModel 映射到 QSpec:
- 如果 goal 命中固定模式:
- “GHZ” ->
PatternNode(ghz) - “Bell” ->
PatternNode(bell) - “QFT” ->
PatternNode(qft) - “QAOA” + MaxCut ->
PatternNode(qaoa_ansatz)
- “GHZ” ->
- 否则:
- 若输入已经是
qspec-file,直接通过 - 若无法确定,返回结构化错误:
manual_qspec_required
- 若输入已经是
v1 不接受“任意自然语言都自动规划成高质量量子算法”这种目标。
v1 的目标是:
- 把常见、明确、模式化的量子任务做稳
- 给 agent 一个可预测的编译运行时
class BackendDriver(Protocol):
name: str
def supports(self, qspec: QSpec) -> CapabilityReport: ...
def emit(self, qspec: QSpec, workspace: Path) -> EmitResult: ...
def validate(self, qspec: QSpec, workspace: Path) -> ValidationReport: ...
def simulate(self, qspec: QSpec, workspace: Path) -> SimulationReport | None: ...
def benchmark(self, qspec: QSpec, workspace: Path) -> BenchmarkReport | None: ...职责:
- QSpec -> Python 源码
- 生成
QuantumCircuit - 可选参数对象
- 可选观测量对象
- 输出为可运行脚本
- 代码必须可直接运行
- 使用函数式入口:
def build_circuit(...) -> QuantumCircuit: - 如果有仿真入口,写在
if __name__ == "__main__": - 自动包含 measurement counts 打印
from qiskit import QuantumCircuit
def build_circuit() -> QuantumCircuit:
qc = QuantumCircuit(4, 4)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.cx(2, 3)
qc.measure(range(4), range(4))
return qc
if __name__ == "__main__":
from qiskit_aer import AerSimulator
qc = build_circuit()
sim = AerSimulator()
result = sim.run(qc, shots=1024).result()
print(result.get_counts())- 优先从 Qiskit circuit 导出
- 写入
artifacts/qasm/main.qasm - 对于 Qiskit 不支持的高级节点,先 lower 到 circuit 再导出
职责:
- QSpec -> Classiq Python SDK 代码
- 尽量用高层模式表达,不降成纯 gate list
ghzbellqfthardware_efficient_ansatz- 部分
qaoa_ansatz within_apply
返回结构化能力错误:
{
"status": "unsupported",
"reason": "pattern_not_supported_by_classiq_emitter",
"details": {"pattern": "custom_oracle"}
}- QSpec 内部保留
WithinApplyNode - 对 Qiskit lowering:展开成
U/V/U†结构 - 对 Classiq lowering:优先映射成接近
within-apply语义的代码结构
能力:
- 本地模拟
- 统计资源
- 生成图
- 生成 QASM 3
build_circuit_from_qspec(qspec)run_local_simulation(circuit, shots)draw_diagram(circuit)estimate_resources(circuit)
能力:
- 使用
Target或 backend constraints 做转译校验 - 检查:
- basis gates
- coupling map
- angle bounds(后续)
- optimization result
- 显式
constraints.basis_gates/connectivity_map - 或远端 provider 获取的 backend(v1 可不做)
{
"status": "ok",
"transpiled_depth": 27,
"transpiled_two_qubit_gates": 9,
"warnings": []
}能力:
- 生成 Classiq Python SDK 文件
- 如果安装并配置 Classiq,则尝试 synthesize
- 输出 Classiq 相关资源和导出产物
默认关闭,需要:
- 安装
classiq - 显式
backend_preferences包含classiq - 配置环境变量/API 信息
- 不强依赖 Classiq 平台登录流程自动化
- 不实现 Studio 集成
- 默认只对 Qiskit local 路径执行
- 记录:
- shots
- counts
- error
- elapsed_ms
- 对有 constraints 的程序执行
- 记录:
- success/fail
- original depth / transpiled depth
- original 2Q / transpiled 2Q
- coupling insertions
- warnings
统一指标:
- width
- depth
- size
- gate_histogram
- two_qubit_gates
- measure_count
- parameter_count
至少产出两个文件:
circuit.txtcircuit.png
v1 benchmark 只做“结构性 benchmark”,不做真实硬件性能宣称:
- 比较不同 backend lowering 产物的 width/depth/2Q gates
- 如果某 backend 无法支持,记录原因
{
"revision": "rev_000012",
"input": {
"mode": "intent",
"path": ".quantum/intents/latest.md"
},
"qspec": {
"path": ".quantum/specs/current.json",
"hash": "sha256:..."
},
"artifacts": {...},
"diagnostics": {...},
"backend_reports": {...},
"warnings": [],
"errors": [],
"suggestions": [
"Try adding connectivity constraints for realistic transpilation.",
"Add benchmark against Classiq backend if installed."
]
}把大报告压成一段适合 agent 读取的摘要。
规则:
- <= 1200 chars
- 包含 status / 核心产物 / 核心错误 / 下一步建议
不用自定义 aionrs tool,不改 aionrs core。
只使用:
- Read
- Write
- Bash
- CLAUDE.md
- hooks(可选)
用户自然语言
↓
aionrs 读取 CLAUDE.md 规则
↓
aionrs 写 .quantum/intents/latest.md
↓
aionrs 执行: qrun exec --workspace .quantum --intent-file .quantum/intents/latest.md --json
↓
aionrs 读取 reports/latest.json 和 artifacts
↓
aionrs 向用户总结并展示代码路径
# Quantum Project Rules
When the user asks for quantum-computing code, do not handwrite large quantum programs first.
Workflow:
1. Write the task into `.quantum/intents/latest.md` using the intent template.
2. Run:
`qrun exec --workspace .quantum --intent-file .quantum/intents/latest.md --json`
3. Read `.quantum/reports/latest.json`.
4. If artifacts were generated successfully, inspect the generated code before proposing edits.
5. Prefer updating the intent and re-running `qrun` over manually rewriting generated quantum code.[hooks.post_tool_use]
command = "bash -lc 'if [ -f .quantum/specs/current.json ]; then qrun doctor --workspace .quantum >/dev/null 2>&1 || true; fi'"- 保持平台无关
- 利用 aionrs 现有 Bash / 文件能力
- 不被 aionrs 当前 sub-agent / tool registry 行为绑定
Classiq 是backend / exporter / optional synthesis engine,不是源语义。
QSpec -> Classiq Python SDK- 若已安装 Classiq,可尝试 synthesize
- 支持输出对比报告
- 支持从 OpenQASM 侧做互操作(后续)
- 不直接支持 native
.qmodparser - 不做完整
qasm_to_qmod -> 再回到 QSpec的 round-trip - 不保证所有高层语义节点都能映射到 Classiq
v0.2 / v0.3 可加:
import --format qasmimport --format qiskit- 如果需要,再做
import --format classiq-qmod(排到后面)
0.1.x: 稳定 CLI JSON 输出、稳定 workspace 布局、稳定 QSpec 基础字段0.2.x: 扩展 pattern node、Classiq synthesize 增强、import 能力0.3.x: 可选 remote hardware submit / richer benchmarking
qrun exec --json输出一旦发布,字段新增只能追加,不能删除/重命名QSpec.version必须带 schema version- workspace 中保留 revision 历史
覆盖:
- intent parser
- qspec validation
- node normalization
- emitter 代码生成
- report writer
- workspace manager
qrun init --workspace .quantum
qrun exec --workspace .quantum --intent-file examples/intent-ghz.md --json断言:
- 生成 qspec
- 生成 qiskit 代码
- 生成 qasm3
- 本地仿真成功
- 有 diagram
断言:
- 生成参数化电路
- 资源统计可用
- benchmark 报告存在
断言:
- 返回结构化
dependency_missing - 其他 backend 不受影响
断言:
- transpile validation 失败
- 报告里有清晰错误
固定输入 -> 固定 artifact snapshot:
- GHZ qiskit 代码
- GHZ qasm3
- GHZ report 摘要
- QAOA qspec
ruff check .mypy srcpytest -q- 对 qiskit extra 跑 integration tests
- Classiq tests 仅在专门环境跑
- 建立
pyproject.toml - CLI 骨架
qrun init- workspace 目录生成
qrun init --workspace .quantum可运行- 生成目录和默认配置
- 单元测试通过
- 实现 Markdown + front matter 解析
- 实现 revision / manifest / trace
- 能读取
examples/intent-ghz.md - 写入
trace/events.ndjson
- 实现 Pydantic 模型
- 支持 GHZ / Bell / QFT / HEA / QAOA pattern
intent -> qspec
- 生成稳定
specs/current.json - snapshot test 通过
- QSpec -> Python 源码
- 生成可运行
main.py
- GHZ 示例生成的代码可导入并运行
- 代码风格稳定
- 本地仿真
- 资源统计
- ASCII 图和 PNG 图
- GHZ 仿真成功
reports/latest.json含 simulation/resources/diagram
- 从 circuit 导出 OpenQASM 3
- 写 artifact
artifacts/qasm/main.qasm存在- snapshot test 通过
- 支持 basis gates / connectivity map
- 报告 transpiled metrics
- 约束成功/失败路径都可测试
- 支持 QSpec -> Classiq Python SDK
- 支持能力检查
- GHZ / QFT / HEA 至少可导出
- 不支持 pattern 返回结构化 unsupported
- 如果安装/配置正确,则调用 Classiq synthesize
- 记录输出/错误
- 无 Classiq 环境时 graceful degrade
- 有环境时生成 backend report
- 多 backend 对比
- 统一摘要
- suggestions 生成
qrun bench --json可运行- summary 足够短且稳定
- 生成
integrations/aionrs/CLAUDE.md.example - hooks 示例
- 文档示例
- 按文档可在 aionrs 中跑通
- README
- architecture docs
- changelog skeleton
- versioning notes
- 新用户能按 README 安装并运行 GHZ 示例
def exec_command(args: ExecArgs) -> ExecResult:
ws = WorkspaceManager.load_or_init(args.workspace)
source = load_input(args)
if source.kind == "intent":
intent = parse_intent(source)
qspec = plan_to_qspec(intent)
else:
qspec = load_qspec(source)
qspec = normalize_qspec(qspec)
validate_qspec(qspec)
artifacts = {}
backend_reports = {}
warnings = []
errors = []
if "qiskit" in requested_exports(qspec, args):
artifacts["qiskit_code"] = emit_qiskit(qspec, ws)
if "qasm3" in requested_exports(qspec, args):
artifacts["qasm3"] = emit_qasm3(qspec, ws)
if "classiq-python" in requested_exports(qspec, args):
result = emit_classiq(qspec, ws)
if result.status == "ok":
artifacts["classiq_code"] = result.path
else:
warnings.append(result.reason)
diag = run_diagnostics(qspec, ws, artifacts)
report = write_report(ws, qspec, artifacts, diag, warnings, errors)
summary = summarize_report(report)
return ExecResult(
status=derive_status(warnings, errors),
workspace=str(ws.root),
revision=ws.current_revision,
summary=summary,
warnings=warnings,
errors=errors,
artifacts=artifacts,
diagnostics=diag,
next_actions=build_next_actions(report),
)from pathlib import Path
from typing import Protocol
from quantum_runtime.qspec.model import QSpec
class CapabilityReport(TypedDict):
status: str
supported: bool
reasons: list[str]
class EmitResult(TypedDict):
status: str
path: str | None
reason: str | None
class BackendDriver(Protocol):
name: str
def supports(self, qspec: QSpec) -> CapabilityReport: ...
def emit(self, qspec: QSpec, out_dir: Path) -> EmitResult: ...应对:
- emitter 只支持明确 pattern
- 不支持时返回结构化 unsupported,而不是瞎生成
应对:
- pin major version
- 模板生成,不把 API 细节交给 agent 记忆
- CI 跑 integration tests
应对:
- 前期要求宿主 agent 生成结构化 intent 模板
- planner 只做小范围模板映射
应对:
- JSON schema 先冻结
- golden tests 覆盖
exec --json
满足以下全部条件才算完成:
qrun init、exec、inspect、doctor可用- GHZ / QFT / HEA / 基础 QAOA intent 能跑通
- 能生成 Qiskit 代码、QASM3、report、diagram
- 支持 local simulation 和 target validation
- Classiq emitter 至少覆盖 GHZ/QFT/HEA
- aionrs 按示例可接通
- CI 通过,golden tests 稳定
- 增加 import 能力
- 加强 Classiq synthesize/report
- 增加更多 pattern
- 增加 benchmark 对比维度
- 严格按 PR 顺序实施,不要试图一口气完成全部功能。
- 每个 PR 必须:
- 更新测试
- 更新文档
- 给出可运行命令
- 不要实现内置 LLM planner。
- 不要为 aionrs 写 custom tool;初期只走 Bash + 文件集成。
- 所有 JSON 输出必须通过 schema 校验。
- 所有不支持的 backend/path 必须返回结构化错误,不允许 silent fail。
- 先做 deterministic pipeline,再加 Classiq synthesize。
- 如果遇到 Classiq 环境不可用,保留接口和测试替身,不阻塞整个项目。
uv venv
source .venv/bin/activate
uv pip install -e '.[dev,qiskit]'
qrun init --workspace .quantum
cp examples/intent-ghz.md .quantum/intents/latest.md
qrun exec --workspace .quantum --intent-file .quantum/intents/latest.md --json
cat .quantum/reports/latest.json
python .quantum/artifacts/qiskit/main.py预期:
.quantum/specs/current.json存在.quantum/artifacts/qiskit/main.py存在.quantum/artifacts/qasm/main.qasm存在.quantum/figures/circuit.png存在.quantum/reports/latest.json中status=ok
uv pip install -e '.[classiq]'
qrun export --workspace .quantum --format classiq-python
qrun bench --workspace .quantum --backends qiskit-local,classiq --json预期:
- 若 Classiq 可用,导出 Classiq Python 文件
- 若不可用,输出结构化 dependency_missing 或 backend_unavailable
- 不影响已有 Qiskit 路径