Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inheritance from standard cells #249

Merged
merged 4 commits into from Feb 17, 2024
Merged

Allow inheritance from standard cells #249

merged 4 commits into from Feb 17, 2024

Conversation

sebastian-goeldi
Copy link
Collaborator

Move the code creating the KCell from __call__ for _kcell.

This will allow to make inheritance.

E.g.

```Create a post-processed waveguide```
import kfactory as kf

class TestBendEuler(kf.cells.euler.BendEuler):  # type: ignore[unused-ignore, misc]
    def __init__(self) -> None:
        super().__init__(kf.kcl)

    @kf.cell  # type: ignore[misc, unused-ignore]
    def __call__(self, width: float) -> kf.KCell:  # type: ignore[override, unused-ignore]
        c = self._kcell(
            width=width,
            radius=30,
            layer=LAYER.WG,
            enclosure=wg_enc,
            angle=90,
            resolution=150,
        )
        c.info.creation_time = "2023-02-12Z23:00:00"

        return c

# could also use bend_euler = TestBendEuler()
bend = TestBendEuler()(width=1)

@sebastian-goeldi
Copy link
Collaborator Author

sebastian-goeldi commented Feb 12, 2024

@joamatab is this what you roughly wanted?

@github-actions github-actions bot added enhancement New feature or request cells labels Feb 12, 2024
@joamatab
Copy link
Collaborator

joamatab commented Feb 13, 2024

not really, this seems overly complicated

i prefer functions over classes, as they are easier to read and to write

@sebastian-goeldi
Copy link
Collaborator Author

You have to choose, either make it inheritable as a class or use no decorator.

With this you now have three choices:

  • The above
  • my_kcell.dup() (needs name change to avoid collision, i.e. doesn't change the cached KCell)
  • use e.g. kf.cells.straight.straight._kcell(...) to get the uncached version directly and wrap that in a @cell decorator to cache (this will not set all settings though, only the ones passed to the new function with @cell)

I can't give you something to inject a post_process into an existing function. At that point, just unlock the cell and modify it, it's the same as if you were grabbing kwargs from the footprint of the function.

@joamatab
Copy link
Collaborator

then, l prefer keeping the cell decorator as it is and then passing an explicit post_process function

gdsfactory/gdsfactory#2524

@sebastian-goeldi sebastian-goeldi merged commit 742d04c into main Feb 17, 2024
7 checks passed
@sebastian-goeldi sebastian-goeldi deleted the improve-cells branch February 17, 2024 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cells enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants