[BUG] Unusual error when running direct recursion
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the reproducer in the issue: a recursive def test(qubit[1] a, int b) that calls itself with a[0], which fails with "Expecting qubit argument for 'a'". The reporter points at Qasm3SubroutineProcessor.process_quantum_arg, so read how qubit arguments are resolved inside a subroutine's own scope. Done when the recursive program validates without error and the existing subroutine tests still pass.
由索引模型根据 Issue 内容生成。
描述
Environment
- PyQASM version: 0.3.2
- Python version: 3.12.8
- Operating system: Windows
What happened?
Issue
The OpenQASM standard allows direct recursion by making gate/subroutine identifiers available within their own scope.
However, pyqasm fails when handling recursive calls, producing an unexpected parameter type error.
Example
OPENQASM 3;
include "stdgates.inc";
qubit[5] qb;
bit[5] cb;
const float my_angle = .1;
def test(qubit[1] a,int b){
p(my_angle) a[0];
if(b > 0){
test(a[0],b-1);
}
}
test(qb[2],3);
'''
Observed Behavior
The recursive call throws the following error:
ERROR :pyqasm: Error at line 9, column 2 in QASM file
>>>>>> test(a[0], b - 1)
ValidationError: Expecting qubit argument for 'a'. Qubit register 'a' not found for function 'test'
- note that both test(a,b-1); and test(a[0],b-1); threw the same error when I was testing for semantic errors in my code
Expected Behavior
pyqasm should accept recursive calls in accordance with the OpenQASM standard, correctly resolving subroutine identifiers within their own scope.
Suggestions (Optional)
Id assume this is an error regarding scoping/aliasing within subroutine calls rather than a recursion issue, since error originates from: Qasm3SubroutineProcessor.process_quantum_arg(
- 主要语言
- Python
- 星标
- 29
- 派生
- 33
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 14
环境准备
- 没有 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 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 57/100
维护者通常 1 天内回复
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py可能已有人在做 @danielgaskins 于 14 天前认领。 未关闭enhancement qasm2
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM可能已有人在做 @Jah-yee 于 22 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
backlog
难度 1/5 1 小时以内 新手友好度 91/100
EchoTools/nevr-runtime#1108 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
btclib-org/btclib-wallet#587 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 68/100
Judgment-Pack/judgment-pack-spec#275 ·
维护者通常 1 天内回复