Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify routing #22

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cspdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from cspdk.cells import _bend, _straight, _taper
from cspdk.config import PATH
from cspdk.models import get_models
from cspdk.routing import get_routing_strategies
from cspdk.tech import LAYER, LAYER_STACK, LAYER_VIEWS
from cspdk.tech import LAYER, LAYER_STACK, LAYER_VIEWS, routing_strategies

_models = get_models()
_cells = get_cells(cells)
Expand All @@ -19,7 +18,6 @@
}
)
_cross_sections = get_cross_sections(tech)
_routing_strategies = get_routing_strategies()
PDK = Pdk(
name="cornerstone",
cells=_cells,
Expand All @@ -28,7 +26,7 @@
layer_stack=LAYER_STACK,
layer_views=LAYER_VIEWS,
models=_models,
routing_strategies=_routing_strategies,
routing_strategies=routing_strategies,
)
PDK.activate()

Expand Down
3 changes: 3 additions & 0 deletions cspdk/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,9 @@ def crossing_sc() -> gf.Component:
return c


array = gf.components.array


if __name__ == "__main__":
# c = die_sc()
c = crossing_sc()
Expand Down
86 changes: 0 additions & 86 deletions cspdk/routing.py

This file was deleted.

18 changes: 18 additions & 0 deletions cspdk/samples/get_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""`get_route` returns a Manhattan route between two ports. """

import gdsfactory as gf

import cspdk

if __name__ == "__main__":
c = gf.Component("sample_connect")
mmi1 = c << cspdk.cells.mmi1x2_nc()
mmi2 = c << cspdk.cells.mmi1x2_nc()
mmi2.move((500, 50))

route = cspdk.tech.get_route_nc(
mmi1.ports["o3"],
mmi2.ports["o1"],
)
c.add(route.references)
c.show()
53 changes: 53 additions & 0 deletions cspdk/tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,59 @@ def get_layer_stack(

cross_sections = get_cross_sections(sys.modules[__name__])

############################
# Routing functions
############################

_settings_sc = dict(
straight="straight_sc", cross_section=xs_sc, bend="bend_sc", taper="taper_sc"
)
_settings_so = dict(
straight="straight_so", cross_section=xs_so, bend="bend_so", taper="taper_so"
)
_settings_rc = dict(
straight="straight_rc", cross_section=xs_rc, bend="bend_rc", taper="taper_rc"
)
_settings_ro = dict(
straight="straight_ro", cross_section=xs_ro, bend="bend_ro", taper="taper_ro"
)
_settings_nc = dict(
straight="straight_nc", cross_section=xs_nc, bend="bend_nc", taper="taper_nc"
)
_settings_no = dict(
Comment on lines +185 to +200
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider using a loop or a more dynamic structure for settings initialization.

The repetitive structure for initializing settings for different routing configurations could be simplified using a loop or a dictionary comprehension, enhancing maintainability and reducing code duplication.

Suggested change
_settings_sc = dict(
straight="straight_sc", cross_section=xs_sc, bend="bend_sc", taper="taper_sc"
)
_settings_so = dict(
straight="straight_so", cross_section=xs_so, bend="bend_so", taper="taper_so"
)
_settings_rc = dict(
straight="straight_rc", cross_section=xs_rc, bend="bend_rc", taper="taper_rc"
)
_settings_ro = dict(
straight="straight_ro", cross_section=xs_ro, bend="bend_ro", taper="taper_ro"
)
_settings_nc = dict(
straight="straight_nc", cross_section=xs_nc, bend="bend_nc", taper="taper_nc"
)
_settings_no = dict(
settings_prefixes = ["sc", "so", "rc", "ro", "nc", "no"]
settings = {
f"settings_{suffix}": {
"straight": f"straight_{suffix}",
"cross_section": f"xs_{suffix}",
"bend": f"bend_{suffix}",
"taper": f"taper_{suffix}"
} for suffix in settings_prefixes
}

straight="straight_no", cross_section=xs_no, bend="bend_no", taper="taper_no"
)


get_route_sc = partial(gf.routing.get_route, **_settings_sc)
get_route_so = partial(gf.routing.get_route, **_settings_so)
get_route_rc = partial(gf.routing.get_route, **_settings_rc)
get_route_ro = partial(gf.routing.get_route, **_settings_ro)
get_route_nc = partial(gf.routing.get_route, **_settings_nc)
get_route_no = partial(gf.routing.get_route, **_settings_no)

get_bundle_sc = partial(gf.routing.get_bundle, **_settings_sc)
get_bundle_so = partial(gf.routing.get_bundle, **_settings_so)
get_bundle_rc = partial(gf.routing.get_bundle, **_settings_rc)
get_bundle_ro = partial(gf.routing.get_bundle, **_settings_ro)
get_bundle_nc = partial(gf.routing.get_bundle, **_settings_nc)
get_bundle_no = partial(gf.routing.get_bundle, **_settings_no)


routing_strategies = dict(
get_route_sc=get_route_sc,
get_route_so=get_route_so,
get_route_rc=get_route_rc,
get_route_ro=get_route_ro,
get_route_nc=get_route_nc,
get_route_no=get_route_no,
get_bundle_sc=get_bundle_sc,
get_bundle_so=get_bundle_so,
get_bundle_rc=get_bundle_rc,
get_bundle_ro=get_bundle_ro,
get_bundle_nc=get_bundle_nc,
)


if __name__ == "__main__":
from gdsfactory.technology.klayout_tech import KLayoutTechnology
Expand Down
Binary file added tests/gds_ref/array.gds
Binary file not shown.
Loading
Loading