Coverage for klayout_pex/klayout/netlist_csv.py: 26%

23 statements  

« 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 __future__ import annotations 

25 

26import klayout.db as kdb 

27 

28from klayout_pex.log import ( 

29 info, 

30) 

31 

32 

33class NetlistCSVWriter: 

34 @staticmethod 

35 def write_csv(netlist: kdb.Netlist, 

36 top_cell_name: str, 

37 output_path: str): 

38 with open(output_path, 'w') as f: 

39 f.write('Device;Net1;Net2;Capacitance [fF]\n') 

40 

41 top_circuit: kdb.Circuit = netlist.circuit_by_name(top_cell_name) 

42 

43 # NOTE: only caps for now 

44 for d in top_circuit.each_device(): 

45 # https://www.klayout.de/doc-qt5/code/class_Device.html 

46 dc = d.device_class() 

47 if isinstance(dc, kdb.DeviceClassCapacitor): 

48 dn = d.expanded_name() or d.name 

49 if dc.name != 'PEX_CAP': 

50 info(f"Ignoring device {dn}") 

51 continue 

52 param_defs = dc.parameter_definitions() 

53 params = {p.name: d.parameter(p.id()) for p in param_defs} 

54 d: kdb.Device 

55 net1 = d.net_for_terminal('A') 

56 net2 = d.net_for_terminal('B') 

57 cap = params['C'] 

58 cap_femto = round(cap * 1e15, 2) 

59 f.write(f"{dn};{net1.name};{net2.name};{cap_femto}\n")