Fix retry accounting and preserve authored bend lengths in benchmarks
This commit is contained in:
parent
f609e5a695
commit
72f8fbda5a
3 changed files with 26 additions and 9 deletions
|
|
@ -81,6 +81,7 @@ def _public_defaults(case: BenchmarkCase, defaults: RoutingOptions) -> RoutingOp
|
||||||
bend_collision_type=geometry.bend_collision_type,
|
bend_collision_type=geometry.bend_collision_type,
|
||||||
bend_proxy_geometry=geometry.bend_proxy_geometry,
|
bend_proxy_geometry=geometry.bend_proxy_geometry,
|
||||||
bend_physical_geometry=geometry.bend_physical_geometry,
|
bend_physical_geometry=geometry.bend_physical_geometry,
|
||||||
|
bend_physical_length=geometry.bend_physical_length,
|
||||||
sbend_outlines=geometry.sbend_outlines,
|
sbend_outlines=geometry.sbend_outlines,
|
||||||
bend_clip_margin=geometry.bend_clip_margin,
|
bend_clip_margin=geometry.bend_clip_margin,
|
||||||
min_straight_length=geometry.min_straight_length,
|
min_straight_length=geometry.min_straight_length,
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ from inire.tests.routing_benchmark_case import BenchmarkCase
|
||||||
from inire.tests.routing_benchmarks import (
|
from inire.tests.routing_benchmarks import (
|
||||||
BENCHMARK_CASES,
|
BENCHMARK_CASES,
|
||||||
CROSSING_BENCHMARK_CASES,
|
CROSSING_BENCHMARK_CASES,
|
||||||
FALLBACK_BENCHMARK_CASES,
|
|
||||||
)
|
)
|
||||||
from inire.tests.routing_corpus import CASE_GROUPS, automatic_options, profile_options
|
from inire.tests.routing_corpus import CASE_GROUPS, automatic_options, profile_options
|
||||||
|
from scripts.benchmark_retry_order import _measure as _measure_retry
|
||||||
from scripts.compare_topological_routing import (
|
from scripts.compare_topological_routing import (
|
||||||
_direct_trials,
|
_direct_trials,
|
||||||
_measure as _measure_selected_mode,
|
_measure as _measure_selected_mode,
|
||||||
|
|
@ -124,7 +124,10 @@ def test_automatic_skips_identical_guide_retry_on_staggered_grid() -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_benchmark_profile_records_effective_options(tmp_path, monkeypatch) -> None:
|
def test_benchmark_profile_records_effective_options(tmp_path, monkeypatch) -> None:
|
||||||
case = next(case for case in FALLBACK_BENCHMARK_CASES if case.name == "fallback-custom-physical")
|
(fixture,) = CASE_GROUPS["fallback-custom-physical"]
|
||||||
|
search = replace(fixture.options.search, bend_physical_length=25)
|
||||||
|
case = replace(fixture, options=replace(fixture.options, search=search))
|
||||||
|
monkeypatch.setitem(CASE_GROUPS, case.name, (case,))
|
||||||
defaults = RoutingOptions()
|
defaults = RoutingOptions()
|
||||||
output = tmp_path / "benchmark.json"
|
output = tmp_path / "benchmark.json"
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
|
|
@ -142,6 +145,7 @@ def test_benchmark_profile_records_effective_options(tmp_path, monkeypatch) -> N
|
||||||
geometry = case.options.search
|
geometry = case.options.search
|
||||||
assert options["search"]["bend_radii"] == list(geometry.bend_radii)
|
assert options["search"]["bend_radii"] == list(geometry.bend_radii)
|
||||||
assert shape(options["search"]["bend_physical_geometry"]).equals(geometry.bend_physical_geometry)
|
assert shape(options["search"]["bend_physical_geometry"]).equals(geometry.bend_physical_geometry)
|
||||||
|
assert options["search"]["bend_physical_length"] == geometry.bend_physical_length
|
||||||
[sample] = run["samples"]
|
[sample] = run["samples"]
|
||||||
assert payload["cost_metrics"] == {"valid_costs": "benchmark_weighted_length", "native_valid_costs": "native_objective"}
|
assert payload["cost_metrics"] == {"valid_costs": "benchmark_weighted_length", "native_valid_costs": "native_objective"}
|
||||||
assert sample["native_valid_costs"].keys() == sample["valid_costs"].keys()
|
assert sample["native_valid_costs"].keys() == sample["valid_costs"].keys()
|
||||||
|
|
@ -159,6 +163,18 @@ def test_benchmark_profile_records_effective_options(tmp_path, monkeypatch) -> N
|
||||||
assert options["topology"]["automatic_length_weights"] is None
|
assert options["topology"]["automatic_length_weights"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_retry_experiment_records_worker_expansions() -> None:
|
||||||
|
(case,) = CASE_GROUPS["retry-holdout-floor-pocket"]
|
||||||
|
|
||||||
|
sample = _measure_retry(case, "public-defaults", "lattice-500")
|
||||||
|
|
||||||
|
[attempt] = sample["retry_attempts"]
|
||||||
|
[stage] = [stage for stage in sample["stages"] if stage["policy"] == "early-bounded-lattice"]
|
||||||
|
assert attempt["policy"] == "bounded-lattice"
|
||||||
|
assert 0 < attempt["nodes_expanded"] == stage["nodes_expanded"] <= sample["nodes_expanded"]
|
||||||
|
assert len(sample["verified"]) == case.routing_bound
|
||||||
|
|
||||||
|
|
||||||
def test_seed_order_locked_rejects_touching_routes_at_zero_clearance() -> None:
|
def test_seed_order_locked_rejects_touching_routes_at_zero_clearance() -> None:
|
||||||
problem = RoutingProblem(
|
problem = RoutingProblem(
|
||||||
bounds=(0, 0, 100, 40),
|
bounds=(0, 0, 100, 40),
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,12 @@ class _RetryExperiment(_AutomaticRun):
|
||||||
self.retry_policy = policy
|
self.retry_policy = policy
|
||||||
self.retry_attempts: list[dict] = []
|
self.retry_attempts: list[dict] = []
|
||||||
|
|
||||||
def _record_retry(self, policy: str, outcome: str, started: float, first_run: int) -> None:
|
def _record_retry(self, policy: str, outcome: str, started: float, first_attempt: int) -> None:
|
||||||
self.retry_attempts.append({
|
self.retry_attempts.append({
|
||||||
"policy": policy,
|
"policy": policy,
|
||||||
"outcome": outcome,
|
"outcome": outcome,
|
||||||
"elapsed_s": perf_counter() - started,
|
"elapsed_s": perf_counter() - started,
|
||||||
"nodes_expanded": sum(metrics.nodes_expanded for metrics in self.metrics[first_run:]),
|
"nodes_expanded": sum(metrics.nodes_expanded for metrics in self.attempts.samples[first_attempt:]),
|
||||||
})
|
})
|
||||||
|
|
||||||
def _search_trials(self, trials: list[Trial], target: int) -> None:
|
def _search_trials(self, trials: list[Trial], target: int) -> None:
|
||||||
|
|
@ -105,10 +105,10 @@ class _RetryExperiment(_AutomaticRun):
|
||||||
and _near_port_coverage_stalled(trials, target)
|
and _near_port_coverage_stalled(trials, target)
|
||||||
):
|
):
|
||||||
retry = replace(options, search=replace(options.search, node_limit=limit))
|
retry = replace(options, search=replace(options.search, node_limit=limit))
|
||||||
started, first_run = perf_counter(), len(self.metrics)
|
started, first_attempt = perf_counter(), len(self.attempts.samples)
|
||||||
self._lattice_fallback(trials, retry, "Near-port and lookahead searches were one net short", policy="early-bounded-lattice")
|
self._lattice_fallback(trials, retry, "Near-port and lookahead searches were one net short", policy="early-bounded-lattice")
|
||||||
complete = len(trials[-1].valid_costs) == target
|
complete = len(trials[-1].valid_costs) == target
|
||||||
self._record_retry("bounded-lattice", "complete" if complete else "incomplete", started, first_run)
|
self._record_retry("bounded-lattice", "complete" if complete else "incomplete", started, first_attempt)
|
||||||
if complete:
|
if complete:
|
||||||
return
|
return
|
||||||
trials[-1] = replace(trials[-1], selection="incomplete-layout")
|
trials[-1] = replace(trials[-1], selection="incomplete-layout")
|
||||||
|
|
@ -142,12 +142,12 @@ class _RetryExperiment(_AutomaticRun):
|
||||||
policy: str,
|
policy: str,
|
||||||
check_connectivity: bool = False,
|
check_connectivity: bool = False,
|
||||||
) -> list[Trial]:
|
) -> list[Trial]:
|
||||||
started, first_run = perf_counter(), len(self.metrics)
|
started, first_attempt = perf_counter(), len(self.attempts.samples)
|
||||||
if check_connectivity:
|
if check_connectivity:
|
||||||
with self._time("plan", policy=policy):
|
with self._time("plan", policy=policy):
|
||||||
blocked = _disconnected_nets(self.problem, self.board, options, retained)
|
blocked = _disconnected_nets(self.problem, self.board, options, retained)
|
||||||
if blocked:
|
if blocked:
|
||||||
self._record_retry(policy, "disconnected", started, first_run)
|
self._record_retry(policy, "disconnected", started, first_attempt)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
retry = replace(
|
retry = replace(
|
||||||
|
|
@ -164,7 +164,7 @@ class _RetryExperiment(_AutomaticRun):
|
||||||
verified = self._verify_incumbent(trial)
|
verified = self._verify_incumbent(trial)
|
||||||
complete = len(verified.valid_costs) == target
|
complete = len(verified.valid_costs) == target
|
||||||
trials.append(verified if complete else replace(verified, selection="incomplete-layout"))
|
trials.append(verified if complete else replace(verified, selection="incomplete-layout"))
|
||||||
self._record_retry(policy, "complete" if complete else "incomplete", started, first_run)
|
self._record_retry(policy, "complete" if complete else "incomplete", started, first_attempt)
|
||||||
return trials
|
return trials
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue