inire/docs/routing-diagnostics.md

67 lines
7 KiB
Markdown
Raw Normal View History

# Routing diagnostics and metrics
Use coverage and physical path verification to establish correctness. Then compare path cost, expansions, and wall time at the same geometry, search budgets, and refinement settings. [Benchmark profiles](topological-routing.md#reproduce-a-comparison)
## Automatic reports
| Field | Interpretation |
| --- | --- |
| `verified_net_ids`, `max_routed` | Verified IDs in the selected layout and the upper bound. `capacity_limit` identifies an applicable vertical cut. `port_conflicts` identifies disjoint conflicts between fixed terminals. |
| `selected_stage`, `selected_planner` | Index and planner name of the chosen stage. A refinement stage can win. |
| `stages` | Search, verification, and refinement attempts with verified, locked, skipped, and out-of-bounds net IDs as applicable. Each stage has a planner, worker mode, operation, node limit, and optional policy and retry reason. |
| `planner_rejections`, `cost_pass_performed` | Rejected constructive candidates and whether weighted column scoring ran. |
| `timings`, `duration_s` | Exclusive wall time for planning, search, verification, and refinement, including unsuccessful work. Total duration also includes orchestration between timed operations. |
A stage's `mode` names its worker. Its `planner` identifies the algorithm that proposed the layout. A bundle candidate can use an `off` worker for seed verification. `run.topology`, when populated, describes the selected worker's corridor counts, seeded nets, and constrained seed expansions. Detailed traces and expanded states describe the selected attempt. By comparison, `run.metrics` sums the workers' counters across attempts. [Report definitions](../inire/results.py)
## RouteMetrics
The counters measure work, so a net can contribute to multiple attempts. Count final verified nets with `result.is_valid` or `run.automatic.verified_net_ids`.
| Question | Counters |
| --- | --- |
| How much search ran? | `nodes_expanded`, `moves_generated`, `moves_added`, and `pruned_*` measure expansion, admission, and pruning. `warm_start_paths_built` and `warm_start_paths_used` track seed creation and reuse. |
| Did congestion settle? | `route_iterations`, `nets_routed`, and `nets_reached_target` count iterations and attempts. `iteration_reverified_nets`, `iteration_conflict_edges`, and `nets_carried_forward` show verification work, conflicts, and reuse. |
| Which geometric queries dominate? | `ray_cast_calls*` splits rays by caller. `ray_cast_candidate_bounds` and `ray_cast_exact_geometry_checks` distinguish broad-phase and exact tests. Tree and grid rebuild counts measure index maintenance. |
| How many dynamic candidates reach exact tests? | `congestion_check_calls`, `congestion_candidate_ids`, and `congestion_exact_pair_checks` track queries, candidate objects, and confirmed geometry tests. Cache and precheck counters record reused work and conservative skips. |
| What did final checks cost? | `verify_path_report_calls`, `verify_static_buffer_ops`, `verify_dynamic_candidate_nets`, and `verify_dynamic_exact_pair_checks` track verification work. |
| Was local repair or refinement productive? | `pair_local_search_*` tracks considered pairs, attempts, accepted replacements, and expansions. `late_phase_capped_*` tracks carried incumbents before repair. `refinement_*` counts windows, candidate construction, checks, and accepted changes. |
`*_total_ns` fields report measured durations. Stable counters help compare algorithmic changes. Repeated wall times reveal costs that counters miss. The [counter schema](../inire/results.py) lists every field. The [committed example snapshot](performance.md) and its [JSON](performance_baseline.json) record historical observations.
## Traces
Enable the corresponding `DiagnosticsOptions` flag to populate a trace. Trace entries are immutable. Use an `iteration_callback` for live snapshots across attempts. Automatic callback indices increase across workers and the callback count follows the actual schedule.
| Result field | Contents | Example |
| --- | --- | --- |
| `iteration_trace` | Per-iteration verified coverage, congestion penalty, conflict counts, and A* work. `net_attempts` attributes expansions, pruning, congestion calls, and seed usage to each rerouted net. | [Iteration trace](iteration_trace.md) |
| `conflict_trace` | Post-iteration, restored-best, and final conflict snapshots. Each entry includes complete net IDs, undirected dynamic conflict edges, and the component indices responsible for those edges. Static and self-collision details are counts in each routing report. | [Conflict trace](conflict_trace.md) |
| `frontier_trace` | Analysis-only reruns of final reached-but-colliding nets. Records counts and sampled prune events near dynamic overlap hotspots, including move type, state, and reason. | [Frontier trace](frontier_trace.md) |
| `pre_pair_frontier_trace` | The relevant unresolved subset iteration before pair-local repair. Records reroute order, conflict edges, per-net attempt work, and targeted frontier analysis. | [Pre-pair trace](pre_pair_frontier_trace.md) |
| `expanded_nodes` | Explored integer port states from searches that capture expansions. | [Fan-out example](../examples/07_large_scale_routing.py) |
Frontier analysis leaves the route result fixed. Pair-local repair runs as part of routing and can change the installed paths after a successful whole-set check.
## Reproduce and compare
Capture the same profiles at both revisions for a behavior-preserving change. Exact parity checks results, verified net IDs, path seeds, both costs, stage order and metadata, and stable counters. Add `--callbacks` and `--diagnostics` to both captures to include live callback payloads and detailed traces.
```sh
python -m scripts.routing_benchmark_parity capture /tmp/routing-before.json
# Run the next capture with the same options on the changed revision.
python -m scripts.routing_benchmark_parity capture /tmp/routing-after.json
python -m scripts.routing_benchmark_parity compare /tmp/routing-before.json /tmp/routing-after.json
```
For a policy change, compare coverage, verified IDs, paths, and costs before examining intended changes to stage work. Use interleaved repeats for timings. Report the median per board and compare tail boards by name. Separate work inside failed retries from total routing time.
```sh
python -m scripts.record_performance_baseline --output-dir /tmp/inire-perf
python -m scripts.diff_performance_baseline --metric nodes_expanded --metric ray_cast_calls
python -m scripts.record_iteration_trace --output-dir /tmp/inire-iteration
python -m scripts.record_pre_pair_frontier_trace --output-dir /tmp/inire-pre-pair
INIRE_RUN_PERFORMANCE=1 python -m pytest -q inire/tests/test_example_performance.py
```
The trace writers also support `--scenario` and `--include-performance-only`. Use `scripts.record_conflict_trace` and `scripts.record_frontier_trace` for individual hotspot investigations. The [pair-local characterization](pair_local_characterization.md) and [optimization log](optimization_pass_01_log.md) preserve earlier experiments.