Bound search memory and verify process geometry before layout export
This commit is contained in:
parent
facde64f09
commit
e6ae242cb2
1 changed files with 645 additions and 102 deletions
154
inire/tests/test_layout.py
Normal file
154
inire/tests/test_layout.py
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
from shapely import union_all
|
||||
from shapely.geometry import box
|
||||
|
||||
from inire import (
|
||||
Bend90Seed, CongestionOptions, NetSpec, PathSeed, Port, RefinementOptions,
|
||||
RoutingOptions, RoutingProblem, SBendOutline, SearchOptions, StraightSeed, TopologyOptions, route,
|
||||
)
|
||||
from inire.layout import PlacedPort, coplanar_geometry, partition_layers, preserves_length, route_profiles, verify_export_grid
|
||||
|
||||
|
||||
_REPLAY = RoutingOptions(search=SearchOptions(node_limit=0), refinement=RefinementOptions(enabled=False))
|
||||
|
||||
|
||||
def test_declared_port_width_check_requires_transition_for_wider_device() -> None:
|
||||
source = PlacedPort(Port(10000, 10000, 0), 500)
|
||||
target = PlacedPort(Port(110000, 10000, 0), 3000)
|
||||
with pytest.raises(ValueError, match="joins widths 500 and 3000"):
|
||||
source.connect("wide", target)
|
||||
|
||||
inlet = PlacedPort(Port(70000, 10000, 0), 500)
|
||||
net = source.connect("before_taper", inlet)
|
||||
assert net.width == 500
|
||||
assert net.target == inlet.port
|
||||
rotated = replace(source, port=source.port.rotated(90)).connect("rotated", replace(inlet, port=inlet.port.rotated(90)))
|
||||
assert rotated.start.r == rotated.target.r == 90
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("outer_radius", "grid", "valid"), [(3070, 1, False), (3070, 0.01, True), (3072, 1, True)])
|
||||
def test_export_verifies_actual_rounded_bend_clearance(outer_radius, grid, valid) -> None:
|
||||
center_x, center_y = 3000, 6070
|
||||
inner = NetSpec("inside", Port(center_x, center_y - 2500, 0), Port(center_x + 2500, center_y, 90), 490)
|
||||
outer = NetSpec("outside", Port(center_x, center_y - outer_radius, 0), Port(center_x + outer_radius, center_y, 90), 509.94)
|
||||
seeds = {"inside": PathSeed((Bend90Seed(2500, "CCW"),)), "outside": PathSeed((Bend90Seed(outer_radius, "CCW"),))}
|
||||
problem = RoutingProblem((0, 0, 7000, 7000), (inner, outer), initial_paths=seeds, clearance=70)
|
||||
options = replace(_REPLAY, search=replace(_REPLAY.search, bend_radii=(2500, outer_radius)))
|
||||
results = route(problem, options=options).results_by_net
|
||||
assert all(result.is_valid for result in results.values())
|
||||
|
||||
exported = verify_export_grid(problem, results, grid=grid)
|
||||
|
||||
assert exported.is_valid is valid
|
||||
assert all(not report.discontinuous for report in exported.reports_by_net.values())
|
||||
assert all(report.dynamic_collision_count == int(not valid) for report in exported.reports_by_net.values())
|
||||
|
||||
|
||||
@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
|
||||
nets = tuple(NetSpec(f"cpw{i}", Port(10000, 30000 + i * pitch, 0), Port(210000, 30000 + i * pitch, 0), width)
|
||||
for i in range(2))
|
||||
seeds = {net.net_id: PathSeed((StraightSeed(200000),)) for net in nets}
|
||||
problem = RoutingProblem((0, 0, 220000, 100000), nets, initial_paths=seeds, clearance=3000)
|
||||
signals = route(problem, options=_REPLAY).results_by_net
|
||||
envelopes = route(replace(problem, nets=tuple(replace(net, width=29500) for net in nets)), options=_REPLAY).results_by_net
|
||||
assert all(signal.is_valid for signal in signals.values())
|
||||
assert all(envelope.is_valid for envelope in envelopes.values()) == valid
|
||||
if valid:
|
||||
shapes = [coplanar_geometry(signals[net.net_id], envelopes[net.net_id]) for net in nets]
|
||||
assert shapes[0].ground_exclusion.distance(shapes[1].ground_exclusion) == 6500
|
||||
assert all(shape.gaps.area == 14000 * 200000 for shape in shapes)
|
||||
|
||||
|
||||
def test_cpw_turn_builds_wider_exclusion_from_the_verified_envelope() -> None:
|
||||
radius = 15000
|
||||
net = NetSpec("flux", Port(35000, 20000, 0), Port(50000, 35000, 90), 15500)
|
||||
problem = RoutingProblem((0, 0, 100000, 80000), (net,), initial_paths={"flux": PathSeed((Bend90Seed(radius, "CCW"),))})
|
||||
options = replace(_REPLAY, search=SearchOptions(node_limit=0, bend_radii=(radius,), sbend_radii=()))
|
||||
signal = route(problem, options=options).results_by_net["flux"]
|
||||
envelope = route(replace(problem, nets=(replace(net, width=29500),)), options=options).results_by_net["flux"]
|
||||
|
||||
cpw = coplanar_geometry(signal, envelope, ground_margin=10000)
|
||||
|
||||
assert cpw.ground_exclusion.covers(union_all(envelope.locked_geometry))
|
||||
assert cpw.gaps.area > 0
|
||||
|
||||
|
||||
def test_profile_options_apply_to_active_search_and_seed_replay() -> None:
|
||||
flux = NetSpec("flux", Port(35000, 20000, 0), Port(50000, 35000, 90), 29500)
|
||||
feed = NetSpec("feed", Port(100000, 20000, 0), Port(115000, 35000, 90), 29500)
|
||||
problem = RoutingProblem((0, 0, 220000, 95000), (flux, feed), clearance=3000)
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(node_limit=80, bend_radii=(15000,), sbend_radii=()),
|
||||
refinement=RefinementOptions(enabled=False),
|
||||
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
|
||||
topology=TopologyOptions(mode="off"),
|
||||
)
|
||||
feed_profile = replace(options, search=replace(options.search, bend_radii=(50000,)))
|
||||
profiles = ((("flux",), options), (("feed",), feed_profile))
|
||||
|
||||
restricted = route_profiles(problem, profiles)
|
||||
|
||||
assert restricted["flux"].is_valid
|
||||
assert not restricted["feed"].is_valid
|
||||
feed = replace(feed, target=Port(150000, 70000, 90))
|
||||
open_board = replace(problem, nets=(flux, feed))
|
||||
both = route_profiles(open_board, profiles)
|
||||
assert both["feed"].as_seed() == PathSeed((Bend90Seed(50000, "CCW"),))
|
||||
assert all(result.is_valid for result in both.values())
|
||||
invalid = replace(open_board, initial_paths={"feed": PathSeed((Bend90Seed(15000, "CCW"),))})
|
||||
with pytest.raises(ValueError, match="'feed'.*outside bend_radii"):
|
||||
route_profiles(invalid, profiles)
|
||||
|
||||
|
||||
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)
|
||||
geometry = {}
|
||||
for layer, nets in partition_layers((((1, 0), silicon), ((4, 0), nitride))).items():
|
||||
problem = RoutingProblem(
|
||||
(0, 0, 20000, 20000), nets,
|
||||
initial_paths={net.net_id: PathSeed((StraightSeed(18000),)) for net in nets},
|
||||
)
|
||||
results = route(problem, options=_REPLAY).results_by_net
|
||||
export = verify_export_grid(problem, results, grid=1)
|
||||
assert export.is_valid
|
||||
geometry[layer] = union_all(tuple(polygon for shapes in export.geometry_by_net.values() for polygon in shapes))
|
||||
assert set(geometry) == {(1, 0), (4, 0)}
|
||||
assert all(shape.geom_type == "Polygon" for shape in geometry.values())
|
||||
assert geometry[1, 0].intersection(geometry[4, 0]).area > 0
|
||||
|
||||
|
||||
def test_authored_template_lengths_are_used_for_candidate_acceptance() -> None:
|
||||
net = NetSpec("arm", Port(20, 20, 0), Port(30, 30, 90))
|
||||
problem = RoutingProblem((0, 0, 100, 100), (net,))
|
||||
outline = box(0, -11, 11, -9).union(box(9, -11, 11, 0))
|
||||
options = RoutingOptions(search=SearchOptions(
|
||||
node_limit=100, bend_radii=(10,), bend_physical_geometry=outline, bend_physical_length=18.7,
|
||||
))
|
||||
result = route(problem, options=options).results_by_net["arm"]
|
||||
assert preserves_length(result, 18.7, tolerance=1e-6)
|
||||
assert not preserves_length(result, 37.4, tolerance=1e-6)
|
||||
assert result.report.total_length == 18.7
|
||||
|
||||
|
||||
def test_authored_sbend_length_survives_seed_replay() -> None:
|
||||
polygon = box(0, -1, 80, 41).intersection(
|
||||
box(0, -1, 80, 1).union(box(1, 0, 79, 41)).union(box(79, 39, 80, 41)),
|
||||
)
|
||||
outline = SBendOutline(40, 50, 2, polygon, length=95)
|
||||
net = NetSpec("shift", Port(10, 10, 0), Port(90, 50, 0))
|
||||
seed = PathSeed(())
|
||||
search = SearchOptions(node_limit=80, bend_radii=(), sbend_radii=(50,), sbend_outlines=(outline,))
|
||||
problem = RoutingProblem((0, 0, 110, 110), (net,))
|
||||
options = RoutingOptions(search=search)
|
||||
result = route(problem, options=options).results_by_net["shift"]
|
||||
assert result.as_seed() != seed
|
||||
replay = route(
|
||||
replace(problem, initial_paths={"shift": result.as_seed()}),
|
||||
options=replace(options, search=replace(search, node_limit=0)),
|
||||
).results_by_net["shift"]
|
||||
assert preserves_length(replay, 95, tolerance=0)
|
||||
Loading…
Reference in a new issue