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:
- Optical nets — extracted from geometric port adjacency (ports that physically touch in the layout are connected)
- Electrical nets — extracted using klayout's built-in
LayoutToNetlistengine 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:
- Schematic-Driven Design —
building circuits, extracting netlists with
cell.netlist(), and comparing connectivity - Netlist & Schematic I/O —
inspecting
Netlistobjects, sorting for stable comparison, serialization, and handling electrically-equivalent ports - 45° Crossing with Virtual Cells — advanced hierarchical design with netlist verification and code generation
See Also
| Topic | Where |
|---|---|
| Core netlist data model | Concepts: Netlist Model |
| Equivalent ports | Guides: Equivalent Ports |