Skip to content

Commit

Permalink
fix mzi and coupler
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Sep 19, 2023
1 parent 703ee5a commit 8a0cf86
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 113 deletions.
19 changes: 8 additions & 11 deletions kgeneric/cells/coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def coupler(

wg = c << straight_coupler(gap, length, width, layer, enclosure)

sbend.connect("o2", wg.ports["o1"])
sbend.connect("o2", wg.ports["o1"], mirror=True)

Check warning on line 60 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L60

Added line #L60 was not covered by tests
sbend_2.connect("o2", wg.ports["o4"])
sbend_r_top = c << bend_s(
width=width,
Expand All @@ -66,7 +66,7 @@ def coupler(
layer=layer,
enclosure=enclosure,
)
sbend_r_bottom = c << bend_s(
sbend_r_bot = c << bend_s(

Check warning on line 69 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L69

Added line #L69 was not covered by tests
width=width,
height=(dy / 2 - width / 2 - gap / 2),
length=dx,
Expand All @@ -75,14 +75,11 @@ def coupler(
)

sbend_r_top.connect("o1", wg.ports["o3"])
sbend_r_bottom.connect("o1", wg.ports["o2"])

# sbend_r_top.transform(kdb.DTrans(0, False, 0, 0))
# sbend_r_bottom.transform(kdb.DTrans(0, False, 0, 0))
sbend_r_bot.connect("o1", wg.ports["o2"], mirror=True)

Check warning on line 78 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L78

Added line #L78 was not covered by tests

c.add_port(name="o1", port=sbend_2.ports["o1"])
c.add_port(name="o2", port=sbend.ports["o1"])
c.add_port(name="o3", port=sbend_r_bottom.ports["o2"])
c.add_port(name="o3", port=sbend_r_bot.ports["o2"])

Check warning on line 82 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L82

Added line #L82 was not covered by tests
c.add_port(name="o4", port=sbend_r_top.ports["o2"])
c.begin_instances_rec()
return c
Expand All @@ -109,13 +106,13 @@ def straight_coupler(
wg_top = c << straight(width, length, layer, enclosure)
wg_top.trans = kdb.Trans(0, True, 0, int((gap + width) / 2 / c.kcl.dbu))

wg_bottom = c << straight(width, length, layer, enclosure)
wg_bottom.trans = kdb.Trans(0, False, 0, -int((gap + width) / 2 / c.kcl.dbu))
wg_bot = c << straight(width, length, layer, enclosure)
wg_bot.trans = kdb.Trans(0, False, 0, -int((gap + width) / 2 / c.kcl.dbu))

Check warning on line 110 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L109-L110

Added lines #L109 - L110 were not covered by tests

c.add_port(name="o1", port=wg_top.ports["o1"])
c.add_port(name="o2", port=wg_top.ports["o2"])
c.add_port(name="o3", port=wg_bottom.ports["o2"])
c.add_port(name="o4", port=wg_bottom.ports["o1"])
c.add_port(name="o3", port=wg_bot.ports["o2"])
c.add_port(name="o4", port=wg_bot.ports["o1"])

Check warning on line 115 in kgeneric/cells/coupler.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/coupler.py#L114-L115

Added lines #L114 - L115 were not covered by tests

c.info["sim"] = "MODE"
return c
Expand Down
110 changes: 35 additions & 75 deletions kgeneric/cells/mzi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from kfactory import cell
from kfactory.kcell import LayerEnum
from kfactory.routing.optical import route
from kfactory.typings import CellSpec
from kfactory.typings import CellFactory
from kfactory.utils.enclosure import LayerEnclosure

from kgeneric.cells.coupler import coupler
Expand All @@ -21,12 +21,12 @@ def mzi(
length_y: float = 2.0,
length_x: float | None = 0.1,
bend: Callable[..., kf.KCell] = bend_euler,
straight: CellSpec = straight_function,
straight_y: CellSpec | None = None,
straight_x_top: CellSpec | None = None,
straight_x_bot: CellSpec | None = None,
splitter: CellSpec = coupler,
combiner: CellSpec | None = None,
straight: CellFactory = straight_function,
straight_y: CellFactory | None = None,
straight_x_top: CellFactory | None = None,
straight_x_bot: CellFactory | None = None,
splitter: CellFactory = coupler,
combiner: CellFactory | None = None,
with_splitter: bool = True,
port_e1_splitter: str = "o3",
port_e0_splitter: str = "o4",
Expand Down Expand Up @@ -78,17 +78,6 @@ def mzi(
"""
combiner = combiner or splitter

straight_x_top = (
partial(straight_x_top, layer=layer)
if straight_x_top and callable(straight_x_top)
else None
)
straight_x_bot = (
partial(straight_x_bot, layer=layer)
if straight_x_bot and callable(straight_x_bot)
else None
)
straight_x_top = straight_x_top or straight
straight_x_bot = straight_x_bot or straight
straight_y = straight_y or straight
Expand All @@ -99,7 +88,7 @@ def mzi(
"radius": radius,
"enclosure": enclosure,
}
bend = kf.kcl.pdk.get_cell(bend, **bend_settings)
bend = bend(**bend_settings)

Check warning on line 91 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L91

Added line #L91 was not covered by tests
c = kf.KCell()
straight_connect = partial(straight_dbu, layer=layer, enclosure=enclosure)
combiner_settings = {
Expand All @@ -109,85 +98,56 @@ def mzi(
}
kwargs.pop("kwargs", "")
kwargs |= combiner_settings
_cp1 = kf.kcl.pdk.get_cell(splitter, **kwargs)
kf.kcl.pdk.get_cell(combiner, **kwargs) if combiner else _cp1
splitter = splitter(**kwargs)
combiner = combiner(**kwargs) if combiner else splitter

Check warning on line 102 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L101-L102

Added lines #L101 - L102 were not covered by tests

if with_splitter:
cp1 = c << _cp1
else:
cp1 = _cp1

cp2 = c << _cp1
cp1 = c << splitter
cp2 = c << combiner

Check warning on line 105 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L104-L105

Added lines #L104 - L105 were not covered by tests
b5 = c << bend
# b5.transform(kf.kdb.Trans.M90)
b5.connect("W0", cp2.ports[port_e0_splitter])
b5.connect("o1", cp2.ports[port_e0_splitter], mirror=True)

Check warning on line 108 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L108

Added line #L108 was not covered by tests
# b5.instance.transform(kf.kdb.Trans(1, False, 0, 0))
# b5.transform(kf.kdb.Trans.M90.R180)

syl = c << kf.kcl.pdk.get_cell(
straight_y,
syl = c << straight_y(

Check warning on line 112 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L112

Added line #L112 was not covered by tests
length=delta_length / 2 + length_y,
width=width,
layer=layer,
enclosure=enclosure,
)
syl.connect("o1", b5.ports["N0"])
syl.connect("o1", b5.ports["o2"])

Check warning on line 118 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L118

Added line #L118 was not covered by tests
b6 = c << bend
b6.connect("W0", syl.ports["o2"], mirror=True)
b6.connect("o1", syl.ports["o2"], mirror=True)

Check warning on line 120 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L120

Added line #L120 was not covered by tests
# b6.transform(kf.kdb.Trans.M90.R270)

straight_x_bot = (
kf.kcl.pdk.get_cell(
straight_x_bot,
width=width,
length=length_x,
layer=layer,
enclosure=enclosure,
)
if length_x
else kf.kcl.pdk.get_cell(
straight_x_bot,
length=length_x,
width=width,
layer=layer,
enclosure=enclosure,
)
straight_x_bot = straight_x_bot(

Check warning on line 123 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L123

Added line #L123 was not covered by tests
width=width,
length=length_x,
layer=layer,
enclosure=enclosure,
)

sxb = c << straight_x_bot
sxb.connect("o1", b6.ports["N0"], mirror=True)
sxb.connect("o1", b6.ports["o2"])

Check warning on line 131 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L131

Added line #L131 was not covered by tests

b1 = c << bend
b1.connect("W0", cp1.ports[port_e1_splitter])
b1.connect("o1", cp1.ports[port_e1_splitter])

Check warning on line 134 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L134

Added line #L134 was not covered by tests

sytl = c << kf.kcl.pdk.get_cell(
straight_y, length=length_y, width=width, layer=layer, enclosure=enclosure
sytl = c << straight_y(

Check warning on line 136 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L136

Added line #L136 was not covered by tests
length=length_y, width=width, layer=layer, enclosure=enclosure
)
sytl.connect("o1", b1.ports["N0"])
sytl.connect("o1", b1.ports["o2"])

Check warning on line 139 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L139

Added line #L139 was not covered by tests

b2 = c << bend
b2.connect("N0", sytl.ports["o2"])
straight_x_top = (
kf.kcl.pdk.get_cell(
straight_x_top,
length=length_x,
width=width,
layer=layer,
enclosure=enclosure,
)
if length_x
else kf.kcl.pdk.get_cell(
straight_x_top,
length=length_x,
width=width,
layer=layer,
enclosure=enclosure,
)
b2.connect("o2", sytl.ports["o2"])
straight_x_top = straight_x_top(

Check warning on line 143 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L142-L143

Added lines #L142 - L143 were not covered by tests
length=length_x,
width=width,
layer=layer,
enclosure=enclosure,
)
sxt = c << straight_x_top
sxt.connect("o1", b2.ports["W0"])

# cp2.transform(port_e0_combiner, cp1.ports[port_e0_splitter])
sxt.connect("o1", b2.ports["o1"])

Check warning on line 150 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L150

Added line #L150 was not covered by tests

bend_width = abs(bend.ports[0].x - bend.ports[1].x)
cp2.connect(port_e0_combiner, cp1.ports[port_e0_splitter])
Expand All @@ -213,8 +173,8 @@ def mzi(
if with_splitter:
c.add_ports([port for port in cp1.ports if port.orientation == 180])
else:
c.add_port(name="o1", port=b1.ports["W0"])
c.add_port(name="o2", port=b5.ports["W0"])
c.add_port(name="o1", port=b1.ports["o1"])
c.add_port(name="o2", port=b5.ports["o1"])

Check warning on line 177 in kgeneric/cells/mzi.py

View check run for this annotation

Codecov / codecov/patch

kgeneric/cells/mzi.py#L176-L177

Added lines #L176 - L177 were not covered by tests
c.add_ports([port for port in cp2.ports if port.orientation == 0])
c.autorename_ports()
return c
Expand Down
27 changes: 0 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,6 @@ version_files = [
"pyproject.toml:version"
]

[tool.flake8]
exclude = [
".git",
"__pycache__",
"lib",
"docs/source/conf.py",
"build",
"dist",
".ipynb_checkpoints",
".tox",
"extra",
"deprecated",
".mypy_cache",
"venv",
"devsim"
]
extend-ignore = "RST303"
ignore = ["E501", "E503", "E722", "W503", "W503", "E203", "B950", "B305", "B018", "B902", "B020", "B905"]
max-complexity = 57
max-line-length = 88
select = ["B", "C", "E", "F", "W", "T4", "B9"]

[tool.isort]
include_trailing_comma = true
line_length = 88
multi_line_output = 3

[tool.mypy]
exclude = [
"kgeneric/cells/mzi.py",
Expand Down

0 comments on commit 8a0cf86

Please sign in to comment.