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

add a function for get_component #625

Merged
merged 6 commits into from
Feb 22, 2025
Merged

add a function for get_component #625

merged 6 commits into from
Feb 22, 2025

Conversation

sebastian-goeldi
Copy link
Collaborator

@sebastian-goeldi sebastian-goeldi commented Feb 21, 2025

Adds a very similar to gdsfactory's get_component function to KCLayout. This will look in the factories or return accordingly either a KCell (in case of int or whatever the functions wants).

Also allows direct casting to other classes based on ProtoTKCell[Any].

@joamatab does gdsfactory's get_component have a different function for the all angle functions or how is that handled?

\cc @flaport

Summary by Sourcery

Add a get_component function to KCLayout to retrieve components using various specifications and support direct casting to other classes. Include tests to validate the function's behavior and error handling.

New Features:

  • Introduce a get_component function in KCLayout that retrieves components based on various specifications, including integers, strings, callable functions, and dictionaries.

Enhancements:

  • Enable direct casting to other classes based on ProtoTKCell[Any] within the get_component function.

Tests:

  • Add tests for the new get_component function to verify its behavior with different input types and ensure it raises errors appropriately.

Copy link
Contributor

sourcery-ai bot commented Feb 21, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new get_component function to the KCLayout class, similar to gdsfactory's function, allowing for flexible component retrieval and casting to other classes. It also includes tests for various use cases and error handling.

Updated class diagram for KCLayout with get_component function

classDiagram
    class KCLayout {
        +get_component(spec: KCellSpec, output_type: type[K], cell_kwargs: Any) K
        +get_component(spec: int) KCell
        +get_component(spec: str, cell_kwargs: Any) ProtoTKCell[Any]
        +get_component(spec: Callable[..., K], cell_kwargs: Any) K
        +get_component(spec: K) K
    }
    class KCellSpecDict {
        +component: str
        +settings: dict[str, Any]
    }
    class ProtoTKCell {
        <<interface>>
    }
    KCLayout --> ProtoTKCell
    KCLayout --> KCellSpecDict
    KCellSpec : int | str | KCellSpecDict | ProtoTKCell[Any] | Callable[..., ProtoTKCell[Any]]
    KCLayout : KCellSpec
Loading

Updated class diagram for KCellSpec and related types

classDiagram
    class KCellSpec {
        <<TypeAlias>>
        int | str | KCellSpecDict | ProtoTKCell[Any] | Callable[..., ProtoTKCell[Any]]
    }
    class KCellSpecDict {
        +component: str
        +settings: NotRequired[dict[str, Any]]
    }
    class ProtoTKCell {
        <<interface>>
    }
    KCellSpec --> KCellSpecDict
    KCellSpec --> ProtoTKCell
Loading

File-Level Changes

Change Details Files
Addition of the get_component function to KCLayout.
  • Implemented multiple overloads for get_component to handle different types of specifications.
  • Added logic to handle callable specifications, string specifications, and integer specifications.
  • Included error handling for invalid use of cell keyword arguments with static cells.
src/kfactory/layout.py
Introduction of KCellSpec and KCellSpecDict types.
  • Defined KCellSpec as a type alias for various specification types.
  • Created KCellSpecDict as a TypedDict for component specifications with optional settings.
src/kfactory/typings.py
Addition of tests for the get_component function.
  • Tested normal function calls with different parameters.
  • Tested function calls with output_type parameter.
  • Included tests to ensure proper error handling for invalid input.
tests/test_layout.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the enhancement New feature or request label Feb 21, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.97%. Comparing base (060e948) to head (67d1b28).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #625      +/-   ##
==========================================
+ Coverage   65.89%   65.97%   +0.08%     
==========================================
  Files          64       64              
  Lines        9713     9732      +19     
  Branches     1811     1816       +5     
==========================================
+ Hits         6400     6421      +21     
  Misses       2782     2782              
+ Partials      531      529       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastian-goeldi sebastian-goeldi changed the title add a function add a function for get_component Feb 21, 2025
@sebastian-goeldi sebastian-goeldi merged commit ee11df5 into main Feb 22, 2025
18 checks passed
@sebastian-goeldi sebastian-goeldi deleted the add-get-component branch February 22, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants