Skip to content

Commit

Permalink
Merge pull request #77 from gdsfactory/change-kcell
Browse files Browse the repository at this point in the history
Change kcell and allow complex ports
  • Loading branch information
sebastian-goeldi authored Apr 17, 2023
2 parents 1cd51ca + 747ee1a commit 28da648
Show file tree
Hide file tree
Showing 30 changed files with 2,137 additions and 2,185 deletions.
11 changes: 6 additions & 5 deletions docs/notebooks/00_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
# x(float): x coordinate
# y(float): y coordinate
#
text2 = t.transformed(kf.kdb.CplxTrans(2.0, 45.0, False, 5.0, 30.0))
text2 = t.transformed(
kf.kdb.DCplxTrans(2.0, 45.0, False, 5.0, 30.0).to_itrans(c.klib.dbu)
)
# text1.movey(25)
# text2.move([5, 30])
# text2.rotate(45)
Expand Down Expand Up @@ -130,11 +132,10 @@ def straight(length=10, width=1, layer=(1, 0)):
_layer = kf.klib.layer(*layer)
wg.shapes(_layer).insert(box)
wg.add_port(
kf.DPort(
kf.Port(
name="o1",
position=(box.left, box.center().y),
width=width,
angle=2,
dwidth=width,
dcplx_trans=kf.kdb.DCplxTrans(1, 180, False, box.left, box.center().y),
layer=_layer,
)
)
Expand Down
9 changes: 1 addition & 8 deletions docs/notebooks/02_DRC.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
c << box
c

c.shapes(c.klib.layer(2, 0)).insert(
kf.utils.violations.fix_spacing(
c, 1000, c.klib.layer(1, 0), metrics=kf.kdb.Metrics.Euclidian
)
)
c

# +
c = kf.KCell("tiled_test")

Expand All @@ -56,7 +49,7 @@
d2 = datetime.now()

c.shapes(c.klib.layer(2, 0)).insert(
kf.utils.violations.fix_spacing_tiled(
kf.utils.fix_spacing_tiled(
c,
1000,
c.klib.layer(1, 0),
Expand Down
1 change: 1 addition & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Tutorials

notebooks/00_geometry
notebooks/01_references
notebooks/02_DRC
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"black>=21",
"black>=23",
"mypy",
"pre-commit",
"gitpython",
Expand Down
19 changes: 9 additions & 10 deletions src/kfactory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""The import order matters, we need to first import the important stuff
"""KFactory package. Utilities for creating photonic devices.
Uses the klayout package as a backend.
isort:skip_file
"""

# The import order matters, we need to first import the important stuff.
# isort:skip_file

import klayout.dbcore as kdb
import klayout.lay as lay
from .kcell import (
KCell,
CplxKCell,
Instance,
Port,
DPort,
ICplxPort,
DCplxPort,
Ports,
autocell,
cell,
Expand All @@ -31,24 +31,23 @@

__all__ = [
"KCell",
"CplxKCell",
"Instance",
"Port",
"DPort",
"ICplxPort",
"DCplxPort",
"Ports",
"autocell",
"cell",
"klib",
"KLib",
"default_save",
"kdb",
"lay",
"port",
"pcells",
"placer",
"routing",
"utils",
"show",
"klay",
"logger",
"LayerEnum",
]
37 changes: 31 additions & 6 deletions src/kfactory/config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Kfactory configuration."""

from __future__ import annotations

import re
import sys
import traceback
from itertools import takewhile
from typing import Any, Optional

import loguru
from loguru import logger as logger


def add_traceback(record: loguru.Record) -> None:
"""Add a traceback to the logger."""
extra = record["extra"]
if extra.get("with_traceback", False):
extra["traceback"] = "\n" + "".join(traceback.format_stack())
Expand All @@ -19,25 +21,49 @@ def add_traceback(record: loguru.Record) -> None:


def tracing_formatter(record: loguru.Record) -> str:
# Filter out frames coming from Loguru internals
"""Traceback filtering.
Filter out frames coming from Loguru internals.
"""
frames = takewhile(
lambda f: "/loguru/" not in f.filename, traceback.extract_stack()
)
stack = " > ".join(f"{f.filename}:{f.name}:{f.lineno}" for f in frames)
record["extra"]["stack"] = stack

if record["extra"].get("with_backtrace", False):
return "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{extra[stack]}</cyan> - <level>{message}</level>\n{exception}"
return (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level>"
" | <cyan>{extra[stack]}</cyan> - <level>{message}</level>\n{exception}"
)

else:
return "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>\n{exception}"
return (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}"
"</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan>"
" - <level>{message}</level>\n{exception}"
)


class LogFilter:
def __init__(self, level: str, regex: Optional[str] = None) -> None:
"""Filter certain messages by log level or regex.
Filtered messages are not evaluated and discarded.
"""

def __init__(self, level: str, regex: str | None = None) -> None:
"""Create new filter.
Args:
level: Minimum log level to print to log. Options:
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
regex: Discard messages matching the regex string. Set to `None` to disable.
"""
self.level = level
self.regex = regex

def __call__(self, record: loguru.Record) -> bool:
"""Loguru needs the filter to be callable."""
levelno = logger.level(self.level).no
if self.regex is None:
return record["level"].no >= levelno
Expand All @@ -50,6 +76,5 @@ def __call__(self, record: loguru.Record) -> bool:
filter = LogFilter("DEBUG")
logger.remove()
logger.add(sys.stdout, format=tracing_formatter, filter=filter)
# format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}{extra[traceback]}</level>",

__all__ = ["logger", "filter"]
15 changes: 7 additions & 8 deletions src/kfactory/generic_tech.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Technology settings."""
from __future__ import annotations

from enum import Enum
from typing import Any, Dict, Iterator, List, Optional, Tuple
from typing import Any

from pydantic import BaseModel

from .kcell import KCell, KLib, LayerEnum, klib
from .kcell import LayerEnum

# from kfactory import KCell, KLib, library

Expand Down Expand Up @@ -119,11 +118,11 @@ class LayerLevel(BaseModel):
bias: in um for the etch.
"""

layer: Optional[Tuple[int, int]]
layer: tuple[int, int] | None
thickness: float
thickness_tolerance: Optional[float] = None
thickness_tolerance: float | None = None
zmin: float
material: Optional[str] = None
material: str | None = None
sidewall_angle: float = 0
z_to_bias: Optional[Tuple[List[float], List[float]]] = None
info: Dict[str, Any] = {}
z_to_bias: tuple[list[float], list[float]] | None = None
info: dict[str, Any] = {}
Loading

0 comments on commit 28da648

Please sign in to comment.