NVIDIA/cuda-quantum

[Python] Incorrect return value with a bool parameter

annagrin opened 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

The code below outputs an incorrect value:

@cudaq.kernel(verbose=True)
def kernel(c: int, b: bool) -> int:
    return c
    
print(kernel(1, True)) # Expected 1

Output

module attributes {quake.mangled_name_map = {__nvqpp__mlirgen__kernel = "__nvqpp__mlirgen__kernel_PyKernelEntryPointRewrite"}} {
  func.func @__nvqpp__mlirgen__kernel(%arg0: i64, %arg1: i1) -> i64 attributes {"cudaq-entrypoint"} {
    %0 = cc.alloca i64
    cc.store %arg0, %0 : !cc.ptr<i64>
    %1 = cc.alloca i1
    cc.store %arg1, %1 : !cc.ptr<i1>
    %2 = cc.load %0 : !cc.ptr<i64>
    return %2 : i64
  }
}

72057594037927936

Note
Passing two ints or two bools seems to work correctly:

  @cudaq.kernel(verbose=True)
  def kernel(b:bool, b2: bool) -> bool:
      return b
  
  assert kernel(True, False) == True
  @cudaq.kernel(verbose=True)
  def kernel(b:int, b2: int) -> int:
      return b
  
  assert kernel(42, 53) == 42

Steps to reproduce the bug

@cudaq.kernel(verbose=True)
def kernel(c: int, b: bool) -> int:
    return c
    
print(kernel(1, True))

Output

72057594037927936

Expected behavior

1

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