Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to gdsfactory9 #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions .github/workflows/test_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,23 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Test pre-commit hooks
run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit run -a
test_code:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

test:
runs-on: ${{ matrix.os }}
container: ghcr.io/gdsfactory/gdsfactory:main
strategy:
max-parallel: 12
matrix:
python-version: ["3.11"]
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
make dev
- name: Test with pytest
run: pytest tests/
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: uv sync --all-extras
- name: Run Tests
run: make test
2 changes: 1 addition & 1 deletion .github/write_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

filepath = PATH.repo / "docs" / "cells.rst"

skip = {}
skip: set[str] = set()

skip_plot: tuple[str, ...] = ("add_fiber_array_siepic",)
skip_settings: tuple[str, ...] = ("flatten", "safe_cell_names")
Expand Down
11 changes: 10 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
rev: "v0.4.1"
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
Expand All @@ -39,3 +39,12 @@ repos:
types: [file]
files: \.(j2|yml|yaml)$
exclude: .github/.*

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
args: [--strict]
additional_dependencies:
- gdsfactory
- pytest
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ install:
pre-commit install

dev:
pip install -e .[dev,docs]
uv sync --all-extras
uv pip install -e .
uv run pre-commit install

test:
pytest -s
uv run pytest -s

cov:
pytest --cov=gvtt
uv run pytest --cov=gvtt

mypy:
mypy . --ignore-missing-imports
uv run mypy . --ignore-missing-imports

pylint:
pylint gvtt
uv run pylint gvtt

ruff:
ruff --fix gvtt/*.py
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A public [gdsfactory](https://gdsfactory.github.io/gdsfactory/index.html#) proce

### Installation for users

Use python3.10 or python3.11, as some tools like kfactory are not available for older versions of python. We recommend [VSCode](https://code.visualstudio.com/) as an IDE.
Use python3.11 or later, as some tools like kfactory are not available for older versions of python. We recommend [VSCode](https://code.visualstudio.com/) as an IDE.

If you don't have python installed on your system you can [download anaconda](https://www.anaconda.com/download/)

Expand Down
11 changes: 2 additions & 9 deletions examples/python/tutorial-5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@gf.cell
def arm():
def arm() -> gf.Component:
c = gf.Component(name="arm")

straight = gf.components.straight(length=10)
Expand Down Expand Up @@ -35,7 +35,7 @@ def arm():


@gf.cell
def mzi():
def mzi() -> gf.Component:
c = gf.Component("mzi")
a1 = c << arm()
a2 = c << arm()
Expand Down Expand Up @@ -74,11 +74,4 @@ def mzi():
p2.dxmin = die.dxmax - die.info["frame_margin"]
p2.dy = 250

routes = gf.routing.route_bundle_all_angle(
[mymzi.ports["o1"], mymzi.ports["o2"]], [p1.ports["o1"], p2.ports["o1"]]
)

for route in routes:
c.add(route.references)

c.show()
5 changes: 3 additions & 2 deletions gvtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gdsfactory.get_factories import get_cells
from gdsfactory.pdk import Pdk, constants
from gdsfactory.technology import LayerViews
from gdsfactory.typings import Layer

from gvtt import components
from gvtt.config import PATH
Expand All @@ -19,7 +20,7 @@
LAYER.WG_ARCO_ADD: 100.0,
}

FRAME_LAYERS = {}
FRAME_LAYERS: dict[Layer, str] = {}

PORT_MARKER_LAYER_TO_TYPE = {
LAYER.PORT: "optical",
Expand Down Expand Up @@ -53,7 +54,7 @@
layers=LAYER,
layer_stack=None,
layer_views=LAYER_VIEWS,
layer_transitions=LAYER_TRANSITIONS,
layer_transitions=LAYER_TRANSITIONS, # type: ignore[arg-type]
constants=constants,
)

Expand Down
34 changes: 17 additions & 17 deletions gvtt/components/bend_euler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

from typing import Any

import gdsfactory as gf
import numpy as np
from gdsfactory.add_padding import get_padding_points
from gdsfactory.component import Component
from gdsfactory.components.wire import wire_corner
from gdsfactory.path import euler
from gdsfactory.typings import CrossSectionSpec, Optional
from gdsfactory.typings import Coordinate, CrossSectionSpec

from gvtt.tech import xs_sc

Expand All @@ -15,19 +16,19 @@ def _eulerR_1550(angle: float) -> float:
if angle == 0:
return 0.0
p, v, a0 = 0.79, 2093.0, 18.75 # for 1550 nm, TE, 1.875 um
return (v / max(abs(angle), a0)) ** (1.0 / p)
return float((v / max(abs(angle), a0)) ** (1.0 / p))


@gf.cell
def bend_euler(
angle: float = 90.0,
p: float = 1.0,
with_arc_floorplan: bool = False,
npoints: Optional[int] = None,
npoints: int | None = None,
direction: str = "ccw",
with_bbox: bool = True,
cross_section: CrossSectionSpec = xs_sc,
**kwargs,
**kwargs: Any,
) -> Component:
"""Returns an euler bend that transitions from straight to curved.

Expand Down Expand Up @@ -65,26 +66,25 @@ def bend_euler(
dx = gf.get_cross_section(cross_section, **kwargs)
radius = _eulerR_1550(abs(angle))

if radius is None:
return wire_corner(cross_section=dx)

c = Component()

p = euler(
path = euler(
radius=radius, angle=angle, p=p, use_eff=with_arc_floorplan, npoints=npoints
)

ref = c << p.extrude(dx)
c.info["length"] = float(np.round(p.length(), 3))
c.info["dy"] = float(np.round(abs(float(p.points[0][0] - p.points[-1][0])), 3))
c.info["radius_min"] = float(np.round(p.info["Rmin"], 3))
c.info["radius"] = float(p.dxmax)
ref = c << path.extrude(dx)
c.info["length"] = float(np.round(path.length(), 3))
c.info["dy"] = float(
np.round(abs(float(path.points[0][0] - path.points[-1][0])), 3)
)
c.info["radius_min"] = float(np.round(path.info["Rmin"], 3))
c.info["radius"] = float(path.dxmax)
c.info["width"] = float(dx.width)

if with_bbox and dx.bbox_layers:
padding = []
padding: list[list[Coordinate]] = []
angle = int(angle)
for offset in dx.bbox_offsets:
for offset in dx.bbox_offsets or []:
top = offset if angle in {180, -180, -90} else 0
bottom = 0 if angle in {-90} else offset
points = get_padding_points(
Expand All @@ -100,7 +100,7 @@ def bend_euler(
c.add_polygon(points, layer=layer)

if direction == "cw":
ref.dmirror(p1=[0, 0], p2=[1, 0])
ref.dmirror(p1=(0, 0), p2=(1, 0))

c.add_ports(ref.ports)
return c
Expand Down
29 changes: 15 additions & 14 deletions gvtt/components/die.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import gdsfactory as gf
from gdsfactory.components.text import text
from gdsfactory.typings import ComponentSpec, Float2, LayerSpec
from gdsfactory.components import text
from gdsfactory.typings import ComponentSpec, Coordinate, Float2, LayerSpec

import gvtt
from gvtt.layers import LAYER


def box(x0, y0, w, h):
def box(x0: float, y0: float, w: float, h: float) -> list[Coordinate]:
dw = w / 2.0
dh = h / 2.0
return [
[x0 + dw, y0 + dh],
[x0 + dw, y0 - dh],
[x0 - dw, y0 - dh],
[x0 - dw, y0 + dh],
(x0 + dw, y0 + dh),
(x0 + dw, y0 - dh),
(x0 - dw, y0 - dh),
(x0 - dw, y0 + dh),
]


Expand All @@ -33,20 +34,20 @@ def die(
c = gf.Component(name="die")
w, h = size[0], size[1]

for layer, size in gvtt.frame_dimensions.items():
c.add_polygon(box(w / 2.0 - size / 2.0, 0.0, size, h), layer=layer)
c.add_polygon(box(-w / 2.0 + size / 2.0, 0.0, size, h), layer=layer)
for layer_, size_ in gvtt.frame_dimensions.items():
c.add_polygon(box(w / 2.0 - size_ / 2.0, 0.0, size_, h), layer=layer_)
c.add_polygon(box(-w / 2.0 + size_ / 2.0, 0.0, size_, h), layer=layer_)

c.add_polygon(box(0.0, h / 2.0 - size / 2.0, w, size), layer=layer)
c.add_polygon(box(0.0, -h / 2.0 + size / 2.0, w, size), layer=layer)
c.add_polygon(box(0.0, h / 2.0 - size_ / 2.0, w, size_), layer=layer_)
c.add_polygon(box(0.0, -h / 2.0 + size_ / 2.0, w, size_), layer=layer_)

if bbox_layer:
c.add_polygon(
[[w / 2, h / 2], [w / 2, -h / 2], [-w / 2, -h / 2], [-w / 2, h / 2]],
[(w / 2, h / 2), (w / 2, -h / 2), (-w / 2, -h / 2), (-w / 2, h / 2)],
layer=bbox_layer,
)

c.info["frame_margin"] = gvtt.frame_dimensions[gvtt.LAYER.WG_SNGL_ADD] + 1.5
c.info["frame_margin"] = gvtt.frame_dimensions[LAYER.WG_SNGL_ADD] + 1.5

# c.info["port_x_position_west"] = (
# -w / 2.0 + gvtt.frame_dimensions[gvtt.LAYER.WG_SNGL_ADD] + 1.5
Expand Down
14 changes: 8 additions & 6 deletions gvtt/components/mmi1x2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gdsfactory as gf
from gdsfactory.component import Component
from gdsfactory.components.straight import straight as straight_function
from gdsfactory.components.taper import taper as taper_function
from gdsfactory.components import straight as straight_function
from gdsfactory.components import taper as taper_function
from gdsfactory.typings import ComponentSpec, CrossSectionSpec

from gvtt.tech import TECH
Expand All @@ -14,7 +14,7 @@ def mmi1x2(
length_taper: float = 1.0,
length_mmi: float = 43.25,
width_mmi: float = 6.25,
gap_mmi=(6.25 - 2 * TECH.width_strip) / 2,
gap_mmi: float = (6.25 - 2 * TECH.width_strip) / 2,
taper: ComponentSpec = taper_function,
straight: ComponentSpec = straight_function,
cross_section: CrossSectionSpec = "xs_sc",
Expand Down Expand Up @@ -69,24 +69,26 @@ def mmi1x2(
a = gap_mmi / 2 + width_taper / 2
_ = c << gf.get_component(straight, length=length_mmi, cross_section=xs_mmi)

temp_component = Component()

ports = [
gf.Port(
temp_component.add_port(
"o1",
orientation=180,
center=(0, 0),
width=width_taper,
layer=x.layer,
cross_section=x,
),
gf.Port(
temp_component.add_port(
"o2",
orientation=0,
center=(+length_mmi, +a),
width=width_taper,
layer=x.layer,
cross_section=x,
),
gf.Port(
temp_component.add_port(
"o3",
orientation=0,
center=(+length_mmi, -a),
Expand Down
18 changes: 12 additions & 6 deletions gvtt/components/mmi2x2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import gdsfactory as gf
from gdsfactory.component import Component
from gdsfactory.components.straight import straight as straight_function
from gdsfactory.components.taper import taper as taper_function
from gdsfactory.components import straight as straight_function
from gdsfactory.components import taper as taper_function
from gdsfactory.typings import ComponentSpec, CrossSectionSpec

from gvtt.tech import TECH
Expand Down Expand Up @@ -73,17 +73,23 @@ def mmi2x2(
straight, length=length_mmi, width=width_mmi, cross_section=cross_section
)

temp_component = Component()

ports = [
gf.Port("o1", orientation=180, center=(0, -a), width=w_taper, cross_section=x),
gf.Port("o2", orientation=180, center=(0, +a), width=w_taper, cross_section=x),
gf.Port(
temp_component.add_port(
"o1", orientation=180, center=(0, -a), width=w_taper, cross_section=x
),
temp_component.add_port(
"o2", orientation=180, center=(0, +a), width=w_taper, cross_section=x
),
temp_component.add_port(
"o3",
orientation=0,
center=(length_mmi, +a),
width=w_taper,
cross_section=x,
),
gf.Port(
temp_component.add_port(
"o4",
orientation=0,
center=(length_mmi, -a),
Expand Down
Loading
Loading