Skip to content

Commit

Permalink
basic components and library structure
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroCampana committed Jan 30, 2024
1 parent 9898d8a commit 75c0004
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 10 deletions.
52 changes: 44 additions & 8 deletions poetry.lock

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

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
18 changes: 17 additions & 1 deletion src/qutegds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
"""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

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()
74 changes: 74 additions & 0 deletions src/qutegds/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""List of coplanar waveguide elements."""

from functools import partial

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

from qutegds.geometry import subtract


@gf.cell()
def cpw(component_name: str, gap: float = 1, width=2, **kwargs):
"""
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


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


@gf.cell()
def straight_taper(
straight: ComponentSpec = gf.components.straight,
taper: ComponentFactory = gf.components.taper,
):
"""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 = 2,
width2: float = 4,
gap1: float = 1,
gap2: float = 2,
len_taper: float = 4,
len_rect: float = 4,
**kwargs
):
"""Return rf port."""
cpw = gf.Component()
straight = partial(gf.components.straight, length=len_rect, **kwargs)
taper = partial(gf.components.taper, length=len_taper, **kwargs)

outer = straight_taper(
straight=partial(straight, width=width2 + 2 * gap2),
taper=partial(taper, width1=width1 + 2 * gap1, width2=width2 + 2 * gap2),
)
inner = straight_taper(
straight=partial(straight, width=width2),
taper=partial(taper, width1=width1, width2=width2),
)
_ = cpw << subtract(outer, inner)
cpw.add_ports(outer.ports)
return cpw
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")
42 changes: 42 additions & 0 deletions tests/test_components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""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 gdsfactory.difftest import difftest
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 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):
component.assert_ports_on_grid()

0 comments on commit 75c0004

Please sign in to comment.