Fix fabrication verification and routing diagnostics follow-up

This commit is contained in:
Jan Petykiewicz 2026-11-29 00:09:54 -08:00
commit cea23ef1b4
13 changed files with 248 additions and 76 deletions

View file

@ -30,6 +30,8 @@ Search bounds the two move caches by entries and polygon coordinates. It drops t
Enable the `DiagnosticsOptions` flag for the question you want to answer.
When explicit guide or seed mode retries without guidance cost, the returned traces describe the selected attempt. Iteration numbers use the same indices as the progress callback. Work counters include both attempts.
| Question | Flag and result |
| --- | --- |
| Which net consumed an iteration's budget? | `capture_iteration_trace` records `iteration_trace`. Inspect per-net `net_attempts` for expansions, pruning, congestion calls, and seed usage. |

View file

@ -44,7 +44,7 @@ The fields below appear in constructor order. Use one layout unit for coordinate
| `RoutingResult.path` | Ordered path components from the source to the last reached state. An unroutable result has an empty path. |
| `RoutingResult.reached_target` | Whether the path reached the target position and heading. With heading inference, the check uses the chosen heading. Read `is_valid` for the result of geometry verification. |
| `RoutingResult.report` | `total_length` in layout units plus static, dynamic, and self-collision counts. `out_of_bounds` flags geometry outside the board. `discontinuous` flags missing or point-only joins, including at terminal faces. `invalid_geometry` flags invalid or empty physical polygons. `seed_error` identifies a supplied bend that cannot carry the net's width. `terminal_error` identifies an inaccessible start or target face. |
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons and the sequence of moves, respectively. Check validity before exporting polygons or using them as keepouts. |
| `RoutingResult.locked_geometry` and `as_seed()` | Physical polygons and the sequence of moves, respectively. Check validity before exporting polygons or [reserving a completed net](route-a-layout.md#reuse-an-existing-route). |
| `RoutingRunResult.automatic` | In automatic mode, the selected planner, verified IDs, stage history, and any capacity or port-conflict bound. `None` for explicit modes. |
| `RoutingRunResult.topology` and `metrics` | Corridor counts and seed work when reported by the selected worker, plus work counters across the run. |

View file

@ -32,14 +32,15 @@ An authored 286.770 µm path in the Raymond MZI array can be replaced geometrica
## Check the export grid
Use the layout writer's rounding grid in routing units. `verify_export_grid` rounds route vertices while holding the supplied keepouts fixed. Supply the actual keepout geometry as it will appear in the file. Export the returned polygons only if their reports pass. Recheck the assembled cell after writing when the writer performs further operations such as path merging or coordinate transforms.
Use the layout writer's rounding grid in routing units. `verify_export_grid` rounds route vertices while holding the supplied keepouts fixed. Supply the keepout geometry as it will appear in the file and pass all intended routes on the layer in one call so they are checked against each other. The function requires each supplied result to have passed routing verification. Recheck the assembled cell after writing when the writer performs further operations such as path merging or coordinate transforms.
```python
from inire.layout import verify_export_grid
verified = {name: result for name, result in run.results_by_net.items() if result.is_valid}
export = verify_export_grid(problem, verified, grid=1.0)
assert export.is_valid, export.reports_by_net
results = {net.net_id: run.results_by_net[net.net_id] for net in problem.nets}
export = verify_export_grid(problem, results, grid=1.0)
if not export.is_valid:
raise ValueError(export.reports_by_net)
geometry_by_net = export.geometry_by_net
```
@ -58,24 +59,32 @@ for layer, nets in partition_layers([((1, 0), silicon_net), ((4, 0), nitride_net
plane = RoutingProblem(bounds, nets, static_obstacles=keepouts_by_layer[layer], clearance=clearance_by_layer[layer])
run = route(plane, options=options_by_layer[layer])
export = verify_export_grid(plane, run.results_by_net, grid=1.0)
assert export.is_valid, export.reports_by_net
if not export.is_valid:
raise ValueError(export.reports_by_net)
geometry_by_layer[layer] = export.geometry_by_net
```
For different bend rules on the same layer, supply each group's allowed radii in `SearchOptions`. `route_profiles` applies those options to search, seed replay, and refinement, and reserves the verified groups in the order supplied. In the QFoundry example, the flux line can use 15 µm radius while the feedline requires at least 50 µm although both have a 15.5 µm signal width and 7 µm gaps. [QFoundry process profiles](https://github.com/tii-qfoundry/PDK_QFoundry/blob/9c31db1d6879c96bd98460ee134181a865481d75/qfoundry/tech/waveguides.xml#L21-L64)
```python
from inire.layout import route_profiles
from inire import RoutingProblem
from inire.layout import route_profiles, verify_export_grid
results = route_profiles(plane, [
(("flux",), flux_options),
(("feed",), feed_options),
cpw_plane = RoutingProblem(
bounds, (flux_net, feed_net), static_obstacles=cpw_keepouts, clearance=ground_strip_width,
)
results = route_profiles(cpw_plane, [
((flux_net.net_id,), flux_options),
((feed_net.net_id,), feed_options),
])
export = verify_export_grid(cpw_plane, results, grid=1.0)
if not export.is_valid:
raise ValueError(export.reports_by_net)
```
## Verify a coplanar waveguide cross-section
For a 15.5 µm signal with a 7 µm gap on each side, route the 29.5 µm envelope. Use the required ground-strip width as the clearance between envelopes. Replay the verified seed with a 15.5 µm net using the same ports and bend rules. The conductor and envelope together define the negative gap mask. A separate wider ground exclusion can be buffered locally from the envelope. This fills the inside of turns where a constant-width circular strip wider than the bend diameter would collapse.
For a 15.5 µm signal with a 7 µm gap on each side, route the 29.5 µm envelope. Use the required ground-strip width as the clearance between envelopes. Replay the verified seed with a 15.5 µm net using the same ports and bend rules. The conductor and envelope together define the negative gap mask. `coplanar_geometry` checks for side contact and allows the gap to end at the terminal faces. Check the process minimum gap in the assembled layout. A separate wider ground exclusion can be buffered locally from the envelope. This fills the inside of turns where a constant-width circular strip wider than the bend diameter would collapse.
```python
from inire.layout import coplanar_geometry

View file

@ -90,7 +90,7 @@ For a multi-net layout, apply the validity check to every net you intend to expo
## Reuse an existing route
- **Give the router a route it can move.** Put `result.as_seed()` in `initial_paths` under the net's ID. A seed uses the current start port, width, and geometry settings. Search can follow a partial seed from the first iteration and can leave it to find another approach. To build a hint from turns and straights, see the [path seed reference](api-reference.md#path-seeds).
- **Hold a route fixed.** Check `result.is_valid`, then add `result.locked_geometry` to `static_obstacles` while routing other nets. The next run applies its own clearance to those polygons.
- **Hold a route fixed.** Check `result.is_valid`, then replay its seed in the first group of `route_profiles` with search and refinement disabled. Later groups respect it as a distinct net, including at zero clearance. Verify the groups together before [exporting the layer](fabrication.md#check-the-export-grid).
When terminal headings are inferred, store the two selected ports alongside the seed, width, and geometry options. Use those exact ports to replay the route and export the same polygons.
@ -123,30 +123,30 @@ for net in verified_nets:
assert result.locked_geometry == chosen.results_by_net[net.net_id].locked_geometry
```
Route a straight net, then use its polygons as keepouts in a second routing problem. The second net has to detour around one end of the fixed route.
Route a straight net, then reserve it while routing another net on the same layer. The second net has to detour around one end of the fixed route.
```python
from inire import (
NetSpec, Port, RoutingOptions,
RoutingProblem, SearchOptions, route,
)
from dataclasses import replace
from inire import NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.layout import route_profiles, verify_export_grid
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
first = RoutingProblem(
bounds=bounds,
nets=(NetSpec("fixed", Port(10, 0, 0), Port(90, 0, 0)),),
)
fixed = route(first, options=options).results_by_net["fixed"]
fixed_net = NetSpec("fixed", Port(10, 0, 0), Port(90, 0, 0))
detour_net = NetSpec("detour", Port(50, -20, 90), Port(50, 20, 90))
problem = RoutingProblem(bounds=bounds, nets=(fixed_net, detour_net), clearance=0)
fixed = route(replace(problem, nets=(fixed_net,)), options=options).results_by_net["fixed"]
assert fixed.is_valid
second = RoutingProblem(
bounds=bounds,
nets=(NetSpec("detour", Port(50, -20, 90), Port(50, 20, 90)),),
static_obstacles=fixed.locked_geometry,
replay_options = replace(
options, search=replace(options.search, node_limit=0), refinement=RefinementOptions(enabled=False),
)
detour = route(second, options=options).results_by_net["detour"]
assert detour.is_valid
problem = replace(problem, initial_paths={"fixed": fixed.as_seed()})
results = route_profiles(problem, [(("fixed",), replay_options), (("detour",), options)])
export = verify_export_grid(problem, results, grid=1.0)
if not export.is_valid:
raise ValueError(export.reports_by_net)
```
To compare the two paths on a plot, see the [fixed-route example](../../examples/README.md#route-around-fixed-geometry).

View file

@ -1,4 +1,7 @@
from inire import NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
from dataclasses import replace
from inire import NetSpec, ObjectiveWeights, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
from inire.layout import route_profiles, verify_export_grid
from inire.utils.visualization import plot_routing_results
@ -8,30 +11,28 @@ def main() -> None:
bounds = (0, -50, 100, 50)
options = RoutingOptions(
search=SearchOptions(bend_radii=(10.0,)),
# Isolate the lattice detour and use the fixed net only for clearance checks.
# Isolate the lattice detour.
objective=ObjectiveWeights(danger_weight=0.0),
topology=TopologyOptions(mode="off"),
)
print("Routing initial net...")
problem_a = RoutingProblem(
bounds=bounds,
nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0)),),
)
results_a = route(problem_a, options=options).results_by_net
fixed = results_a["netA"]
fixed_net = NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0))
detour_net = NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90))
problem = RoutingProblem(bounds, (fixed_net, detour_net))
fixed = route(replace(problem, nets=(fixed_net,)), options=options).results_by_net["netA"]
assert fixed.is_valid
print("Routing detour net around locked path...")
problem_b = RoutingProblem(
bounds=bounds,
nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90)),),
static_obstacles=fixed.locked_geometry,
replay = replace(
options, search=replace(options.search, node_limit=0), refinement=RefinementOptions(enabled=False),
)
results_b = route(problem_b, options=options).results_by_net
assert results_b["netB"].is_valid
problem = replace(problem, initial_paths={"netA": fixed.as_seed()})
results = route_profiles(problem, [(("netA",), replay), (("netB",), options)])
export = verify_export_grid(problem, results, grid=1)
if not export.is_valid:
raise ValueError(export.reports_by_net)
results = {**results_a, **results_b}
fig, _ax = plot_routing_results(results, [], bounds)
fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png")

View file

@ -20,7 +20,7 @@ After [installing Inire](../README.md#install), run the example scripts with Pyt
![A second waveguide makes a U-shaped detour around the left end of a fixed straight waveguide.](03_locked_paths.png)
The first call routes a straight waveguide. The second uses its polygons as keepouts, so the new connection passes to the left of the fixed route. Run [`03_locked_paths.py`](03_locked_paths.py) to reproduce the detour. To hold a route fixed in your own design, follow the [route reuse workflow](../docs/user/route-a-layout.md#reuse-an-existing-route).
The first call routes a straight waveguide. `route_profiles` replays and reserves it, so the new connection passes to the left of the fixed route. The example verifies both routes together on the export grid. Run [`03_locked_paths.py`](03_locked_paths.py) to reproduce the detour. To hold a route fixed in your own design, follow the [route reuse workflow](../docs/user/route-a-layout.md#reuse-an-existing-route).
<a id="fit-bends-to-available-room"></a>

View file

@ -376,10 +376,21 @@ class RoutingWorld:
frozen_net_ids: frozenset[str] = frozenset(),
) -> DynamicCongestionDetail:
"""Use physical clearance when admitting a move with a hard obstacle."""
metrics = self.metrics
if metrics is not None:
metrics.total_congestion_check_calls += 1
hits = set()
for polygon in result.physical_geometry:
for other_net_id, _index, other in self._physical_candidates(net_id, polygon):
if other_net_id in hits or not _violates_net_clearance(polygon, other, self.clearance):
candidates = self._physical_candidates(net_id, polygon)
if metrics is not None and candidates:
metrics.total_congestion_candidate_nets += len({other_net_id for other_net_id, _, _ in candidates})
metrics.total_congestion_candidate_ids += len(candidates)
for other_net_id, _index, other in candidates:
if other_net_id in hits:
continue
if metrics is not None:
metrics.total_congestion_exact_pair_checks += 1
if not _violates_net_clearance(polygon, other, self.clearance):
continue
if other_net_id in frozen_net_ids:
return DynamicCongestionDetail(soft_overlap_count=len(hits), hits_frozen_net=True)
@ -681,13 +692,10 @@ class RoutingWorld:
grid_net_cache: dict[tuple[str, int, int, int, int], tuple[str, ...]] | None = None,
broad_phase_cache: dict[tuple[str, int, int, int, int], dict[str, tuple[int, ...]]] | None = None,
) -> DynamicCongestionDetail:
if self.metrics is not None:
self.metrics.total_congestion_check_calls += 1
dynamic_paths = self._dynamic_paths
if not dynamic_paths.geometries:
return DynamicCongestionDetail()
if not self.clearance or frozen_net_ids:
return self.check_physical_move_congestion(result, net_id, frozen_net_ids=frozen_net_ids)
if self.metrics is not None:
self.metrics.total_congestion_check_calls += 1
candidates_by_net = self._collect_congestion_candidates(
result,
@ -696,8 +704,6 @@ class RoutingWorld:
grid_net_cache,
broad_phase_cache,
)
if not candidates_by_net:
return DynamicCongestionDetail()
return self._check_real_congestion(
result,
candidates_by_net,

View file

@ -7,10 +7,12 @@ from math import fsum, isfinite
from typing import TYPE_CHECKING
from shapely import set_precision, union_all
from shapely.geometry import LineString
from inire import route
from inire.constants import TOLERANCE_LINEAR
from inire.geometry.collision import RoutingWorld
from inire.geometry.primitives import rotate_cardinal
from inire.model import NetSpec
if TYPE_CHECKING:
@ -56,7 +58,7 @@ def verify_export_grid(
*,
grid: float,
) -> ExportVerification:
"""Round vertices to the export grid and check the geometry the writer will receive."""
"""Round and check the supplied routes together against the problem's keepouts."""
if not isfinite(grid) or grid <= 0:
raise ValueError("Export grid must be finite and positive")
nets = {net.net_id: net for net in problem.nets}
@ -89,7 +91,11 @@ def verify_export_grid(
def _round_component(component: ComponentResult, grid: float) -> ComponentResult:
rounded = tuple(set_precision(polygon, grid, mode="pointwise") for polygon in component.physical_geometry)
# Keep the snapped vertices while allowing verification at sub-grid clearances.
rounded = tuple(
set_precision(set_precision(polygon, grid, mode="pointwise"), 0, mode="pointwise")
for polygon in component.physical_geometry
)
return replace(
component, physical_geometry=rounded, collision_geometry=rounded,
dilated_physical_geometry=rounded, dilated_collision_geometry=rounded,
@ -130,7 +136,22 @@ def coplanar_geometry(
envelope = union_all(gap_envelope.locked_geometry)
if not envelope.covers(core) and not envelope.buffer(TOLERANCE_LINEAR).covers(core):
raise ValueError("CPW gap envelope must contain its conductor")
return CPWGeometry(core, envelope.difference(core), envelope.buffer(ground_margin) if ground_margin else envelope)
gaps = envelope.difference(core)
if gaps.is_empty:
raise ValueError("CPW gap envelope must leave a nonempty gap")
contact = core.intersection(envelope.boundary)
if not contact.is_empty:
first, last = conductor.path[0], conductor.path[-1]
terminal_regions = []
for port, face in ((first.start_port, first.port_faces[0]), (last.end_port, last.port_faces[1])):
if face is None:
raise ValueError("CPW conductor must have a face at each terminal")
endpoints = [rotate_cardinal(0, offset, int(port.r)) for offset in face[:2]]
terminal = LineString([(port.x + dx, port.y + dy) for dx, dy in endpoints])
terminal_regions.append(terminal.buffer(TOLERANCE_LINEAR))
if not union_all(terminal_regions).covers(contact):
raise ValueError("CPW gap closes away from the terminal faces")
return CPWGeometry(core, gaps, envelope.buffer(ground_margin) if ground_margin else envelope)
def partition_layers(nets_with_layers: Iterable[tuple[tuple[int, int], NetSpec]]) -> dict[tuple[int, int], tuple[NetSpec, ...]]:

View file

@ -7,8 +7,9 @@ from shapely.geometry import Polygon
from inire.constants import TOLERANCE_LINEAR
from inire.geometry.component_overlap import invalid_component_join
from inire.geometry.components import build_component, path_within_board
from inire.geometry.primitives import Port
from inire.geometry.components import bend90_grid_span, build_component, path_within_board
from inire.geometry.primitives import Port, rotate_cardinal
from inire.geometry.sbend import sbend_grid_span
from inire.router.refiner import component_hits_ancestor_chain
from ._astar_types import AStarContext, AStarMetrics, AStarNode, SearchRunConfig
@ -18,6 +19,21 @@ if TYPE_CHECKING:
from ._astar_types import CongestionCaches
def _bend_endpoint_outside_board(start: Port, kind: MoveKind, params: tuple, board: Polygon) -> bool:
if kind == "bend90":
radius, direction = params
forward = bend90_grid_span(radius)
lateral = forward if direction == "CCW" else -forward
else:
lateral, radius = params
forward = sbend_grid_span(lateral, radius)
dx, dy = rotate_cardinal(forward, lateral, int(start.r))
x, y = start.x + dx, start.y + dy
xmin, ymin, xmax, ymax = board.bounds
tol = TOLERANCE_LINEAR
return not (xmin - tol <= x <= xmax + tol and ymin - tol <= y <= ymax + tol)
def process_move(
parent: AStarNode,
target: Port,
@ -74,6 +90,10 @@ def process_move(
else:
context.metrics.total_move_cache_rel_misses += 1
try:
board = context.cost_evaluator.collision_engine.board
# The terminal center must fit before we allocate a tessellated outline.
if board is not None and move_class != "straight" and _bend_endpoint_outside_board(cp, move_class, params, board):
return
res_rel = build_component(
base_port,
net_width,

View file

@ -104,16 +104,7 @@ def route_explicit(
options: RoutingOptions,
iteration_callback: Callable[[int, dict[str, RoutingResult]], None] | None = None,
) -> RoutingRunResult:
start_index = 0
def notify(_iteration: int, results: dict[str, RoutingResult]) -> None:
nonlocal start_index
assert iteration_callback is not None
iteration_callback(start_index, results)
start_index += 1
callback = notify if iteration_callback is not None else None
with_guidance = route_once(problem, options=options, iteration_callback=callback)
with_guidance = route_once(problem, options=options, iteration_callback=iteration_callback)
topology = options.topology
if (
topology.mode not in ("guide", "seed") or not topology.guide_strength
@ -127,8 +118,26 @@ def route_explicit(
options, topology=replace(topology, guide_strength=0.0),
congestion=replace(options.congestion, max_iterations=1),
)
without_guidance = route_once(problem, options=retry, iteration_callback=callback)
offset = with_guidance.metrics.route_iterations
def notify(iteration: int, results: dict[str, RoutingResult]) -> None:
assert iteration_callback is not None
iteration_callback(offset + iteration, results)
without_guidance = route_once(problem, options=retry, iteration_callback=notify if iteration_callback is not None else None)
old_count = sum(result.is_valid for result in with_guidance.results_by_net.values())
new_count = sum(result.is_valid for result in without_guidance.results_by_net.values())
chosen = without_guidance if new_count > old_count else with_guidance
return replace(chosen, metrics=_sum_route_metrics((with_guidance.metrics, without_guidance.metrics)))
metrics = _sum_route_metrics((with_guidance.metrics, without_guidance.metrics))
if new_count <= old_count:
return replace(with_guidance, metrics=metrics)
pre_pair = without_guidance.pre_pair_frontier_trace
return replace(
without_guidance, metrics=metrics,
iteration_trace=tuple(replace(entry, iteration=entry.iteration + offset) for entry in without_guidance.iteration_trace),
conflict_trace=tuple(
replace(entry, iteration=entry.iteration + offset) if entry.iteration is not None else entry
for entry in without_guidance.conflict_trace
),
pre_pair_frontier_trace=replace(pre_pair, iteration=pre_pair.iteration + offset) if pre_pair is not None else None,
)

View file

@ -7,6 +7,7 @@ from shapely.affinity import rotate, translate
from shapely.geometry import Polygon, box
import inire
import inire.geometry.components as components_module
import inire.router._router as router_module
import inire.router._search as search_module
from inire import (
@ -737,6 +738,46 @@ def test_automatic_residual_cannot_touch_a_locked_distinct_net_at_zero_clearance
assert sum(result.is_valid for result in results.values()) == 1
def test_zero_clearance_search_counts_physical_congestion_work() -> None:
nets = (
NetSpec("horizontal", Port(10, 50, 0), Port(90, 50, 0)),
NetSpec("vertical", Port(50, 10, 90), Port(50, 90, 90)),
)
problem = RoutingProblem((0, 0, 100, 100), nets, clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=20, bend_radii=(), sbend_radii=()),
objective=ObjectiveWeights(danger_weight=0),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False, use_tiered_strategy=False),
refinement=RefinementOptions(enabled=False),
topology=TopologyOptions(mode="off"),
diagnostics=DiagnosticsOptions(capture_iteration_trace=True),
)
run = route(problem, options=options)
assert run.metrics.congestion_check_calls >= 2
assert run.metrics.congestion_candidate_ids >= run.metrics.congestion_exact_pair_checks > 0
assert run.iteration_trace[0].congestion_check_calls == run.metrics.congestion_check_calls
assert run.iteration_trace[0].congestion_exact_pair_checks == run.metrics.congestion_exact_pair_checks
def test_search_rejects_out_of_board_bends_before_tessellation(monkeypatch) -> None:
def unexpected_tessellation(*_args, **_kwargs):
pytest.fail("Search tessellated a bend with an endpoint outside the board")
monkeypatch.setattr(components_module, "_get_num_segments", unexpected_tessellation)
problem = RoutingProblem((0, 0, 100, 50), (NetSpec("straight", Port(10, 20, 0), Port(90, 20, 0)),))
options = RoutingOptions(
search=SearchOptions(node_limit=10, bend_radii=(1e11,), sbend_radii=(1e11,), sbend_offsets=(1,), visibility_guidance="off"),
objective=ObjectiveWeights(danger_weight=0),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
topology=TopologyOptions(mode="off"),
)
assert route(problem, options=options).results_by_net["straight"].is_valid
@pytest.mark.parametrize(("second_x", "y", "valid"), [(53, 25, True), (52, 25, False), (50, 26, True)])
def test_guide_admits_moves_using_physical_inter_net_clearance(second_x, y, valid) -> None:
nets = (

View file

@ -2,11 +2,11 @@ from dataclasses import replace
import pytest
from shapely import union_all
from shapely.geometry import box
from shapely.geometry import Polygon, box
from inire import (
Bend90Seed, CongestionOptions, NetSpec, PathSeed, Port, RefinementOptions,
RoutingOptions, RoutingProblem, SBendOutline, SearchOptions, StraightSeed, TopologyOptions, route,
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,21 @@ 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())
@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)
keepout = box(20, keepout_y, 30, 24)
problem = RoutingProblem((0, 0, 100, 50), (net,), (keepout,), clearance=clearance)
results = route(problem).results_by_net
assert results[net.net_id].is_valid
export = verify_export_grid(problem, results, grid=1)
assert export.geometry_by_net[net.net_id][0].bounds == (10, 19, 90, 21)
assert export.is_valid is valid
assert export.reports_by_net[net.net_id].static_collision_count == int(not valid)
@pytest.mark.parametrize(("pitch", "valid"), [(28000, False), (32000, False), (36000, True)])
def test_cpw_ground_strip_is_verified_using_gap_envelope(pitch, valid) -> None:
width = 15500
@ -77,6 +92,29 @@ def test_cpw_turn_builds_wider_exclusion_from_the_verified_envelope() -> None:
assert cpw.gaps.area > 0
@pytest.mark.parametrize("gap", [0, 0.5])
def test_cpw_checks_for_side_contact_between_terminal_faces(gap) -> None:
signal_outline = Polygon([(0, -1), (3, -1), (12, 5), (15, 5), (15, 7), (12, 7), (3, 1), (0, 1)])
envelope_outline = Polygon([(0, -2), (3, -1 - gap), (12, 5 - gap), (15, 4), (15, 8), (12, 8), (3, 2), (0, 2)])
net = NetSpec("signal", Port(10, 20, 0), Port(25, 26, 0), 2)
problem = RoutingProblem((0, 0, 100, 50), (net,), initial_paths={net.net_id: PathSeed((SBendSeed(6, 10),))})
options = replace(_REPLAY, search=replace(_REPLAY.search, sbend_outlines=(
SBendOutline(6, 10, 2, signal_outline), SBendOutline(6, 10, 4, envelope_outline),
)))
signal = route(problem, options=options).results_by_net[net.net_id]
envelope = route(replace(problem, nets=(replace(net, width=4),)), options=options).results_by_net[net.net_id]
assert signal.is_valid
assert envelope.is_valid
with pytest.raises(ValueError, match="nonempty gap"):
coplanar_geometry(signal, signal)
if gap:
assert coplanar_geometry(signal, envelope).gaps.area > 0
else:
with pytest.raises(ValueError, match="closes away from the terminal faces"):
coplanar_geometry(signal, envelope)
def test_cpw_coupling_etch_keeps_two_signal_sections_separate() -> None:
# The two nets abut opposite faces of the authored 5 µm interruption.
nets = (
@ -124,6 +162,21 @@ def test_profile_options_apply_to_active_search_and_seed_replay() -> None:
route_profiles(invalid, profiles)
@pytest.mark.parametrize(("second_y", "valid"), [(22, False), (23, True)])
def test_profile_reserves_replayed_net_against_zero_clearance_contact(second_y, valid) -> None:
first = NetSpec("first", Port(10, 20, 0), Port(90, 20, 0))
second = NetSpec("second", Port(10, second_y, 0), Port(90, second_y, 0))
seeds = {net.net_id: PathSeed((StraightSeed(80),)) for net in (first, second)}
problem = RoutingProblem((0, 0, 100, 50), (first, second), initial_paths=seeds, clearance=0)
results = route_profiles(problem, [(("first",), _REPLAY), (("second",), _REPLAY)])
assert results["first"].is_valid
assert results["second"].is_valid is valid
if valid:
assert verify_export_grid(problem, results, grid=1).is_valid
def test_independent_layer_outputs_retain_assignment_and_connectivity() -> None:
silicon = NetSpec("si", Port(1000, 10000, 0), Port(19000, 10000, 0), 500)
nitride = NetSpec("sin", Port(10000, 1000, 90), Port(10000, 19000, 90), 750)

View file

@ -5,7 +5,7 @@ from shapely.affinity import rotate, scale
from shapely.geometry import LineString, Polygon, box
from inire import (
CongestionOptions, NetSpec, ObjectiveWeights, PathSeed, Port, RefinementOptions,
CongestionOptions, DiagnosticsOptions, NetSpec, ObjectiveWeights, PathSeed, Port, RefinementOptions,
RoutingOptions, RoutingProblem, SBendSeed, SearchOptions, StraightSeed, TopologyOptions, route,
)
from inire.router._stack import build_routing_stack
@ -151,9 +151,19 @@ def test_guidance_retry_can_change_an_incumbent_in_an_offset_gate(mode) -> None:
congestion=CongestionOptions(max_iterations=2),
refinement=RefinementOptions(enabled=False),
topology=TopologyOptions(mode=mode),
diagnostics=DiagnosticsOptions(capture_iteration_trace=True, capture_conflict_trace=True),
)
snapshots = []
run = route(
problem, options=options,
iteration_callback=lambda index, results: snapshots.append((index, sum(result.is_valid for result in results.values()))),
)
assert all(result.is_valid for result in route(problem, options=options).results_by_net.values())
assert all(result.is_valid for result in run.results_by_net.values())
assert snapshots == [(0, 1), (1, 1), (2, 2)]
assert [(entry.iteration, entry.completed_nets) for entry in run.iteration_trace] == [(2, 2)]
assert [entry.iteration for entry in run.conflict_trace if entry.stage == "iteration"] == [2]
assert run.conflict_trace[-1].iteration is None
def test_lane_assignment_keeps_mesh_path_order_on_equal_costs(monkeypatch: pytest.MonkeyPatch) -> None: