cuda-quantum icon indicating copy to clipboard operation
cuda-quantum copied to clipboard

Iterable data types within quantum kernels

Open marwafar opened this issue 11 months ago • 2 comments

Required prerequisites

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

Describe the feature

If I run the example below:

import cudaq

qubits_num=4

@cudaq.kernel
def circuit():

    qubits=cudaq.qvector(qubits_num)

    s='0001'

    for i in s:
        if i=='1':
            x(qubits[i])

    mz(qubits)

result=cudaq.sample(circuit,shots_count=5000)
print(result)

I get the following error:

cudaq.kernel.ast_bridge.CompilerError: test.py:11: error: {} iterable type not supported.
	 (offending source -> for i in s:
    if i == '1':
        x(qubits[i]))

There are many cases where we need to use if statement. Currently, we have to repeat the code multiple time for each if statement.

Edit from bettinaheim: We have a similar case of "not supported" when iterating over a register of qubits. Let's define more broadly what iterations to support within kernels. Re string, see also https://github.com/NVIDIA/cuda-quantum/issues/1452.

marwafar avatar Mar 23 '24 11:03 marwafar