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
521 stars 184 forks source link

String support within quantum kernels #1452

Open anthony-santana opened 7 months ago

anthony-santana commented 7 months ago

Required prerequisites

Describe the feature

Support a string initialization through multiplication by int in python bridge. This may fall under the larger umbrella of strings in kernels, but in python you can initialize strings as follows:

string = "0" * 5
print(string) # `00000`

As is, we don't support multiplication of these types in the bridge

RuntimeError: Invalid type for Binary Op <class 'ast.Mult'> (Value(%19 = "cc.load"(%17) : (!cc.ptr<!cc.array<i8 x 2>>) -> !cc.array<i8 x 2>), Value(%18 = "cc.load"(%0) : (!cc.ptr<i64>) -> i64))

This should be considered at some point in the future.

bettinaheim commented 7 months ago

We need a spec update regarding the use of strings within quantum kernels more generally.

khalatepradnya commented 4 months ago

+1 Allow passing string arguments to kernels. cudaq.kernel.ast_bridge.CompilerError: custom.py:34: error: str is not a supported type.

anthonysmaldone commented 3 months ago

+1 Being able to pass strings to kernels would greatly enhance readability when passing options. For example:

@cudaq.kernel
def data_encoding_example(encoding_type: str):
    qubit = cudaq.qubit()

    if encoding_type == "rx":
        rx(3.14, qubit)
    elif encoding_type == "ry":
        ry(3.14, qubit)
    elif encoding_type == "rz":
        h(qubit)
        rz(3.14, qubit)

would be very helpful.