Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Incorrect return value with a bool parameter #1580

Open
4 tasks done
annagrin opened this issue Apr 26, 2024 · 0 comments
Open
4 tasks done

[Python] Incorrect return value with a bool parameter #1580

annagrin opened this issue Apr 26, 2024 · 0 comments
Assignees
Labels
python bridge Involves the python bridge to quake

Comments

@annagrin
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python bridge Involves the python bridge to quake
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants