NVIDIA / NVIDIA/cuda-quantum

Calling cudaq.control or cudaq.adjoint on a globally registered operation is not supported

Open
#3,603 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement stale-notified
Dominant language
C++
Stars
1.1k
Forks
455
Avg merge
1d 22h
Merged PRs (30d)
165

Description

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

gate.ctrl works but the cudaq.control(gate..) does not work

import cudaq 
import numpy as np

cudaq.register_operation("U2", np.array([[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]]))

@cudaq.kernel
def kernel():
    
    a = cudaq.qvector(2)
    b = cudaq.qvector(2)
    
    #this works 
    U2.ctrl(a[0], b[0], b[1]) 
    
    #this does the same thing as the above but does not work 
    cudaq.control(U2, a[0], b[0], b[1])

cudaq.sample(kernel)
print(cudaq.draw(kernel))
---------------------------------------------------------------------------
CompilerError                             Traceback (most recent call last)
Cell In[6], line 15
     12     U2.ctrl(a[0], b[0], b[1]) #this works 
     13     cudaq.control(U2, a[0], b[0], b[1])
---> 15 cudaq.sample(kernel)
     16 print(cudaq.draw(kernel))

File /opt/nvidia/cudaq/cudaq/runtime/sample.py:82, in sample(kernel, shots_count, noise_model, explicit_measurements, *args)
     77 if kernel.returnType is not None:
     78     raise RuntimeError(
     79         f"The `sample` API only supports kernels that return None (void). "
     80         f"Kernel '{kernel.name}' has return type '{kernel.returnType}'. "
     81         f"Consider using `run` for kernels that return values.")
---> 82 kernel.compile()
     83 if kernel.module is not None:
     84     for operation in kernel.module.body.operations:

File /opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:217, in PyKernelDecorator.compile(self)
    213 self.capturedDataStorage = self.createStorage()
    215 # Caches the module and stores captured data into
    216 # `self.capturedDataStorage`.
--> 217 self.module, self.argTypes, extraMetadata = compile_to_mlir(
    218     self.astModule,
    219     self.capturedDataStorage,
...
    235     hasattr(ast, 'unparse') and astNode is not None else '') + Color.END
--> 236 raise CompilerError(msg)

CompilerError: 3950899277.py:13: error: calling cudaq.control or cudaq.adjoint on a globally registered operation is not supported
	 (offending source -> cudaq.control(U2, a[0], b[0], b[1]))
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?e10d3eeb-8a90-4b98-8f9a-dc3f79a442fa) or open in a [text editor](command:workbench.action.openLargeOutput?e10d3eeb-8a90-4b98-8f9a-dc3f79a442fa). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
Steps to reproduce the bug

NA

Expected behavior

NA

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

NA

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproduction, focusing on cudaq.register_operation, cudaq.control, cudaq.adjoint, and kernel compilation through cudaq.sample. Trace where the compiler rejects globally registered operations and add coverage for the reported control case and the analogous adjoint case. Done means these operations compile and behave consistently with the registered operation's direct .ctrl form.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.