NVIDIA/cuda-quantum

Unclear error message on passing ndarray to kernels that accept cudaq.State

Closed this issue · 0 comments

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

Python gives unclear message when I pass a ndarray to a kernel that takers cudaq.State as a parameter"

RuntimeError: error: Cannot infer CUDA-Q type from provided Python type (!cc.ptr<!cc.state>)

Offending code:
  File "/home/annagrin/source/cuda-quantum/program.py", line 24, in <module>
    counts = cudaq.sample(kernel, c)

Steps to reproduce the bug

import cudaq
import numpy as np

c = np.array([1, 2j, 3, 4j, 5, 6j, 7, 8j], dtype=np.complex64)

@cudaq.kernel
def kernel(vec: cudaq.State):
    q = cudaq.qvector(vec)

counts = cudaq.sample(kernel, c)

Expected behavior

A better error message would mention the actual type (ndarray) not matching the formal type (cudaq.State)

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