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 version on Quantum Cloud does not allow exponentiation operator #1663

Closed
4 tasks done
rtvuser1 opened this issue May 11, 2024 · 0 comments · Fixed by #1692
Closed
4 tasks done

Python version on Quantum Cloud does not allow exponentiation operator #1663

rtvuser1 opened this issue May 11, 2024 · 0 comments · Fixed by #1692
Labels
bug Something isn't working
Milestone

Comments

@rtvuser1
Copy link

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

When using the Python version on Quantum Cloud, the exponentiation operator ** gives the error:
error: failed to legalize operation 'math.ipowi'
RuntimeError: Remote rest platform: applying IR passes failed.

The workaround is to apply multiplication N times in a loop

Steps to reproduce the bug

Here is a simple code example which, when run gives an error.
Commenting the offending line, and uncommenting the WORKAROUND lines enables this to run on quantum cloud with the --target nvqc argument passed.

    #######################################################
    
    # PYTHON KERNEL - EXPONENTIATION BUG - QUANTUM CLOUD
    
    import cudaq
    
    # Inverse Quantum Fourier Transform
    @cudaq.kernel
    def iqft(register: cudaq.qview):
        M_PI = 3.1415926
        
        N = register.size()
        for i in range(N / 2):
            swap(register[i], register[N - i - 1])
        
        for i in range(N - 1):
            h(register[i])
            j = i + 1
            for y in range(i, -1, -1):
            
                denom = 2 ** (j - y)       # DEVNOTE: Issue ??? This does not work on Quantum Cloud
                
                '''
                X = j - y                   # this WORKAROUND works
                denom = 1
                for i in range(X):
                    denom *= 2
                '''
                
                theta = -M_PI / denom
                r1.ctrl(theta, register[j], register[y]);
              
        h(register[N - 1])
     
    @cudaq.kernel
    def bug_cloud_exp():
    
        # Allocate a number of qubits
        counting_qubits = cudaq.qvector(4)
    
        # Place some bits into test state
        h(counting_qubits)
    
        # Apply inverse quantum Fourier transform
        iqft(counting_qubits)
        
        # Measure to gather sampling statistics
        # (excludes the auxillary qubit).
        mz(counting_qubits)
        
        
    #######################
    # MAIN
     
    if __name__ == "__main__":
    
        print(f"Python Kernel Bug - Exponentiation - Quantum Cloud")
        
        result = cudaq.sample(bug_cloud_exp)
        
        print(f"result: {result}")

Expected behavior

There should be no error when using the ** operator.

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

Not a regression

Environment

  • CUDA Quantum version: 0.7.1
  • Python version: 3.10.12

Suggestions

This is an important bug as the exponentiation operator is critical to many kernels such as QFT
The WOARKAROUND is OK, but this will frustrate users initially

@bmhowe23 bmhowe23 added the bug Something isn't working label May 17, 2024
@bmhowe23 bmhowe23 added this to the release 0.8.0 milestone May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants