Skip to content

Cudaq integration

cudaq_to_squin

cudaq_to_squin(kernel: Callable[..., Any]) -> ir.Method

Convert a CUDA-Q kernel to a squin ir.Method.

The conversion pipeline is::

CUDA-Q kernel  →  QIR (base profile)  →  squin ir.Method

Parameters:

Name Type Description Default
kernel Callable[..., Any]

A CUDA-Q PyKernelDecorator instance.

required

Returns:

Type Description
Method

The squin ir.Method corresponding to kernel.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/cudaq_integration.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def cudaq_to_squin(kernel: Callable[..., Any]) -> ir.Method:
    """Convert a CUDA-Q kernel to a squin ``ir.Method``.

    The conversion pipeline is::

        CUDA-Q kernel  →  QIR (base profile)  →  squin ir.Method

    Args:
        kernel: A CUDA-Q ``PyKernelDecorator`` instance.

    Returns:
        The squin ``ir.Method`` corresponding to *kernel*.
    """
    import cudaq as cudaq_module  # type: ignore[reportMissingImports]
    from qbraid_qir.squin import load  # type: ignore[reportMissingImports]

    qir_str = cudaq_module.translate(kernel, format="qir-base")
    mt: ir.Method = load(qir_str, dialects=logical.kernel)

    assert (run_pass := logical.kernel.run_pass) is not None
    run_pass(mt, aggressive_unroll=True, verify=False)

    return mt

is_cudaq_kernel

is_cudaq_kernel(obj: Any) -> bool

Check whether obj is a CUDA-Q kernel (PyKernelDecorator).

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/cudaq_integration.py
10
11
12
13
14
15
16
def is_cudaq_kernel(obj: Any) -> bool:
    """Check whether *obj* is a CUDA-Q kernel (``PyKernelDecorator``)."""
    try:
        from cudaq import PyKernelDecorator  # type: ignore[reportMissingImports]
    except ImportError:
        return False
    return isinstance(obj, PyKernelDecorator)