Support whole custom S-bend outlines and recover routing detours

This commit is contained in:
Jan Petykiewicz 2026-11-28 10:57:01 -08:00
commit 3d7fc3a705

View file

@ -157,8 +157,11 @@ class _AutomaticRun:
with self._time("verify", planner=stage.planner, mode=stage.mode, policy=stage.policy):
return _trial(run, stage, score=self._selection_cost)
def _seeded_problem(self, trial: Trial) -> RoutingProblem:
seeds = {net_id: trial.run.results_by_net[net_id].as_seed() for net_id in trial.valid_costs}
def _seeded_problem(self, trial: Trial, *, include_unresolved: bool = False) -> RoutingProblem:
seeds = {
net_id: result.as_seed() for net_id, result in trial.run.results_by_net.items()
if result.path and (include_unresolved or net_id in trial.valid_costs)
}
nets = tuple(net for net in self.problem.nets if net.net_id in seeds)
return replace(self.problem, nets=nets, initial_paths=seeds)
@ -170,6 +173,7 @@ class _AutomaticRun:
kind: str,
policy: str | None,
operation: Literal["verify", "refine"],
node_limit: int = 1,
) -> tuple[RoutingRunResult, RoutingStage]:
options = self.options
refinement = options.refinement
@ -177,7 +181,7 @@ class _AutomaticRun:
refinement = replace(refinement, enabled=False)
worker = replace(
options,
search=replace(options.search, node_limit=1),
search=replace(options.search, node_limit=node_limit),
topology=replace(options.topology, mode="off"),
congestion=replace(options.congestion, max_iterations=1),
refinement=refinement,
@ -581,14 +585,16 @@ class _AutomaticRun:
best = _best_trial(trials)
if not self.options.refinement.enabled or not best.valid_costs:
return
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(
self._seeded_problem(best),
self._seeded_problem(best, include_unresolved=has_unresolved_paths),
best.stage.planner,
kind="refinement",
policy=best.stage.policy,
operation="refine",
node_limit=0 if has_unresolved_paths else 1,
)
# Keep reports for unresolved routes when merging the refined subset.
# Any carried-over result without a replayed seed has no path to recheck.
results = {**best.run.results_by_net, **run.results_by_net}
refined = self._trial(replace(run, results_by_net=results), stage)
# Only a whole verified replacement of the incumbent can win.
@ -605,7 +611,7 @@ class _AutomaticRun:
trials: list[Trial] = []
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")
elif isinstance(proxy, shapely.Polygon) or physical != "arc":
elif options.search.sbend_outlines or isinstance(proxy, shapely.Polygon) or physical != "arc":
self._lattice_fallback(trials, options, "Custom bend geometry uses lattice routing")
else:
with self._time("plan"):