Skip to content

fix(lumerical): extend ports beyond PML - #766

Open
joamatab wants to merge 2 commits into
mainfrom
fix/lumerical-port-extension-pml
Open

fix(lumerical): extend ports beyond PML#766
joamatab wants to merge 2 commits into
mainfrom
fix/lumerical-port-extension-pml

Conversation

@joamatab

@joamatab joamatab commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • include per-side FDTD margins in the physical port extension length
  • ensure exported waveguides extend beyond the PML for every port orientation
  • add a regression test comparing exported GDS and FDTD bounds

Validation

  • uv run pytest gplugins/lumerical/tests/test_write_sparameters_lumerical.py gplugins/lumerical/tests/test_background_layers.py gplugins/lumerical/tests/test_netlist.py gplugins/lumerical/tests/test_netlist_get_routes.py -q
  • uv run ruff check gplugins/lumerical/write_sparameters_lumerical.py gplugins/lumerical/tests/test_write_sparameters_lumerical.py
  • uv run ruff format --check gplugins/lumerical/write_sparameters_lumerical.py gplugins/lumerical/tests/test_write_sparameters_lumerical.py

Summary by Sourcery

Extend exported waveguides so that all ports reach beyond the FDTD PML margins and add coverage via regression testing.

Bug Fixes:

  • Ensure physical port extensions include per-side FDTD margins so exported waveguides reach beyond the PML for all port orientations.

Tests:

  • Add a regression test verifying that the exported GDS geometry extends beyond the simulated FDTD bounds for configured margins.

@sourcery-ai

sourcery-ai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Extends physical port waveguides so they reach beyond the FDTD PML margins and adds a regression test to verify exported GDS bounds against FDTD simulation bounds, using a more stateful test session stub to capture FDTD and GDS settings.

Sequence diagram for updated port extension beyond PML in write_sparameters_lumerical

sequenceDiagram
    participant write_sparameters_lumerical
    participant extension_extend_ports

    write_sparameters_lumerical->write_sparameters_lumerical: [compute port_extension_beyond_pml from ss.port_extension and xmargin_left/xmargin_right/ymargin_top/ymargin_bot]
    write_sparameters_lumerical->extension_extend_ports: extend_ports(component_extended, port_extension_beyond_pml)
    extension_extend_ports-->write_sparameters_lumerical: component_extended_beyond_pml
Loading

File-Level Changes

Change Details Files
Extend physical port waveguides beyond the FDTD PML margins when writing Lumerical S-parameters.
  • Compute an effective port extension that includes both the configured port_extension and the maximum of per-side FDTD margins.
  • Use the combined extension length when generating the component with extended ports so waveguides always extend beyond the PML regardless of port orientation.
  • Preserve existing behavior of flattening the extended component after adjusting the extension length.
gplugins/lumerical/write_sparameters_lumerical.py
Enhance the Lumerical write_sparameters tests with a stateful session stub and a regression test ensuring exported GDS extends beyond FDTD bounds.
  • Update the _Session test double to record FDTD solver settings passed to addfdtd and the path used for GDS import.
  • Add a regression test that writes S-parameters for a simple straight waveguide and then re-imports the exported GDS to compare its x-bounds against recorded FDTD x_min/x_max.
  • Validate that the exported component’s x-range exceeds the FDTD bounds in both directions, confirming ports extend beyond PML with margins applied.
gplugins/lumerical/tests/test_write_sparameters_lumerical.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

Copy link
Copy Markdown

Label error. Requires at least 1 of: breaking, bug, github_actions, documentation, dependencies, enhancement, feature, maintenance, security. Found:

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In port_extension_beyond_pml, using max(xmargin_left, xmargin_right, ymargin_top, ymargin_bot) assumes symmetric behavior across all orientations; if margins are intentionally asymmetric per side, consider computing the required extension per port direction instead of a global max to avoid over-extension on some ports.
  • In test_port_extension_reaches_beyond_pml, relying on re-importing the written GDS path adds I/O and an extra dependency on the GDS import behavior; consider asserting against the bounds of component_extended_beyond_pml (or the object passed to gdsimport) directly via a hook or helper to keep the test focused on the FDTD/port extension logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `port_extension_beyond_pml`, using `max(xmargin_left, xmargin_right, ymargin_top, ymargin_bot)` assumes symmetric behavior across all orientations; if margins are intentionally asymmetric per side, consider computing the required extension per port direction instead of a global max to avoid over-extension on some ports.
- In `test_port_extension_reaches_beyond_pml`, relying on re-importing the written GDS path adds I/O and an extra dependency on the GDS import behavior; consider asserting against the bounds of `component_extended_beyond_pml` (or the object passed to `gdsimport`) directly via a hook or helper to keep the test focused on the FDTD/port extension logic.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant