Skip to content

Feature Request: Allow qvector unpacking (*) or direct qvector input for custom operations (cudaq.register_operation) #4120

@mmvandieren

Description

@mmvandieren

Required prerequisites

  • Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

When defining custom quantum operations from unitary matrices using cudaq.register_operation, the generated operation strictly requires discrete cudaq.qubit arguments.

When working with a cudaq.qvector, there is currently no way to dynamically unpack the register into the custom operation call. Python's standard argument unpacking operator (*) is not supported by @cudaq.kernel definitions, and passing the qvector directly throws an error.

import numpy as np

# 1. Define a unitary matrix for a custom operation (e.g., a 2-qubit operator)
custom_matrix = np.eye(4) # Using Identity for simplicity in this MWE
cudaq.register_operation("my_custom_op", custom_matrix)

@cudaq.kernel
def main_kernel():
    # Allocate a vector of 2 qubits
    qvec = cudaq.qvector(2)
    
    # ---------------------------------------------------------
    # DESIRED BEHAVIOR 1: Unpacking (Currently fails to parse/compile)
    # ---------------------------------------------------------
    # my_custom_op(*qvec) 
    
    # ---------------------------------------------------------
    # DESIRED BEHAVIOR 2: Passing the qvector directly 
    # ---------------------------------------------------------
    # my_custom_op(qvec)
    
    # ---------------------------------------------------------
    # CURRENT REQUIRED WORKAROUND: Hardcoding indices
    # ---------------------------------------------------------
    my_custom_op(qvec[0], qvec[1])

# Test the compilation
cudaq.sample(main_kernel)```

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions