Skip to content

Controlled exp_pauli is not working #2822

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

Open
4 tasks done
psm-optimizes opened this issue Apr 17, 2025 · 1 comment
Open
4 tasks done

Controlled exp_pauli is not working #2822

psm-optimizes opened this issue Apr 17, 2025 · 1 comment

Comments

@psm-optimizes
Copy link

psm-optimizes commented Apr 17, 2025

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

  1. I want to use the controlled version of exp_pauli to apply the Hamiltonian simulation of the coefficient matrix of a linear system of equations as a part of a HHL-type algorithm.
  2. Throughout the circuit, I call the controlled exp_pauli in a for loop to apply the Hamiltonian controlled by different cubits.
  3. The error I get is as follows:
    error: 'quake.extract_ref' op invalid constant index value
    RuntimeError Traceback (most recent call last)
    Cell In[17], line 3
    1 # Draw the quantum circuit
    2 print("============================== Circuit structure ============================== \n")
    ----> 3 print(cudaq.draw(GQLSS, b, eigs, r_choice, 2*np.pi, coefficients, words))

RuntimeError: cudaq::builder failed to JIT compile the Quake representation.

Steps to reproduce the bug

The code is available here.

Expected behavior

The circuit should be drawn.

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

Not a regression

Environment

  • CUDA-Q version: 0.10.0
  • Python version: 3.11.8
  • C++ compiler:
  • Operating system: Linux blue2 5.10.0-20-amd64

Suggestions

No response

@bmhowe23
Copy link
Collaborator

Thanks for reporting this issue, @psm-optimizes. Based on a quick look, it looks like there is bug in how CUDA-Q is handling this section of code:

    # Apply y rotations on Ancilla qubit
    for i in range(len(qReg)+1):
        if i != 0:
            ry.ctrl((2*np.pi)/eigs[i-1], [qReg[i-1]], qAnc)  

While we investigate the underlying issue a bit further, I figured it would be worth sharing that there is a workaround available. If you change your code to this, then I think it will work.

    # Apply y rotations on Ancilla qubit
    for i in range(1, len(qReg)+1):
        ry.ctrl((2*np.pi)/eigs[i-1], [qReg[i-1]], qAnc)  

After resolving this issue, the next error message that comes up is RuntimeError: Applying controlled global phase via exp_pauli of identity operator is not supported. That message is occurring because CUDA-Q does not support calling exp_pauli on terms with all Is, so I believe you will need to make this change:

# Drop the `II` term. Adjust downstream calculations as needed.
words = words[1:]
coefficients = coefficients[1:]

Hopefully this helps.

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

No branches or pull requests

2 participants