Skip to content

Commit

Permalink
Merge pull request #2701 from gdsfactory/forbid_width_missmatch
Browse files Browse the repository at this point in the history
Forbid width missmatch
  • Loading branch information
joamatab committed Apr 25, 2024
2 parents 9cd9dbd + 422cb9b commit add7f60
Show file tree
Hide file tree
Showing 39 changed files with 326 additions and 164 deletions.
4 changes: 2 additions & 2 deletions docs/components.rst
Expand Up @@ -1370,7 +1370,7 @@ edge_coupler_silicon

import gdsfactory as gf

c = gf.components.edge_coupler_silicon(length=100, width1=0.5, width2=0.2, with_two_ports=True, cross_section='xs_sc', port_order_name=['o1', 'o2'], port_order_types=['optical', 'optical'])
c = gf.components.edge_coupler_silicon(length=100, width1=0.5, width2=0.2, with_two_ports=True, cross_section='xs_sc', port_names=['o1', 'o2'], port_types=['optical', 'optical'])
c.plot()


Expand Down Expand Up @@ -3334,7 +3334,7 @@ taper

import gdsfactory as gf

c = gf.components.taper(length=10.0, width1=0.5, with_two_ports=True, cross_section='xs_sc', port_order_name=['o1', 'o2'], port_order_types=['optical', 'optical'])
c = gf.components.taper(length=10.0, width1=0.5, with_two_ports=True, cross_section='xs_sc', port_names=['o1', 'o2'], port_types=['optical', 'optical'])
c.plot()


Expand Down
8 changes: 6 additions & 2 deletions gdsfactory/component.py
Expand Up @@ -2951,8 +2951,12 @@ def _check_uncached_components(component, mode):
# from functools import partial
import gdsfactory as gf

c = gf.c.mzi()
c = c.simplify(200e-3)
# c = gf.c.mzi()
# c = c.simplify(200e-3)
c = gf.Component()
s = c << gf.c.straight()
b = c << gf.c.bend_circular(width=1)
b.connect("o1", s.ports["o2"])
c.show()

# c1 = gf.Component()
Expand Down
37 changes: 23 additions & 14 deletions gdsfactory/component_reference.py
Expand Up @@ -804,38 +804,47 @@ def connect(

self.move(origin=p, destination=destination)

if destination.orientation is not None:
self.move(
-overlap
* np.array(
[
cos(destination.orientation * pi / 180),
sin(destination.orientation * pi / 180),
]
)
)

if not np.isclose(p.width, destination.width) and not allow_width_mismatch:
message = f"Port width mismatch: {p.width} != {destination.width} in {self.parent.name} on layer {p.layer}"
message = (
f"Port width mismatch: {p.width} != {destination.width} in {self.parent.name} on layer {p.layer}. "
"Use allow_width_mismatch=True to ignore"
)
if CONF.on_width_missmatch == "error":
raise ValueError(message)
elif CONF.on_width_missmatch == "warn":
warnings.warn(message)

if p.layer != destination.layer and not allow_layer_mismatch:
message = f"Port layer mismatch: {p.layer} != {destination.layer} in {self.parent.name}"
message = (
f"Port layer mismatch: {p.layer} != {destination.layer} in {self.parent.name}. "
"Use allow_layer_mismatch=True to ignore"
)
if CONF.on_layer_missmatch == "error":
raise ValueError(message)
elif CONF.on_layer_missmatch == "warn":
warnings.warn(message)

if p.port_type != destination.port_type and not allow_type_mismatch:
message = f"Port type mismatch: {p.port_type} != {destination.port_type} in {self.parent.name}"
message = (
f"Port type mismatch: {p.port_type} != {destination.port_type} in {self.parent.name}. "
"Use allow_type_mismatch=True to ignore"
)
if CONF.on_type_missmatch == "error":
raise ValueError(message)
elif CONF.on_type_missmatch == "warn":
warnings.warn(message)

if destination.orientation is not None:
self.move(
-overlap
* np.array(
[
cos(destination.orientation * pi / 180),
sin(destination.orientation * pi / 180),
]
)
)

return self

def get_ports_list(self, **kwargs) -> list[Port]:
Expand Down
4 changes: 4 additions & 0 deletions gdsfactory/components/array_with_fanout.py
@@ -1,5 +1,7 @@
from __future__ import annotations

import warnings

import gdsfactory as gf
from gdsfactory.cell import cell
from gdsfactory.component import Component
Expand Down Expand Up @@ -39,6 +41,8 @@ def array_with_fanout(
bend_port_name2: optional port name.
cross_section: cross_section spec.
"""
warnings.warn("array_with_fanout is deprecated. Use gf.c.array instead")

c = Component()
component = gf.get_component(component)
bend = gf.get_component(bend, cross_section=cross_section)
Expand Down
7 changes: 6 additions & 1 deletion gdsfactory/components/array_with_via.py
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from functools import partial

import numpy as np
Expand Down Expand Up @@ -45,6 +46,8 @@ def array_with_via(
port_offset: Optional port movement in um.
kwargs: cross_section settings.
"""
warnings.warn("array_with_fanout is deprecated. Use gf.c.array instead")

c = Component()
component = gf.get_component(component)
via_stack = gf.get_component(via_stack)
Expand Down Expand Up @@ -80,7 +83,9 @@ def array_with_via(
length=xlength, cross_section=cross_section, **kwargs
)
straightx_ref.connect(
"e2", via_stack_ref.get_ports_list(orientation=port_orientation)[0]
"e2",
via_stack_ref.get_ports_list(orientation=port_orientation)[0],
allow_layer_mismatch=True,
)
c.add_port(port_name, port=straightx_ref.ports["e1"])
if port_offset:
Expand Down
2 changes: 1 addition & 1 deletion gdsfactory/components/coupler_full.py
Expand Up @@ -120,5 +120,5 @@ def coupler_full(
# cladding_layers=[(111, 0)],
# cladding_offsets=[3],
)
c.show()
c.show(show_ports=True)
# c.show(show_ports=True)
24 changes: 19 additions & 5 deletions gdsfactory/components/dbr.py
Expand Up @@ -107,17 +107,31 @@ def dbr(
c = Component()
l1 = snap_to_grid(l1)
l2 = snap_to_grid(l2)
cell = dbr_cell(w1=w1, w2=w2, l1=l1, l2=l2, cross_section=cross_section)
cell = dbr_cell(w1=w1, w2=w2, l1=l1, l2=l2, cross_section=cross_section, **kwargs)
c.add_array(cell, columns=n, rows=1, spacing=(l1 + l2, 100))
c.add_port("o1", port=cell.ports["o1"])
p1 = c.add_port("o2", port=cell.ports["o2"])

s = gf.c.straight(length=l1, cross_section=cross_section, **kwargs)
sl = c << s
sr = c << s

p1 = cell.ports["o2"].copy()
p1.center = [(l1 + l2) * n, 0]

sl.connect(port="o2", destination=cell.ports["o1"], allow_width_mismatch=True)
sr.connect(
port="o1",
destination=p1,
allow_width_mismatch=True,
)

c.add_port("o1", port=sl.ports["o1"])
c.add_port("o2", port=sr.ports["o2"])
return c


if __name__ == "__main__":
# c = dbr(w1=0.5, w2=0.6, l1=0.2, l2=0.3, n=10)
c = dbr()
c = dbr_cell()
c = dbr(n=10)
# c = dbr_cell()
# c.assert_ports_on_grid()
c.show(show_ports=True)
4 changes: 2 additions & 2 deletions gdsfactory/components/edge_coupler_array.py
Expand Up @@ -23,14 +23,14 @@
width2=0.2,
length=100,
with_two_ports=True,
port_order_types=("optical", "edge_te"),
port_types=("optical", "edge_te"),
)
edge_coupler_silicon_2 = partial(
taper,
width2=0.2,
length=130,
with_two_ports=True,
port_order_types=("optical", "edge_te"),
port_types=("optical", "edge_te"),
)


Expand Down
2 changes: 1 addition & 1 deletion gdsfactory/components/ge_detector_straight_si_contacts.py
Expand Up @@ -62,7 +62,7 @@ def ge_detector_straight_si_contacts(

if taper:
t1 = c << taper
t1.connect("o2", wg["o1"])
t1.connect("o2", wg["o1"], allow_width_mismatch=True)
c.add_port("o1", port=t1["o1"])

else:
Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/components/greek_cross.py
Expand Up @@ -34,7 +34,7 @@ def greek_cross(
widths: list of widths (same order as layers).
offsets: how much to extend each layer beyond the cross length
negative shorter, positive longer.
via: via component to attach to the cross.
via_stack: via component to attach to the cross.
.. code::
Expand Down Expand Up @@ -87,7 +87,7 @@ def greek_cross(
# Add via
for port in port_at_length:
via_stack_ref = c << gf.get_component(via_stack)
via_stack_ref.connect("e1", port)
via_stack_ref.connect("e1", port, allow_layer_mismatch=True)
c.add_port(name=port.name, port=via_stack_ref.ports["e3"])

c.auto_rename_ports()
Expand Down
14 changes: 12 additions & 2 deletions gdsfactory/components/optimal_hairpin.py
Expand Up @@ -99,10 +99,20 @@ def optimal_hairpin(
xports = min(xpts)
yports = -a + width / 2
c.add_port(
name="e1", center=(xports, -yports), width=width, orientation=180, layer=layer
name="e1",
center=(xports, -yports),
width=width,
orientation=180,
layer=layer,
port_type="electrical",
)
c.add_port(
name="e2", center=(xports, yports), width=width, orientation=180, layer=layer
name="e2",
center=(xports, yports),
width=width,
orientation=180,
layer=layer,
port_type="electrical",
)
return c

Expand Down
3 changes: 2 additions & 1 deletion gdsfactory/components/polarization_splitter_rotator.py
Expand Up @@ -9,6 +9,7 @@
coupler_straight_asymmetric,
)
from gdsfactory.components.taper import taper
from gdsfactory.snap import snap_to_grid2x
from gdsfactory.typings import CrossSectionSpec, Float2, Float3


Expand Down Expand Up @@ -67,7 +68,7 @@ def polarization_splitter_rotator(
)

def bend_s_width(t: ndarray) -> ndarray:
return w4 + (width_out - w4) * t
return snap_to_grid2x(w4 + (width_out - w4) * t)

x_bend = x.copy(width_function=bend_s_width)

Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/components/resistance_sheet.py
Expand Up @@ -52,8 +52,8 @@ def resistance_sheet(
r = c << compass(size=(length + 2 * offset, width + 2 * offset), layer=layer)
c.absorb(r)

pad1.connect("e3", r0.ports["e1"])
pad2.connect("e1", r0.ports["e3"])
pad1.connect("e3", r0.ports["e1"], allow_layer_mismatch=True)
pad2.connect("e1", r0.ports["e3"], allow_layer_mismatch=True)

c.info["resistance"] = ohms_per_square * width * length if ohms_per_square else 0

Expand Down
14 changes: 5 additions & 9 deletions gdsfactory/components/ring_crow_couplers.py
Expand Up @@ -5,7 +5,7 @@
import gdsfactory as gf
from gdsfactory.component import Component
from gdsfactory.components.bend_circular import bend_circular
from gdsfactory.components.coupler_full import coupler_full
from gdsfactory.components.coupler import coupler
from gdsfactory.cross_section import strip
from gdsfactory.typings import ComponentSpec, CrossSectionSpec

Expand All @@ -15,7 +15,7 @@ def ring_crow_couplers(
radius: list[float] = [10.0] * 3,
bends: list[ComponentSpec] = [bend_circular] * 3,
ring_cross_sections: list[CrossSectionSpec] = [strip] * 3,
couplers: list[ComponentSpec] = [coupler_full] * 4,
couplers: list[ComponentSpec] = [coupler] * 4,
) -> Component:
"""Coupled ring resonators with coupler components between gaps.
Expand Down Expand Up @@ -59,12 +59,8 @@ def ring_crow_couplers(
c = Component()

couplers_refs = []
for coupler in couplers:
coupler_ref = (
c.add_ref(coupler)
if type(coupler) == gf.Component
else c.add_ref(coupler())
)
for _coupler in couplers:
coupler_ref = c.add_ref(gf.get_component(_coupler))
couplers_refs.append(coupler_ref)

# Input bus
Expand Down Expand Up @@ -132,7 +128,7 @@ def ring_crow_couplers(

if __name__ == "__main__":
c = ring_crow_couplers(
couplers=[gf.components.coupler_full(coupling_length=0.01, dw=0)] * 4
# couplers=[gf.components.coupler_full(coupling_length=0.01, dw=0)] * 4
)

c.show(show_ports=True, show_subports=False)
Expand Down
18 changes: 14 additions & 4 deletions gdsfactory/components/ring_double_pn.py
Expand Up @@ -177,10 +177,20 @@ def ring_double_pn(
doped_heater_waveguide_offset + doped_heater_width / 2 + add_gap
)

bottom_left_heater_via = c << heater_vias()
bottom_right_heater_via = c << heater_vias()
bottom_left_heater_via.connect("e3", bottom_heater_ref.ports["o1"])
bottom_right_heater_via.connect("e3", bottom_heater_ref.ports["o2"])
bottom_l_heater_via = c << heater_vias()
bottom_r_heater_via = c << heater_vias()
bottom_l_heater_via.connect(
"e3",
bottom_heater_ref.ports["o1"],
allow_layer_mismatch=True,
allow_type_mismatch=True,
)
bottom_r_heater_via.connect(
"e3",
bottom_heater_ref.ports["o2"],
allow_layer_mismatch=True,
allow_type_mismatch=True,
)

c.add_port("o1", port=th_waveguide.ports["o1"])
c.add_port("o2", port=th_waveguide.ports["o2"])
Expand Down

0 comments on commit add7f60

Please sign in to comment.