MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / _make_kernel_ast

Function _make_kernel_ast

python/tests/kernel/test_kernel_signature.py:80–93  ·  view source on GitHub ↗

Build an ``ast.Module`` for a stub kernel with the given type annotations. ``arg_types`` is a list of annotation strings (e.g. ``["int", "float"]``). ``return_type`` is an annotation string (e.g. ``"bool"``) or ``None``.

(arg_types=None, return_type=None)

Source from the content-addressed store, hash-verified

78
79
80def _make_kernel_ast(arg_types=None, return_type=None) -> ast.Module:
81 """
82 Build an ``ast.Module`` for a stub kernel with the given type annotations.
83
84 ``arg_types`` is a list of annotation strings (e.g. ``["int", "float"]``).
85 ``return_type`` is an annotation string (e.g. ``"bool"``) or ``None``.
86 """
87 params = ", ".join(f"a{i}: {t}" for i, t in enumerate(arg_types or []))
88 ret = f" -> {return_type}" if return_type else ""
89 src = textwrap.dedent(f"""\
90 def kernel({params}){ret}:
91 pass
92 """)
93 return ast.parse(src)
94
95
96# -- test cases -------------------------------------------------------------

Callers 5

test_scalar_arg_typesFunction · 0.85
test_container_arg_typesFunction · 0.85
test_return_typesFunction · 0.85

Calls 3

enumerateFunction · 0.85
joinMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected