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 Kernel] bool to int type casting issue #1620

Closed
1tnguyen opened this issue May 7, 2024 · 1 comment · Fixed by #1654
Closed

[Python Kernel] bool to int type casting issue #1620

1tnguyen opened this issue May 7, 2024 · 1 comment · Fixed by #1654
Labels
bug Something isn't working python-lang Anything related to the Python CUDA Quantum language implementation

Comments

@1tnguyen
Copy link
Collaborator

1tnguyen commented May 7, 2024

The below kernel

@cudaq.kernel
def kernel():
    data = cudaq.qvector(2)
    aux = cudaq.qubit()
    x(aux)
    bit = mz(aux)
    # Compare to 1
    if bit == 1:
        x(data[0])
    mz(data)

results in the following IR:

 %6 = bitcast %Result* %5 to i1*
 %7 = load i1, i1* %6, align 1
 %8 = sext i1 %7 to i64
 %9 = icmp eq i64 %8, 1

If bit==True (%7 == true in the above IR), it looks like the icmp returns false. A quick search of LLVM doc indicated that sext i1 ... i64 may convert true to -1.

In fact, the below kernel resulted in the correct distribution (may need the fixes from #1619 to get the measurement feedback detection working properly).

@cudaq.kernel
def kernel5():
    data = cudaq.qvector(2)
    aux = cudaq.qubit()
    x(aux)
    bit = mz(aux)
    # Compare to -1
    if bit == -1:
        x(data[0])
    mz(data)
@1tnguyen 1tnguyen added bug Something isn't working python-lang Anything related to the Python CUDA Quantum language implementation labels May 7, 2024
@1tnguyen
Copy link
Collaborator Author

1tnguyen commented May 7, 2024

@schweitzpgi suggested that we should use cc::CastOpMode::Unsigned in this case.

1tnguyen added a commit to 1tnguyen/cuda-quantum that referenced this issue May 10, 2024
1tnguyen added a commit that referenced this issue May 13, 2024
…n doing integer compare (#1654)

* Fixed #1620

* Fix spell check

* Use cc.CastOp rather than arith.Ext

* Update python/cudaq/kernel/ast_bridge.py

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

* Python code format + apply the recommended change  for the second place

---------

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
schweitzpgi added a commit to schweitzpgi/cuda-quantum that referenced this issue Jun 3, 2024
…n doing integer compare (NVIDIA#1654)

* Fixed NVIDIA#1620

* Fix spell check

* Use cc.CastOp rather than arith.Ext

* Update python/cudaq/kernel/ast_bridge.py

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

* Python code format + apply the recommended change  for the second place

---------

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
schweitzpgi added a commit to schweitzpgi/cuda-quantum that referenced this issue Jun 3, 2024
…n doing integer compare (NVIDIA#1654)

* Fixed NVIDIA#1620

* Fix spell check

* Use cc.CastOp rather than arith.Ext

* Update python/cudaq/kernel/ast_bridge.py

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

* Python code format + apply the recommended change  for the second place

---------

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
schweitzpgi added a commit to schweitzpgi/cuda-quantum that referenced this issue Jun 4, 2024
…n doing integer compare (NVIDIA#1654)

* Fixed NVIDIA#1620

* Fix spell check

* Use cc.CastOp rather than arith.Ext

* Update python/cudaq/kernel/ast_bridge.py

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

* Python code format + apply the recommended change  for the second place

---------

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
MarkusPfundstein pushed a commit to fermioniq/cuda-quantum that referenced this issue Sep 23, 2024
…n doing integer compare (NVIDIA#1654)

* Fixed NVIDIA#1620

* Fix spell check

* Use cc.CastOp rather than arith.Ext

* Update python/cudaq/kernel/ast_bridge.py

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

* Python code format + apply the recommended change  for the second place

---------

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python-lang Anything related to the Python CUDA Quantum language implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant