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

Unexpected JIT compilation error when cudaq.observe from Python #2383

Open
3 of 4 tasks
bmhowe23 opened this issue Nov 15, 2024 · 0 comments
Open
3 of 4 tasks

Unexpected JIT compilation error when cudaq.observe from Python #2383

bmhowe23 opened this issue Nov 15, 2024 · 0 comments
Assignees

Comments

@bmhowe23
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

Running cudaq.observe() from a Python test program shown below produces the following error:

error: 'cc.address_of' op must reference a global
RuntimeError: Could not apply measurements to ansatz.

Steps to reproduce the bug

Save the following to test.py

import cudaq
from typing import List

cudaq.set_target("oqc", emulate=True)

# Initialize a kernel/ ansatz and variational parameters.
@cudaq.kernel
def kernel(angles: List[float]):
    # Allocate a qubit that is initialized to the |0> state.
    qubit = cudaq.qubit()
    # Define gates and the qubits they act upon.
    rx(angles[0], qubit)
    ry(angles[1], qubit)


# Our Hamiltonian will be the Z expectation value of our qubit.
hamiltonian = cudaq.spin.z(0)

# Initial gate parameters which initialize the qubit in the zero state
initial_parameters = [0, 0]

cost_values = []

def cost(parameters):
    """Returns the expectation value as our cost."""
    expectation_value = cudaq.observe(kernel, hamiltonian,
                                      parameters).expectation()
    cost_values.append(expectation_value)
    return expectation_value

# We see that the initial value of our cost function is one, demonstrating that our qubit is in the zero state
initial_cost_value = cost(initial_parameters)
print(initial_cost_value)

And then run the test program:

$ python3 test.py
error: 'cc.address_of' op must reference a global
RuntimeError: Could not apply measurements to ansatz.

Expected behavior

The program should run without errors. Note that a very similar program in C++ (targettests/execution/cudaq_observe.cpp in the repo) seems to run without errors.

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

Yes; last known to have worked in 0.8.0

Environment

  • CUDA-Q version: latest (which is 3300b12 as of the time of this writing)
  • Python version: 3.10
  • C++ compiler: N/A
  • Operating system: N/A

Suggestions

No response

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