Skip to content

Upstream

always_merge_heuristic

always_merge_heuristic(
    region_a: Region, region_b: Region
) -> bool

Always allow merging; all CZs end up in one region in the Place IR.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/upstream.py
30
31
32
def always_merge_heuristic(region_a: ir.Region, region_b: ir.Region) -> bool:
    """Always allow merging; all CZs end up in one region in the Place IR."""
    return True

squin_to_move

squin_to_move(
    mt: Method,
    layout_heuristic: LayoutHeuristicABC,
    placement_strategy: PlacementStrategyABC,
    insert_return_moves: bool = True,
    revert_initial_position: Callable[
        [dict[SSAValue, AtomState], StaticPlacement],
        tuple[tuple[LaneAddress, ...], ...] | None,
    ] = place2move.palindrome_move_layers,
    merge_heuristic: Callable[
        [Region, Region], bool
    ] = default_merge_heuristic,
    no_raise: bool = True,
    logical_initialize: bool = True,
) -> ir.Method

Compile a squin kernel to move dialect.

Parameters:

Name Type Description Default
mt Method

The Squin kernel to compile.

required
layout_heuristic LayoutHeuristicABC

The layout heuristic to use.

required
placement_strategy PlacementStrategyABC

The placement strategy to use.

required
insert_return_moves bool

Whether to insert return moves. Defaults to True.

True
revert_initial_position Callable

Callback returning move layers to insert near the end of each static placement region. Defaults to palindrome_move_layers.

palindrome_move_layers
merge_heuristic Callable[[Region, Region], bool]

Heuristic for merging placement regions. Defaults to default_merge_heuristic.

default_merge_heuristic
no_raise bool

Whether to suppress exceptions during compilation. Defaults to True.

True
logical_initialize bool

Whether to apply rewrites that insert logical qubit initialization operations; when False, these rewrites are skipped. Defaults to True.

True

Returns:

Type Description
Method

ir.Method: The compiled move dialect method.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/upstream.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def squin_to_move(
    mt: ir.Method,
    layout_heuristic: layout.LayoutHeuristicABC,
    placement_strategy: placement.PlacementStrategyABC,
    insert_return_moves: bool = True,
    revert_initial_position: Callable[
        [dict[ir.SSAValue, placement.AtomState], place.StaticPlacement],
        tuple[tuple[LaneAddress, ...], ...] | None,
    ] = place2move.palindrome_move_layers,
    merge_heuristic: Callable[[ir.Region, ir.Region], bool] = default_merge_heuristic,
    no_raise: bool = True,
    logical_initialize: bool = True,
) -> ir.Method:
    """
    Compile a squin kernel to move dialect.

    Args:
        mt (ir.Method): The Squin kernel to compile.
        layout_heuristic (layout.LayoutHeuristicABC): The layout heuristic to use.
        placement_strategy (placement.PlacementStrategyABC): The placement strategy to use.
        insert_return_moves (bool, optional): Whether to insert return moves. Defaults to True.
        revert_initial_position (Callable, optional): Callback returning move
            layers to insert near the end of each static placement region.
            Defaults to palindrome_move_layers.
        merge_heuristic (Callable[[ir.Region, ir.Region], bool], optional): Heuristic for merging placement regions. Defaults to default_merge_heuristic.
        no_raise (bool, optional): Whether to suppress exceptions during compilation. Defaults to True.
        logical_initialize (bool, optional): Whether to apply rewrites that insert logical qubit initialization operations; when False, these rewrites are skipped. Defaults to True.

    Returns:
        ir.Method: The compiled move dialect method.
    """

    out = NativeToPlace(
        merge_heuristic=merge_heuristic,
        logical_initialize=logical_initialize,
    ).emit(mt, no_raise=no_raise)
    out = PlaceToMove(
        layout_heuristic=layout_heuristic,
        placement_strategy=placement_strategy,
        insert_return_moves=insert_return_moves,
        revert_initial_position=revert_initial_position,
        logical_initialize=logical_initialize,
    ).emit(out, no_raise=no_raise)

    passes.TypeInfer(mt.dialects)(out)
    out.verify()
    out.verify_type()

    return out