gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
31 stars 12 forks source link

Add automatic registering of KCell-functions to the KCLayout.factories #261

Closed sebastian-goeldi closed 7 months ago

sebastian-goeldi commented 7 months ago
import kfactory as kf

@kf.kcl.cell
def my_cell_function(...) -> kf.KCell:
    ...

Will now register the function at kf.kcl.factories.my_cell_function

import kfactory as kf

@kf.kcl.cell(register_factory=False)
def my_cell_function(...) -> kf.KCell:
    ...

Will not add it to kf.ckl.factories

Note: It's vital to use the proper KCLayout for registration:

import kfactory as kf
from my_package import MyPDK # Custom KCLayout instance (!=kf.kcl)

### Correct
@MyPDK.cell
def my_cell_function(...) -> kf.KCell:
    c = MyPDK.kcell() # or kf.KCell(kcl=MyPDK)
    ...
    return c

### Throws an error because we are trying to register a KCell belonging to `MyPDK` in `kf.kcl`
@kf.cell # or @kf.kcl.cell
def my_cell_function(...) -> kf.KCell:
    c = MyPDK.kcell()
    ...
    return c

### Throws an error because we are trying to register a KCell belonging to `kf.kcl` in `MyPDK`
@MyPDK.cell
def my_cell_function(...) -> kf.KCell:
    c = kf.KCell() # or kf.kcl.kcell()
    ...
    return c
sebastian-goeldi commented 7 months ago

@joamatab this is probably interesting for you