2026-11-26 11:57:49 -08:00
|
|
|
"""Compare the public routing modes on selected routing benchmarks."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
from dataclasses import asdict, dataclass, replace
|
|
|
|
|
from functools import partial
|
|
|
|
|
from json import dumps
|
|
|
|
|
from math import ceil, isfinite
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from platform import python_version
|
|
|
|
|
from statistics import median
|
|
|
|
|
from time import perf_counter
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
|
|
import shapely
|
|
|
|
|
from shapely.geometry import box, mapping
|
|
|
|
|
|
|
|
|
|
from inire import RoutingOptions, RoutingStage, route
|
2026-12-01 22:39:12 -08:00
|
|
|
from inire.router._routing_policy import LockPlan, _best_trial, _residual_problem
|
2026-11-26 11:57:49 -08:00
|
|
|
from inire.router._routing_policy import _trial as _summarize_trial
|
2026-11-26 21:55:34 -08:00
|
|
|
from inire.tests.direct_routing_policies import DIRECT_POLICIES
|
|
|
|
|
from inire.tests.direct_routing_policies import direct_trials as _direct_trials
|
2026-11-26 19:58:46 -08:00
|
|
|
from inire.tests.routing_corpus import (
|
|
|
|
|
AUTOMATIC_POLICIES,
|
|
|
|
|
CASE_GROUPS,
|
2026-11-27 19:28:48 -08:00
|
|
|
EXAMPLE_NAMES,
|
2026-11-26 19:58:46 -08:00
|
|
|
PROFILES,
|
|
|
|
|
automatic_options,
|
|
|
|
|
benchmark_weighted_length,
|
|
|
|
|
native_verified_costs,
|
|
|
|
|
profile_options,
|
|
|
|
|
select_cases,
|
2026-11-26 11:57:49 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2026-11-26 19:58:46 -08:00
|
|
|
from inire import CapacityLimit, RoutingProblem, RoutingTiming, TopologyReport
|
2026-11-26 11:57:49 -08:00
|
|
|
from inire.router._routing_policy import Trial
|
2026-11-26 19:58:46 -08:00
|
|
|
from inire.tests.routing_benchmark_case import BenchmarkCase
|
2026-11-26 11:57:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
ORDER_POLICIES = ("seed-order-restart", "seed-order-initial", "seed-order-locked")
|
|
|
|
|
BUNDLE_POLICIES = ("bundle-first", "bundle-first-refine")
|
|
|
|
|
POLICIES = (*DIRECT_POLICIES, *ORDER_POLICIES, *BUNDLE_POLICIES, *AUTOMATIC_POLICIES)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
|
|
|
class RunSample:
|
|
|
|
|
duration_s: float
|
|
|
|
|
net_outcomes: dict[str, str]
|
|
|
|
|
valid_costs: dict[str, float]
|
2026-11-26 19:58:46 -08:00
|
|
|
native_valid_costs: dict[str, float]
|
2026-11-26 11:57:49 -08:00
|
|
|
reached_net_ids: tuple[str, ...]
|
|
|
|
|
out_of_bounds_net_ids: tuple[str, ...]
|
|
|
|
|
nodes_expanded: int
|
|
|
|
|
route_iterations: int
|
|
|
|
|
topology: TopologyReport | None
|
|
|
|
|
stages: tuple[RoutingStage, ...]
|
|
|
|
|
bundle_rejection: str | None = None
|
|
|
|
|
bundle_duration_s: float | None = None
|
|
|
|
|
selected_stage: int = 0
|
|
|
|
|
capacity_limit: CapacityLimit | None = None
|
|
|
|
|
planner_rejections: tuple[str, ...] = ()
|
|
|
|
|
port_conflicts: tuple[tuple[str, str], ...] = ()
|
|
|
|
|
max_routed: int | None = None
|
|
|
|
|
cost_pass_performed: bool = False
|
|
|
|
|
timings: tuple[RoutingTiming, ...] = ()
|
|
|
|
|
|
|
|
|
|
|
2026-11-26 19:58:46 -08:00
|
|
|
_trial = partial(_summarize_trial, score=benchmark_weighted_length)
|
2026-11-26 11:57:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mode_options(options: RoutingOptions, strategy: str, profile: str = "matched-budget") -> RoutingOptions:
|
2026-11-26 19:58:46 -08:00
|
|
|
if strategy in AUTOMATIC_POLICIES:
|
|
|
|
|
return automatic_options(options, profile, strategy)
|
|
|
|
|
return replace(options, topology=replace(options.topology, mode="off" if strategy in POLICIES else strategy))
|
2026-11-26 11:57:49 -08:00
|
|
|
|
|
|
|
|
|
2026-11-27 14:12:40 -08:00
|
|
|
def _order_trials(problem: RoutingProblem, options: RoutingOptions, strategy: str) -> list[Trial]:
|
2026-11-26 11:57:49 -08:00
|
|
|
limit = options.search.node_limit
|
|
|
|
|
first_limit = max(1, limit // 2)
|
|
|
|
|
first_order = options.congestion.net_order
|
|
|
|
|
first_options = replace(options, search=replace(options.search, node_limit=first_limit), topology=replace(options.topology, mode="seed"))
|
|
|
|
|
run = route(problem, options=first_options)
|
2026-11-27 14:12:40 -08:00
|
|
|
first = _trial(run, RoutingStage("seed", (), run.metrics.nodes_expanded, first_limit, net_order=first_order))
|
2026-11-26 11:57:49 -08:00
|
|
|
if len(first.valid_costs) == len(problem.nets) or limit == 1:
|
|
|
|
|
return [first]
|
|
|
|
|
|
|
|
|
|
second_order = "shortest" if first_order == "longest" else "longest"
|
|
|
|
|
second_limit = limit - first_limit
|
|
|
|
|
second_options = replace(
|
|
|
|
|
first_options,
|
|
|
|
|
search=replace(options.search, node_limit=second_limit),
|
|
|
|
|
congestion=replace(options.congestion, net_order=second_order),
|
|
|
|
|
)
|
|
|
|
|
incumbents = {net_id: run.results_by_net[net_id] for net_id in first.valid_costs} if strategy != "seed-order-restart" else {}
|
|
|
|
|
if strategy == "seed-order-initial":
|
|
|
|
|
seeds = {net_id: result.as_seed() for net_id, result in incumbents.items()}
|
|
|
|
|
second_problem = replace(problem, initial_paths={**seeds, **problem.initial_paths})
|
|
|
|
|
elif strategy == "seed-order-locked" and incumbents:
|
2026-12-01 22:39:12 -08:00
|
|
|
second_problem = _residual_problem(problem, LockPlan(incumbents))
|
2026-11-26 11:57:49 -08:00
|
|
|
else:
|
|
|
|
|
second_problem = problem
|
|
|
|
|
|
|
|
|
|
run = route(second_problem, options=second_options)
|
|
|
|
|
if strategy == "seed-order-locked":
|
|
|
|
|
run = replace(run, results_by_net={**incumbents, **run.results_by_net})
|
|
|
|
|
stage = RoutingStage("seed", (), run.metrics.nodes_expanded, second_limit, net_order=second_order, incumbent_net_ids=tuple(incumbents))
|
2026-11-27 14:12:40 -08:00
|
|
|
return [first, _trial(run, stage)]
|
2026-11-26 11:57:49 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _measure(case: BenchmarkCase, options: RoutingOptions, strategy: str) -> RunSample:
|
|
|
|
|
board = box(*case.problem.bounds)
|
|
|
|
|
started = perf_counter()
|
|
|
|
|
bundle_rejection = None
|
|
|
|
|
bundle_duration = None
|
|
|
|
|
if strategy in AUTOMATIC_POLICIES:
|
|
|
|
|
run = route(case.problem, options=options)
|
|
|
|
|
report = run.automatic
|
|
|
|
|
assert report is not None
|
|
|
|
|
selected = report.stages[report.selected_stage]
|
2026-11-26 19:58:46 -08:00
|
|
|
valid_costs = {net_id: benchmark_weighted_length(run.results_by_net[net_id]) for net_id in report.verified_net_ids}
|
2026-11-26 11:57:49 -08:00
|
|
|
return RunSample(
|
|
|
|
|
duration_s=perf_counter() - started,
|
|
|
|
|
net_outcomes={net_id: result.outcome for net_id, result in run.results_by_net.items()},
|
|
|
|
|
valid_costs=valid_costs,
|
2026-11-26 19:58:46 -08:00
|
|
|
native_valid_costs=native_verified_costs(case, options, run.results_by_net, report.verified_net_ids),
|
2026-11-26 11:57:49 -08:00
|
|
|
reached_net_ids=tuple(net_id for net_id, result in run.results_by_net.items() if result.reached_target),
|
|
|
|
|
out_of_bounds_net_ids=selected.out_of_bounds_net_ids,
|
|
|
|
|
nodes_expanded=run.metrics.nodes_expanded,
|
|
|
|
|
route_iterations=run.metrics.route_iterations,
|
|
|
|
|
topology=run.topology,
|
|
|
|
|
stages=report.stages,
|
|
|
|
|
selected_stage=report.selected_stage,
|
|
|
|
|
capacity_limit=report.capacity_limit,
|
|
|
|
|
planner_rejections=report.planner_rejections,
|
|
|
|
|
port_conflicts=report.port_conflicts,
|
|
|
|
|
max_routed=report.max_routed,
|
|
|
|
|
cost_pass_performed=report.cost_pass_performed,
|
|
|
|
|
timings=report.timings,
|
|
|
|
|
)
|
|
|
|
|
if strategy in BUNDLE_POLICIES:
|
|
|
|
|
bundle_options = replace(
|
|
|
|
|
options,
|
|
|
|
|
topology=replace(options.topology, mode="bundle", infer_terminal_headings=case.options.topology.infer_terminal_headings),
|
|
|
|
|
congestion=replace(options.congestion, max_iterations=1),
|
|
|
|
|
refinement=replace(options.refinement, enabled=strategy == "bundle-first-refine"),
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
run = route(case.problem, options=bundle_options)
|
|
|
|
|
except ValueError as exc:
|
|
|
|
|
bundle_rejection = str(exc)
|
|
|
|
|
bundle_duration = perf_counter() - started
|
|
|
|
|
trials = _direct_trials(case.fixed_headings_problem(), board, options, "direct-probe-near-port")
|
|
|
|
|
else:
|
|
|
|
|
bundle_duration = perf_counter() - started
|
|
|
|
|
stage = RoutingStage("bundle", (), run.metrics.nodes_expanded, options.search.node_limit, kind="bundle")
|
2026-11-27 14:12:40 -08:00
|
|
|
trials = [_trial(run, stage)]
|
2026-11-26 11:57:49 -08:00
|
|
|
elif strategy in DIRECT_POLICIES:
|
|
|
|
|
problem = case.fixed_headings_problem()
|
|
|
|
|
trials = _direct_trials(problem, board, options, strategy)
|
|
|
|
|
elif strategy in ORDER_POLICIES:
|
|
|
|
|
problem = case.fixed_headings_problem()
|
2026-11-27 14:12:40 -08:00
|
|
|
trials = _order_trials(problem, options, strategy)
|
2026-11-26 11:57:49 -08:00
|
|
|
else:
|
|
|
|
|
run = route(case.fixed_headings_problem(), options=options)
|
2026-11-27 14:12:40 -08:00
|
|
|
trials = [_trial(run, RoutingStage(strategy, (), run.metrics.nodes_expanded, options.search.node_limit))]
|
2026-11-26 11:57:49 -08:00
|
|
|
best = _best_trial(trials)
|
|
|
|
|
duration = perf_counter() - started
|
|
|
|
|
run = best.run
|
|
|
|
|
return RunSample(
|
|
|
|
|
duration_s=duration,
|
|
|
|
|
net_outcomes={net_id: result.outcome for net_id, result in run.results_by_net.items()},
|
|
|
|
|
valid_costs=best.valid_costs,
|
2026-11-26 19:58:46 -08:00
|
|
|
native_valid_costs=native_verified_costs(case, options, run.results_by_net, best.valid_costs),
|
2026-11-26 11:57:49 -08:00
|
|
|
reached_net_ids=tuple(net_id for net_id, result in run.results_by_net.items() if result.reached_target),
|
|
|
|
|
out_of_bounds_net_ids=best.stage.out_of_bounds_net_ids,
|
|
|
|
|
nodes_expanded=sum(trial.stage.nodes_expanded for trial in trials),
|
|
|
|
|
route_iterations=sum(trial.run.metrics.route_iterations for trial in trials),
|
|
|
|
|
topology=run.topology,
|
|
|
|
|
stages=tuple(trial.stage for trial in trials),
|
|
|
|
|
bundle_rejection=bundle_rejection,
|
|
|
|
|
bundle_duration_s=bundle_duration,
|
|
|
|
|
selected_stage=next(i for i, trial in enumerate(trials) if trial is best),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _print_summary(mode: str, samples: list[RunSample]) -> None:
|
|
|
|
|
run = samples[0]
|
|
|
|
|
print(
|
|
|
|
|
f" {mode}: {median(len(sample.valid_costs) for sample in samples):g}/{len(run.net_outcomes)} valid, "
|
|
|
|
|
f"{median(len(sample.reached_net_ids) for sample in samples):g} reached, "
|
|
|
|
|
f"{median(sample.nodes_expanded for sample in samples):g} A* nodes, "
|
|
|
|
|
f"{median(sample.duration_s for sample in samples):.3f} s median",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
|
|
|
|
if run.valid_costs:
|
2026-11-26 19:58:46 -08:00
|
|
|
print(
|
|
|
|
|
f" benchmark-weighted length {sum(run.valid_costs.values()):.2f}, "
|
|
|
|
|
f"native objective cost {sum(run.native_valid_costs.values()):.2f}, nets {', '.join(run.valid_costs)}",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
2026-11-26 11:57:49 -08:00
|
|
|
if run.out_of_bounds_net_ids:
|
|
|
|
|
print(f" outside board {', '.join(run.out_of_bounds_net_ids)}", flush=True)
|
|
|
|
|
if run.bundle_rejection is not None:
|
|
|
|
|
print(f" bundle rejected; using direct-probe-near-port. {run.bundle_rejection}", flush=True)
|
|
|
|
|
if mode in AUTOMATIC_POLICIES:
|
|
|
|
|
selected = run.stages[run.selected_stage]
|
|
|
|
|
policy = f", policy {selected.policy}" if selected.policy else ""
|
|
|
|
|
print(f" selected {selected.planner}, mode {selected.mode}, operation {selected.operation}{policy}", flush=True)
|
|
|
|
|
elapsed = {
|
|
|
|
|
operation: median(sum(timing.duration_s for timing in sample.timings if timing.operation == operation) for sample in samples)
|
|
|
|
|
for operation in ("plan", "verify", "search", "refine")
|
|
|
|
|
}
|
|
|
|
|
print(" median stage time " + ", ".join(f"{operation} {seconds:.3f} s" for operation, seconds in elapsed.items()), flush=True)
|
|
|
|
|
if run.capacity_limit:
|
|
|
|
|
limit = run.capacity_limit
|
|
|
|
|
print(
|
|
|
|
|
f" capacity {limit.tracks}/{limit.crossing_nets} across x={limit.cut_x:g}, at most {limit.max_routed} on the board",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
|
|
|
|
if run.port_conflicts:
|
|
|
|
|
print(f" port spacing limits board to {len(run.net_outcomes) - len(run.port_conflicts)} nets", flush=True)
|
|
|
|
|
return
|
|
|
|
|
if mode in POLICIES:
|
|
|
|
|
for stage in run.stages:
|
|
|
|
|
if stage.kind == "bundle":
|
|
|
|
|
continue
|
|
|
|
|
if stage.kind == "lattice-probe":
|
|
|
|
|
print(f" unlocked lattice probe at {stage.node_limit} nodes per attempt", flush=True)
|
|
|
|
|
continue
|
|
|
|
|
if stage.net_order is not None:
|
|
|
|
|
incumbents = f", carried {', '.join(stage.incumbent_net_ids)}" if stage.incumbent_net_ids else ""
|
|
|
|
|
print(f" {stage.mode} at {stage.node_limit} nodes per attempt, order {stage.net_order}{incumbents}", flush=True)
|
|
|
|
|
continue
|
|
|
|
|
skipped = f", skipped {', '.join(stage.skipped_net_ids)}" if stage.skipped_net_ids else ""
|
|
|
|
|
print(
|
|
|
|
|
f" {stage.mode} at {stage.node_limit} nodes per attempt after locking {len(stage.direct_net_ids)} direct routes{skipped}",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
|
|
|
|
if run.topology is not None:
|
|
|
|
|
corridors = sum(count for _, count in run.topology.corridor_counts)
|
|
|
|
|
seeds = ", ".join(run.topology.seeded_net_ids) or "none"
|
|
|
|
|
print(
|
|
|
|
|
f" {corridors} corridors across {len(run.topology.corridor_counts)} nets, "
|
|
|
|
|
f"seeds {seeds}, {run.topology.seed_nodes_expanded} seed expansions",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _geometry_json(value: object) -> dict:
|
|
|
|
|
if isinstance(value, shapely.Polygon):
|
|
|
|
|
return mapping(value)
|
|
|
|
|
raise TypeError(f"Cannot serialize {type(value).__name__}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
|
parser = ArgumentParser(description=__doc__)
|
2026-11-26 19:58:46 -08:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--profile", choices=PROFILES, default="matched-budget", help="Use CLI budgets, API defaults, or pytest corpus settings."
|
|
|
|
|
)
|
2026-11-26 11:57:49 -08:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--case",
|
2026-11-27 19:28:48 -08:00
|
|
|
choices=tuple(name for name in CASE_GROUPS if name not in EXAMPLE_NAMES),
|
|
|
|
|
type=lambda name: EXAMPLE_NAMES.get(name, name),
|
2026-11-26 11:57:49 -08:00
|
|
|
action="append",
|
2026-11-26 15:23:24 -08:00
|
|
|
help="Select a case or suite. Use 'corpus' to select all boards.",
|
2026-11-26 11:57:49 -08:00
|
|
|
)
|
|
|
|
|
parser.add_argument("--list", action="store_true", help="List the available cases.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--mode",
|
|
|
|
|
choices=("off", "guide", "seed", "automatic"),
|
|
|
|
|
action="append",
|
|
|
|
|
help="Repeat to compare modes. The public-defaults profile selects the shipped mode by default.",
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument("--policy", choices=POLICIES, action="append", help="Include a routing policy. Repeat to compare policies.")
|
|
|
|
|
parser.add_argument("--nodes", type=int, action="append", help="Repeat to compare node budgets. The matched-budget profile defaults to 500.")
|
|
|
|
|
parser.add_argument("--iterations", type=int)
|
|
|
|
|
parser.add_argument("--refinement", choices=("on", "off"), help="Override refinement for public routing modes.")
|
|
|
|
|
parser.add_argument("--refinement-windows", metavar="N", help="Limit attempted windows per net, or use 'unlimited'.")
|
2026-11-26 19:58:46 -08:00
|
|
|
parser.add_argument("--max-corridors", type=int)
|
|
|
|
|
parser.add_argument("--guide-strength", type=float)
|
|
|
|
|
parser.add_argument("--seed-nodes", type=int)
|
2026-11-26 11:57:49 -08:00
|
|
|
parser.add_argument("--sbend-offset", type=float, action="append", help="Override search S-bend offsets. Repeat for multiple offsets.")
|
2026-11-26 19:58:46 -08:00
|
|
|
parser.add_argument("--net-order", choices=("user", "shortest", "longest"))
|
2026-11-26 11:57:49 -08:00
|
|
|
parser.add_argument("--no-warm-start", action="store_true")
|
|
|
|
|
parser.add_argument("--repeat", type=int, default=1, help="Run each configuration this many times and report median runtime.")
|
|
|
|
|
parser.add_argument("--json", type=Path, help="Write options and individual runs to this file.")
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
if args.list:
|
2026-11-26 15:23:24 -08:00
|
|
|
print("All boards (--case corpus)")
|
2026-11-26 11:57:49 -08:00
|
|
|
for group, title in (
|
|
|
|
|
("all", "Core corpus"),
|
|
|
|
|
("holdout", "Held-out boards"),
|
|
|
|
|
("fallback", "Fallback cases"),
|
|
|
|
|
("external", "External cases"),
|
|
|
|
|
("crossings", "Preplaced crossings"),
|
2026-11-26 15:23:24 -08:00
|
|
|
("stress", "Stress cases"),
|
2026-11-30 15:24:03 -08:00
|
|
|
("geometry-corners", "Tight geometry"),
|
|
|
|
|
("complex-layouts", "Complex layouts"),
|
|
|
|
|
("search-challenges", "Search challenges"),
|
|
|
|
|
("scaling", "Large net and keepout counts"),
|
2026-11-26 19:58:46 -08:00
|
|
|
("retry-holdout", "Retry-policy holdouts"),
|
2026-11-26 11:57:49 -08:00
|
|
|
):
|
|
|
|
|
print(f"{title} (--case {group})")
|
2026-11-26 19:58:46 -08:00
|
|
|
for case in CASE_GROUPS[group]:
|
2026-11-27 19:28:48 -08:00
|
|
|
name = EXAMPLE_NAMES.get(case.name, case.name)
|
|
|
|
|
print(f" {name:40} {case.description}")
|
2026-11-26 11:57:49 -08:00
|
|
|
return
|
2026-11-26 19:58:46 -08:00
|
|
|
if (args.nodes and min(args.nodes) < 1) or (args.iterations is not None and args.iterations < 1) or args.repeat < 1:
|
2026-11-26 11:57:49 -08:00
|
|
|
parser.error("--nodes, --iterations and --repeat must be positive")
|
|
|
|
|
if args.sbend_offset is not None and not all(isfinite(offset) for offset in args.sbend_offset):
|
|
|
|
|
parser.error("--sbend-offset must be finite")
|
|
|
|
|
refinement_overrides: dict[str, bool | int | None] = {}
|
|
|
|
|
if args.refinement is not None:
|
|
|
|
|
refinement_overrides["enabled"] = args.refinement == "on"
|
|
|
|
|
if args.refinement_windows is not None:
|
|
|
|
|
limit_error = "--refinement-windows must be a positive integer or 'unlimited'"
|
|
|
|
|
try:
|
|
|
|
|
limit = None if args.refinement_windows == "unlimited" else int(args.refinement_windows)
|
|
|
|
|
except ValueError:
|
|
|
|
|
parser.error(limit_error)
|
|
|
|
|
if limit is not None and limit < 1:
|
|
|
|
|
parser.error(limit_error)
|
|
|
|
|
refinement_overrides["max_windows_per_net"] = limit
|
2026-11-26 19:58:46 -08:00
|
|
|
topology_overrides = {
|
|
|
|
|
name: value
|
|
|
|
|
for name, value in (
|
|
|
|
|
("max_corridors", args.max_corridors),
|
|
|
|
|
("guide_strength", args.guide_strength),
|
|
|
|
|
("seed_node_limit", args.seed_nodes),
|
2026-11-26 11:57:49 -08:00
|
|
|
)
|
2026-11-26 19:58:46 -08:00
|
|
|
if value is not None
|
|
|
|
|
}
|
|
|
|
|
cases = select_cases(args.case or ["terminal-bench"])
|
2026-11-26 11:57:49 -08:00
|
|
|
sbend_offsets = tuple(args.sbend_offset) if args.sbend_offset is not None else None
|
|
|
|
|
records = []
|
|
|
|
|
requested = [*(args.mode or ()), *(args.policy or ())]
|
2026-11-26 19:58:46 -08:00
|
|
|
default_modes = ("off", "guide", "seed") if args.profile == "matched-budget" else (RoutingOptions().topology.mode,)
|
2026-11-26 11:57:49 -08:00
|
|
|
modes = tuple(dict.fromkeys(requested or default_modes))
|
|
|
|
|
for case in cases:
|
2026-11-26 19:58:46 -08:00
|
|
|
base = profile_options(case, args.profile)
|
|
|
|
|
try:
|
|
|
|
|
topology = replace(base.topology, **topology_overrides)
|
|
|
|
|
except ValueError as exc:
|
|
|
|
|
parser.error(str(exc))
|
|
|
|
|
budgets = tuple(dict.fromkeys(args.nodes or (base.search.node_limit,)))
|
|
|
|
|
iterations = base.congestion.max_iterations if args.iterations is None else args.iterations
|
2026-11-26 11:57:49 -08:00
|
|
|
for budget in budgets:
|
2026-11-27 19:28:48 -08:00
|
|
|
name = EXAMPLE_NAMES.get(case.name, case.name)
|
|
|
|
|
print(f"{name} | {budget} nodes per attempt", flush=True)
|
2026-11-26 11:57:49 -08:00
|
|
|
options = replace(
|
|
|
|
|
base,
|
2026-11-26 19:58:46 -08:00
|
|
|
topology=topology,
|
2026-11-26 11:57:49 -08:00
|
|
|
search=replace(
|
|
|
|
|
base.search, node_limit=budget, sbend_offsets=sbend_offsets if sbend_offsets is not None else base.search.sbend_offsets
|
|
|
|
|
),
|
|
|
|
|
refinement=replace(base.refinement, **refinement_overrides),
|
|
|
|
|
congestion=replace(
|
|
|
|
|
base.congestion,
|
|
|
|
|
max_iterations=iterations,
|
2026-11-26 19:58:46 -08:00
|
|
|
net_order=args.net_order or base.congestion.net_order,
|
|
|
|
|
warm_start_enabled=not args.no_warm_start and base.congestion.warm_start_enabled,
|
2026-11-26 11:57:49 -08:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
mode_options = {mode: _mode_options(options, mode, args.profile) for mode in modes}
|
|
|
|
|
samples: dict[str, list[RunSample]] = {mode: [] for mode in modes}
|
|
|
|
|
for repeat in range(args.repeat):
|
|
|
|
|
offset = repeat % len(modes)
|
|
|
|
|
for mode in modes[offset:] + modes[:offset]:
|
|
|
|
|
samples[mode].append(_measure(case, mode_options[mode], mode))
|
|
|
|
|
for mode in modes:
|
|
|
|
|
_print_summary(mode, samples[mode])
|
|
|
|
|
records.append(
|
|
|
|
|
{
|
|
|
|
|
"case": case.name,
|
|
|
|
|
"strategy": mode,
|
|
|
|
|
"requested_mode": mode_options[mode].topology.mode,
|
2026-11-30 15:24:03 -08:00
|
|
|
"grid_nm": case.grid_nm,
|
2026-11-26 11:57:49 -08:00
|
|
|
"reference_net_ids": [net_id for net_id, _ in case.reference_paths],
|
|
|
|
|
"options": asdict(mode_options[mode]),
|
|
|
|
|
"samples": [asdict(sample) for sample in samples[mode]],
|
|
|
|
|
"duration_s_median": median(sample.duration_s for sample in samples[mode]),
|
|
|
|
|
"duration_s_p95": sorted(sample.duration_s for sample in samples[mode])[ceil(0.95 * len(samples[mode])) - 1],
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
if args.json is not None:
|
|
|
|
|
payload = {
|
|
|
|
|
"profile": args.profile,
|
|
|
|
|
"python": python_version(),
|
|
|
|
|
"shapely": shapely.__version__,
|
|
|
|
|
"geos": shapely.geos_version_string,
|
2026-11-26 19:58:46 -08:00
|
|
|
"cost_metrics": {"valid_costs": "benchmark_weighted_length", "native_valid_costs": "native_objective"},
|
2026-11-26 11:57:49 -08:00
|
|
|
"runs": records,
|
|
|
|
|
}
|
|
|
|
|
args.json.write_text(dumps(payload, indent=2, default=_geometry_json) + "\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|