Index
Move generators for the configuration search tree.
A MoveGenerator produces candidate move sets from a configuration node. Different implementations enable different search strategies — exhaustive enumeration, goal-directed search, greedy grid growing, etc.
All generators yield candidate frozenset[LaneAddress]. Validation (lane validity, collision checks, transposition table lookups) is performed by ConfigurationTree.apply_move_set and higher-level helpers such as ConfigurationTree.expand_node, so generators are free to over-generate — invalid candidates are filtered out when moves are applied to the tree.
BusContext
dataclass
BusContext(
move_type: MoveType,
bus_id: int,
direction: Direction,
arch_spec: ArchSpec,
pos_to_loc: dict[tuple[float, float], LocationAddress],
collision_srcs: frozenset[LocationAddress],
)
Pre-computed context for AOD grid construction on a single bus.
Encapsulates the position map, collision set, bus identity, and the
divide-and-conquer algorithm for building AOD-compatible rectangular
grids. Create one per (move_type, bus_id, direction) group via
:meth:from_tree.
The grid construction algorithm has two phases:
- Greedy init — O(n) sequential pass that forms initial clusters by greedily expanding rectangles one atom at a time.
- Merge — iterative passes that try to merge clusters. Clusters that don't participate in any merge are promoted to solved and removed from the active set, since merged clusters only grow and a cluster that can't merge now can never merge later.
build_aod_grids
build_aod_grids(
entries: dict[int, LaneAddress],
) -> list[frozenset[LaneAddress]]
Build AOD-compatible rectangular grids from desired next-hop lanes.
Two phases: 1. Greedy sequential pass to form initial clusters (O(n)). 2. Merge pass to combine clusters that the greedy ordering missed. Clusters that cannot merge are marked solved and removed from the active set so they don't slow down later rounds.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
from_tree
classmethod
from_tree(
tree: ConfigurationTree,
occupied: frozenset[LocationAddress],
move_type: MoveType,
bus_id: int,
direction: Direction,
) -> BusContext
Build a BusContext from a ConfigurationTree and occupied set.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
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 91 92 93 94 95 96 97 98 99 100 101 102 | |
greedy_init
greedy_init(
entries: dict[int, LaneAddress],
) -> list[Cluster]
Form initial clusters via greedy sequential expansion.
Processes atoms in order and greedily expands a rectangle. Atoms that don't fit start a new cluster in the next pass. Repeats until all atoms are assigned or individually invalid.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
is_valid_rect
is_valid_rect(xs: set[float], ys: set[float]) -> bool
Check if every position in the X * Y rectangle is a valid bus source with no collision.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
106 107 108 109 110 111 112 113 114 | |
lane_position
lane_position(lane: LaneAddress) -> tuple[float, float]
Get the physical (x, y) position of a lane's source.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
134 135 136 137 | |
merge_clusters
merge_clusters(clusters: list[Cluster]) -> list[Cluster]
Merge clusters until no more merges are possible.
Each pass lets every active cluster try to absorb compatible neighbours. Clusters that don't participate in any merge are promoted to solved and removed from the active set — merged clusters only grow, so a cluster that can't merge now will never be able to merge later.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
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 246 247 | |
rect_to_lanes
rect_to_lanes(
xs: set[float], ys: set[float]
) -> frozenset[LaneAddress]
Convert an X * Y rectangle into the corresponding lane set.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/aod_grouping.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
EntropyNode
Bases: Protocol
Minimal node metadata required by HeuristicMoveGenerator.
ExhaustiveMoveGenerator
dataclass
ExhaustiveMoveGenerator(
max_x_capacity: int | None = None,
max_y_capacity: int | None = None,
)
Enumerates all valid AOD grids from the configuration.
For each (move_type, bus_id, direction) group, finds all source positions, enumerates grid subsets within AOD capacity, and yields the full grid of lane addresses.
Pre-filters grids where an occupied source has an occupied destination (collision) as an optimization.
NOTE for Rust port: replace itertools.combinations with Gosper's hack for bitmask enumeration of exactly-k-set-bits subsets. This avoids iterating all 2^n masks when capacity is small. See #298.
max_x_capacity
class-attribute
instance-attribute
max_x_capacity: int | None = None
Maximum number of unique X positions the AOD can address.
max_y_capacity
class-attribute
instance-attribute
max_y_capacity: int | None = None
Maximum number of unique Y positions the AOD can address.
GreedyMoveGenerator
dataclass
GreedyMoveGenerator(target: dict[int, LocationAddress])
Greedy shortest-path move generator.
For each unresolved qubit, computes the shortest path to its target while routing around all other atoms (but not itself) and takes the first lane. Those first-step lanes are grouped by (move_type, bus_id, direction) and partitioned into AOD-compatible rectangular grids via BusContext.
target
instance-attribute
target: dict[int, LocationAddress]
Mapping of qubit ID to target location.
generate
generate(
node: ConfigurationNode, tree: ConfigurationTree
) -> Iterator[frozenset[LaneAddress]]
Yield candidate move sets.
Steps: 1. For each qubit, find shortest path to target routing around all other atoms (but not itself). 2. Take the first lane from each path. 3. Group by (move_type, bus_id, direction). 4. Build AOD-compatible rectangular grids per group.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/greedy.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 | |
HeuristicMoveGenerator
dataclass
HeuristicMoveGenerator(
scorer: CandidateScorer,
params: SearchParams,
search_nodes: dict[int, EntropyNode],
)
Generates ranked candidate movesets using entropy-weighted scoring.
Implements the MoveGenerator protocol. The traversal sets
search_nodes before the search loop begins so the generator
can read per-node entropy.
search_nodes
instance-attribute
search_nodes: dict[int, EntropyNode]
Mapping of id(ConfigurationNode) -> entropy metadata node.
generate
generate(
node: ConfigurationNode, tree: ConfigurationTree
) -> Iterator[frozenset[LaneAddress]]
Yield candidate movesets ranked by moveset score (descending).
Steps: 1. Get entropy from traversal metadata node. 2. Score all (qubit, move_type, bus_id, direction) pairs. 3. Per-qubit: keep top C triples. 4. Group by (move_type, bus_id, direction), collect positive-score qubits. 5. Resolve conflicts within each group (greedy by score). 6. Build moveset per group, score with score_moveset, sort descending.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/heuristic.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
MoveGenerator
Bases: Protocol
Interface for generating candidate move sets from a configuration.
Implementations yield candidate move sets. Validation and node creation are handled by ConfigurationTree.expand_node.
generate
generate(
node: ConfigurationNode, tree: ConfigurationTree
) -> Iterator[frozenset[LaneAddress]]
Yield candidate move sets from the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
ConfigurationNode
|
The configuration to generate moves from. |
required |
tree
|
ConfigurationTree
|
The configuration tree (provides arch_spec, path_finder). |
required |
Yields:
| Type | Description |
|---|---|
frozenset[LaneAddress]
|
frozenset[LaneAddress] — each candidate parallel move set. |
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/generators/base.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |