`pow(k) @` modifier rejects non-integer exponents
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
Start with the power-modifier check near src/pyqasm/visitor.py:1627, where the integer-only validation and the existing negative-integer inversion live. Then look at src/pyqasm/linalg.py and src/pyqasm/decomposer.py to see how a single-qubit matrix is turned into U(θ, φ, λ). Done means pow(0.5) @ x matches the sx matrix, pow(0.25) @ x and pow(1.5) @ z work, and unsupported multi-qubit or runtime-valued exponents raise a named ValidationError, with tests in tests/qasm3/test_gate.py.
由索引模型根据 Issue 内容生成。
描述
Limitation
The power modifier is defined as: "The modifier
pow(k) @ replaces its gate argument U by its kth power U^k for some positive integer
or floating point number k (not necessarily constant)."
pyqasm requires k to be an integer and rejects everything else.
Example QASM failure
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
pow(0.5) @ x q[0];
ValidationError: Power modifier argument must be an integer in gate operation QuantumGate(...)
Integer exponents, including negative ones, work today:
pow(2) @ x q[0]; // OK
pow(-1) @ x q[0]; // OK
so the restriction is specifically on the fractional case — which is the interesting one, since
pow(0.5) @ x is the square root of X.
Change Requested
- Accept a floating-point
kinpow(k) @. - For a fractional
k, the repeat-the-gate expansion used for integers does not apply. The
unrolled result must be computed from the gate's matrix as U^k via matrix power — the
principal branch, matching the spec's definition. - Where a fractional power of a gate has a known closed form in the standard library, prefer
emitting that named gate over a synthesisedU(θ, φ, λ). For examplepow(0.5) @ xis
sx. - If a fractional power cannot be realised for a given gate, raise a
ValidationErrornaming
the gate and the exponent — not the current blanket "must be an integer".
Implementation Details
- The rejection is at
src/pyqasm/visitor.py:1627. The surrounding block already handles
negative integers by inverting and repeating, so the integer path is a useful reference for
where the fractional branch belongs. src/pyqasm/linalg.pyand the Cythonsrc/pyqasm/accelerate/linalg.pyxalready provide the
matrix machinery used by the decomposer; a matrix power via eigendecomposition fits there
rather than in the visitor.- The single-qubit result can be routed through the existing ZYZ /
U(θ, φ, λ)decomposition
insrc/pyqasm/decomposer.py, so the fractional case reduces to "compute the matrix, then
decompose" and reuses tested code. - Decide the multi-qubit policy explicitly. A fractional power of a two-qubit gate is well
defined mathematically but expensive to synthesise; rejecting it with a clear message is a
reasonable first increment, provided the message says so. - The spec's "not necessarily constant" clause implies a runtime-valued exponent. That cannot
be resolved during unrolling and is out of scope here — reject it with a specific message. - Tests:
tests/qasm3/test_gate.py—pow(0.5) @ xagainst thesxmatrix,pow(0.25) @ x,
pow(1.5) @ z, a fractional power underctrl @, and a clear error for the unsupported
multi-qubit case.
- 主要语言
- Python
- 星标
- 29
- 派生
- 33
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qBraid/pyqasm 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
enhancement error-handling program-validation
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py可能已有人在做 @danielgaskins 于 7 天前认领。 未关闭enhancement qasm2
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM可能已有人在做 @Jah-yee 于 15 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost可能已有人在做 @tonycoder-hub 于 9 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 22/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
anchore/grype-db#1149 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: `hermes plugins update` clones an entire monorepo twice - `subdir` is resolved but dropped at both catalog-update call sites可能已有人在做 @HootRock 今天认领。 未关闭comp/cli P2 type/perf
难度 2/5 1-3 小时 新手友好度 72/100
NousResearch/hermes-agent#142417 · 2 条评论 ·
维护者通常 1 天内回复
-
SMC SPEC
难度 2/5 1-3 小时 新手友好度 70/100
tenstorrent/tt-oca-harness#3287 ·
维护者通常 1 天内回复
-
bug enhancement python
难度 2/5 1-3 小时 新手友好度 85/100
DewaldOosthuizen/tech-cheat-sheets-and-notes#392 ·
维护者通常 1 天内回复
-
security
难度 2/5 1-3 小时 新手友好度 72/100
fabriziosalmi/wildbox#801 ·
维护者通常 1 天内回复