Preserve verify-only diagnostics and honor refinement objectives
This commit is contained in:
parent
f9ba5669dd
commit
2611085808
10 changed files with 188 additions and 29 deletions
|
|
@ -42,7 +42,7 @@ The fields below appear in constructor order. Use one layout unit for coordinate
|
||||||
| `RoutingResult.is_valid` and `outcome` | `is_valid` is true when the outcome is `completed`. Read `outcome` to distinguish success, a failed geometry check (`colliding`), a path that stopped short (`partial`), or an empty path (`unroutable`). |
|
| `RoutingResult.is_valid` and `outcome` | `is_valid` is true when the outcome is `completed`. Read `outcome` to distinguish success, a failed geometry check (`colliding`), a path that stopped short (`partial`), or an empty path (`unroutable`). |
|
||||||
| `RoutingResult.path` | Ordered path components from the source to the last reached state. An unroutable result has an empty path. |
|
| `RoutingResult.path` | Ordered path components from the source to the last reached state. An unroutable result has an empty path. |
|
||||||
| `RoutingResult.reached_target` | Whether the path reached the target position and heading. With heading inference, the check uses the chosen heading. Read `is_valid` for the result of geometry verification. |
|
| `RoutingResult.reached_target` | Whether the path reached the target position and heading. With heading inference, the check uses the chosen heading. Read `is_valid` for the result of geometry verification. |
|
||||||
| `RoutingResult.report` | `total_length` in layout units plus static, dynamic, and self-collision counts. `out_of_bounds` flags geometry outside the board. `discontinuous` flags missing or point-only joins, including at terminal faces. `invalid_geometry` flags invalid or empty physical polygons. |
|
| `RoutingResult.report` | `total_length` in layout units plus static, dynamic, and self-collision counts. `out_of_bounds` flags geometry outside the board. `discontinuous` flags missing or point-only joins, including at terminal faces. `invalid_geometry` flags invalid or empty physical polygons. `seed_error` identifies a supplied bend that cannot carry the net's width. |
|
||||||
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons and the sequence of moves, respectively. Check validity before exporting polygons or using them as keepouts. |
|
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons and the sequence of moves, respectively. Check validity before exporting polygons or using them as keepouts. |
|
||||||
| `RoutingRunResult.automatic` | In automatic mode, the selected planner, verified IDs, stage history, and any capacity or port-conflict bound. `None` for explicit modes. |
|
| `RoutingRunResult.automatic` | In automatic mode, the selected planner, verified IDs, stage history, and any capacity or port-conflict bound. `None` for explicit modes. |
|
||||||
| `RoutingRunResult.topology` and `metrics` | Corridor counts and seed work when reported by the selected worker, plus work counters across the run. |
|
| `RoutingRunResult.topology` and `metrics` | Corridor counts and seed work when reported by the selected worker, plus work counters across the run. |
|
||||||
|
|
@ -66,7 +66,7 @@ To read a route's polygons and write them to a test file, follow the [geometry e
|
||||||
|
|
||||||
| Field | Default | Effect |
|
| Field | Default | Effect |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `node_limit` | `1_000_000` | Nonnegative integer per-search expansion ceiling. Automatic uses smaller budgets for its initial stages. Zero skips search and corridor preparation and allows verification of supplied seeds. |
|
| `node_limit` | `1_000_000` | Nonnegative integer per-search expansion ceiling. Automatic uses smaller budgets for its initial stages. Zero skips search and corridor preparation and verifies supplied seeds in one pass if congestion iterations are enabled. Disable refinement to inspect the unchanged seed geometry. |
|
||||||
| `min_straight_length` | `5.0` | Finite, nonnegative minimum length for regular forward moves in lattice search. |
|
| `min_straight_length` | `5.0` | Finite, nonnegative minimum length for regular forward moves in lattice search. |
|
||||||
| `max_straight_length` | `2000.0` | Finite, positive maximum distance for the forward scan in lattice search. |
|
| `max_straight_length` | `2000.0` | Finite, positive maximum distance for the forward scan in lattice search. |
|
||||||
| `greedy_h_weight` | `1.5` | Finite, nonnegative weight on the estimated cost still needed to reach the target. Lower values give more influence to the cost of the path so far. |
|
| `greedy_h_weight` | `1.5` | Finite, nonnegative weight on the estimated cost still needed to reach the target. Lower values give more influence to the cost of the path so far. |
|
||||||
|
|
@ -117,7 +117,7 @@ Increase the iteration limit when later reroutes might resolve conflicts. Adjust
|
||||||
| Field | Default | Effect |
|
| Field | Default | Effect |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `enabled` | `True` | Try geometric improvements after routing. |
|
| `enabled` | `True` | Try geometric improvements after routing. |
|
||||||
| `objective` | `None` | Use another `ObjectiveWeights` value for refinement, or reuse the search objective. |
|
| `objective` | `None` | Use another `ObjectiveWeights` value for refinement, or reuse the search objective. When set, automatic mode uses this objective to compare a verified refinement with its incumbent on the same net set. `automatic_length_weights` still applies to planner selection. |
|
||||||
| `max_windows_per_net` | `4` | Maximum number of path sections to try replacing per net across improvement rounds. Use `1` for a shorter pass or `None` to remove this limit. |
|
| `max_windows_per_net` | `4` | Maximum number of path sections to try replacing per net across improvement rounds. Use `1` for a shorter pass or `None` to remove this limit. |
|
||||||
|
|
||||||
### TopologyOptions
|
### TopologyOptions
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class RoutingReport:
|
||||||
out_of_bounds: bool = False
|
out_of_bounds: bool = False
|
||||||
discontinuous: bool = False
|
discontinuous: bool = False
|
||||||
invalid_geometry: bool = False
|
invalid_geometry: bool = False
|
||||||
|
seed_error: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def intrinsic_collision_count(self) -> int:
|
def intrinsic_collision_count(self) -> int:
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,9 @@ class _AutomaticRun:
|
||||||
return run
|
return run
|
||||||
|
|
||||||
def _selection_cost(self, result: RoutingResult) -> float:
|
def _selection_cost(self, result: RoutingResult) -> float:
|
||||||
|
if not self.options.search.node_limit:
|
||||||
|
# Verification-only runs have a single candidate to report.
|
||||||
|
return 0.0
|
||||||
if self.length_weights is not None:
|
if self.length_weights is not None:
|
||||||
return weighted_path_length(result.path, self.length_weights)
|
return weighted_path_length(result.path, self.length_weights)
|
||||||
if self.evaluator is None:
|
if self.evaluator is None:
|
||||||
|
|
@ -581,10 +584,10 @@ class _AutomaticRun:
|
||||||
)
|
)
|
||||||
trials.append(self._trial(run, stage))
|
trials.append(self._trial(run, stage))
|
||||||
|
|
||||||
def _refine(self, trials: list[Trial]) -> None:
|
def _refine(self, trials: list[Trial]) -> Trial | None:
|
||||||
best = _best_trial(trials)
|
best = _best_trial(trials)
|
||||||
if not self.options.refinement.enabled or not best.valid_costs:
|
if not self.options.refinement.enabled or not best.valid_costs:
|
||||||
return
|
return None
|
||||||
has_unresolved_paths = any(result.path and not result.is_valid for result in best.run.results_by_net.values())
|
has_unresolved_paths = any(result.path and not result.is_valid for result in best.run.results_by_net.values())
|
||||||
run, stage = self._seeded_attempt(
|
run, stage = self._seeded_attempt(
|
||||||
self._seeded_problem(best, include_unresolved=has_unresolved_paths),
|
self._seeded_problem(best, include_unresolved=has_unresolved_paths),
|
||||||
|
|
@ -596,9 +599,21 @@ class _AutomaticRun:
|
||||||
)
|
)
|
||||||
# Any carried-over result without a replayed seed has no path to recheck.
|
# Any carried-over result without a replayed seed has no path to recheck.
|
||||||
results = {**best.run.results_by_net, **run.results_by_net}
|
results = {**best.run.results_by_net, **run.results_by_net}
|
||||||
refined = self._trial(replace(run, results_by_net=results), stage)
|
refined = self._trial(replace(run, results_by_net=results), stage).as_replacement_for(best)
|
||||||
# Only a whole verified replacement of the incumbent can win.
|
# Only a whole verified replacement of the incumbent can win.
|
||||||
trials.append(refined.as_replacement_for(best))
|
trials.append(refined)
|
||||||
|
objective = self.options.refinement.objective
|
||||||
|
if objective is None:
|
||||||
|
return None
|
||||||
|
if not refined.selectable:
|
||||||
|
return best
|
||||||
|
evaluator = build_native_cost_evaluator(self.problem, objective)
|
||||||
|
|
||||||
|
def cost(trial: Trial) -> float:
|
||||||
|
paths = (trial.run.results_by_net[net_id].path for net_id in trial.valid_costs)
|
||||||
|
return sum(evaluator.path_cost(path[0].start_port, path) for path in paths)
|
||||||
|
|
||||||
|
return refined if cost(refined) < cost(best) else best
|
||||||
|
|
||||||
def execute(self) -> RoutingRunResult:
|
def execute(self) -> RoutingRunResult:
|
||||||
started = perf_counter()
|
started = perf_counter()
|
||||||
|
|
@ -609,6 +624,7 @@ class _AutomaticRun:
|
||||||
rejections = ()
|
rejections = ()
|
||||||
target = len(self.problem.nets)
|
target = len(self.problem.nets)
|
||||||
trials: list[Trial] = []
|
trials: list[Trial] = []
|
||||||
|
refinement_choice = None
|
||||||
if not self.problem.nets or options.search.node_limit <= 0 or options.congestion.max_iterations <= 0:
|
if not self.problem.nets or options.search.node_limit <= 0 or options.congestion.max_iterations <= 0:
|
||||||
self._lattice_fallback(trials, options, "No automatic search requested")
|
self._lattice_fallback(trials, options, "No automatic search requested")
|
||||||
elif (
|
elif (
|
||||||
|
|
@ -634,8 +650,8 @@ class _AutomaticRun:
|
||||||
else:
|
else:
|
||||||
worker = replace(options, refinement=replace(options.refinement, enabled=False))
|
worker = replace(options, refinement=replace(options.refinement, enabled=False))
|
||||||
self._lattice_fallback(trials, worker, "Constrained triangulation is unavailable")
|
self._lattice_fallback(trials, worker, "Constrained triangulation is unavailable")
|
||||||
self._refine(trials)
|
refinement_choice = self._refine(trials)
|
||||||
best = _best_trial(trials)
|
best = refinement_choice or _best_trial(trials)
|
||||||
metrics = _sum_route_metrics(self.metrics)
|
metrics = _sum_route_metrics(self.metrics)
|
||||||
report = AutomaticRoutingReport(
|
report = AutomaticRoutingReport(
|
||||||
tuple(trial.stage for trial in trials),
|
tuple(trial.stage for trial in trials),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from contextlib import contextmanager, nullcontext
|
from contextlib import contextmanager, nullcontext
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field, replace
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from shapely import shortest_line
|
from shapely import shortest_line
|
||||||
|
|
@ -36,7 +36,7 @@ from inire.router._congestion_policy import (
|
||||||
from inire.router._pair_local import search_pair_candidate
|
from inire.router._pair_local import search_pair_candidate
|
||||||
from inire.router._route_traces import conflict_trace_entry, iteration_trace_entry, net_attempt_trace
|
from inire.router._route_traces import conflict_trace_entry, iteration_trace_entry, net_attempt_trace
|
||||||
from inire.router._search import incumbent_guidance, path_guidance, route_astar
|
from inire.router._search import incumbent_guidance, path_guidance, route_astar
|
||||||
from inire.router._seed_materialization import materialize_path_seed
|
from inire.router._seed_materialization import materialize_path_seed, seed_width_error
|
||||||
from inire.router.refiner import PathRefiner
|
from inire.router.refiner import PathRefiner
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -70,6 +70,7 @@ class _RoutingState:
|
||||||
recent_attempt_work: dict[str, int]
|
recent_attempt_work: dict[str, int]
|
||||||
pre_pair_candidate: _PrePairCandidate | None
|
pre_pair_candidate: _PrePairCandidate | None
|
||||||
corridors: dict[str, tuple[Corridor, ...]] = field(default_factory=dict)
|
corridors: dict[str, tuple[Corridor, ...]] = field(default_factory=dict)
|
||||||
|
seed_errors: dict[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def best_conflict_edges(self) -> int | None:
|
def best_conflict_edges(self) -> int | None:
|
||||||
|
|
@ -289,7 +290,6 @@ class PathFinder:
|
||||||
def _prepare_state(self, corridors: dict[str, tuple[Corridor, ...]] | None = None) -> _RoutingState:
|
def _prepare_state(self, corridors: dict[str, tuple[Corridor, ...]] | None = None) -> _RoutingState:
|
||||||
problem = self.context.problem
|
problem = self.context.problem
|
||||||
congestion = self.context.options.congestion
|
congestion = self.context.options.congestion
|
||||||
initial_paths = self._materialize_problem_initial_paths()
|
|
||||||
net_specs = {net.net_id: net for net in problem.nets}
|
net_specs = {net.net_id: net for net in problem.nets}
|
||||||
num_nets = len(net_specs)
|
num_nets = len(net_specs)
|
||||||
state = _RoutingState(
|
state = _RoutingState(
|
||||||
|
|
@ -299,7 +299,7 @@ class PathFinder:
|
||||||
needs_self_collision_check=set(),
|
needs_self_collision_check=set(),
|
||||||
start_time=time.monotonic(),
|
start_time=time.monotonic(),
|
||||||
timeout_s=max(60.0, 10.0 * num_nets * congestion.max_iterations),
|
timeout_s=max(60.0, 10.0 * num_nets * congestion.max_iterations),
|
||||||
initial_paths=initial_paths,
|
initial_paths=None,
|
||||||
accumulated_expanded_nodes=[],
|
accumulated_expanded_nodes=[],
|
||||||
best_results={},
|
best_results={},
|
||||||
best_is_installed=False,
|
best_is_installed=False,
|
||||||
|
|
@ -309,6 +309,7 @@ class PathFinder:
|
||||||
recent_attempt_work={},
|
recent_attempt_work={},
|
||||||
pre_pair_candidate=None,
|
pre_pair_candidate=None,
|
||||||
)
|
)
|
||||||
|
self._materialize_problem_initial_paths(state)
|
||||||
if congestion.max_iterations <= 0 or (self.context.options.search.node_limit <= 0 and self.context.options.topology.mode != "bundle"):
|
if congestion.max_iterations <= 0 or (self.context.options.search.node_limit <= 0 and self.context.options.topology.mode != "bundle"):
|
||||||
return state
|
return state
|
||||||
self._prepare_topology(state, corridors)
|
self._prepare_topology(state, corridors)
|
||||||
|
|
@ -325,20 +326,19 @@ class PathFinder:
|
||||||
state.results[net_id] = RoutingResult(net_id, path, reached_target=True, report=report)
|
state.results[net_id] = RoutingResult(net_id, path, reached_target=True, report=report)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def _materialize_problem_initial_paths(self) -> dict[str, tuple[ComponentResult, ...]] | None:
|
def _materialize_problem_initial_paths(self, state: _RoutingState) -> None:
|
||||||
if not self.context.problem.initial_paths:
|
if not self.context.problem.initial_paths:
|
||||||
return None
|
return
|
||||||
|
|
||||||
search = self.context.options.search
|
search = self.context.options.search
|
||||||
net_specs = {net.net_id: net for net in self.context.problem.nets}
|
|
||||||
initial_paths: dict[str, tuple[ComponentResult, ...]] = {}
|
initial_paths: dict[str, tuple[ComponentResult, ...]] = {}
|
||||||
for net_id, seed in self.context.problem.initial_paths.items():
|
for net_id, seed in self.context.problem.initial_paths.items():
|
||||||
if net_id not in net_specs:
|
if net_id not in state.net_specs:
|
||||||
raise ValueError(f"Initial path provided for unknown net: {net_id}")
|
raise ValueError(f"Initial path provided for unknown net: {net_id}")
|
||||||
error = search.seed_geometry_error(seed)
|
error = search.seed_geometry_error(seed)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
raise ValueError(f"Initial path for {net_id!r} {error}")
|
raise ValueError(f"Initial path for {net_id!r} {error}")
|
||||||
net = net_specs[net_id]
|
net = state.net_specs[net_id]
|
||||||
path = materialize_path_seed(
|
path = materialize_path_seed(
|
||||||
seed,
|
seed,
|
||||||
start=net.start,
|
start=net.start,
|
||||||
|
|
@ -346,9 +346,11 @@ class PathFinder:
|
||||||
search=search,
|
search=search,
|
||||||
clearance=self.context.cost_evaluator.collision_engine.clearance,
|
clearance=self.context.cost_evaluator.collision_engine.clearance,
|
||||||
)
|
)
|
||||||
if path is not None:
|
if path is None:
|
||||||
|
state.seed_errors[net_id] = f"Initial path for {net_id!r} {seed_width_error(seed, net.width)}"
|
||||||
|
elif path:
|
||||||
initial_paths[net_id] = path
|
initial_paths[net_id] = path
|
||||||
return initial_paths or None
|
state.initial_paths = initial_paths or None
|
||||||
|
|
||||||
def _replace_installed_paths(
|
def _replace_installed_paths(
|
||||||
self, state: _RoutingState, results: dict[str, RoutingResult], *, net_ids: Sequence[str] | None = None
|
self, state: _RoutingState, results: dict[str, RoutingResult], *, net_ids: Sequence[str] | None = None
|
||||||
|
|
@ -809,6 +811,8 @@ class PathFinder:
|
||||||
return review
|
return review
|
||||||
|
|
||||||
def _run_pair_local_search(self, state: _RoutingState, review: _IterationReview) -> None:
|
def _run_pair_local_search(self, state: _RoutingState, review: _IterationReview) -> None:
|
||||||
|
if not self.context.options.search.node_limit:
|
||||||
|
return
|
||||||
targets = self._collect_pair_local_targets(state, state.results, review)
|
targets = self._collect_pair_local_targets(state, state.results, review)
|
||||||
if not targets:
|
if not targets:
|
||||||
return
|
return
|
||||||
|
|
@ -840,6 +844,8 @@ class PathFinder:
|
||||||
if iteration == 0 and initial_path is not None and (initial_arrives or search.node_limit <= 0):
|
if iteration == 0 and initial_path is not None and (initial_arrives or search.node_limit <= 0):
|
||||||
self.metrics.total_warm_start_paths_used += 1
|
self.metrics.total_warm_start_paths_used += 1
|
||||||
path: Sequence[ComponentResult] | None = initial_path
|
path: Sequence[ComponentResult] | None = initial_path
|
||||||
|
elif search.node_limit == 0:
|
||||||
|
path = None
|
||||||
else:
|
else:
|
||||||
coll_model, _ = resolve_bend_geometry(search)
|
coll_model, _ = resolve_bend_geometry(search)
|
||||||
skip_congestion = False
|
skip_congestion = False
|
||||||
|
|
@ -1027,7 +1033,8 @@ class PathFinder:
|
||||||
) -> bool:
|
) -> bool:
|
||||||
congestion = self.context.options.congestion
|
congestion = self.context.options.congestion
|
||||||
reroute_net_ids = set(state.ordered_net_ids)
|
reroute_net_ids = set(state.ordered_net_ids)
|
||||||
for iteration in range(congestion.max_iterations):
|
rounds = congestion.max_iterations if self.context.options.search.node_limit else min(1, congestion.max_iterations)
|
||||||
|
for iteration in range(rounds):
|
||||||
review = self._run_iteration(
|
review = self._run_iteration(
|
||||||
state,
|
state,
|
||||||
iteration,
|
iteration,
|
||||||
|
|
@ -1060,13 +1067,21 @@ class PathFinder:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _refine_results(self, state: _RoutingState) -> None:
|
def _refine_results(self, state: _RoutingState) -> None:
|
||||||
if not self.context.options.refinement.enabled or not state.results:
|
options = self.context.options
|
||||||
|
if not options.refinement.enabled or not state.results:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
proximity_ready = bool(options.search.node_limit)
|
||||||
for net_id in state.ordered_net_ids:
|
for net_id in state.ordered_net_ids:
|
||||||
result = state.results.get(net_id)
|
result = state.results.get(net_id)
|
||||||
if not result or not result.is_valid or not self.refiner.has_refinement_bends(result.path):
|
if not result or not result.is_valid or not self.refiner.has_refinement_bends(result.path):
|
||||||
continue
|
continue
|
||||||
|
if not proximity_ready:
|
||||||
|
evaluator = self.context.cost_evaluator
|
||||||
|
weights = options.refinement.objective or options.objective
|
||||||
|
if evaluator.danger_map is not None and weights.danger_weight:
|
||||||
|
evaluator.danger_map.precompute(self.context.problem.static_obstacles)
|
||||||
|
proximity_ready = True
|
||||||
net = state.net_specs[net_id]
|
net = state.net_specs[net_id]
|
||||||
self.metrics.total_refine_path_calls += 1
|
self.metrics.total_refine_path_calls += 1
|
||||||
self.context.cost_evaluator.collision_engine.remove_path(net_id)
|
self.context.cost_evaluator.collision_engine.remove_path(net_id)
|
||||||
|
|
@ -1087,8 +1102,12 @@ class PathFinder:
|
||||||
details_by_net: dict[str, PathVerificationDetail] = {}
|
details_by_net: dict[str, PathVerificationDetail] = {}
|
||||||
for net in self.context.problem.nets:
|
for net in self.context.problem.nets:
|
||||||
result = state.results.get(net.net_id)
|
result = state.results.get(net.net_id)
|
||||||
|
seed_error = state.seed_errors.get(net.net_id) if self.context.options.congestion.max_iterations else None
|
||||||
if not result or not result.path:
|
if not result or not result.path:
|
||||||
final_results[net.net_id] = RoutingResult(net_id=net.net_id, path=(), reached_target=False)
|
final_results[net.net_id] = RoutingResult(
|
||||||
|
net_id=net.net_id, path=(), reached_target=False,
|
||||||
|
report=RoutingReport(invalid_geometry=seed_error is not None, seed_error=seed_error),
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
capture_conflicts = diagnostics.capture_conflict_trace or (diagnostics.capture_frontier_trace and result.reached_target)
|
capture_conflicts = diagnostics.capture_conflict_trace or (diagnostics.capture_frontier_trace and result.reached_target)
|
||||||
detail = self.context.cost_evaluator.collision_engine.verify_path_details(
|
detail = self.context.cost_evaluator.collision_engine.verify_path_details(
|
||||||
|
|
@ -1102,7 +1121,7 @@ class PathFinder:
|
||||||
net_id=net.net_id,
|
net_id=net.net_id,
|
||||||
path=result.path,
|
path=result.path,
|
||||||
reached_target=result.reached_target,
|
reached_target=result.reached_target,
|
||||||
report=detail.report,
|
report=detail.report if seed_error is None else replace(detail.report, seed_error=seed_error),
|
||||||
)
|
)
|
||||||
if diagnostics.capture_conflict_trace:
|
if diagnostics.capture_conflict_trace:
|
||||||
review = review_verified_results(final_results, details_by_net)
|
review = review_verified_results(final_results, details_by_net)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,13 @@ def seed_move(segment: PathSegmentSeed) -> tuple[MoveKind, tuple]:
|
||||||
raise TypeError(f"Unsupported seed segment: {type(segment)!r}")
|
raise TypeError(f"Unsupported seed segment: {type(segment)!r}")
|
||||||
|
|
||||||
|
|
||||||
|
def seed_width_error(seed: PathSeed, net_width: float) -> str | None:
|
||||||
|
for index, segment in enumerate(seed.segments, start=1):
|
||||||
|
if isinstance(segment, (Bend90Seed, SBendSeed)) and not bend_fits_width(segment.radius, net_width):
|
||||||
|
return f"segment {index} ({type(segment).__name__}) needs radius at least {net_width / 2:g}, got {segment.radius:g}"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def materialize_path_seed(
|
def materialize_path_seed(
|
||||||
seed: PathSeed,
|
seed: PathSeed,
|
||||||
*,
|
*,
|
||||||
|
|
@ -31,7 +38,7 @@ def materialize_path_seed(
|
||||||
search: SearchOptions,
|
search: SearchOptions,
|
||||||
clearance: float,
|
clearance: float,
|
||||||
) -> tuple[ComponentResult, ...] | None:
|
) -> tuple[ComponentResult, ...] | None:
|
||||||
if any(isinstance(segment, (Bend90Seed, SBendSeed)) and not bend_fits_width(segment.radius, net_width) for segment in seed.segments):
|
if seed_width_error(seed, net_width) is not None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
path: list[ComponentResult] = []
|
path: list[ComponentResult] = []
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ def build_routing_stack(problem: RoutingProblem, options: RoutingOptions) -> Rou
|
||||||
|
|
||||||
danger_map = DangerMap(bounds=problem.bounds)
|
danger_map = DangerMap(bounds=problem.bounds)
|
||||||
refinement = options.refinement
|
refinement = options.refinement
|
||||||
if options.congestion.max_iterations > 0 and (
|
if options.search.node_limit > 0 and options.congestion.max_iterations > 0 and (
|
||||||
options.objective.danger_weight or (refinement.enabled and refinement.objective is not None and refinement.objective.danger_weight)
|
options.objective.danger_weight or (refinement.enabled and refinement.objective is not None and refinement.objective.danger_weight)
|
||||||
):
|
):
|
||||||
danger_map.precompute(list(problem.static_obstacles))
|
danger_map.precompute(problem.static_obstacles)
|
||||||
|
|
||||||
evaluator = CostEvaluator.from_objective(
|
evaluator = CostEvaluator.from_objective(
|
||||||
world,
|
world,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from scipy.spatial import cKDTree
|
||||||
from shapely.geometry import box
|
from shapely.geometry import box
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterable, Iterator
|
||||||
|
|
||||||
from shapely.geometry import LinearRing, Polygon
|
from shapely.geometry import LinearRing, Polygon
|
||||||
from inire.router._astar_types import AStarMetrics
|
from inire.router._astar_types import AStarMetrics
|
||||||
|
|
@ -94,7 +94,7 @@ class DangerMap:
|
||||||
self._cost_cache: OrderedDict[tuple[int, int], float] = OrderedDict()
|
self._cost_cache: OrderedDict[tuple[int, int], float] = OrderedDict()
|
||||||
self.metrics: AStarMetrics | None = None
|
self.metrics: AStarMetrics | None = None
|
||||||
|
|
||||||
def precompute(self, obstacles: list[Polygon]) -> None:
|
def precompute(self, obstacles: Iterable[Polygon]) -> None:
|
||||||
"""
|
"""
|
||||||
Pre-compute the proximity tree by sampling obstacle boundaries.
|
Pre-compute the proximity tree by sampling obstacle boundaries.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -512,6 +512,76 @@ def test_zero_search_budget_verifies_seeds_without_triangulation(mode, monkeypat
|
||||||
assert run.metrics.nodes_expanded == 0
|
assert run.metrics.nodes_expanded == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("mode", ["automatic", "off", "guide", "seed"])
|
||||||
|
@pytest.mark.parametrize("rounds", [1, 10])
|
||||||
|
def test_verify_only_retains_colliding_seeds_and_final_trace(mode, rounds, monkeypatch) -> None:
|
||||||
|
nets = (
|
||||||
|
NetSpec("horizontal", Port(10, 50, 0), Port(90, 50, 0)),
|
||||||
|
NetSpec("vertical", Port(50, 10, 90), Port(50, 90, 90)),
|
||||||
|
NetSpec("partial", Port(10, 80, 0), Port(90, 80, 0)),
|
||||||
|
NetSpec("unseeded", Port(10, 90, 0), Port(90, 90, 0)),
|
||||||
|
)
|
||||||
|
seeds = {net.net_id: PathSeed((StraightSeed(80),)) for net in nets[:2]}
|
||||||
|
seeds["partial"] = PathSeed((StraightSeed(40),))
|
||||||
|
problem = RoutingProblem((0, 0, 100, 100), nets, (box(5, 5, 8, 8),), initial_paths=seeds)
|
||||||
|
options = RoutingOptions(
|
||||||
|
search=SearchOptions(node_limit=0),
|
||||||
|
congestion=CongestionOptions(max_iterations=rounds),
|
||||||
|
diagnostics=DiagnosticsOptions(capture_conflict_trace=True),
|
||||||
|
refinement=RefinementOptions(enabled=False),
|
||||||
|
topology=TopologyOptions(mode=mode),
|
||||||
|
)
|
||||||
|
|
||||||
|
def fail_on_proximity(*_args):
|
||||||
|
pytest.fail("Geometry-only verification built a proximity map")
|
||||||
|
|
||||||
|
monkeypatch.setattr(DangerMap, "precompute", fail_on_proximity)
|
||||||
|
run = route(problem, options=options)
|
||||||
|
|
||||||
|
for net in nets[:2]:
|
||||||
|
result = run.results_by_net[net.net_id]
|
||||||
|
assert result.as_seed() == seeds[net.net_id]
|
||||||
|
assert result.outcome == "colliding"
|
||||||
|
assert result.report.dynamic_collision_count == 1
|
||||||
|
assert run.results_by_net["partial"].outcome == "partial"
|
||||||
|
assert run.results_by_net["unseeded"].outcome == "unroutable"
|
||||||
|
assert run.conflict_trace[-1].conflict_edges == (("horizontal", "vertical"),)
|
||||||
|
assert run.metrics.nodes_expanded == 0
|
||||||
|
assert run.metrics.route_iterations == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("mode", ["automatic", "off", "guide", "seed"])
|
||||||
|
@pytest.mark.parametrize("move", [Bend90Seed(10, "CCW"), SBendSeed(6, 10)])
|
||||||
|
def test_verify_only_reports_width_incompatible_seed_segments(mode, move) -> None:
|
||||||
|
net = NetSpec("wide", Port(20, 30, 0), Port(30, 40, 90), width=30)
|
||||||
|
peer = NetSpec("peer", Port(20, 80, 0), Port(70, 80, 0))
|
||||||
|
seeds = {"wide": PathSeed((move,)), "peer": PathSeed((StraightSeed(50),))}
|
||||||
|
problem = RoutingProblem((0, 0, 100, 100), (net, peer), initial_paths=seeds)
|
||||||
|
options = RoutingOptions(
|
||||||
|
search=SearchOptions(node_limit=0, bend_radii=(10,), sbend_radii=(10,)),
|
||||||
|
topology=TopologyOptions(mode=mode),
|
||||||
|
)
|
||||||
|
|
||||||
|
results = route(problem, options=options).results_by_net
|
||||||
|
|
||||||
|
assert results["peer"].is_valid
|
||||||
|
report = results["wide"].report
|
||||||
|
assert report.invalid_geometry
|
||||||
|
assert report.seed_error == f"Initial path for 'wide' segment 1 ({type(move).__name__}) needs radius at least 15, got 10"
|
||||||
|
|
||||||
|
|
||||||
|
def test_active_search_can_recover_from_width_incompatible_seed() -> None:
|
||||||
|
net = NetSpec("wide", Port(20, 30, 0), Port(70, 30, 0), width=30)
|
||||||
|
problem = RoutingProblem((0, 0, 100, 100), (net,), initial_paths={"wide": PathSeed((Bend90Seed(10, "CCW"),))})
|
||||||
|
options = RoutingOptions(search=SearchOptions(node_limit=10, bend_radii=(10,)), topology=TopologyOptions(mode="off"))
|
||||||
|
|
||||||
|
result = route(problem, options=options).results_by_net["wide"]
|
||||||
|
|
||||||
|
assert result.is_valid
|
||||||
|
assert result.report.seed_error is not None
|
||||||
|
assert result.as_seed() == PathSeed((StraightSeed(50),))
|
||||||
|
|
||||||
|
|
||||||
def test_automatic_falls_back_to_lattice_when_corridor_search_is_unavailable(monkeypatch) -> None:
|
def test_automatic_falls_back_to_lattice_when_corridor_search_is_unavailable(monkeypatch) -> None:
|
||||||
monkeypatch.delattr(shapely, "constrained_delaunay_triangles", raising=False)
|
monkeypatch.delattr(shapely, "constrained_delaunay_triangles", raising=False)
|
||||||
net = NetSpec("line", Port(10, 50, 0), Port(90, 50, 0))
|
net = NetSpec("line", Port(10, 50, 0), Port(90, 50, 0))
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,50 @@ def test_automatic_refinement_rechecks_retained_partial_paths() -> None:
|
||||||
assert traced.conflicting_net_ids == ("foldback",)
|
assert traced.conflicting_net_ids == ("foldback",)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("weights", [None, (0, 0, 0)])
|
||||||
|
def test_automatic_selects_refinement_using_its_explicit_objective(weights) -> None:
|
||||||
|
problem = _seeded_foldback()
|
||||||
|
lattice_options = replace(
|
||||||
|
_REFINEMENT_OPTIONS,
|
||||||
|
search=replace(_REFINEMENT_OPTIONS.search, node_limit=100),
|
||||||
|
objective=ObjectiveWeights(0, 0, 0, 0),
|
||||||
|
refinement=RefinementOptions(objective=ObjectiveWeights(danger_weight=0)),
|
||||||
|
)
|
||||||
|
automatic_options = replace(
|
||||||
|
lattice_options, topology=TopologyOptions(mode="automatic", automatic_length_weights=weights),
|
||||||
|
)
|
||||||
|
expected = route(problem, options=lattice_options).results_by_net["foldback"]
|
||||||
|
run = route(problem, options=automatic_options)
|
||||||
|
actual = run.results_by_net["foldback"]
|
||||||
|
|
||||||
|
assert actual.is_valid
|
||||||
|
assert len(actual.path) == 9
|
||||||
|
assert actual.as_seed() == expected.as_seed()
|
||||||
|
assert run.automatic.stages[run.automatic.selected_stage].operation == "refine"
|
||||||
|
|
||||||
|
|
||||||
|
def test_seeded_refinement_builds_proximity_map_at_zero_search_budget(monkeypatch) -> None:
|
||||||
|
problem = replace(_seeded_foldback(), static_obstacles=(box(0, 0, 10, 10),))
|
||||||
|
options = replace(
|
||||||
|
_REFINEMENT_OPTIONS,
|
||||||
|
search=replace(_REFINEMENT_OPTIONS.search, node_limit=0),
|
||||||
|
refinement=RefinementOptions(objective=ObjectiveWeights()),
|
||||||
|
)
|
||||||
|
calls = []
|
||||||
|
precompute = DangerMap.precompute
|
||||||
|
|
||||||
|
def track(self, obstacles):
|
||||||
|
calls.append(tuple(obstacles))
|
||||||
|
precompute(self, obstacles)
|
||||||
|
|
||||||
|
monkeypatch.setattr(DangerMap, "precompute", track)
|
||||||
|
run = route(problem, options=options)
|
||||||
|
|
||||||
|
assert run.results_by_net["foldback"].is_valid
|
||||||
|
assert run.metrics.refinement_candidates_accepted > 0
|
||||||
|
assert calls == [problem.static_obstacles]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ["automatic", "off"])
|
@pytest.mark.parametrize("mode", ["automatic", "off"])
|
||||||
def test_refinement_preserves_custom_bend_geometry_on_seed_replay(mode) -> None:
|
def test_refinement_preserves_custom_bend_geometry_on_seed_replay(mode) -> None:
|
||||||
outline = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
outline = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ Implemented items 1, 2, and 17 cover missing joins, extra line or point contact
|
||||||
|
|
||||||
Implemented items 3, 6, and 21 retain constructive planning for unused custom outlines, reject unsupported search and congestion settings, and match custom S-bend widths consistently in search and replay.
|
Implemented items 3, 6, and 21 retain constructive planning for unused custom outlines, reject unsupported search and congestion settings, and match custom S-bend widths consistently in search and replay.
|
||||||
|
|
||||||
|
Implemented items 11, 13, and 30 preserve replay diagnostics across all four modes, report the segment of a width-incompatible seed, skip proximity work in geometry-only runs, and use explicit refinement weights for automatic refinement selection.
|
||||||
|
|
||||||
| Batch | Work | Acceptance gate |
|
| Batch | Work | Acceptance gate |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Physical verification | 1, 2, 17, 23, and 38 | Reject the faulty geometry and keep legal joins valid in search and seed replay. Check circular bend accuracy, folded-route spacing, and isolation between different nets. |
|
| Physical verification | 1, 2, 17, 23, and 38 | Reject the faulty geometry and keep legal joins valid in search and seed replay. Check circular bend accuracy, folded-route spacing, and isolation between different nets. |
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue