-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior when kernel takes list of booleans #2262
Comments
Hi @jezerjojo14 , I tested some other variants of your code, changing the value being checked, the defined type for the list and the actual values in the list. Boolean list, boolean comparisonimport cudaq
@cudaq.kernel
def circ_test(n: int, bools: list[bool]):
q = cudaq.qvector(n)
for j in range(n):
b=bools[j]
if b==True:
x(q[j])
print(cudaq.draw(circ_test,5,[False,True,False,True,False])) Output: print(cudaq.draw(circ_test,5,[0,1,0,1,0])) Output: Boolean list, integer comparisonimport cudaq
@cudaq.kernel
def circ_test(n: int, bools: list[bool]):
q = cudaq.qvector(n)
for j in range(n):
b=bools[j]
if b==1:
x(q[j])
print(cudaq.draw(circ_test,5,[False,True,False,True,False])) Output: Integer list, boolean comparisonimport cudaq
@cudaq.kernel
def circ_test(n: int, bools: list[int]):
q = cudaq.qvector(n)
for j in range(n):
b=bools[j]
if b==True:
x(q[j])
print(cudaq.draw(circ_test,5,[0,1,0,1,0])) Output:
Integer list, integer comparisonimport cudaq
@cudaq.kernel
def circ_test(n: int, bools: list[int]):
q = cudaq.qvector(n)
for j in range(n):
b=bools[j]
if b==1:
x(q[j])
print(cudaq.draw(circ_test,5,[0,1,0,1,0])) Output:
If we were to call the kernel with a list of booleans, it would work too: print(cudaq.draw(circ_test,5,[False,True,False,True,False])) Output:
TakeawayYou can currently call your kernel passing a list of booleans as long as the kernel treats it as a list of integers. There is likely something wrong when using lists of booleans inside quantum kernels. A simplified version of your code where the kernel receives a |
I'm curious as to what was going wrong in the first place but this is a great solution to the problem I was facing. Thanks @bebora 👍 |
Fixed with #2338 |
Required prerequisites
Describe the bug
I needed to send a list of$n$ booleans as a parameter to a kernel to specify which of $n$ qubits to apply $X$ gates on. The kernel does not throw any errors, but does not seem to be interpreting this list of booleans correctly. I'm not sure but I think it might be interpreting the list of booleans as a single integer?
Steps to reproduce the bug
This is the kernel:
This is how it behaves for different examples:
Here's a modified kernel:
No output
No output
No output
Expected behavior
For the first kernel, I expect an$X$ gate to be applied on the $i$ -th qubit if and only if the $i$ -th element of the boolean list is False. For the second kernel I expect the same but for when the $i$ -th element of the boolean list is True.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response
The text was updated successfully, but these errors were encountered: