Share routing preparation and report benchmark worker options
This commit is contained in:
parent
266aeb6c5e
commit
8c8cbe569b
1 changed files with 152 additions and 43 deletions
|
|
@ -12,7 +12,7 @@ from statistics import median
|
|||
from time import perf_counter
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from inire import route
|
||||
from inire import _route, route
|
||||
from inire.router._automatic import _AutomaticRun
|
||||
from inire.router._routing_policy import LockPlan, _best_trial, _disconnected_nets, _route_residual
|
||||
from inire.tests.routing_corpus import (
|
||||
|
|
@ -28,8 +28,9 @@ from inire.tests.routing_corpus import (
|
|||
if TYPE_CHECKING:
|
||||
from typing import Literal
|
||||
|
||||
from inire import _IterationCallback
|
||||
from inire.model import RoutingOptions, RoutingProblem
|
||||
from inire.results import RoutingResult
|
||||
from inire.results import RoutingResult, RoutingRunResult
|
||||
from inire.router._routing_policy import Trial
|
||||
from inire.seeds import PathSeed
|
||||
from inire.tests.routing_benchmark_case import BenchmarkCase
|
||||
|
|
@ -54,8 +55,14 @@ _POLICIES = {
|
|||
|
||||
|
||||
class _RetryExperiment(_AutomaticRun):
|
||||
def __init__(self, problem: RoutingProblem, options: RoutingOptions, policy: _RetryPolicy) -> None:
|
||||
super().__init__(problem, options, None)
|
||||
def __init__(
|
||||
self,
|
||||
problem: RoutingProblem,
|
||||
options: RoutingOptions,
|
||||
iteration_callback: _IterationCallback | None,
|
||||
policy: _RetryPolicy,
|
||||
) -> None:
|
||||
super().__init__(problem, options, iteration_callback)
|
||||
self.retry_policy = policy
|
||||
self.retry_attempts: list[dict] = []
|
||||
|
||||
|
|
@ -179,12 +186,21 @@ def _near_port_coverage_stalled(trials: list[Trial], target: int) -> bool:
|
|||
|
||||
def _measure(case: BenchmarkCase, profile: str, name: str) -> dict:
|
||||
options = automatic_options(profile_options(case, profile), profile)
|
||||
retry_attempts: list[dict] = []
|
||||
|
||||
def run_experiment(
|
||||
problem: RoutingProblem, options: RoutingOptions, iteration_callback: _IterationCallback | None,
|
||||
) -> RoutingRunResult:
|
||||
experiment = _RetryExperiment(problem, options, iteration_callback, _POLICIES[name])
|
||||
run = experiment.execute()
|
||||
retry_attempts.extend(experiment.retry_attempts)
|
||||
return run
|
||||
|
||||
started = perf_counter()
|
||||
experiment = None if name == "baseline" else _RetryExperiment(case.problem, options, _POLICIES[name])
|
||||
if experiment is None:
|
||||
if name == "baseline":
|
||||
run = route(case.problem, options=options)
|
||||
else:
|
||||
run = experiment.execute()
|
||||
run = _route(case.problem, options=options, run_router=run_experiment)
|
||||
elapsed = perf_counter() - started
|
||||
report = run.automatic
|
||||
assert report is not None
|
||||
|
|
@ -199,7 +215,7 @@ def _measure(case: BenchmarkCase, profile: str, name: str) -> dict:
|
|||
"seeds": {net_id: repr(run.results_by_net[net_id].as_seed()) for net_id in verified},
|
||||
"stages": [asdict(stage) for stage in report.stages],
|
||||
"selected_stage": report.selected_stage,
|
||||
"retry_attempts": [] if experiment is None else experiment.retry_attempts,
|
||||
"retry_attempts": retry_attempts,
|
||||
"timings": [asdict(timing) for timing in report.timings],
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue