Just-In-Time (JIT) compile `self` (:class:`Kernel`), and call the kernel function at the provided concrete arguments. Args: *arguments (Optional[Any]): The concrete values to evaluate the kernel function at. Leave empty if the `target` kernel do
(self, *args)
| 1742 | StringAttr.get(self.uniqName, context=ctx)) |
| 1743 | |
| 1744 | def __call__(self, *args): |
| 1745 | """ |
| 1746 | Just-In-Time (JIT) compile `self` (:class:`Kernel`), and call the kernel |
| 1747 | function at the provided concrete arguments. |
| 1748 | |
| 1749 | Args: |
| 1750 | *arguments (Optional[Any]): The concrete values to evaluate the |
| 1751 | kernel function at. Leave empty if the `target` kernel doesn't |
| 1752 | accept any arguments. |
| 1753 | |
| 1754 | ```python |
| 1755 | # Example: |
| 1756 | # Create a kernel that accepts an int and float as its |
| 1757 | # arguments. |
| 1758 | kernel, qubit_count, angle = cudaq.make_kernel(int, float) |
| 1759 | # Parameterize the number of qubits by `qubit_count`. |
| 1760 | qubits = kernel.qalloc(qubit_count) |
| 1761 | # Apply an `rx` rotation on the first qubit by `angle`. |
| 1762 | kernel.rx(angle, qubits[0]) |
| 1763 | # Call the `Kernel` on the given number of qubits (5) and at |
| 1764 | a concrete angle (pi). |
| 1765 | kernel(5, 3.14)) |
| 1766 | ``` |
| 1767 | """ |
| 1768 | if len(self.appliedNoiseChannels) > 0: |
| 1769 | noise_model = cudaq_runtime.get_noise() |
| 1770 | if noise_model is not None: |
| 1771 | # Note: the runtime would already warn about `apply_noise` |
| 1772 | # called but no noise model provided. Here, we just ignore the |
| 1773 | # registration of inline noise applications. |
| 1774 | for noise_channel in self.appliedNoiseChannels: |
| 1775 | noise_model.register_channel(noise_channel) |
| 1776 | |
| 1777 | if len(args) != len(self.mlirArgTypes): |
| 1778 | emitFatalError(f"Invalid number of arguments passed to kernel " |
| 1779 | f"`{self.funcName}` ({len(args)} provided, " |
| 1780 | f"{len(self.mlirArgTypes)} required") |
| 1781 | # validate the argument types |
| 1782 | processedArgs = [] |
| 1783 | for i, arg in enumerate(args): |
| 1784 | # Handle `list[str]` separately - we allow this only for |
| 1785 | # `list[cudaq.pauli_word]` inputs |
| 1786 | if issubclass(type(arg), list) and len(arg) and all( |
| 1787 | isinstance(a, str) for a in arg): |
| 1788 | [emitErrorIfInvalidPauli(a) for a in arg] |
| 1789 | processedArgs.append([cudaq_runtime.pauli_word(a) for a in arg]) |
| 1790 | continue |
| 1791 | |
| 1792 | # Handle `str` input separately - we allow this for |
| 1793 | # `cudaq.pauli_word` inputs |
| 1794 | if isinstance(arg, str): |
| 1795 | emitErrorIfInvalidPauli(arg) |
| 1796 | processedArgs.append(cudaq_runtime.pauli_word(arg)) |
| 1797 | continue |
| 1798 | |
| 1799 | argType = type(arg) |
| 1800 | listType = None |
| 1801 | if argType == list: |
nothing calls this directly
no test coverage detected