Skip to content

CUDA-Q kernel cannot use with itertools.product #2586

@ikkoham

Description

@ikkoham

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 itertools import product
import cudaq

@cudaq.kernel
def test():
    q = cudaq.qubit()
    x(q)

does not work...

Steps to reproduce the bug

Error message was

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 5
      1 from itertools import product as product_
      2 import cudaq
      4 @cudaq.kernel
----> 5 def test():
      6     q = cudaq.qubit()
      7     x(q)

File [/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:526](http://10.20.100.80:1519/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py#line=525), in kernel(function, **kwargs)
    517 """
    518 The `cudaq.kernel` represents the CUDA-Q language function 
    519 attribute that programmers leverage to indicate the following function 
   (...)
    523 Verbose logging can be enabled via `verbose=True`. 
    524 """
    525 if function:
--> 526     return PyKernelDecorator(function)
    527 else:
    529     def wrapper(function):

File [/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py:96](http://10.20.100.80:1519/opt/nvidia/cudaq/cudaq/kernel/kernel_decorator.py#line=95), in PyKernelDecorator.__init__(self, function, verbose, module, kernelName, funcSrc, signature, location, overrideGlobalScopedVars)
     94 for name, var in self.globalScopedVars.items():
     95     if isinstance(var, type):
---> 96         globalRegisteredTypes[name] = (var, var.__annotations__)
     98 # Once the kernel is compiled to MLIR, we
     99 # want to know what capture variables, if any, were
    100 # used in the kernel. We need to track these.
    101 self.dependentCaptures = None

AttributeError: type object 'itertools.product' has no attribute '__annotations__'

Expected behavior

no error

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:

I'm using CUDA-Q container for 0.9.1

Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions