cuda-quantum icon indicating copy to clipboard operation
cuda-quantum copied to clipboard

Multiple inputs to kernels throws an error

Open zohimchandani opened this issue 10 months ago • 4 comments

Required prerequisites

  • [X] 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.
  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • [X] If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

import cudaq 
from cudaq import spin 
import numpy as np 

n_samples = 1
n_params = 2 
h = spin.z(0)
qubit_count = 1
params = np.random.rand(n_samples, n_params)

When we have an int as an input to the kernel, it seems to work fine as shown below:

@cudaq.kernel
def kernel(qubit_count: int):
    
    qvector = cudaq.qvector(qubit_count)
    
    h(qvector[0])
               
result = cudaq.observe(kernel, h, qubit_count)

If we input a np.ndarray, this also works fine:

@cudaq.kernel
def kernel(params: np.ndarray):
    
    qvector = cudaq.qvector(1)
    
    rx(params[0], qvector[0])
    ry(params[1], qvector[0])
                
result = cudaq.observe(kernel, h, params)

However, 2 inputs seems to throw an error:

@cudaq.kernel
def kernel(qubit_count: int, params: np.ndarray):
    
    qvector = cudaq.qvector(qubit_count)
    
    rx(params[0], qvector[0])
    ry(params[1], qvector[0])
                
result = cudaq.observe(kernel, h, qubit_count, params)

RuntimeError: 2D array argument provided for an observe broadcast, but argument 0 (<class 'int'>) must be a list.

print(cudaq.__version__)
CUDA Quantum Version latest (https://github.com/NVIDIA/cuda-quantum 1c434b15044e9fe1df32af4a00d662aa270aa69e)

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

No response

zohimchandani avatar Apr 08 '24 12:04 zohimchandani