unroll() ignores inv @ on decomposed gates (cphaseshift, cv, pswap)

未关闭
#473 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@TheGupta2012 已经在做这个了。

开始于 2026年11月19日。

  • #492 来自 @TheGupta2012 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
compilers

调研方向

The bug is in unroll() in pyqasm, which drops the inv @ modifier when decomposing cphaseshift, cv and pswap. Start by reproducing with the snippet in the issue, then find where the decomposition of these gates is emitted and how modifiers are passed through. Done when inv @ G unrolls to the reversed, individually inverted decomposition for these three gates, and a test pins the negated rz/rx angles.

由索引模型根据 Issue 内容生成。

描述

bug
Problem

unroll() drops the inv @ modifier on gates it decomposes, so the inverse comes out as the original gate. Seen with pyqasm 1.3.0 on cphaseshift, cv and pswap.

import pyqasm
for line in ["inv @ cphaseshift(0.5) q[0], q[1];", "cphaseshift(-0.5) q[0], q[1];"]:
    m = pyqasm.loads(f"OPENQASM 3.0;\nqubit[2] q;\n{line}")
    m.unroll(external_gates=["cnot"])
    print(line, "->", " ".join(pyqasm.dumps(m).splitlines()[2:4]))
inv @ cphaseshift(0.5) q[0], q[1]; -> rz(0.25) q[0]; ...
cphaseshift(-0.5) q[0], q[1]; -> rz(-0.25) q[0]; ...

The unrolled inv @ cphaseshift(0.5) is identical to cphaseshift(0.5). inv @ pswap(0.5) likewise unrolls with rz(0.5), and inv @ cv with rx(0.785…) where rx(-0.785…) is expected. No error is raised, so the program silently gets the wrong unitary. qBraid's Braket→OpenQASM 3→Qiskit route hit this (worked around in qBraid/qBraid#1533 by writing negative powers as the gate's adjoint).

Expected

inv @ G unrolls to the inverse of G's decomposition (reversed order, each gate inverted), or raises if that isn't supported.

主要语言
Python
星标
29
派生
33
平均合并
1 天 20 小时
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

qBraid/pyqasm 的其他 Issue

查看 qBraid/pyqasm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。