NVIDIA / NVIDIA/cuda-quantum

List defined inside a kernel passed into subkernel throws an error

Open
#2,240 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug python bridge stale-notified
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
from typing import List
import cudaq

# Define a quantum kernel that applies X gates to supplied indices 
@cudaq.kernel
def padX(qubits: cudaq.qvector, indices: List[int]):
        
    for i in indices:
        x(qubits[i])  

@cudaq.kernel
def main_kernel(num_qubits: int, some_list: List[int]):
    
    q = cudaq.qvector(num_qubits)
    
    x(q)
    
    padX(q, some_list)  #list passed in works 
    
    padX(q, [0, 1]) #list passed in as argument works 
    
    xyz = [0, 1] #list can be defined inside a kernel - no errors here
    padX(q, xyz) #list defined inside kernel then passed in DOES NOT WORK 
    
    
some_list = [0, 1] 
num_qubits = 3

print(cudaq.draw(main_kernel, num_qubits, some_list))
print(cudaq.sample(main_kernel, num_qubits, some_list))
RuntimeError: could not compile code for 'main_kernel'.
error: 'func.call' op operand type mismatch: expected operand type '!cc.stdvec<i64>', but provided '!cc.ptr<!cc.stdvec<i64>>' for operand number 1
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 Quantum 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 supplied Python reproducer and the reported func.call operand type mismatch. Trace compilation of the xyz list defined inside main_kernel when it is passed to padX, comparing it with the working external and inline list cases. Done means the reproducer compiles successfully and both cudaq.draw and cudaq.sample work for the kernel-defined list.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.