diff --git a/gdsfactory/components/add_grating_couplers.py b/gdsfactory/components/add_grating_couplers.py index c5499de901..2cc0f18e32 100644 --- a/gdsfactory/components/add_grating_couplers.py +++ b/gdsfactory/components/add_grating_couplers.py @@ -7,14 +7,12 @@ import numpy as np import gdsfactory as gf -from gdsfactory.add_labels import get_input_label_text_loopback from gdsfactory.component import Component from gdsfactory.components.bend_euler import bend_euler from gdsfactory.components.grating_coupler_elliptical_trenches import grating_coupler_te from gdsfactory.components.straight import straight from gdsfactory.cross_section import strip from gdsfactory.port import select_ports_optical -from gdsfactory.routing.get_input_labels import get_input_labels from gdsfactory.routing.manhattan import round_corners from gdsfactory.routing.utils import ( check_ports_have_equal_spacing, @@ -23,8 +21,6 @@ from gdsfactory.typings import ( ComponentSpec, CrossSectionSpec, - LabelListFactory, - LayerSpec, PortsDict, ) @@ -33,28 +29,20 @@ def add_grating_couplers( component: ComponentSpec = straight, grating_coupler: ComponentSpec = grating_coupler_te, - layer_label: LayerSpec | None = None, gc_port_name: str = "o1", - get_input_labels_function: LabelListFactory | None = get_input_labels, select_ports: Callable[..., PortsDict] = select_ports_optical, - component_name: str | None = None, ) -> Component: """Returns new component with grating couplers and labels. Args: component: to add grating_couplers. grating_coupler: grating_coupler spec. - layer_label: for label. gc_port_name: where to add label. - get_input_labels_function: function to get label. select_ports: for selecting optical_ports. - component_name: optional component name. """ c = Component() component = gf.get_component(component) - c.component = component - component_name = component_name or component.metadata_child.get("name") c.add_ref(component) grating_coupler = gf.get_component(grating_coupler) @@ -71,15 +59,6 @@ def add_grating_couplers( io_gratings.append(gc_ref) c.add(gc_ref) - if layer_label and get_input_labels_function: - labels = get_input_labels_function( - io_gratings, - list(component.ports.values()), - component_name=component_name, - layer_label=layer_label, - gc_port_name=gc_port_name, - ) - c.add(labels) c.copy_child_info(component) return c @@ -88,14 +67,10 @@ def add_grating_couplers( def add_grating_couplers_with_loopback_fiber_single( component: ComponentSpec = "spiral_inner_io_fiber_single", grating_coupler: ComponentSpec = grating_coupler_te, - layer_label: tuple[int, int] | None = None, gc_port_name: str = "o1", - get_input_labels_function: LabelListFactory | None = get_input_labels, - get_input_label_text_loopback_function: Callable = get_input_label_text_loopback, select_ports: Callable[..., PortsDict] = select_ports_optical, with_loopback: bool = True, cross_section: CrossSectionSpec = strip, - component_name: str | None = None, loopback_xspacing: float = 5.0, rotation: int = 90, ) -> Component: @@ -104,27 +79,21 @@ def add_grating_couplers_with_loopback_fiber_single( Args: component: to add grating_couplers. grating_coupler: grating_coupler spec function, string or dict. - layer_label: optional layer_label for the ports. gc_port_name: grating_coupler port name. - get_input_labels_function: function to get grating_coupler labels. - get_input_label_text_loopback_function: select_ports: function to select ports. with_loopback: adds a reference loopback. cross_section: for routing. - component_name: optional component name. loopback_xspacing: in um. rotation: in degrees, 90 for North South devices, 0 for East-West. """ c = Component() component = gf.get_component(component) - c.component = component c.add_ref(component) grating_coupler = gf.get_component(grating_coupler) c.info["polarization"] = grating_coupler.info["polarization"] c.info["wavelength"] = grating_coupler.info["wavelength"] - component_name = component_name or component.metadata_child.get("name") io_gratings = [] optical_ports = select_ports(component.ports) @@ -138,16 +107,6 @@ def add_grating_couplers_with_loopback_fiber_single( c.add(gc_ref) c.add_port(name=port.name, port=port) - if layer_label and get_input_labels_function: - labels = get_input_labels_function( - io_gratings, - optical_ports, - component_name=component_name, - layer_label=layer_label, - gc_port_name=gc_port_name, - ) - c.add(labels) - p2 = optical_ports[0] p1 = optical_ports[-1] @@ -175,30 +134,6 @@ def add_grating_couplers_with_loopback_fiber_single( p1.port_type = "loopback" p2.port_type = "loopback" - if layer_label and get_input_labels_function: - port = wg.ports["o2"] - text = get_input_label_text_loopback_function( - port=port, gc=grating_coupler, gc_index=0, component_name=component_name - ) - - c.add_label( - text=text, - position=port.center, - anchor="o", - layer=layer_label, - ) - - port = wg.ports["o1"] - text = get_input_label_text_loopback_function( - port=port, gc=grating_coupler, gc_index=1, component_name=component_name - ) - c.add_label( - text=text, - position=port.center, - anchor="o", - layer=layer_label, - ) - c.copy_child_info(component) return c @@ -216,12 +151,7 @@ def add_grating_couplers_with_loopback_fiber_array( gc_rotation: int = -90, straight_separation: float = 5.0, bend: ComponentSpec = bend_euler, - layer_label: LayerSpec | None = None, - layer_label_loopback: LayerSpec | None = None, - component_name: str | None = None, with_loopback: bool = True, - nlabels_loopback: int = 2, - get_input_labels_function: LabelListFactory | None = get_input_labels, cross_section: CrossSectionSpec = "xs_sc", select_ports: Callable = select_ports_optical, loopback_yspacing: float = 4.0, @@ -237,13 +167,7 @@ def add_grating_couplers_with_loopback_fiber_array( gc_rotation: grating coupler rotation in degrees. straight_separation: in um. bend: bend spec. - layer_label: for testing label. - layer_label_loopback: for testing label alignment loopback. - component_name: optional component name. with_loopback: If True, add compact loopback alignment ports. - nlabels_loopback: number of ports to label \ - (0: no labels, 1: first port, 2: both ports). - get_input_labels_function: for getting test labels. cross_section: CrossSectionSpec. select_ports: function to select ports. loopback_yspacing: in um. @@ -255,7 +179,6 @@ def add_grating_couplers_with_loopback_fiber_array( gc = gf.get_component(grating_coupler) direction = "S" - component_name = component_name or component.metadata_child.get("name") c = Component() c.copy_child_info(component) @@ -290,16 +213,6 @@ def add_grating_couplers_with_loopback_fiber_array( gc_ref.connect(gc.ports[gc_port_name].name, port) references += [gc_ref] - if layer_label and get_input_labels_function: - labels = get_input_labels_function( - io_gratings=references, - ordered_ports=optical_ports, - component_name=component_name, - layer_label=layer_label, - gc_port_name=gc_port_name, - ) - c.add(labels) - if with_loopback: y0 = references[0].ports[gc_port_name].y - loopback_yspacing xs = [p.x for p in optical_ports] @@ -341,32 +254,8 @@ def add_grating_couplers_with_loopback_fiber_array( c.add([gca1, gca2]) c.add(loopback_route.references) c.add_port(name="loopback_1", port=port0) - c.add_port(name=f"loopback_{len(component.ports)+2}", port=port1) - - component_name_loopback = f"loopback_{component_name}" - if nlabels_loopback == 1: - io_gratings_loopback = [gca1] - ordered_ports_loopback = [port0] - elif nlabels_loopback == 2: - io_gratings_loopback = [gca1, gca2] - ordered_ports_loopback = [port0, port1] - if nlabels_loopback == 0 or layer_label is None: - pass - elif 0 < nlabels_loopback <= 2 and get_input_labels_function: - c.add( - get_input_labels_function( - io_gratings=io_gratings_loopback, - ordered_ports=ordered_ports_loopback, - component_name=component_name_loopback, - layer_label=layer_label_loopback or layer_label, - gc_port_name=gc_port_name, - ) - ) - else: - raise ValueError( - f"Invalid nlabels_loopback = {nlabels_loopback}, " - "valid (0: no labels, 1: first port, 2: both ports2)" - ) + c.add_port(name="loopback_2", port=port1) + ports = [p.flip() for p in component.ports.values()] c.add_ports(ports) c.copy_child_info(component) diff --git a/gdsfactory/samples/01_component_pcell_with_pins.py b/gdsfactory/samples/01_component_pcell_with_pins.py index d61975de2e..f0c0f28d2b 100644 --- a/gdsfactory/samples/01_component_pcell_with_pins.py +++ b/gdsfactory/samples/01_component_pcell_with_pins.py @@ -29,7 +29,12 @@ def straight_narrow( if __name__ == "__main__": - wg = straight_narrow(decorator=gf.add_pins.add_pins) + from functools import partial + c = partial( + gf.c.spiral_inner_io, + decorator=gf.c.add_grating_couplers_with_loopback_fiber_array, + ) + wg = c() # By default show adds pins, so you don't need it to show_ports wg.show(show_ports=False) diff --git a/test-data-regression/test_settings_add_grating_couplers_.yml b/test-data-regression/test_settings_add_grating_couplers_.yml index e8d6d7d96c..4cbcfa8f93 100644 --- a/test-data-regression/test_settings_add_grating_couplers_.yml +++ b/test-data-regression/test_settings_add_grating_couplers_.yml @@ -6,16 +6,12 @@ settings: default: component: function: straight - component_name: null gc_port_name: o1 - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 - layer_label: null select_ports: function: select_ports settings: @@ -23,16 +19,12 @@ settings: full: component: function: straight - component_name: null gc_port_name: o1 - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 - layer_label: null select_ports: function: select_ports settings: diff --git a/test-data-regression/test_settings_add_grating_couplers_fiber_array_.yml b/test-data-regression/test_settings_add_grating_couplers_fiber_array_.yml index a17630b0ff..eec2c6754b 100644 --- a/test-data-regression/test_settings_add_grating_couplers_fiber_array_.yml +++ b/test-data-regression/test_settings_add_grating_couplers_fiber_array_.yml @@ -35,23 +35,17 @@ settings: component: spiral_inner_io settings: length: 20000.0 - component_name: null cross_section: xs_sc excluded_ports: null gc_port_name: o1 gc_rotation: -90 - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 grating_separation: 127.0 - layer_label: null - layer_label_loopback: null loopback_yspacing: 4.0 - nlabels_loopback: 2 select_ports: function: select_ports settings: @@ -65,23 +59,17 @@ settings: component: spiral_inner_io settings: length: 20000.0 - component_name: null cross_section: xs_sc excluded_ports: null gc_port_name: o1 gc_rotation: -90 - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 grating_separation: 127.0 - layer_label: null - layer_label_loopback: null loopback_yspacing: 4.0 - nlabels_loopback: 2 select_ports: function: select_ports settings: diff --git a/test-data-regression/test_settings_add_grating_couplers_with_loopback_fiber_single_.yml b/test-data-regression/test_settings_add_grating_couplers_with_loopback_fiber_single_.yml index a6cfa3da7c..b486ed0037 100644 --- a/test-data-regression/test_settings_add_grating_couplers_with_loopback_fiber_single_.yml +++ b/test-data-regression/test_settings_add_grating_couplers_with_loopback_fiber_single_.yml @@ -53,24 +53,16 @@ settings: child: null default: component: spiral_inner_io_fiber_single - component_name: null cross_section: function: cross_section settings: add_pins_function_name: add_pins_inside1nm gc_port_name: o1 - get_input_label_text_loopback_function: - function: get_input_label_text - settings: - prefix: loopback_ - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 - layer_label: null loopback_xspacing: 5.0 rotation: 90 select_ports: @@ -80,24 +72,16 @@ settings: with_loopback: true full: component: spiral_inner_io_fiber_single - component_name: null cross_section: function: cross_section settings: add_pins_function_name: add_pins_inside1nm gc_port_name: o1 - get_input_label_text_loopback_function: - function: get_input_label_text - settings: - prefix: loopback_ - get_input_labels_function: - function: get_input_labels grating_coupler: function: grating_coupler_elliptical_trenches settings: polarization: te taper_angle: 35 - layer_label: null loopback_xspacing: 5.0 rotation: 90 select_ports: diff --git a/test-data-regression/test_settings_spiral_inner_io_fiber_array_.yml b/test-data-regression/test_settings_spiral_inner_io_fiber_array_.yml index ff2797a3e8..0efb5841ef 100644 --- a/test-data-regression/test_settings_spiral_inner_io_fiber_array_.yml +++ b/test-data-regression/test_settings_spiral_inner_io_fiber_array_.yml @@ -12,14 +12,14 @@ ports: port_type: optical shear_angle: null width: 0.5 - loopback_4: + loopback_2: center: - 254.0 - 46.0 layer: - 1 - 0 - name: loopback_4 + name: loopback_2 orientation: 90.0 port_type: optical shear_angle: null