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

RuntimeError when using kernel.control() alongside other controlled operations #2692

Open
3 of 4 tasks
bharat-thotakura opened this issue Mar 5, 2025 · 0 comments
Open
3 of 4 tasks

Comments

@bharat-thotakura
Copy link
Contributor

bharat-thotakura commented Mar 5, 2025

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

Adding broader controlled operations (e.g., controlled on a 'sub kernel') can result in a RuntimeError if paired with gates such as cswap, ccz, or ccx.

Steps to reproduce the bug

This issue can be seen, for example, in a snippet like:

import cudaq

cudaq.set_target("nvidia")

kernel = cudaq.make_kernel()
qvector = kernel.qalloc(4)

kernel.h(qvector)

qubit_placeholders = [cudaq.qubit for _ in range(2)]
sub_kernel, *control_qubits = cudaq.make_kernel(*qubit_placeholders)
sub_kernel.cx(*control_qubits)
kernel.control(sub_kernel, qvector[0], qvector[3], qvector[2])

kernel.cswap(qvector[1], qvector[2], qvector[0])
kernel.mz(qvector)

cudaq.sample(kernel).dump()
# error: 'llvm.call' op operand type mismatch for operand 3: '!llvm.ptr<func<void (ptr<struct<"Array", opaque>>, ptr<struct<"Qubit", opaque>>, ptr<struct<"Qubit", opaque>>)>>' != '!llvm.ptr<func<void (ptr<struct<"Array", opaque>>, ptr<struct<"Qubit", opaque>>)>>'
# RuntimeError: cudaq::builder failed to JIT compile the Quake representation.

whereas, the following works:

import cudaq

cudaq.set_target("nvidia")

kernel = cudaq.make_kernel()
qvector = kernel.qalloc(4)

kernel.h(qvector)

qubit_placeholders = [cudaq.qubit for _ in range(2)]
sub_kernel, *control_qubits = cudaq.make_kernel(*qubit_placeholders)
sub_kernel.cx(*control_qubits)
kernel.control(sub_kernel, qvector[0], qvector[3], qvector[2])

kernel.mz(qvector)

cudaq.sample(kernel).dump()
# { 0000:60 0001:60 0010:64 0011:69 0100:57 0101:67 0110:64 0111:59 1000:66 1001:65 1010:71 1011:58 1100:50 1101:73 1110:61 1111:56 }

with print(cudaq.draw(kernel)) showing that the ccx was correctly interpreted:

Image

Expected behavior

I would expect kernel to support all kernel.control(), cswap, ccx, ccz operations

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant