Skip to content

Commit

Permalink
Merge pull request #2 from twpalab/base_cpw
Browse files Browse the repository at this point in the history
Add basic components and library structure
  • Loading branch information
PietroCampana authored Jan 31, 2024
2 parents 9898d8a + 079f474 commit b36ca3a
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 12 deletions.
54 changes: 45 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = ">=3.10, <=3.12"
python = ">=3.10, <=3.12.1"
gdsfactory = "7.10.5"

[build-system]
Expand All @@ -28,6 +28,7 @@ pylint = ">=2.16.0"
pylint-exit = "^1.2.0"
pytest = ">=7.2.2"
pytest-mock = ">=3.10.0"
pytest-regressions = ">=2.5.0"
mypy = "^1.7.1"

[tool.poetry.group.docs]
Expand All @@ -44,5 +45,8 @@ sphinx-copybutton = "^0.5.1"
sphinx-last-updated-by-git = "^0.3.5"

[[tool.mypy.overrides]]
module=["h5py"]
module=["gdsfactory.*"]
ignore_missing_imports = true

[tool.pytest.ini_options]
filterwarnings = ["ignore::DeprecationWarning"]
20 changes: 19 additions & 1 deletion src/qutegds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
"""qutegds module."""

import importlib.metadata as im
import sys

__version__ = im.version(__package__)

import gdsfactory as gf
from gdsfactory.generic_tech import get_generic_pdk
from gdsfactory.get_factories import get_cells

from qutegds.components import *

generic_pdk = get_generic_pdk()
cells = get_cells(sys.modules[__name__])
qute_pdk = gf.Pdk(
name="qute",
cells=cells,
base_pdk=generic_pdk,
layers=generic_pdk.layers,
layer_views=generic_pdk.layer_views,
cross_sections=generic_pdk.cross_sections,
)
qute_pdk.activate()
100 changes: 100 additions & 0 deletions src/qutegds/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""List of coplanar waveguide elements."""
from functools import partial

import gdsfactory as gf
from gdsfactory import Component
from gdsfactory.typings import ComponentFactory, ComponentSpec

from qutegds.geometry import subtract

WIDTH = 6
GAP = 3
WIDTH_PAD = 350
GAP_PAD = 70
SPACE_PAD = 10


@gf.cell()
def cpw(
component_name: str = "straight", gap: float = GAP, width: float = WIDTH, **kwargs
) -> Component:
"""
Return simple coplanar waveguide from single component.
By default, returns negative mask of the CPW trace.
Args:
component_name (str): name of the component to be used
width (float): width of the central CPW trace
gap (float): space in um between the CPW trace and ground
"""
cpw = gf.Component()
outer = gf.get_component(component_name, width=width + 2 * gap, **kwargs)
inner = gf.get_component(component_name, width=width, **kwargs)
_ = cpw << subtract(outer, inner)
cpw.add_ports(outer.ports)
return cpw


snake = partial(cpw, component_name="delay_snake")


@gf.cell()
def straight_taper(
straight: ComponentSpec = gf.components.straight,
taper: ComponentFactory = gf.components.taper,
) -> Component:
"""Return straight section connected with taper."""
st = gf.get_component(straight)
return gf.add_tapers(
st,
taper=taper,
ports=[st["o1"]],
)


@gf.cell()
def rf_port(
width1: float = WIDTH,
width2: float = WIDTH_PAD,
gap1: float = GAP,
gap2: float = GAP_PAD,
len_taper: float = 200,
len_rect: float = 100,
space_pad=SPACE_PAD,
**kwargs,
) -> Component:
"""Return rf port."""
cpw = gf.Component()
straight = partial(gf.components.straight, **kwargs)
taper = partial(gf.components.taper, length=len_taper, **kwargs)

outer = straight_taper(
straight=partial(
straight, length=len_rect + space_pad, width=width2 + 2 * gap2
),
taper=partial(taper, width1=width1 + 2 * gap1, width2=width2 + 2 * gap2),
)
inner = straight_taper(
straight=partial(straight, length=len_rect, width=width2),
taper=partial(taper, width1=width1, width2=width2),
)
_ = cpw << subtract(outer, inner)
cpw.add_ports(outer.ports)
return cpw


@gf.cell()
def cpw_with_ports(
gap=GAP, width=WIDTH, length=1000, straight=cpw, launcher=rf_port
) -> Component:
"""CPW with ports at extremities."""
launch = launcher(gap1=gap, width1=width)
c = gf.Component()
lref = c << launch
lref2 = c << launch
stref = c << straight(gap=gap, width=width, length=length)

lref.connect("o1", stref.ports["o2"])
lref2.connect("o1", stref.ports["o1"])
return c
6 changes: 6 additions & 0 deletions src/qutegds/geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Geometry related functions."""
from functools import partial

import gdsfactory as gf

subtract = partial(gf.geometry.boolean, operation="not")
44 changes: 44 additions & 0 deletions tests/test_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
This code tests all your cells in the PDK.
it will test 3 things:
1. difftest: will test the GDS geometry of a new GDS compared to a reference. Thanks to Klayout fast booleans.add()
2. settings test: will compare the settings in YAML with a reference YAML file.add()
3. ensure ports are on grid, to avoid port snapping errors that can create 1nm gaps later on when you build circuits.
"""
import pathlib

import pytest
from gdsfactory.component import Component
from pytest_regressions.data_regression import DataRegressionFixture

from qutegds import cells

skip_test = {"subtract"}
cell_names = set(cells.keys()) - set(skip_test)
dirpath = pathlib.Path(__file__).absolute().parent / "gds_ref"


@pytest.fixture(params=cell_names, scope="function")
def component(request) -> Component:
"""Return requested component."""
return cells[request.param]()


# def test_pdk_gds(component: Component) -> None:
# """Avoid regressions in GDS geometry shapes and layers."""
# difftest(component, dirpath=dirpath)


def test_pdk_settings(
component: Component, data_regression: DataRegressionFixture
) -> None:
"""Avoid regressions when exporting settings."""
data_regression.check(component.to_dict())


def test_assert_ports_on_grid(component: Component):
"""Check if ports are aligned to grid."""
component.assert_ports_on_grid()
8 changes: 8 additions & 0 deletions tests/test_components/test_pdk_settings_cpw_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function: cpw
info: {}
module: qutegds.components
name: cpw
settings:
component_name: straight
gap: 3
width: 6
12 changes: 12 additions & 0 deletions tests/test_components/test_pdk_settings_cpw_with_ports_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function: cpw_with_ports
info: {}
module: qutegds.components
name: cpw_with_ports
settings:
gap: 3
launcher:
function: rf_port
length: 1000
straight:
function: cpw
width: 6
12 changes: 12 additions & 0 deletions tests/test_components/test_pdk_settings_rf_port_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function: rf_port
info: {}
module: qutegds.components
name: rf_port
settings:
gap1: 3
gap2: 70
len_rect: 100
len_taper: 200
space_pad: 10
width1: 6
width2: 350
8 changes: 8 additions & 0 deletions tests/test_components/test_pdk_settings_snake_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function: cpw
info: {}
module: qutegds.components
name: cpw_component_namedelay_snake
settings:
component_name: delay_snake
gap: 3
width: 6
15 changes: 15 additions & 0 deletions tests/test_components/test_pdk_settings_straight_taper_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function: straight_taper
info:
length: 10.0
route_info_length: 10.0
route_info_type: xs_sc
route_info_weight: 10.0
route_info_xs_sc_length: 10.0
width: 0.5
module: qutegds.components
name: straight_taper
settings:
straight:
function: straight
taper:
function: taper

0 comments on commit b36ca3a

Please sign in to comment.