Skip to content

Commit

Permalink
fix mzi and coupler (#18)
Browse files Browse the repository at this point in the history
* fix mzi and coupler
* fix pyproject
  • Loading branch information
joamatab authored Sep 20, 2023
1 parent 703ee5a commit 3274ad1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
make docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v2
with:
path: "./docs/_build/html/"
deploy-docs:
Expand Down
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)
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(
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)

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"])
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))

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"])

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)
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

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

cp2 = c << _cp1
cp1 = c << splitter
cp2 = c << combiner
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)
# 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(
length=delta_length / 2 + length_y,
width=width,
layer=layer,
enclosure=enclosure,
)
syl.connect("o1", b5.ports["N0"])
syl.connect("o1", b5.ports["o2"])
b6 = c << bend
b6.connect("W0", syl.ports["o2"], mirror=True)
b6.connect("o1", syl.ports["o2"], mirror=True)
# 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(
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"])

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

sytl = c << kf.kcl.pdk.get_cell(
straight_y, length=length_y, width=width, layer=layer, enclosure=enclosure
sytl = c << straight_y(
length=length_y, width=width, layer=layer, enclosure=enclosure
)
sytl.connect("o1", b1.ports["N0"])
sytl.connect("o1", b1.ports["o2"])

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(
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"])

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"])
c.add_ports([port for port in cp2.ports if port.orientation == 0])
c.autorename_ports()
return c
Expand Down
33 changes: 3 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = ["flit_core >=3.2,<4"]

[project]
authors = [
{name = "Skandan Chandrasekar", email = "[email protected]"}
{name = "gdsfactory", email = "[email protected]"}
]
classifiers = [
"Programming Language :: Python :: 3.10",
Expand All @@ -17,7 +17,7 @@ dependencies = [
"kfactory==0.8.4",
"scipy"
]
description = "KLayout generic PDK"
description = "Kfactory generic PDK"
keywords = ["python"]
license = {file = "LICENSE"}
name = "kgeneric"
Expand All @@ -37,7 +37,7 @@ docs = [
"autodoc_pydantic",
"matplotlib",
"jupytext",
"jupyter-book==0.14.0",
"jupyter-book>=0.15.1,<0.16",
"sphinx-autodoc-typehints",
"sphinx-click"
]
Expand Down 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 3274ad1

Please sign in to comment.