Coverage for klayout_pex/klayout/netlist_reducer.py: 82%
22 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-17 17:24 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-17 17:24 +0000
1#
2# --------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: 2024 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/martinjankoehler/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)
33class NetlistReducer:
34 @staticmethod
35 def reduce(netlist: kdb.Netlist,
36 top_cell_name: str,
37 cap_threshold: float = 0.05e-15) -> kdb.Netlist:
38 reduced_netlist: kdb.Netlist = netlist.dup()
39 reduced_netlist.combine_devices() # merge C/R
41 top_circuit: kdb.Circuit = reduced_netlist.circuit_by_name(top_cell_name)
43 devices_to_remove: List[kdb.Device] = []
45 for d in top_circuit.each_device():
46 d: kdb.Device
47 dc = d.device_class()
48 if isinstance(dc, kdb.DeviceClassCapacitor):
49 # net_a = d.net_for_terminal('A')
50 # net_b = d.net_for_terminal('B')
51 c_value = d.parameter('C')
52 if c_value < cap_threshold:
53 devices_to_remove.append(d)
55 elif isinstance(dc, kdb.DeviceClassResistor):
56 # TODO
57 pass
59 for d in devices_to_remove:
60 info(f"Removed device {d.name} {d.parameter('C')}")
61 top_circuit.remove_device(d)
63 return reduced_netlist