Required prerequisites
Describe the bug
The scope of variables in cudaq.kernel is inconsistent. Here, I'm presenting an instance of code where, inside a loop, a given variable is updated, but that change is not reflected outside the loop.
The 'res' variable takes up the False value inside the loop, but it preserves the True value outside the loop. Completely evading the change that happened inside the loop.
Steps to reproduce the bug
import cudaq
@cudaq.kernel
def test():
qubits=cudaq.qvector(2)
res = True
for i in range(2):
res = mz(qubits[i])
if res == False:
inner_mz = mz(qubits)
if res == True:
outer_mz = mz(qubits)
result=cudaq.sample(test)
print(result)
Output:
{
global : { 00:1000 }
outer_mz : { 00:1000 }
inner_mz : { 0000:1000 }
res : { 00:1000 }
}
Expected behavior
{
global : { 00:1000 }
inner_mz : { 0000:1000 }
res : { 00:1000 }
}
The if condition outside the loop should not work because the value of 'res' is changed inside the loop.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA Quantum version:
- Python version:
- C++ compiler:
- Operating system:
Suggestions
No response
Required prerequisites
Describe the bug
The scope of variables in cudaq.kernel is inconsistent. Here, I'm presenting an instance of code where, inside a loop, a given variable is updated, but that change is not reflected outside the loop.
The 'res' variable takes up the False value inside the loop, but it preserves the True value outside the loop. Completely evading the change that happened inside the loop.
Steps to reproduce the bug
Output:
{
global : { 00:1000 }
outer_mz : { 00:1000 }
inner_mz : { 0000:1000 }
res : { 00:1000 }
}
Expected behavior
{
global : { 00:1000 }
inner_mz : { 0000:1000 }
res : { 00:1000 }
}
The if condition outside the loop should not work because the value of 'res' is changed inside the loop.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response