Skip to content

feat(via_stack): directional NSEW ports, case-insensitive input, degenerate single-layer#197

Merged
ThomasPluck merged 3 commits into
mainfrom
feat/via-stack-directional-ports-degenerate
Jun 25, 2026
Merged

feat(via_stack): directional NSEW ports, case-insensitive input, degenerate single-layer#197
ThomasPluck merged 3 commits into
mainfrom
feat/via-stack-directional-ports-degenerate

Conversation

@ThomasPluck

@ThomasPluck ThomasPluck commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Three changes to via_stack to support GDSFactory+ Livewire electrical routing:

  • Directional ports: Replaces center-positioned bottom/top ports with {layer}_{N|S|E|W} ports at bbox edges. N/S ports span the x-extent, E/W ports span the y-extent — gives the router directional routing information for multi-layer electrical routes.
  • Case-insensitive input normalization: bottom_layer/top_layer are matched case-insensitively against known BEOL names (e.g. METAL1Metal1). Original input casing is preserved in port labels so callers can pass connectivity-style names.
  • Degenerate single-layer case: bottom_layer == top_layer now produces a single metal rectangle with NSEW ports instead of raising ValueError. This lets the build pipeline use via_stack uniformly for both cross-layer and same-layer junction points.

Breaking change

Port names change from bottom/top to {layer}_{N|S|E|W} (e.g. Metal1_N, Metal2_E). Checked all callers in-tree (capacitors.py, sample_to_3d_electrical.py, LNA examples) — none reference ports by name, they only use the component as a positioned ref.

Test plan

  • via_stack("Metal1", "Metal2") produces Metal1_{N,S,E,W} and Metal2_{N,S,E,W} ports at correct bbox positions
  • via_stack("METAL1", "METAL2") resolves case and creates correct geometry
  • via_stack("Metal1", "Metal1") produces single-layer rectangle with Metal1_{N,S,E,W} ports, no vias
  • via_stack("Metal2", "Metal1") still raises ValueError
  • Existing callers (capacitors.py MOM cap) unaffected — CI should confirm

Summary by Sourcery

Update via_stack to support directional NSEW electrical ports with case-insensitive layer handling and a single-layer degenerate case.

New Features:

  • Expose directional NSEW electrical ports per participating layer on via_stack components using bbox-based positioning.
  • Allow via_stack to create a single-layer metal rectangle with ports when bottom_layer equals top_layer.

Bug Fixes:

  • Relax bottom/top layer ordering validation to permit equal layers while still rejecting inverted layer order.

Enhancements:

  • Normalize bottom_layer and top_layer inputs case-insensitively against known BEOL layer names while preserving original casing for port labels.

…nerate single-layer support

Three changes to via_stack to support GDSFactory+ Livewire electrical routing:

1. **Directional ports**: Replace center-positioned `bottom`/`top` ports with
   `{layer}_{N|S|E|W}` ports at bbox edges. N/S ports span the x-extent,
   E/W ports span the y-extent. This gives the router directional information
   for multi-layer electrical routes.

2. **Case-insensitive input**: Normalize `bottom_layer`/`top_layer` against
   known BEOL names so callers can pass connectivity-style names (e.g.
   `METAL1`, `metal1`) and they resolve to the canonical `Metal1` used
   internally. Original input casing is preserved in port labels.

3. **Degenerate single-layer case**: Allow `bottom_layer == top_layer`.
   Produces a single metal rectangle with NSEW ports (no vias). This lets
   the build pipeline use via_stack uniformly for both multi-layer and
   same-layer junction points without special-casing.
@sourcery-ai

sourcery-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds directional NSEW electrical ports to via_stack, normalizes layer name inputs case-insensitively, and supports a degenerate single-layer case without error while preserving original labels in port names.

File-Level Changes

Change Details Files
Introduce case-insensitive normalization of bottom_layer/top_layer while preserving original input for port labels.
  • Build a lowercase-to-canonical-name map from BEOL and sub-metal layer names.
  • Store original bottom_layer/top_layer strings as bottom_port_label/top_port_label for use in port naming.
  • Normalize bottom_layer/top_layer to canonical names via the map before computing layer order.
ihp/cells/via_stacks.py
Relax layer ordering validation to allow the degenerate single-layer via_stack case.
  • Change bottom/top layer index comparison from >= to > when validating BEOL order.
  • Allow bottom_layer == top_layer to pass validation and proceed to geometry creation.
ihp/cells/via_stacks.py
Replace single center 'bottom'/'top' ports with directional NSEW ports per participating layer, sized and placed at the component bounding box edges.
  • Remove existing center-based 'bottom' and 'top' electrical ports.
  • Compute half-width/half-height and define NSEW port positions, orientations, and widths based on bbox extents.
  • Build a list of participating layers that includes bottom_layer and, conditionally, top_layer if it differs in canonical or label form.
  • Add NSEW electrical ports for each participating layer, naming them as '{original_input_label}_{direction}' and mapping to the appropriate pin layer.
  • Ensure single-layer via_stack produces only one set of NSEW ports without vias while preserving label casing.
ihp/cells/via_stacks.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

@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 the degenerate single-layer case, when bottom_layer and top_layer differ only by case (e.g. METAL1 vs Metal1), the current _port_layers condition still adds two sets of ports on the same physical layer; if the intent is a single set of {layer}_{N,S,E,W} ports, consider tightening the condition to only add one logical layer of ports after normalization.
  • You might want to reuse the normalized layer names (bottom_layer/top_layer) consistently for port labels as well, or else clearly separate the concepts (e.g. normalized_layer vs connectivity_label) to avoid confusion where ports on the same physical layer have different naming conventions depending on input casing.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the degenerate single-layer case, when `bottom_layer` and `top_layer` differ only by case (e.g. `METAL1` vs `Metal1`), the current `_port_layers` condition still adds two sets of ports on the same physical layer; if the intent is a single set of `{layer}_{N,S,E,W}` ports, consider tightening the condition to only add one logical layer of ports after normalization.
- You might want to reuse the normalized layer names (`bottom_layer`/`top_layer`) consistently for port labels as well, or else clearly separate the concepts (e.g. `normalized_layer` vs `connectivity_label`) to avoid confusion where ports on the same physical layer have different naming conventions depending on input casing.

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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces case-insensitive normalization for layer names in via_stack and replaces the single "bottom" and "top" ports with directional ports (N, S, E, W) at the bounding box edges for both layers. It also relaxes the layer order check to allow the bottom and top layers to be identical. The review feedback correctly identifies a bug where duplicate overlapping ports could be created if the bottom and top layers normalize to the same physical layer but have different casings, and provides a code suggestion to resolve this.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread ihp/cells/via_stacks.py
Comment on lines +377 to +379
_port_layers = [(bottom_layer, bottom_port_label)]
if top_layer != bottom_layer or top_port_label != bottom_port_label:
_port_layers.append((top_layer, top_port_label))

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.

medium

When bottom_layer and top_layer normalize to the same physical layer but have different casings (e.g., "metal1" and "Metal1"), the condition top_port_label != bottom_port_label evaluates to True. This causes duplicate overlapping ports to be added on the same physical layer, which can lead to routing errors in gdsfactory. We should only append the top layer ports if the normalized layers are physically different.

Suggested change
_port_layers = [(bottom_layer, bottom_port_label)]
if top_layer != bottom_layer or top_port_label != bottom_port_label:
_port_layers.append((top_layer, top_port_label))
_port_layers = [(bottom_layer, bottom_port_label)]
if top_layer != bottom_layer:
_port_layers.append((top_layer, top_port_label))

Port names changed from bottom/top to {layer}_{N|S|E|W} — update the
regression reference to match the new port scheme.
@ThomasPluck ThomasPluck merged commit 46c1743 into main Jun 25, 2026
@ThomasPluck ThomasPluck deleted the feat/via-stack-directional-ports-degenerate branch June 25, 2026 13:54
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.

2 participants