Skip to content

Compile

compile_squin_to_move

compile_squin_to_move(
    mt: Method,
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> ir.Method

Compile a physical squin kernel to the move dialect.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/compile.py
28
29
30
31
32
33
34
35
36
37
38
39
def compile_squin_to_move(
    mt: ir.Method,
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> ir.Method:
    """Compile a physical squin kernel to the move dialect."""
    return PhysicalPipeline(
        arch_spec=get_physical_arch_spec(),
        layout_heuristic=layout_heuristic,
        placement_strategy=placement_strategy,
    ).emit(mt, no_raise=no_raise)

compile_squin_to_move_and_visualize

compile_squin_to_move_and_visualize(
    mt: Method,
    interactive: bool = True,
    animated: bool = False,
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> None

Compile a physical squin kernel to moves and visualize the program.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/compile.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def compile_squin_to_move_and_visualize(
    mt: ir.Method,
    interactive: bool = True,
    animated: bool = False,
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> None:
    """Compile a physical squin kernel to moves and visualize the program."""
    mt = compile_squin_to_move(
        mt,
        no_raise=no_raise,
        layout_heuristic=layout_heuristic,
        placement_strategy=placement_strategy,
    )
    arch_spec = get_physical_arch_spec()
    marker = "o"

    if animated:
        visualize.animated_debugger(
            mt, arch_spec, interactive=interactive, atom_marker=marker
        )
    else:
        visualize.debugger(mt, arch_spec, interactive=interactive, atom_marker=marker)

compile_squin_to_move_best

compile_squin_to_move_best(
    mt: Method,
    strategies: Sequence[tuple[str, PlacementStrategyABC]],
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
) -> tuple[ir.Method, str]

Compile with each (label, strategy) and return the one producing the fewest :class:move.Move events.

Ties are resolved by earliest-in-list (caller-controlled preference). The returned label names the winning strategy.

The three intra-stage heuristics (:class:DefaultTargetGenerator, :class:CongestionAwareTargetGenerator, :class:AODClusterTargetGenerator) each win on different circuit shapes. Racing all three and keeping the best covers the per-circuit variation without designing a meta-heuristic.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/compile.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
80
81
82
83
84
85
86
87
88
89
90
def compile_squin_to_move_best(
    mt: ir.Method,
    strategies: Sequence[tuple[str, PlacementStrategyABC]],
    no_raise: bool = True,
    layout_heuristic: LayoutHeuristicABC | None = None,
) -> tuple[ir.Method, str]:
    """Compile with each ``(label, strategy)`` and return the one producing
    the fewest :class:`move.Move` events.

    Ties are resolved by earliest-in-list (caller-controlled preference).
    The returned ``label`` names the winning strategy.

    The three intra-stage heuristics
    (:class:`DefaultTargetGenerator`,
    :class:`CongestionAwareTargetGenerator`,
    :class:`AODClusterTargetGenerator`) each win on different circuit
    shapes. Racing all three and keeping the best covers the per-circuit
    variation without designing a meta-heuristic.
    """
    if not strategies:
        raise ValueError("compile_squin_to_move_best requires at least one strategy")

    best_mt: ir.Method | None = None
    best_events = -1
    best_label = ""
    for label, strategy in strategies:
        compiled = compile_squin_to_move(
            mt,
            no_raise=no_raise,
            layout_heuristic=layout_heuristic,
            placement_strategy=strategy,
        )
        events = _count_move_events(compiled)
        # strict-less keeps the earliest on ties.
        if best_mt is None or events < best_events:
            best_mt = compiled
            best_events = events
            best_label = label
    assert best_mt is not None
    return best_mt, best_label

compile_to_physical_squin_noise_model

compile_to_physical_squin_noise_model(
    mt: Method,
    noise_model: NoiseModelABC | None = None,
    no_raise: bool = True,
    arch_spec=None,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> ir.Method

Compile a physical squin kernel to physical squin with inserted noise channels.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/compile.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
def compile_to_physical_squin_noise_model(
    mt: ir.Method,
    noise_model: NoiseModelABC | None = None,
    no_raise: bool = True,
    arch_spec=None,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> ir.Method:
    """Compile a physical squin kernel to physical squin with inserted noise channels."""
    if noise_model is None:
        noise_model = generate_simple_noise_model()
    if arch_spec is None:
        arch_spec = get_physical_arch_spec()

    move_mt = compile_squin_to_move(
        mt,
        no_raise=no_raise,
        layout_heuristic=layout_heuristic,
        placement_strategy=placement_strategy,
    )
    transformer = MoveToSquinPhysical(
        arch_spec=arch_spec,
        noise_model=noise_model,
        aggressive_unroll=False,
    )

    return transformer.emit(move_mt, no_raise=no_raise)

compile_to_stim_program

compile_to_stim_program(
    mt: Method,
    noise_model: NoiseModelABC | None = None,
    no_raise: bool = True,
    arch_spec=None,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> str

Compile a physical squin kernel to a Stim program string.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/compile.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def compile_to_stim_program(
    mt: ir.Method,
    noise_model: NoiseModelABC | None = None,
    no_raise: bool = True,
    arch_spec=None,
    layout_heuristic: LayoutHeuristicABC | None = None,
    placement_strategy: PlacementStrategyABC | None = None,
) -> str:
    """Compile a physical squin kernel to a Stim program string."""
    noise_kernel = compile_to_physical_squin_noise_model(
        mt,
        noise_model=noise_model,
        no_raise=no_raise,
        arch_spec=arch_spec,
        layout_heuristic=layout_heuristic,
        placement_strategy=placement_strategy,
    )
    RemoveReturn().rewrite(noise_kernel.code)
    noise_kernel = squin_to_stim(noise_kernel)
    buf = io.StringIO()
    emit = EmitStimMain(dialects=noise_kernel.dialects, io=buf)
    emit.initialize()
    emit.run(node=noise_kernel)
    return buf.getvalue().strip()