Skip to content

Logical layout

LogicalLayoutHeuristic dataclass

LogicalLayoutHeuristic()

Bases: LayoutHeuristicABC

compute_layout

compute_layout(
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
) -> tuple[layout.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. For example: [ ((control1, target1), (control2, target2)), # stage 1 ((control3, target3),), # stage 2 ... ]

required

Returns:

Type Description
tuple[LocationAddress, ...]

A tuple of LocationAddress objects mapping logical qubit indices to physical locations.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/heuristics/logical_layout.py
84
85
86
87
88
89
90
91
92
93
94
95
96
def compute_layout(
    self,
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
) -> tuple[layout.LocationAddress, ...]:
    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)

LogicalLayoutHeuristicRecencyWeighted dataclass

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

Bases: LogicalLayoutHeuristic

compute_layout

compute_layout(
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
) -> tuple[layout.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. For example: [ ((control1, target1), (control2, target2)), # stage 1 ((control3, target3),), # stage 2 ... ]

required

Returns:

Type Description
tuple[LocationAddress, ...]

A tuple of LocationAddress objects mapping logical qubit indices to physical locations.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/heuristics/logical_layout.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def compute_layout(
    self,
    all_qubits: tuple[int, ...],
    stages: list[tuple[tuple[int, int], ...]],
) -> tuple[layout.LocationAddress, ...]:
    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)