Keep route placement at the layout writer boundary

Use the effective net, seed, and search settings as the placement recipe. Remove the export-grid, whole-layer, and CPW mask assembly helpers and cover replay from resolved ports.
This commit is contained in:
Jan Petykiewicz 2026-11-29 16:36:32 -08:00
commit 42e1de9884

View file

@ -8,14 +8,14 @@ To get a result you can experiment with, run the [single-net quick start](../../
2. **Set source and target headings.** A heading is the direction the waveguide travels as it leaves its source or enters its target. Heading 0 points east and 90 points north. If a device labels a target port by the direction it faces outward, reverse that heading by 180 degrees. For example, a waveguide entering a west-facing port travels east, so its target heading is 0.
3. **Add a net for each connection.** Give each `NetSpec` a unique ID and the guide width. Use your process's allowed bend radii in [`SearchOptions`](api-reference.md#searchoptions).
4. **Set the board and keepouts.** Pass the board rectangle as `bounds`, Shapely polygons as `static_obstacles`, and the required physical spacing as `clearance`. For the defaults and accepted inputs, see [`RoutingProblem`](api-reference.md#routingproblem).
5. **Route and check.** Call `route(problem, options=options)`. Automatic mode is the default. Before exporting, [check each net's result](tune-and-troubleshoot.md#read-the-result).
5. **Route and check.** Call `route(problem, options=options)`. Automatic mode is the default. Before using a placement recipe, [check the net's result](tune-and-troubleshoot.md#read-the-result).
<a id="connect-a-preplaced-crossing"></a>
## Route between placed crossings
1. **Place the crossing cells.** Keep each cell's physical footprint and internal connections in your layout. Get the port positions and headings in board coordinates after applying placement and rotation.
2. **Reserve routing keepouts around the cells.** Use the device's routing keepout if supplied. Otherwise, start from its footprint and make local openings at the ports you're connecting. Keep the full physical cell in the exported layout.
2. **Reserve routing keepouts around the cells.** Use the device's routing keepout if supplied. Otherwise, start from its footprint and make local openings at the ports you're connecting. Keep the full physical cell in your layout.
3. **Route the external connections.** Give Inire one net per connection between devices. The example connects A's east port to B's west port. B's arrival heading points east into the cell.
![Two rectangular crossing cells at different heights. A waveguide runs from the opening on A's right edge to the opening on B's left edge. Both port arrows point east.](../figures/placed-crossing.png)
@ -63,36 +63,33 @@ result = run.results_by_net[net_id]
assert result.is_valid
```
Before export, check the port joins and clearance against the actual placed-cell geometry. Inire verifies the external route against the keepouts you supplied.
When assembling the layout, check the port joins and clearance against the actual placed-cell geometry. Inire verifies the external route against the keepouts you supplied.
For declared port widths and transition cells, see [Check placed optical ports](fabrication.md#check-placed-optical-ports).
## Export verified geometry
## Save a placement recipe
Use `result.locked_geometry` to pass a verified net's physical polygons to a layout writer. To inspect the coordinates in a text file, continue from the quick start or the crossing example and write the polygons as well-known text (WKT). Keep track of your coordinate unit when importing the file into another tool.
Port positions snap to integers. Arc vertices can remain fractional. If the writer uses an integer database grid, [verify the coordinates that will be written](fabrication.md#check-the-export-grid).
After checking `result.is_valid`, use `result.as_seed()` to get the ordered moves. Keep the effective net, the component settings, and your coordinate unit with the recipe. The effective net records the resolved terminal positions and headings and the route width.
```python
from pathlib import Path
from shapely.geometry import GeometryCollection
if not result.is_valid:
raise ValueError(f"{result.net_id}: {result.outcome}")
raise ValueError(f"Route {result.net_id!r} ended with outcome {result.outcome!r}")
geometry = GeometryCollection(result.locked_geometry)
Path("route.wkt").write_text(geometry.wkt + "\n", encoding="utf-8")
placement = (result.effective_net, result.as_seed(), options.search)
```
For a multi-net layout, apply the validity check to every net you intend to export. If a route is short or colliding, use its outcome to choose the [next troubleshooting check](tune-and-troubleshoot.md#read-the-result).
The example uses the `options` from the crossing example. If you called `route(problem)`, use `RoutingOptions().search`.
Place the first move at the effective start port and each subsequent move at the previous move's end port. For explicit placements, read the `move_spec`, `start_port`, and `end_port` of each component in `result.path`. Use the same width, radii, tangent extensions, and custom outlines that the router checked.
Your layout tool realizes the components and writes the layout. Choose widths and clearance with enough margin for any downstream rounding. Inire's verification describes the supplied geometry in routing units. Use `result.locked_geometry` to inspect the polygons it checked or reserve them in a later routing run.
## 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 use `FixedRoute.from_result(result)` and pass it in `fixed_routes` alongside the remaining nets. The next run respects it as a distinct net, including at zero clearance. Verify the groups together before [exporting the layer](fabrication.md#check-the-export-grid).
- **Hold a route fixed.** Check `result.is_valid`, then use `FixedRoute.from_result(result)` and pass it in `fixed_routes` alongside the remaining nets. The next run respects it as a distinct net, including at zero clearance.
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.
When terminal headings are inferred, use the effective net with the saved moves to replay the same placement.
```python
from dataclasses import replace
@ -105,7 +102,7 @@ seeds = {}
for net in problem.nets:
result = chosen.results_by_net[net.net_id]
if result.is_valid:
verified_nets.append(replace(net, start=result.path[0].start_port, target=result.path[-1].end_port))
verified_nets.append(result.effective_net)
seeds[net.net_id] = result.as_seed()
replay = route(
@ -129,7 +126,6 @@ Route a straight net, then reserve it while routing another net on the same laye
from dataclasses import replace
from inire import FixedRoute, NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.layout import verify_export_grid
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
@ -139,12 +135,11 @@ problem = RoutingProblem(bounds=bounds, nets=(fixed_net, detour_net), clearance=
fixed = route(replace(problem, nets=(fixed_net,)), options=options).results_by_net["fixed"]
remaining = replace(problem, nets=(detour_net,), fixed_routes=(FixedRoute.from_result(fixed),))
run = route(remaining, options=options)
export = verify_export_grid(remaining, run.results_by_net, grid=1.0)
if not export.is_valid:
raise ValueError(export.reports_by_net)
detour = route(remaining, options=options).results_by_net["detour"]
assert detour.is_valid
detour_placement = (detour.effective_net, detour.as_seed(), options.search)
```
For imported metal or waveguide polygons, use `FixedRoute("existing_net", imported_polygons)`. Supply fixed polygons in their final layer coordinates. Export checks new routes against them and returns the new polygons.
For imported metal or waveguide polygons that belong to an existing net, use `FixedRoute("existing_net", imported_polygons)`. Supply polygons in board coordinates. For other artwork that blocks routing, use `static_obstacles`.
To compare the two paths on a plot, see the [fixed-route example](../../examples/README.md#route-around-fixed-geometry).