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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
    )
    new_dialects = (
        mt.dialects.union(all_dialects).discard(gate_dialect).union(kernel)
    )

    out = mt.similar(new_dialects)
    UpdateDialectsOnCallGraph(new_dialects, no_raise=no_raise)(out)
    SquinToNativePass(new_dialects, no_raise=no_raise)(out)
    # verify all kernels in the callgraph
    new_callgraph = CallGraph(out)
    all_kernels = (ker for kers in new_callgraph.defs.values() for ker in kers)
    for ker in all_kernels:
        ker.verify()

    return out

UpdateDialectsOnCallGraph dataclass

UpdateDialectsOnCallGraph()

Bases: Pass

Update All dialects on the call graph to a new set of dialects given to this pass.

Usage

pass_ = UpdateDialectsOnCallGraph(rule=rule, dialects=new_dialects) pass_(some_method)

Note: This pass does not update the dialects of the input method, but copies all other methods invoked within it before updating their dialects.