Skip to content

Commit

Permalink
Merge branch 'main' into fix_ipython_filename
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-goeldi authored Jun 26, 2024
2 parents c846850 + 230b9c8 commit 35a3678
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Test with pytest
env:
KFACTORY_LOGFILTER_LEVEL: "ERROR"
run: pytest -vv -s
run: pytest
test_docs:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

# What's Changed

## New

- Routing indirect fixes [#409](https://github.com/gdsfactory/kfactory/pull/409)

## Bug Fixes

- fix connection issue caring about mirror when it should not [#403](https://github.com/gdsfactory/kfactory/pull/403)
- fix indirect routing [#402](https://github.com/gdsfactory/kfactory/pull/402)

## Documentation

- Routing indirect fixes [#409](https://github.com/gdsfactory/kfactory/pull/409)
- fix connection issue caring about mirror when it should not [#403](https://github.com/gdsfactory/kfactory/pull/403)

**Full Changelog**: https://github.com/gdsfactory/kfactory/compare/v0.17.5...v0.17.6
Expand Down
2 changes: 1 addition & 1 deletion src/kfactory/kcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3966,7 +3966,7 @@ def write(
if kcell.is_library_cell() and not kcell._destroyed():
kcell.convert_to_static(recursive=True)

for kc in self.kcells.values():
for kc in list(self.kcells.values()):
kc.insert_vinsts()

return self.layout.write(str(filename), options)
Expand Down
42 changes: 30 additions & 12 deletions src/kfactory/routing/manhattan.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ def route_smart(
)

router_bboxes: list[kdb.Box] = [
kdb.Box(router.start.t.disp.to_p(), router.end.t.disp.to_p())
kdb.Box(router.start.t.disp.to_p(), router.end.t.disp.to_p()).enlarged(
router.width // 2
)
for router in all_routers
]
complete_bbox = router_bboxes[
Expand All @@ -910,6 +912,9 @@ def route_smart(
if overlap_complete.empty():
bundled_bboxes.append(bundle_bbox)
bundle_bbox = bbox.dup()
bundle_region = kdb.Region(bundle_bbox)
if not (bundle_region & box_region).is_empty():
bundle_bbox += box_region.interacting(bundle_region).bbox()
bundle = [router]
bundled_routers.append(bundle)
else:
Expand All @@ -918,13 +923,19 @@ def route_smart(
if not (dbrbox & bundled_bbox).empty():
bb = bundled_bboxes[i]
bundled_routers[i].append(router)
bundled_bboxes[i] = bb + bbox.enlarged(router.width // 2)
bundled_bboxes[i] = bb + bbox
bundle_bbox = bundled_bboxes[i]
bundle = bundled_routers[i]
break
bundled_bboxes.append(bundle_bbox)
bundle_bbox = bbox.dup()
bundle = [router]
bundled_routers.append(bundle)

else:
bundled_bboxes.append(bundle_bbox)
bundle_bbox = bbox.dup()
bundle_region = kdb.Region(bundle_bbox)
if not (bundle_region & box_region).is_empty():
bundle_bbox += box_region.interacting(bundle_region).bbox()
bundle = [router]
bundled_routers.append(bundle)
continue
else:
bundle.append(router)
bundle_bbox += bbox
Expand All @@ -943,7 +954,6 @@ def route_smart(
for i, _ in reversed(merge_bboxes):
del bundled_bboxes[i]
del bundled_routers[i]

for router_bundle in bundled_routers:
sorted_routers = _sort_routers(router_bundle)

Expand Down Expand Up @@ -1234,17 +1244,21 @@ def route_to_bbox(
) -> None:
if not bbox.empty():
if bbox_routing == "minimal":
bb = bbox.dup()
for router in routers:
hw1 = router.router.width // 2 + separation
bb += router.t * kdb.Point(router.router.bend90_radius - hw1, 0)
for router in routers:
hw1 = router.router.width // 2 + separation
match router.t.angle:
case 0:
router.straight_nobend(bbox.right + hw1 - router.t.disp.x)
router.straight_nobend(bb.right + hw1 - router.t.disp.x)
case 1:
router.straight_nobend(bbox.top + hw1 - router.t.disp.y)
router.straight_nobend(bb.top + hw1 - router.t.disp.y)
case 2:
router.straight_nobend(-bbox.left + hw1 + router.t.disp.x)
router.straight_nobend(-bb.left + hw1 + router.t.disp.x)
case 3:
router.straight_nobend(-bbox.bottom + hw1 + router.t.disp.y)
router.straight_nobend(-bb.bottom + hw1 + router.t.disp.y)
elif bbox_routing == "full":
for router in routers:
hw1 = max(
Expand Down Expand Up @@ -1613,6 +1627,8 @@ def _sort_route(router: ManhattanRouterSide) -> int:
rs.straight_nobend(x)
elif x > -rs.router.bend90_radius:
rs.straight(rs.router.bend90_radius + x)
if rs.ta == 0 and x > 0:
rs.straight(x)
rs.left()
bbox += rs.t * kdb.Point(0, -hw2)
else:
Expand All @@ -1622,6 +1638,8 @@ def _sort_route(router: ManhattanRouterSide) -> int:
rs.straight_nobend(x)
elif x > -rs.router.bend90_radius:
rs.straight(rs.router.bend90_radius + x)
if rs.ta == 0 and x > 0:
rs.straight(x)
rs.right()
bbox += rs.t * kdb.Point(0, hw2)

Expand Down
2 changes: 0 additions & 2 deletions tests/test_all_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,3 @@ def test_all_angle_bundle(LAYER: kf.LayerEnum) -> None:
straight_factory=sf,
bend_factory=bf,
)

c.show()
3 changes: 1 addition & 2 deletions tests/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
def test_enclosure_name(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
wg = straight_factory_dbu(width=1000, length=10000)
assert wg.name == "straight_W1000_L10000_LWG_EWGSTD"
wg.show()


def test_circular_snapping(LAYER: kf.LayerEnum) -> None:
Expand Down Expand Up @@ -47,7 +46,7 @@ def recursive_dict_cell(d: dict[str, dict[str, str] | str]) -> kf.KCell:
c = kf.KCell()
return c

recursive_dict_cell({"test": {"test2": "test3"}, "test4": "test5"}).show()
recursive_dict_cell({"test": {"test2": "test3"}, "test4": "test5"})


def test_ports_cell(LAYER: kf.LayerEnum) -> None:
Expand Down
1 change: 0 additions & 1 deletion tests/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def test_cells(cell_name: str) -> None:
c << c_run
c << c_ref
c << c_xor
c.show()

kf.logger.critical(f"Differences found in {cell!r} on layer {layer_tuple}")
val = input("Save current GDS as new reference (Y)? [Y/n]")
Expand Down
2 changes: 0 additions & 2 deletions tests/test_cplxcells.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def simple_cplx_cell(layer: kf.LayerEnum) -> kf.KCell:

def test_cell(LAYER: kf.LayerEnum) -> None:
c = simple_cplx_cell(LAYER.WG)
c.show()


def test_connected_cell(LAYER: kf.LayerEnum) -> None:
Expand All @@ -43,4 +42,3 @@ def test_connected_cell(LAYER: kf.LayerEnum) -> None:
sckc1 = c << simple_cplx_cell(layer)
sckc2 = c << simple_cplx_cell(layer)
sckc2.connect("o1", sckc1, "o1")
c.show()
18 changes: 6 additions & 12 deletions tests/test_enclosure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@ def mmi_enc(layer: kf.kcell.LayerEnum, enclosure: kf.LayerEnclosure) -> kf.KCell


def test_enclosure(LAYER: kf.LayerEnum) -> None:
enc = kf.LayerEnclosure([(LAYER.WG, 500, -250)])
kf.LayerEnclosure([(LAYER.WG, 500, -250)])


def test_enc(LAYER: kf.LayerEnum, wg_enc: kf.LayerEnclosure) -> None:
enc = wg_enc
wg_enc

c = mmi_enc(LAYER.WG, wg_enc)
c.show()
mmi_enc(LAYER.WG, wg_enc)


def test_neg_enc(LAYER: kf.LayerEnum) -> None:
enc = kf.LayerEnclosure([(LAYER.WGCLAD, -1500, 1000)])

c = mmi_enc(LAYER.WG, enc)
c.show()
mmi_enc(LAYER.WG, enc)


def test_layer_multi_enc(LAYER: kf.LayerEnum) -> None:
Expand All @@ -56,8 +54,7 @@ def test_layer_multi_enc(LAYER: kf.LayerEnum) -> None:
(LAYER.WGCLAD, -500, -400),
]
)
c = mmi_enc(LAYER.WG, enc)
c.show()
mmi_enc(LAYER.WG, enc)


def test_layer_merge_enc(LAYER: kf.LayerEnum) -> None:
Expand All @@ -68,8 +65,7 @@ def test_layer_merge_enc(LAYER: kf.LayerEnum) -> None:
(LAYER.WGCLAD, -2000, 1000),
]
)
c = mmi_enc(LAYER.WG, enc)
c.show()
mmi_enc(LAYER.WG, enc)


def test_um_enclosure(LAYER: kf.LayerEnum) -> None:
Expand Down Expand Up @@ -159,5 +155,3 @@ def test_pdkenclosure(LAYER: kf.LayerEnum, straight_blank: kf.KCell) -> None:
assert (
(kf.kdb.Region(c.shapes(LAYER.WGCLADEXCLUDE)) & port_wg_ex) - port_wg_ex
).is_empty()

c.show()
4 changes: 0 additions & 4 deletions tests/test_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def taper_dyn(

extrude_path_dynamic(c, layer, path, _width, enclosure)

c.show()

return c


Expand All @@ -29,7 +27,6 @@ def taper_static(

_width = [width + np.sin(x * np.pi / 2) for x in [_x / 20 for _x in range(21)]]
extrude_path_dynamic(c, layer, path, _width, enclosure)
c.show()

return c

Expand All @@ -52,7 +49,6 @@ def test_enc_extrude_dyn(LAYER: kf.LayerEnum, wg_enc: kf.LayerEnclosure) -> None
_width = lambda x: width + width * np.sin(x * np.pi / 2)

enclosure.extrude_path_dynamic(c, path, layer, _width)
c.show()


def test_enc_extrude_static(LAYER: kf.LayerEnum, wg_enc: kf.LayerEnclosure) -> None:
Expand Down
31 changes: 0 additions & 31 deletions tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import kfactory as kf
import pytest
from collections.abc import Callable
from random import randint, uniform

Expand All @@ -19,8 +18,6 @@ def test_grid_dbu_1d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
align_x="origin",
)

c.show()


def test_grid_dbu_2d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -40,8 +37,6 @@ def test_grid_dbu_2d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
align_x="origin",
)

c.show()


def test_grid_dbu_2d_uneven(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -62,8 +57,6 @@ def test_grid_dbu_2d_uneven(straight_factory_dbu: Callable[..., kf.KCell]) -> No
align_y="ymax",
)

c.show()


def test_grid_dbu_2d_rotation(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -85,8 +78,6 @@ def test_grid_dbu_2d_rotation(straight_factory_dbu: Callable[..., kf.KCell]) ->
align_y="ymin",
)

c.show()


def test_grid_dbu_1d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -104,8 +95,6 @@ def test_grid_dbu_1d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> Non
shape=(1, 10),
)

c.show()


def test_grid_dbu_2d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -126,8 +115,6 @@ def test_grid_dbu_2d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> Non
shape=(4, 5),
)

c.show()


def test_grid_dbu_2d_shape_rotation(
straight_factory_dbu: Callable[..., kf.KCell],
Expand All @@ -151,8 +138,6 @@ def test_grid_dbu_2d_shape_rotation(
shape=(3, 7),
)

c.show()


def test_flexgrid_dbu_1d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -169,8 +154,6 @@ def test_flexgrid_dbu_1d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
align_x="origin",
)

c.show()


def test_flexgrid_dbu_2d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -190,8 +173,6 @@ def test_flexgrid_dbu_2d(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
align_x="origin",
)

c.show()


def test_flexgrid_dbu_2d_rotation(
straight_factory_dbu: Callable[..., kf.KCell],
Expand All @@ -214,8 +195,6 @@ def test_flexgrid_dbu_2d_rotation(
align_x="center",
)

c.show()


def test_flexgrid_dbu_1d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -233,8 +212,6 @@ def test_flexgrid_dbu_1d_shape(straight_factory_dbu: Callable[..., kf.KCell]) ->
shape=(1, 10),
)

c.show()


def test_flexgrid_dbu_2d_shape(straight_factory_dbu: Callable[..., kf.KCell]) -> None:
c = kf.KCell()
Expand All @@ -255,8 +232,6 @@ def test_flexgrid_dbu_2d_shape(straight_factory_dbu: Callable[..., kf.KCell]) ->
shape=(4, 5),
)

c.show()


def test_flexgrid_dbu_2d_shape_rotation(
straight_factory_dbu: Callable[..., kf.KCell],
Expand All @@ -280,8 +255,6 @@ def test_flexgrid_dbu_2d_shape_rotation(
shape=(3, 7),
)

c.show()


def test_grid_2d_shape_rotation(
straight_factory: Callable[..., kf.KCell],
Expand All @@ -306,8 +279,6 @@ def test_grid_2d_shape_rotation(
target_trans=kf.kdb.DCplxTrans(1, 37, False, 0, 0),
)

c.show()


def test_flexgrid_2d_shape_rotation(
straight_factory: Callable[..., kf.KCell],
Expand All @@ -331,5 +302,3 @@ def test_flexgrid_2d_shape_rotation(
shape=(3, 7),
target_trans=kf.kdb.DCplxTrans(1, 37, False, 0, 0),
)

c.show()
Loading

0 comments on commit 35a3678

Please sign in to comment.