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

Measurement result type conversion to int

Open ikkoham opened this issue 6 months ago • 0 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

Type conversion from bool to int in kernel fails.

Steps to reproduce the bug

import cudaq

@cudaq.kernel
def mykernel() -> int:
    qubit = cudaq.qubit()
    result = mz(qubit)
    return result

mykernel()

fails

CompilerError: 3902201743.py:7: error: Invalid return type, function was defined to return a <class 'int'> but the value being returned is of type <class 'bool'>
	 (offending source -> return result)

Expected behavior

import cudaq

@cudaq.kernel
def mykernel() -> bool:
    qubit = cudaq.qubit()
    result = mz(qubit)
    return result

mykernel()

and

import cudaq

@cudaq.kernel
def mykernel() -> float:
    qubit = cudaq.qubit()
    result = mz(qubit)
    return result

mykernel()

works.

I'm not sure this is a bug or spec.

Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

Environment

  • CUDA Quantum version: 0.8.0
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response

ikkoham avatar Aug 22 '24 01:08 ikkoham