Skip to content

Conversation

joamatab
Copy link
Contributor

@joamatab joamatab commented Jun 6, 2025

fixes lumerical extension

image

Summary by Sourcery

Improve the Lumerical extension by enhancing margin controls, adding layer exclusion support, and standardizing layer handling for robust S-parameter simulations

New Features:

  • Add an exclude_layers parameter to skip specified layers during simulation

Enhancements:

  • Default ymargin to 3 and support per-side margin overrides for backward compatibility
  • Automatically flatten and rename the extended component group before GDS export
  • Set cladding opacity to 10% in the Lumerical model
  • Expand docstring to include exclude_layers and additional simulation settings

Copy link
Contributor

sourcery-ai bot commented Jun 6, 2025

Reviewer's Guide

Refactored write_sparameters_lumerical to streamline margin handling, introduce exclude_layers filtering, unify layer tuple support and import logic, enforce component flattening/naming, and set cladding opacity; also updated get_meep_geometry to accept tuple layers.

Sequence Diagram: Lumerical Geometry Setup in write_sparameters_lumerical

sequenceDiagram
    participant func as write_sparameters_lumerical
    participant comp_ext as component_extended_beyond_pml
    participant session as s (LumericalSession)
    participant lstack as layer_stack

    func->>comp_ext: flatten()
    func->>comp_ext: name = "top"
    func->>comp_ext: write_gds()
    comp_ext-->>func: gdspath

    func->>session: addfdtd(...)
    func->>session: addmesh(...)
    func->>session: addstructure("rect", name="clad")
    func->>session: setnamed("clad", "alpha", 0.1)

    func->>comp_ext: get_polygons_points(merge=True)
    comp_ext-->>func: polygons_per_layer

    func->>lstack: layers.values()
    lstack-->>func: levels
    loop For each level in levels
        func->>func: Process level (get layer_tuple, layer_index)
        alt if layer_index in exclude_layers OR not in polygons_per_layer
            func->>func: Skip layer processing
        else
            func->>func: Get zmin, thickness, material details
            func->>session: gdsimport(gdspath, "top", layer_tuple_string)
            func->>session: setnamed(layername, "z", z_value)
            func->>session: setnamed(layername, "z span", thickness_value)
            func->>session: set_material(structure=layername, material=material_spec)
        end
    end

    loop For each port
        func->>func: Calculate port geometry (z, zspan) using updated index_to_zmin/thickness
        func->>session: addport()
        func->>session: Configure port properties (name, z, etc.)
    end
Loading

Class Diagram: Updated signature for write_sparameters_lumerical function

classDiagram
    class write_sparameters_lumerical {
        <<Function>>
        +component: Component
        +layer_stack: LayerStack
        +dirpath: PathType
        +port_source_name_function: Callable
        +session: Optional[Any]
        +layer_to_name: Optional[dict[Layer, str]]
        +simulation_settings: SimulationSettings
        +port_margin: float
        +port_source_offset: float
        +port_symmetries: Optional[list[str]]
        +material_name_to_lumerical: Optional[dict[str, MaterialSpec]]
        +delete_fsp_files: bool
        +xmargin: float
        +ymargin: float
        +xmargin_left: Optional[float]
        +xmargin_right: Optional[float]
        +ymargin_top: Optional[float]
        +ymargin_bot: Optional[float]
        +zmargin: float
        +exclude_layers: Optional[list[int]]
        +settings: dict
        +write_sparameters_lumerical(...): np.ndarray
    }
Loading

File-Level Changes

Change Details Files
Simplified margin API and added exclude_layers
  • Switched ymargin default to 3 and changed specific margins to optional with fallback logic
  • Introduced exclude_layers parameter to skip specified layers
  • Updated function signature and docstring to reflect new settings
gplugins/lumerical/write_sparameters_lumerical.py
Streamlined component padding application
  • Replaced inline or-fallbacks in padding call with explicit xmargin_left/right and ymargin_top/bot variables
gplugins/lumerical/write_sparameters_lumerical.py
Enforced component flattening and naming before GDS export
  • Copied and flattened component_extended_beyond_pml
  • Assigned fixed name “top” to the structure
gplugins/lumerical/write_sparameters_lumerical.py
Unified layer processing, indexing, and import logic
  • Added support for tuple layers alongside LogicalLayer/DerivedLayer
  • Built index_to_thickness and index_to_zmin via gf.get_layer and robust type checks
  • Filtered out exclude_layers and layers without polygons, imported GDS, set material and z positions with error handling
gplugins/lumerical/write_sparameters_lumerical.py
Configured cladding opacity
  • Set the cladding structure’s alpha (opacity) to 0.1 immediately after creation
gplugins/lumerical/write_sparameters_lumerical.py
Extended tuple layer support in MEEP geometry
  • Handled plain tuple layers in get_meep_geometry_from_component
  • Updated error message to include tuple support
gplugins/gmeep/get_meep_geometry.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!

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 bug Something isn't working label Jun 6, 2025
@joamatab joamatab merged commit a6dd9da into main Jun 6, 2025
14 of 16 checks passed
@joamatab joamatab deleted the fix_lumerical_extension branch June 6, 2025 22:13
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.

Hey @joamatab - I've reviewed your changes - here's some feedback:

  • Use explicit None checks for margin defaults (e.g., if xmargin_left is None:) rather than truthy or to allow zero margins.
  • Extract the repeated logic for deriving layer_tuple from level into a helper to reduce duplication and simplify the index/thickness loops.
  • Replace isinstance(..., tuple | LayerEnum) usages with a proper tuple of types (e.g., (tuple, LayerEnum)) to avoid runtime TypeError.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +210 to +213
xmargin_left = xmargin_left or xmargin
xmargin_right = xmargin_right or xmargin
ymargin_top = ymargin_top or ymargin
ymargin_bot = ymargin_bot or ymargin
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Use explicit None check instead of or for margin defaults

Using or will override valid zero values. Use if xmargin_left is None: xmargin_left = xmargin to ensure only None triggers the default.

Suggested change
xmargin_left = xmargin_left or xmargin
xmargin_right = xmargin_right or xmargin
ymargin_top = ymargin_top or ymargin
ymargin_bot = ymargin_bot or ymargin
if xmargin_left is None:
xmargin_left = xmargin
if xmargin_right is None:
xmargin_right = xmargin
if ymargin_top is None:
ymargin_top = ymargin
if ymargin_bot is None:
ymargin_bot = ymargin

layer = level.layer

if isinstance(layer, LogicalLayer):
assert isinstance(layer.layer, tuple | LayerEnum)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Invalid isinstance(..., tuple | LayerEnum) check

Use (tuple, LayerEnum) instead of tuple | LayerEnum in isinstance to avoid a TypeError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant