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
473 stars 172 forks source link

Valid kernel argument throwing compile-time error #2103

Open amccaskey opened 3 weeks ago

amccaskey commented 3 weeks ago
#include "cudaq.h"

__qpu__ void adapt_kernel(std::size_t numQubits,
                          const std::function<void(cudaq::qview<>)> &statePrep,
                          const std::vector<double> &thetas,
                          const std::vector<double> &coefficients,
                          const std::vector<cudaq::pauli_word> &trotterOpList) {
  cudaq::qvector q(numQubits);
  statePrep(q);
}

produces the following error

In file included from tmp2.cpp:1:
In file included from /cuda-quantum/runtime/cudaq.h:13:
In file included from /cuda-quantum/runtime/cudaq/qis/qubit_qis.h:15:
In file included from /cuda-quantum/runtime/cudaq/qis/qarray.h:12:
In file included from /cuda-quantum/runtime/cudaq/qis/qview.h:12:
In file included from /cuda-quantum/runtime/cudaq/qis/qudit.h:11:
In file included from /cuda-quantum/runtime/cudaq/qis/execution_manager.h:13:
In file included from /cuda-quantum/runtime/cudaq/spin_op.h:14:
In file included from /../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/functional:59:
/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:587:18: error: may not use quantum types in non-kernel functions
      operator()(_ArgTypes... __args) const
                 ^
error: C++ source has errors. nvq++ cannot proceed.

presumably due to qview<> in the std::function type triggering the "quantum types not allowed" error at ASTBridge.cpp:318. I'm not sure how to make the bridge view this as valid.

This is a useful programming pattern when building libraries.

This seems to be working in the AST-Quake/callable-2.cpp test file . In fact the above code compiles if I change the qview to a qubit& and update the function body accordingly. It also works if I change to qvector<>& in the functional argument. Not sure why qview<> does not work.

sacpis commented 3 weeks ago

Thanks @amccaskey for filing this issue. Would you please give me an example code you are trying to run?

amccaskey commented 3 weeks ago

This is just the code snippet above, and run cudaq-quake on it.