NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
486 stars 179 forks source link

Dynamic kernels #2233

Open zohimchandani opened 3 days ago

zohimchandani commented 3 days ago

Required prerequisites

Describe the feature

One may need to either grow, reduce or change the structure of the kernel within an algorithm. The idea of inserting a gate in a specific location comes into play here without having to modify/ copy the kernel once again.

For example:

import cudaq 

@cudaq.kernel
def kernel():
    q = cudaq.qvector (3)
    x(q[0])

@cudaq.kernel
def dynamic_kernel(q1: cudaq.qubit, q2: cudaq.qubit):
    cx(q1, q2)

for i in range(n_epochs): 

    result = scipy.optimize(obj)

    if result < 1: 
        cudaq.insert(dynamic_kernel, kernel, position = 2) #insert dynamic kernel into kernel at position 2

    #need to think about what position 2 means in this case