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

Rework cross section #596

Merged
merged 11 commits into from
Feb 8, 2025
Merged

Rework cross section #596

merged 11 commits into from
Feb 8, 2025

Conversation

sebastian-goeldi
Copy link
Collaborator

@sebastian-goeldi sebastian-goeldi commented Jan 31, 2025

Summary by Sourcery

Refactor the cross section implementation to use a more generic approach based on abstract base classes and generics. Rename width parameter in extrude_path and extrude_path_points functions from µm to um.

New Features:

  • Introduce a new generic TCrossSection abstract base class for defining cross sections with different unit types.

Tests:

  • Update tests to reflect the changes in the cross section implementation.

Copy link
Contributor

sourcery-ai bot commented Jan 31, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new CrossSection class, refactors the existing SymmetricalCrossSection class, and adds a new abstract base class TCrossSection. The CrossSection class now uses a base SymmetricalCrossSection for its implementation. The LayerEnclosure class was also modified to use um instead of µm.

Class diagram for the new CrossSection hierarchy

classDiagram
    class TCrossSection~TUnit~ {
      <<abstract>>
      -_base_cross_section: SymmetricalCrossSection
      +width(): TUnit
      +layer(): LayerInfo
      +enclosure(): LayerEnclosure
      +sections(): dict
      +radius(): TUnit
      +radius_min(): TUnit
    }

    class SymmetricalCrossSection {
      +width: int
      +enclosure: LayerEnclosure
      +name: str
      +radius: int
      +radius_min: int
      +main_layer(): LayerInfo
    }

    class CrossSection {
      +__init__(width: int, layer: LayerInfo, sections: list)
      +sections(): tuple
    }

    class DCrossSection {
      +__init__(width: int, layer: LayerInfo, sections: list)
    }

    TCrossSection <|-- CrossSection
    TCrossSection <|-- DCrossSection
    CrossSection *-- SymmetricalCrossSection : uses
    DCrossSection *-- SymmetricalCrossSection : uses

    note for TCrossSection "Generic abstract base class for cross sections"
    note for SymmetricalCrossSection "Base implementation for cross sections"
    note for CrossSection "Concrete implementation for integer units"
    note for DCrossSection "Concrete implementation for database units"
Loading

File-Level Changes

Change Details Files
Introduce abstract base class TCrossSection and concrete class CrossSection.
  • Added an abstract base class TCrossSection.
  • Added a concrete class CrossSection that inherits from TCrossSection.
  • The CrossSection class now uses a base SymmetricalCrossSection for its implementation.
  • Added a DCrossSection class for double precision cross sections.
src/kfactory/cross_section.py
Refactor SymmetricalCrossSection class.
  • Added a default value for the name attribute.
  • Added radius and radius_min attributes.
  • Added a validator to set the name if it is not provided.
  • Removed the cached property decorator from the main_layer method.
src/kfactory/cross_section.py
Modify LayerEnclosure class to use um instead of µm.
  • Changed the documentation to use um instead of µm.
  • Updated the extrude_path and extrude_path_dynamic functions to use um instead of µm.
src/kfactory/enclosure.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

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 62.56983% with 134 lines in your changes missing coverage. Please review.

Project coverage is 65.88%. Comparing base (977cb38) to head (89cdeb9).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/kfactory/kcell.py 49.07% 53 Missing and 2 partials ⚠️
src/kfactory/cross_section.py 63.20% 42 Missing and 4 partials ⚠️
src/kfactory/enclosure.py 68.75% 14 Missing and 1 partial ⚠️
src/kfactory/port.py 64.28% 7 Missing and 3 partials ⚠️
src/kfactory/layout.py 81.39% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #596      +/-   ##
==========================================
- Coverage   65.97%   65.88%   -0.09%     
==========================================
  Files          64       64              
  Lines        9516     9636     +120     
  Branches     1772     1786      +14     
==========================================
+ Hits         6278     6349      +71     
- Misses       2717     2763      +46     
- Partials      521      524       +3     

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

@sebastian-goeldi sebastian-goeldi added the enhancement New feature or request label Feb 4, 2025
@sebastian-goeldi sebastian-goeldi marked this pull request as ready for review February 7, 2025 22:24
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.

if not bbox_offsets:
bbox_offsets = [0 for _ in range(len(bbox_layers))]
else:
if not len(bbox_offsets) == len(bbox_layers):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Simplify logical expression using De Morgan identities (de-morgan)

Suggested change
if not len(bbox_offsets) == len(bbox_layers):
if len(bbox_offsets) != len(bbox_layers):

if not bbox_offsets:
bbox_offsets = [0 for _ in range(len(bbox_layers))]
else:
if not len(bbox_offsets) == len(bbox_layers):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Simplify logical expression using De Morgan identities (de-morgan)

Suggested change
if not len(bbox_offsets) == len(bbox_layers):
if len(bbox_offsets) != len(bbox_layers):

if cross_section.name not in self.cross_sections:
self.cross_sections[cross_section.name] = cross_section
return cross_section
return self.cross_sections[cross_section.name]
xs = self.cross_sections[cross_section.name]
if not xs == cross_section:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Simplify logical expression using De Morgan identities (de-morgan)

Suggested change
if not xs == cross_section:
if xs != cross_section:

@@ -540,6 +537,7 @@
layer_sections: dict[kdb.LayerInfo, LayerSection]
_name: str | None = PrivateAttr()
main_layer: kdb.LayerInfo | None
bbox_sections: dict[kdb.LayerInfo, tuple[int, int, int, int]]

def __init__(
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Replace mutable default arguments with None (default-mutable-arg)

Comment on lines +428 to 430
if other is None:
return None
return kdb.CplxTrans(self.layout.dbu) * other
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

Suggested change
if other is None:
return None
return kdb.CplxTrans(self.layout.dbu) * other
return None if other is None else kdb.CplxTrans(self.layout.dbu) * other

@sebastian-goeldi sebastian-goeldi merged commit ccb2a2e into main Feb 8, 2025
15 of 16 checks passed
@sebastian-goeldi sebastian-goeldi deleted the rework-cross-section branch February 8, 2025 19:01
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