Valid kernel argument throwing compile-time error
Open
@schweitzpgi is already working on this.
Since Aug 19, 2024.
critical
stale-notified
- Dominant language
- C++
- Stars
- 1.1k
- Forks
- 456
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 165
Description
#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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.