Preserve route identity through reservation and export

This commit is contained in:
Jan Petykiewicz 2026-11-29 00:12:59 -08:00
commit 286caa273b

View file

@ -5,7 +5,7 @@ from shapely import union_all
from shapely.geometry import Polygon, box
from inire import (
Bend90Seed, CongestionOptions, NetSpec, PathSeed, Port, RefinementOptions,
Bend90Seed, CongestionOptions, FixedRoute, NetSpec, PathSeed, Port, RefinementOptions,
RoutingOptions, RoutingProblem, SBendOutline, SBendSeed, SearchOptions, StraightSeed, TopologyOptions, route,
)
from inire.layout import PlacedPort, coplanar_geometry, partition_layers, preserves_length, route_profiles, verify_export_grid
@ -46,6 +46,49 @@ def test_export_verifies_actual_rounded_bend_clearance(outer_radius, grid, valid
assert all(report.dynamic_collision_count == int(not valid) for report in exported.reports_by_net.values())
def test_export_rejects_stale_net_specs_and_accepts_legacy_results() -> None:
net = NetSpec("track", Port(10, 20, 0), Port(90, 20, 0))
problem = RoutingProblem((0, 0, 100, 50), (net,))
results = route(problem).results_by_net
result = results["track"]
assert result.requested_net == net
assert result.effective_net == net
for stale in (replace(net, width=6), replace(net, target=Port(90, 20, 90))):
with pytest.raises(ValueError, match="different"):
verify_export_grid(replace(problem, nets=(stale,)), results, grid=1)
legacy = replace(result, requested_net=None, effective_net=None)
assert verify_export_grid(problem, {"track": legacy}, grid=1).is_valid
@pytest.mark.parametrize("mode", ["automatic", "off", "guide", "seed"])
@pytest.mark.parametrize(("start_x", "y", "valid"), [(10, 22, False), (40, 22, False), (40, 23, True)])
def test_imported_fixed_routes_hold_clearance_at_edges_and_vertices(mode, start_x, y, valid) -> None:
net = NetSpec("new", Port(start_x, y, 0), Port(90, y, 0))
fixed = FixedRoute("existing", (box(10, 19, 40, 21),))
problem = RoutingProblem((0, 0, 100, 50), (net,), clearance=0, fixed_routes=(fixed,))
options = RoutingOptions(
search=SearchOptions(node_limit=20, bend_radii=(), sbend_radii=()),
topology=TopologyOptions(mode=mode),
)
results = route(problem, options=options).results_by_net
assert set(results) == {"new"}
assert results["new"].is_valid is valid
if valid:
assert verify_export_grid(problem, results, grid=1).is_valid
def test_fixed_route_from_result_preserves_polygon_and_owner() -> None:
net = NetSpec("first", Port(10, 20, 0), Port(90, 20, 0))
problem = RoutingProblem((0, 0, 100, 50), (net,))
fixed = FixedRoute.from_result(route(problem).results_by_net["first"])
assert fixed.net_id == net.net_id
assert fixed.polygons[0].equals(box(10, 19, 90, 21))
with pytest.raises(ValueError, match="Duplicate active or fixed"):
replace(problem, fixed_routes=(fixed,))
@pytest.mark.parametrize(("keepout_y", "clearance", "valid"), [(21, 0.2, False), (21.2, 0.4, False), (21.25, 0.2, True)])
def test_export_checks_keepout_clearance_smaller_than_the_grid(keepout_y, clearance, valid) -> None:
net = NetSpec("signal", Port(10, 20, 0), Port(90, 20, 0), 1.4)