Apply a call to the given `target` kernel within the function-body of `self` at the provided target arguments. Args: target (:class:`Kernel`): The kernel to call from within `self`. *target_arguments (Optional[:class:`QuakeValue`]): The arguments
(self, target, *target_arguments)
| 1387 | return |
| 1388 | |
| 1389 | def apply_call(self, target, *target_arguments): |
| 1390 | """ |
| 1391 | Apply a call to the given `target` kernel within the function-body of |
| 1392 | `self` at the provided target arguments. |
| 1393 | |
| 1394 | Args: |
| 1395 | target (:class:`Kernel`): The kernel to call from within `self`. |
| 1396 | *target_arguments (Optional[:class:`QuakeValue`]): |
| 1397 | The arguments to the `target` kernel. Leave empty if the `target` |
| 1398 | kernel doesn't accept any arguments. |
| 1399 | |
| 1400 | Raises: |
| 1401 | RuntimeError: if the `*target_arguments` passed to the apply |
| 1402 | call don't match the argument signature of `target`. |
| 1403 | |
| 1404 | ```python |
| 1405 | # Example: |
| 1406 | # Build a `Kernel` that's parameterized by a `cudaq.qubit`. |
| 1407 | target_kernel, other_qubit = cudaq.make_kernel(cudaq.qubit) |
| 1408 | target_kernel.x(other_qubit) |
| 1409 | # Build a `Kernel` that will call `target_kernel` within its |
| 1410 | # own function body. |
| 1411 | kernel = cudaq.make_kernel() |
| 1412 | qubit = kernel.qalloc() |
| 1413 | # Use `qubit` as the argument to `target_kernel`. |
| 1414 | kernel.apply_call(target_kernel, qubit) |
| 1415 | # The final measurement of `qubit` should return the 1-state. |
| 1416 | kernel.mz(qubit)) |
| 1417 | ``` |
| 1418 | """ |
| 1419 | if isa_kernel_decorator(target): |
| 1420 | if not target.is_compiled(): |
| 1421 | name = target.name |
| 1422 | emitFatalError( |
| 1423 | f"Kernel '{name}' must be compiled to be used in the kernel builder. " |
| 1424 | f"Call `{name}.compile()` before initializing the kernel builder, " |
| 1425 | f"or deactivate deferred compilation:\n\n" |
| 1426 | f" @cudaq.kernel(defer_compilation=False)\n" |
| 1427 | f" def {name}(...): ...\n") |
| 1428 | target = self.resolve_callable_arg(self.insertPoint, |
| 1429 | DecoratorCapture(target)) |
| 1430 | self.__applyControlOrAdjoint(target, False, [], *target_arguments) |
| 1431 | |
| 1432 | def resolve_callable_arg(self, insPt, |
| 1433 | target: DecoratorCapture | LinkedKernelCapture): |