Refactor routing internals and archive retry benchmarks
This commit is contained in:
parent
a8720ac8c9
commit
ea5cfe7f31
1 changed files with 3481 additions and 2583 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from functools import partial
|
||||
from time import perf_counter
|
||||
from typing import TYPE_CHECKING
|
||||
from collections.abc import Callable
|
||||
|
||||
from shapely.geometry import Polygon, box
|
||||
|
|
@ -22,14 +23,17 @@ from inire import (
|
|||
)
|
||||
from inire.geometry.collision import RoutingWorld
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.results import RouteMetrics
|
||||
from inire.results import RouteMetrics, _sum_route_metrics
|
||||
from inire.router._astar_types import AStarContext, AStarMetrics
|
||||
from inire.router._router import PathFinder
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.tests.routing_benchmarks import BENCHMARK_CASES, EXTERNAL_BENCHMARK_CASES, FALLBACK_BENCHMARK_CASES, BenchmarkCase
|
||||
from inire.tests.routing_corpus import SNAPSHOT_CASES, profile_options
|
||||
from inire.tests.terminal_bench_scenario import terminal_bench_options, terminal_bench_problem
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from inire.tests.routing_benchmark_case import BenchmarkCase
|
||||
|
||||
_SEARCH_FIELDS = set(SearchOptions.__dataclass_fields__)
|
||||
_CONGESTION_FIELDS = set(CongestionOptions.__dataclass_fields__)
|
||||
_REFINEMENT_FIELDS = set(RefinementOptions.__dataclass_fields__)
|
||||
|
|
@ -100,16 +104,6 @@ def _make_run_result(
|
|||
)
|
||||
|
||||
|
||||
def _sum_metrics(metrics_list: tuple[RouteMetrics, ...]) -> RouteMetrics:
|
||||
metric_names = RouteMetrics.__dataclass_fields__
|
||||
return RouteMetrics(
|
||||
**{
|
||||
name: sum(getattr(metrics, name) for metrics in metrics_list)
|
||||
for name in metric_names
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _build_evaluator(
|
||||
bounds: tuple[float, float, float, float],
|
||||
*,
|
||||
|
|
@ -276,7 +270,7 @@ def snapshot_example_03() -> ScenarioSnapshot:
|
|||
)
|
||||
results_b = pathfinder_b.route_all()
|
||||
t1 = perf_counter()
|
||||
combined_metrics = _sum_metrics((metrics_a, pathfinder_b.metrics.snapshot()))
|
||||
combined_metrics = _sum_route_metrics((metrics_a, pathfinder_b.metrics.snapshot()))
|
||||
return _make_snapshot("example_03_locked_paths", {**results_a, **results_b}, t1 - t0, combined_metrics)
|
||||
|
||||
|
||||
|
|
@ -408,7 +402,7 @@ def snapshot_example_06() -> ScenarioSnapshot:
|
|||
"example_06_bend_collision_models",
|
||||
combined_results,
|
||||
t1 - t0,
|
||||
_sum_metrics(tuple(route_metrics)),
|
||||
_sum_route_metrics(route_metrics),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -610,7 +604,7 @@ def snapshot_example_08() -> ScenarioSnapshot:
|
|||
)
|
||||
results_custom = pathfinder_custom.route_all()
|
||||
t1 = perf_counter()
|
||||
combined_metrics = _sum_metrics((pathfinder_std.metrics.snapshot(), pathfinder_custom.metrics.snapshot()))
|
||||
combined_metrics = _sum_route_metrics((pathfinder_std.metrics.snapshot(), pathfinder_custom.metrics.snapshot()))
|
||||
return _make_snapshot(
|
||||
"example_08_custom_bend_geometry",
|
||||
{**results_std, **results_custom},
|
||||
|
|
@ -657,7 +651,7 @@ def snapshot_terminal_bench_pr345() -> ScenarioSnapshot:
|
|||
|
||||
def _snapshot_routing_benchmark(case: BenchmarkCase) -> ScenarioSnapshot:
|
||||
start = perf_counter()
|
||||
run = route(case.problem, options=case.options)
|
||||
run = route(case.problem, options=profile_options(case, "fixture"))
|
||||
return _make_snapshot(f"routing_benchmark_{case.name.replace('-', '_')}", run.results_by_net, perf_counter() - start, run.metrics)
|
||||
|
||||
|
||||
|
|
@ -691,8 +685,7 @@ PERFORMANCE_SCENARIO_SNAPSHOTS: tuple[tuple[str, ScenarioSnapshotRun], ...] = (
|
|||
("terminal_bench_pr345", snapshot_terminal_bench_pr345),
|
||||
*(
|
||||
(f"routing_benchmark_{case.name.replace('-', '_')}", partial(_snapshot_routing_benchmark, case))
|
||||
for case in (*BENCHMARK_CASES, *FALLBACK_BENCHMARK_CASES, *EXTERNAL_BENCHMARK_CASES)
|
||||
if case.name != "terminal-bench"
|
||||
for case in SNAPSHOT_CASES
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue