Quantum kernel function conversion *********************************** ``quantum_kernel`` functions can be converted to a quantum kernel expression using three methods. If the quantum kernel function is already written and one does not want to modify or copy it, one can use the following template function: ``template QExpr qexpr::convert(Args... args)`` where ``qk_function`` is any ``quantum_kernel`` function with arbitrary parameters, so long as it has a ``void`` return type. The argument type list ``Args`` must be the same as that of ``qk_function`` and the argument list ``args`` is subject to the same constraints as those imposed on ``qk_function`` as a ``quantum_kernel`` function (see the |DGR|). An exception is that ``qbit`` arguments to converted ``quantum_kernel`` functions *are* allowed, so long as they are compile-time resolvable when evaluated; see :ref:`local_qubits`. For example: .. code-block:: C++ const int N = 4; qbit qs[N]; void quantum_kernel prepAll() { for (int i=0; i()); qexpr::eval_hold(qexpr::convert(qs[2], qs[3])); ... } This kind of conversion can be useful for debugging ``quantum_kernel`` functions; see :ref:`debug`. Alternatively, a ``quantum_kernel`` function can be modified directly to return a quantum kernel expression by adding a return statement using the keyword ``this_as_expr``. For reasons outlined in :ref:`compilation-overview`, any function which returns ``this_as_expr`` must have the added attribute ``PROTECT`` as enforced by the FLEQ compilation stage of IQC. For example: .. code-block:: C++ PROTECT QExpr prepAll_qexpr() { for (int i=0; i