[BUG] Unusual error when running direct recursion
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 45/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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(
- Dominant language
- Python
- Stars
- 29
- Forks
- 33
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from qBraid/pyqasm
-
dumps() prints the original program when unroll() leaves at most one statementPossibly taken @ShiveshDragon claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
qBraid/pyqasm#493 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
enhancement error-handling program-validation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 43/100
Maintainers usually reply within 1 day
-
dependencies enhancement
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
Similar issues
-
auto-reported bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
backend bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
nolte/kamerplanter#3193 ·
Maintainers usually reply within 1 day
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwisePossibly taken @abdulwaarith0 claimed this today. Openneeds-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
MakazhanAlpamys/Soup#3690 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day