Make retry exports optional and report benchmark placement and selection
This commit is contained in:
parent
f247cff54a
commit
f6e7bac4c5
1 changed files with 78 additions and 20 deletions
|
|
@ -22,6 +22,7 @@ from inire.tests.routing_corpus import (
|
|||
benchmark_weighted_length,
|
||||
native_verified_costs,
|
||||
profile_options,
|
||||
route_placement,
|
||||
select_cases,
|
||||
)
|
||||
|
||||
|
|
@ -184,7 +185,7 @@ def _near_port_coverage_stalled(trials: list[Trial], target: int) -> bool:
|
|||
return len(first.valid_costs) == target - 1 and first.valid_costs.keys() == second.valid_costs.keys()
|
||||
|
||||
|
||||
def _measure(case: BenchmarkCase, profile: str, name: str) -> dict:
|
||||
def _measure(case: BenchmarkCase, profile: str, name: str, *, capture_details: bool = True) -> dict:
|
||||
options = automatic_options(profile_options(case, profile), profile)
|
||||
retry_attempts: list[dict] = []
|
||||
|
||||
|
|
@ -205,14 +206,17 @@ def _measure(case: BenchmarkCase, profile: str, name: str) -> dict:
|
|||
report = run.automatic
|
||||
assert report is not None
|
||||
verified = sorted(report.verified_net_ids)
|
||||
summary = {"elapsed_s": elapsed, "verified": verified}
|
||||
if not capture_details:
|
||||
return summary
|
||||
return {
|
||||
"elapsed_s": elapsed,
|
||||
"verified": verified,
|
||||
**summary,
|
||||
"routing_bound": report.max_routed,
|
||||
"nodes_expanded": run.metrics.nodes_expanded,
|
||||
"weighted_cost": {net_id: benchmark_weighted_length(run.results_by_net[net_id]) for net_id in verified},
|
||||
"native_cost": native_verified_costs(case, options, run.results_by_net, verified),
|
||||
"seeds": {net_id: repr(run.results_by_net[net_id].as_seed()) for net_id in verified},
|
||||
"placements": {net_id: route_placement(run.results_by_net[net_id]) for net_id in verified},
|
||||
"stages": [asdict(stage) for stage in report.stages],
|
||||
"selected_stage": report.selected_stage,
|
||||
"retry_attempts": retry_attempts,
|
||||
|
|
@ -220,13 +224,13 @@ def _measure(case: BenchmarkCase, profile: str, name: str) -> dict:
|
|||
}
|
||||
|
||||
|
||||
def _measure_case(job: tuple[BenchmarkCase, str, tuple[str, ...], int]) -> dict:
|
||||
case, profile, policies, repeats = job
|
||||
def _measure_case(job: tuple[BenchmarkCase, str, tuple[str, ...], int, bool]) -> dict:
|
||||
case, profile, policies, repeats, capture_details = job
|
||||
samples = {name: [] for name in policies}
|
||||
for index in range(repeats):
|
||||
offset = index % len(policies)
|
||||
for name in policies[offset:] + policies[:offset]:
|
||||
samples[name].append(_measure(case, profile, name))
|
||||
samples[name].append(_measure(case, profile, name, capture_details=capture_details))
|
||||
return {"case": case.name, "profile": profile, "required": len(case.problem.nets), "samples": samples}
|
||||
|
||||
|
||||
|
|
@ -237,24 +241,27 @@ def main() -> None:
|
|||
parser.add_argument("--policy", choices=tuple(_POLICIES), action="append")
|
||||
parser.add_argument("--repeat", type=int, default=1)
|
||||
parser.add_argument("--jobs", type=int, default=1)
|
||||
parser.add_argument("--json", type=Path, required=True)
|
||||
parser.add_argument("--json", type=Path, help="Write per-run coverage, placement, costs, and retry details to this file.")
|
||||
args = parser.parse_args()
|
||||
if args.repeat < 1 or args.jobs < 1:
|
||||
parser.error("--repeat and --jobs must be positive")
|
||||
cases = select_cases(args.case or ["corpus"])
|
||||
profiles = tuple(dict.fromkeys(args.profile or ("public-defaults", "corpus-regression")))
|
||||
policies = tuple(dict.fromkeys(args.policy or _POLICIES))
|
||||
jobs = [(case, profile, policies, args.repeat) for case in cases for profile in profiles]
|
||||
capture_details = args.json is not None
|
||||
jobs = [(case, profile, policies, args.repeat, capture_details) for case in cases for profile in profiles]
|
||||
rows = []
|
||||
with ProcessPoolExecutor(max_workers=args.jobs) as pool:
|
||||
for result in pool.map(_measure_case, jobs):
|
||||
rows.append(result)
|
||||
if capture_details:
|
||||
rows.append(result)
|
||||
summary = " ".join(
|
||||
f"{name}={len(samples[0]['verified'])}/{result['required']}@{median(s['elapsed_s'] for s in samples):.3f}s"
|
||||
for name, samples in result["samples"].items()
|
||||
)
|
||||
print(result["case"], result["profile"], summary, flush=True)
|
||||
args.json.write_text(dumps({"runs": rows}, indent=2) + "\n", encoding="utf-8")
|
||||
if args.json is not None:
|
||||
args.json.write_text(dumps({"runs": rows}, indent=2) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue