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

Unable to Apply Operators from a List of Operator Names in cudaq.register_operation() #2595

Open
3 of 4 tasks
poojarao8 opened this issue Feb 6, 2025 · 0 comments
Open
3 of 4 tasks

Comments

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

I am trying to apply several general unitary matrices to a circuit. I can successfully use cudaq.register_operation(...) by explicitly specifying the operation name. However, I have a use case where I need to store these operator names in a list and retrieve them within a loop. While no error is raised, nothing gets added to the kernel when I attempt this approach. Below is a minimal working example that demonstrates the issue.

Steps to reproduce the bug

Working Example (Using Operator Name Directly):

import cudaq
import math
from cudaq import spin
import numpy as np

N = 2

# Define the observable in spin operator form
observable = 0.5 * spin.z(0) * spin.z(1)

U = np.array([
    [0, 0, 0.92387953, -0.38268343j],
    [0, 0, -0.38268343j, 0.92387953],
    [-0.38268343j, 0.92387953, 0, 0],
    [0.92387953, -0.38268343j, 0, 0]
]) 

cudaq.register_operation("spa", U)
op = ["spa"]

##############################
###   BASE FUNCTIONALITY   ###
##############################
@cudaq.kernel
def cudaq_circuit():
    qubits = cudaq.qvector(N)
    spa(qubits[0], qubits[1])

# Observe the circuit with the specified observable
result = cudaq.observe(cudaq_circuit, observable)
print("Using directly: ", result.expectation())    ### Output :  0.3535533770918846

Expected behavior

Desired Implementation (Using Operator from List):

@cudaq.kernel
def cudaq_circuit():
    qubits = cudaq.qvector(N)
    op[0](qubits[0], qubits[1])

# Observe the circuit with the specified observable
result = cudaq.observe(cudaq_circuit, observable)
print("Trying to use from vector of operator names: ", result.expectation())    ### Output:  0.5

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

Not a regression

Environment

  • CUDA-Q version:
  • Python version:
  • C++ compiler:
  • Operating system:

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

1 participant