Skip to content

add target_neff parameter to mode solver#711

Open
mdecea wants to merge 6 commits into
gdsfactory:mainfrom
mdecea:target_neff
Open

add target_neff parameter to mode solver#711
mdecea wants to merge 6 commits into
gdsfactory:mainfrom
mdecea:target_neff

Conversation

@mdecea
Copy link
Copy Markdown

@mdecea mdecea commented May 10, 2026

Summary by Sourcery

New Features:

  • Introduce an optional target_neff parameter on the Waveguide model to control the target effective index used by the mode solver. This is very relevant for bent and leaky modes.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an optional target_neff parameter to the Waveguide mode solver API and threads it through to td.ModeSpec, defaulting to the real part of the core refractive index when unspecified.

Sequence diagram for Waveguide target_neff propagation to ModeSpec

sequenceDiagram
    participant WG as Waveguide
    participant Core as CoreMaterial
    participant ModeSpec as td_ModeSpec

    WG->>Core: get_refractive_index()
    Core-->>WG: n_core
    WG->>WG: compute_target_neff()
    note over WG: if self.target_neff is not None
    WG->>ModeSpec: ModeSpec(num_modes, target_neff, bend_radius, bend_axis, num_pml)
Loading

Class diagram for updated Waveguide mode solver API

classDiagram
    class Waveguide {
        +float surface_thickness
        +float surface_k
        +float bend_radius
        +float target_neff
        +int num_modes
        +bool group_index_step
        +Precision precision
        waveguide()
    }

    class ModeSpec {
        +int num_modes
        +float target_neff
        +float bend_radius
        +int bend_axis
        +tuple num_pml
    }

    Waveguide ..> ModeSpec : creates
Loading

File-Level Changes

Change Details Files
Expose target_neff as a configurable mode-solver parameter and propagate it into ModeSpec while preserving the previous default behavior.
  • Extend Waveguide docstring to describe the new target_neff parameter and its default behavior.
  • Add target_neff: float
None = None as a Waveguide model field.
  • Compute a local target_neff value that falls back to n_core.real when the attribute is not set.
  • Pass the computed target_neff into td.ModeSpec in both waveguide() code paths instead of hard-coding n_core.real.

  • 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

    Copy link
    Copy Markdown
    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 - I've left some high level feedback:

    • The target_neff selection logic (self.target_neff vs n_core.real) is duplicated in both waveguide implementations; consider extracting this into a small helper/property to avoid repetition and keep behavior consistent if it changes later.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - The `target_neff` selection logic (`self.target_neff` vs `n_core.real`) is duplicated in both `waveguide` implementations; consider extracting this into a small helper/property to avoid repetition and keep behavior consistent if it changes later.

    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.

    Copy link
    Copy Markdown

    @gemini-code-assist gemini-code-assist Bot left a comment

    Choose a reason for hiding this comment

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

    Code Review

    This pull request introduces a target_neff parameter to the Waveguide class in gplugins/tidy3d/modes.py, allowing users to specify a target effective index for the mode solver. This parameter is integrated into the waveguide methods of both Waveguide and WaveguideCoupler. Feedback suggests documenting the new parameter in the WaveguideCoupler docstring for consistency and refactoring the duplicated logic for calculating target_neff into a shared method or property.

    Comment thread gplugins/tidy3d/modes.py Outdated
    Comment thread gplugins/tidy3d/modes.py Outdated
    @mdecea
    Copy link
    Copy Markdown
    Author

    mdecea commented May 10, 2026

    Changed the default material to lossless SiO2. The current SiO2 material causes perfectly good modes to show losses of 50 dB/cm!

    @mdecea
    Copy link
    Copy Markdown
    Author

    mdecea commented May 13, 2026

    Added functionality to track modes on bend radius sweeps. This makes it so that we are robust to modes changing order as the radius in the mode solver changes.

    @nikosavola nikosavola added the simulations simulation plugins label May 14, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    simulations simulation plugins

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants