Required prerequisites
Describe the bug
In Python, a for loop that never runs leaves its loop variable unbound, so reading it afterwards raises NameError. In a CUDA-Q kernel the read silently returns whatever is in the variable's stack slot.
Steps to reproduce the bug
import cudaq
@cudaq.kernel
def k(n: int):
q = cudaq.qvector(3)
for i in range(n):
h(q[i])
x(q[i])
print(cudaq.sample(k, 0, shots_count=20))
Gives output as
RuntimeError: Provided index [18446744073709551615] >= array size [3]
Expected behavior
Reading a loop variable after a zero trip loop should raise, matching Python's NameError, rather than produce a value.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version:
- Python version:
- C++ compiler:
- Operating system:
Suggestions
No response
Required prerequisites
Describe the bug
In Python, a for loop that never runs leaves its loop variable unbound, so reading it afterwards raises NameError. In a CUDA-Q kernel the read silently returns whatever is in the variable's stack slot.
Steps to reproduce the bug
Gives output as
Expected behavior
Reading a loop variable after a zero trip loop should raise, matching Python's NameError, rather than produce a value.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response