Skip to content

Netlist Extraction

The kfnetlist.extract subpackage extracts hierarchical netlists from kfactory/klayout layout cells. It requires klayout as a runtime dependency.

Architecture

Extraction combines two complementary approaches:

  1. Optical nets — extracted from geometric port adjacency (ports that physically touch in the layout are connected)
  2. Electrical nets — extracted using klayout's built-in LayoutToNetlist engine with user-defined connectivity rules

The main extract() function orchestrates both, walks the cell hierarchy, and returns a dict[str, Netlist] keyed by cell name.

Pipeline

extract(cell)
    │
    ├── gather equivalent ports from cell/factory metadata
    │
    ├── l2n_elec(cell)              ← electrical connectivity
    │   ├── duplicate layout
    │   ├── materialize port markers as Text shapes
    │   ├── connect layers per connectivity rules
    │   └── klayout extract_netlist()
    │
    └── for each cell in hierarchy:
        ├── get_optical_nets(cell)   ← geometric port adjacency
        │   ├── bucket cell ports by (x, y, layer)
        │   ├── bucket instance ports by (x, y, layer)
        │   └── check_connection() on candidate pairs
        │
        ├── merge optical + electrical nets
        ├── flatten unnamed / excluded instances
        └── apply equivalent port folding if equivalent ports defined

Requirements

The extraction subpackage uses Protocol types to remain decoupled from kfactory's concrete classes. The only hard dependency is klayout (for kdb.LayoutToNetlist, kdb.Region, transforms, etc.).

The wrap_kdb_instance callback bridges kfnetlist's protocol-based API with kfactory's instance wrapper. In kfactory, this is typically:

lambda i: Instance(kcl=cell.kcl, instance=i)

Submodules

Module Purpose
extract Main extract() orchestrator
get_optical_nets Geometric port-adjacency extraction
l2n_elec Electrical layout-to-netlist
check_connection Port-pair comparison bitmask

kfactory examples

kfactory uses kfnetlist internally for netlist extraction. The kfactory docs have end-to-end examples showing extraction in practice:

See Also

Topic Where
Core netlist data model Concepts: Netlist Model
Equivalent ports Guides: Equivalent Ports