Skip to content

Commit

Permalink
Merge pull request #144 from gdsfactory/143-keep_mirror-in-add_ports-…
Browse files Browse the repository at this point in the history
…is-not-always-set-properly

fixed keep_mirror flag for add_port
  • Loading branch information
sebastian-goeldi authored Jun 1, 2023
2 parents 91f217c + 4030a74 commit 9e1b748
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/143.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed add_port ignore keep_mirror flag
12 changes: 6 additions & 6 deletions src/kfactory/kcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def add_port(
"""
if self._locked:
raise LockedError(self)
self.ports.add_port(port=port, name=name)
self.ports.add_port(port=port, name=name, keep_mirror=keep_mirror)

def add_ports(
self, ports: Iterable[Port], prefix: str = "", keep_mirror: bool = False
Expand Down Expand Up @@ -2243,10 +2243,10 @@ def add_port(
"""
_port = port.copy()
if not keep_mirror:
if port._trans:
port._trans.mirror = False
elif port._dcplx_trans:
port._dcplx_trans.mirror = False
if _port._trans:
_port._trans.mirror = False
elif _port._dcplx_trans:
_port._dcplx_trans.mirror = False
if name is not None:
_port.name = name
self._ports.append(_port)
Expand All @@ -2257,7 +2257,7 @@ def add_ports(
"""Append a list of ports."""
for p in ports:
name = p.name or ""
self.add_port(port=p, name=prefix + name)
self.add_port(port=p, name=prefix + name, keep_mirror=keep_mirror)

@overload
def create_port(
Expand Down
38 changes: 38 additions & 0 deletions tests/test_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,41 @@ def test_connect_integer(wg):
wg2.connect("o1", wg1, "o1")

assert wg2.ports["o1"].trans == kf.kdb.Trans(0, False, 0, 0)


def test_keep_mirror(LAYER):
c = kf.KCell()

p1 = kf.Port(trans=kf.kdb.Trans.M90, width=1000, layer=LAYER.WG)

c.add_port(p1, name="o1")
c.add_port(p1, name="o2", keep_mirror=True)

assert c["o1"].trans.is_mirror() is False
assert c["o2"].trans.is_mirror() is True


def test_addports_keep_mirror(LAYER):
c = kf.KCell()

ports = [
kf.Port(
name=f"{i}",
width=1000,
layer=LAYER.WG,
trans=kf.kdb.Trans(i, True, 0, 0),
)
for i in range(4)
]

c.add_ports(ports, prefix="mirr_", keep_mirror=True)
c.add_ports(ports, prefix="nomirr_", keep_mirror=False)

for i in range(4):
t1 = c[f"mirr_{i}"].trans
t2 = c[f"nomirr_{i}"].trans

t2_mirr = t2.dup()
t2_mirr.mirror = not t2_mirr.is_mirror()

assert t1 == t2_mirr

0 comments on commit 9e1b748

Please sign in to comment.