Skip to content
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

Error not thrown when broadcasting custom unitary to a qvector. #2452

Open
3 of 4 tasks
justinlietz opened this issue Dec 5, 2024 · 2 comments
Open
3 of 4 tasks

Error not thrown when broadcasting custom unitary to a qvector. #2452

justinlietz opened this issue Dec 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@justinlietz
Copy link
Collaborator

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

When attempting to broadcast a custom unitary to a qvector, an error is not thrown. In the reproducer below, the kernel produces an incorrect result when sampled.

Steps to reproduce the bug

cudaq.register_operation("custom_i", np.array([1, 0, 0, 1]))                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                   
@cudaq.kernel                                                                                                                                                                                                                                                                      
def bell():                                                                                                                                                                                                                                                                        
    qubits = cudaq.qvector(2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    custom_i(qubits) 

Expected behavior

An error is thrown when attempting to broadcast a custom unitary to a qvector.

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

@schweitzpgi
Copy link
Collaborator

@amccaskey is the desired meaning to broadcast the custom unitary across each qubit? (That's the interpretation for the builtins.)

@schweitzpgi schweitzpgi added the bug Something isn't working label Dec 11, 2024
@Squirtle007
Copy link

+1
Accepting cudaq.qvector can provide flexibility and convenience for multi-qubit custom op within a kernel.

error: invalid number of arguments occurs when the code below is executed with cudaq.draw, cudaq.sample, etc:

num_qubits = 2
cudaq.register_operation("custom_op", np.identity(2**num_qubits))

@cudaq.kernel
def kernel(num_qubits: int):
    qubits = cudaq.qvector(num_qubits)
    custom_op(qubits)  # Doesn't work

Then we need to manually pass the qubits (or cudaq.qubit) one by one:

@cudaq.kernel
def kernel(num_qubits: int):
    qubits = cudaq.qvector(num_qubits)
    custom_op(qubits[0], qubits[1])

@Squirtle007 Squirtle007 marked this as a duplicate and then as not a duplicate of #2484 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants