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
427 stars 149 forks source link

`from_state` error with `kernel.qalloc()` #1022

Open anthony-santana opened 7 months ago

anthony-santana commented 7 months ago

Required prerequisites

Describe the bug

There is a runtime error when passing a single qubit that's been allocated with kernel.qalloc() to cudaq.from_state. The bug goes away when allocating a single qubit in a qvec kernel.qalloc(1).

Steps to reproduce the bug

import cudaq
import numpy as np

state = np.array([0,1])

kernel = cudaq.make_kernel()
qubit = kernel.qalloc()
# ok with:
# qubit = kernel.qalloc(1)

cudaq.from_state(kernel, qubit, state)
> RuntimeError: [from_state] cannot infer size of input quantum register, please specify the number of qubits via the from_state() final argument.

Expected behavior

Expect the from_state function to accept a single qubit that's not necessarily nested in a qvec. Or, we should pack the qubit in a temporary qvec behind the scenes.

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

Not a regression

Environment

Suggestions

No response

bettinaheim commented 1 week ago

Needs to be confirmed if this is still an issue with the new state handling.