2026-04-02 16:15:02 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from collections import Counter
|
|
|
|
|
from dataclasses import asdict
|
2026-11-26 19:58:46 -08:00
|
|
|
from typing import TYPE_CHECKING
|
2026-04-02 16:15:02 -07:00
|
|
|
|
2026-11-26 19:58:46 -08:00
|
|
|
from inire.tests.trace_recording import NO_WARM_START_SCENARIOS, record_trace
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from inire.results import RoutingRunResult
|
2026-04-02 16:15:02 -07:00
|
|
|
|
|
|
|
|
|
2026-11-26 19:58:46 -08:00
|
|
|
def _scenario_payload(result: RoutingRunResult) -> dict[str, object]:
|
|
|
|
|
return {"iteration_trace": [asdict(entry) for entry in result.iteration_trace]}
|
2026-04-02 16:15:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _render_markdown(payload: dict[str, object]) -> str:
|
|
|
|
|
lines = [
|
|
|
|
|
"# Iteration Trace",
|
|
|
|
|
"",
|
|
|
|
|
f"Generated at {payload['generated_at']} by `{payload['generator']}`.",
|
|
|
|
|
"",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for scenario in payload["scenarios"]:
|
|
|
|
|
lines.extend(
|
|
|
|
|
[
|
|
|
|
|
f"## {scenario['name']}",
|
|
|
|
|
"",
|
|
|
|
|
f"Results: {scenario['summary']['valid_results']} valid / "
|
|
|
|
|
f"{scenario['summary']['reached_targets']} reached / "
|
|
|
|
|
f"{scenario['summary']['total_results']} total.",
|
|
|
|
|
"",
|
2026-11-26 19:58:46 -08:00
|
|
|
"| Iteration | Penalty | Routed Nets | Completed | Conflict Edges | Dynamic Collisions | "
|
|
|
|
|
"Nodes | Congestion Checks | Candidate Ids | Exact Pairs |",
|
2026-04-02 16:15:02 -07:00
|
|
|
"| --: | --: | --: | --: | --: | --: | --: | --: | --: | --: |",
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
net_node_counts: Counter[str] = Counter()
|
|
|
|
|
net_check_counts: Counter[str] = Counter()
|
|
|
|
|
for entry in scenario["iteration_trace"]:
|
|
|
|
|
lines.append(
|
|
|
|
|
"| "
|
|
|
|
|
f"{entry['iteration']} | "
|
|
|
|
|
f"{entry['congestion_penalty']:.1f} | "
|
|
|
|
|
f"{len(entry['routed_net_ids'])} | "
|
|
|
|
|
f"{entry['completed_nets']} | "
|
|
|
|
|
f"{entry['conflict_edges']} | "
|
|
|
|
|
f"{entry['total_dynamic_collisions']} | "
|
|
|
|
|
f"{entry['nodes_expanded']} | "
|
|
|
|
|
f"{entry['congestion_check_calls']} | "
|
|
|
|
|
f"{entry['congestion_candidate_ids']} | "
|
|
|
|
|
f"{entry['congestion_exact_pair_checks']} |"
|
|
|
|
|
)
|
|
|
|
|
for attempt in entry["net_attempts"]:
|
|
|
|
|
net_node_counts[attempt["net_id"]] += attempt["nodes_expanded"]
|
|
|
|
|
net_check_counts[attempt["net_id"]] += attempt["congestion_check_calls"]
|
|
|
|
|
|
|
|
|
|
lines.extend(["", "Top nets by iteration-attributed nodes expanded:", ""])
|
|
|
|
|
if net_node_counts:
|
|
|
|
|
for net_id, count in net_node_counts.most_common(10):
|
|
|
|
|
lines.append(f"- `{net_id}`: {count}")
|
|
|
|
|
else:
|
|
|
|
|
lines.append("- None")
|
|
|
|
|
|
|
|
|
|
lines.extend(["", "Top nets by iteration-attributed congestion checks:", ""])
|
|
|
|
|
if net_check_counts:
|
|
|
|
|
for net_id, count in net_check_counts.most_common(10):
|
|
|
|
|
lines.append(f"- `{net_id}`: {count}")
|
|
|
|
|
else:
|
|
|
|
|
lines.append("- None")
|
|
|
|
|
|
|
|
|
|
lines.append("")
|
|
|
|
|
|
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2026-11-26 19:58:46 -08:00
|
|
|
record_trace(
|
|
|
|
|
__file__,
|
|
|
|
|
"iteration_trace",
|
|
|
|
|
scenario_label="iteration-trace",
|
|
|
|
|
default_scenarios=NO_WARM_START_SCENARIOS,
|
|
|
|
|
scenario_payload=_scenario_payload,
|
|
|
|
|
render_markdown=_render_markdown,
|
2026-04-02 16:15:02 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|