原模型: Floki00/cirdit_multimodal_compile_3to5qubit_v1.1 论文: Synthesis of discrete-continuous quantum circuits with multimodal diffusion models (arXiv:2506.01666) 项目页: https://florianfuerrutter.github.io/genQC/ License: Apache-2.0
本仓库是 genQC 多模态扩散电路编译模型 CirDiT 在昇腾 NPU 上的服务化适配(vLLM-Ascend pooling runner)。将自然语言电路描述 + 目标酉矩阵编译为离散-连续量子门序列(3–5 qubit,最多 32 门)。
传统量子电路编译(合成)需要将任意目标酉矩阵 U 分解为量子门序列。genQC 用多模态扩散模型统一处理两类门:
h、cx、ccx、swaprx(θ)、ry(θ)、rz(θ)、cp(θ)扩散模型直接生成"离散门类别 + 连续旋转角参数"的联合表示,从而把离散-连续混合合成问题变成一个去噪生成问题。
| 属性 | 值 |
|---|---|
| 参数量 | ~150M(训练 ~800k steps) |
| 支持 qubit 数 | 3–5 |
| 最大门数 | 32(min 4) |
| 门池 | h cx ccx swap rx ry rz cp |
| 调度器 | 双 DDIM(主 + 宽通道联合去噪) |
| 预测类型 | v-type(速度预测) |
| 训练 | classifier-free guidance(enable_guidance_train,guidance_train_p=0.1) |
┌────────────────────────────────────────────┐
prompt (37 tokens) │ Frozen OpenCLIP (ViT-B-32, penultimate) │ → c_emb [1, 37, 512]
└────────────────────────────────────────────┘
┌────────────────────────────────────────────┐
target unitary │ UnitaryTextEncoder (unitary encoding) │ → U [1, 2, 32, 32]
(2×32×32) └────────────────────────────────────────────┘
┌────────────────────────────────────────────┐
│ Rotational Multimodial Embedder Tiny │
│ 12 class values + 3 param dims │
└────────────────────────────────────────────┘
↓
┌───────────────────────────────────────────────────────────┐
│ CirDiT 主干 (UnitaryCLIPPartialNoise) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Packing branch ch=256 depth=6 heads=8 │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Core branch ch=768 depth=12 heads=16 (RoPE) │ │
│ └─────────────────────────────────────────────────────┘ │
└───────────────────────────────────────────────────────────┘
↓
双 DDIM 去噪(主通道 + 宽通道,classifier-free guidance, g=1.0)
↓
门 token [5, 32] + 连续参数 [1, 32] → 192 float| 模块 | 参数 | 值 |
|---|---|---|
| Core DiT | ch_core / depth_core / num_heads_core | 768 / 12 / 16 |
| Packing DiT | ch_packing / depth_packing / num_heads_packing | 256 / 6 / 8 |
| RoPE | p_rope / base_rope | 0.9 / 1000.0 |
| 嵌入 | c_emb_size / t_emb_size | 640 / 512 |
| Color/CLR | clr_dim | 16(离散 13 + 参数 3) |
| 文本编码 | OpenCLIP ViT-B-32 (datacomp_xl_s13b_b90k) | max_length=37, penultimate layer, frozen |
| Unitary 编码 | text_encoding_ch 128 / unitary_encoding_ch 40 | downscale 4, depth 8 |
| 调度器 | β 范围 | 调度 | 用途 |
|---|---|---|---|
scheduler (主) | 0.001 → 0.012 | path:beta_schedule_learned_linear | 离散门通道 |
scheduler_w (宽) | 0.0002 → 0.024 | cos_alpha4 | 连续参数通道 |
两者均 prediction_type=v-type、1000 timesteps。推理时各用 30 步,双通道联合去噪,classifier-free guidance g=1.0。
原模型是 PyTorch UnitaryCLIPPartialNoiseCompilationCirDiT(扩散模型),不是自回归 LLM,因此通过 vLLM-Ascend --runner pooling --convert embed 服务化,经 OpenAI 兼容的 /v1/embeddings 端点访问。
cirdit_ascend/ OOT 插件)forward 内禁 .item()/.cpu() 同步,解码、量化反算、RNG 均在设备上完成。IsAttentionFree / attn_type="attention_free":满足 vLLM HybridKVCacheCoordinator 断言。Pooler:返回固定长度 [192] 行(门 token + 参数)。cirdit_compile_aux 装载,避免首请求设备迁移。export ASCEND_RT_VISIBLE_DEVICES=1 # 逻辑芯片 1
export VLLM_ALLOW_LONG_MAX_MODEL_LEN=1
python3 -m vllm.entrypoints.openai.api_server \
--model /opt/atomgit/models/Floki00/cirdit_compile_servable \
--tokenizer /opt/atomgit/adapt/cirdit_tokenizer \
--load-format safetensors \
--dtype float32 \
--max-model-len 2094 \
--max-num-seqs 2 \
--port 8068 \
--enforce-eager \
--no-enable-chunked-prefill \
--no-enable-prefix-caching \
--runner pooling --convert embed \
--served-model-name cirdit-compile⚠️
--no-enable-chunked-prefill必须:CirDiT 每请求固定 2094 tokens,切块会导致 EngineCore 崩溃。
[0] magic = 77
[1..8] header: system_size, num_qubits, max_gates, num_steps,
g*1000, seed, prompt_len, flags
[9..45] prompt tokens (37, CLIP tokenizer, 0-padded)
[46..2093] 2×32×32 quantized unitary(real + imag,16-bit 定点)quantize = round(val × 32767) + 1_000_000(U_SCALE/U_OFFSET)tensor_prod_pad 约定)[0..159] gate tokens,flattened [5, 32](行优先)
[160..191] 连续参数 [-1, 1](nP=1 × 32)192 = 5(qubit) × 32(max_gates) + 1(param) × 32
| token | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| 门 | h | cx | ccx | swap | rx | ry | rz | cp |
| 参数 | – | – | – | – | θ | θ | θ | θ |
参数化门 token = {5,6,7,8},pad token = 9。
cd /opt/atomgit/adapt/cirdit_ascend/run
bash serve.shcurl -X POST http://127.0.0.1:8068/v1/embeddings \
-H 'Content-Type: application/json' \
-d '{
"model": "cirdit-compile",
"input": [ [77, 5, 5, 32, 30, 1000, 0, 37, 0, ...] ]
}'from cirdit_ascend.protocol import encode_request, decode_output
import numpy as np, requests
# 1. CLIP tokenizer 编码 prompt
pids = clip_tokenizer(prompt)["input_ids"][:37]
pids = pids + [0] * (37 - len(pids))
# 2. 编码目标酉([2, N, N],real+imag)
row = encode_request(np.array(pids), unitary, system_size=5,
num_qubits=5, max_gates=32, num_steps=30, g=1.0)
# 3. 请求
r = requests.post("http://127.0.0.1:8068/v1/embeddings",
json={"model": "cirdit-compile", "input": [row]}, timeout=300)
emb = np.array(r.json()["data"][0]["embedding"])
# 4. 解码门序列
gates = emb[:160].reshape(5, 32).astype(int) # [5, 32] gate tokens
params = emb[160:] # [32] 连续参数/opt/atomgit/models/Floki00/
├── cirdit_multimodal_compile_3to5qubit_v1.1/ # 真实权重 (765MB model.safetensors)
│ ├── model.safetensors
│ ├── config.yaml / config.json / README.md
│ ├── embedder.safetensors / beta_schedule_learned_linear.safetensors
├── cirdit_compile_servable/ # serve 入口(model.safetensors 软链)
└── cirdit_compile_aux/ # aux 权重
├── config.yaml / embedder.safetensors / beta_schedule...
└── clip/clip_text.safetensors + tokenizer| 指标 | 值 |
|---|---|
| 冷请求(首次 TBE 编译) | 20.4s |
| 热请求 | 2.96s |
| NPU1 AICore 峰值 | 19% |
| HBM 占用 | 4192 MB |
| 语义区分度(不同 prompt,L1) | 453 |
| 输出 embedding | 有限(finite),维度 192 |
README.md ← 本文档
__init__.py ← vLLM pooling adapter(架构注册 + forward)
genqc_model.py ← CirDiT 主干 1:1 重建(PyTorch)
embedder.py ← Rotational Multimodial Embedder
schedulers.py ← 双 DDIM 调度器(v-type)
clip_text.py ← Frozen OpenCLIP ViT-B-32 编码器
protocol.py ← 2094-token 请求 / 192-float 输出协议
inference.py ← Python 推理示例
serve.sh ← vLLM-Ascend 启动脚本
tests_cirdit_e2e.yaml ← e2e 验证配置
cirdit-model.md ← 适配文档
assets/ ← 图片目录@misc{fuerrutter2025synthesis,
title={Synthesis of discrete-continuous quantum circuits with multimodal diffusion models},
author={Fürrutter, Florian and Muñoz-Gil, Gorka and Garcia-Beni, Alejandro and Bermejo, Pablo and Murta, Bruno and Roman-Roche, Pablo and Zini, Marçal and Gasull, Adrià and del Campo, Andrea and Aspuru-Guzik, Alán},
year={2025},
eprint={2506.01666},
archivePrefix={arXiv},
primaryClass={quant-ph}
}