Skip to content

Layout

LogicalLayoutHeuristic dataclass

LogicalLayoutHeuristic(
    arch_spec: ArchSpec = get_arch_spec(),
)

Bases: LayoutHeuristicABC


              flowchart TD
              bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic[LogicalLayoutHeuristic]
              bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC[LayoutHeuristicABC]

                              bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC --> bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic
                


              click bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic href "" "bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic"
              click bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC href "" "bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC"
            

compute_layout

compute_layout(
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
    pinned: dict[int, LocationAddress] | None = None,
) -> tuple[LocationAddress, ...]

Compute the initial qubit layout from circuit stages.

Parameters:

Name Type Description Default
all_qubits tuple[int, ...]

Tuple of logical qubit indices to be mapped.

required
stages list[tuple[tuple[int, int], ...]]

List of circuit stages, where each stage is a tuple of (control, target) qubit pairs representing two-qubit gates.

required
pinned dict[int, LocationAddress] | None

Map from logical qubit ID to pre-pinned LocationAddress. Implementations MUST place each pinned qubit at its requested address and MUST NOT use any address in pinned.values() for un-pinned qubits. None or empty preserves previous behavior. All values in pinned MUST be valid home positions for the architecture (i.e. present in arch_spec.home_sites); passing an out-of-arch address raises ValueError.

None

Returns:

Type Description
LocationAddress

A tuple of LocationAddress objects mapping logical qubit indices

...

to physical locations. Pinned IDs return their pinned address;

tuple[LocationAddress, ...]

un-pinned IDs return the heuristic's choice. Raises if no legal

tuple[LocationAddress, ...]

layout exists.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/heuristics/logical/layout.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def compute_layout(
    self,
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
    pinned: dict[int, LocationAddress] | None = None,
) -> tuple[LocationAddress, ...]:
    pinned = {} if pinned is None else pinned
    self._validate_pinned(all_qubits, pinned)
    edges: dict[tuple[int, int], float] = {}

    for control, target in chain.from_iterable(stages):
        n, m = min(control, target), max(control, target)
        edge_weight = edges.get((n, m), 0)
        edges[(n, m)] = edge_weight + 1

    return self._compute_layout_from_weighted_edges(all_qubits, edges, pinned)

LogicalLayoutHeuristicRecencyWeighted dataclass

LogicalLayoutHeuristicRecencyWeighted(
    arch_spec: ArchSpec = get_arch_spec(),
    layout_lookahead_layers: int | None = None,
    layout_decay_gamma: float = 0.85,
)

Bases: LogicalLayoutHeuristic


              flowchart TD
              bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristicRecencyWeighted[LogicalLayoutHeuristicRecencyWeighted]
              bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic[LogicalLayoutHeuristic]
              bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC[LayoutHeuristicABC]

                              bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic --> bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristicRecencyWeighted
                                bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC --> bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic
                



              click bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristicRecencyWeighted href "" "bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristicRecencyWeighted"
              click bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic href "" "bloqade.lanes.heuristics.logical.layout.LogicalLayoutHeuristic"
              click bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC href "" "bloqade.lanes.analysis.layout.analysis.LayoutHeuristicABC"
            

compute_layout

compute_layout(
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
    pinned: dict[int, LocationAddress] | None = None,
) -> tuple[LocationAddress, ...]

Compute the initial qubit layout from circuit stages.

Parameters:

Name Type Description Default
all_qubits tuple[int, ...]

Tuple of logical qubit indices to be mapped.

required
stages list[tuple[tuple[int, int], ...]]

List of circuit stages, where each stage is a tuple of (control, target) qubit pairs representing two-qubit gates.

required
pinned dict[int, LocationAddress] | None

Map from logical qubit ID to pre-pinned LocationAddress. Implementations MUST place each pinned qubit at its requested address and MUST NOT use any address in pinned.values() for un-pinned qubits. None or empty preserves previous behavior. All values in pinned MUST be valid home positions for the architecture (i.e. present in arch_spec.home_sites); passing an out-of-arch address raises ValueError.

None

Returns:

Type Description
LocationAddress

A tuple of LocationAddress objects mapping logical qubit indices

...

to physical locations. Pinned IDs return their pinned address;

tuple[LocationAddress, ...]

un-pinned IDs return the heuristic's choice. Raises if no legal

tuple[LocationAddress, ...]

layout exists.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/heuristics/logical/layout.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def compute_layout(
    self,
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
    pinned: dict[int, LocationAddress] | None = None,
) -> tuple[LocationAddress, ...]:
    pinned = {} if pinned is None else pinned
    self._validate_pinned(all_qubits, pinned)
    if self.layout_lookahead_layers is None:
        considered_layers = stages
    else:
        considered_layers = stages[: self.layout_lookahead_layers]

    edges: dict[tuple[int, int], float] = {}
    for depth, layer in enumerate(considered_layers):
        decay_weight = self.layout_decay_gamma**depth
        for control, target in layer:
            n, m = min(control, target), max(control, target)
            edge_weight = edges.get((n, m), 0.0)
            edges[(n, m)] = edge_weight + decay_weight

    return self._compute_layout_from_weighted_edges(all_qubits, edges, pinned)