custom gate register_operation doesn't seem to work if it is invoked in one kernel which is nested in another.
Open
Nobody has claimed this yet.
python bridge
stale-notified
verify and close
- Dominant language
- C++
- Stars
- 1.1k
- Forks
- 456
- 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
cudaq.register_operation appears not to work in a nested kernel situation. see code example below
Steps to reproduce the bug
my_matrix = np.matrix([[0, 1], [1, 0]])
cudaq.register_operation("my_gate", my_matrix)
@cudaq.kernel
def my_kernel(qubits : cudaq.qview):
my_gate(qubits[0])
@cudaq.kernel
def kernel(num_qubits : int):
qubits = cudaq.qvector(num_qubits)
my_kernel(qubits[0]) # Can't call custom gate through another kernel here
my_gate(qubits[0]) # Can call the custom gate directly here
result = cudaq.sample(kernel, 2, shots_count=1000)
print(result)
Expected behavior
Expected to call the my_gate through the my_kernel call.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- **CUDA-Q version **: 0.9.1
- Python version:
- C++ compiler:
- Operating system:
Suggestions
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the cudaq.register_operation API and reproduce the provided nested-kernel example on CUDA-Q 0.9.1. Verify the behavior through cudaq.sample: the custom my_gate should work both directly in kernel and through my_kernel without changing the reported expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- quantum-computing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100