Skip to content

Add mode settings to hashed parameters#683

Open
gronniger wants to merge 1 commit intogdsfactory:mainfrom
gronniger:fix_modes_in_caching
Open

Add mode settings to hashed parameters#683
gronniger wants to merge 1 commit intogdsfactory:mainfrom
gronniger:fix_modes_in_caching

Conversation

@gronniger
Copy link
Contributor

@gronniger gronniger commented Mar 6, 2026

Currently, the different input / output modes given in port_source_names, port_source_modes and port_modes are not considered in hashing the simulation settings during write_sparameters_meep().
Therefore, e.g. running a TM simulation after a TE simulation would load the wrong cached simulation results instead of performing a new simulation.

Summary by Sourcery

Ensure Meep S-parameter simulations account for port mode settings when hashing simulation configurations to select cached results.

Bug Fixes:

  • Include port source names, port source modes, and port modes in the simulation settings used for caching to avoid reusing results across different mode configurations.

Enhancements:

  • Simplify port initialization by deriving port names and mode defaults directly from the component ports instead of using an intermediate dummy component.

@gronniger gronniger requested a review from joamatab as a code owner March 6, 2026 15:43
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 6, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensure Meep S-parameter simulation caching accounts for port source/mode configuration by initializing port-related parameters early and including them in the hashed simulation settings, while removing an unnecessary dummy Component/port-extraction block.

Sequence diagram for updated Meep S-parameter caching with port modes

sequenceDiagram
    participant Caller
    participant write_sparameters_meep
    participant Component
    participant Cache

    Caller->>write_sparameters_meep: call write_sparameters_meep(component, port_source_names, port_source_modes, port_modes, ...)
    activate write_sparameters_meep

    write_sparameters_meep->>Component: read ports from component.ports
    Component-->>write_sparameters_meep: list of Port

    write_sparameters_meep->>write_sparameters_meep: derive port_names from component.ports
    write_sparameters_meep->>write_sparameters_meep: initialize port_source_names (fallback to port_names)
    write_sparameters_meep->>write_sparameters_meep: initialize port_source_modes (fallback {name: [0]})
    write_sparameters_meep->>write_sparameters_meep: initialize port_modes (fallback [0])

    write_sparameters_meep->>write_sparameters_meep: build sim_settings including port_source_names, port_source_modes, port_modes, resolution, port_symmetries, wavelength_start, wavelength_stop, ...
    write_sparameters_meep->>Cache: compute hash(sim_settings)
    Cache-->>write_sparameters_meep: cache_key

    write_sparameters_meep->>Cache: check cached_results[cache_key]
    alt cache hit
        Cache-->>write_sparameters_meep: cached S-parameters
        write_sparameters_meep-->>Caller: return cached S-parameters
    else cache miss
        write_sparameters_meep->>write_sparameters_meep: run Meep simulations (respecting port_source_names, port_source_modes, port_modes)
        write_sparameters_meep->>Cache: store results under cache_key
        Cache-->>write_sparameters_meep: ack
        write_sparameters_meep-->>Caller: return new S-parameters
    end
    deactivate write_sparameters_meep
Loading

File-Level Changes

Change Details Files
Include port source and mode configuration in the hashed simulation settings used for caching.
  • Initialize port_names directly from component.ports instead of from a dummy Component reference.
  • Default port_source_names, port_source_modes, and port_modes early in the function based on the component’s ports and basic mode indices.
  • Add port_source_names, port_source_modes, and port_modes to the sim_settings dict so they influence the cache key used by write_sparameters_meep().
gplugins/gmeep/write_sparameters_meep.py
Simplify port handling logic by removing redundant dummy component and port extraction code.
  • Delete creation of a dummy Component and associated component_ref used solely to obtain ports.
  • Remove the late redefinition of port_names, port_source_names, port_source_modes, and port_modes, relying instead on the earlier initialization.
gplugins/gmeep/write_sparameters_meep.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

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 - I've reviewed your changes and they look great!


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