Skip to content

Demonstrate LVS with KLayout#426

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/demonstrate-lvs-with-klayout
Draft

Demonstrate LVS with KLayout#426
Copilot wants to merge 5 commits into
mainfrom
copilot/demonstrate-lvs-with-klayout

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Adds a KLayout LVS deck for layout-vs-schematic verification of superconducting quantum circuits, with Jinja2 templating for maintainability and documentation explaining the full flow.

New layers

  • Port layers (PORT_M1 1/10, PORT_M2 2/10) for net terminal detection per metal
  • Device marker layers (MK_TRANSMON 200/0, MK_RESONATOR 201/0, MK_INDUCTOR 202/0, MK_CAPACITOR 203/0, MK_JJ 204/0) for component identification via boolean AND with physical layers

LVS deck (qpdk/klayout/lvs/)

  • qpdk.lvs.j2 — Jinja2 template covering layer definitions, connectivity (TSV, indium bumps, airbridges), marker-based device extraction, and port/pin detection
  • render_lvs.py — Declarative data tables for layers, connectivity rules, and device definitions; renders the template
  • qpdk.lvs — Generated deck, invoked as:
klayout -b -r qpdk/klayout/lvs/qpdk.lvs \
    -rd input=layout.gds \
    -rd schematic=netlist.cir \
    -rd report=lvs_report.lvsdb

Adding a new device type requires only appending to the DEVICES list in render_lvs.py and re-rendering.

Documentation (docs/lvs.md)

Covers what LVS is in the quantum context, how the deck works (connectivity, ports, markers), how to add port/marker shapes to components, how to run LVS, and how to inspect results in KLayout's Netlist Database Browser.

Tests (tests/test_lvs.py)

9 tests covering template rendering, layer/connectivity/device coverage, and committed file consistency.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI linked an issue Mar 29, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Demonstrate LVS flow with KLayout and gdsfactory Demonstrate LVS with KLayout Mar 29, 2026
Copilot AI requested a review from nikosavola March 29, 2026 13:49
@nikosavola nikosavola requested a review from Copilot March 29, 2026 14:00
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests Relating to testing labels Mar 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an LVS (layout-vs-schematic) flow to QPDK using KLayout, including a generated LVS deck (via Jinja2 templating), new LVS-specific layers (ports + device markers), documentation for running/inspecting LVS, and a small test suite to keep the generated deck in sync.

Changes:

  • Introduces a Jinja2-templated KLayout LVS deck plus a Python renderer and committed generated output.
  • Adds LVS port layers and device marker layers to the PDK layer map and layer-view configuration (YAML + KLayout layer properties).
  • Adds documentation and tests for the rendering/deck consistency.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_lvs.py New tests asserting renderer output coverage and that the committed deck matches rendering.
qpdk/tech.py Adds PORT_* and MK_* layer constants to the PDK layer map.
qpdk/layers.yaml Adds LVS_Ports and LVS_Markers layer-view groups for visibility/coloring.
qpdk/klayout/tech.lyt Reorders connectivity <symbols> entries (no functional changes apparent).
qpdk/klayout/lvs/render_lvs.py New deck renderer with declarative layer/connectivity/device tables.
qpdk/klayout/lvs/qpdk.lvs.j2 New Jinja2 template for the KLayout LVS deck.
qpdk/klayout/lvs/qpdk.lvs Generated LVS deck committed to the repo.
qpdk/klayout/layers.lyp Adds LVS port/marker groups to the KLayout layer properties file.
docs/lvs.md New end-to-end documentation for the LVS flow, including component authoring guidance.
docs/index.md Adds LVS docs page to the docs toctree under “Verification”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_lvs.py
Comment on lines +5 to +15
from qpdk.klayout.lvs import render_lvs as _render_lvs_mod
from qpdk.klayout.lvs.render_lvs import (
CONNECTIONS,
DEVICES,
MARKER_LAYERS,
PHYSICAL_LAYERS,
PORT_LAYERS,
render,
)


Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

from qpdk.klayout.lvs ... will fail because qpdk/klayout/ and qpdk/klayout/lvs/ are not Python packages in this repo (no __init__.py files). Add __init__.py files (or move the renderer into an existing package) so these imports and tests can run.

Suggested change
from qpdk.klayout.lvs import render_lvs as _render_lvs_mod
from qpdk.klayout.lvs.render_lvs import (
CONNECTIONS,
DEVICES,
MARKER_LAYERS,
PHYSICAL_LAYERS,
PORT_LAYERS,
render,
)
from importlib.machinery import SourceFileLoader
from pathlib import Path
_render_lvs_path = (
Path(__file__).resolve().parents[1]
/ "qpdk"
/ "klayout"
/ "lvs"
/ "render_lvs.py"
)
_render_lvs_mod = SourceFileLoader(
"qpdk_klayout_lvs_render_lvs", str(_render_lvs_path)
).load_module()
CONNECTIONS = _render_lvs_mod.CONNECTIONS
DEVICES = _render_lvs_mod.DEVICES
MARKER_LAYERS = _render_lvs_mod.MARKER_LAYERS
PHYSICAL_LAYERS = _render_lvs_mod.PHYSICAL_LAYERS
PORT_LAYERS = _render_lvs_mod.PORT_LAYERS
render = _render_lvs_mod.render

Copilot uses AI. Check for mistakes.
Comment thread qpdk/klayout/lvs/render_lvs.py Outdated
Comment on lines +16 to +17
from jinja2 import Environment, FileSystemLoader

Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

render_lvs.py imports jinja2, but jinja2 is not listed in the project’s core or test dependencies (it appears only under the docs dependency group). Since this module is imported by tests and is part of the shipped package, add jinja2 to the appropriate runtime deps (or make this import optional / guarded) to avoid ImportError in CI and user installs.

Suggested change
from jinja2 import Environment, FileSystemLoader
try:
from jinja2 import Environment, FileSystemLoader
except ImportError: # pragma: no cover - exercised only when jinja2 is missing
def _missing_jinja2(*args: object, **kwargs: object) -> "NoReturn": # type: ignore[name-defined]
raise RuntimeError(
"The 'jinja2' package is required to use qpdk.klayout.lvs.render_lvs. "
"Install it as a runtime dependency (e.g. 'pip install jinja2') or via "
"the appropriate extras group for this project."
)
Environment = _missing_jinja2 # type: ignore[assignment]
FileSystemLoader = _missing_jinja2 # type: ignore[assignment]

Copilot uses AI. Check for mistakes.
Comment thread qpdk/klayout/lvs/render_lvs.py Outdated

from jinja2 import Environment, FileSystemLoader

from qpdk import logger
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

Importing logger via from qpdk import logger executes qpdk/__init__.py (which constructs the PDK and imports gdsfactory), adding unnecessary side effects and startup cost for a simple deck renderer. Prefer importing the logger directly (e.g., from qpdk.logger import logger) to keep this script lightweight.

Suggested change
from qpdk import logger
from qpdk.logger import logger

Copilot uses AI. Check for mistakes.
Comment thread qpdk/klayout/lvs/render_lvs.py Outdated
"""Render the QPDK KLayout LVS deck from a Jinja2 template.

The template ``qpdk.lvs.j2`` lives next to this script and is rendered into
``qpdk.lvs`` using the layer and device definitions from :mod:`qpdk.tech`.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The module docstring says the deck is rendered “using the layer and device definitions from qpdk.tech”, but the layer/connectivity/device tables are currently hard-coded in this file. Either source these values from qpdk.tech (to prevent drift) or adjust the docstring to match the implementation.

Suggested change
``qpdk.lvs`` using the layer and device definitions from :mod:`qpdk.tech`.
``qpdk.lvs`` using the layer and device definitions defined in this module.

Copilot uses AI. Check for mistakes.
Comment thread docs/lvs.md Outdated
Comment on lines +184 to +187
(bbox[0][0], bbox[0][1]),
(bbox[1][0], bbox[0][1]),
(bbox[1][0], bbox[1][1]),
(bbox[0][0], bbox[1][1]),
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

In this example, bbox = c.bbox() is treated like a 2×2 array (bbox[0][0], etc.), but elsewhere in this repo bbox() returns a KLayout box-like object with attributes (left/right/top/bottom or p1/p2). As written, this snippet is likely to raise at runtime; update it to use the box attributes used throughout the codebase.

Suggested change
(bbox[0][0], bbox[0][1]),
(bbox[1][0], bbox[0][1]),
(bbox[1][0], bbox[1][1]),
(bbox[0][0], bbox[1][1]),
(bbox.left, bbox.bottom),
(bbox.right, bbox.bottom),
(bbox.right, bbox.top),
(bbox.left, bbox.top),

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests Relating to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Demonstrate LVS

3 participants