Complete feasible stress layouts with verified routing fallbacks
This commit is contained in:
parent
d9f0e78330
commit
a2dfb73c33
1 changed files with 1022 additions and 76 deletions
|
|
@ -18,12 +18,28 @@ from inire.geometry.collision import RoutingWorld
|
|||
from inire.model import resolve_bend_geometry
|
||||
from inire.results import AutomaticRoutingReport, CapacityLimit, RouteMetrics, RoutingStage, RoutingTiming, _planner_for_mode
|
||||
from inire.router._bundle import ordered_bundle_terminal_headings, plan_ordered_bundle
|
||||
from inire.router._columns import column_seed_candidates, open_intervals, rectangular_obstacle_bounds
|
||||
from inire.router._compact import compact_port_seed_set
|
||||
from inire.router._perimeter import bundle_turnaround_candidates, perimeter_detour_candidates, terminal_link_seed
|
||||
from inire.router._routing_policy import LockPlan, _best_trial, _direct_trials, _disconnected_nets, _is_short_shift, _route_residual, _trial
|
||||
from inire.router._columns import column_jog_candidates, column_seed_candidates, open_intervals, rectangular_obstacle_bounds
|
||||
from inire.router._compact import compact_port_seed_set, short_shift_seed_set
|
||||
from inire.router._perimeter import (
|
||||
bundle_turnaround_candidates,
|
||||
perimeter_detour_candidates,
|
||||
residual_dogleg_candidates,
|
||||
terminal_link_seed,
|
||||
)
|
||||
from inire.router._routing_policy import (
|
||||
LockPlan,
|
||||
_best_trial,
|
||||
_direct_trials,
|
||||
_disconnected_nets,
|
||||
_is_short_shift,
|
||||
_local_delta,
|
||||
_residual_problem,
|
||||
_route_residual,
|
||||
_trial,
|
||||
)
|
||||
from inire.router._seed_materialization import materialize_path_seed
|
||||
from inire.router._stack import route_once
|
||||
from inire.router._topology import plan_corridors
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.seeds import SBendSeed
|
||||
|
|
@ -36,6 +52,7 @@ if TYPE_CHECKING:
|
|||
from inire.model import NetSpec, RoutingOptions, RoutingProblem
|
||||
from inire.results import RoutingOperation, RoutingResult, RoutingRunResult
|
||||
from inire.router._routing_policy import Trial
|
||||
from inire.router._topology import Corridor
|
||||
from inire.seeds import PathSeed
|
||||
|
||||
|
||||
|
|
@ -164,6 +181,7 @@ class _AutomaticRun:
|
|||
operation: RoutingOperation = "search",
|
||||
planner: str | None = None,
|
||||
policy: str | None = None,
|
||||
corridors: dict[str, tuple[Corridor, ...]] | None = None,
|
||||
) -> RoutingRunResult:
|
||||
def notify(_iteration: int, results: dict[str, RoutingResult]) -> None:
|
||||
assert self.iteration_callback is not None
|
||||
|
|
@ -178,6 +196,7 @@ class _AutomaticRun:
|
|||
options=options,
|
||||
iteration_callback=notify if self.iteration_callback else None,
|
||||
phase_timer=time_operation,
|
||||
corridors=corridors,
|
||||
)
|
||||
self.metrics.append(run.metrics)
|
||||
return run
|
||||
|
|
@ -256,6 +275,16 @@ class _AutomaticRun:
|
|||
self.cost_pass_performed = True
|
||||
if self._column_trial(True, trials) is None:
|
||||
rejections.append("Cost scoring found no verified column layout")
|
||||
if not trials or len(_best_trial(trials).valid_costs) < len(problem.nets):
|
||||
planner = "local-sbend"
|
||||
with self._time("plan", planner=planner):
|
||||
shifts = short_shift_seed_set(problem, options.search, self._score)
|
||||
if shifts is not None:
|
||||
trial = self._verify(replace(problem, initial_paths=shifts), planner)
|
||||
complete = len(trial.valid_costs) == len(problem.nets)
|
||||
trials.append(replace(trial, selectable=complete))
|
||||
if not complete:
|
||||
rejections.append("Local S-bend layout failed full verification")
|
||||
return trials, tuple(rejections)
|
||||
|
||||
def _column_trial(self, weighted: bool, trials: list[Trial]) -> Trial | None:
|
||||
|
|
@ -368,7 +397,7 @@ class _AutomaticRun:
|
|||
break
|
||||
return trials
|
||||
|
||||
def _incumbent_trials(self, options: RoutingOptions, best: Trial) -> list[Trial]:
|
||||
def _incumbent_trials(self, options: RoutingOptions, best: Trial, target: int) -> list[Trial]:
|
||||
problem = self.problem
|
||||
retained = {net_id: best.run.results_by_net[net_id] for net_id in best.valid_costs}
|
||||
with self._time("plan", policy="incumbent-retry"):
|
||||
|
|
@ -389,14 +418,47 @@ class _AutomaticRun:
|
|||
return [self._trial(run, stage)]
|
||||
|
||||
policy = "incumbent-residual"
|
||||
run, stage = _route_residual(problem, options, "direct-seed", LockPlan(retained), run_route=partial(self._run, policy=policy))
|
||||
locks = LockPlan(retained)
|
||||
run, stage = _route_residual(problem, options, "direct-seed", locks, run_route=partial(self._run, policy=policy))
|
||||
stage = replace(stage, kind=policy, policy=policy, retry_reason="Residual terminals remain connected with the incumbents locked")
|
||||
trial = self._trial(run, stage)
|
||||
if len(trial.valid_costs) < len(problem.nets):
|
||||
return [trial]
|
||||
seeds = {net_id: result.as_seed() for net_id, result in run.results_by_net.items()}
|
||||
verified = self._verify(replace(problem, initial_paths=seeds), stage.planner, kind="incumbent-verified", policy=policy)
|
||||
return [replace(trial, selectable=False), verified]
|
||||
if len(trial.valid_costs) == len(problem.nets):
|
||||
return [replace(trial, selectable=False), self._verify_incumbent(trial)]
|
||||
trials = [trial]
|
||||
if len(trial.valid_costs) < target:
|
||||
dogleg = self._residual_dogleg_trial(options, _best_trial([best, trial]))
|
||||
if dogleg is not None:
|
||||
return [trial, dogleg]
|
||||
joint = self._joint_lane_trial(options, locks, trial)
|
||||
if joint is not None:
|
||||
trials.append(replace(joint, selectable=False))
|
||||
if joint.improves_on(_best_trial([best, trial])):
|
||||
trials.append(self._verify_incumbent(joint))
|
||||
return trials
|
||||
|
||||
def _verify_incumbent(self, trial: Trial) -> Trial:
|
||||
seeds = {net_id: trial.run.results_by_net[net_id].as_seed() for net_id in trial.valid_costs}
|
||||
problem = replace(self.problem, nets=tuple(net for net in self.problem.nets if net.net_id in seeds), initial_paths=seeds)
|
||||
verified = self._verify(problem, trial.stage.planner, kind="incumbent-verified", policy=trial.stage.policy)
|
||||
results = {**trial.run.results_by_net, **verified.run.results_by_net}
|
||||
return replace(verified, run=replace(verified.run, results_by_net=results), selectable=verified.valid_costs.keys() == seeds.keys())
|
||||
|
||||
def _residual_dogleg_trial(self, options: RoutingOptions, incumbent: Trial) -> Trial | None:
|
||||
problem = self.problem
|
||||
if len(incumbent.valid_costs) != len(problem.nets) - 1:
|
||||
return None
|
||||
retained = {net_id: incumbent.run.results_by_net[net_id] for net_id in incumbent.valid_costs}
|
||||
residual = _residual_problem(problem, LockPlan(retained))
|
||||
(net,) = residual.nets
|
||||
seeds = {net_id: result.as_seed() for net_id, result in retained.items()}
|
||||
planner = "residual-dogleg"
|
||||
with self._time("plan", planner=planner, policy=planner):
|
||||
for seed in islice(residual_dogleg_candidates(residual, options.search), 8):
|
||||
candidate = replace(problem, initial_paths={**seeds, net.net_id: seed})
|
||||
trial = self._verify(candidate, planner, policy=planner)
|
||||
if len(trial.valid_costs) == len(problem.nets):
|
||||
return trial
|
||||
return None
|
||||
|
||||
def _direct(self, options: RoutingOptions, policy: str) -> list[Trial]:
|
||||
with self._time("plan", planner="direct", policy=policy):
|
||||
|
|
@ -447,6 +509,14 @@ class _AutomaticRun:
|
|||
if len(_best_trial(trials).valid_costs) >= target:
|
||||
return
|
||||
|
||||
if target == len(problem.nets) and not problem.initial_paths:
|
||||
with self._time("plan", planner="column-jogs"):
|
||||
for seeds in islice(column_jog_candidates(problem, options.search), 8):
|
||||
trial = self._verify(replace(problem, initial_paths=seeds), "column-jogs")
|
||||
if len(trial.valid_costs) == target:
|
||||
trials.append(trial)
|
||||
return
|
||||
|
||||
if len(problem.nets) <= 2:
|
||||
with self._time("plan", planner="perimeter"):
|
||||
trials.extend(self._perimeter_trials(options))
|
||||
|
|
@ -462,7 +532,7 @@ class _AutomaticRun:
|
|||
return
|
||||
seeded = replace(options, topology=replace(options.topology, mode="seed"))
|
||||
if best.valid_costs and len(problem.nets) > 2 and not problem.initial_paths:
|
||||
trials.extend(self._incumbent_trials(seeded, best))
|
||||
trials.extend(self._incumbent_trials(seeded, best, target))
|
||||
if len(_best_trial(trials).valid_costs) < target:
|
||||
run = self._run(problem, options=seeded, policy="seed-fallback")
|
||||
stage = RoutingStage("seed", (), run.metrics.nodes_expanded, options.search.node_limit, policy="seed-fallback")
|
||||
|
|
@ -477,6 +547,40 @@ class _AutomaticRun:
|
|||
policy="budget-escalation",
|
||||
)
|
||||
|
||||
def _joint_lane_trial(self, options: RoutingOptions, locks: LockPlan, previous: Trial) -> Trial | None:
|
||||
residual = _residual_problem(self.problem, locks)
|
||||
if len(residual.nets) < 2:
|
||||
return None
|
||||
policy = "joint-portal-lanes"
|
||||
unresolved = frozenset(net.net_id for net in residual.nets if net.net_id not in previous.valid_costs)
|
||||
order = options.congestion.net_order
|
||||
nets = residual.nets
|
||||
if order != "user":
|
||||
nets = tuple(sorted(nets, key=lambda net: sum(map(abs, _local_delta(net))), reverse=order == "longest"))
|
||||
with self._time("plan", planner="corridor-seed", mode="seed", policy=policy):
|
||||
corridors = plan_corridors(
|
||||
residual.bounds,
|
||||
residual.static_obstacles,
|
||||
nets,
|
||||
clearance=residual.clearance,
|
||||
bend_radius=min(options.search.bend_radii, default=0.0),
|
||||
limit=options.topology.max_corridors,
|
||||
joint_net_ids=unresolved,
|
||||
)
|
||||
if not corridors:
|
||||
return None
|
||||
retry = replace(options, congestion=replace(options.congestion, max_iterations=min(3, options.congestion.max_iterations)))
|
||||
run, stage = _route_residual(
|
||||
self.problem, retry, "direct-seed", locks, run_route=partial(self._run, policy=policy, corridors=corridors)
|
||||
)
|
||||
stage = replace(
|
||||
stage,
|
||||
policy=policy,
|
||||
incumbent_net_ids=tuple(locks.direct),
|
||||
retry_reason="Unresolved nets share a portal with alternative lane assignments",
|
||||
)
|
||||
return self._trial(run, stage)
|
||||
|
||||
def _lattice_fallback(self, trials: list[Trial], options: RoutingOptions, reason: str, *, policy: str | None = None) -> None:
|
||||
run = self._run(self.problem, options=replace(options, topology=replace(options.topology, mode="off")), policy=policy)
|
||||
stage = RoutingStage(
|
||||
|
|
@ -540,7 +644,7 @@ class _AutomaticRun:
|
|||
target = min(target, cut.max_routed)
|
||||
if not cut and not conflicts:
|
||||
trials, rejections = self._constructive_trials()
|
||||
if not trials or len(_best_trial(trials).valid_costs) < target:
|
||||
if not any(trial.selectable for trial in trials) or len(_best_trial(trials).valid_costs) < target:
|
||||
self._search_trials(trials, target)
|
||||
self._refine(trials)
|
||||
best = _best_trial(trials)
|
||||
|
|
|
|||
Loading…
Reference in a new issue