From 3274ad1ed7eae2e84db4b99cfd3426142c423798 Mon Sep 17 00:00:00 2001 From: Joaquin Matres <4514346+joamatab@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:20:59 -0700 Subject: [PATCH] fix mzi and coupler (#18) * fix mzi and coupler * fix pyproject --- .github/workflows/pages.yml | 2 +- kgeneric/cells/coupler.py | 19 +++---- kgeneric/cells/mzi.py | 110 ++++++++++++------------------------ pyproject.toml | 33 +---------- 4 files changed, 47 insertions(+), 117 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 5553661..791f15a 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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: diff --git a/kgeneric/cells/coupler.py b/kgeneric/cells/coupler.py index eef367e..7189e1d 100644 --- a/kgeneric/cells/coupler.py +++ b/kgeneric/cells/coupler.py @@ -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, @@ -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, @@ -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 @@ -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 diff --git a/kgeneric/cells/mzi.py b/kgeneric/cells/mzi.py index bc848d4..2f2450d 100644 --- a/kgeneric/cells/mzi.py +++ b/kgeneric/cells/mzi.py @@ -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 @@ -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", @@ -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 @@ -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 = { @@ -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]) @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1776c5c..f3621f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = ["flit_core >=3.2,<4"] [project] authors = [ - {name = "Skandan Chandrasekar", email = "s39chand@uwaterloo.ca"} + {name = "gdsfactory", email = "contact@gdsfactory.com"} ] classifiers = [ "Programming Language :: Python :: 3.10", @@ -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" @@ -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" ] @@ -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",