From fc97d06119beb9789d914a994c7df331e5bd4de9 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:13:11 -0700 Subject: [PATCH 1/3] simplify routing --- cspdk/__init__.py | 6 +- cspdk/cells.py | 3 + cspdk/routing.py | 86 -------- cspdk/samples/get_route.py | 18 ++ cspdk/tech.py | 53 +++++ tests/gds_ref/array.gds | Bin 0 -> 272 bytes tests/test_netlists/test_netlists_array_.yml | 197 +++++++++++++++++++ tests/test_pdk/test_settings_array_.yml | 22 +++ 8 files changed, 295 insertions(+), 90 deletions(-) delete mode 100644 cspdk/routing.py create mode 100644 cspdk/samples/get_route.py create mode 100644 tests/gds_ref/array.gds create mode 100644 tests/test_netlists/test_netlists_array_.yml create mode 100644 tests/test_pdk/test_settings_array_.yml diff --git a/cspdk/__init__.py b/cspdk/__init__.py index a9f96ff..4ee87eb 100644 --- a/cspdk/__init__.py +++ b/cspdk/__init__.py @@ -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) @@ -19,7 +18,6 @@ } ) _cross_sections = get_cross_sections(tech) -_routing_strategies = get_routing_strategies() PDK = Pdk( name="cornerstone", cells=_cells, @@ -28,7 +26,7 @@ layer_stack=LAYER_STACK, layer_views=LAYER_VIEWS, models=_models, - routing_strategies=_routing_strategies, + routing_strategies=routing_strategies, ) PDK.activate() diff --git a/cspdk/cells.py b/cspdk/cells.py index 8455b06..0dc47b7 100644 --- a/cspdk/cells.py +++ b/cspdk/cells.py @@ -1364,6 +1364,9 @@ def crossing_sc() -> gf.Component: return c +array = gf.components.array + + if __name__ == "__main__": # c = die_sc() c = crossing_sc() diff --git a/cspdk/routing.py b/cspdk/routing.py deleted file mode 100644 index 09ac61a..0000000 --- a/cspdk/routing.py +++ /dev/null @@ -1,86 +0,0 @@ -from functools import partial - -from gdsfactory.routing import get_route -from gdsfactory.routing.factories import routing_strategy - -from cspdk import cells -from cspdk.cells import _bend, _straight, _taper, wire_corner - - -def get_routing_strategies(): - return { - **get_routing_strategies_for_cross_section(""), - **get_routing_strategies_for_cross_section("xs_sc"), - **get_routing_strategies_for_cross_section("xs_so"), - **get_routing_strategies_for_cross_section("xs_rc"), - **get_routing_strategies_for_cross_section("xs_ro"), - **get_routing_strategies_for_cross_section("xs_nc"), - **get_routing_strategies_for_cross_section("xs_no"), - } - - -def get_routing_strategies_for_cross_section(cross_section): - suffix = "" - if "_" in cross_section: - suffix = f"_{cross_section.split('_')[-1]}" - else: - cross_section = "xs_sc" - straight = getattr(cells, f"straight{suffix}", _straight) - bend = getattr(cells, f"bend{suffix}", _bend) - taper = getattr(cells, f"taper{suffix}", _taper) - return { - f"get_bundle{suffix}": partial( - routing_strategy["get_bundle"], - straight=straight, - bend=bend, - cross_section=cross_section, - ), - f"get_bundle_electrical{suffix}": partial( - routing_strategy["get_bundle_electrical"], - straight=straight, - bend=wire_corner, - cross_section=cross_section, - ), - f"get_bundle_path_length_match{suffix}": partial( - routing_strategy["get_bundle_path_length_match"], - straight=straight, - bend=bend, - taper=taper, - cross_section=cross_section, - ), - f"get_bundle_same_axis_no_grouping{suffix}": partial( - routing_strategy["get_bundle_same_axis_no_grouping"], - taper=taper, - route_filter=partial( - get_route, - bend=bend, - straight=straight, - ), - cross_section=cross_section, - ), - f"get_bundle_from_waypoints{suffix}": partial( - routing_strategy["get_bundle_from_waypoints"], - straight=straight, - taper=taper, - bend=bend, - cross_section=cross_section, - ), - f"get_bundle_from_steps{suffix}": partial( - routing_strategy["get_bundle_from_steps"], - straight=straight, - taper=taper, - bend=bend, - cross_section=cross_section, - ), - f"get_bundle_from_steps_electrical{suffix}": partial( - routing_strategy["get_bundle_from_steps_electrical"], - straight=straight, - taper=taper, - bend=wire_corner, - cross_section=cross_section, - ), - } - - -if __name__ == "__main__": - print(get_routing_strategies()["get_bundle"]) diff --git a/cspdk/samples/get_route.py b/cspdk/samples/get_route.py new file mode 100644 index 0000000..0473a92 --- /dev/null +++ b/cspdk/samples/get_route.py @@ -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() diff --git a/cspdk/tech.py b/cspdk/tech.py index 23bd4be..9f419aa 100644 --- a/cspdk/tech.py +++ b/cspdk/tech.py @@ -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( + 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 diff --git a/tests/gds_ref/array.gds b/tests/gds_ref/array.gds new file mode 100644 index 0000000000000000000000000000000000000000..fb52ed841793d69fa31e55ac38242f105ba1a210 GIT binary patch literal 272 zcmZQzV_;&6V31*CVt>rQ#URPR&Y;4efXrs#VPeb4Oe#t&s$^ggVP>^+>@@d2w)}&o z%MSeov!g;7WLRSp0)VBin}i2!L~CI&VJMg|!HW(FAG-Ms+D zWMK0Az`!C1)Wgnz*9H!-4M24q3=C|%ObnU~Y Date: Tue, 16 Apr 2024 20:31:18 -0700 Subject: [PATCH 2/3] add circuit_simulations_with_routing --- .../circuit_simulations_with_routing.py | 32 ++++++++++ cspdk/tech.py | 64 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 cspdk/samples/circuit_simulations_with_routing.py diff --git a/cspdk/samples/circuit_simulations_with_routing.py b/cspdk/samples/circuit_simulations_with_routing.py new file mode 100644 index 0000000..6f40a05 --- /dev/null +++ b/cspdk/samples/circuit_simulations_with_routing.py @@ -0,0 +1,32 @@ +import gdsfactory as gf +import jax.numpy as jnp +import matplotlib.pyplot as plt +import sax + +import cspdk +from cspdk import PDK + +if __name__ == "__main__": + c = gf.Component() + mzi1 = c << cspdk.cells.mzi_sc(delta_length=10) + mzi2 = c << cspdk.cells.mzi_sc(delta_length=100) + mzi2.move((200, 200)) + route = cspdk.tech.get_route_sc(mzi1.ports["o2"], mzi2.ports["o1"]) + c.add(route.references) + c.add_port(name="o1", port=mzi1.ports["o1"]) + c.add_port(name="o2", port=mzi2.ports["o2"]) + c.show() + c.plot_netlist_flat() + netlist = c.get_netlist_recursive() + models = PDK.models + circuit, _ = sax.circuit(netlist, models=models) # type: ignore + wl = jnp.linspace(1.5, 1.6, 256) + + S = circuit(wl=wl) + plt.figure(figsize=(14, 4)) + plt.title("MZI") + plt.plot(1e3 * wl, jnp.abs(S["o1", "o2"]) ** 2) # type: ignore + plt.xlabel("λ [nm]") + plt.ylabel("T") + plt.grid(True) + plt.show() diff --git a/cspdk/tech.py b/cspdk/tech.py index 9f419aa..7ef3675 100644 --- a/cspdk/tech.py +++ b/cspdk/tech.py @@ -209,6 +209,32 @@ def get_layer_stack( get_route_nc = partial(gf.routing.get_route, **_settings_nc) get_route_no = partial(gf.routing.get_route, **_settings_no) +get_route_from_steps_sc = partial( + gf.routing.get_route_from_steps, + **_settings_sc, +) +get_route_from_steps_so = partial( + gf.routing.get_route_from_steps, + **_settings_so, +) +get_route_from_steps_rc = partial( + gf.routing.get_route_from_steps, + **_settings_rc, +) +get_route_from_steps_ro = partial( + gf.routing.get_route_from_steps, + **_settings_ro, +) +get_route_from_steps_nc = partial( + gf.routing.get_route_from_steps, + **_settings_nc, +) +get_route_from_steps_no = partial( + gf.routing.get_route_from_steps, + **_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) @@ -216,6 +242,31 @@ def get_layer_stack( get_bundle_nc = partial(gf.routing.get_bundle, **_settings_nc) get_bundle_no = partial(gf.routing.get_bundle, **_settings_no) +get_bundle_from_steps_sc = partial( + gf.routing.get_bundle_from_steps, + **_settings_sc, +) +get_bundle_from_steps_so = partial( + gf.routing.get_bundle_from_steps, + **_settings_so, +) +get_bundle_from_steps_rc = partial( + gf.routing.get_bundle_from_steps, + **_settings_rc, +) +get_bundle_from_steps_ro = partial( + gf.routing.get_bundle_from_steps, + **_settings_ro, +) +get_bundle_from_steps_nc = partial( + gf.routing.get_bundle_from_steps, + **_settings_nc, +) +get_bundle_from_steps_no = partial( + gf.routing.get_bundle_from_steps, + **_settings_no, +) + routing_strategies = dict( get_route_sc=get_route_sc, @@ -224,11 +275,24 @@ def get_layer_stack( get_route_ro=get_route_ro, get_route_nc=get_route_nc, get_route_no=get_route_no, + get_route_from_steps_sc=get_route_from_steps_sc, + get_route_from_steps_so=get_route_from_steps_so, + get_route_from_steps_rc=get_route_from_steps_rc, + get_route_from_steps_ro=get_route_from_steps_ro, + get_route_from_steps_nc=get_route_from_steps_nc, + get_route_from_steps_no=get_route_from_steps_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, + get_bundle_no=get_bundle_no, + get_bundle_from_steps_sc=get_bundle_from_steps_sc, + get_bundle_from_steps_so=get_bundle_from_steps_so, + get_bundle_from_steps_rc=get_bundle_from_steps_rc, + get_bundle_from_steps_ro=get_bundle_from_steps_ro, + get_bundle_from_steps_nc=get_bundle_from_steps_nc, + get_bundle_from_steps_no=get_bundle_from_steps_no, ) From baec3aaabd0bdbd746730272f1fdfcc403ab545e Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Fri, 19 Apr 2024 07:14:37 -0700 Subject: [PATCH 3/3] remove duplicated layers --- cspdk/klayout/d25/Cornerstone.lyd25 | 2 + cspdk/klayout/tech/layers.lyp | 190 --------------------------- cspdk/samples/circuit_simulations.py | 2 +- cspdk/tech.py | 2 +- 4 files changed, 4 insertions(+), 192 deletions(-) delete mode 100644 cspdk/klayout/tech/layers.lyp diff --git a/cspdk/klayout/d25/Cornerstone.lyd25 b/cspdk/klayout/d25/Cornerstone.lyd25 index 876bfb1..6128169 100644 --- a/cspdk/klayout/d25/Cornerstone.lyd25 +++ b/cspdk/klayout/d25/Cornerstone.lyd25 @@ -18,6 +18,7 @@ core = input(3, 0) +slab = input(5, 0) nitride = input(203, 0) nitride_etch = input(204, 0) heater = input(39, 0) @@ -26,6 +27,7 @@ metal = input(41, 0) z(core, zstart: 0.0, zstop: 0.2, name: 'core: si 3/0', ) +z(slab, zstart: 0.0, zstop: 0.1, name: 'slab: si 5/0', ) z(nitride, zstart: 0.0, zstop: 0.3, name: 'nitride: sin 203/0', ) z(nitride_etch, zstart: 0.0, zstop: 0.3, name: 'nitride_etch: sin 204/0', ) z(heater, zstart: 1.1, zstop: 1.8, name: 'heater: TiN 39/0', ) diff --git a/cspdk/klayout/tech/layers.lyp b/cspdk/klayout/tech/layers.lyp deleted file mode 100644 index 811824a..0000000 --- a/cspdk/klayout/tech/layers.lyp +++ /dev/null @@ -1,190 +0,0 @@ - - - - #ff9d9d - #ff9d9d - 0 - 0 - I3 - - true - true - false - 1 - false - false - 0 - WG 3/0 - 3/0@1 - - - #c0c0c0 - #c0c0c0 - 0 - 0 - I3 - - true - true - false - 1 - false - false - 0 - SLAB 5/0 - 5/0@1 - - - #00ffff - #00ffff - 0 - 0 - I3 - - true - true - true - 1 - false - false - 0 - RIB 4/0 - 4/0@1 - - - #0000ff - #0000ff - 0 - 0 - I3 - - true - true - true - 1 - false - false - 0 - GRA 6/0 - 6/0@1 - - - #ffa500 - #ffa500 - 0 - 0 - I3 - - true - true - false - - false - false - 0 - NITRIDE 203/0 - 203/0@1 - - - #0000ff - #0000ff - 0 - 0 - I3 - - true - true - true - 1 - false - false - 0 - NITRIDE_ETCH 204/0 - 204/0@1 - - - #ebc634 - #ebc634 - 0 - 0 - I3 - - true - true - false - - false - false - 0 - HEATER 39/0 - 39/0@1 - - - - #008080 - 0 - 0 - I3 - - true - true - false - - false - false - 0 - PAD 41/0 - 41/0@1 - - - #000000 - #000000 - 0 - 0 - I1 - - true - true - false - - false - false - 0 - FLOORPLAN 99/0 - 99/0@1 - - - #00ffff - #00ffff - 0 - 0 - I1 - - true - true - false - - false - false - 0 - LABEL_SETTINGS 100/0 - 100/0@1 - - - #00ffff - #00ffff - 0 - 0 - I1 - - true - true - false - - false - false - 0 - LABEL_INSTANCE 101/0 - 101/0@1 - - diff --git a/cspdk/samples/circuit_simulations.py b/cspdk/samples/circuit_simulations.py index 4b53482..61374cf 100644 --- a/cspdk/samples/circuit_simulations.py +++ b/cspdk/samples/circuit_simulations.py @@ -6,7 +6,7 @@ from cspdk import PDK if __name__ == "__main__": - c = cspdk.cells.mzi_sc(delta_length=100) + c = cspdk.cells.mzi_sc(delta_length=10) c.show() c.plot_netlist() netlist = c.get_netlist() diff --git a/cspdk/tech.py b/cspdk/tech.py index 7ef3675..9005025 100644 --- a/cspdk/tech.py +++ b/cspdk/tech.py @@ -300,7 +300,7 @@ def get_layer_stack( from gdsfactory.technology.klayout_tech import KLayoutTechnology LAYER_VIEWS = LayerViews(PATH.lyp_yaml) - LAYER_VIEWS.to_lyp(PATH.lyp) + # LAYER_VIEWS.to_lyp(PATH.lyp) connectivity = cast(list[ConnectivitySpec], [("HEATER", "HEATER", "PAD")])