Coverage for klayout_pex/klayout/netlist_reducer.py: 96%
23 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-02 23:32 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-02 23:32 +0000
1#
2# --------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: 2024-2025 Martin Jan Köhler and Harald Pretl
4# Johannes Kepler University, Institute for Integrated Circuits.
5#
6# This file is part of KPEX
7# (see https://github.com/iic-jku/klayout-pex).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21# SPDX-License-Identifier: GPL-3.0-or-later
22# --------------------------------------------------------------------------------
23#
24from typing import *
26import klayout.db as kdb
28from ..log import (
29 info,
30)
31from .parasitic_device_classes import PARASITIC_CAPACITOR_CLASS_NAME
34class NetlistReducer:
35 @staticmethod
36 def reduce(netlist: kdb.Netlist,
37 top_cell_name: str,
38 cap_threshold: float = 0.05e-15) -> kdb.Netlist:
39 reduced_netlist: kdb.Netlist = netlist.dup()
40 reduced_netlist.combine_devices() # merge C/R
42 top_circuit: kdb.Circuit = reduced_netlist.circuit_by_name(top_cell_name)
44 devices_to_remove: List[kdb.Device] = []
46 for d in top_circuit.each_device():
47 d: kdb.Device
48 dc = d.device_class()
49 # NOTE: only the parasitics KPEX added, the capacitors of the LVS netlist (e.g. MIM, MOM)
50 # may have no C parameter (#203)
51 if dc.name == PARASITIC_CAPACITOR_CLASS_NAME:
52 # net_a = d.net_for_terminal('A')
53 # net_b = d.net_for_terminal('B')
54 c_value = d.parameter('C')
55 if c_value < cap_threshold:
56 devices_to_remove.append(d)
58 elif isinstance(dc, kdb.DeviceClassResistor):
59 # TODO
60 pass
62 for d in devices_to_remove:
63 info(f"Removed device {d.name} {d.parameter('C')}")
64 top_circuit.remove_device(d)
66 return reduced_netlist