Skip to content

Commit

Permalink
Merge pull request #16 from gdsfactory/add_cells
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
joamatab authored Aug 16, 2023
2 parents 1f42aec + 0fa6826 commit 703ee5a
Show file tree
Hide file tree
Showing 50 changed files with 378 additions and 456 deletions.
146 changes: 22 additions & 124 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,141 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "0122e76bfe37d895fa9085712e65dbfef2e349b1"
rev: d2bd9cd497c81622c3f5774b336ab451691f1c36
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
exclude: ^(conda\.recipe/meta\.yaml|conda_build/templates/.*\.yaml|docs/click/meta\.yaml|conda/meta\.yaml|conda/construct.yaml|.*\.pic\.yml|conda/constructor/Miniforge3/construct.yaml)
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: trailing-whitespace

# - repo: https://github.com/hakancelik96/unimport
# rev: 0.14.1
# hooks:
# - id: unimport
# args: [--remove, --include-star-import]
# - repo: https://github.com/pycqa/isort
# rev: "3a72e069635a865a92b8a0273aa829f630cbcd6f"
# hooks:
# - id: isort
# files: "demo_project/.*"
# args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/psf/black
rev: "eb32729ab562c010d9f644a3bbb2305196b2deb7"
rev: 1b028cc9d99c2c2e82f9b727742539173a92a373
hooks:
- id: black
# exclude: '^gdsfactory/samples/notebooks/|^docs/notebooks/'

# - repo: https://github.com/pycqa/flake8
# rev: "647996c743f9e77368ce46cc74abe98549dd4c3a"
# hooks:
# - id: flake8

# - repo: https://github.com/kynan/nbstripout
# rev: e4c5b4dcbab4afa0b88b7a9243db42b1a8d95dde
# hooks:
# - id: nbstripout
# files: ".ipynb"

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.2
- repo: https://github.com/codespell-project/codespell
rev: 38bc4a97f6e22827e86526148efa38f1044a97f8
hooks:
- id: pyupgrade
args: [--py37-plus, --keep-runtime-typing]
- id: codespell
additional_dependencies:
- tomli

# - repo: https://github.com/codespell-project/codespell
# rev: 68ea3cff5eba266e0814794cce6cd19537f58137
# hooks:
# - id: codespell
# args: ["-L TE,TE/TM,te,ba,FPR,fpr_spacing,ro,donot"]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: ee7a347451760f817260ca3cafae4e3bec06bc84
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "6c0ceaccffa1ebb1db1ea1a6d7289b50d29bfce2"
hooks:
- id: shellcheck

# - repo: https://github.com/pre-commit/pygrep-hooks
# rev: 7b4409161486c6956bb3206ce96db5d56731b1b9 # Use the ref you want to point at
# hooks:
# - id: python-use-type-annotations
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/PyCQA/bandit
rev: 45619e0c8325fad08f0cbd74034e5161a16b1b4f
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.10.0
hooks:
- id: bandit
args: [--exit-zero]
# ignore all tests, not just tests data
exclude: ^tests/
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "961f38dddd22ebfc8338e1244352afdc71ee6771"
# hooks:
# - id: mypy
# exclude: ^(docs/|example-plugin/|tests/fixtures)
# additional_dependencies:
# - "pydantic"
# - repo: https://github.com/terrencepreilly/darglint
# rev: master
# hooks:
# - id: darglint
# - repo: https://github.com/pycqa/pydocstyle
# rev: "a6fe4222012e990042c86cdaaa904a8d059752ee"
# hooks:
# - id: pydocstyle
# additional_dependencies: ["pydocstyle[toml]"]
# - repo: https://github.com/asottile/reorder_python_imports
# rev: 2b2f0c74acdb3de316e23ceb7dd0d7945c354050
# hooks:
# - id: reorder-python-imports
# - repo: https://github.com/PyCQA/pylint
# rev: v2.14.1
# hooks:
# - id: pylint
# args: [--exit-zero]
# - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
# rev: 6565d773ca281682d7062d4c0be74538cc474cc9
# hooks:
# - id: pretty-format-java
# args: [--autofix]
# - id: pretty-format-kotlin
# args: [--autofix]
# - id: pretty-format-yaml
# args: [--autofix, --indent, "2"]
# - repo: https://github.com/adrienverge/yamllint.git
# rev: v1.21.0 # or higher tag
# hooks:
# - id: yamllint
# args: [--format, parsable, --strict]
# - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
# rev: 0.1.0 # or specific tag
# hooks:
# - id: yamlfmt
# - repo: https://github.com/pre-commit/pygrep-hooks
# rev: "f6fb13e9516d1a9720a30a4049c930235abd642e"
# hooks:
# - id: python-check-blanket-noqa
# - id: python-check-blanket-type-ignore
# - id: python-no-log-warn
# - id: python-no-eval
# - id: python-use-type-annotations
# - id: rst-backticks
# - id: rst-directive-colons
# - id: rst-inline-touching-normal
# - repo: https://github.com/nbQA-dev/nbQA
# rev: 952c895a21aced4601165c43f77188559a5e825c
# hooks:
# - id: nbqa-black
# additional_dependencies: [jupytext, black] # optional, only if you're using Jupytext
# - id: nbqa-pyupgrade
# args: ["--py37-plus"]
# - id: nbqa-flake8
# - id: nbqa-isort
# args: ["--float-to-top"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "9e466ccca34e1b6b1e3a160152db786b8bc4c788"
- id: pretty-format-toml
args: [--autofix]

- repo: https://github.com/aristanetworks/j2lint.git
rev: v1.1.0
hooks:
- id: ruff
- id: j2lint
args: [--ignore, jinja-statements-delimiter, jinja-statements-indentation, --]
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
install:
pip install -e .[dev]
pre-commit install

dev:
pip install -e .[dev,docs]
pip install git+https://github.com/gdsfactory/kfactory.git

dev: install

test:
pytest -s

Expand Down Expand Up @@ -33,7 +31,6 @@ update-pre:
git-rm-merged:
git branch -D `git branch --merged | grep -v \* | xargs`


release:
git push
git push origin --tags
Expand All @@ -43,12 +40,6 @@ build:
pip install build
python -m build

jupytext:
jupytext docs/**/*.ipynb --to py

notebooks:
jupytext docs/**/*.py --to ipynb

docs:
jb build docs

Expand Down
9 changes: 5 additions & 4 deletions docs/write_cells.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import inspect
import pathlib

import numpy as np
from kfactory.kcell import Any, Callable, KCell, LayerEnum, clean_name

from kgeneric.tests.test_cells import cell_factories as cells
from kfactory.kcell import KCell, Any, clean_name, Callable
from kfactory.kcell import LayerEnum


def dict2name(prefix: str = "", **kwargs) -> str:
Expand Down Expand Up @@ -34,7 +35,7 @@ def clean_value_json(
return value.name
elif type(value) in [float, np.float64]: # float
return np.round(value, 3)
elif isinstance(value, (tuple, list)):
elif isinstance(value, tuple | list):
return value
elif isinstance(value, dict):
return dict2name(**value)
Expand Down Expand Up @@ -78,7 +79,7 @@ def clean_value_json(
[
f"{p}={repr(clean_value_json(sig.parameters[p].default))}"
for p in sig.parameters
if isinstance(sig.parameters[p].default, (int, float, str, tuple))
if isinstance(sig.parameters[p].default, int | float | str | tuple)
and p not in skip_settings
]
)
Expand Down
4 changes: 3 additions & 1 deletion docs/write_cells_jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import inspect
import pathlib

from kfactory.kcell import clean_value

from kgeneric import cells_dict as cells

filepath = pathlib.Path(__file__).parent.absolute() / "cells.py"
Expand Down Expand Up @@ -50,7 +52,7 @@
[
f"{p}={repr(clean_value(sig.parameters[p].default))}"
for p in sig.parameters
if isinstance(sig.parameters[p].default, (int, float, str, tuple))
if isinstance(sig.parameters[p].default, int | float | str | tuple)
and p not in skip_settings
]
)
Expand Down
10 changes: 5 additions & 5 deletions kgeneric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
__version__ = "0.0.2"
from kfactory.pdk import Pdk, get_cells

from kgeneric.pdk import LAYER
from kgeneric import cells
from kgeneric import cells, gpdk, layers
from kgeneric.layers import LAYER
from kgeneric.tech import TECH


cells_dict = get_cells([cells])
cells_dict = get_cells([gpdk])
pdk = Pdk(name="generic", cell_factories=cells_dict, layers=LAYER)


__all__ = ("pdk", "cells")
__all__ = ("pdk", "gpdk", "cells", "layers", "TECH")
20 changes: 12 additions & 8 deletions kgeneric/cells/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# flake8: noqa

from .bezier import bend_s
from .circular import bend_circular
from .coupler import coupler, straight_coupler
from .euler import bend_euler, bend_s_euler
from .grating_coupler_elliptical import grating_coupler_elliptical
from .mzi import mzi
from .taper import taper
from .straight import straight
from kgeneric.cells.bezier import bend_s
from kgeneric.cells.circular import bend_circular
from kgeneric.cells.coupler import coupler, straight_coupler
from kgeneric.cells.euler import bend_euler, bend_s_euler
from kgeneric.cells.grating_coupler_elliptical import grating_coupler_elliptical
from kgeneric.cells.mzi import mzi
from kgeneric.cells.taper import taper
from kgeneric.cells.straight import straight, straight_dbu
from kgeneric.cells.dbu.taper import taper as taper_dbu


__all__ = [
"bend_circular",
Expand All @@ -18,6 +20,8 @@
"grating_coupler_elliptical",
"mzi",
"straight",
"straight_dbu",
"straight_coupler",
"taper",
"taper_dbu",
]
8 changes: 3 additions & 5 deletions kgeneric/cells/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import numpy as np
import numpy.typing as nty
from scipy.special import binom # type: ignore[import]

from kfactory import KCell, LayerEnum, cell, kdb
from kfactory.utils.enclosure import LayerEnclosure
from kfactory.utils.enclosure import extrude_path
from kfactory.utils.enclosure import LayerEnclosure, extrude_path
from scipy.special import binom # type: ignore[import]

__all__ = ["bend_s"]

Expand Down Expand Up @@ -93,8 +91,8 @@ def bend_s(


if __name__ == "__main__":
from kgeneric.pdk import LAYER
from kgeneric import pdk
from kgeneric.pdk import LAYER

um = 1 / pdk.kcl.dbu
enclosure = LayerEnclosure(
Expand Down
4 changes: 1 addition & 3 deletions kgeneric/cells/circular.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
"""

import numpy as np

from kfactory import kdb
from kfactory.kcell import KCell, LayerEnum, cell
from kfactory.utils.enclosure import LayerEnclosure
from kfactory.utils.enclosure import extrude_path
from kfactory.utils.enclosure import LayerEnclosure, extrude_path

__all__ = ["bend_circular"]

Expand Down
12 changes: 5 additions & 7 deletions kgeneric/cells/coupler.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from typing import Union

from kfactory import KCell, cell, kdb

from kfactory.kcell import LayerEnum

from kfactory.utils.enclosure import LayerEnclosure

from kgeneric.pdk import LAYER
from kgeneric.cells.bezier import bend_s
from kgeneric.cells.straight import straight
from kgeneric.layers import LAYER


@cell
Expand All @@ -18,17 +14,19 @@ def coupler(
dy: float = 5.0,
dx: float = 5.0,
width: float = 0.5,
layer: Union[int, LayerEnum] = LAYER.WG,
layer: int | LayerEnum = LAYER.WG,
enclosure: LayerEnclosure = LayerEnclosure(),
) -> KCell:
r"""Symmetric coupler.
Args:
gap: between straights in um.
length: of coupling region in um.
dy: port to port vertical spacing in um.
dx: length of bend in x direction in um.
layer: layer number or name.
enclosure: straight enclosure.
.. code::
dx dx
|------| |------|
Expand Down Expand Up @@ -95,7 +93,7 @@ def straight_coupler(
gap: float = 0.2,
length: float = 10.0,
width: float = 0.5,
layer: Union[int, LayerEnum] = LAYER.WG,
layer: int | LayerEnum = LAYER.WG,
enclosure: LayerEnclosure = LayerEnclosure(),
) -> KCell:
"""Straight coupler.
Expand Down
2 changes: 1 addition & 1 deletion kgeneric/cells/dbu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .taper import taper
from .straight import straight
from .taper import taper

__all__ = ["straight", "taper"]
Loading

0 comments on commit 703ee5a

Please sign in to comment.