Skip to content

fix: gdsfactory 9.43 compatibility (duplicate port + deprecated params)#165

Open
joamatab wants to merge 1 commit into
mainfrom
fix/gdsfactory-9.43-compat
Open

fix: gdsfactory 9.43 compatibility (duplicate port + deprecated params)#165
joamatab wants to merge 1 commit into
mainfrom
fix/gdsfactory-9.43-compat

Conversation

@joamatab
Copy link
Copy Markdown
Contributor

@joamatab joamatab commented May 18, 2026

Summary

  • Patch _register_ports to skip position-equality duplicate check — IHP transistors have pin-marker boxes on different layers (Metal1, GatPoly) at overlapping positions, and kfactory BasePort.__eq__ only compares transforms, causing false "duplicate port" errors
  • Remove deprecated component_name and taper params from add_pads_top (removed in gdsfactory 9.43 route_bundle API)

Test plan

  • All 714 tests pass locally (make test-force)

Summary by Sourcery

Ensure compatibility with gdsfactory 9.43 by adjusting port registration and updating pad-routing helpers.

Bug Fixes:

  • Work around false duplicate-port detection in gdsfactory 9.43 for IHP transistors by registering ports based on names instead of position equality.

Enhancements:

  • Update add_pads_top helpers to match the gdsfactory 9.43 route_bundle/add_pads_top API by removing deprecated parameters.

- Patch _register_ports to skip position-equality duplicate check.
  IHP transistors have pin-marker boxes on different layers (Metal1,
  GatPoly) at overlapping positions. kfactory BasePort.__eq__ only
  compares transforms, causing false "duplicate port" errors.
- Remove deprecated component_name and taper params from add_pads_top
  (removed in gdsfactory 9.43 route_bundle API).
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 18, 2026

Reviewer's Guide

Adds a compatibility patch for gdsfactory 9.43’s port registration behavior and removes deprecated parameters from IHP pad-adding container helpers to match the new routing API.

Sequence diagram for patched gdsfactory _register_ports behavior

sequenceDiagram
    participant Caller
    participant gdsfactory_add_ports as gdsfactory_add_ports
    participant _name_only_register_ports as _name_only_register_ports
    participant Component as component

    Caller->>gdsfactory_add_ports: _register_ports(component, ports, auto_rename_ports, allow_none_names)
    activate gdsfactory_add_ports
    gdsfactory_add_ports->>_name_only_register_ports: _name_only_register_ports(component, ports, auto_rename_ports, allow_none_names)
    activate _name_only_register_ports
    _name_only_register_ports->>gdsfactory_add_ports: sort_ports_clockwise(ports)
    gdsfactory_add_ports-->>_name_only_register_ports: ports (sorted)

    loop for each port in ports
        _name_only_register_ports->>Component: check port.name in component.ports
        alt name already in component.ports
            _name_only_register_ports-->>Caller: ValueError
        else name not in component.ports
            _name_only_register_ports->>Component: add_port(name=port.name, port=port)
        end
    end

    alt auto_rename_ports
        _name_only_register_ports->>Component: auto_rename_ports()
    end

    _name_only_register_ports-->>gdsfactory_add_ports: component
    deactivate _name_only_register_ports
    gdsfactory_add_ports-->>Caller: component
    deactivate gdsfactory_add_ports
Loading

File-Level Changes

Change Details Files
Patch gdsfactory’s internal _register_ports to detect duplicates by name only instead of using BasePort.eq position-based equality, avoiding false duplicate-port errors for overlapping pin markers.
  • Import gdsfactory.add_ports as a separate module alias to access internal helpers.
  • Store the original _register_ports function for potential future reference.
  • Introduce _name_only_register_ports that sorts ports, then checks for duplicates solely by port.name (honoring allow_none_names) before adding them to the component and optionally auto-renaming.
  • Monkey-patch gdsfactory.add_ports._register_ports to point to _name_only_register_ports at import time.
ihp/cells2/utils.py
Align add_pads_top helper signatures and calls with gdsfactory 9.43 by dropping deprecated component_name and taper parameters.
  • Remove component_name and taper parameters from add_pads_top function definitions in both legacy and cells2 container modules.
  • Update docstrings to no longer mention component_name and taper.
  • Update gf.routing.add_pads_top call sites to omit the removed parameters so the wrapper matches the upstream API.
ihp/cells/containers.py
ihp/cells2/containers.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
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 global monkeypatch of _gf_add_ports._register_ports in utils.py affects all gdsfactory usage; consider scoping the workaround to just the IHP flow (e.g., via a local helper that calls the patched logic or by patching/unpatching around specific calls) to avoid surprising behavior elsewhere.
  • It may be safer to guard the _register_ports override on the detected gdsfactory version and/or feature-test the original behavior, so that future gdsfactory changes don’t silently interact badly with this compatibility shim.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The global monkeypatch of `_gf_add_ports._register_ports` in `utils.py` affects all gdsfactory usage; consider scoping the workaround to just the IHP flow (e.g., via a local helper that calls the patched logic or by patching/unpatching around specific calls) to avoid surprising behavior elsewhere.
- It may be safer to guard the `_register_ports` override on the detected gdsfactory version and/or feature-test the original behavior, so that future gdsfactory changes don’t silently interact badly with this compatibility shim.

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 simplifies the add_pads_top function across the ihp cells by removing the component_name and taper parameters. It also implements a monkey-patch in ihp/cells2/utils.py to override gdsfactory port registration behavior, preventing false rejections of overlapping ports. Feedback indicates that the logic for checking existing port names is flawed and inefficient, and it suggests moving the monkey-patch to a central initialization location to ensure it is reliably applied.

Comment thread ihp/cells2/utils.py
Comment on lines +24 to +34
for port in ports:
_port_name = port.name
if allow_none_names and _port_name is None:
continue
if _port_name is not None and _port_name in component.ports:
component_ports = [p.name for p in component.ports]
raise ValueError(
f"port {_port_name!r} already in {component_ports}. "
"You can pass a port_name_prefix to add it with a different name."
)
component.add_port(name=_port_name, port=port)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The collision check _port_name in component.ports is likely incorrect for gdsfactory 9.x/kfactory. In these versions, component.ports is a PortStack (which behaves like a list of Port objects), so checking if a string (_port_name) is in the stack will always return False. This prevents the custom ValueError from ever being raised, falling back to the default (and potentially less descriptive) error from add_port.

Additionally, performing this check inside the loop results in O(N*M) complexity. A more efficient and correct approach would be to pre-calculate the set of existing port names.

Suggested change
for port in ports:
_port_name = port.name
if allow_none_names and _port_name is None:
continue
if _port_name is not None and _port_name in component.ports:
component_ports = [p.name for p in component.ports]
raise ValueError(
f"port {_port_name!r} already in {component_ports}. "
"You can pass a port_name_prefix to add it with a different name."
)
component.add_port(name=_port_name, port=port)
existing_names = {p.name for p in component.ports}
for port in ports:
_port_name = port.name
if allow_none_names and _port_name is None:
continue
if _port_name is not None and _port_name in existing_names:
raise ValueError(
f"port {_port_name!r} already in {list(existing_names)}. "
"You can pass a port_name_prefix to add it with a different name."
)
component.add_port(name=_port_name, port=port)
existing_names.add(_port_name)

Comment thread ihp/cells2/utils.py
return component


_gf_add_ports._register_ports = _name_only_register_ports
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Applying a global monkey-patch at the module level of a utility file can be fragile. If this module is not imported before a component is instantiated or a routing function is called, the patch will not be active. Consider moving this workaround to a more central initialization location (e.g., the package's __init__.py) to ensure it is consistently applied across the PDK, especially since ihp/cells/containers.py does not explicitly import this utility.

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