Skip to content

Squin2native

SquinToNative

A Target that converts Squin gates to native gates.

emit

emit(mt: Method, *, no_raise=True) -> ir.Method

Convert Squin gates to native gates.

Parameters:

Name Type Description Default
mt Method

The method to convert.

required
no_raise bool

Whether to suppress errors. Defaults to True.

True

Returns:

Type Description
Method

ir.Method: The converted method.

Source code in .venv/lib/python3.12/site-packages/bloqade/native/upstream/squin2native.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def emit(self, mt: ir.Method, *, no_raise=True) -> ir.Method:
    """Convert Squin gates to native gates.

    Args:
        mt (ir.Method): The method to convert.
        no_raise (bool, optional): Whether to suppress errors. Defaults to True.

    Returns:
        ir.Method: The converted method.
    """
    old_callgraph = CallGraph(mt)
    all_dialects = chain.from_iterable(
        ker.dialects.data for kers in old_callgraph.defs.values() for ker in kers
    )
    combined_dialects = mt.dialects.union(all_dialects).union(kernel)

    out = mt.similar(combined_dialects)
    UpdateDialectsOnCallGraph(combined_dialects, no_raise=no_raise)(out)
    CallGraphPass(combined_dialects, rewrite.Walk(GateRule()), no_raise=no_raise)(
        out
    )
    # verify all kernels in the callgraph and discard gate dialect
    out.dialects.discard(gate_dialect)
    new_callgraph = CallGraph(out)
    for ker in new_callgraph.edges.keys():
        ker.dialects.discard(gate_dialect)
        ker.verify()

    return out